Skip to content

backup: clean up BACKUP-LOCK on compaction failure - #172915

Open
shivamshaw23 wants to merge 2 commits into
cockroachdb:masterfrom
shivamshaw23:fix-172889-compaction-lock-cleanup
Open

backup: clean up BACKUP-LOCK on compaction failure#172915
shivamshaw23 wants to merge 2 commits into
cockroachdb:masterfrom
shivamshaw23:fix-172889-compaction-lock-cleanup

Conversation

@shivamshaw23

Copy link
Copy Markdown

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.

@shivamshaw23
shivamshaw23 requested a review from a team as a code owner July 29, 2026 10:29
@shivamshaw23
shivamshaw23 requested review from dt and removed request for a team July 29, 2026 10:29
@blathers-crl

blathers-crl Bot commented Jul 29, 2026

Copy link
Copy Markdown

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:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@blathers-crl blathers-crl Bot added the O-community Originated from the community label Jul 29, 2026
@shivamshaw23

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@cockroachlabs-cla-agent

cockroachlabs-cla-agent Bot commented Jul 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread pkg/backup/backup_job.go Outdated

// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dt
dt requested review from dt and kev-cao July 30, 2026 12:08
@dt

dt commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@kev-cao is this the same lock you were thinking about deprecating?

@shivamshaw23
shivamshaw23 force-pushed the fix-172889-compaction-lock-cleanup branch from e47bad7 to 98b5afc Compare July 30, 2026 12:40
@blathers-crl

blathers-crl Bot commented Jul 30, 2026

Copy link
Copy Markdown

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Comment thread pkg/backup/backup_job.go Outdated
Comment on lines +1970 to +1974
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)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@shivamshaw23
shivamshaw23 force-pushed the fix-172889-compaction-lock-cleanup branch from 98b5afc to f06e724 Compare July 31, 2026 18:37
@blathers-crl

blathers-crl Bot commented Jul 31, 2026

Copy link
Copy Markdown

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.

@shivamshaw23

Copy link
Copy Markdown
Author

Thanks for the review @kev-cao! I've updated the PR with the requested changes:

  1. Switched to using \�esteffort.Warning\ for lock deletion.
  2. Completely rewrote the datadriven test following the
    angekeys\ pattern to use \save-cluster-ts\ and properly format the decimal timestamps for the compaction start/end boundaries.
  3. Added a release note to the commit message to satisfy the bot.

Ready for another look!

@kev-cao kev-cao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@blathers-crl

blathers-crl Bot commented Aug 1, 2026

Copy link
Copy Markdown

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@shivamshaw23

Copy link
Copy Markdown
Author

Thanks for catching the CI failure. Root cause: the test used expect-pausepoint on the compact directive, which asserts that the SQL call returns a synchronous "pause point ... hit" error. But crdb_internal.backup_compaction starts an asynchronous job (via StartCompactionJobCreateAdoptableJobWithTxn) and returns immediately with the job ID, so no synchronous pausepoint error ever surfaces — hence expected pause point error.

Fixed in 84864bb: start the compaction without expect-pausepoint and instead wait for the job to reach the paused state (job tag=comp1 wait-for-state=paused) before cancelling it. This matches the async pattern already used by the rangekeys test. The pausepoint (backup_compaction.after.details_has_checkpoint) still fires after the BACKUP-LOCK is written, so cancelling from the paused state exercises the OnFailOrCancel cleanup path as intended, and the follow-up compaction (comp2) verifies the lock no longer blocks it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backup: compaction jobs are blocked by locks from failed compaction jobs

3 participants