diff --git a/core/storage/wal.rs b/core/storage/wal.rs index 2b08715af..35882bf7d 100644 --- a/core/storage/wal.rs +++ b/core/storage/wal.rs @@ -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 = { diff --git a/tests/integration/functions/test_wal_api.rs b/tests/integration/functions/test_wal_api.rs index 10185745d..a93ac05c7 100644 --- a/tests/integration/functions/test_wal_api.rs +++ b/tests/integration/functions/test_wal_api.rs @@ -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(); +}