Browse Source

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

refactor-mempool
Roman Zeyde 7 years ago
parent
commit
b71c41854e
No known key found for this signature in database GPG Key ID: 87CAE5FA46917CBB
  1. 3
      src/bulk.rs
  2. 12
      src/store.rs

3
src/bulk.rs

@ -242,7 +242,8 @@ pub fn index(daemon: &Daemon, metrics: &Metrics, store: DBStore) -> Result<DBSto
}); });
store.write(vec![parser.last_indexed_row()]); store.write(vec![parser.last_indexed_row()]);
store.flush(); store.flush();
store.compact(); // will take a while.
let store = store.compact(); // will take a while.
store.put(FINISH_MARKER, b""); store.put(FINISH_MARKER, b"");
Ok(store) Ok(store)
}).join() }).join()

12
src/store.rs

@ -72,8 +72,7 @@ impl DBStore {
pub fn enable_compaction(self) -> Self { pub fn enable_compaction(self) -> Self {
let mut opts = self.opts.clone(); let mut opts = self.opts.clone();
opts.bulk_import = false; opts.bulk_import = false;
drop(self); drop(self); // DB must be closed before being re-opened
// DB must be closed before being re-opened:
DBStore::open_opts(opts) DBStore::open_opts(opts)
} }
@ -81,10 +80,15 @@ impl DBStore {
self.db.put(key, value).unwrap(); 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"); 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"); info!("finished full compaction");
store
} }
} }

Loading…
Cancel
Save