From 903ed9cebff40e389d6087b061f2311e283cb29b Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Tue, 7 Jul 2026 09:31:49 +0200 Subject: [PATCH] commitlog: Fix trim logic in stream writer (#5488) StreamWriter::create_and_metadata truncates the segment if given OnTrailingData::Trim and there is a bad commit in the existing segment. It did, however, only do that when there exists an offset index, and otherwise return the last-good metadata without actually modifying the file. --- crates/commitlog/src/stream/writer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/commitlog/src/stream/writer.rs b/crates/commitlog/src/stream/writer.rs index c7cc2ed5132..b99622b83f4 100644 --- a/crates/commitlog/src/stream/writer.rs +++ b/crates/commitlog/src/stream/writer.rs @@ -132,9 +132,9 @@ where "failed to truncate offset index for segment {last} containing trailing data: {e}" ) })?; - segment.ftruncate(sofar.tx_range.end, sofar.size_in_bytes)?; - segment.seek(io::SeekFrom::End(0))?; } + segment.ftruncate(sofar.tx_range.end, sofar.size_in_bytes)?; + segment.seek(io::SeekFrom::End(0))?; sofar } },