Skip to content

Fixes #34058: Evict a committed cascade from the cache in one step; give the IT server production's search pool - #34059

Merged
harshach merged 5 commits into
mainfrom
fix/flaky-async-restore-and-es-pool
Sep 27, 2026
Merged

harshach merged 5 commits into
mainfrom
fix/flaky-async-restore-and-es-pool

Conversation

@mohityadav766

@mohityadav766 mohityadav766 commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Describe your changes:

Fixes #34058

Two integration tests have been failing intermittently and evicting PRs from the merge queue. One is a real cache bug, the other a test-harness setting.

1. With the Redis cache on, restored children could 404 right after an async restore. This is RestoreHierarchyIT.asyncRestore_returns202AndRestoresFullHierarchy in the postgres-elasticsearch-redis lane.

Since #33866, a cascade's children are evicted from Redis only after its transaction commits, in drainCacheInvalidations. The drain goes 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. 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. In one failing run the schema GET 404'd about 0.2 s after the database was re-read as restored, and the async job finished about 2.5 s after that.

2. The IT server ran on the search client's schema pool defaults. This is SearchResourceIT.testEntityTypeCountsResponseFormat in the mysql-elasticsearch lane.

TestSuiteBootstrap never set maxConnTotal or maxConnPerRoute. The in-process server therefore had 10 connections to the single Elasticsearch host instead of the 50/100 conf/openmetadata.yaml ships. Under the parallel lane the pool stayed empty past connectionRequestTimeoutSecs (5 s), which surfaced as DeadlineTimeoutException in StrictConnPool. Rest5Client wraps that timeout as "error while performing request". The bootstrap now sets the production values.

These are the postgres-elasticsearch-redis parallel-lane reports from 2026-09-23 06:51 to 2026-09-25 15:57 UTC, split by whether the tested commit contains #33866. This is CI observation, not a controlled run:

Tested commit Reports syncRestore fails asyncRestore fails test_sdkOnlyAsyncOperations fails (unrelated)
without #33866 188 3 0 12
with #33866 86 0 7 8

#33866 fixed the sync failure (#33860) and opened this async one.

Type of change:

  • Bug fix

High-level design:

The fix is in the post-commit cache drain, EntityRepository.drainCacheInvalidations → evictCommittedWrites. For the keys a transaction deferred, it now:

  1. Bumps every write epoch first. A loader that read the pre-commit row can't write it back to Redis or L1 after the eviction, because the existing loader race guard sees the epoch move.
  2. Deletes every entity key in one DEL. That covers the id hash (base and reference) plus the by-name and reference aliases, via the new CachedEntityDao.invalidateEntities. The batch is split only past 1,000 keys, so a very large cascade never blocks Redis on one command. The whole batch turns over at once. The root still evicts inline, so a reader can still see the root restored before its children for about one Redis round trip after the commit. Before this change that gap lasted the whole sequential drain, which is the window the test hit.
  3. Evicts L1 after that DEL. A reader in the window copies the stale Redis entry into L1, and until now nothing evicted it after the commit.
  4. Then, per key: the derived Redis caches (relationships, read bundle, lineage, tags), the pub/sub notice to other instances, and an EntityCacheRepair re-armed from the commit. The repair armed inside the transaction fires 500 ms after that eviction, which a long transaction can outlive.

invalidateRedisL2ForEntity, used when no scope is open and by the repair, now uses the same one-DEL eviction instead of four round trips.

Without Redis (for example the MySQL lane), the drain now also re-evicts L1 and re-arms the repair for each deferred key. That is local work only, and it closes the same L1 hole there.

Alternatives considered and rejected:

  • Deferring the root's own inline eviction too, so the whole hierarchy flips together. That would change read-your-write for every single-entity update inside its own transaction.
  • Polling for the children in the test. That would hide a real inconsistency: a restored database whose schemas 404 for a moment.

No migration, schema or config changes.

Tests:

Use cases covered

  • A reader that cached the soft-deleted copy during the restore transaction sees the restored entity once the transaction commits.
  • A committed batch leaves Redis in one step: no reader finds one child evicted while a sibling still serves its pre-commit copy.
  • A stale L1 copy that lands after the drain is still evicted when the transaction outlived the repair it armed itself.
  • Inside a deferral scope Redis keeps the entry until the drain. Without a scope it is evicted immediately.
  • invalidateEntities evicts every variant of a batch in one DEL, and splits only past 1,000 keys.

Unit tests

  • I added unit tests for the new/changed logic.
  • New: openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/DeferredCacheInvalidationTest.java (5 tests). It runs the real L1 loader and the real CachedEntityDao over an in-memory Redis stand-in; only the DB read is stubbed.
  • Updated: CachedEntityDaoAliasEvictionTest (+2 tests). In EntityRepositoryRestoreTest, the two mock-verify deferral tests from Fixes 33860: evict Redis L2 after commit, not inside the write transaction #33866 were replaced by state-based versions in the new class.
  • Without the fix (on main), 3 of the 5 new tests fail. After the drain, L1 still serves the soft-deleted copy. The watched Redis keys left after each write are [2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0]. No repair is armed at commit.
  • With the fix, 172/172 tests pass across the 21 unit-test classes that touch the cache, post-commit and deferral code.
  • Coverage %: 32 of 33 changed executable lines are covered (JaCoCo): 19/19 in EntityRepository.java and 13/14 in CachedEntityDao.java. The uncovered line is the EntityCacheBypass guard's return in invalidateEntities.

Backend integration tests

  • Not applicable (no backend API changes).
  • Re-ran locally on postgres + Elasticsearch + Redis (-Pcache-tests, parallel lane): RestoreHierarchyIT 5/5 and SearchResourceIT 77/77 (3 pre-existing skips). Neither flake reproduces locally without CI load, so this run confirms the restore and search paths still work. The regression proof is the unit tests above, and CI's postgres-elasticsearch-redis lane on this PR.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

Verified through the tests above, not on a manual stack. To check by hand with the Redis cache enabled:

  1. Create a database with a few schemas and tables, and soft-delete it recursively.
  2. Read a schema with include=all, which caches its soft-deleted copy.
  3. PUT /api/v1/databases/restore?async=true.
  4. Poll GET /api/v1/databases/{id} until it is restored, then immediately GET /api/v1/databaseSchemas/{schemaId}. It should return 200. Before this fix it intermittently returned 404 under load.

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: I updated the migration scripts or explained why it is not needed. (N/A: no schema changes.)
  • For UI changes: I attached a screen recording and/or screenshots above. (N/A: no UI changes.)
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.

🤖 Generated with Claude Code

mohityadav766 and others added 2 commits September 26, 2026 00:25
…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 <[email protected]>
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 <[email protected]>
@mohityadav766
mohityadav766 requested a review from a team as a code owner September 25, 2026 19:11
@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Sep 25, 2026
@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

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

@mohityadav766 mohityadav766 self-assigned this Sep 25, 2026
@gitar-bot

gitar-bot Bot commented Sep 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Committed cascade eviction changes cache behavior, alongside integration-server pool sizing.

Fixes two flaky integration tests by evicting committed cascades from Redis in one atomic step and configuring the IT server with production search pool sizes. The cache drain now bumps write epochs, deletes all entity keys in a single DEL command (split only past 1,000 keys), evicts L1 after that, and re-arms repairs—eliminating the window where restored children could 404 while their parent reads as restored. The search pool is configured to production's 50/100 instead of the client schema defaults. Comprehensive unit tests cover the deferred invalidation logic, and integration tests confirm the restore and search paths remain functional.

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

@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-09-27T17:59:42Z)

Blocked the queue: integration-tests-mysql-elasticsearch

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.

Flaky ITs: async restore 404s on restored children with the Redis cache; IT search pool runs on schema defaults

2 participants