Commit f5a45559 authored by goroutine's avatar goroutine Committed by GitHub

Merge pull request #64 from siddontang/siddontang/writebatch-len

writebatch support clear and len API
parents 8081edec f748faa5
......@@ -891,6 +891,20 @@ impl WriteBatch {
pub fn is_empty(&self) -> bool {
self.count() == 0
}
pub fn data_size(&self) -> usize {
unsafe {
let mut data_size: usize = 0;
let _ = rocksdb_ffi::rocksdb_writebatch_data(self.inner, &mut data_size);
return data_size;
}
}
pub fn clear(&self) {
unsafe {
rocksdb_ffi::rocksdb_writebatch_clear(self.inner);
}
}
}
impl Drop for WriteBatch {
......@@ -1102,6 +1116,13 @@ mod test {
let p = db.write(batch);
assert!(p.is_ok());
assert!(db.get(b"k1").unwrap().is_none());
let batch = WriteBatch::new();
let prev_size = batch.data_size();
let _ = batch.delete(b"k1");
assert!(batch.data_size() > prev_size);
batch.clear();
assert_eq!(batch.data_size(), prev_size);
}
#[test]
......
use rocksdb::{DB, Options, Range, Writable};use tempdir::TempDir;
use rocksdb::{DB, Options, Range, Writable};
use tempdir::TempDir;
#[test]
......
......@@ -2,7 +2,8 @@
use rocksdb::{Writable, DB, CompactionFilter, Options};
use std::sync::{Arc, RwLock};
use std::sync::atomic::{AtomicBool, Ordering};use tempdir::TempDir;
use std::sync::atomic::{AtomicBool, Ordering};
use tempdir::TempDir;
struct Filter {
drop_called: Arc<AtomicBool>,
......
use rocksdb::{DB, Options};use tempdir::TempDir;
use rocksdb::{DB, Options};
use tempdir::TempDir;
#[test]
......@@ -22,4 +23,3 @@ fn test_log_file_opt() {
let db = DB::open(opts, path.path().to_str().unwrap()).unwrap();
drop(db);
}
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