Re-open DB before compaction (to close unused file descriptors)

This commit is contained in:
Roman Zeyde 2018-08-02 15:00:30 +03:00
parent 45b507a241
commit b71c41854e
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with 10 additions and 5 deletions

View File

@ -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()

View File

@ -72,8 +72,7 @@ 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)
}
@ -81,10 +80,15 @@ impl DBStore {
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
}
}