barrel_query_cursor (barrel_docdb v1.1.1)

View Source

Query cursor management for chunked query execution

Manages cursor state for paginated queries using ETS. Each cursor holds: - Snapshot reference for consistent reads across chunks - Last key position for resumption - Query metadata for validation - Expiry time for cleanup

Summary

Functions

Create a new cursor with snapshot Returns an opaque cursor token

Drop a cursor entry WITHOUT releasing its snapshot. Used when resuming: the successor cursor (or the terminal chunk) now owns the shared snapshot, so releasing it here would drop a snapshot still in use by later chunks.

Look up a cursor by token Returns cursor data if valid and not expired

Release a cursor and its snapshot

Start the cursor manager

Update cursor position after a chunk

Functions

create(StoreRef, DbName, QueryType, LastKey, Snapshot)

-spec create(term(), binary(), atom(), binary(), term()) -> binary().

Create a new cursor with snapshot Returns an opaque cursor token

detach(CursorId)

-spec detach(binary()) -> ok.

Drop a cursor entry WITHOUT releasing its snapshot. Used when resuming: the successor cursor (or the terminal chunk) now owns the shared snapshot, so releasing it here would drop a snapshot still in use by later chunks.

handle_call(Request, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

lookup(CursorId)

-spec lookup(binary()) ->
                {ok,
                 #cursor{id :: binary(),
                         store_ref :: term(),
                         db_name :: binary(),
                         snapshot :: term() | undefined,
                         last_key :: binary(),
                         query_type :: atom(),
                         created_at :: integer(),
                         expires_at :: integer()}} |
                {error, not_found | expired}.

Look up a cursor by token Returns cursor data if valid and not expired

release(CursorId)

-spec release(binary()) -> ok.

Release a cursor and its snapshot

start_link()

-spec start_link() -> {ok, pid()} | {error, term()}.

Start the cursor manager

terminate(Reason, State)

update(CursorId, NewLastKey)

-spec update(binary(), binary()) -> ok | {error, not_found}.

Update cursor position after a chunk