backup: clean up BACKUP-LOCK on compaction failure - #172915
Conversation
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
I have read the CLA Document and I hereby sign the CLA |
|
|
||
| // For compaction jobs, clean up the BACKUP-LOCK file from the backup | ||
| // destination to unblock subsequent compaction attempts that may target | ||
| // the same location. Unlike regular backups where the collection is |
There was a problem hiding this comment.
unlike
I don't really follow the "unlike" framing here, since producing a backup from a compaction or from fresh KV export are both equally bound by the write-only/WORM policies enforced on the collection. Worth stating the actual reason cleanup is safe here directly instead.
There was a problem hiding this comment.
Good point, thanks. I removed the comparison to regular backups and stated the reason directly: a failed compaction does not produce a valid backup at the destination, so the stale lock only blocks subsequent compactions. Updated in 98b5afc.
|
@kev-cao is this the same lock you were thinking about deprecating? |
e47bad7 to
98b5afc
Compare
|
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
| if err := backupinfo.DeleteBackupLock( | ||
| ctx, cfg, details.URI, b.job.ID(), p.User(), | ||
| ); err != nil { | ||
| log.Dev.Warningf(ctx, "unable to delete backup lock file on compaction failure: %+v", err) | ||
| } |
There was a problem hiding this comment.
We can use besteffort.Warning here
|
|
||
| # We will trigger compaction on the backup chain we just created. | ||
| query-sql expect-pausepoint tag=compaction1 | ||
| SELECT job_id IS NOT NULL FROM [SELECT crdb_internal.backup_compaction(0, 'BACKUP INTO LATEST IN ''userfile://defaultdb.public.foo/foo''', 'userfile://defaultdb.public.foo/foo', NULL, NULL)]; |
There was a problem hiding this comment.
I don't think passing NULL for the start and end times works here, we expect decimal values. I'd recommend looking at the pkg/backup/testdata/backup-restore/rangekeys test to see how to set those times.
When a compaction job fails, the leftover BACKUP_LOCK file is now removed in OnFailOrCancel. Subsequent compactions will no longer be blocked by stale locks. Fixes cockroachdb#172889 Release note (bug fix): Fixed a bug where a failed backup compaction job would leave behind a BACKUP-LOCK file on external storage, blocking all subsequent compaction attempts to the same destination until the lock was manually removed or a new full backup started a new chain.
98b5afc to
f06e724
Compare
|
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Thanks for the review @kev-cao! I've updated the PR with the requested changes:
Ready for another look! |
kev-cao
left a comment
There was a problem hiding this comment.
Unfortunately, this still did not pass the unit tests in CI. The new datadriven test failed with error:
datadriven_test.go:548:
Error Trace: pkg/backup/datadriven_test.go:548
pkg/backup/datadriven_test.go:903
external/com_github_cockroachdb_datadriven/datadriven.go:120
external/com_github_cockroachdb_datadriven/datadriven.go:367
external/com_github_cockroachdb_datadriven/datadriven.go:373
external/com_github_cockroachdb_datadriven/datadriven.go:215
external/com_github_cockroachdb_datadriven/datadriven.go:188
external/com_github_cockroachdb_datadriven/datadriven.go:148
external/com_github_cockroachdb_datadriven/datadriven.go:119
pkg/backup/datadriven_test.go:517
bazel-out/k8-fastbuild/bin/pkg/backup/data_driven_generated_test.go:105
Error: Expected value not to be nil.
Test: TestDataDriven_compaction_failed_lock_cleanup
Messages: expected pause point error
datadriven.go:343:
fatal during /mnt/engflow/worker/work/0/exec/bazel-out/k8-fastbuild/bin/pkg/backup/backup_test_/backup_test.runfiles/com_github_cockroachdb_cockroach/pkg/backup/testdata/backup-restore/compaction-failed-lock-cleanup:55:
SELECT crdb_internal.backup_compaction(0, 'BACKUP INTO LATEST IN ''nodelocal://1/test-root/''', '/2026/07/31-185258.72', '1785523978726471839.0000000000'::DECIMAL, '1785523986667139219.0000000000'::DECIMAL);
The compaction-failed-lock-cleanup datadriven test used `expect-pausepoint` on the `compact` directive, which asserts that the SQL call returns a synchronous "pause point ... hit" error. However, crdb_internal.backup_compaction starts an asynchronous job and returns immediately with the job ID, so no such error ever surfaces. The assertion therefore failed in CI with "expected pause point error". Start the compaction without expecting a synchronous pausepoint error and instead wait for the job to reach the paused state before cancelling it, matching the async pattern already used by the rangekeys test. Release note: None Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
Thanks for catching the CI failure. Root cause: the test used Fixed in 84864bb: start the compaction without |
Fixes #172889
When a compaction job fails, the leftover BACKUP_LOCK file is now removed in OnFailOrCancel. Subsequent compactions will no longer be blocked by stale locks.