pub struct BitCask { /* private fields */ }Expand description
BitCask 的极简变体。BitCask 是日志结构键值引擎(如 Riak 所用)。 与其他实现生成的 BitCask 库不兼容。参见: https://riak.com/assets/bitcask-intro.pdf
BitCask 将键值对追加写入日志文件,并在内存中维护键到文件偏移的映射。 所有存活键须能装入内存。删除会向日志写入墓碑值。为清理旧垃圾 (已删除或被覆盖的键),可通过只写入存活数据的新日志来压缩,丢弃被替换的值与墓碑。
本实现比标准 BitCask 简单得多:
-
不写多个固定大小日志文件,而是使用单个任意大小的追加日志。 这会增加压缩量(每次压缩须重写整文件),也可能超过文件系统文件大小限制。 不过本库预期数据库较小。
-
压缩期间会锁住数据库的读写。可接受:仅在节点启动时压缩,且文件预期较小。
-
不使用 hint 文件,打开时扫描日志本身构建 keydir。Hint 只省略值, 而本库值预期较小,hint 几乎与压缩后的日志一样大。
-
日志条目不含时间戳或校验和。
编码后的日志条目结构:
- 键长度,大端 u32 [4 字节]。
- 值长度,大端 i32;墓碑为 -1 [4 字节]。
- 键原始字节 [<= 2 GB]。
- 值原始字节 [<= 2 GB]。
Implementations§
Trait Implementations§
Source§impl Engine for BitCask
impl Engine for BitCask
Source§type ScanIterator<'a> = ScanIterator<'a>
type ScanIterator<'a> = ScanIterator<'a>
Engine::scan 返回的迭代器类型。Source§fn scan(&mut self, range: impl RangeBounds<Vec<u8>>) -> Self::ScanIterator<'_>
fn scan(&mut self, range: impl RangeBounds<Vec<u8>>) -> Self::ScanIterator<'_>
按有序范围迭代键值对。
Source§fn scan_dyn(
&mut self,
range: (Bound<Vec<u8>>, Bound<Vec<u8>>),
) -> Box<dyn ScanIterator + '_>
fn scan_dyn( &mut self, range: (Bound<Vec<u8>>, Bound<Vec<u8>>), ) -> Box<dyn ScanIterator + '_>
与 scan 类似,但可用于 trait 对象(动态分发)。
Source§fn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>where
Self: Sized,
fn scan_prefix(&mut self, prefix: &[u8]) -> Self::ScanIterator<'_>where
Self: Sized,
迭代所有以给定前缀开头的键值对。
Auto Trait Implementations§
impl Freeze for BitCask
impl RefUnwindSafe for BitCask
impl Send for BitCask
impl Sync for BitCask
impl Unpin for BitCask
impl UnsafeUnpin for BitCask
impl UnwindSafe for BitCask
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more