Skip to content

Release stale compaction claims by heartbeat, not claim time - #23

Merged
rorylshanks merged 1 commit into
mainfrom
compact-lease-heartbeat
Nov 16, 2026
Merged

rorylshanks merged 1 commit into
mainfrom
compact-lease-heartbeat

Conversation

@rorylshanks

Copy link
Copy Markdown
Collaborator

Problem

When a compactor dies mid-batch, its COMPACTING rows stay claimed for 24 hours after the claim.

  • Maintenance releases a row when compact_stale_at <= now - staleAfter.
  • compact_stale_at was LEAST(heartbeat, compacting_at), which is always the claim time, so heartbeats never moved it.
  • staleAfter was the compact window, 24h by default.

While a dead worker holds a row, COMPACT_READY artifacts in the same partition cannot be finalized, so the job cannot be imported. In a recent run, a worker stopped 15 minutes after claiming a batch. Its row and the 6 artifacts behind it waited 23h45m.

Before 16623ef the release measured from updated_at, the heartbeat, but the timeout was still the compact window.

Changes

  • Each compact heartbeat sets compact_stale_at to the heartbeat time. A row written outside a heartbeat uses updated_at, falling back to compacting_at.
  • Maintenance releases COMPACTING rows whose last heartbeat is more than 5 minutes old (compactLeaseTimeout). Workers heartbeat every 5 seconds, so that is 60 missed heartbeats.
  • The compact window still caps a live batch, through the worker's own deadline.
  • No migration. Each heartbeat rewrites the column. Existing rows still hold their claim time, so after deploy, rows from dead workers are released on the first maintenance pass.
  • Docs: rewrite-flow.md, postgres.md and operations.md describe the new lease.

Warning

Deploy all workers together, as deployment.md already requires. An old worker keeps writing its claim time, so a new worker's maintenance would release that worker's live batch after 5 minutes. The old worker's next heartbeat then either takes the row back or fails and cancels the batch.

Verification

  • go build ./... and go vet on cmd/... and internal/state/... pass locally.
  • New TestPostgresCompactLeaseFollowsHeartbeat: claim at T, heartbeat at T+1h. The row is kept at T+1h4m and released at T+1h5m. On main the row is released at T+1h4m.
  • assertSchedulingColumns now expects compact_stale_at to equal updated_at, falling back to compacting_at.
  • Not run locally: go test ./... (needs Postgres) and ./e2e/run.sh. CI runs both.

🤖 Generated with Claude Code

compact_stale_at was the claim time, so a dead compactor held its
COMPACTING rows, and blocked finalization of their partitions, until
the compact window (24h) passed since the claim. Heartbeats now move
compact_stale_at, and maintenance releases rows whose last heartbeat
is older than 5 minutes. The compact window still caps live batches
in the worker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rorylshanks
rorylshanks merged commit 44eddd3 into main Nov 16, 2026
11 checks passed
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