Browse Source
Re-open DB before compaction (to close unused file descriptors)
refactor-mempool
Roman Zeyde
7 years ago
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with
10 additions and
5 deletions
-
src/bulk.rs
-
src/store.rs
|
|
@ -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() |
|
|
|
|
|
@ -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 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|