Skip to content

feat(master): auto-sweep MergeWal from pending WAL generations - #162

Merged
beinan merged 1 commit into
mainfrom
feat/master-auto-merge-wal
Jul 21, 2026
Merged

feat(master): auto-sweep MergeWal from pending WAL generations#162
beinan merged 1 commit into
mainfrom
feat/master-auto-merge-wal

Conversation

@beinan

@beinan beinan commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Master now runs a second periodic sweep that auto-enqueues MergeWal tasks, so MemWAL merge no longer depends on someone clicking the UI "Merge WAL"/"Optimize" button.
  • Each sweep reads the periodically-scanned stats table and enqueues a MergeWal for every experiment whose pending_wal_generations >= MERGE_WAL_MIN_GENERATIONS, reusing the existing run_merge_wal fan-out to WORKER_ENDPOINTS (each worker folds its own shard).
  • Depless MergeWal now de-dupes (via should_dedupe) so a slow broadcast is not re-queued by the next sweep; the Optimize chain's dependent MergeWal (has depends_on) is unaffected.

Why

Before this, of the three merge trigger paths only the manual UI button actually fired MergeWal: the master auto-sweep only enqueued Compact, and the data-plane local triggers (ROLLOUT_MERGE_AFTER_GENERATIONS / ROLLOUT_CLEANUP_INTERVAL_SECS) default to off. This gives the master a single, evolvable place to drive WAL merge automatically.

Config

  • MERGE_WAL_INTERVAL_SECS (default 600, 0 disables)
  • MERGE_WAL_MIN_GENERATIONS (default 8)

Correctness

  • Merge still runs on the shard-owning worker (cleanup_own_shard); master is only the trigger, so no live writer is fenced.
  • Multi-replica safe: sweep holds a dedicated merge-wal-sweep coordination lock, mirroring the compaction sweep.
  • Idempotent + at-least-once: duplicate triggers are harmless (reclaimed=0 when nothing pending); de-dup just avoids waste.
  • Candidate data lags at most one STATS_SCAN_INTERVAL_SECS; acceptable for background convergence.

Test plan

  • cargo check / cargo clippy -p lance-context-master --all-targets clean
  • cargo test -p lance-context-master (new sweep_merge_wal_enqueues_over_threshold_and_dedupes is etcd-gated like the other sweep/dedupe tests)
  • Manual e2e: master + 2 workers, write to build pending generations, wait one sweep interval, observe "auto merge-wal sweep queued" and pending_wal_generations dropping.

Follow-up (not in this PR)

Smarter per-worker targeting (introspection endpoint + endpoint→shard routing) instead of global-count broadcast.

🤖 Generated with Claude Code

Previously MemWAL merge only fired via the manual "Merge WAL"/"Optimize"
UI buttons — the master's periodic sweep only enqueued Compact, and the
data-plane's local merge triggers default to off. Add a second periodic
sweep that enqueues a MergeWal task for every experiment whose scanned
pending_wal_generations crosses MERGE_WAL_MIN_GENERATIONS, reusing the
existing fan-out to worker endpoints. Depless MergeWal now de-dupes so a
slow broadcast is not re-queued.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@beinan
beinan merged commit f8be598 into main Jul 21, 2026
9 checks passed
@beinan
beinan deleted the feat/master-auto-merge-wal branch July 21, 2026 17:47
beinan added a commit that referenced this pull request Jul 22, 2026
## Summary
- `RolloutStore::spawn_periodic_cleanup` and its `cleanup_interval_secs`
option/field had **no production caller**. WAL merge is driven by two
live paths instead: the server's process-wide `spawn_global_sweeper` and
the master's fan-out `MergeWal` sweep (#162), both calling
`cleanup_own_shard` directly.
- Removes the per-store timer, its
`RolloutStoreOptions.cleanup_interval_secs` option and the store field,
the two dead tests, and stale doc/comment references. This eliminates a
confusing third WAL-scheduling path.
- The **server-level** `rollout_cleanup_interval_secs` (which drives the
active global sweeper) is retained unchanged.

Net: 5 insertions, 220 deletions.

## Test plan
- [x] `cargo build -p lance-context-core -p lance-context-server -p
lance-context`
- [x] `cargo test -p lance-context-core rollout` (27 passed)
- [x] `cargo clippy` clean on all three crates
- [x] `cargo fmt --all`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4 <noreply@anthropic.com>
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.

1 participant