Repository navigation
Description
Detail Bug Report
Introduced in #34647 by @pmbrull on Oct 5, 2026
Summary
- Context:
OpenSearchVectorServiceruns a "staged" chunk-index recreate during a full reindex: it writes new chunk documents into a bare next-generation index (G1) and only atomically promotes it (alias swap +remove_indexof the old targetL0) once every vector-indexable entity type finalizes. While the recreate is in flight, live entity edits are routed throughupdateEntityEmbeddings, which writes the new chunks to the live alias (which during a recreate points atL0) and is supposed to mirror the same write intoG1so the edit survives promotion. - Bug: The live-edit mirror write goes through
resolveChunkSinkTarget(), a discovery helper backed by a 15-second JVM-local cache that can holdnull. On every JVM except the one running the reindex job, the in-JVMstagedChunkIndexfield isnull, so the mirror relies entirely on this cache. When the cache holds a stalenull— because it was populated before the coordinator createdG1(including by a pre-recreate probe whose TTL hasn't expired) or because a transient cluster-state probe failed —mirrorToStagedGenerationsilently no-ops, and the live edit is written only toL0, which promotion thenremove_indexes. - Actual vs. expected: A live entity edit committed during a full reindex should still be present in the chunk index after the reindex promotes; instead its post-edit chunks are absent from
G1, and semantic/vector search (searchChunksByParent) serves the pre-edit passages for that entity until the entity is edited again or the next full reindex runs. - Impact: Stale semantic/
searchChunksByParentresults for the affected entity. Keyword and entity-document search are unaffected (the entity doc carries its own post-edit embedding viapartialUpdateEntity). The entity remains searchable with valid — but stale — passages, not missing entirely. The symptom self-heals on the next edit to that entity; for rarely-edited entities the stale window can persist until the next full reindex.
Code with Bug
In openmetadata-service/src/main/java/org/openmetadata/service/search/vector/OpenSearchVectorService.java:
if (refresh != ChunkRefresh.NONE) {
replaceChunks(chunkIndexName, parentId, chunkDocs, previousCount(header)); // writes to the live alias, which points at OLD generation L0 during a recreate
mirrorToStagedGeneration(parentId, chunkDocs); // <-- BUG 🔴 mirror can silently no-op when discovery cache returns stale null
} private void mirrorToStagedGeneration(String parentId, List<Map<String, Object>> chunkDocs) {
String staged = resolveChunkSinkTarget();
if (staged != null) {
try {
replaceChunks(staged, parentId, chunkDocs, previousCount(getChunkHeader(staged, parentId)));
} catch (IOException | RuntimeException e) {
LOG.warn("Failed to mirror chunks for {} into staged {}: {}", parentId, staged, e.getMessage());
}
} // <-- BUG 🔴 staged==null is silently skipped; live edit remains only in L0 and can be deleted on promotion
} private static final long SINK_TARGET_CACHE_MS = 15_000;
...
private String resolveChunkSinkTarget() {
String target = stagedChunkIndex; // null on every non-coordinator JVM
if (target == null) {
long now = System.currentTimeMillis();
if (now - cachedSinkTargetAt > SINK_TARGET_CACHE_MS) {
cachedSinkTarget = findActiveStagedGeneration(); // returns null when no un-promoted *_g* index exists, or on a transient probe failure (caught at :693, logged only at DEBUG)
cachedSinkTargetAt = now;
}
target = cachedSinkTarget; // <-- BUG 🔴 returns cached null for up to 15s, preventing mirroring during recreate
}
return target;
}Explanation
During a staged chunk-index recreate in a multi-node deployment, user edits may be handled by JVMs that are not running the reindex job. On those JVMs, stagedChunkIndex is unset, so mirrorToStagedGeneration() depends on resolveChunkSinkTarget().
resolveChunkSinkTarget() can return a cached null for up to 15 seconds (either because it cached null before G1 existed, or because findActiveStagedGeneration() transiently failed and returned null). When this happens, the mirror write is skipped without any warning.
Meanwhile updateEntityEmbeddings() still writes the updated chunks to the live alias, which during recreate points at the old generation (L0). When the recreate is promoted, the promotion action removes L0 (remove_index). If the reindex sink already streamed that entity (pre-edit) into G1, the post-edit chunks are never present in G1 after promotion, producing stale searchChunksByParent results until the next edit or full reindex.
Codebase Inconsistency
- Reindex sink writes (
writeEntityChunks/backfillEntityChunks) receive the run-scoped staged target explicitly viaReindexContext.getStagedChunkIndex()and do not use discovery. - Live-edit mirroring (
mirrorToStagedGeneration) usesresolveChunkSinkTarget()(the lossy discovery + null cache path). resolveChunkSinkTarget’s javadoc states it “only serves deletes,” indicating the helper was not intended for write-path correctness after the mirror call site was added.
Recommended Fix
Latch the run-scoped staged chunk index from the participant’s ReindexContext into a JVM-local field used by resolveChunkSinkTarget() (e.g., set cachedSinkTarget / cachedSinkTargetAt) for the duration of the run, so live-edit mirroring does not depend on best-effort cluster discovery.
Constraint: do not set stagedChunkIndex on participants, because that field is used to gate promotion (markEntityTypeReindexed) and is coordinator-only.
As a stopgap, add a WARN log when mirrorToStagedGeneration cannot resolve a staged target (today it silently skips).
History
This bug was introduced in commit fd05475. PR #34647 ("Fixes #34394: Add memory lifecycle and status filtering") added the mirrorToStagedGeneration method and its call site at OpenSearchVectorService.java:330 to prevent live edits from being stranded in the old generation during a staged chunk recreate. The change routed the mirror write through the existing resolveChunkSinkTarget() discovery helper — a 15-second JVM-local null cache designed only for the delete path (deleteEntityChunks, where a null is harmless) — instead of threading the run-scoped staged target from ReindexContext the way sink writes already did. The silent if (staged != null) skip with no else branch or log meant that when the cache held a stale null on a non-coordinator JVM, the mirror would no-op without any signal, leaving the live edit stranded in the soon-to-be-remove_indexed old generation. The PR also did not update the resolveChunkSinkTarget javadoc, which still reads "this only serves deletes," masking the new write-path call site from anyone reading the code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone ✅
Activity
Fixes open-metadata#35100: latch run-scoped staged chunk target on re…