Skip to content

Fixes #35914: Keep OpenSearch vectors in source to avoid closed readers (backport 2.0 #35917) - #36208

Merged
manerow merged 1 commit into
2.0from
fix/35914-opensearch-closed-readers-2.0
Oct 26, 2026
Merged

manerow merged 1 commit into
2.0from
fix/35914-opensearch-closed-readers-2.0

Conversation

@manerow

@manerow manerow commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Issue

Cherry-pick of #35917 (Fixes #35914) onto 2.0. It replaces the automatic backport #35945, which was closed without merging.

Problem

On OpenSearch 3.x, the k-NN plugin rebuilds the embedding field from its vector files when it reads a document. This is called "derived source". Concurrent updates, segment merges and scroll cleanup can leave one of those vector readers closed (opensearch-project/k-NN#3138). After that, every request that has to read documents from the index fails with already_closed_exception. That includes embedding updates and normal searches, even though the cluster reports healthy.

A customer on 2.0 with OpenSearch 3.5.0 hit this on the test case index. The Data Quality tab failed with "all shards failed", while the summary cards still loaded because they only run aggregations. A reindex made it go away, but it can come back.

What this PR changes

Same change as #35917. Every OpenSearch index that stores embeddings is now created with index.knn.derived_source.enabled=false. This applies to entity indexes and to the live and staged chunk indexes. Vectors are then kept in the stored _source, so the failing reader is never used. Embedding generation, vector indexing and kNN search all keep working. Elasticsearch is not affected.

The setting is static. Existing indexes only pick it up after a full reindex that recreates them.

One adaptation for 2.0: the regression test restores the original lifecycle handlers when it finishes. On main it does this with EntityLifecycleEventDispatcher.replaceHandler, which does not exist on 2.0. Here it calls unregisterHandler and then registerHandler for each handler. The test is @Isolated, so nothing else runs during that step. The production code is identical to main.

What users will notice

After upgrading and running a full reindex with index recreation, searches and embedding updates no longer fail with already_closed_exception. Vector indexes use somewhat more disk, because the vectors are stored in _source as well.

How it was tested

On this branch:

  • OsUtilsTest, OpenSearchVectorServiceTest and OpenSearchVectorServiceChunkStagingTest: 69 tests, all pass.
  • OpenSearchVectorReaderIT reproduces the concurrent update, merge and scroll load on the test case index and on the chunk index:
OpenSearch Derived source Result
3.4.0 off (this PR) Pass (2 of 2)
3.4.0 on (2.0 today) Fails with already_closed_exception (2 of 2)
3.5.0 off (this PR) Pass (2 of 2)
3.5.0 on (2.0 today) Fails with already_closed_exception (2 of 2)

The "on" rows put the old index settings back locally, to check that the test catches the bug on this branch.

RetriggerView in GreptileConfidence Score: 4/5

No behavioral blocker was established, but the explicit Java convention requirements must be satisfied before merging.

Findings

  1. P2 `createIndex` has two returns ▶
  2. P2 Repeated strings lack constants ▶
  3. P2 New declarations omit required `final` ▶

Summary

Keeps OpenSearch vectors in stored _source by loading shared settings for entity indexes and live and staged chunk indexes.

  • OpenSearch vector indexes keep embeddings in stored source.

Reviews (1) · Last reviewed commit: "Fixes #35914: Keep OpenSearch vectors in..." · Reviewed by Greptile

@manerow
manerow requested a review from a team as a code owner October 26, 2026 07:55
@manerow
manerow requested review from harshach and removed request for a team October 26, 2026 07:55
@manerow manerow added skip-pr-checks Bypass PR metadata validation check safe to test Add this label to run secure Github workflows on PRs backend labels Oct 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.

@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Disabling OpenSearch derived source stores vectors in _source, increasing index disk usage and requiring recreation for existing indexes to receive the setting.

Adds index.knn.derived_source.enabled=false to every embedding-capable OpenSearch index (entity indexes plus live and staged chunk indexes) so vectors stay in _source and avoid the closed-reader already_closed_exception on OpenSearch 3.x. Changes requested: the setting is unconditional, but the k-NN plugin only registers it starting with 2.19.0, so on OpenSearch 2.6–2.18 index creation would fail with an unknown-setting error. Gate the setting on the cluster version (3.x or ≥ 2.19), or document a new minimum OpenSearch version for semantic search, before merge.

✅ 1 closed
Closed: Edge Case: derived_source setting fails index creation on OpenSearch < 2.19

📄 openmetadata-spec/src/main/resources/elasticsearch/opensearch_vector_index_mapping.json:5 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OsUtils.java:725-734 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/opensearch/OsUtils.java:785 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:946
knn.derived_source.enabled is now added to every embedding-capable entity index and to the live and staged chunk indexes, and nothing checks the cluster version first. The k-NN plugin only registers index.knn.derived_source.enabled starting with 2.19.0 (2.19.0 release notes, KNNSettings 2.19.0.0). Version 2.17.0.0 does not have it (KNNSettings 2.17.0.0), so older clusters reject index creation with an unknown-setting error. This branch says it supports OpenSearch 2.6+ (AGENTS.md). Failing to create the hybrid RRF pipeline is treated as non-fatal, so semantic search on 2.10–2.18 partly works today. With this change, a reindex on those clusters would fail to create the entity and chunk indexes at all. Fix: add the setting only when the cluster runs OpenSearch 3.x (or ≥ 2.19). The bug from k-NN#3138 only happens with derived source, which is on by default only in 3.x. Alternatively, document a new minimum OpenSearch version for semantic search.

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

@sonarqubecloud

Copy link
Copy Markdown

@manerow
manerow merged commit f65effa into 2.0 Oct 26, 2026
114 of 128 checks passed
@manerow
manerow deleted the fix/35914-opensearch-closed-readers-2.0 branch October 26, 2026 08:31
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 skip-pr-checks Bypass PR metadata validation check

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants