Commit d64e54ed authored by Little-Wallace's avatar Little-Wallace

filter empty batch

Signed-off-by: 's avatarLittle-Wallace <bupt2013211450@gmail.com>
parent 25391594
...@@ -738,13 +738,30 @@ impl DB { ...@@ -738,13 +738,30 @@ impl DB {
&self.path &self.path
} }
pub fn multi_thread_write(&self, batches: &Vec<WriteBatch>, writeopts: &WriteOptions) -> Result<(), String> { pub fn multi_thread_write(
&self,
batches: &Vec<WriteBatch>,
writeopts: &WriteOptions,
) -> Result<(), String> {
unsafe { unsafe {
if batches.len() == 1 { if batches.len() == 1 {
ffi_try!(crocksdb_write(self.inner, writeopts.inner, batches[0].inner)); ffi_try!(crocksdb_write(
self.inner,
writeopts.inner,
batches[0].inner
));
} else { } else {
let b : Vec<*mut DBWriteBatch> = batches.iter().map(|w| w.inner).collect(); let b: Vec<*mut DBWriteBatch> = batches
ffi_try!(crocksdb_write_multi_batch(self.inner, writeopts.inner, b.as_ptr(), b.len())); .iter()
.filter(|w| w.count() > 0)
.map(|w| w.inner)
.collect();
ffi_try!(crocksdb_write_multi_batch(
self.inner,
writeopts.inner,
b.as_ptr(),
b.len()
));
} }
} }
Ok(()) Ok(())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment