|
|
@ -1649,9 +1649,13 @@ impl WriteBatch { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Remove database entries from start key to end key.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Removes the database entries in the range ["begin_key", "end_key"), i.e.,
|
|
|
|
|
|
|
|
/// including "begin_key" and excluding "end_key". It is not an error if no
|
|
|
|
|
|
|
|
/// keys exist in the range ["begin_key", "end_key").
|
|
|
|
pub fn delete_range<K: AsRef<[u8]>>(&mut self, start_key: K, end_key: K) -> Result<(), Error> { |
|
|
|
pub fn delete_range<K: AsRef<[u8]>>(&mut self, start_key: K, end_key: K) -> Result<(), Error> { |
|
|
|
let start_key = start_key.as_ref(); |
|
|
|
let (start_key, end_key) = (start_key.as_ref(), end_key.as_ref()); |
|
|
|
let end_key = end_key.as_ref(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
ffi::rocksdb_writebatch_delete_range( |
|
|
|
ffi::rocksdb_writebatch_delete_range( |
|
|
@ -1665,9 +1669,13 @@ impl WriteBatch { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn delete_range_cf<K: AsRef<[u8]>>(&mut self, cf: ColumnFamily, start_key: K, end_key: K) -> Result<(), Error> { |
|
|
|
pub fn delete_range_cf<K: AsRef<[u8]>>( |
|
|
|
let start_key = start_key.as_ref(); |
|
|
|
&mut self, |
|
|
|
let end_key = end_key.as_ref(); |
|
|
|
cf: ColumnFamily, |
|
|
|
|
|
|
|
start_key: K, |
|
|
|
|
|
|
|
end_key: K, |
|
|
|
|
|
|
|
) -> Result<(), Error> { |
|
|
|
|
|
|
|
let (start_key, end_key) = (start_key.as_ref(), end_key.as_ref()); |
|
|
|
|
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
ffi::rocksdb_writebatch_delete_range_cf( |
|
|
|
ffi::rocksdb_writebatch_delete_range_cf( |
|
|
@ -1978,7 +1986,9 @@ fn writebatch_works() { |
|
|
|
assert_eq!(batch.len(), 0); |
|
|
|
assert_eq!(batch.len(), 0); |
|
|
|
assert!(batch.is_empty()); |
|
|
|
assert!(batch.is_empty()); |
|
|
|
let _ = batch.put(b"k1", b"v1111"); |
|
|
|
let _ = batch.put(b"k1", b"v1111"); |
|
|
|
assert_eq!(batch.len(), 1); |
|
|
|
let _ = batch.put(b"k2", b"v2222"); |
|
|
|
|
|
|
|
let _ = batch.put(b"k3", b"v3333"); |
|
|
|
|
|
|
|
assert_eq!(batch.len(), 3); |
|
|
|
assert!(!batch.is_empty()); |
|
|
|
assert!(!batch.is_empty()); |
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
let p = db.write(batch); |
|
|
|
let p = db.write(batch); |
|
|
@ -1996,6 +2006,17 @@ fn writebatch_works() { |
|
|
|
assert!(p.is_ok()); |
|
|
|
assert!(p.is_ok()); |
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
assert!(db.get(b"k1").unwrap().is_none()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// test delete_range
|
|
|
|
|
|
|
|
let mut batch = WriteBatch::default(); |
|
|
|
|
|
|
|
let _ = batch.delete_range(b"k2", b"k4"); |
|
|
|
|
|
|
|
assert_eq!(batch.len(), 1); |
|
|
|
|
|
|
|
assert!(!batch.is_empty()); |
|
|
|
|
|
|
|
let p = db.write(batch); |
|
|
|
|
|
|
|
assert!(p.is_ok()); |
|
|
|
|
|
|
|
assert!(db.get(b"k2").unwrap().is_none()); |
|
|
|
|
|
|
|
assert!(db.get(b"k3").unwrap().is_none()); |
|
|
|
|
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
// test size_in_bytes
|
|
|
|
// test size_in_bytes
|
|
|
|
let mut batch = WriteBatch::default(); |
|
|
|
let mut batch = WriteBatch::default(); |
|
|
|