Commit 64bf4689 authored by Brian Anderson's avatar Brian Anderson Committed by pingcap-github-bot

Add Rc-based SstFileReader iterators (#372)

parent 531392a6
...@@ -34,6 +34,7 @@ use std::io; ...@@ -34,6 +34,7 @@ use std::io;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str::from_utf8; use std::str::from_utf8;
use std::sync::Arc; use std::sync::Arc;
use std::{fs, ptr, slice}; use std::{fs, ptr, slice};
...@@ -2143,6 +2144,27 @@ impl SstFileReader { ...@@ -2143,6 +2144,27 @@ impl SstFileReader {
} }
} }
/// Create an iterator out of a reference-counted SstFileReader.
///
/// This exists due to restrictions on lifetimes in associated types.
/// See RocksSstIterator in TiKV's engine_rocks.
pub fn iter_rc(this: Rc<Self>) -> DBIterator<Rc<Self>> {
Self::iter_opt_rc(this, ReadOptions::new())
}
pub fn iter_opt_rc(this: Rc<Self>, readopts: ReadOptions) -> DBIterator<Rc<Self>> {
unsafe {
DBIterator {
inner: crocksdb_ffi::crocksdb_sstfilereader_new_iterator(
this.inner,
readopts.get_inner(),
),
_db: this,
_readopts: readopts,
}
}
}
pub fn read_table_properties<F: FnOnce(&TableProperties)>(&self, mut action: F) { pub fn read_table_properties<F: FnOnce(&TableProperties)>(&self, mut action: F) {
extern "C" fn callback<F: FnOnce(&TableProperties)>( extern "C" fn callback<F: FnOnce(&TableProperties)>(
ctx: *mut c_void, ctx: *mut c_void,
......
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