|
|
|
@ -26,6 +26,7 @@ use crate::{ |
|
|
|
|
WriteBatch, WriteOptions, DEFAULT_COLUMN_FAMILY_NAME, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
use crate::ffi_util::CSlice; |
|
|
|
|
use libc::{self, c_char, c_int, c_uchar, c_void, size_t}; |
|
|
|
|
use std::collections::BTreeMap; |
|
|
|
|
use std::ffi::{CStr, CString}; |
|
|
|
@ -1272,6 +1273,49 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// If the key definitely does not exist in the database, then this method
|
|
|
|
|
/// returns `(false, None)`, else `(true, None)` if it may.
|
|
|
|
|
/// If the key is found in memory, then it returns `(true, Some<CSlice>)`.
|
|
|
|
|
///
|
|
|
|
|
/// This check is potentially lighter-weight than calling `get()`. One way
|
|
|
|
|
/// to make this lighter weight is to avoid doing any IOs.
|
|
|
|
|
pub fn key_may_exist_cf_opt_value<K: AsRef<[u8]>>( |
|
|
|
|
&self, |
|
|
|
|
cf: &impl AsColumnFamilyRef, |
|
|
|
|
key: K, |
|
|
|
|
readopts: &ReadOptions, |
|
|
|
|
) -> (bool, Option<CSlice>) { |
|
|
|
|
let key = key.as_ref(); |
|
|
|
|
let mut val: *mut c_char = ptr::null_mut(); |
|
|
|
|
let mut val_len: usize = 0; |
|
|
|
|
let mut value_found: c_uchar = 0; |
|
|
|
|
let may_exists = 0 |
|
|
|
|
!= unsafe { |
|
|
|
|
ffi::rocksdb_key_may_exist_cf( |
|
|
|
|
self.inner.inner(), |
|
|
|
|
readopts.inner, |
|
|
|
|
cf.inner(), |
|
|
|
|
key.as_ptr() as *const c_char, |
|
|
|
|
key.len() as size_t, |
|
|
|
|
&mut val, /*value*/ |
|
|
|
|
&mut val_len, /*val_len*/ |
|
|
|
|
ptr::null(), /*timestamp*/ |
|
|
|
|
0, /*timestamp_len*/ |
|
|
|
|
&mut value_found, /*value_found*/ |
|
|
|
|
) |
|
|
|
|
}; |
|
|
|
|
// The value is only allocated (using malloc) and returned if it is found and
|
|
|
|
|
// value_found isn't NULL. In that case the user is responsible for freeing it.
|
|
|
|
|
if may_exists && value_found != 0 { |
|
|
|
|
( |
|
|
|
|
may_exists, |
|
|
|
|
Some(unsafe { CSlice::from_raw_parts(val, val_len) }), |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
(may_exists, None) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn create_inner_cf_handle( |
|
|
|
|
&self, |
|
|
|
|
name: impl CStrLike, |
|
|
|
|