fix(wal): make TruncateAll early return work when AllowEmpty is true#3124
Merged
Conversation
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
The previous check (first == 0 && last == 0) only matched the AllowEmpty=false never-written case. With AllowEmpty=true, an empty WAL reports first > last, so the early return never fired and TruncateAll sent a pointless truncate request to the library. Change to first > last which correctly covers all empty states. Also remove misleading doc comment that implied TruncateAll checks AllowEmpty itself — the check is in the underlying tidwall/wal. Made-with: Cursor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3124 +/- ##
=======================================
Coverage 58.58% 58.58%
=======================================
Files 2099 2099
Lines 173525 173525
=======================================
+ Hits 101657 101659 +2
+ Misses 62805 62804 -1
+ Partials 9063 9062 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
e53b3d3 to
eec4f8a
Compare
cody-littley
approved these changes
Mar 26, 2026
yzang2019
approved these changes
Mar 26, 2026
jewei1997
pushed a commit
that referenced
this pull request
Mar 30, 2026
…3124) ## Summary - The previous `TruncateAll` early return (`first == 0 && last == 0`) only matched the `AllowEmpty=false` never-written case. With `AllowEmpty=true`, an empty WAL reports `first > last`, so the early return never fired and `TruncateAll` sent a pointless truncate request to the underlying library. - Change to `first > last` which correctly covers empty states when AllowEmpty is true, currently we don't call this when AllowEmpty is false. - Remove misleading doc comment that implied `TruncateAll` checks `AllowEmpty` itself — the check is in the underlying `tidwall/wal`. ## Test plan - `TestTruncateAllOnEmptyLog` already covers calling `TruncateAll` on an empty log with `AllowEmpty=true` — now hits the early return instead of round-tripping through `sendTruncate` - All existing WAL tests pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TruncateAllearly return (first == 0 && last == 0) only matched theAllowEmpty=falsenever-written case. WithAllowEmpty=true, an empty WAL reportsfirst > last, so the early return never fired andTruncateAllsent a pointless truncate request to the underlying library.first > lastwhich correctly covers empty states when AllowEmpty is true, currently we don't call this when AllowEmpty is false.TruncateAllchecksAllowEmptyitself — the check is in the underlyingtidwall/wal.Test plan
TestTruncateAllOnEmptyLogalready covers callingTruncateAllon an empty log withAllowEmpty=true— now hits the early return instead of round-tripping throughsendTruncate