|
|
@ -564,96 +564,71 @@ impl DB { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
pub fn merge_opt(&self, key: &[u8], value: &[u8], writeopts: &WriteOptions) -> Result<(), String> { |
|
|
|
|
|
|
|
|
|
|
|
impl Writable for DB { |
|
|
|
|
|
|
|
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
self.put_opt(key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn put_cf(&self, |
|
|
|
|
|
|
|
cf: DBCFHandle, |
|
|
|
|
|
|
|
key: &[u8], |
|
|
|
|
|
|
|
value: &[u8]) |
|
|
|
|
|
|
|
-> Result<(), String> { |
|
|
|
|
|
|
|
self.put_cf_opt(cf, key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn merge(&self, key: &[u8], value: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create(); |
|
|
|
|
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
rocksdb_ffi::rocksdb_merge(self.inner, |
|
|
|
rocksdb_ffi::rocksdb_merge(self.inner, |
|
|
|
writeopts.clone(), |
|
|
|
writeopts.inner, |
|
|
|
key.as_ptr(), |
|
|
|
key.as_ptr(), |
|
|
|
key.len() as size_t, |
|
|
|
key.len() as size_t, |
|
|
|
value.as_ptr(), |
|
|
|
value.as_ptr(), |
|
|
|
value.len() as size_t, |
|
|
|
value.len() as size_t, |
|
|
|
err_ptr); |
|
|
|
err_ptr); |
|
|
|
rocksdb_ffi::rocksdb_writeoptions_destroy(writeopts); |
|
|
|
|
|
|
|
if !err.is_null() { |
|
|
|
if !err.is_null() { |
|
|
|
return Err(error_message(err)); |
|
|
|
return Err(error_message(err)); |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn merge_cf_opt(&self, |
|
|
|
fn merge_cf(&self, |
|
|
|
|
|
|
|
cf: DBCFHandle, |
|
|
|
cf: DBCFHandle, |
|
|
|
key: &[u8], |
|
|
|
key: &[u8], |
|
|
|
value: &[u8]) |
|
|
|
value: &[u8], |
|
|
|
|
|
|
|
writeopts: &WriteOptions) |
|
|
|
-> Result<(), String> { |
|
|
|
-> Result<(), String> { |
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create(); |
|
|
|
|
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
rocksdb_ffi::rocksdb_merge_cf(self.inner, |
|
|
|
rocksdb_ffi::rocksdb_merge_cf(self.inner, |
|
|
|
writeopts.clone(), |
|
|
|
writeopts.inner, |
|
|
|
cf, |
|
|
|
cf, |
|
|
|
key.as_ptr(), |
|
|
|
key.as_ptr(), |
|
|
|
key.len() as size_t, |
|
|
|
key.len() as size_t, |
|
|
|
value.as_ptr(), |
|
|
|
value.as_ptr(), |
|
|
|
value.len() as size_t, |
|
|
|
value.len() as size_t, |
|
|
|
err_ptr); |
|
|
|
err_ptr); |
|
|
|
rocksdb_ffi::rocksdb_writeoptions_destroy(writeopts); |
|
|
|
|
|
|
|
if !err.is_null() { |
|
|
|
if !err.is_null() { |
|
|
|
return Err(error_message(err)); |
|
|
|
return Err(error_message(err)); |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn delete_opt(&self, key: &[u8], writeopts: &WriteOptions) -> Result<(), String> { |
|
|
|
fn delete(&self, key: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create(); |
|
|
|
|
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
rocksdb_ffi::rocksdb_delete(self.inner, |
|
|
|
rocksdb_ffi::rocksdb_delete(self.inner, |
|
|
|
writeopts.clone(), |
|
|
|
writeopts.inner, |
|
|
|
key.as_ptr(), |
|
|
|
key.as_ptr(), |
|
|
|
key.len() as size_t, |
|
|
|
key.len() as size_t, |
|
|
|
err_ptr); |
|
|
|
err_ptr); |
|
|
|
rocksdb_ffi::rocksdb_writeoptions_destroy(writeopts); |
|
|
|
|
|
|
|
if !err.is_null() { |
|
|
|
if !err.is_null() { |
|
|
|
return Err(error_message(err)); |
|
|
|
return Err(error_message(err)); |
|
|
|
} |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn delete_cf_opt(&self, cf: DBCFHandle, key: &[u8], writeopts: &WriteOptions) -> Result<(), String> { |
|
|
|
fn delete_cf(&self, cf: DBCFHandle, key: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
let writeopts = rocksdb_ffi::rocksdb_writeoptions_create(); |
|
|
|
|
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let mut err: *const i8 = 0 as *const i8; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
let err_ptr: *mut *const i8 = &mut err; |
|
|
|
rocksdb_ffi::rocksdb_delete_cf(self.inner, |
|
|
|
rocksdb_ffi::rocksdb_delete_cf(self.inner, |
|
|
|
writeopts.clone(), |
|
|
|
writeopts.inner, |
|
|
|
cf, |
|
|
|
cf, |
|
|
|
key.as_ptr(), |
|
|
|
key.as_ptr(), |
|
|
|
key.len() as size_t, |
|
|
|
key.len() as size_t, |
|
|
|
err_ptr); |
|
|
|
err_ptr); |
|
|
|
rocksdb_ffi::rocksdb_writeoptions_destroy(writeopts); |
|
|
|
|
|
|
|
if !err.is_null() { |
|
|
|
if !err.is_null() { |
|
|
|
return Err(error_message(err)); |
|
|
|
return Err(error_message(err)); |
|
|
|
} |
|
|
|
} |
|
|
@ -662,6 +637,40 @@ impl Writable for DB { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Writable for DB { |
|
|
|
|
|
|
|
fn put(&self, key: &[u8], value: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
self.put_opt(key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn put_cf(&self, |
|
|
|
|
|
|
|
cf: DBCFHandle, |
|
|
|
|
|
|
|
key: &[u8], |
|
|
|
|
|
|
|
value: &[u8]) |
|
|
|
|
|
|
|
-> Result<(), String> { |
|
|
|
|
|
|
|
self.put_cf_opt(cf, key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn merge(&self, key: &[u8], value: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
self.merge_opt(key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn merge_cf(&self, |
|
|
|
|
|
|
|
cf: DBCFHandle, |
|
|
|
|
|
|
|
key: &[u8], |
|
|
|
|
|
|
|
value: &[u8]) |
|
|
|
|
|
|
|
-> Result<(), String> { |
|
|
|
|
|
|
|
self.merge_cf_opt(cf, key, value, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn delete(&self, key: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
self.delete_opt(key, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn delete_cf(&self, cf: DBCFHandle, key: &[u8]) -> Result<(), String> { |
|
|
|
|
|
|
|
self.delete_cf_opt(cf, key, &WriteOptions::new()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl WriteBatch { |
|
|
|
impl WriteBatch { |
|
|
|
pub fn new() -> WriteBatch { |
|
|
|
pub fn new() -> WriteBatch { |
|
|
|
WriteBatch { |
|
|
|
WriteBatch { |
|
|
|