Cursor Validity Limits During Index Modification
0 reputation · 29 Aug 2023, 05:24 UTC
0 reputation · 29 Aug 2023, 05:24 UTC
FaunaDB utilizes cursor-based pagination via the Page function to ensure consistent performance during large result set retrieval. This mechanism relies on opaque pointers to maintain position within an index scan, avoiding the linear overhead associated with traditional offset-based pagination.
A design uncertainty arises when the underlying index or the sort order of a query is modified while a client holds an active cursor for a multi-page result set. Because cursors are tied to the specific state and structure of the index used during the initial request, changes to the index definition may invalidate existing pointers.
After cursor references when the index terms are redefined?34775 reputation · 29 Aug 2023, 17:17 UTC
When the index underlying a FaunaDB Page cursor is modified, any existing After cursor becomes invalid and cannot be safely reused. FaunaDB does not provide a mechanism to map a legacy cursor to a new index structure; the client must discard the cursor and restart pagination from the first page.
invalid cursor) when an outdated cursor is supplied after such a change.Because the cursor token is tied to the exact tuple ordering used at the time of the initial Page call, any change that affects that ordering breaks the correspondence between the token and a location in the new index. Without a stored mapping of old index entries to new ones, FaunaDB cannot translate the token, so it treats it as invalid.
Page query (without a cursor) to obtain a fresh first‑page result set and a new cursor.If the index modification only added new fields that do not participate in the sort order used for pagination, existing cursors might remain valid. To confirm whether a restart is truly required, please verify: Did the index change affect the sort expression or any field that participates in the ordering used by the original Page query?
Use comments to ask for clarification. Post a solution as an answer.
5,950 reputation · 29 Aug 2023, 06:29 UTC
An additional nuance is the read transaction snapshot. A cursor issued in a transaction is evaluated against the index version visible to that transaction at start time. If an index definition changes in a later transaction, a cursor created before the change can remain usable for the remainder of its originating read transaction, even though the same cursor string will fail in a new transaction that sees the new index version.
That means invalidation is not always immediate globally; it is tied to the transaction boundary that produced the cursor. Once the transaction ends and a new request starts, FaunaDB will bind the cursor to the current index version and reject it if the version does not match.