flash_kv/
option.rs

1use lazy_static::lazy_static;
2use std::path::PathBuf;
3
4lazy_static! {
5  pub static ref DEFAULT_DIR_PATH: PathBuf = std::env::temp_dir().join("flash-kv");
6}
7
8#[derive(Debug, Clone)]
9pub struct Options {
10  // database directory
11  pub dir_path: PathBuf,
12
13  //data file size
14  pub data_file_size: u64,
15
16  // sync writes or not
17  pub sync_writes: bool,
18
19  // the number of bytes to write before sync
20  pub bytes_per_sync: usize,
21
22  // index type option
23  pub index_type: IndexType,
24
25  // use mmap or not
26  pub mmap_at_startup: bool,
27
28  // merge threshold
29  pub file_merge_threshold: f32,
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub enum IndexType {
34  /// Btree index
35  BTree,
36
37  /// SkipList index
38  SkipList,
39
40  /// B+Tree index
41  BPlusTree,
42}
43
44impl Default for Options {
45  fn default() -> Self {
46    Self {
47      dir_path: DEFAULT_DIR_PATH.clone(),
48      data_file_size: 256 * 1024 * 1024, // 256MB
49      sync_writes: false,
50      bytes_per_sync: 0,
51      index_type: IndexType::BTree,
52      mmap_at_startup: true,
53      file_merge_threshold: 0.6,
54    }
55  }
56}
57pub struct IteratorOptions {
58  pub prefix: Vec<u8>,
59  pub reverse: bool,
60}
61
62#[allow(clippy::derivable_impls)]
63impl Default for IteratorOptions {
64  fn default() -> Self {
65    Self {
66      prefix: Default::default(),
67      reverse: false,
68    }
69  }
70}
71
72pub struct WriteBatchOptions {
73  // max batch number in one batch write
74  pub max_batch_num: usize,
75
76  // when commit if sync or not
77  pub sync_writes: bool,
78}
79
80impl Default for WriteBatchOptions {
81  fn default() -> Self {
82    Self {
83      max_batch_num: 1000,
84      sync_writes: true,
85    }
86  }
87}
88
89#[derive(Debug, Clone, Copy, PartialEq, Eq)]
90pub enum IOManagerType {
91  // Standard IO file
92  StandardFileIO,
93
94  // Memory Map IO
95  MemoryMap,
96}