Repository navigation
Release stale compaction claims by heartbeat, not claim time - #23
Merged
Merged
Conversation
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>
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.
Problem
When a compactor dies mid-batch, its
COMPACTINGrows stay claimed for 24 hours after the claim.compact_stale_at <= now - staleAfter.compact_stale_atwasLEAST(heartbeat, compacting_at), which is always the claim time, so heartbeats never moved it.staleAfterwas the compact window, 24h by default.While a dead worker holds a row,
COMPACT_READYartifacts 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
compact_stale_atto the heartbeat time. A row written outside a heartbeat usesupdated_at, falling back tocompacting_at.COMPACTINGrows whose last heartbeat is more than 5 minutes old (compactLeaseTimeout). Workers heartbeat every 5 seconds, so that is 60 missed heartbeats.rewrite-flow.md,postgres.mdandoperations.mddescribe the new lease.Warning
Deploy all workers together, as
deployment.mdalready 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 ./...andgo vetoncmd/...andinternal/state/...pass locally.TestPostgresCompactLeaseFollowsHeartbeat: claim at T, heartbeat at T+1h. The row is kept at T+1h4m and released at T+1h5m. Onmainthe row is released at T+1h4m.assertSchedulingColumnsnow expectscompact_stale_atto equalupdated_at, falling back tocompacting_at.go test ./...(needs Postgres) and./e2e/run.sh. CI runs both.🤖 Generated with Claude Code