Re-open DB before compaction (to close unused file descriptors)
This commit is contained in:
parent
45b507a241
commit
b71c41854e
|
@ -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()
|
||||
|
|
12
src/store.rs
12
src/store.rs
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user