Skip to content

Commit 194c71e

Browse files
committed
Implement batched_multi_get_multi_cf_opt().
Signed-off-by: Jason Volk <jason@zemos.net>
1 parent 5e5c37c commit 194c71e

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

src/db.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1879,6 +1879,53 @@ impl<T: ThreadMode, D: DBInner> DBCommon<T, D> {
18791879
}
18801880
}
18811881

1882+
/// Return the values associated with the given keys and the specified
1883+
/// column families where internally the read requests are processed in
1884+
/// batch if block-based table SST format is used. It is a more optimized
1885+
/// version of multi_get_cf_opt, and allows for multiple column families.
1886+
pub fn batched_multi_get_multi_cf_opt<'a, C, K, I>(
1887+
&self,
1888+
keys: I,
1889+
sorted_input: bool,
1890+
readopts: &ReadOptions,
1891+
) -> impl Iterator<Item = Result<Option<DBPinnableSlice<'_>>, Error>>
1892+
where
1893+
K: AsRef<[u8]> + 'a + ?Sized,
1894+
I: IntoIterator<Item = (&'a C, &'a K)>,
1895+
C: AsColumnFamilyRef + 'a,
1896+
{
1897+
let (ptr_cfs, (ptr_keys, keys_sizes)): (Vec<_>, (Vec<_>, Vec<_>)) = keys
1898+
.into_iter()
1899+
.map(|(cf, k)| (cf.inner(), k.as_ref()))
1900+
.map(|(cf, k)| (cf, ((k.as_ptr() as *const c_char), k.len())))
1901+
.unzip();
1902+
1903+
let mut pinned_values = vec![ptr::null_mut(); ptr_keys.len()];
1904+
let mut errors = vec![ptr::null_mut(); ptr_keys.len()];
1905+
unsafe {
1906+
ffi::rocksdb_batched_multi_get_multi_cf(
1907+
self.inner.inner(),
1908+
readopts.inner,
1909+
ptr_keys.len(),
1910+
ptr_cfs.as_ptr().cast_mut(),
1911+
ptr_keys.as_ptr(),
1912+
keys_sizes.as_ptr(),
1913+
pinned_values.as_mut_ptr(),
1914+
errors.as_mut_ptr(),
1915+
sorted_input,
1916+
);
1917+
}
1918+
pinned_values
1919+
.into_iter()
1920+
.zip(errors)
1921+
.map(|(v, e)| match (v, e) {
1922+
_ if !e.is_null() => Err(convert_rocksdb_error(e)),
1923+
_ if !v.is_null() => Ok(Some(unsafe { DBPinnableSlice::from_c(v) })),
1924+
_ if v.is_null() => Ok(None),
1925+
_ => unreachable!(),
1926+
})
1927+
}
1928+
18821929
/// Returns `false` if the given key definitely doesn't exist in the database, otherwise returns
18831930
/// `true`. This function uses default `ReadOptions`.
18841931
pub fn key_may_exist<K: AsRef<[u8]>>(&self, key: K) -> bool {

0 commit comments

Comments
 (0)