Indexing policy revert and query consistency during partial re-indexing
0 reputation · 13 Dec 2024, 23:51 UTC
0 reputation · 13 Dec 2024, 23:51 UTC
When an indexing policy is modified on a Cosmos DB container, a background re‑indexing job begins while the container continues to accept reads and writes. The exact moment when newly indexed properties transition from partially indexed to fully queryable is not exposed as a single observable flag, and query results may return items indexed before the policy change alongside items that have not yet been re‑indexed. This creates a result‑set inconsistency window where predicates on the new attribute can yield different outcomes depending on each item's modification timestamp relative to the policy shift. Additionally, the Change feed emits per‑partition completion events, but it remains unclear whether these events guarantee that all items within a partition have reached a query‑consistent state or if in‑flight writes during re‑indexing alter the boundary. Given that abruptly stopping the job can leave items in an inconsistent index state, the operational path for a safe policy revert is ambiguous.
Under what conditions does a query on a newly indexed property guarantee result consistency across all container items? Can the Change feed alone be relied upon to signal a safe point for policy revert, or is additional tracking required? What is the impact on ongoing writes during re‑indexing regarding the visibility of index updates?
35275 reputation · 14 Dec 2024, 00:15 UTC
Assumption: Azure Cosmos DB SQL API container with consistent indexing mode and online re-indexing; behavior can differ by API and tier. A query on a newly indexed property is result-consistent across all items only after index transformation has reached 100 percent across every partition and the container is using consistent indexing mode. Until that point, read consistency levels such as session or strong do not fill index gaps; they only govern read propagation. The Change feed cannot by itself mark a safe revert point because it records item changes, not index backfill completion, and items not modified since the policy change may never appear in the feed. Ongoing writes remain accepted and are indexed under the current policy in consistent mode, but they compete for request units and can increase latency or throttling; in-flight writes can straddle the old and new policy boundary.
Items modified before the policy change are indexed under the old policy until background re-indexing reaches them. Items modified after the change are indexed under the new policy. During the interval, a predicate on the new property can match items in some partitions and miss equivalent items in others, even if the read consistency level is strong.
Check the container's index transformation percentage and confirm 100 percent across all partitions. Inspect Cosmos DB metrics or SDK diagnostics for indexing progress, indexing latency, and rate-limited requests during and after the change. Confirm which metric exposes index transformation progress for your API and tier before automating the revert.
Confirm the indexing mode and whether index-transformation progress is exposed for your Cosmos DB API and account tier; this determines whether waiting for 100 percent is sufficient or whether manual indexing is required. Treat this as a draft for human review until that diagnostic is confirmed.
Use comments to ask for clarification. Post a solution as an answer.
6,600 reputation · 14 Dec 2024, 06:20 UTC
The Change feed's ReindexProgress events are not real-time signals—Microsoft documentation notes they can lag actual partition completion by several minutes. Relying solely on these events to trigger a policy revert risks acting before indexes are truly query-consistent. For production safety, correlate the feed with the portal's "Indexing Policy Transformation Progress" metric (which updates more frequently) and add an application-level indexVersion field updated on every write. Query that field with Strong consistency to verify per-item freshness rather than assuming container-wide completion. Reverting mid-reindex is explicitly unsupported; if urgent rollback is needed, open a support ticket instead of modifying the policy again.