Repository navigation
Fixes #37466: Skip the glossary tagged-asset rewrite on indices that hold no tagged document - #37467
Conversation
…ssary term move is approved
Accepting a held move or rename applied it inside POST /tasks/{id}/resolve
and waited on an _update_by_query across the global search alias. On a
large cluster that takes ~60s and can fail with 429 (too many scroll
contexts), so the reviewer's request timed out. The DB rewrite stays
synchronous; the tagged-asset rewrite now starts after commit on the async
executor, as an unheld move already does.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Every glossary-term tagged-asset rewrite, waited on or not, now runs on one single-threaded lane in post-commit drain order, so a later rename cannot overtake an approved move's background rewrite. Adds ADR:2026-11-10-an-approved-glossary-term-move-rewrites-tagged-assets-in-the-background.
| A reviewer's accept returns as quickly as an unheld move does. The cost is that rewrites queue | ||
| behind one another on a server: a PATCH rename can wait for a slow background rewrite that started | ||
| before it. Ordering is per server and starts at the post-commit drain, so it does not cover two | ||
| servers, or two commits whose drains run in the opposite order to their commits. Neither was |
There was a problem hiding this comment.
Cross-server rename after an approval leaves search on a stale FQN (new with this PR).
Reviewer accepts A→B on server 1, then the term is renamed B→C on server 2. Server 2's rewrite runs first and matches 0 docs (they still say A); server 1's background rewrite lands afterwards and writes B. Final state: DB tags …NetRevenueX (C), search doc …Costs.NetRevenue (B); a search for the current FQN returns 0 assets, still wrong minutes later, nothing in the retry queue.
On main the same sequence ends correct, because resolve only returns after the rewrite. So "Neither was covered before either" doesn't hold for sequential actions: before, only two truly concurrent requests could race; now one user doing two things in a row can hit it.
Tested locally: two servers sharing one MySQL + Elasticsearch, a proxy delaying the approved move's _update_by_query by 20s, compared against this branch with only its two Java files reverted to main.
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: with the rewrite back inside resolve, an A→B approval finishes before a later B→C rename on any server can start, so the sequence ends on C as it does on main.
| .updateGlossaryTermByFqnPrefix(GLOBAL_SEARCH_ALIAS, oldFqn, newFqn, TAGS_FQN); | ||
| searchRepository.deferIfFlushScopeActive( | ||
| () -> { | ||
| final Future<?> queued = ASSET_REWRITES.submit(rewrite); |
There was a problem hiding this comment.
Deleting a term right after its move is approved leaves the deleted term on assets in search.
The term-delete search cleanup (updateChildren on tags.tagFQN) doesn't go through ASSET_REWRITES, so it runs before the queued move rewrite. Sequence I saw: delete cleanup at +1s finds nothing (docs still have the old FQN), then the move rewrite at +20s writes the new FQN back onto the table. Final: DB has no tag, search doc tagged with the deleted term. On main the tag is removed. This happens on a single server too. Glossary renames (GlossaryRepository) also bypass the lane.
Tested locally: two servers sharing one MySQL + Elasticsearch, a proxy delaying the approved move's _update_by_query by 20s, compared against this branch with only its two Java files reverted to main.
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: the move's rewrite completes before resolve returns, so a delete that follows sees the moved FQN and its updateChildren cleanup removes the tag, as on main. Glossary renames are unaffected because there's no lane to bypass any more.
| "conceptMappings,references,relatedTerms,synonyms,style"; | ||
| private static final String PARENT_OF_RELATION_TYPE = "parentOf"; | ||
| // ponytail: one lane per server for every glossary; per-glossary lanes if rewrites queue up. | ||
| private static final ExecutorService ASSET_REWRITES = |
There was a problem hiding this comment.
One lane per server makes unrelated renames wait behind a slow approved rewrite.
Renaming a term in a different glossary right after an approval took 19.5s (main: 0.3s); it queued behind the approved move's rewrite. On the AUT cluster that rewrite took about 60s, so parallel specs that rename glossary terms on the same server could start hitting their own 60s waits, which would move the flakiness rather than remove it. Per-glossary (or per-FQN-prefix) lanes would keep the ordering without the cross-glossary stall.
Tested locally: two servers sharing one MySQL + Elasticsearch, a proxy delaying the approved move's _update_by_query by 20s, compared against this branch with only its two Java files reverted to main.
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: there's no shared lane, so unrelated renames never queue behind an approved move. Each rename also now touches only the indices that hold its tagged documents, so it gets cheaper rather than slower.
| () -> { | ||
| final Future<?> queued = ASSET_REWRITES.submit(rewrite); | ||
| if (!inBackground) { | ||
| awaitAssetRewrite(queued, oldFqn, newFqn); |
There was a problem hiding this comment.
A PATCH rename right after an approval now blocks for the whole background rewrite.
Approve A→B, then rename the same term on the same server: the PATCH took 19.7s (main: 0.7s). The ordering is right (final search tag is C), but the user doing the rename now pays the full approved-move rewrite time. Worth stating in the ADR's Consequences with the numbers, since this is the latency the PR moves off the reviewer.
Tested locally: two servers sharing one MySQL + Elasticsearch, a proxy delaying the approved move's _update_by_query by 20s, compared against this branch with only its two Java files reverted to main.
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: a PATCH right after an approval no longer waits on anything queued. Each request pays only for its own rewrite, which is now restricted to the matching indices, or skipped when nothing is tagged.
| // ponytail: one lane per server for every glossary; per-glossary lanes if rewrites queue up. | ||
| private static final ExecutorService ASSET_REWRITES = | ||
| Executors.newSingleThreadExecutor( | ||
| Thread.ofVirtual().name("glossary-asset-rewrite-", 0).factory()); |
There was a problem hiding this comment.
Queued rewrites are lost on restart.
ASSET_REWRITES is in-memory and never shut down. If a pod restarts (rolling deploy) while an approved move's rewrite is queued or running, it's dropped with no SearchIndexRetryQueue entry, even though the reviewer already got a 200. Search stays on the old FQN until a reindex. Before, the rewrite could only be lost during the request itself. Enqueueing the intent before submit (or a shutdown hook that drains/enqueues) would close this. (Code reading; not reproduced.)
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: nothing is queued in memory any more. The rewrite runs before the reviewer gets the 200, and a failure is enqueued in SearchIndexRetryQueue as before.
| if (parentChanged || glossaryChanged || nameChanged) { | ||
| invalidateTerm(updated.getId()); | ||
| updateAssetIndexes(oldFqn, newFqn); | ||
| updateAssetIndexes(oldFqn, newFqn, isApprovedChange()); |
There was a problem hiding this comment.
Cache invalidation for tagged entities can miss while a background rewrite is pending.
invalidateCacheForTaggedEntitiesAndDescendants(oldFqn) (a few lines above) finds tagged assets through search. If this term was just moved by an approval and its rewrite is still queued, search still holds the pre-move FQN, so a rename here finds none of the tagged assets and their cached entities keep old tags until TTL (with Redis or another cache enabled). (Code reading; not reproduced, ITs run cache-off.)
There was a problem hiding this comment.
Thanks, this was a good catch. All six findings come from the background lane, so I took a different approach in 83cc7a7 and reverted the lane and its ADR. The rewrite is synchronous again, exactly as on main. The 60s turned out to be the engine retrying a rejected scroll: an update-by-query on _all opens a scroll context on every shard of every index even when nothing matches. updateGlossaryTermByFqnPrefix now runs a size-0 search with an _index terms aggregation first. When nothing is tagged it skips the update-by-query entirely (the AUT case: the test term has no tagged assets); otherwise it rewrites only the indices that hold a match.
For this one: no rewrite is ever pending after a request returns, so invalidateCacheForTaggedEntitiesAndDescendants finds the tagged assets under the FQN the search docs actually hold.
… tagged Reverts the background lane from 40af058 and its decision record. The 60s wait was the engine retrying a rejected scroll: an update-by-query on the global alias opens a scroll context on every shard of every index even when nothing matches. A size-0 search with an _index terms aggregation now picks the indices holding a tagged document; nothing tagged means no update-by-query, and otherwise only those indices are rewritten. The rewrite stays synchronous, so ordering, durability and read-your-write are as on main.
A search that missed a shard could drop an index holding tagged documents from the rewrite with nothing logged. It now throws, so the rename goes to SearchIndexRetryQueue. A full 1000-bucket page falls back to the whole alias instead of silently leaving indices out. Adds ADR:2026-11-11-a-global-alias-rewrite-targets-only-the-indices-holding-a-match.
Code Review ✅ Approved 🔴 High risk 4 closed / 4 findingsScoping glossary tag rewrites to discovered indices affects search-index integrity; an incomplete search result could leave moved terms stale in asset documents. Skips the glossary tagged-asset search rewrite when no index holds a matching document, and narrows the update-by-query to only the indices that do, avoiding the scroll-context exhaustion that caused 429 failures on approved glossary term moves. Rewrite remains synchronous in the request, and failed shards route to the retry queue. Previously open findings around ordering, unrecorded ADR rules, and partial shard failures were resolved, and the decision record is now added. ✅ 4 closed✅ Bug: Unordered background rewrite can be overtaken by the next term rename
✅ Quality: Background-vs-inline asset rewrite rule is not recorded in an ADR
✅ Edge Case: Partial shard failures in the probe search silently skip tagged docs
✅ Quality: Probe-then-narrow rule and its 1000-index cap are not recorded
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
…ssary term move is approved (#37467) (#37519) * Fixes #37466: Rewrite tagged assets in the background when a held glossary term move is approved Accepting a held move or rename applied it inside POST /tasks/{id}/resolve and waited on an _update_by_query across the global search alias. On a large cluster that takes ~60s and can fail with 429 (too many scroll contexts), so the reviewer's request timed out. The DB rewrite stays synchronous; the tagged-asset rewrite now starts after commit on the async executor, as an unheld move already does. * Order glossary tagged-asset rewrites and record the decision Every glossary-term tagged-asset rewrite, waited on or not, now runs on one single-threaded lane in post-commit drain order, so a later rename cannot overtake an approved move's background rewrite. Adds ADR:2026-11-10-an-approved-glossary-term-move-rewrites-tagged-assets-in-the-background. (cherry picked from commit 7e18ef8)
Describe your changes:
Fixes #37466
GlossaryTermMoveApproval.spec.tshas failed or been flaky in nightly AUT on MySQL and Postgres since it landed on 2026-11-03. The reviewer'sPOST /api/v1/tasks/{id}/resolvetakes about 61s, longer than the test's 60s wait.Root cause (from the AUT
collate.log): accepting a held move runsGlossaryTermRepository.updateParent→updateAssetIndexes→updateGlossaryTermByFqnPrefix, which sends an_update_by_query?refresh=trueto the global_allalias. An update-by-query opens a scroll context on every shard it reaches, whether or not anything there matches. Across_allthat is one per shard of every index (more during a reindex, when*_rebuild_*indices are aliased in). On the busy AUT node that exhaustssearch.max_open_scroll_context(500). The engine then retries the rejected scroll with its built-in backoff: 500ms start, 11 retries, about 59.5s in total. Finally it fails with429 Trying to create too many scroll contexts:The term in the test has no tagged assets, so all of that time is spent on a rewrite with nothing to update.
Fix (
OpenSearchEntityManagerandElasticSearchEntityManager,updateGlossaryTermByFqnPrefix): before the update-by-query, run a size-0 search with the same prefix query and a terms aggregation on_index. A plain search opens no scroll contexts.No index holds a tagged document: no update-by-query runs at all.
Otherwise: the update-by-query (and its reconciler refresh) targets only the indices that hold a match, instead of every shard behind
_all.The search reports a failed shard: the rewrite is not attempted and the rename goes to
SearchIndexRetryQueue, so a busy shard can't silently drop an index.The 1000-bucket page is full: it may have been cut short, so the update falls back to the whole alias.
The rule is recorded in
ADR:2026-11-11-a-global-alias-rewrite-targets-only-the-indices-holding-a-match.The rewrite stays synchronous in the request, exactly as on main, so ordering, read-your-write behaviour and failure handling (
SearchIndexRetryQueue) are unchanged.Type of change:
High-level design:
N/A — small change (two search managers, one query added before an existing call, one decision record).
Tests:
Use cases covered
resolvereturns immediately.Unit tests
OpenSearchEntityManagerUpdateByQueryRetryTest,ElasticSearchEntityManagerUpdateByQueryRetryTest:aGlossaryPrefixRenameNothingIsTaggedWithRunsNoUpdateByQuery— fails on main, which always sends the update-by-query.aGlossaryPrefixRenameRewritesOnlyTheIndicesHoldingATaggedDocument— fails on main, which targetsall.aGlossaryPrefixRenameWhoseSearchMissedAShardGoesToTheRetryQueue— a failed shard queues a retry and runs no update.aGlossaryPrefixRenameMatchingAFullPageOfIndicesRewritesTheWholeAlias— a full page targets the alias.Backend integration tests
WorkflowDefinitionResourceIT#test_approvedGlossaryTermMoveRewritesTaggedAssetsInSearch: tags a table with the term, approves a held move, and checks the table's search document carries the new tag FQN.mysql-elasticsearchandpostgres-opensearch), re-run onddafaadfa15:global-statelane): 5/5 on each engine.RenameCascadeSearchIT(glossary/tag/classification rename and move cascades,parallellane): 9/9 on each engine.WorkflowDefinitionResourceIT, which the merge queue runs.Playwright (UI) tests
playwright/e2e/Features/Glossary/GlossaryTermMoveApproval.spec.tsagainst a server built from this branch at83cc7a7cbcd(MySQL + Elasticsearch): 4 passed. The server log showsNo search documents are tagged under PwMoveGate….Revenue….NetRevenue…; nothing to rewriteon the resolve thread, andresolvereturned 200.Manual testing performed
resolve.The 429 itself only reproduces on a scroll-saturated cluster like nightly AUT. The next nightly run is the end-to-end check.
UI screen recording:
Not applicable — backend-only fix.
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: N/A
For a UI feature or feature task: N/A
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md.Decision check: adds
docs/decisions/2026-11-11-a-global-alias-rewrite-targets-only-the-indices-holding-a-match.md.I have added a test that covers the exact scenario we are fixing (unit tests for the skipped and narrowed update-by-query; the IT and Playwright spec for the approved move).
🤖 Generated with Claude Code