Skip to content

Deleted rows stay deleted after a restart - #143

Merged
austin-barrington merged 1 commit into
mainfrom
fix/delete-survives-restart
Nov 28, 2026
Merged

austin-barrington merged 1 commit into
mainfrom
fix/delete-survives-restart

Conversation

@austin-barrington

Copy link
Copy Markdown
Member

Rows a DELETE removed no longer come back when a node restarts.

Bug

Since #132, DELETE removes rows from chDB. A restarted node flushes the WAL entries it kept behind its last flush again; they are kept on purpose, for chDB parts the OS had not written back. Those entries put the deleted rows back. Found by the n3 e2e of the stack: rows every pod had confirmed deleted reappeared after pod 1 restarted.

Fix

  • Each row delete keeps a marker in wal_meta: the table, the predicate, and how far the WAL was flushed when the delete ran (DeleteMarker, WalPort::record_delete).
  • On restart the flush service replays the markers kept from before the WAL was opened. A replay chunk stops at the next marker, the delete runs again once the entries before it are flushed again, and the entries after it, written after the delete, are flushed on top.
  • A marker is dropped when the WAL is truncated past it. Markers recorded by the running process are never replayed, so a DELETE that Raft applies on startup, before the flush service exists, isn't mistaken for an old one.
  • A replayed delete that fails stops the flush and is retried on the next one. One that names a column the table no longer has is skipped with a warning.
  • docs/user-guide/basic-operations.md described DELETE as tombstones. It now describes row deletes, the restart replay, and the gap below.

Not fixed

Only restarts are covered, as agreed. In a cluster, a write that reaches a replica after the replica applied the DELETE (replication queue, hinted handoff) is still not removed. A DELETE that times out waiting for the restart replay (15 s) can also miss rows the replay puts back afterwards.

Tests

  • deleted_rows_stay_deleted_after_a_restart_reflushes_the_wal, compat with chDB. The WAL is closed and reopened (TestContext::reopen_wal). Before the fix it returned [1.0, 2.0] (expected [2.0]).
  • a_row_written_after_a_delete_survives_the_restart_reflush: before the fix [1.0, 2.0, 3.0]. With the replay but without stopping chunks at markers, [2.0]: the later row was lost.
  • delete_markers_outlive_a_reopen_until_truncated_past, RocksDB unit test: markers survive a reopen, are dropped only once truncation passes them, and ones recorded since the open are not replayed.
  • Turning off marker recording or pruning makes each test fail.
  • Local gate: fmt, clippy, lib, integration and CLI tests pass.

@cursor

cursor Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes WAL truncation, flush ordering, and delete replay on a core durability path; mis-ordering could affect row visibility, though behavior is heavily tested.

Overview
Fixes deleted rows reappearing when a node restarts and re-flushes retained WAL entries into chDB.

DELETE + durability: Each delete now persists a DeleteMarker in RocksDB wal_meta (predicate + WAL flushed_through). delete_flushed_rows performs the row delete and calls WalPort::record_delete; markers are removed when truncation passes their sequence.

Flush replay: On startup, FlushServiceImpl loads markers from WalPort::delete_markers and, during flush, re-applies deletes once WAL entries up to each marker’s flushed_through are written again. Flush windows are capped at the next pending marker so writes after the original delete still flush on top.

Wiring: BatchingWal delegates marker APIs to RocksDbWal; multi-measurement DROP SERIES waits for flush only on the first delete, then uses delete_flushed_rows. User docs now describe row deletes, WAL wait, and restart replay (not tombstones).

Integration tests cover reopen_wal, post-delete writes, and marker lifecycle.

Reviewed by Cursor Bugbot for commit 23980c0. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 23980c0. Configure here.

}
}

self.replay_deletes_through(cursor).await?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Markers dropped before replay completes

High Severity

A restart reflush writes deleted rows back, then truncate_before drops the DeleteMarker from wal_meta as soon as those WAL entries are gone. The matching replay_deletes_through runs only after that truncate. If replay fails, or the process dies in between, the durable marker is already gone and the restored rows stay. On restart flushed_margin_start returns the chunk end because sizes is empty, so this drop happens on the first reflush.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 23980c0. Configure here.

@austin-barrington
austin-barrington force-pushed the fix/delete-survives-restart branch from 23980c0 to ae78d75 Compare November 28, 2026 01:19
@austin-barrington
austin-barrington changed the base branch from fix/drop-series-replicas to main November 28, 2026 01:19

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not approved. Cursor Bugbot reported one unresolved high-severity finding on delete-marker replay after restart, so human review is needed and no reviewers were assigned. CI checks on this head passed.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Router and Approver

@austin-barrington
austin-barrington force-pushed the fix/delete-survives-restart branch from ae78d75 to a7f0614 Compare November 28, 2026 01:59
@austin-barrington
austin-barrington merged commit 5caa63d into main Nov 28, 2026
2 checks passed
A restarted node flushes the WAL entries kept behind its last flush again,
which put back rows a DELETE had removed. Each row delete now keeps a
marker of how far the WAL was flushed; a restart replays the markers kept
from before the WAL opened, at that point in the WAL, and drops them once
the WAL is truncated past it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant