Skip to content

[core] Fix JDBC catalog drop, alter and create failure handling - #10270

Open
LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:m/core-093-jdbc-catalog
Open

LuciferYang wants to merge 2 commits into
apache:masterfrom
LuciferYang:m/core-093-jdbc-catalog

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Purpose

JdbcCatalog mishandled three failure paths.

  1. Cascade dropDatabaseImpl removed only the four JDBC row sets and never deleted the database directory, leaking warehouse/<db>.db/ (schema and data) and desyncing the catalog from the filesystem. Recreating the same database and table then collided with the stale schema-0. It now deletes the directory, matching FileSystemCatalog. This runs only after the dropDatabase override has already done the existence and cascade/empty checks, so the recursive delete is safe.

  2. alterDatabaseImpl did no existence check: altering a missing database with ignoreIfNotExists = false inserted a property row and returned success instead of throwing DatabaseNotExistException, and databaseExists then reported the database as present, materializing a phantom database. It now verifies existence first.

  3. createTableImplWithLock leaked the created directory when a create failed after the schema was committed to the filesystem but before the JDBC row was inserted. It now removes the directory on that path, guarded so it deletes only a directory this call created and then failed to register (a schemaCreated flag combined with the existing registered flag). A table that already exists on the filesystem but is absent from the JDBC catalog (the state repairTable recovers) is left untouched.

This closes #10269.

Tests

  • testDropDatabaseCascadeDeletesWarehouseDirectory pins that a cascade drop removes the database directory.
  • testAlterDatabaseOnMissingDatabaseThrows pins that altering a missing database throws instead of creating a phantom entry.
  • testCreateTablePreservesUnregisteredOnDiskTableOnFailure pins that a failed create does not delete a pre-existing on-disk table that is absent from the JDBC catalog, and that it stays recoverable via repairTable.

API and Format

No.

Documentation

No.

dropDatabaseImpl deleted only the JDBC row sets and left the warehouse
database directory behind, unlike the file system catalog, so after a
cascade drop re-creating the database and a same-name table failed
because the schema directory already existed. Delete the database
directory too.

alterDatabaseImpl never checked that the database exists: an ALTER on a
missing database inserted property rows, silently materializing a
phantom database. Throw DatabaseNotExistException first.

createTableImplWithLock cleaned the committed schema directory only
when insertTable returned false, but the realistic failure is the
SQLException it throws; clean the directory in the catch as well — but
only until the table row is committed, since the table keeps working
when a later step like the property sync fails.

Assisted-by: GLM-5.3
createTableImplWithLock cleaned the table directory on any pre-registration
failure. When createTable fails because an on-disk schema already exists
(table present on the file system but missing from the JDBC catalog, a state
repairTable is meant to recover), that recursively deleted the pre-existing
table's data. Guard the cleanup with a schemaCreated flag so only a directory
created by this call is removed. Add a test pinning that the pre-existing
directory survives and stays recoverable via repairTable.
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.

JDBC catalog mishandles failures in dropDatabase, alterDatabase and createTable

1 participant