pub struct BfTree { /* private fields */ }Expand description
The bf-tree instance
Implementations§
Source§impl BfTree
impl BfTree
Sourcepub fn recovery(
config_file: impl AsRef<Path>,
wal_file: impl AsRef<Path>,
buffer_ptr: Option<*mut u8>,
)
pub fn recovery( config_file: impl AsRef<Path>, wal_file: impl AsRef<Path>, buffer_ptr: Option<*mut u8>, )
Recovery a Bf-Tree from snapshot and WAL files. Incomplete function, internal use only
Sourcepub fn new_from_snapshot(
bf_tree_config: Config,
buffer_ptr: Option<*mut u8>,
) -> Result<Self, ConfigError>
pub fn new_from_snapshot( bf_tree_config: Config, buffer_ptr: Option<*mut u8>, ) -> Result<Self, ConfigError>
Instead of creating a new Bf-Tree instance, it loads a Bf-Tree snapshot file and resume from there.
Source§impl BfTree
impl BfTree
Sourcepub fn new(
file_path: impl AsRef<Path>,
cache_size_byte: usize,
) -> Result<Self, ConfigError>
pub fn new( file_path: impl AsRef<Path>, cache_size_byte: usize, ) -> Result<Self, ConfigError>
Create a new bf-tree instance with customized storage backend and circular buffer size
For in-memory tree, use :memory: as file path.
For cache-only tree, use :cache: as file path
For disk tree, file_path is the path to the index file
Mini page cache must be at least 8192 bytes for practical workloads.
use bf_tree::BfTree;
let tree = BfTree::new(":memory:", 8192).unwrap();Sourcepub fn new_with_config_file<P: AsRef<Path>>(
config_file_path: P,
) -> Result<Self, ConfigError>
pub fn new_with_config_file<P: AsRef<Path>>( config_file_path: P, ) -> Result<Self, ConfigError>
Create a new bf-tree instance with customized configuration based on a config file
Sourcepub fn with_config(
config: Config,
buffer_ptr: Option<*mut u8>,
) -> Result<Self, ConfigError>
pub fn with_config( config: Config, buffer_ptr: Option<*mut u8>, ) -> Result<Self, ConfigError>
Initialize the bf-tree with provided config. For advanced user only. An optional pre-allocated buffer pointer can be provided to use as the buffer pool memory.
Sourcepub fn get_buffer_metrics(&self) -> CircularBufferMetrics
pub fn get_buffer_metrics(&self) -> CircularBufferMetrics
Get the buffer metrics of the circular buffer. This is a blocking call, will stop all other buffer operations, use it wisely.
Sourcepub fn update_read_promotion_rate(&self, new_rate: usize)
pub fn update_read_promotion_rate(&self, new_rate: usize)
Chance% to promote a base read record to mini page.
Sourcepub fn insert(&self, key: &[u8], value: &[u8]) -> LeafInsertResult
pub fn insert(&self, key: &[u8], value: &[u8]) -> LeafInsertResult
Insert a key-value pair to the system, overrides existing value if present.
use bf_tree::BfTree;
use bf_tree::LeafReadResult;
let mut config = bf_tree::Config::default();
config.cb_min_record_size(4);
let tree = BfTree::with_config(config, None).unwrap();
tree.insert(b"key", b"value");
let mut buffer = [0u8; 1024];
let read_size = tree.read(b"key", &mut buffer);
assert_eq!(read_size, LeafReadResult::Found(5));
assert_eq!(&buffer[..5], b"value");Sourcepub fn read(&self, key: &[u8], out_buffer: &mut [u8]) -> LeafReadResult
pub fn read(&self, key: &[u8], out_buffer: &mut [u8]) -> LeafReadResult
Read a record from the tree. Returns the number of bytes read.
TODO: don’t panic if the out_buffer is too small, instead returns a error.
use bf_tree::BfTree;
use bf_tree::LeafReadResult;
let mut config = bf_tree::Config::default();
config.cb_min_record_size(4);
let tree = BfTree::with_config(config, None).unwrap();
tree.insert(b"key", b"value");
let mut buffer = [0u8; 1024];
let read_size = tree.read(b"key", &mut buffer);
assert_eq!(read_size, LeafReadResult::Found(5));
assert_eq!(&buffer[..5], b"value");Sourcepub fn delete(&self, key: &[u8])
pub fn delete(&self, key: &[u8])
Delete a record from the tree.
use bf_tree::BfTree;
use bf_tree::LeafReadResult;
let tree = BfTree::default();
tree.insert(b"key", b"value");
tree.delete(b"key");
let mut buffer = [0u8; 1024];
let rt = tree.read(b"key", &mut buffer);
assert_eq!(rt, LeafReadResult::Deleted);Sourcepub fn scan_with_count<'a>(
&'a self,
key: &[u8],
cnt: usize,
return_field: ScanReturnField,
) -> Result<ScanIter<'a, 'a>, ScanIterError>
pub fn scan_with_count<'a>( &'a self, key: &[u8], cnt: usize, return_field: ScanReturnField, ) -> Result<ScanIter<'a, 'a>, ScanIterError>
Scan records in the tree, with starting key and desired scan count. Returns a iterator that yields key-value pairs.
pub fn scan_with_end_key<'a>( &'a self, start_key: &[u8], end_key: &[u8], return_field: ScanReturnField, ) -> Result<ScanIter<'a, 'a>, ScanIterError>
Sourcepub fn get_metrics(&mut self) -> Option<Value>
pub fn get_metrics(&mut self) -> Option<Value>
Collect all metrics and reset the metric recorder The caller needs to ensure there are no references to the bf-tree’s metrics recorder anymore.