Skip to content

[2.1] Delete the chunks of a recursive delete's descendants (backport 2.1 #38884) - #38886

Open
manerow wants to merge 4 commits into
2.1from
fix/2.1-vector-chunk-cascade-delete
Open

manerow wants to merge 4 commits into
2.1from
fix/2.1-vector-chunk-cascade-delete

Conversation

@manerow

@manerow manerow commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Backport of PR #38884 to 2.1, adapted rather than cherry-picked. 2.1 has neither the shared vector service of PR #38415 nor the chunk delete of PR #38841, and on 2.1 only OpenSearch has a chunk index. So this ports the lifecycle part and the retry worker's chunk cleanup; the vector handler keeps 2.1's own delete for each entity.

  1. Hard delete. The vector handler deletes chunks in the prepareHardDelete hook, which every hard-deleted entity passes through, descendants of a recursive delete included. The dispatcher gives a handler the entities of one type together, which a recursive delete prepares in groups of up to 500 per tree level. After each group's commit, its chunks are deleted on the ordered lanes, behind any update already queued, in at most one task per lane, not one per descendant. The delete event no longer deletes chunks. A logical test suite's hard delete, the one path that skipped the hook, now calls it.
  2. Soft delete. A recursive soft delete marks descendants deleted with a bulk update and sends no soft-delete event, so their chunks stayed matchable. The handler now deletes the chunks of any entity updated to deleted. A restore writes them back through the same update.
  3. Shed deletes. A lane task that a full lane sheds goes to the search retry queue. As in PR #38841, its worker now also removes the chunks of an entity that is gone, soft-deleted or no longer embedded, never those of a live embedded one. A delete the cluster refuses is still only logged.

Apart from one javadoc, the lifecycle files match PR #38884. PR #38884 also batches deletes inside each lane task and sweeps orphaned chunks; this backport does neither (see the release note).

Why

After a service, database or schema was deleted, semantic search and AskCollate kept returning its tables, dashboards and charts. This affects OpenSearch on every 2.0 and 2.1 release.

Decision record

ADR:2026-11-09-lifecycle-handlers-prepare-a-hard-delete-before-its-rows-are-removed, v2, worded as in PR #38884. The chunk lifecycle record exists only on main.

Verification

  • New VectorChunkCascadeDeleteIT (OpenSearch 3.4, calls the vector handler directly, no server): without this change, 40 tables passed through the hard delete hook keep their chunks after 30 s and a soft-deleted table keeps all 3; with it, both pass.
  • Two new SearchIndexRetryWorkerTest cases fail without the retry worker change and pass with it: gone, soft-deleted, opted-out and replaced entities lose their chunks, a live embedded one keeps them.
  • Unit: all 3231 search and lifecycle tests pass, with the logical suite test of PR #38884.
  • The impact map check passes.

Not run on 2.1: a local server E2E (run on main for both engines in PR #38884) and the full impacted plan.

Release note

On OpenSearch with semantic search, chunks left by earlier recursive deletes stay searchable until the next Search Indexing run that covers all entity types. If your scheduled run covers only some types, run it once with all entities after upgrading.

@manerow
manerow requested a review from a team as a code owner November 26, 2026 16:13
@manerow
manerow requested review from pmbrull and removed request for a team November 26, 2026 16:13
@manerow manerow added the skip-pr-checks Bypass PR metadata validation check label Nov 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

Comment on lines +187 to 188
removeChunksUnlessEmbedded(normalize(record.getEntityId()), root.getType(), rootEntity);
completeClaim(record);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Edge Case: A failed chunk-delete replay still completes the retry claim

The retry worker is now the only place that replays a chunk delete shed by a full lane. It calls vectorService.deleteEntityChunks(entityId) and then completeClaim(record) without checking the outcome. On 2.1, OpenSearchVectorService.deleteEntityChunks goes through deleteChunksFrom, which catches every Exception and logs it at DEBUG. So if OpenSearch rejects or times out the delete (likely under the same load that filled the lane), nothing reaches handleProcessingError. The row is still deleted from the queue as a success, and the descendant's chunks stay matchable until a full reindex. The retry ends up dropping the exact work it exists to replay.

Fix: on the retry path, use a chunk delete that throws. For example, add a deleteEntityChunksOrThrow to VectorIndexService (the default can delegate) that rethrows instead of logging at DEBUG, and call it from removeChunksOf. The failure then goes through handleProcessingError and the claim is kept for another attempt.

Use a variant that throws on the retry path so the existing error handling keeps the claim:

private void removeChunksOf(String entityId, String entityType) throws IOException {
  VectorIndexService vectorService = searchRepository.getVectorIndexService();
  boolean embeddedType =
      entityType.isEmpty() || AvailableEntityTypes.isVectorIndexable(entityType);
  if (vectorService != null && embeddedType) {
    vectorService.deleteEntityChunksOrThrow(entityId);
  }
}
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 🟡 Medium risk 1 closed / 2 findings

Ordered, retried vector-chunk cleanup for hard and soft deletes changes search-index lifecycle behavior; failures could leave stale chunks searchable or remove valid matches.

Backports the chunk lifecycle fix so semantic search stops returning tables, dashboards and charts after their parent service, database or schema is deleted, covering hard deletes, soft deletes and shed retry work. Changes requested: the retry worker completes its claim even when the OpenSearch chunk delete fails, because deleteChunksFrom swallows exceptions at DEBUG, so the failed replay is silently dropped instead of retried.

  • SearchIndexRetryWorker calls vectorService.deleteEntityChunks and then completeClaim without checking the outcome
  • Fix by adding a throwing chunk-delete variant for the retry path so failures reach handleProcessingError and the claim is kept
⚠️ Edge Case: A failed chunk-delete replay still completes the retry claim

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:187-188 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:720 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:739-745 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/lifecycle/EntityLifecycleEventDispatcher.java:478-480

The retry worker is now the only place that replays a chunk delete shed by a full lane. It calls vectorService.deleteEntityChunks(entityId) and then completeClaim(record) without checking the outcome. On 2.1, OpenSearchVectorService.deleteEntityChunks goes through deleteChunksFrom, which catches every Exception and logs it at DEBUG. So if OpenSearch rejects or times out the delete (likely under the same load that filled the lane), nothing reaches handleProcessingError. The row is still deleted from the queue as a success, and the descendant's chunks stay matchable until a full reindex. The retry ends up dropping the exact work it exists to replay.

Fix: on the retry path, use a chunk delete that throws. For example, add a deleteEntityChunksOrThrow to VectorIndexService (the default can delegate) that rethrows instead of logging at DEBUG, and call it from removeChunksOf. The failure then goes through handleProcessingError and the claim is kept for another attempt.

Use a variant that throws on the retry path so the existing error handling keeps the claim
private void removeChunksOf(String entityId, String entityType) throws IOException {
  VectorIndexService vectorService = searchRepository.getVectorIndexService();
  boolean embeddedType =
      entityType.isEmpty() || AvailableEntityTypes.isVectorIndexable(entityType);
  if (vectorService != null && embeddedType) {
    vectorService.deleteEntityChunksOrThrow(entityId);
  }
}
✅ 1 closed
✅ Edge Case: Shed chunk-delete batches are retried as search reindex, so chunks stay

📄 openmetadata-service/src/main/java/org/openmetadata/service/events/lifecycle/EntityLifecycleEventDispatcher.java:475-489 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/lifecycle/EntityLifecycleEventDispatcher.java:687-701 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorEmbeddingHandler.java:88-99 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/VectorEmbeddingHandler.java:158-163 📄 openmetadata-service/src/main/java/org/openmetadata/service/events/lifecycle/OrderedLaneExecutor.java:205-218
When a lane is full, submitPerLane sheds the OrderedLaneBatchTask and enqueueLaneFailureRetry (EntityLifecycleEventDispatcher.java:687-702) puts each entity on SearchIndexRetryQueue. Because the entity is already hard-deleted, SearchIndexRetryWorker cannot resolve it. It calls removeStaleEntityById, which only runs searchClient.deleteEntity on the entity's write targets, then completes the claim. It never calls deleteEntityChunks. So for a large cascade under load (the case this PR targets), every shed lane task leaves its descendants' chunks orphaned, and they stay matchable by semantic search and AskCollate until a full reindex. The Javadoc on submitInEntityOrder says a shed part "goes to the search retry queue", which suggests it will be recovered, but it won't be. Also, deleteChunks(String) catches every exception, so a delete that throws never reaches this retry path either.

Fix options:

  • Make the retry worker's stale-entity cleanup also delete the vector chunks for the id.
  • Or, for DELETE_CHUNKS_OPERATION, run the shed batch inline or record it in a chunk-specific retry, and let delete failures propagate so they get retried.
🤖 Prompt for agents
Code Review: Backports the chunk lifecycle fix so semantic search stops returning tables, dashboards and charts after their parent service, database or schema is deleted, covering hard deletes, soft deletes and shed retry work. Changes requested: the retry worker completes its claim even when the OpenSearch chunk delete fails, because `deleteChunksFrom` swallows exceptions at DEBUG, so the failed replay is silently dropped instead of retried.
  
  - `SearchIndexRetryWorker` calls `vectorService.deleteEntityChunks` and then `completeClaim` without checking the outcome
  - Fix by adding a throwing chunk-delete variant for the retry path so failures reach `handleProcessingError` and the claim is kept

1. ⚠️ Edge Case: A failed chunk-delete replay still completes the retry claim
   Files: openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:187-188, openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:720, openmetadata-service/src/main/java/org/openmetadata/service/search/SearchIndexRetryWorker.java:739-745, openmetadata-service/src/main/java/org/openmetadata/service/events/lifecycle/EntityLifecycleEventDispatcher.java:478-480

   The retry worker is now the only place that replays a chunk delete shed by a full lane. It calls `vectorService.deleteEntityChunks(entityId)` and then `completeClaim(record)` without checking the outcome. On 2.1, `OpenSearchVectorService.deleteEntityChunks` goes through `deleteChunksFrom`, which catches every `Exception` and logs it at DEBUG. So if OpenSearch rejects or times out the delete (likely under the same load that filled the lane), nothing reaches `handleProcessingError`. The row is still deleted from the queue as a success, and the descendant's chunks stay matchable until a full reindex. The retry ends up dropping the exact work it exists to replay.
   
   Fix: on the retry path, use a chunk delete that throws. For example, add a `deleteEntityChunksOrThrow` to `VectorIndexService` (the default can delegate) that rethrows instead of logging at DEBUG, and call it from `removeChunksOf`. The failure then goes through `handleProcessingError` and the claim is kept for another attempt.

   Fix (Use a variant that throws on the retry path so the existing error handling keeps the claim):
   private void removeChunksOf(String entityId, String entityType) throws IOException {
     VectorIndexService vectorService = searchRepository.getVectorIndexService();
     boolean embeddedType =
         entityType.isEmpty() || AvailableEntityTypes.isVectorIndexable(entityType);
     if (vectorService != null && embeddedType) {
       vectorService.deleteEntityChunksOrThrow(entityId);
     }
   }

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

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 has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants