1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use crate::errors::Result;
use crate::iterable::Iterable;
use kvproto::import_sstpb::SstMeta;
use std::path::PathBuf;
#[derive(Clone, Debug)]
pub struct SSTMetaInfo {
pub total_bytes: u64,
pub total_kvs: u64,
pub meta: SstMeta,
}
pub trait SstExt: Sized {
type SstReader: SstReader;
type SstWriter: SstWriter;
type SstWriterBuilder: SstWriterBuilder<Self>;
}
pub trait SstReader: Iterable + Sized {
fn open(path: &str) -> Result<Self>;
fn verify_checksum(&self) -> Result<()>;
fn iter(&self) -> Self::Iterator;
}
pub trait SstWriter: Send {
type ExternalSstFileInfo: ExternalSstFileInfo;
type ExternalSstFileReader: std::io::Read;
fn put(&mut self, key: &[u8], val: &[u8]) -> Result<()>;
fn delete(&mut self, key: &[u8]) -> Result<()>;
fn file_size(&mut self) -> u64;
fn finish(self) -> Result<Self::ExternalSstFileInfo>;
fn finish_read(self) -> Result<(Self::ExternalSstFileInfo, Self::ExternalSstFileReader)>;
}
#[derive(Copy, Clone)]
pub enum SstCompressionType {
Lz4,
Snappy,
Zstd,
}
pub trait SstWriterBuilder<E>
where
E: SstExt,
{
fn new() -> Self;
fn set_db(self, db: &E) -> Self;
fn set_cf(self, cf: &str) -> Self;
fn set_in_memory(self, in_memory: bool) -> Self;
fn set_compression_type(self, compression: Option<SstCompressionType>) -> Self;
fn set_compression_level(self, level: i32) -> Self;
fn build(self, path: &str) -> Result<E::SstWriter>;
}
pub trait ExternalSstFileInfo {
fn new() -> Self;
fn file_path(&self) -> PathBuf;
fn smallest_key(&self) -> &[u8];
fn largest_key(&self) -> &[u8];
fn sequence_number(&self) -> u64;
fn file_size(&self) -> u64;
fn num_entries(&self) -> u64;
}