|
|
|
@ -1107,6 +1107,15 @@ impl WriteBatch { |
|
|
|
|
unsafe { ffi::rocksdb_writebatch_count(self.inner) as usize } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Return WriteBatch serialized size (in bytes).
|
|
|
|
|
pub fn size_in_bytes(&self) -> usize { |
|
|
|
|
unsafe { |
|
|
|
|
let mut batch_size: size_t = 0; |
|
|
|
|
ffi::rocksdb_writebatch_data(self.inner, &mut batch_size); |
|
|
|
|
batch_size as usize |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool { |
|
|
|
|
self.len() == 0 |
|
|
|
|
} |
|
|
|
@ -1404,6 +1413,14 @@ fn writebatch_works() { |
|
|
|
|
assert!(p.is_ok()); |
|
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
|
} |
|
|
|
|
{ |
|
|
|
|
// test size_in_bytes
|
|
|
|
|
let mut batch = WriteBatch::default(); |
|
|
|
|
let before = batch.size_in_bytes(); |
|
|
|
|
let _ = batch.put(b"k1", b"v1234567890"); |
|
|
|
|
let after = batch.size_in_bytes(); |
|
|
|
|
assert!(before + 10 <= after); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
let opts = Options::default(); |
|
|
|
|
assert!(DB::destroy(&opts, path).is_ok()); |
|
|
|
|