Skip to content

Commit

Permalink
Re-open DB before compaction (to close unused file descriptors)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed Aug 2, 2018
1 parent 45b507a commit b71c418
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ pub fn index(daemon: &Daemon, metrics: &Metrics, store: DBStore) -> Result<DBSto
});
store.write(vec![parser.last_indexed_row()]);
store.flush();
store.compact(); // will take a while.

let store = store.compact(); // will take a while.
store.put(FINISH_MARKER, b"");
Ok(store)
}).join()
Expand Down
12 changes: 8 additions & 4 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@ impl DBStore {
pub fn enable_compaction(self) -> Self {
let mut opts = self.opts.clone();
opts.bulk_import = false;
drop(self);
// DB must be closed before being re-opened:
drop(self); // DB must be closed before being re-opened
DBStore::open_opts(opts)
}

pub fn put(&self, key: &[u8], value: &[u8]) {
self.db.put(key, value).unwrap();
}

pub fn compact(&self) {
pub fn compact(self) -> Self {
let opts = self.opts.clone();
drop(self); // DB must be closed before being re-opened

let store = DBStore::open_opts(opts);
info!("starting full compaction");
self.db.compact_range(None, None); // would take a while
store.db.compact_range(None, None); // would take a while
info!("finished full compaction");
store
}
}

Expand Down

0 comments on commit b71c418

Please sign in to comment.