Skip to content

Commit ebc661f

Browse files
committed
refactor: seqno map
1 parent 3f3443d commit ebc661f

4 files changed

Lines changed: 28 additions & 20 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mod keyspace;
118118
mod locked_file;
119119
mod meta_keyspace;
120120
mod path;
121-
mod poison_dart;
121+
mod poison;
122122
mod readable;
123123
mod recovery;
124124
mod snapshot;

src/recovery.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn recover_sealed_memtables(
141141
let raw_reader = JournalReader::new(journal_path)?;
142142
let reader = JournalBatchReader::new(raw_reader);
143143

144-
let mut watermarks: HashMap<InternalKeyspaceId, EvictionWatermark> = HashMap::default();
144+
let mut watermarks: HashMap<_, EvictionWatermark> = HashMap::default();
145145

146146
for batch in reader {
147147
let batch = batch?;
@@ -216,8 +216,8 @@ pub fn recover_sealed_memtables(
216216

217217
let keyspace_lsn = tree.get_highest_persisted_seqno();
218218

219-
// IMPORTANT: Only apply sealed memtables to keyspaces
220-
// that have a lower seqno to avoid double flushing
219+
// IMPORTANT: Apply the sealed memtable only if it contains data newer than the
220+
// keyspace's persisted LSN.
221221
let should_skip_sealed_memtable =
222222
keyspace_lsn.is_some_and(|keyspace_lsn| keyspace_lsn >= wm.lsn);
223223

src/supervisor.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,24 @@ impl Supervisor {
5050
pub fn new(inner: SupervisorInner) -> Self {
5151
Self(Arc::new(inner))
5252
}
53+
54+
pub fn build_seqno_map(
55+
&self,
56+
keyspaces: &Keyspaces,
57+
) -> Vec<crate::journal::manager::EvictionWatermark> {
58+
use crate::AbstractTree;
59+
60+
let mut seqnos = Vec::with_capacity(keyspaces.len());
61+
62+
for keyspace in keyspaces.values() {
63+
if let Some(lsn) = keyspace.tree.get_highest_memtable_seqno() {
64+
seqnos.push(crate::journal::manager::EvictionWatermark {
65+
lsn,
66+
keyspace: keyspace.clone(),
67+
});
68+
}
69+
}
70+
71+
seqnos
72+
}
5373
}

src/worker_pool.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
// (found in the LICENSE-* files in the repository)
44

55
use crate::{
6-
compaction::worker::run as run_compaction, flush::worker::run as run_flush,
7-
journal::manager::EvictionWatermark, poison_dart::PoisonDart, stats::Stats,
8-
supervisor::Supervisor, Keyspace,
6+
compaction::worker::run as run_compaction, flush::worker::run as run_flush, poison::PoisonDart,
7+
stats::Stats, supervisor::Supervisor, Keyspace,
98
};
10-
use lsm_tree::{AbstractTree, MemtableId};
9+
use lsm_tree::MemtableId;
1110
use std::{
1211
borrow::Cow,
1312
sync::{atomic::AtomicUsize, Arc, Mutex},
@@ -164,18 +163,7 @@ fn worker_tick(ctx: &WorkerState) -> crate::Result<bool> {
164163
#[expect(clippy::expect_used)]
165164
let keyspaces = ctx.supervisor.keyspaces.write().expect("lock is poisoned");
166165

167-
let mut seqnos = Vec::with_capacity(keyspaces.len());
168-
169-
for keyspace in keyspaces.values() {
170-
if let Some(lsn) = keyspace.tree.get_highest_memtable_seqno() {
171-
seqnos.push(EvictionWatermark {
172-
lsn,
173-
keyspace: keyspace.clone(),
174-
});
175-
}
176-
}
177-
178-
seqnos
166+
ctx.supervisor.build_seqno_map(&keyspaces)
179167
};
180168

181169
journal_manager.rotate_journal(&mut journal_writer, seqno_map)?;

0 commit comments

Comments
 (0)