Done
Details
Details
Assignee
Ruslan Kashapov
Ruslan Kashapov(Deactivated)Reporter
Robert Varga
Robert VargaLabels
Components
Fix versions
Priority
Created March 11, 2024 at 5:49 PM
Updated February 6, 2025 at 2:13 PM
Resolved May 14, 2024 at 11:06 AM
JournalSegmentWriter.reset() has two implementations, which are pretty much the same thing. These should be concentrated into JournalSegmentWriter itself, with proper reading callouts to the two concrete implementations – so that we have a single place maintaining the logic.
Furthermore this method serves two distinct purposes:
reset(0) is used as a magic value to indicate to go through all entries for the purposes when the file is open for the first time (see CONTROLLER-2043's final fix for details)
other invocations are coming from JournalSegmentWriter.truncate(long) and their purpose boils down to resetting the file position the the indicated entry
The first case should be a dedicated method, called from the constructor only. That method should be verifying CRC, but it should not be deserializing all entries – just the last one.
The second case should really be inlined into truncate() and should consult the index, which is guaranteed to may know where exactly the a previous entry lies – so it can rewind to that offset and only read that entry enough entries to correctly position.