changeset 391:b27d1c73b0d7

db_impl: Call make_room_for_write() before doing a write operation.
author Lewin Bormann <lbo@spheniscida.de>
date Mon, 09 Oct 2017 21:59:25 +0200
parents deff4aa09832
children 0d95cbc27e93
files src/db_impl.rs
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/db_impl.rs	Mon Oct 09 21:58:52 2017 +0200
+++ b/src/db_impl.rs	Mon Oct 09 21:59:25 2017 +0200
@@ -364,6 +364,9 @@
     /// disk.
     pub fn write(&mut self, batch: WriteBatch, sync: bool) -> Result<()> {
         assert!(self.log.is_some());
+
+        self.make_room_for_write(false)?;
+
         let entries = batch.count() as u64;
         let log = self.log.as_mut().unwrap();
         let next = self.vset.borrow().last_seq + 1;
@@ -510,10 +513,11 @@
 
 impl DB {
     // COMPACTIONS //
+
     /// 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) -> Result<()> {
-        if self.mem.approx_mem_usage() < self.opt.write_buffer_size {
+    fn make_room_for_write(&mut self, force: bool) -> Result<()> {
+        if !force && self.mem.approx_mem_usage() < self.opt.write_buffer_size {
             Ok(())
         } else {
             // Create new memtable.