Skip to content

feat(wal): expose AllowEmpty config and add TruncateAll method#3049

Merged
wen-coding merged 2 commits intomainfrom
wen/wal-truncate-all
Mar 11, 2026
Merged

feat(wal): expose AllowEmpty config and add TruncateAll method#3049
wen-coding merged 2 commits intomainfrom
wen/wal-truncate-all

Conversation

@wen-coding
Copy link
Contributor

@wen-coding wen-coding commented Mar 11, 2026

Summary

  • Adds AllowEmpty bool to wal.Config and passes it through to tidwall/wal.Options, enabling callers to permit a fully empty log after truncation.
  • Adds TruncateAll() method to WAL[T] that removes all entries in a single call. No-ops on an already-empty log; returns an error if AllowEmpty is not set.
  • This enables the autobahn persistence layer to clear a WAL in-place (e.g. when the prune anchor advances past all persisted entries) instead of the heavier close → remove directory → reopen pattern currently used in indexedWAL.Reset().

Test plan

  • TestTruncateAll — writes entries, truncates all, verifies empty state, writes new entries, reopens and verifies continuity
  • TestTruncateAllWithoutAllowEmpty — confirms TruncateAll returns an error when AllowEmpty is not set
  • TestTruncateAllOnEmptyLog — confirms no-op on an already-empty log
  • Full existing test suite passes (29/29)

Passes tidwall/wal's AllowEmpty option through the Config struct so
callers can permit removing all entries from the log. Adds a
TruncateAll() convenience method that empties the log in one call.

This enables callers (e.g. autobahn persistence) to clear a WAL
in-place instead of the heavier close-remove-reopen pattern.

Made-with: Cursor
@wen-coding wen-coding force-pushed the wen/wal-truncate-all branch from 1ef5869 to 82877e8 Compare March 11, 2026 04:03
@github-actions
Copy link

github-actions bot commented Mar 11, 2026

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMar 11, 2026, 2:48 PM

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.36%. Comparing base (2bb2537) to head (edb4a81).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-db/wal/wal.go 50.00% 4 Missing and 4 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3049      +/-   ##
==========================================
+ Coverage   58.33%   58.36%   +0.02%     
==========================================
  Files        2079     2080       +1     
  Lines      171885   171733     -152     
==========================================
- Hits       100268   100229      -39     
+ Misses      62671    62577      -94     
+ Partials     8946     8927      -19     
Flag Coverage Δ
sei-chain-pr 67.34% <50.00%> (?)
sei-db 70.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
sei-db/wal/wal.go 68.65% <50.00%> (+0.12%) ⬆️

... and 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wen-coding wen-coding enabled auto-merge (squash) March 11, 2026 14:30
@wen-coding wen-coding merged commit 30f8b0a into main Mar 11, 2026
38 checks passed
@wen-coding wen-coding deleted the wen/wal-truncate-all branch March 11, 2026 15:01
wen-coding added a commit that referenced this pull request Mar 11, 2026
Now that sei-db/wal exposes AllowEmpty and TruncateAll (#3049), use
them to clear a WAL in-place instead of the heavier close → remove
directory → reopen pattern.

- Enable AllowEmpty in WAL config.
- Replace Reset() with TruncateAll() — single call, no dir removal.
- Remove dir/codec fields from indexedWAL (only needed for reopen).
- Eliminate firstIdx == 0 sentinel: Count() is now just nextIdx -
  firstIdx, empty when equal. Write() no longer needs the first-write
  bookkeeping branch.
- Update openIndexedWAL to handle AllowEmpty's empty-log reporting
  (first > last) uniformly with the non-empty case.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants