Skip to content

Commit 0d67bf4

Browse files
committed
fix: removing ctrl-c handle and verbose
1 parent 82d1b35 commit 0d67bf4

6 files changed

Lines changed: 1 addition & 177 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 92 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ hex = "0.4.3"
2121
lz4 = "1.24.0"
2222
farmhash = "1.1.5"
2323
bitvec = "1.0.1"
24-
ctrlc = {version = "3.2.3", features = ["termination"]}
2524
serde = {version = "1.0.148", features = ["derive"]}
2625
chrono = "0.4.23"

src/dustdata.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use storage::lsm;
1111
#[derive(Clone)]
1212
pub struct LsmConfig {
1313
pub flush_threshold: Size,
14-
pub detect_exit_signals: bool,
1514
}
1615

1716
/// A DustData configuration
@@ -22,7 +21,6 @@ pub struct LsmConfig {
2221
#[derive(Clone)]
2322
pub struct DustDataConfig {
2423
pub path: String,
25-
pub verbose: bool,
2624
pub lsm_config: LsmConfig,
2725
}
2826

@@ -150,16 +148,11 @@ impl DustData {
150148
pub fn new(configuration: DustDataConfig) -> Self {
151149
let path = path::Path::new(&configuration.path);
152150

153-
let mut lsm = storage::lsm::Lsm::new(lsm::LsmConfig {
154-
verbose: configuration.verbose,
151+
let lsm = storage::lsm::Lsm::new(lsm::LsmConfig {
155152
flush_threshold: size_to_usize(configuration.clone().lsm_config.flush_threshold),
156153
sstable_path: path.to_str().unwrap().to_string(),
157154
});
158155

159-
if configuration.lsm_config.detect_exit_signals {
160-
lsm.handle_ctrlc();
161-
}
162-
163156
Self {
164157
lsm,
165158
config: configuration,

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod bloom;
22
mod dustdata;
33
mod storage;
4-
mod utils;
54

65
pub use self::{
76
dustdata::DustData, dustdata::DustDataConfig, dustdata::Error, dustdata::ErrorCode,
@@ -24,10 +23,8 @@ mod dustdata_tests {
2423

2524
fn get_default_config() -> DustDataConfig {
2625
DustDataConfig {
27-
verbose: true,
2826
path: "./test_data/dustdata".to_string(),
2927
lsm_config: LsmConfig {
30-
detect_exit_signals: false,
3128
flush_threshold: Size::Megabytes(128),
3229
},
3330
}

src/storage/lsm/mod.rs

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::sync::{Arc, Mutex};
66

77
use crate::bloom::BloomFilter;
88
use crate::dustdata::{Error, ErrorCode, Result};
9-
use crate::logs;
109

1110
use self::snapshots::Snapshot;
1211

@@ -20,7 +19,6 @@ mod writer;
2019
pub struct LsmConfig {
2120
pub flush_threshold: usize,
2221
pub sstable_path: String,
23-
pub verbose: bool,
2422
}
2523

2624
#[derive(Clone)]
@@ -71,53 +69,6 @@ impl Lsm {
7169
}
7270
}
7371

74-
pub fn handle_ctrlc(&mut self) {
75-
let c_mem = Arc::clone(&self.memtable);
76-
let c_den = Arc::clone(&self.dense_index);
77-
let c_config = self.lsm_config.clone();
78-
let c_bloom = Arc::clone(&self.bloom_filter);
79-
80-
ctrlc::set_handler(move || {
81-
if c_config.verbose {
82-
logs!("Ctrl-C detected.");
83-
}
84-
85-
let memtable = c_mem.lock().unwrap();
86-
let mut dense_index = c_den.lock().unwrap();
87-
88-
if memtable.is_empty() {
89-
if c_config.verbose {
90-
logs!("No data to flush.");
91-
}
92-
93-
std::process::exit(0);
94-
}
95-
96-
if c_config.verbose {
97-
logs!("Flushing memtable to disk...");
98-
}
99-
100-
let segments =
101-
sstable::Segment::from_tree(memtable.deref(), c_config.sstable_path.as_str());
102-
103-
for token in segments.1 {
104-
dense_index.insert(token.0, token.1);
105-
}
106-
107-
let mut keys = Vec::new();
108-
109-
for segment in dense_index.deref() {
110-
keys.push(segment.0.clone());
111-
}
112-
113-
index::write_index(&c_config.sstable_path, dense_index.deref());
114-
filter::write_filter(&c_config.sstable_path, c_bloom.lock().unwrap().deref());
115-
116-
std::process::exit(0);
117-
})
118-
.ok();
119-
}
120-
12172
pub fn insert(&mut self, key: &str, value: bson::Bson) -> Result<()> {
12273
if self.contains(key) {
12374
return Err(Error {
@@ -211,10 +162,6 @@ impl Lsm {
211162
pub fn flush(&mut self) -> Result<()> {
212163
let memtable = self.get_memtable();
213164

214-
if self.lsm_config.verbose {
215-
logs!("Flushing memtable to disk...");
216-
}
217-
218165
if memtable.is_empty() {
219166
return Ok(());
220167
}
@@ -302,22 +249,10 @@ impl Drop for Lsm {
302249
let memtable = self.memtable.lock().unwrap();
303250
let mut dense_index = self.dense_index.lock().unwrap();
304251

305-
if self.lsm_config.verbose {
306-
logs!("LSM is being dropped.");
307-
}
308-
309252
if memtable.is_empty() {
310-
if self.lsm_config.verbose {
311-
logs!("No memtable to flush to disk.");
312-
}
313-
314253
return;
315254
}
316255

317-
if self.lsm_config.verbose {
318-
logs!("Flushing memtable to disk.");
319-
}
320-
321256
let segments =
322257
sstable::Segment::from_tree(memtable.deref(), self.lsm_config.sstable_path.as_str());
323258

src/utils/mod.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)