Skip to content

Pagination & consistency

How read freshness works in LoonFS, and how to page through listings, changefeeds, diffs, and search results.

This page explains how read consistency controls freshness on single requests and how pagination works across directory listings, changefeeds, diffs, and search.

Because checking object storage adds latency (roughly 200 ms on a cold check), LoonFS lets you choose between cached reads and strongly consistent reads per request. When an operation spans multiple pages, you also need to know whether the endpoint pages over moving live state or pins a specific namespace sequence.

Checking object storage for the latest manifest and WAL tip on every read would add a round trip even when a slightly stale result is acceptable. Live read endpoints therefore accept a consistency query parameter:

  • eventual (default): reads from the server’s last confirmed head while that head is within the allowed staleness window, then checks object storage again. On the reference server, the default staleness window is 1,000 ms (an implementation default, not a protocol requirement).
  • strong: confirms the latest head in object storage before reading, so the response reflects every commit acknowledged before the read started.
HTTP
GET /v0/namespaces/demo/filesystem/entry?path=%2Freports&consistency=strong

Use strong when a read must reflect a commit that was just acknowledged through another server or embedded process, including a permission change. Reads on a single server never move backward in time, but if your client sends consecutive requests to different servers, their cached heads may differ.

Strong consistency applies to one request at a time. Two strong reads in a row can still see different states if another client commits between those two reads.

Directory listings, trash listings, file revisions, snapshots, and grep paginate with opaque cursors.

Pass limit if you want a smaller page size (check Limits for the deployment’s default and maximum page sizes). When a response includes next_cursor, URL-encode that token and pass it back as cursor on the next request, keeping the same target path or inode and the same query parameters:

HTTP
GET /v0/namespaces/demo/filesystem/entries?path=%2Freports&limit=100
GET /v0/namespaces/demo/filesystem/entries?path=%2Freports&limit=100&cursor=RETURNED_CURSOR

Keep paging until next_cursor is absent. Don’t stop just because a page contains fewer items than limit, because LoonFS filters out entries the caller can’t view and caps the work done per request.

Directory listings return entries in canonical name order, and recursive listings walk directories depth-first.

On a live namespace, a cursor for a directory, trash, or revision listing records the position to resume from, not a snapshot of the namespace. If another writer adds a file behind your cursor position or renames a file while you are paging, your walk can miss an entry or return the same entry twice.

When you need a consistent multi-page walk (for example, when exporting a directory tree):

  1. Create a snapshot and save its snapshot ID (snapshot_id).
  2. Pass that snapshot_id on the first listing request and on every later page.
  3. Pass the same snapshot_id on any file reads or downloads tied to the export.
  4. Delete the snapshot when you finish, or set a ttl_ms when creating the snapshot so it expires automatically.

Keep the same snapshot_id on every page of a snapshot-backed listing, because changing or omitting snapshot_id mid-pagination returns invalid_request. Don’t combine snapshot_id with consistency, because the snapshot already selects the exact state to read.

Trash listings don’t accept snapshot_id. On live endpoints that include head_seq in the response, you can detect concurrent commits by checking whether head_seq changed between pages, though restarting on every change isn’t practical on a busy namespace.

List changes and List differences paginate with sequence numbers rather than opaque cursors.

Pass next_after_seq from each response back as after_seq on the next request until next_after_seq is absent, and persist your resume position only after you finish processing the page. Because new commits can be written to a live namespace while you read the changefeed, pass a snapshot_id if you want the feed to stop at a specific captured sequence.

A single commit can contain thousands of operations. If you set split_commits=true, LoonFS can split a large commit across pages and return both next_after_seq and next_event_index. Resume by passing next_after_seq as after_seq and next_event_index as event_index, and stop sending event_index (or reset event_index to 0) once the response omits next_event_index. Wait until you’ve read the final chunk of a split commit before treating that commit as complete.

When paging through List differences, keep your original from_seq and the first response’s to_seq unchanged on every later page while advancing after_seq (and event_index if split_commits=true). If you omit to_seq, each page defaults to the namespace’s current head, so commits written between pages shift the end of the diff.

If a changefeed or diff request returns below_retention_floor, compaction has already removed the history needed to compute that range. Rebuild your local state from a fresh listing or snapshot and resume from that state’s sequence number. Creating a snapshot protects the view captured by that snapshot, but it doesn’t stop the live namespace’s retention floor from advancing.

Unlike directory listings, Grep pins the first page’s head_seq inside its cursor, so later pages search that same namespace state. Keep your pattern and other query parameters unchanged across pages.

  • Index rebuilds or retention expiry. If the search index is rebuilt or the retention floor passes the cursor’s head_seq (returning below_retention_floor), the cursor becomes invalid and you must restart the search from the first page.
  • Permissions on changed files. LoonFS checks permissions on every page. If a file was modified after the cursor’s head_seq, viewing a match from that earlier version requires the history right, so a caller without history won’t see that match.
  • Stale index searches. When allow_stale=true, the cursor also records the original index coverage (built_through_seq), so later pages don’t start including newly indexed commits partway through pagination. See Search.