pub struct BfTree { /* private fields */ }Expand description
The bf-tree instance
Implementations§
Source§impl BfTree
impl BfTree
pub fn recovery( config_file: impl AsRef<Path>, wal_file: impl AsRef<Path>, buffer_ptr: Option<*mut u8>, )
Source§impl BfTree
impl BfTree
Sourcepub fn new(file_path: impl AsRef<Path>, cache_size_byte: usize) -> Self
pub fn new(file_path: impl AsRef<Path>, cache_size_byte: usize) -> Self
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);Sourcepub fn new_with_config_file<P: AsRef<Path>>(config_file_path: P) -> Self
pub fn new_with_config_file<P: AsRef<Path>>(config_file_path: P) -> Self
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>) -> Self
pub fn with_config(config: Config, buffer_ptr: Option<*mut u8>) -> Self
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 tree = BfTree::default();
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 tree = BfTree::default();
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<'a>(&'a self, key: &'a [u8], cnt: usize) -> ScanIter<'a, 'a>
pub fn scan<'a>(&'a self, key: &'a [u8], cnt: usize) -> ScanIter<'a, 'a>
Scan records in the tree, with starting key and desired scan count. Returns a iterator that yields key-value pairs.
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.