Skip to content

Handle each database in its own transaction in clean - #79

Open
kakudo415 wants to merge 1 commit into
cloudspannerecosystem:masterfrom
kakudo415:clean-per-database-transaction
Open

kakudo415 wants to merge 1 commit into
cloudspannerecosystem:masterfrom
kakudo415:clean-per-database-transaction

Conversation

@kakudo415

Copy link
Copy Markdown

Problem

clean lists the target databases, drops them and deletes their metadata rows in a single read-write transaction. Dropping a database is an admin API call, so it is not rolled back when the transaction is aborted. An abort therefore leaves metadata rows for databases that no longer exist. Those rows are listed again on the next run, which tries to drop them again, and once enough rows have accumulated clean never finishes.

Changes

  • clean lists the targets in a read-only transaction and then handles each database in its own read-write transaction: re-read the row, drop the database, delete the row. A failure or abort affects only that database, and the rows of databases handled earlier are already committed.
  • Inside each transaction the row is re-read and skipped if it was removed or updated after it was listed, so a database that was taken out of the pool in the meantime is not dropped.
  • dropDatabase no longer creates an admin client on every call. It takes the admin client from the caller: Pool passes the one it already holds, and CleanAll creates one for the whole run and closes it afterwards.

The first non-NotFound error from DropDatabase still stops the run, and a NotFound is still ignored so that the row of an already dropped database is removed.

`clean` listed the target databases, dropped them and deleted their
rows in a single read-write transaction. Dropping a database is an
admin API call that is not rolled back when the transaction is
aborted, so an abort left rows for databases that no longer existed.
Those rows were listed again on the next run, which tried to drop them
again, and once enough rows had accumulated `clean` no longer finished.

`clean` now lists the targets in a read-only transaction and then
handles each database in its own read-write transaction: it re-reads
the row, drops the database and deletes the row. A failure or abort
affects only that database, and the rows of databases handled earlier
are already committed. The row is skipped if it was removed or updated
after it was listed, so a database that was taken out of the pool in
the meantime is not dropped.

`dropDatabase` created a new admin client on every call. It now takes
the admin client from the caller: `Pool` passes the one it already
holds, and `CleanAll` creates one for the whole run.
@kakudo415
kakudo415 force-pushed the clean-per-database-transaction branch 2 times, most recently from f9dfeac to 706b990 Compare September 16, 2026 08:23
@kakudo415
kakudo415 marked this pull request as ready for review September 16, 2026 08:27
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