Azure / Azure/azure-sdk-for-python

[Cosmos] feed_range query continuation token replays documents from non-cursor PK ranges

Aperta
#46,473 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Client Cosmos needs-team-attention
Lingua principale
Python
Stelle
5.6k
Fork
3.4k
Merge medio
2g 2h
PR unite (30g)
213

Descrizione

### Summary

When `query_items(feed_range=..., max_item_count=N)` is invoked with a `feed_range` that overlaps multiple physical partition key (PK) ranges (for example, after a server-side split), `__QueryFeed` issues one POST per overlapping inner range and merges the partial results.

PR #46469 fixed the page-size bug (the merged page is now truncated to `max_item_count`). However, the **continuation token surfaced to the caller** is still only the last inner range's `x-ms-continuation`. Round-tripping that token on the next page sends it to every inner range — which is undefined server-side and would produce duplicates, missing documents, or non-terminating iteration.

As a safety mitigation in PR #46469, when the merged page is actually truncated the continuation header is **suppressed** so callers observe the truncated page as terminal rather than experiencing data loss. This makes the broken pagination case visible (pagination ends early) instead of silently corrupting results, but it also means **only the first page of a multi-range `feed_range` query is reliable**.

### Proposed fix

Implement a **composite continuation token** that spans all overlapping inner PK ranges for a `feed_range` query:

- Track per-inner-range continuation tokens and remaining-cap state.
- Encode them into a single opaque continuation string surfaced to the caller.
- On resume, decode and route each per-range token to its corresponding inner POST.
- Stop issuing inner POSTs once the user-requested `max_item_count` cap is reached for the current page; carry the unconsumed inner range continuations forward.

### Related

- PR #46469 — initial fix for the K×N page-size bug + safety mitigation
- Files: `sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py`, `sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py` (`__QueryFeed`, feed_range_epk branch)

### Affected SDK area

`Azure.Cosmos`

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Leggi la PR #46469 e i rami __QueryFeed feed_range_epk in sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py e sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py. Definisci come vengono rappresentate, codificate, decodificate e instradate alla ripresa le continuazioni per intervallo e i limiti rimanenti. Il lavoro è completato quando le query su più intervalli possono continuare tra le pagine senza riprodurre i documenti, perdere risultati o terminare in anticipo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
databases
Tipo di issue
Bug
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.