Skip to content

Bound the time backup cleanup spends canceling blocked queries - #146

Open
liang8283 wants to merge 1 commit into
apache:mainfrom
liang8283:fix-cleanup-hang
Open

liang8283 wants to merge 1 commit into
apache:mainfrom
liang8283:fix-cleanup-hang

Conversation

@liang8283

Copy link
Copy Markdown
Collaborator

Change logs

When gpbackup fails or is interrupted, DoCleanup opens a new session in cancelBlockedQueries to cancel its lock-waiting queries, and only closes the connection pool afterwards. The backup transactions keep their locks until then.

The new session's queries had no time limit. With resource groups enabled, sessions queued behind the backup's locks hold the role's concurrency slots, so the cleanup session queues for a slot that is only freed once those locks are released. gpbackup then never finishes cleanup, and every session waiting on its locks, plus any new query from that role, stays queued until someone terminates them by hand.

This change:

  • Runs the whole cancel step, including the connection setup queries (which take no context), under a 20 second deadline.
  • On timeout or error, logs a warning and lets cleanup continue instead of calling gplog.FatalOnError, which used to skip the history update, helper cleanup and lock file removal. Exiting then releases the backup's locks.
  • Fixes the previous 20 second timeout, which never fired because time.After was re-created on every 500 ms tick.

Testing

  • New unit tests for the cancel logic and the deadline handling.
  • On a Cloudberry cluster with resource groups: gpbackup was blocked in LOCK TABLE, then the role's resource-group slots were filled with sessions waiting on the backup's locks, and gpbackup was interrupted with SIGINT.
    • Before: still in "Beginning cleanup" after 60 seconds, and the cluster stayed blocked for that role.
    • After: "Timed out after 20s attempting to cancel blocked queries", "Cleanup complete", gpbackup exits and the waiting sessions proceed.
    • Without slot pressure, both versions still cancel the blocked LOCK ("Canceling 1 blocked queries") and exit within a second.

When gpbackup fails or is interrupted, DoCleanup opens a new session to
cancel its queries that wait for locks, and only closes the connection
pool afterwards. Until then the backup transactions keep their locks.

The new session's queries can wait without limit. With resource groups,
sessions queued behind the backup's locks hold the role's concurrency
slots, so the cleanup session queues for a slot that is only freed once
those locks are released: gpbackup never finishes cleanup, and the
sessions waiting on its locks never run.

The cancel step now runs under a 20 second deadline, including the
connection setup queries, which take no context. On timeout or error it
logs a warning and cleanup continues, so the history entry, helper
cleanup and lock file are still handled, and exiting releases the locks.

This also fixes the previous 20 second timeout, which never fired
because time.After was re-created on every 500 ms tick, and would have
skipped the rest of cleanup through gplog.FatalOnError if it had.
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