/** * Copyright (c) 2025 Elara AI Pty Ltd * Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details. */ /** * The paging runtime's third layer: batched reads (#1351). Several reads of one * source asked as ONE request and ONE channel, named by a digest of what it * asks: a batch of key searches (`seekAll`), the rows of several keys of a Dict * (`rowsAll`), a Dict's rows under the keys some runs of a record's index name * (`joinAll`, #1393), the entries of several runs (`runsAll`), where a * narrowing's runs sit in its record (`placeAll`, #1349) and which entries they * hold (`withinAll`). What a batch answers serves the single reads too. * * @packageDocumentation */ import { type EastTypeValue, type option } from "@elaraai/east"; import { type DatasetFindQuery, type DatasetFindResult } from "@elaraai/e3-api-client"; import { type TreePath } from "@elaraai/e3-types"; import type { PagedSelector, PagedSource, PagedRow, PagedRun, PagedPlacement } from "./api.js"; import { type Snapshot } from "./state.js"; import { PagedReads } from "./reads.js"; /** * The batched reads over the single ones: the paging runtime's third layer. */ export declare class PagedBatches extends PagedReads { /** * Several key searches of one source's rows, read as ONE request and ONE * channel (#1351): each query's bounds, as `seek` answers them, in the order * asked — `none` while any is in flight. * * @remarks * The batch is one channel, named by a digest of what it asks, which * holds its answer — every query's bounds, in order — kept as a landed * window is, bounded with them. A query the runtime already holds — one a * search's channel holds, or the revision holds apart from a channel * ({@link Snapshot.searches}) — is answered from it; the rest go in one * `findKeys` request (one for each {@link DATASET_BATCH_MAX} of them), whose * readers track the batch's channel. As the answer lands, each query's * bounds go into a search's channel waiting on it and among those the * revision holds — the last {@link MAX_LANDED_SEARCHES} of them — so a * search asked later answers from them, and the batch's channel re-fires * once, with every reader waiting on one of its queries. A reader walking * on leaves no search of its own behind: what it asked goes with its * batch's channel, and its searches' bounds with the least recently used. * * @param source - The rows searched: a dataset's own, or one of a record's indexes * @param queries - The searches, as e3's wire takes them; their index is the source's * @returns Each search's bounds, in order, once every one has landed * @throws The batch's failure, until a read after the retry gap asks again */ seekAll(source: PagedSource, queries: readonly DatasetFindQuery[]): option; /** A search's bounds the runtime holds: its channel's, or what the revision holds apart from a channel. */ protected landedSearch(snapshot: Snapshot, key: string): DatasetFindResult | undefined; /** * Launch a batch's key searches not already held: one request for each * {@link DATASET_BATCH_MAX} of them, the answers landing together on the * batch's channel beside those held as it launched. */ protected launchSeekBatch(workspace: string, path: TreePath, snapshot: Snapshot, revision: string, selector: PagedSelector, batchKey: string, queries: readonly DatasetFindQuery[], keys: readonly string[], known: readonly (DatasetFindResult | undefined)[]): void; /** * The rows a Dict source holds under several keys, read as ONE request and * ONE channel (#1351): each key's row, or its absence, and its position in * the source's canonical order, in the order asked — `none` while the read * is in flight. * * @remarks * A key the runtime already holds — a row an earlier read by key answered, * or a key a landed window of the same rows holds — is answered from what it * holds, and the rest go in one rows request: the server holds an answer to * its byte budget, and what it did not reach is asked again until every key * is answered. Each row is held at its position, so a later read by its key * — a search by the key, then a one-row page at its row — answers from it, * with no request. * * @param source - A Dict dataset's own rows * @param keys - The keys, as East values of the key type * @returns Each key's row, in order, once every one is known * @throws The read's failure, until a read after the retry gap asks again; * at once, for a source that is not a Dict's own rows */ rowsAll(source: PagedSource, keys: readonly unknown[]): option; /** Launch a rows read for the keys not already held, asking again for what * each answer's budget did not reach. */ protected launchRowsBatch(workspace: string, path: TreePath, snapshot: Snapshot, revision: string, sourceType: EastTypeValue, batchKey: string, literals: readonly string[], known: readonly (PagedRow | undefined)[]): void; /** * The rows a Dict source holds under the keys the entries of some runs of * one of a record's indexes name, read as ONE request and ONE channel * (#1393): each entry's key, the Dict's row under it or its absence, and * its position in the Dict, in the runs' order — `none` while the read is * in flight. The server reads the keys from the index: none is sent. * * @remarks * The read is pinned to both datasets' revisions, and its channel is both * snapshots', so a move of either drops it and the reader asks again at * the new one; a refusal naming either's new content moves that one. The * server holds an answer to a page's bounds, and the runs' rest is asked * again until every entry is answered. Each row is held at its position, * as a read by key's are, so a later read by its key answers from it. * * @param dict - A Dict dataset's own rows: the rows read * @param of - One of a record's indexes: the runs' rows, whose entries name the keys * @param runs - The runs: ascending, disjoint, each inside the index * @returns Each entry's row, in the runs' order, once every one is known * @throws The read's failure, until a read after the retry gap asks again; * at once, for a source that is not a Dict's own rows, or runs of no index */ joinAll(dict: PagedSource, of: PagedSource, runs: readonly PagedRun[]): option; /** Launch a read of a Dict's rows by a record's runs, asking again for the * entries each answer's bounds did not reach. */ protected launchJoins(workspace: string, dict: PagedSource, snapshot: Snapshot, revision: string, of: PagedSource, index: string, runsSnapshot: Snapshot, runsRevision: string, batchKey: string, runs: readonly PagedRun[]): void; /** * The revision a source's reads are pinned to now (#1393): what a reader * keeps what it read of the source under, so a move reads it again — a * tracked read, which re-fires as the source moves. * * @param source - The source * @returns Its dataset's revision; none while it is found, or while the dataset has no value * @throws The failed lookup's reason, until a read after the retry gap looks again */ revisionOf(source: PagedSource): option; /** * Ask again what failed of a source (#1510): the Retry of a reader that * holds the source alone, not the pinned handle whose `refresh` asks it — * a read by key's ({@link rowsAll}) among what it asks again. What failed * of its dataset for a reason a retry can fix is asked again at once, not * after the retry gap a read alone waits, and the content it holds is * looked up again, as `refresh` asks them. Deferred, as `refresh` is: a * Retry asked while a view renders never re-fires that render from * inside it. With no paging service installed there is nothing to ask. * * @param source - The source */ askAgain(source: PagedSource): void; /** * The entries of several runs of a source's rows, read as ONE request and * ONE channel (#1351): one window of the source's type holding exactly the * runs' entries, in order — `none` while the read is in flight. * * @remarks * The server holds an answer to a page's bounds, and the runs' rest is asked * again until every entry has landed, the parts joined in order. The window * is kept as a landed window is, bounded with them, and a window of the same * rows inside one of its runs is answered from it, as from a landed window * that covers it (#1217). * * @param source - The rows read: a dataset's own, or one of a record's * indexes, joined as its selector says * @param runs - The runs: ascending, disjoint, each inside the source * @returns The window, once every entry has landed * @throws The read's failure, until a read after the retry gap asks again */ runsAll(source: PagedSource, runs: readonly PagedRun[]): option; /** Launch a runs read, asking again for the entries each answer's bounds * did not reach. */ protected launchRunsBatch(workspace: string, path: TreePath, snapshot: Snapshot, revision: string, source: PagedSource, batchKey: string, runs: readonly PagedRun[]): void; /** * Where a narrowing's runs of one of a record's indexes sit in the record * (#1349): how many of the runs' entries each record segment holds, placed * a window at a time and drawn as the windows land. * * @remarks * The first window learns how many entries the server places in one, and * the rest are asked {@link PLACE_CONCURRENCY} at a time from there; a * window placed short leaves the rest of it to ask again. Runs past a * request's {@link DATASET_BATCH_MAX} are placed a group at a time. A * narrowing's runs name each row once, so the windows' placements add up, * segment by segment. The channel re-fires as each window lands, its * placement `complete` once the last has. The revision holds the placements * of at most {@link MAX_HELD_PLACEMENTS} narrowings, the least recently read * going first — never one a reader holds — so a viewer trying narrowing * after narrowing leaves no more behind. * * @param source - One of a record's indexes, the runs' rows * @param runs - The narrowing's runs: ascending, disjoint, each inside the index * @returns What is placed so far, once the first window has landed * @throws The placement's failure, until a read after the retry gap asks again; * at once, for a source that is no record's index */ placeAll(source: PagedSource, runs: readonly PagedRun[]): option; /** Launch a placement: its windows, {@link PLACE_CONCURRENCY} at a time, * each answer added in as it lands. */ protected launchPlacement(workspace: string, path: TreePath, snapshot: Snapshot, revision: string, index: string, batchKey: string, runs: readonly PagedRun[]): void; /** * Which of some index entries a narrowing's runs of one of a record's * indexes hold (#1349): for each entry key, whether it lies in one of the * runs, in the order asked — `none` while any is in flight. * * @remarks * Each key's answer is held at the revision, by the runs, so a key asked * again — a segment drawn again, a window panned back — is answered from * what is held, and only the keys not held go in a request: one for each * {@link DATASET_BATCH_MAX} keys, and for each as many runs, a key in any * group of the runs being in them. Past {@link MAX_HELD_WITHIN} answers * over every narrowing of the revision, the least recently used * narrowing's least recently read go first, but a batch keeps every key * its reader asks of until the reader has read them ({@link HeldWithin}): * several readers whose keys together pass the cap each read theirs after * one batch, and a reader whose answers went since asks again for those * alone. * * @param source - One of a record's indexes, the runs' rows * @param runs - The narrowing's runs: ascending, disjoint, each inside the index * @param keys - `.east` literals of the index's entry keys, `(ik=…, k=…)`: at * most {@link MAX_WITHIN_KEYS} in one read * @returns Whether each key lies in one of the runs, once every one is known * @throws The read's failure, until a read after the retry gap asks again; * at once, for a source that is no record's index, or more keys than a read takes */ withinAll(source: PagedSource, runs: readonly PagedRun[], keys: readonly string[]): option; /** * How many membership answers the runtime holds of a source's dataset, * over every narrowing's runs, how many of them batches keep for their * readers, and how many batches keep any (#1349): what its specs hold the * bounds to. A move drops them all, so they are always the current * revision's. * * @param source - One of a record's indexes, or any source of the same record * @returns The answers held, those kept, and the batches keeping them */ protected withinHeld(source: PagedSource): { answers: number; kept: number; batches: number; }; /** * What the runtime holds now (test use only, through a subclass, as * {@link withinHeld} is): the channels it keeps, the versions it keeps of * channels, the longest channel's key, and of a source's dataset at its * revision the searches' bounds it holds apart from a channel, how many * narrowings' membership answers it holds and how many of its channels hold * a placement — what its specs hold the runtime's bounds to. * * @param source - Any source of the dataset * @returns What it holds */ protected holding(source: PagedSource): { channels: number; versions: number; longestKey: number; searches: number; narrowings: number; placements: number; }; /** Launch a membership read of the keys not held: a request for each group * of keys and of runs, a key in any group of the runs being in them. */ protected launchWithin(workspace: string, path: TreePath, snapshot: Snapshot, revision: string, index: string, family: string, batchKey: string, runs: readonly PagedRun[], keys: readonly string[]): void; } //# sourceMappingURL=batches.d.ts.map