Exposes a function to compact the database

Use it after load
pull/171/head
Tpt 3 years ago
parent 8c0b4f5322
commit 98f9a307b8
  1. 1
      lib/benches/store.rs
  2. 1
      lib/src/storage/backend/rocksdb.rs
  3. 15
      lib/src/storage/mod.rs
  4. 10
      lib/src/store.rs

@ -43,6 +43,7 @@ fn do_load(store: &Store, data: &[u8]) {
None,
)
.unwrap();
store.optimize().unwrap();
}
fn store_query_and_update(c: &mut Criterion) {

@ -304,7 +304,6 @@ impl Db {
}
}
#[cfg(test)]
#[allow(clippy::unnecessary_wraps)]
pub fn compact(&self, column_family: &ColumnFamily) -> Result<()> {
unsafe {

@ -841,6 +841,21 @@ impl Storage {
self.db.flush(&self.id2str_cf)
}
#[cfg(not(target_arch = "wasm32"))]
pub fn compact(&self) -> Result<()> {
self.db.compact(&self.default_cf)?;
self.db.compact(&self.gpos_cf)?;
self.db.compact(&self.gpos_cf)?;
self.db.compact(&self.gosp_cf)?;
self.db.compact(&self.spog_cf)?;
self.db.compact(&self.posg_cf)?;
self.db.compact(&self.ospg_cf)?;
self.db.compact(&self.dspo_cf)?;
self.db.compact(&self.dpos_cf)?;
self.db.compact(&self.dosp_cf)?;
self.db.compact(&self.id2str_cf)
}
pub fn get_str(&self, key: &StrHash) -> Result<Option<String>> {
self.db
.get(&self.id2str_cf, &key.to_be_bytes())?

@ -561,6 +561,16 @@ impl Store {
pub fn flush(&self) -> io::Result<()> {
self.storage.flush()
}
/// Optimizes the database for future workload.
///
/// Useful to call after a batch upload or an other similar operation.
///
/// Warning: Can take hours on huge databases.
#[cfg(not(target_arch = "wasm32"))]
pub fn optimize(&self) -> io::Result<()> {
self.storage.compact()
}
}
impl fmt::Display for Store {

Loading…
Cancel
Save