Skip to content

Fixes 33358: Pin hard-delete, subtree and transaction-boundary atomicity - #33362

Merged
harshach merged 13 commits into
mainfrom
harshach/entity-atomicity-tests
Sep 27, 2026
Merged

harshach merged 13 commits into
mainfrom
harshach/entity-atomicity-tests

Conversation

@harshach

@harshach harshach commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #33358

Pins hard-delete, subtree, and transaction-boundary behavior with real SQL transaction and failure probes. The original 12 cases remain, and four workflow-cancellation cases now cover nested commit and rollback.

The failing CI lanes exposed additional races and test-load issues, fixed here:

  • Defer hard-delete workflow cancellation and negative-cache markers until the owning transaction commits. This ports the fix and four tests from stacked PR Fixes 33360: Cancel workflows and mark not-found after the owning delete commit #33365.
  • Drop a database history row if its required service relationship vanishes between the version query and hydration. A deterministic regression test failed before the guard and passes after it.
  • Evict a committed cascade's Redis entity keys together, then clear L1 and refresh repair scheduling. Set the integration server's search connection pool to the production sizes. These are the two focused commits from PR Fixes #34058: Evict a committed cascade from the cache in one step; give the IT server production's search pool #34059, now merged into main, preserved with their original authorship.
  • Run RdfLiveWriteRecoveryIT and RdfBlueGreenRebuildIT only in the existing MySQL and PostgreSQL/OpenSearch RDF lanes. The ordinary parallel lanes had been starting duplicate Fuseki and database containers; the Redis report showed 60-second graph-clear timeouts and broad request timeouts during that load.
  • Evict entity cache entries after each committed write instead of storing the writer's copy. Concurrent writers can finish their cache work out of commit order; eviction is order-independent, while write-through left an older entity in Redis. Also delete version history before rewriting the entity row during a revert so it takes locks in the same order as a version bump. These two commits come from open PR Stop concurrent writers leaving a stale entity in the cache, and fix the revert/bump deadlock #34077 and include deterministic cache-order and lock-order integration tests.

No schema or migration changes. PR #34059 has since merged to main. PR #33365 and PR #34077 remain open and overlap this branch.

Type of change:

  • Bug fix
  • Improvement

High-level design:

The atomicity tests use a Jdbi TransactionHandler decorator and a SqlLogger failure probe to assert committed and rolled-back database state. History hydration uses the existing row-by-row fallback when a required relationship disappears. Post-commit actions and cache eviction use the repository's existing deferral scope.

Tests:

  • Backend unit tests after the cache-order change: 34/34 passed across EntityRepositoryHistoryPageTest, DeferredCacheInvalidationTest, CachedEntityDaoAliasEvictionTest, and EntityRepositoryRestoreTest.
  • MySQL/Elasticsearch parallel profile: 16/16 atomicity tests passed.
  • PostgreSQL/Elasticsearch/Redis parallel profile: 17/17 passed, including RestoreHierarchyIT.asyncRestore_returns202AndRestoresFullHierarchy.
  • PostgreSQL/Elasticsearch/Redis after the cache-order change: 14/14 passed across EntityCacheWriteOrderIT, EntityUpdateLockOrderIT, EventSubscriptionResourceIT.test_concurrentEnableDisableLeavesScheduleMatchingCommittedState, RestoreHierarchyIT.asyncRestore_returns202AndRestoresFullHierarchy, and EntityHardDeletionAtomicityIT.
  • MySQL/Elasticsearch after the lock-order change: EntityUpdateLockOrderIT passed.
  • Java Spotless applied to both changed Maven modules.

Ingestion integration tests:

Not applicable.

Playwright (UI) tests:

Not applicable.

Manual testing performed:

No manual tests beyond the local unit and integration runs above.

Checklist:

Add three integration tests that pin the transactional behaviour of
EntityRepository on main using real commits counted through a delegating
Jdbi TransactionHandler and a SqlLogger-based failure probe:

- EntityTransactionBoundaryIT: nested executeInTransaction units commit
  once and publish post-commit actions after the outer commit, an outer
  failure rolls back nested writes and discards deferred actions, and
  custom-property replacement (removeExtensions + storeExtensions) keeps
  column-extension rows while committing once / rolling back together.
- EntityHardDeletionAtomicityIT: deleteInternal and bulkHardDeleteSubtree
  commit once, roll back with an enclosing transaction (rows, extension
  rows and cached existence preserved), and roll back all dependent
  metadata when the entity-row delete fails.
- EntitySubtreeAtomicityIT: bulk soft delete / restore inside an enclosing
  transaction rolls back rows and version history together.

SqlFailureProbe injects a failure once after a matching SQL statement on
the calling thread only, so background jobs are unaffected.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 15, 2026
timothybrush pushed a commit to timothybrush/OpenMetadata that referenced this pull request Sep 27, 2026
…text> (open-metadata#33642)

* Scope the JDBI test decorators on Predicate<StatementContext>

Three PRs in the open-metadata#32946 stack each carry their own copy of these decorators and
now collide with the versions open-metadata#33539 landed on main:

  CONFLICT (add/add) SqlQueryCounter.java   open-metadata#33344, open-metadata#33355
  CONFLICT (add/add) SqlFailureProbe.java   open-metadata#33362

Their copies are not gratuitous - they scope on Predicate<StatementContext>
rather than the BooleanSupplier that merged, and open-metadata#33344 and open-metadata#33355 already call
the three-argument forRequests and deadlockOnce. This makes main's copy the one
they call, so the dedup on rebase is a deletion rather than a rewrite.

Predicate<StatementContext> is also the better answer to the review on open-metadata#33539
that forRequests was too broad. A fragment alone cannot tell the request under
test apart from a concurrent one running the same SQL; the caller needs a look
at each candidate statement. SqlFailureProbe.forRequests therefore returns, but
requiring the caller's predicate rather than matching any in-flight request.

SqlFailureProbe.deadlockOnce covers open-metadata#33344's SqlQueryCounter.deadlockOnce so
EntityRepositoryGoldenIT becomes a one-line swap. Injection stays in the probe
rather than moving into the counter: a counter that also throws is two jobs in
one class, and the probe's one-shot claim is already a compareAndSet.

16 unit tests, both guards verified to fail without the code that satisfies
them - dropping the predicate gate gives "a matching statement the predicate
rejects must not be counted", and replacing the CAS with a check-then-act gives
"both threads were past the guard at once ... expected: <1> but was: <2>".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Cover the request-scoped overloads, which nothing exercised

Review feedback, and correct: forRequests was called by nothing but itself. The
unit tests injected predicates through the package-private constructor and
SqlTestDecoratorsIT only used the calling-thread ones, so the composed scope -
"a request is in flight AND the caller's predicate accepts" - was the one line
in these classes with no coverage. It is also the line where a regression is
silent: get it wrong and every REST-driven statement is rejected, or every one
is accepted, and a test supplying its own predicate would never notice.

RequestLatencyContext.startRequest and clearContext are public statics, so the
composition is testable without a server. Four tests, two per class: a matching
statement outside any request is not counted or claimed, the same statement
inside one is, and a caller predicate that rejects still wins while a request
is in flight.

Each half is independently guarded. Dropping the request check fails with "no
request in flight, so there is nothing to attribute the statement to"; dropping
the caller predicate fails with "a request is in flight but the caller's
predicate rejects this statement". Verified both ways.

20 unit tests total.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Replace deadlockOnce with a scope-free deadlock() supplier

Review follow-up from @manerow, and the trap is real. deadlockOnce built its
probe through the calling-thread constructor, while the open-metadata#33344 factory it was
meant to replace is request-scoped. Its only call site, EntityRepositoryGoldenIT,
drives a PATCH over REST, so the statement runs on a Jetty worker: a
calling-thread probe never fires, and the replay test goes green without ever
exercising the replay. Silent false pass, in the one place whose job is to prove
a deadlock is retried.

A convenience that has to guess a scope will keep guessing wrong, so there is no
longer one. deadlock() returns the failure shape DeadlockRetry replays and
composes with either scope, which makes the mistake impossible to make by
accident:

  new SqlFailureProbe(jdbi, fragment, deadlock())                      // this thread
  SqlFailureProbe.forRequests(jdbi, fragment, deadlock(), mine::match) // a request

Two claims in this PR were also wrong and are corrected in the description. The
open-metadata#33344 call site counts as well as injects - assertEquals(2, writes.count()) -
and no factory here does both, so the swap is not one line; it nests a counter
around a probe. And SqlQueryCounter.afterFirst is still not provided, so open-metadata#33344
cannot delete its copy outright either. A new test pins the nesting: the probe
sits outermost while both are open, closing it hands the logger back to the
counter rather than the application, and the chain unwinds to the original.

21 unit tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Move the composition test to the IT, where it can assert behaviour

Review feedback, and correct: assertSame on the SqlLogger chain is wiring, not
behaviour, and passes even if delegation stops invoking the inner decorator -
the one failure it needed to catch.

I had justified it by saying a real StatementContext could not be built here.
That was wrong twice over. StatementContext is not final; it has a private
constructor that reflection can reach. But the signature is not stable: this
module resolves jdbi3-core 3.37.1, whose constructor takes (ConfigRegistry,
ExtensionMethod), while 3.47.0 takes a third Type argument. A unit test built on
that would break on a minor dependency bump.

So the test moves to SqlTestDecoratorsIT, where real statements produce real
contexts and no reflection is needed. It now asserts what one statement does to
both decorators: the outer probe fires, the inner counter still sees the same
statement, and once the probe is spent the counter keeps counting through it.
The unit-level wiring assertion is deleted rather than kept alongside.

20 unit tests; the composition case runs in the IT lane.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
@harshach
harshach marked this pull request as ready for review September 27, 2026 02:35
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit a3836ca608a46f8aa8643a1f5e8e1e5611c3092b in Playwright run 36343094739, attempt 1.

✅ 4613 passed · ❌ 0 failed · 🟡 7 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 39m 42s

⏱️ Max setup 4m 28s · max shard execution 19m 47s · max shard-job elapsed before upload 25m 48s · reporting 19s

🌐 219.47 requests/attempt · 2.21 app boots/UI scenario · 39.17% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 39.17% (convergence target: at most 15%).
  • Browser traffic was 219.47 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.21 per UI scenario (10833 boots / 4903 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 66 0 0 0 0 0
✅ Shard advanced-search-02 64 0 0 0 0 0
🟡 Shard chromium-01 136 0 1 0 0 0
✅ Shard chromium-02 131 0 0 0 0 0
✅ Shard chromium-03 137 0 0 0 0 0
🟡 Shard chromium-04 118 0 2 0 0 0
✅ Shard chromium-05 158 0 0 0 0 0
✅ Shard chromium-06 174 0 0 0 0 0
✅ Shard chromium-07 131 0 0 0 0 0
✅ Shard chromium-08 170 0 0 0 0 0
🟡 Shard chromium-09 135 0 1 0 0 0
🟡 Shard chromium-10 124 0 1 0 0 0
✅ Shard chromium-11 183 0 0 0 0 0
✅ Shard chromium-12 156 0 0 0 0 0
✅ Shard chromium-13 148 0 0 0 0 0
✅ Shard chromium-14 186 0 0 0 0 0
✅ Shard chromium-15 170 0 0 0 0 0
✅ Shard chromium-16 138 0 0 0 0 0
✅ Shard chromium-17 168 0 0 0 0 0
✅ Shard chromium-18 161 0 0 0 0 0
🟡 Shard chromium-19 140 0 1 0 0 0
✅ Shard chromium-20 163 0 0 0 0 0
✅ Shard chromium-21 158 0 0 0 0 0
✅ Shard chromium-22 132 0 0 0 0 0
✅ Shard chromium-23 146 0 0 1 0 0
✅ Shard chromium-24 166 0 0 0 0 0
✅ Shard chromium-25 163 0 0 0 0 0
✅ Shard chromium-26 147 0 0 0 0 0
🟡 Shard chromium-27 104 0 1 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 87 0 0 0 0 0
✅ Shard import-export-02 63 0 0 0 0 0
✅ Shard ingestion-01 40 0 0 0 0 0
✅ Shard ingestion-02 53 0 0 0 0 0
✅ Shard reindex-01 41 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 7 flaky test(s) (passed on retry)
  • Features/ContextCenterArticles.spec.ts › Quick link card opens the configured url in a new tab (shard chromium-01, 1 retry)
  • Features/ContextCenterArticles.spec.ts › Article listing search filters, clears, and shows empty state (shard chromium-04, 1 retry)
  • Features/AccessControlSettings.spec.ts › should show all 4 landing cards and navigate to each panel (shard chromium-04, 1 retry)
  • Pages/Lineage/PlatformLineage.spec.ts › Verify Platform Lineage View (shard chromium-09, 1 retry)
  • Pages/Users.spec.ts › Admin soft & hard delete and restore user from profile page (shard chromium-10, 1 retry)
  • Features/ContextCenterArticlesFilters.spec.ts › sort options route to the correct data path (shard chromium-19, 1 retry)
  • Flow/ObservabilityAlerts.spec.ts › Ingestion Pipeline alert (shard chromium-27, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

harshach and others added 6 commits September 27, 2026 09:44
Port the fix from stacked PR #33365 onto the current retryable cleanup path. Workflow cancellation and negative-cache markers now wait for the outer transaction to commit; rollback discards both actions.
Drop a history row when its required service relationship disappears during hydration. The new regression test failed before the guard and passes after it. Run the container-heavy RDF write recovery suite only in the dedicated RDF lanes, where CI still covers both database backends.
…op L1

With the Redis cache on, an async restore of a database could leave its
schemas answering 404 right after the restore committed.
RestoreHierarchyIT.asyncRestore_returns202AndRestoresFullHierarchy failed
in 7 of the 86 postgres-elasticsearch-redis parallel-lane runs whose
commit contains #33866, and in none of the 188 without it.

Since #33866 the cascade's children leave Redis only after commit, in
drainCacheInvalidations, one entity at a time with about ten synchronous
Redis calls each. The restored root still evicts inline in EntityUpdater,
so it reads as restored the moment the transaction commits, while its
children keep serving their soft-deleted copies until the drain reaches
them. The test polls the database, then reads a schema inside that
window.

The drain now evicts the committed batch in one pass:
- it bumps every write epoch first, so a loader that read the pre-commit
  row cannot write it back after the eviction;
- it deletes every entity key (id hash, by-name and reference aliases) in
  one DEL, split only past 1,000 keys;
- it evicts L1 after that DEL, since a reader in the window copies the
  stale Redis entry into L1 and nothing evicted it after the commit;
- it re-arms EntityCacheRepair from the commit, because the repair armed
  inside the transaction fires 500 ms after that eviction, which a long
  transaction outlives.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 9ce609c)
TestSuiteBootstrap never set maxConnTotal or maxConnPerRoute, so the
in-process server ran on the schema defaults: 10 connections to the single
Elasticsearch host (30 total) instead of the 50/100 in
conf/openmetadata.yaml. Under the parallel lane that pool stayed empty
longer than connectionRequestTimeoutSecs (5 s), and requests failed with
"error while performing request", Rest5Client's wrapper for the lease
timeout. That is how SearchResourceIT.testEntityTypeCountsResponseFormat
failed in the merge queue for #33338.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 148570d)
The Redis parallel report spent 188 seconds in this container-heavy class while the dedicated RDF lanes also ran it successfully. Gate it on enableRdf like the live-write recovery suite so CI keeps coverage without competing for Redis parallel-lane resources.
@gitar-bot

gitar-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · Changes transaction boundaries for hard deletes and entity history, affecting stored-data integrity

Pins hard-delete, subtree, and transaction-boundary atomicity with real SQL transaction and failure probes across 12 test cases, including four new workflow-cancellation scenarios. Defers hard-delete side effects and cache eviction until commit, guards against vanished service relationships during history hydration, and fixes test-load issues by restricting RDF tests to dedicated lanes. All integration tests passed with no issues found.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native hard-delete, subtree and nested-transaction atomicity is unpinned

2 participants