Skip to content

Fix bug where empty leftover active segment is deleted and batch id is lost#389

Merged
CGodiksen merged 4 commits intomainfrom
bug/empty-leftover-active-segment
Mar 30, 2026
Merged

Fix bug where empty leftover active segment is deleted and batch id is lost#389
CGodiksen merged 4 commits intomainfrom
bug/empty-leftover-active-segment

Conversation

@CGodiksen
Copy link
Copy Markdown
Collaborator

This PR closes #387 by updating close_leftover_active_segment() so it returns the next batch id, determined by the leftover active segment. This fixes the bug where deleting empty leftover active segment files could make it so the WAL loses track of the next batch id, if there were no closed segments.

A unit test have been added for this specific scenario to ensure that the bug is fixed and the edge case is handled correctly.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes WAL batch-id continuity on startup when an empty leftover active segment exists and there are no closed segments, preventing batch-id reset to 0 after an unclean shutdown (closes #387).

Changes:

  • Update close_leftover_active_segment() to return the next batch id implied by the leftover active segment (Option<u64>).
  • Use the recovered next id during SegmentedLog::try_new() initialization when no closed segments exist.
  • Add a unit test covering the edge case where all closed segments were persisted/deleted and only an empty active segment remains.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@CGodiksen CGodiksen requested a review from chrthomsen March 30, 2026 10:54
@CGodiksen CGodiksen merged commit 2004734 into main Mar 30, 2026
7 of 13 checks passed
@CGodiksen CGodiksen deleted the bug/empty-leftover-active-segment branch March 30, 2026 14:09
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.

Fix edge case where empty active segment file is deleted and there are no closed segment files in WAL

4 participants