Repository navigation
Fixes #33741: lock the data product so a concurrent assets/add cannot orphan its edge (2.0) - #37107
Conversation
… orphan its edge (2.0) Backport of #33762. A hard delete of a data product sweeps its entity_relationship rows before deleting its own row, and writers only checked that the data product exists with a read the cache can answer, so an assets/add landing inside the delete left a HAS edge to a deleted data product. Writers now share-lock the data products an entity gains (lockExistingIds, FOR SHARE) in the same transaction as the edge insert and fail with not-found when the row is gone. On 2.0 the assets/add path is DataProductRepository.bulkAssetsOperation, which inserted edges outside any transaction; it now locks and inserts each edge inside flushInOneTransaction. A lockRowsForDelete hook runs first in both cleanup transactions (direct delete and domain cascade), and DataProductRepository locks its rows there before the relationship sweep. DataProductDeleteRaceIT holds row locks on a separate connection to fix the interleaving of delete-first, add-first (through a table PATCH on 2.0) and domain-cascade races.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved🔴 High risk · The new locks serialize data-product linking with hard deletes; transaction or lock-order problems could block requests or leave orphaned relationship edges. Backports the data product delete race fix to 2.0: writers share-lock the data product before adding edges, the assets/add path inserts edges in one transaction, and the delete takes row locks first so a concurrent assets/add can no longer orphan its relationship row. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Describe your changes:
Fixes #33741
Backport of #33762 to
2.0. Anassets/addthat lands while the same data product is being hard-deleted leaves anentity_relationshipHAS row whose data product no longer exists.Why it happens on 2.0. The delete removes the data product's relationship rows first and its own row last, in one transaction, without locking anything. On the write side,
DataProductRepository.bulkAssetsOperationchecks the data product once withfind(entityId, ALL), which can come from the cache, then callsaddRelationshipfor each asset outside any transaction; its@Transactionannotation has no effect on a repository class. An add that lands after the delete's sweep inserts its edge, and nothing removes it.What this changes (same design as #33762 on
main, plus one 2.0-only change):EntityDAO.lockExistingIds,FOR SHARE) in the same transaction as the edge insert, and fails withdataProduct … not foundwhen a row is gone. CoversupdateDataProducts(PUT/PATCH) and bothstoreDataProductspaths (create, bulk create).bulkAssetsOperationnow share-locks the data product and inserts each edge inside oneflushInOneTransaction, because on 2.0assets/adddoes not go through the asset's own PATCH as it does onmain(Fixes #34689: record every Assets tab edit on the asset as its own PATCH #35026).lockRowsForDeletehook runs first inside both cleanup transactions, a direct delete and a domain's bulk cascade.DataProductRepositorytakes the row locks there (EntityDAO.lockIdsForUpdate,SELECT … IN (…) ORDER BY id FOR UPDATE) before the sweep.With both, the two requests serialize: either the add commits first and the delete's sweep removes its edge, or the delete commits first and the add fails with not-found.
Not covered here (same as
main): input/output port edges have the same race; ghost rows that already exist are #33742.Type of change:
High-level design:
N/A — backport of #33762. The lock ordering is documented in the Javadoc of
EntityRepository#lockDataProductsand#lockRowsForDelete.Tests:
Backend integration tests
openmetadata-integration-tests/.../it/tests/DataProductDeleteRaceIT.java(ported from Fixes #33741: lock the data product so a concurrent assets/add cannot orphan its edge #33762). Each test holds a row lock on a separate connection to pause one request at a known point, waits on the database's own view of in-flight statements, and asserts on the rows left indata_product_entityandentity_relationship.assets/addnever writes the asset row, so holding that row cannot pause it), and on MySQL a waiting statement is detected throughPROCESSLIST(aFOR SHAREblocked on a row sits in statestatisticswithout aninnodb_trxLOCK WAITentry).2.0without the fix: Postgres 3 of 3, MySQL 2 of 3 (No relationship row may outlive the deleted data product ==> expected: <0> but was: <1>).DataProductDeleteRaceITDataProductDeleteRaceITDataProductDeleteRaceIT,DataProductResourceIT,DataProductDomainMigrationIT,DomainResourceIT,DomainBulkAssetsDryRunIT,DomainIsolationIT,MultiDomainHasDomainIT,BulkAssetChangeEventUserIT,EntityRelationshipCleanupIT,UnitOfWorkRollbackIT,OrphanedEntityReferenceITDataProductDeleteRaceIT,DataProductResourceIT,DomainResourceITOneTransactionFlushAtomicityITPlaywright (UI) tests
DataProducts,Domains,DataProductAndSubdomains,DomainAdvanced,DataProductDomainMigrationagainst a local server built from this branch: 102 of 103 pass. The one failure,DataProductAndSubdomains.spec.ts:353("Add assets to data product and verify count"), times out with the Add Assets modal's Save button still disabled, so it never sendsassets/add; it fails the same way against plain2.0(81ce386e08), so it is pre-existing and unrelated to this change.Manual testing performed
Covered by the race IT, which drives the real
assets/add, table PATCH, data product delete and domain hard-delete endpoints against MySQL and Postgres.UI screen recording:
Not applicable — backend-only fix.
Checklist:
Fixes <issue-number>: <short explanation>Fixes #<issue-number>above.REVIEW.md; same change as Fixes #33741: lock the data product so a concurrent assets/add cannot orphan its edge #33762, which passed its review threads.docs/decisions/record; the lock ordering is stated in the code's Javadoc.🤖 Generated with Claude Code