Repository navigation
Conversation
…a revert A same-session update that returns an entity to its previous version rewrote the entity row and then deleted that version's history row. A version bump inserts the history row and then rewrites the entity row. Taken in opposite orders, overlapping updates of one entity by the same user deadlocked. Postgres broke the cycle only after its one-second deadlock timeout, and the retry committed the two requests in the reverse of their original order. Both revert branches (storeUpdate and storeUpdateWithOptimisticLocking) now delete the history row first, so the two paths take the rows in the same order and simply queue. EntityUpdateLockOrderIT holds the history row the way a concurrent bump does and checks that the reverting update does not lock the entity row while it waits.
…r's copy After committing, every write path pushed its own serialized copy of the entity into Redis. Concurrent writers commit in one order but can finish that post-commit work in the other: the earlier committer is often still dispatching lifecycle and search work when the later one is done. So the cache could keep an older committed version until the next write or the repair pass. EventSubscriptionResourceIT's concurrent enable/disable test caught it on the Redis lane: the database held "enabled", the scheduler agreed, and the cached GET returned "disabled". A version guard cannot order the copies: a same-session revert moves both the version and updatedAt backwards. Writers now only evict, as the bulk paths already did, and only readers load entities into the cache, from the database and under the write-epoch guard. Evictions commute, so the order in which writers finish no longer matters. The JSON-capture ThreadLocal existed only to feed the write-through, so it goes too, with its unit test. EntityCacheWriteOrderIT holds one writer's post-commit actions until a second writer has committed, which replays the ordering on demand.
✅ Playwright Results — workflow succeededValidated commit ✅ 4602 passed · ❌ 0 failed · 🟡 3 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky PerformanceBlocking 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) 56m 1s ⏱️ Max setup 4m 53s · max shard execution 24m 33s · max shard-job elapsed before upload 27m 35s · reporting 1m 9s 🌐 122.00 requests/attempt · 2.24 app boots/UI scenario · 51.32% common-shard skew Optimization targets still in progress:
🟡 3 flaky test(s) (passed on retry)
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
Code Review ✅ Approved🟡 Medium risk · Repository-wide cache eviction and entity-history lock ordering change write behavior Fixes concurrent writer cache staleness and revert/bump deadlock by switching to cache-aside eviction for writers and reordering lock acquisition in same-session reverts. Adds two integration tests demonstrating the fixes; all 849 unit tests and 728 regression integration tests pass. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledOptionsDisplay: compact → Counting what did not apply, without listing it. 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 the
EventSubscriptionResourceIT.test_concurrentEnableDisableLeavesScheduleMatchingCommittedStateflake on the Redis lane. This is a test fix, so there is no linked issue and the PR carriesskip-pr-checks.The test toggles an alert on and off from two threads and checks that the scheduler agrees with the row. When it failed (job), the scheduler was right: the database ended enabled and the job was scheduled. The test's
GET, served from the entity cache, returned disabled. Two bugs combined:invalidateCachesAfterStorealready documented this race as out of scope, because a version-guarded write needs a Redis read before every write. A version guard can't work in any case: a same-session revert moves bothversionandupdatedAtbackwards.Changes:
postUpdateManynow evict the entity, as the bulk paths already did. Only readers load entities into the cache, from the database and under the existing write-epoch guard. Evictions commute, so the order writers finish in no longer matters. The JSON-capture ThreadLocal from Fixes 30008: Improve server startup and write-path latency #30009 existed only to feed the write-through, so it is removed along with its unit test.storeUpdateandstoreUpdateWithOptimisticLocking.Trade-off: the first read after a single create or update now loads from the database, not Redis. Bulk create and update already worked this way.
This overlaps with #33862, which also reorders
invalidateCachesAfterStore, so whichever lands second needs a small merge. The two are complementary: #33862 fixes the reader-side L1 load race and Redis breaker recovery; this PR fixes writer-side ordering.Type of change:
High-level design:
The cache moves to cache-aside: writers evict, readers populate.
Alternatives considered:
versionandupdatedAtare not monotonic under session consolidation.EntityCacheRepair's re-eviction 500 ms after a write. It narrows the window but still serves the older state to reads inside it, which is exactly what the failing test did.Rollout: no migration or configuration change.
Tests:
Use cases covered
Unit tests
EntityRepositoryStorageJsonReuseTestis removed with the machinery it covered.org.openmetadata.service.jdbi3.**andorg.openmetadata.service.cache.**unit tests pass: 849 tests.Backend integration tests
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/cache/EntityCacheWriteOrderIT.java(Redis profiles). It holds one writer's post-commit actions until a second writer has committed, then reads by id and by name.main: fails withexpected: <later writer> but was: <earlier writer>.openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/EntityUpdateLockOrderIT.java(all profiles). It holds the version-history row as a concurrent bump would, and requires the chart row to stay lockable (FOR UPDATE NOWAIT) while the reverting update waits.main: fails, because the revert locked the chart row.-Pcache-tests): 478 tests, 0 failures. Covers the new ITs,EventSubscriptionResourceIT,ContainerCacheCorrectnessIT,RelationshipCacheInvalidationIT,TagRenameCacheIT,OneTransactionFlushAtomicityIT,AsyncSearchIndexConsistencyIT, andChartResourceITincluding BaseEntityIT's Redis read-after-write tests.EventSubscriptionResourceIT.Ingestion integration tests
Playwright (UI) tests
Manual testing performed
main(both fail) and with the fix (both pass).mvn spotless:checkon both changed modules.UI screen recording / screenshots:
Not applicable.
Checklist:
Fixes <issue-number>: <short explanation>— not applicable: a test fix has no issue and gets a descriptive title.Fixes #<issue-number>above — not applicable: a test fix, labelledskip-pr-checks.