diskquota/jdbc: fix renameLayer leaving TILESET.KEY stale (#1526)#1529
Open
groldan wants to merge 2 commits into
Open
diskquota/jdbc: fix renameLayer leaving TILESET.KEY stale (#1526)#1529groldan wants to merge 2 commits into
groldan wants to merge 2 commits into
Conversation
Add failsafe-driven integration tests that run the JDBCQuotaStoreTest suite against real PostgreSQL and Oracle XE via Testcontainers. Add a GitHub Actions workflow that runs them on PRs touching the diskquota module. The legacy fixture-based tests stay in place and keep skipping cleanly when no fixture file is present. The Oracle IT is @ignored for now: SERIALIZABLE transactions in JDBCQuotaStore hit ORA-08176 on freshly-indexed tables, which the Oracle-recommended retry-on-serialization-failure pattern resolves; the IT could be re-checked and enabled once retry is implemented. No production code is modified. on-behalf-of: @camptocamp <info@camptocamp.com>
…e#1526) JDBCQuotaStore.renameLayer only updated LAYER_NAME, leaving the layer-name prefix in TILESET.KEY and TILEPAGE.TILESET_ID stale - later lookups missed the row, getOrCreateTileSet inserted duplicates, and quota by id was split across two rows. The rename SQL now rewrites KEY too; ON UPDATE CASCADE on the TILEPAGE FK keeps TILESET_ID in lockstep. OracleDialect keeps the legacy behavior (no ON UPDATE CASCADE on Oracle); a follow-up will use deferrable constraints there. on-behalf-of: @camptocamp <info@camptocamp.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Renaming a layer in a deployment using the JDBC disk-quota store leaves the quota tables in a half-renamed state:
TILESET.LAYER_NAMEis updated to the new name, but the embedded layer-name prefix inTILESET.KEY(and the FK reference fromTILEPAGE.TILESET_ID) is not.The next
getTileSetByIdmisses the row,getOrCreateTileSetinserts a duplicate, and quota-by-id is split across two rows.Root cause
Full description in
Fix:
1. Rewrite
KEYin the rename SQLSQLDialect.getRenameLayerStatementnow rewrites bothLAYER_NAMEand the layer-name prefix ofKEY:SUBSTRING ... FROM POSITION(...)is standard SQL on PostgreSQL, HSQL, and H2.2.
ON UPDATE CASCADEon the TILEPAGE -> TILESET FKThe FK is now declared
REFERENCES ${schema}TILESET(KEY) ON UPDATE CASCADE ON DELETE CASCADE.TILEPAGE.TILESET_IDfollows theTILESET.KEYrewrite automatically on fresh schemas.Pre-existing installations are upgraded in place by
SQLDialect.migrateForeignKeys, invoked frominitializeTablesafterthe table-creation pass.
The migration:
DatabaseMetaData.getImportedKeys.importedKeyCascade, drops it and re-adds it with the new rule.ALTER TABLE DROP CONSTRAINTfails because the winner has already dropped it. The resultingDataAccessExceptionis caught, the live FK state is re-checked via the same metadata query, and a now-cascade FK is accepted as concurrent success rather than propagated.3. Oracle: legacy behavior preserved
Oracle does not support
ON UPDATE CASCADEon foreign keys.OracleDialectoverrides bothgetRenameLayerStatement(keeps LAYER_NAME-only) andmigrateForeignKeys(no-op). Today's behavioris preserved on that dialect - the bug remains there.
The proper Oracle-side fix is
DEFERRABLE INITIALLY IMMEDIATEon the FK plus pairedUPDATEs in aSET CONSTRAINTS ALL DEFERREDtransaction. That belongs in a follow-up fix for #1527: Oracle XE doesn't currently survive the broader SERIALIZABLE /ORA-08176issue (tracked separately), so the Oracle IT remains@Ignored.Test coverage
JDBCQuotaStoreTest.testRenameLayer/testRenameLayer2extended to assert that bothTILESET.KEYand (via cascade)TILEPAGE.TILESET_IDcarry the new layer prefix after rename. These would fail against the pre-fix single-column UPDATE by construction.New
AbstractForeignKeyMigrationTestbuilds a legacy-schema fixture by strippingON UPDATE CASCADEfrom the dialect's own DDL, then verifies three paths:migrateAddsOnUpdateCascadeToTilepageForeignKey- legacy FK upgraded to cascade.migrateIsIdempotent- second call is a no-op.migrateIsConcurrentStartupSafe- multiple threads withCyclicBarrier, must return cleanly and the FK must end cascade.Without the recheck-on-failure step in
upgradeTilepageForeignKey, the concurrent test fails on both HSQL (user lacks privilege or object not found: SYS_FK_NNNN) and PostgreSQL (constraint "tilepage_tileset_id_fkey" of relation "tilepage" does not exist).Runs on
HSQLForeignKeyMigrationTest(surefire) andPostgreSQLForeignKeyMigrationIT(failsafe under-Ponline).Affected versions
Present on
main(GeoWebCache 2.x) and the1.28.xseries. Suggested backport target:1.28.x.Out of scope:
Requires:
Fixes: