Skip to content

Commit 88c6b67

Browse files
dracooooooLeslieKid
authored andcommitted
feat: Implement delete operation for WAL based on local storage (apache#1566)
## Rationale Currently the WAL based on the local disk does not support the delete function. This PR implements that functionality. This is a follow-up task of apache#1552 and apache#1556. ## Detailed Changes 1. For each `Segment`, add a hashmap to record the minimum and maximum sequence numbers of all tables within that segment. During `delete` and `write` operations, this hashmap will be updated. During read operations, logs will be filtered based on this hashmap. 2. During the `delete` operation, based on the aforementioned hashmap, if all logs of all tables in a read-only segment (a segment that is not currently being written to) are marked as deleted, the segment file will be physically deleted from the disk. ## Test Plan Unit test, TSBS and running a script locally that repeatedly inserts data, forcibly kills, and restarts the database process to test persistence.
1 parent 8cf5696 commit 88c6b67

File tree

7 files changed

+409
-172
lines changed

7 files changed

+409
-172
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analytic_engine/src/instance/write.rs

-15
Original file line numberDiff line numberDiff line change
@@ -531,21 +531,6 @@ impl<'a> Writer<'a> {
531531
e
532532
})?;
533533

534-
// When wal is disabled, there is no need to do this check.
535-
if !self.instance.disable_wal {
536-
// NOTE: Currently write wal will only increment seq by one,
537-
// this may change in future.
538-
let last_seq = table_data.last_sequence();
539-
if sequence != last_seq + 1 {
540-
warn!(
541-
"Sequence must be consecutive, table:{}, table_id:{}, last_sequence:{}, wal_sequence:{}",
542-
table_data.name,table_data.id,
543-
table_data.last_sequence(),
544-
sequence
545-
);
546-
}
547-
}
548-
549534
debug!(
550535
"Instance write finished, update sequence, table:{}, table_id:{} last_sequence:{}",
551536
table_data.name, table_data.id, sequence

src/wal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ name = "read_write"
4747
required-features = ["wal-message-queue", "wal-table-kv", "wal-rocksdb", "wal-local-storage"]
4848

4949
[dependencies]
50+
anyhow = { workspace = true }
5051
async-trait = { workspace = true }
5152
bytes_ext = { workspace = true }
5253
chrono = { workspace = true }

src/wal/src/local_storage_impl/config.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
use serde::{Deserialize, Serialize};
1919

2020
#[derive(Debug, Clone, Serialize, Deserialize)]
21+
#[serde(default)]
2122
pub struct LocalStorageConfig {
22-
pub path: String,
23-
pub max_segment_size: usize,
23+
pub data_dir: String,
24+
pub segment_size: usize,
2425
pub cache_size: usize,
2526
}
2627

2728
impl Default for LocalStorageConfig {
2829
fn default() -> Self {
2930
Self {
30-
path: "/tmp/horaedb".to_string(),
31-
max_segment_size: 64 * 1024 * 1024, // 64MB
31+
data_dir: "/tmp/horaedb".to_string(),
32+
segment_size: 64 * 1024 * 1024, // 64MB
3233
cache_size: 3,
3334
}
3435
}

0 commit comments

Comments
 (0)