Mercurial > lbo > hg > leveldb-rs
changeset 608:2abfa394ba2d
Merge pull request #36 from dermesser/do-more-compactions
Do compactions after writing memtables (#34)
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 15 Jul 2023 22:06:55 +0200 |
parents | 08549e2435ff (current diff) 6395514d9a34 (diff) |
children | e41530366262 |
files | |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/db_impl.rs Tue Jun 20 17:52:43 2023 +0200 +++ b/src/db_impl.rs Sat Jul 15 22:06:55 2023 +0200 @@ -418,8 +418,10 @@ /// flush makes sure that all pending changes (e.g. from put()) are stored on disk. pub fn flush(&mut self) -> Result<()> { - assert!(self.log.is_some()); - self.log.as_mut().unwrap().flush() + if let Some(ref mut log) = self.log.as_mut() { + log.flush()?; + } + Ok(()) } } @@ -565,9 +567,7 @@ /// make_room_for_write checks if the memtable has become too large, and triggers a compaction /// if it's the case. fn make_room_for_write(&mut self, force: bool) -> Result<()> { - if !force && self.mem.approx_mem_usage() < self.opt.write_buffer_size { - Ok(()) - } else if self.mem.len() == 0 { + if !force && self.mem.approx_mem_usage() < self.opt.write_buffer_size || self.mem.len() == 0 { Ok(()) } else { // Create new memtable. @@ -594,8 +594,9 @@ /// maybe_do_compaction starts a blocking compaction if it makes sense. fn maybe_do_compaction(&mut self) -> Result<()> { if self.imm.is_some() { - self.compact_memtable() - } else if self.vset.borrow().needs_compaction() { + self.compact_memtable()?; + } + if self.vset.borrow().needs_compaction() { let c = self.vset.borrow_mut().pick_compaction(); if let Some(c) = c { self.start_compaction(c) @@ -949,6 +950,7 @@ impl Drop for DB { fn drop(&mut self) { + self.flush().ok(); let _ = self.release_lock(); } }