Mercurial > lbo > hg > leveldb-rs
changeset 614:e41530366262
Merge pull request #33 from KAIYOHUGO/master
Add Compressor
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 15 Jul 2023 22:09:44 +0200 |
parents | 2abfa394ba2d (diff) 3cfa3633c012 (current diff) |
children | f48ec74f26b0 |
files | src/db_impl.rs |
diffstat | 1 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/db_impl.rs Sat Jul 15 22:25:31 2023 +0800 +++ b/src/db_impl.rs Sat Jul 15 22:09:44 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) @@ -946,6 +947,7 @@ impl Drop for DB { fn drop(&mut self) { + self.flush().ok(); let _ = self.release_lock(); } }