fix bug - continue checkpoint as usual even if frames range is degenerate

This commit is contained in:
Nikita Sivukhin
2025-08-21 17:37:19 +04:00
parent c34d884b6e
commit d7e47c1268
2 changed files with 48 additions and 15 deletions

View File

@@ -1552,21 +1552,6 @@ impl WalFile {
max_frame = max_frame.min(upper_bound);
}
if max_frame <= nbackfills {
tracing::debug!(
"no need in checkpoint: max_frame={}, nbackfills={}, prev={:?}",
max_frame,
nbackfills,
self.prev_checkpoint
);
return Ok(IOResult::Done(CheckpointResult {
num_attempted: self.prev_checkpoint.num_attempted,
num_backfilled: self.prev_checkpoint.num_backfilled,
max_frame: nbackfills,
maybe_guard: None,
}));
}
self.ongoing_checkpoint.max_frame = max_frame;
self.ongoing_checkpoint.min_frame = nbackfills + 1;
let to_checkpoint = {

View File

@@ -540,6 +540,9 @@ fn test_wal_upper_bound_truncate() {
writer.checkpoint(mode).err().unwrap(),
LimboError::Busy
));
writer
.execute("insert into test values (3, 'final')")
.unwrap();
}
#[test]
@@ -579,3 +582,48 @@ fn test_wal_state_checkpoint_seq() {
}
);
}
#[test]
fn test_wal_checkpoint_no_work() {
let db = TempDatabase::new_empty(false);
let writer = db.connect_limbo();
let reader = db.connect_limbo();
writer
.execute("create table test(id integer primary key, value text)")
.unwrap();
// open read txn in order to hold early WAL frames and prevent them from checkpoint
reader.execute("BEGIN").unwrap();
reader.execute("SELECT * FROM test").unwrap();
writer
.execute("insert into test values (1, 'hello')")
.unwrap();
writer
.execute("insert into test values (2, 'turso')")
.unwrap();
writer
.checkpoint(CheckpointMode::Passive {
upper_bound_inclusive: None,
})
.unwrap();
assert!(writer
.checkpoint(CheckpointMode::Truncate {
upper_bound_inclusive: None,
})
.is_err());
writer
.execute("insert into test values (3, 'limbo')")
.unwrap();
let state = writer.wal_state().unwrap();
assert_eq!(
state,
WalState {
checkpoint_seq_no: 0,
max_frame: 5
}
);
reader.execute("SELECT * FROM test").unwrap();
}