Kafka WAL: an append reported as failed may be persisted and replayed after its row sequences are reused
What type of bug is this?
Data corruption
What subsystems are affected?
Datanode
Minimal reproduce step
Not reproduced deterministically yet; the sequence below follows from the code paths named.
- A region write goes to
KafkaLogStore::append_batch, and the append returns an error although the record was persisted: either another region in the same batch failed (append_batchjoins the per-region produces withtry_join_all, so one error fails the call after other regions' records were written), or the produce timed out after the broker stored it (rskafka retries on I/O errors and timeouts without an idempotent producer,producer_id/base_sequenceare -1, so a timed-out request may be stored, possibly twice). - Mito reports the write as failed and does not advance the region's
committed_sequence(region_write_ctx.rs, thewrite_walerror path inworker/handle_write.rs), so the next write to the region reuses the same row sequences and is acknowledged. - Restart before a flush covers the later write.
What did you expect to see?
Only acknowledged writes are visible after replay.
What did you see instead?
Replay filters records only by entry_id > flushed_entry_id and re-inserts rows with the sequences recorded in the WAL; deduplication keeps the highest sequence per primary key and timestamp. The persisted-but-failed record is replayed next to the acknowledged write that reused its sequences, and the unacknowledged value can win. If the failed record landed at a higher offset than the later write (client timeout 5 s, broker timeout 30 s), a flush does not cover it either. Append-mode tables can also get duplicate rows from a retried produce.
What operating system did you use?
Any
What version of GreptimeDB did you use?
main
Relevant log output and stack trace
None. Found while reviewing the same failure mode in the object store WAL (#9320, #9334). Related observation: after replay, set_sequence_and_entry_id assigns committed_sequence from the last replayed entry rather than taking the maximum, so it can move backwards; with the experimental sequence-range incremental read of Flow, rows that replay with a sequence at or below the boundary Flow already consumed are never read by Flow.
Source: GreptimeTeam/greptimedb