Skip to content

Fixes 33860: evict Redis L2 after commit, not inside the write transaction - #33866

Merged
mohityadav766 merged 2 commits into
mainfrom
fix/33860-restore-cascade-partial
Sep 24, 2026
Merged

mohityadav766 merged 2 commits into
mainfrom
fix/33860-restore-cascade-partial

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #33860

A recursive soft-delete followed by a restore could silently leave part of the subtree soft-deleted,
so a plain GET on a descendant 404'd long after the restore returned 200. In the failing run, 9 of
12 tables came back and sync_schema_2.sync_table_2_1 did not — 253 ms after the restore committed,
with no error logged anywhere.

The cause is invalidation ordering, not the restore cascade. restoreEntity runs inside
executeInTransaction, and persistBulkUpdaters calls updateMany then invalidateMany while that
transaction is still open. invalidateMany → invalidate(T) → invalidateCache(T) issued the Redis
DEL inline, before the COMMIT. Any concurrent reader in that window took the resulting miss,
read the not-yet-committed row (deleted=true) and re-populated the key with it. After the commit
Redis kept serving deleted=true until TTL, and the read path turns that into a 404.

The window is the whole cascade transaction — 1 database + 3 schemas + 12 tables — not a nanosecond,
which is why it was hit often enough to evict PRs from the merge queue.

Type of change:

  • Bug fix

High-level design:

Both mechanisms needed to prevent this already existed, and both stopped one layer short:

Mechanism Gap Change
DEFERRED_CACHE_INVALIDATIONS — executeInTransaction opens the scope and drains it post-commit invalidateCacheForEntity(type,id,fqn) honours it, but invalidateCache(T) — the path every entity write actually takes — bypassed it and called the cache DAOs directly both now route through deferOrInvalidateRedisL2
EntityCacheRepair — delayed re-eviction, whose javadoc names this exact race only re-evicted the in-JVM Guava caches, never Redis L2 now re-evicts L2 as well, and returns immediately when no Redis cache is configured

invalidateRedisL2ForEntity also picked up the reference and tagUsage variants that only the
POJO path was dropping, so deferring loses no coverage — and it makes invalidateCacheForEntity
match its own javadoc claim of dropping "every cached variant".

Guava L1 eviction deliberately stays inline. It is a local map operation, not a round trip, and
keeping it immediate preserves read-your-write within the request.

Not changed: a handful of specialised paths still call the cache DAOs directly (the rename
cascade around EntityRepository:11280-11465, ContainerRepository:834). They are outside this
bug's path; worth a follow-up sweep rather than widening this PR.

Tests:

Use cases covered

  • Restoring a soft-deleted database makes every descendant reachable again, on a Redis-backed
    deployment under concurrent read load.
  • Any entity write: the L2 eviction is not observable until the writing transaction commits.

Unit tests

  • Added two cases to EntityRepositoryRestoreTest:
    • invalidateCache_insideDeferralScope_holdsRedisEvictionUntilDrain — with a scope open the Redis
      DAO is untouched; after drainCacheInvalidations() the base and by-name keys are evicted.
    • invalidateCache_withoutDeferralScope_evictsRedisImmediately — guards against the fix silently
      disabling invalidation when there is no transaction to wait for.

Verified the test actually catches the bug by reverting invalidateCache to the inline call:

[ERROR] EntityRepositoryRestoreTest.invalidateCache_insideDeferralScope_holdsRedisEvictionUntilDrain:291
[ERROR] Tests run: 19, Failures: 1

and with the fix restored:

Tests run: 19, Failures: 0, Errors: 0, Skipped: 0 -- EntityRepositoryRestoreTest

Wider unit sweep over the repository and cache packages
(-Dtest='EntityRepository*Test,*Cache*Test'):

Tests run: 191, Failures: 0, Errors: 0, Skipped: 0

Backend integration tests

  • No new endpoints. The bug surfaced through existing ITs —
    RestoreHierarchyIT.syncRestore_restoresFullHierarchy and
    TableResourceIT>BaseEntityIT.test_sdkOnlyAsyncOperations — which should stop flaking on the
    Redis lane. I could not reproduce the race deterministically on a local single-threaded run, so
    the CI Redis lane is the real signal here.

Ingestion integration tests

  • Not applicable.

Playwright (UI) tests

  • Not applicable.

Manual testing performed

Traced the failure end-to-end in the CI log for run 35744755756 (job 106804504501) by following the
failing table's UUID: created → cascade-soft-deleted (verified by the test's own include=all read)
→ database restore committed → 404. The 9 tables that returned 200 each logged
CACHE: Writing entity to Redis during the assertion loop — cache misses, served from the DB and
therefore correct. The failing one logged no such write: it was a cache hit, and the hit was stale.

UI screen recording / screenshots:

Not applicable.

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: not applicable.
  • For UI changes: not applicable.
  • I have added tests and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

🤖 Generated with Claude Code

RetriggerConfidence Score: 2/5

The PR is not safe to merge until delayed Redis repair is made post-commit-aware, covers the original rename FQN, and preserves uncached-entity exclusions.

Findings

  1. P1 Repair Can Precede Commit ▶
  2. P1 Old Rename Key Survives ▶
  3. P1 Repair Bypasses Cacheability Guard ▶
Summary

This PR routes entity-write Redis invalidations through the existing post-commit deferral mechanism and extends delayed cache repair to Redis L2.

  • Centralizes entity, reference, relationship, read-bundle, lineage, tag, and cross-node invalidation.
  • Adds unit coverage for deferred and immediate Redis eviction.
  • The new delayed Redis repair is not commit-relative, omits the original FQN during renames, and bypasses the uncached-entity guard.
Diagram
sequenceDiagram
    participant W as Writer transaction
    participant R as Concurrent reader
    participant L2 as Redis L2
    participant T as Delayed repair
    W->>T: Schedule repair (500 ms)
    T->>L2: Evict before long transaction commits
    R->>L2: Cache miss
    R->>W: Read pre-commit database state
    W-->>W: Commit
    W->>L2: Post-commit eviction
    R->>L2: Late put of stale state
    Note over T,L2: Repair already ran, so stale value survives
Loading

Reviews (1) · Last reviewed commit: "fix(cache): evict Redis L2 after commit,..."

…tion

A recursive soft-delete followed by a restore could silently leave part of
the subtree soft-deleted, so a plain GET on a descendant 404'd long after the
restore returned 200.

The cause is invalidation ordering, not the restore cascade. restoreEntity
runs inside executeInTransaction, and persistBulkUpdaters calls updateMany
then invalidateMany while that transaction is still open. invalidateMany ->
invalidate(T) -> invalidateCache(T) issued the Redis DEL inline, before the
COMMIT. Any concurrent reader in that window took the resulting miss, read
the not-yet-committed row (deleted=true) and re-populated the key with it.
After the commit Redis kept serving deleted=true until TTL.

The window is the whole cascade transaction - one database, three schemas,
twelve tables in the failing run - not a nanosecond, which is why it was hit
often enough to evict PRs from the merge queue.

Both mechanisms needed to prevent this already existed and both stopped one
layer short:

- invalidateCacheForEntity(type, id, fqn) honours DEFERRED_CACHE_INVALIDATIONS
  and lets executeInTransaction drain it post-commit. invalidateCache(T) - the
  path every entity write actually takes - bypassed the scope and called the
  cache DAOs directly. Both now go through deferOrInvalidateRedisL2.
- EntityCacheRepair exists specifically to backstop a racing loader's stale
  put, but only re-evicted the in-JVM Guava caches. It now re-evicts the
  Redis L2 too, and skips entirely when no Redis cache is configured.

invalidateRedisL2ForEntity also picked up the reference and tag-usage
variants that only the POJO path was dropping, so deferring loses no
coverage - and invalidateCacheForEntity now matches its own javadoc claim of
dropping "every cached variant".

Guava L1 eviction stays inline: it is a local map operation, not a round
trip, and keeping it immediate preserves read-your-write within the request.

Fixes #33860

Co-Authored-By: Claude Opus 5 <[email protected]>
@mohityadav766
mohityadav766 requested a review from a team as a code owner September 23, 2026 07:44
@github-actions

github-actions Bot commented Sep 23, 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 added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 23, 2026
Comment on lines +3574 to +3577
private static void deferOrInvalidateRedisL2(String entityType, UUID id, String fqn) {
if (!isCacheableEntityType(entityType)) {
return;
}

@gitar-bot gitar-bot Bot Sep 23, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Bug: Uncached types (user/domain/bot…) no longer publish cross-pod invalidation

invalidateCache(T) used to publish pub/sub for every entity type. It now goes through deferOrInvalidateRedisL2, which returns early for UNCACHED_ENTITY_TYPES (user, bot, domain, dataProduct, task, workflow*, testCaseResolutionStatus), so updates and deletes of those entities never reach peer pods. CACHE_WITH_ID/CACHE_WITH_NAME (Guava L1) still cache those types on every pod, so in a multi-pod Redis deployment the other pods keep serving stale users/domains/bots until TTL. Their remote Invalidatables also stop firing, e.g. the JwtFilter email→username cache for users and the not-found cache. UserRepository.invalidateTaskCacheForIds has a comment describing this exact gap and publishes manually to work around it. Fix: keep the isCacheableEntityType short-circuit for the Redis DELs, but still publish (deferred post-commit when a scope is open) for uncached types on the POJO write path. Or move the pubsub publish outside the cacheable gate.

Always fan out cross-pod invalidation; only gate the Redis DELs on cacheability.:

private static void deferOrInvalidateRedisL2(String entityType, UUID id, String fqn) {
  if (!isCacheableEntityType(entityType)) {
    // Peers still hold this type in Guava L1; tell them post-commit.
    PostCommitActionQueue.runOrDefer(() -> publishInvalidation(entityType, id, fqn));
    return;
  }
  Map<CacheInvalidationKey, CacheInvalidationKey> deferred = DEFERRED_CACHE_INVALIDATIONS.get();
  if (deferred != null) {
    recordCacheInvalidation(deferred, entityType, id, fqn);
  } else {
    invalidateRedisL2ForEntity(entityType, id, fqn);
  }
}

Was this helpful? React with 👍 / 👎

if (request.id() == null || CacheBundle.getCachedEntityDao() == null) {
return;
}
EntityRepository.invalidateRedisL2ForEntity(request.entityType(), request.id(), request.fqn());

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.

P1 Repair can precede commit

The 500 ms repair timer starts when invalidation is recorded inside the transaction, while the authoritative deferred invalidation runs only after commit. If a recursive restore lasts longer than 500 ms, this repair can evict Redis before commit. A concurrent reader can then load the old database state and write it back after the post-commit eviction, leaving the stale value in Redis. Start this repair from the post-commit path, or otherwise ensure its delay begins only after commit.

Knowledge Base Used: Metadata entity lifecycle

if (request.id() == null || CacheBundle.getCachedEntityDao() == null) {
return;
}
EntityRepository.invalidateRedisL2ForEntity(request.entityType(), request.id(), request.fqn());

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.

P1 Old rename key survives

The delayed Redis repair invalidates only request.fqn(), although rename requests also carry originalFqn. If a reader began loading the old name before the initial eviction and writes that entry back afterward, this delayed pass removes only the new-name key. The old alias then remains until TTL, so a lookup by the former FQN can return the renamed entity instead of not found. The Redis repair should invalidate the distinct original FQN too, as the existing L1 repair already does.

Knowledge Base Used: Metadata entity lifecycle

if (request.id() == null || CacheBundle.getCachedEntityDao() == null) {
return;
}
EntityRepository.invalidateRedisL2ForEntity(request.entityType(), request.id(), request.fqn());

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.

P1 Repair bypasses cacheability guard

This call bypasses deferOrInvalidateRedisL2 and its isCacheableEntityType guard. Because repair is scheduled before that guard, writes to deliberately uncached types such as tasks, bots, domains, and data products now perform delayed Redis deletions across every cache layer and publish cross-node invalidations. Large cascades therefore regain the Redis workload that the existing short-circuit avoids because it can push operations past their timeout budgets. Apply the same cacheability check to the delayed repair.

Knowledge Base Used: Metadata entity lifecycle

@github-actions

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 5954eef57a7bbcb42463e644c659f86809f1ea28 in Playwright run 35976899269, attempt 1.

✅ 4569 passed · ❌ 0 failed · 🟡 18 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) 1h 1m 2s

⏱️ Max setup 5m 29s · max shard execution 23m 24s · max shard-job elapsed before upload 26m 56s · reporting 1m 3s

🌐 124.08 requests/attempt · 2.24 app boots/UI scenario · 41.88% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 41.88% (convergence target: at most 15%).
  • Application boot ratio was 2.24 per UI scenario (10994 boots / 4912 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
✅ Shard chromium-01 156 0 0 0 0 0
✅ Shard chromium-02 159 0 0 0 0 0
🟡 Shard chromium-03 187 0 1 0 0 0
✅ Shard chromium-04 204 0 0 0 0 0
✅ Shard chromium-05 170 0 0 0 0 0
✅ Shard chromium-06 148 0 0 0 0 0
🟡 Shard chromium-07 166 0 1 0 0 0
✅ Shard chromium-08 194 0 0 0 0 0
🟡 Shard chromium-09 184 0 2 0 0 0
✅ Shard chromium-10 179 0 0 0 0 0
✅ Shard chromium-11 158 0 0 1 0 0
🟡 Shard chromium-12 158 0 3 0 0 0
✅ Shard chromium-13 163 0 0 0 0 0
🟡 Shard chromium-14 191 0 1 0 0 0
✅ Shard chromium-15 181 0 0 0 0 0
✅ Shard chromium-16 124 0 0 0 0 0
🟡 Shard chromium-17 182 0 2 0 0 0
✅ Shard chromium-18 171 0 0 0 0 0
🟡 Shard chromium-19 156 0 1 0 0 0
🟡 Shard chromium-20 173 0 2 0 0 0
🟡 Shard chromium-21 181 0 1 0 0 0
🟡 Shard chromium-22 193 0 2 0 0 0
🟡 Shard chromium-23 214 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 51 0 0 0 0 0
✅ Shard import-export-02 99 0 0 0 0 0
🟡 Shard ingestion-01 45 0 1 0 0 0
✅ Shard ingestion-02 55 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
🟡 18 flaky test(s) (passed on retry)
  • Features/Tasks/TaskNavigation.spec.ts › clicking task notification while on entity task tab refreshes the task list (shard chromium-03, 1 retry)
  • Features/ClassificationTagUsage.spec.ts › opens the tagged assets from the usage count (shard chromium-07, 1 retry)
  • Features/ContextCenterArticlesFilters.spec.ts › sort options route to the correct data path (shard chromium-09, 1 retry)
  • Features/PersonaAIContext.spec.ts › compound OR conditions are serialized into the save payload (shard chromium-09, 1 retry)
  • Features/Tasks/TaskResolution.spec.ts › non-team member should NOT see approve button for team task (shard chromium-12, 1 retry)
  • Pages/Lineage/DataAssetLineage.spec.ts › Column lineage for topic -> topic (shard chromium-12, 1 retry)
  • Features/Dashboards.spec.ts › should display data model when service name contains dots (shard chromium-12, 1 retry)
  • Features/Glossary/GlossaryAdvancedOperations.spec.ts › should create glossary with mutually exclusive toggle ON (shard chromium-14, 1 retry)
  • Features/AIMode/CustomPropertiesPanel.spec.ts › detail page does not show Add, Edit, or Delete buttons with ViewAll only (shard chromium-17, 1 retry)
  • Pages/ExplorePageRightPanel.spec.ts › Should NOT show restricted edit buttons for Data Steward for database (shard chromium-17, 1 retry)
  • Features/Tasks.spec.ts › should create request description task from entity page (shard chromium-19, 1 retry)
  • Features/DataQuality/ColumnLevelTests.spec.ts › Column Values To Not Match Regex (shard chromium-20, 1 retry)
  • Features/DataQuality/DataQualityDashboard.spec.ts › Data Assets Coverage pie chart segment click redirects to Test Suites and Explore (shard chromium-20, 1 retry)
  • Pages/Domains.spec.ts › Rename domain with data products attached at domain and subdomain levels (shard chromium-21, 1 retry)
  • Pages/AppRunsHistoryLogs.spec.ts › External app run logs open in the LogViewerModal (shard chromium-22, 1 retry)
  • Pages/Entity.spec.ts › Delete Directory (shard chromium-22, 1 retry)
  • Pages/InputOutputPorts.spec.ts › Output ports section collapse/expand (shard chromium-23, 1 retry)
  • Features/DataQuality/AddTestCaseNewFlow.spec.ts › Add Column Test Case (shard ingestion-01, 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

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.

[CI-Integration Failure ] Restore cascade silently leaves part of the subtree soft-deleted (Api <type> instance for <uuid> not found)

2 participants