Repository navigation
Fixes #35914: Keep OpenSearch vectors in source to avoid closed readers (backport 2.0 #35917) - #36208
Conversation
…rs (backport 2.0 #35917)
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
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 ✅ 1 closedClosed: Edge Case: derived_source setting fails index creation on OpenSearch < 2.19
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 |
|



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
embeddingfield 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 withalready_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
mainit does this withEntityLifecycleEventDispatcher.replaceHandler, which does not exist on2.0. Here it callsunregisterHandlerand thenregisterHandlerfor each handler. The test is@Isolated, so nothing else runs during that step. The production code is identical tomain.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_sourceas well.How it was tested
On this branch:
OsUtilsTest,OpenSearchVectorServiceTestandOpenSearchVectorServiceChunkStagingTest: 69 tests, all pass.OpenSearchVectorReaderITreproduces the concurrent update, merge and scroll load on the test case index and on the chunk index:already_closed_exception(2 of 2)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.
No behavioral blocker was established, but the explicit Java convention requirements must be satisfied before merging.
Findings
Summary
Keeps OpenSearch vectors in stored
_sourceby loading shared settings for entity indexes and live and staged chunk indexes.Reviews (1) · Last reviewed commit: "Fixes #35914: Keep OpenSearch vectors in..." · Reviewed by Greptile