Skip to content

Fixes #38355: wrap Data Product bulk ports writes in a real transaction - #38392

Merged
yan-3005 merged 4 commits into
mainfrom
detail/bug-fix/fixes-38355-wrap-data-product-bulk-ports-writes-in-04586d
Nov 23, 2026
Merged

yan-3005 merged 4 commits into
mainfrom
detail/bug-fix/fixes-38355-wrap-data-product-bulk-ports-writes-in-04586d

Conversation

@detail-app

@detail-app detail-app Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Detail bug report: View on Detail

Describe your changes:

Fixes #38355

I worked on the Data Product bulk input/output port APIs (PUT /v1/dataProducts/{id|name}/{inputPorts|outputPorts}/{add|remove}) because a mid-flow failure could partially commit the batch. The private bulkPortsOperation carried @Transaction, but repositories are plain classes instantiated via reflection — not JDBI SQL-object proxies — so the annotation is inert. With no caller opening a real transaction, each on-demand DAO call in the write path (addRelationship/deleteRelationship per port, changeEventDAO().insert, storeEntity) grabbed its own connection and auto-committed. A failure on statement N+1 left the first N port relationship rows permanently persisted while the client received a 5xx with no per-row accounting — divergent port/entity-version/change-event state and no way for the caller to know what landed.

Type of change:

  • Bug fix

High-level design:

N/A — small change. The fix mirrors the established EntityRepository.restoreEntity pattern (and the approval path in ChangeApplyService.apply that already drives the same linkPorts + recordPortChange writes): drop the inert @Transaction from bulkPortsOperation and wrap each of the four public entry points (bulkAddInputPorts/bulkRemoveInputPorts/bulkAddOutputPorts/bulkRemoveOutputPorts) in executeInTransaction(() -> ...). This funnels the whole multi-statement write through one daoCollection.inTransaction scope, so relationship rows, the change-event insert, and the entity store commit or roll back together, with deadlock retry and post-commit deferral handled by executeInTransaction. A comment documents the inert-annotation pitfall, matching the convention in EntityRepository.

Tests:

Use cases covered

  • Bulk add of input ports is all-or-nothing: every eligible port lands, or none do.
  • Bulk remove of input ports is all-or-nothing: every eligible port is removed, or none are.
  • A bulk-port request blocked at the entity store mid-flow exposes zero partial port rows to a second connection (the per-port writes stay uncommitted in the one transaction).
  • The inert-@Transaction pattern is structurally rejected going forward on the bulk-ports write path.

Unit tests

  • I added unit tests for the new/changed logic.
  • Files added/updated:
    • openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/DataProductRepositoryTransactionTest.java — reflection guard asserting bulkPortsOperation is not annotated with @Transaction and the four public bulk*Ports entry points return BulkOperationResult and are not @Transaction-annotated. Prevents the inert-annotation copy-paste drift (the report notes it was copied from a 2023 inert pattern and the codebase's own warning was never propagated here) from being reintroduced.

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for new/changed API endpoints.
  • Files added/updated:
    • openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/DataProductPortsAtomicityIT.java — atomicity IT using the row-lock visibility pattern from DataProductDeleteRaceIT: holds SELECT ... FOR UPDATE on the data_product_entity row so a bulk-port request blocks at recordPortChange's storeEntity (after linkPorts has issued its per-port writes), then asserts from a second connection that zero port rows are visible while blocked (pre-fix the per-port writes auto-committed and were visible). Registered in the global-state lane via openmetadata-integration-tests/pom.xml (mirroring DataProductDeleteRaceIT's include/exclude pairs across all engine profiles).

PR checks run only the Java unit tests; the integration tests run in the merge queue and JavaUIIT / search-it nightly. For PR creation, record focused checks and list broader checks as pending. Merge readiness requires the full impacted plan. Tests are selected from .github/java-tests/impact-map.json:

make java_affected ARGS="--scope focused" # select focused checks; --scope full for merge readiness
make java_affected_run ARGS="--scope focused" # run once if no applicable evidence exists
make java_affected ARGS="--publish-results" # publish saved results without rerunning

Without gh, drop --update-pr, paste target/java-tests/local-pr-results.md between the markers, and post target/java-tests/local-pr-results-details.md as a PR comment.

  • make java_affected ARGS="--scope focused" plans the new unit test + the new DataProductPortsAtomicityIT (global-state, mysql-elasticsearch) plus the existing DataProductRepository-using unit classes.
  • mvn test -pl openmetadata-service -Dtest=DataProductRepositoryTransactionTest → 3 tests, 0 failures (BUILD SUCCESS). Verified it fails on the reverted fix (bulkPortsOperation must not carry @Transaction: expected: <false> but was: <true>), then passes again after restoring the fix.
  • mvn -pl openmetadata-service,openmetadata-integration-tests spotless:check → BUILD SUCCESS.
  • mvn test -pl openmetadata-service -Dtest='DataProductRepositoryTransactionTest,EntityRepositoryTagCacheTest,PersonaContextBuilderTest,RuleEvaluatorTest' → 83 tests, 0 failures (the focused unit set the planner selected).

Verification also ran against a real OpenMetadata Dropwizard stack on Testcontainers MySQL 8.4.13 + Elasticsearch 9.3.0:

  • DataProductResourceIT (parallel lane, mysql-elasticsearch) → 295 tests, 0 failures, 28 skipped (@Disabled system-settings rules). Covers all port endpoints happy paths and pre-flight rejections.
  • DataProductPortsAtomicityIT (global-state lane) → 2 tests, 0 failures on the fix. Verified it fails on the reverted fix exactly as the bug predicts: bulkAddInputPortsBlockedMidFlowExposesNoPartialRows expected: <0> but was: <4> (the per-port rows auto-committed while blocked) and bulkRemoveInputPortsBlockedMidFlowRemovesNoPartialRows expected: <4> but was: <0> (the per-port deletes auto-committed). Passes again after restoring the fix.
  • WorkflowDefinitionResourceIT + DataProductDeleteRaceIT (global-state lane) → 160 tests, 0 failures — approval-gated ports path and the sibling row-lock race tests, no regression.
  • DataProductDomainMigrationIT + DataProductDomainContainmentMigrationIT (parallel lane) → 13 tests, 0 failures — domain/asset port-migration paths, no regression.

Pending (run in merge-queue CI): the --scope full plan — the full impacted IT suite across mysql-elasticsearch, postgres-opensearch, cache-tests, and rdf lanes/engines. Not run here because the host has 4.8 GiB RAM and the reactor-wide recompile (-am) of the full IT set OOMs javac; the focused lane subset above covers the directly-impacted paths on the default engine. The Postgres+OpenSearch re-run of DataProductResourceIT (to confirm rollback semantics on a second DB engine) is also deferred to merge-queue CI on the same memory budget.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

End-to-end against the running server is covered by the integration tests above (the Dropwizard app started on a real port against Testcontainers MySQL+ES, and the SDK exercised the actual PUT /v1/dataProducts/.../inputPorts/add and /remove endpoints over HTTP, asserting both the BulkOperationResult response and the persisted entity_relationship/entity-version state).

UI screen recording:

Not applicable — backend-only change (no .ts/.tsx files touched).

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable).
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
  • Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under docs/decisions/ (see its README.md). This description is gone from git log after the squash-merge.

Automatic Fixes PRs can be configured here.

RetriggerView in GreptileConfidence Score: 5/5

The reviewed changes appear safe to merge.

Summary

The PR wraps all four bulk-port methods in executeInTransaction, removes the ineffective private @Transaction annotation, and registers tests that check writes from a second database connection.

  • Data Product port batches save their links and change record together.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Bulk port request] --> B[executeInTransaction]
  B --> C[Check ports and approval requirements]
  C --> D[Write relationships, change event, and entity]
  D --> E{Write succeeds?}
  E -->|Yes| F[Commit together]
  E -->|No| G[Roll back together]
Loading

Reviews (4) · Last reviewed commit: "Drop annotation-only DataProductReposito..." · Reviewed by Greptile

@detail-app
detail-app Bot requested a review from a team as a code owner November 21, 2026 04:08
@detail-app
detail-app Bot requested a review from harshach November 21, 2026 04:08
detail-app Bot and others added 2 commits November 21, 2026 06:00
Per the Java guide (no fully-qualified names in executable code), import
BulkAssets, Relationship, ChangeActor, BulkOperationResult, and Transaction
in DataProductRepositoryTransactionTest, and import Relationship in
DataProductPortsAtomicityIT. Addresses review feedback.
@yan-3005 yan-3005 added the To release Will cherry-pick this PR into the release branch label Nov 23, 2026
The three cases only reflect on @transaction annotations; two of them pass on
main without the fix, and none would catch a regression that removed the
executeInTransaction boundary. DataProductPortsAtomicityIT is the behavioural
regression: both of its cases fail on main (partial port rows visible while
the bulk add/remove is blocked) and pass with the fix.
@yan-3005

Copy link
Copy Markdown
Contributor

Verified locally (MySQL + Elasticsearch, global-state lane):

  • DataProductPortsAtomicityIT on main code: 2/2 fail. 4 input-port rows are visible while the bulk add is blocked at the entity store, and all 4 are gone while the bulk remove is blocked. So the bug is real and this IT is the regression.
  • Dropped DataProductRepositoryTransactionTest in 525a1a5. It only reflects on @Transaction annotations: 2 of its 3 cases pass on main without the fix, and none would catch the executeInTransaction boundary being removed.
  • Deadlock retry is safe: executeInTransaction rolls the attempt back and DeferralScope.reopenForAttempt() resets the deferred search/RDF/post-commit work, and the lifecycle dispatch in linkPorts goes through PostCommitActionQueue.

@yan-3005 yan-3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: DataProductPortsAtomicityIT fails 2/2 on main (partial port rows visible mid-flow) and passes 2/2 with this fix; deadlock retry replays cleanly through DeferralScope. LGTM.

@yan-3005
yan-3005 enabled auto-merge (squash) November 23, 2026 15:51
@yan-3005
yan-3005 merged commit 146d6ed into main Nov 23, 2026
56 checks passed
@yan-3005
yan-3005 deleted the detail/bug-fix/fixes-38355-wrap-data-product-bulk-ports-writes-in-04586d branch November 23, 2026 16:10
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #38515 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

yan-3005 added a commit that referenced this pull request Nov 24, 2026
…on (#38392) (#38515)

* Fixes #38355: wrap Data Product bulk ports writes in a real transaction

* Use imports instead of fully-qualified names in new tests

Per the Java guide (no fully-qualified names in executable code), import
BulkAssets, Relationship, ChangeActor, BulkOperationResult, and Transaction
in DataProductRepositoryTransactionTest, and import Relationship in
DataProductPortsAtomicityIT. Addresses review feedback.

* Drop annotation-only DataProductRepositoryTransactionTest

The three cases only reflect on @transaction annotations; two of them pass on
main without the fix, and none would catch a regression that removed the
executeInTransaction boundary. DataProductPortsAtomicityIT is the behavioural
regression: both of its cases fail on main (partial port rows visible while
the bulk add/remove is blocked) and pass with the fix.

---------




(cherry picked from commit 146d6ed)

Co-authored-by: detail-app[bot] <180357370+detail-app[bot]@users.noreply.github.com>
Co-authored-by: Ram Narayan Balaji <[email protected]>
Co-authored-by: Ram Narayan Balaji <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Data Product bulk add/remove ports can partially commit on failure (missing transaction)

3 participants