@elaraai/e3-api-server 1.0.96 → 1.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -4
- package/dist/src/handlers/dataflow.d.ts +9 -1
- package/dist/src/handlers/dataflow.d.ts.map +1 -1
- package/dist/src/handlers/dataflow.js +19 -4
- package/dist/src/handlers/dataflow.js.map +1 -1
- package/dist/src/handlers/dataset-batches.d.ts +203 -0
- package/dist/src/handlers/dataset-batches.d.ts.map +1 -0
- package/dist/src/handlers/dataset-batches.js +442 -0
- package/dist/src/handlers/dataset-batches.js.map +1 -0
- package/dist/src/handlers/dataset-place.d.ts +104 -0
- package/dist/src/handlers/dataset-place.d.ts.map +1 -0
- package/dist/src/handlers/dataset-place.js +282 -0
- package/dist/src/handlers/dataset-place.js.map +1 -0
- package/dist/src/handlers/dataset-reads.d.ts +205 -0
- package/dist/src/handlers/dataset-reads.d.ts.map +1 -0
- package/dist/src/handlers/dataset-reads.js +350 -0
- package/dist/src/handlers/dataset-reads.js.map +1 -0
- package/dist/src/handlers/datasets.d.ts +19 -30
- package/dist/src/handlers/datasets.d.ts.map +1 -1
- package/dist/src/handlers/datasets.js +84 -549
- package/dist/src/handlers/datasets.js.map +1 -1
- package/dist/src/handlers/datasets.spec.js +968 -14
- package/dist/src/handlers/datasets.spec.js.map +1 -1
- package/dist/src/handlers/index.d.ts +5 -1
- package/dist/src/handlers/index.d.ts.map +1 -1
- package/dist/src/handlers/index.js +4 -1
- package/dist/src/handlers/index.js.map +1 -1
- package/dist/src/handlers/key-search.d.ts +102 -0
- package/dist/src/handlers/key-search.d.ts.map +1 -0
- package/dist/src/handlers/key-search.js +351 -0
- package/dist/src/handlers/key-search.js.map +1 -0
- package/dist/src/handlers/segments.d.ts +124 -0
- package/dist/src/handlers/segments.d.ts.map +1 -0
- package/dist/src/handlers/segments.js +278 -0
- package/dist/src/handlers/segments.js.map +1 -0
- package/dist/src/handlers/workspaces.spec.js +1 -0
- package/dist/src/handlers/workspaces.spec.js.map +1 -1
- package/dist/src/portable.spec.js +3 -2
- package/dist/src/portable.spec.js.map +1 -1
- package/dist/src/routes/dataset-path.d.ts +16 -0
- package/dist/src/routes/dataset-path.d.ts.map +1 -1
- package/dist/src/routes/dataset-path.js +18 -0
- package/dist/src/routes/dataset-path.js.map +1 -1
- package/dist/src/routes/datasets.d.ts.map +1 -1
- package/dist/src/routes/datasets.js +228 -2
- package/dist/src/routes/datasets.js.map +1 -1
- package/dist/src/routes/executions.js +1 -1
- package/dist/src/routes/executions.js.map +1 -1
- package/dist/src/routes/transfer.d.ts.map +1 -1
- package/dist/src/routes/transfer.js +11 -5
- package/dist/src/routes/transfer.js.map +1 -1
- package/dist/src/stopping-run.d.ts +24 -3
- package/dist/src/stopping-run.d.ts.map +1 -1
- package/dist/src/stopping-run.js +29 -7
- package/dist/src/stopping-run.js.map +1 -1
- package/dist/src/stopping-run.spec.js +30 -1
- package/dist/src/stopping-run.spec.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A dataset's reads in batches (#1351): several key searches of one
|
|
7
|
+
* collection in one request (`findKeys`), the rows of several keys of a Dict
|
|
8
|
+
* (the rows form) — or of the keys some runs of a record's index name (#1393)
|
|
9
|
+
* — and the entries of several runs of a collection's rows (the runs form) —
|
|
10
|
+
* each answered at one content hash, each reading every segment it touches
|
|
11
|
+
* once, several at a time, through the decoded segments the API process keeps.
|
|
12
|
+
*
|
|
13
|
+
* A batch is a POST — its queries, keys or runs travel in the body — so no
|
|
14
|
+
* cache between keeps its answer: a client's own caches serve a batch asked
|
|
15
|
+
* again.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { encodeBeast2For, fromEastTypeValue, isTypeValueEqual, none, parseFor, printType, some, } from '@elaraai/east';
|
|
20
|
+
import { BEAST2_CONTENT_TYPE, datasetRowsType } from '@elaraai/e3-types';
|
|
21
|
+
import { workspaceGetDatasetStatus } from '@elaraai/e3-core/portable';
|
|
22
|
+
import { sendJsonError } from '../errors.js';
|
|
23
|
+
import { PAGE_BYTE_BUDGET_DEFAULT, PAGE_MAX_LIMIT, cachedSegments, collectionOf, corruptRefusal, elementsOf, indexOf, openForRead, openTarget, pageError, readDataset, rowsByKey, searchTarget, } from './dataset-reads.js';
|
|
24
|
+
import { compileKeySearch, locateAll } from './key-search.js';
|
|
25
|
+
import { comparators, decodedSegments, firstWhere } from './segments.js';
|
|
26
|
+
/** The most queries, keys or runs one batch read takes: 10,000, a page's cap. */
|
|
27
|
+
export const DATASET_BATCH_MAX = PAGE_MAX_LIMIT;
|
|
28
|
+
/**
|
|
29
|
+
* The most bytes a batch read's JSON body holds: 16 MiB.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* A batch names at most {@link DATASET_BATCH_MAX} queries, keys or runs, so a
|
|
33
|
+
* batch of the most it names has some 1.6 KB of `.east` literals for each,
|
|
34
|
+
* and the cap is four times a page's byte budget, the most an answer holds. A
|
|
35
|
+
* body past it is refused 413 `payload_too_large` as soon as its length says
|
|
36
|
+
* so, or as its bytes pass the cap, the rest never read: no request makes the
|
|
37
|
+
* server hold more of its body than this.
|
|
38
|
+
*/
|
|
39
|
+
export const DATASET_BATCH_BODY_MAX = 16 * 1024 * 1024;
|
|
40
|
+
/**
|
|
41
|
+
* Answer several key searches of one collection in one request: each as
|
|
42
|
+
* `findDatasetKey` answers it, in the order asked, at one content hash.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Every query's bounds are placed by a bisect of the manifest's fences, which
|
|
46
|
+
* reads nothing; every segment a bound lands in is then read once for all of
|
|
47
|
+
* them, several at a time, through the decoded segments the API process
|
|
48
|
+
* keeps, and each bound's row is a binary search of its segment's keys. So a
|
|
49
|
+
* window's searches decode its few segments, never a segment a search.
|
|
50
|
+
*
|
|
51
|
+
* Responds with JSON `{ results: [{ found, row, count }, …] }`. A batch of more
|
|
52
|
+
* than {@link DATASET_BATCH_MAX} queries is refused, and so is any query a
|
|
53
|
+
* single search would refuse, naming it by its place in the batch.
|
|
54
|
+
*
|
|
55
|
+
* @param storage - Storage backend
|
|
56
|
+
* @param repoPath - Repository identifier
|
|
57
|
+
* @param workspace - Workspace name
|
|
58
|
+
* @param treePath - The dataset's path
|
|
59
|
+
* @param request - The queries, the index they search and the pin
|
|
60
|
+
* @returns The answers, or a JSON refusal
|
|
61
|
+
*/
|
|
62
|
+
export async function findDatasetKeys(storage, repoPath, workspace, treePath, request) {
|
|
63
|
+
try {
|
|
64
|
+
if (request.queries.length > DATASET_BATCH_MAX) {
|
|
65
|
+
return pageError('bad_request', `A batch of key searches takes at most ${DATASET_BATCH_MAX} queries; this one has ${request.queries.length}`);
|
|
66
|
+
}
|
|
67
|
+
const dataset = await readDataset(storage, repoPath, workspace, treePath, request.hash, 'key search');
|
|
68
|
+
if (dataset instanceof Response)
|
|
69
|
+
return dataset;
|
|
70
|
+
const target = await searchTarget(storage, repoPath, workspace, treePath, dataset, request.index);
|
|
71
|
+
if (target instanceof Response)
|
|
72
|
+
return target;
|
|
73
|
+
const searches = [];
|
|
74
|
+
for (const [i, query] of request.queries.entries()) {
|
|
75
|
+
const search = compileKeySearch(query, target);
|
|
76
|
+
if ('type' in search)
|
|
77
|
+
return pageError(search.type, `query ${i}: ${search.message}`);
|
|
78
|
+
searches.push(search);
|
|
79
|
+
}
|
|
80
|
+
const segments = await openTarget(storage, repoPath, target);
|
|
81
|
+
if (segments instanceof Response)
|
|
82
|
+
return segments;
|
|
83
|
+
let located;
|
|
84
|
+
try {
|
|
85
|
+
located = await locateAll(storage, repoPath, segments, searches.flatMap((search) => search.bounds));
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return corruptRefusal(err, 'dataset_not_canonical');
|
|
89
|
+
}
|
|
90
|
+
const results = [];
|
|
91
|
+
let at = 0;
|
|
92
|
+
for (const search of searches) {
|
|
93
|
+
results.push(search.answer(located.slice(at, at + search.bounds.length), segments.elementCount));
|
|
94
|
+
at += search.bounds.length;
|
|
95
|
+
}
|
|
96
|
+
return new Response(JSON.stringify({ results }), {
|
|
97
|
+
status: 200,
|
|
98
|
+
headers: {
|
|
99
|
+
'Content-Type': 'application/json',
|
|
100
|
+
'Cache-Control': 'no-store',
|
|
101
|
+
'X-Content-SHA256': dataset.hash,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
return sendJsonError(err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Read the rows a Dict holds under several keys in one request: each key's
|
|
111
|
+
* row, or its absence, and its position in the Dict's canonical order, in the
|
|
112
|
+
* order asked, as beast2 of `datasetRowsType(K, V)`. The keys are the
|
|
113
|
+
* request's own (`keys`), or those the entries of some runs of one of a
|
|
114
|
+
* record's indexes name, in the runs' order (`keysOf`, #1393).
|
|
115
|
+
*
|
|
116
|
+
* @remarks
|
|
117
|
+
* Each key is placed in the segment that can hold it by a bisect of the
|
|
118
|
+
* manifest's fences, which reads nothing, and every such segment is read once,
|
|
119
|
+
* several at a time, through the decoded segments the API process keeps, and
|
|
120
|
+
* searched by bisection. A position is the same row space a page's element
|
|
121
|
+
* windows address: a key the Dict holds is at its row's, and one it does not
|
|
122
|
+
* at the one it would take — what a search by the key answers.
|
|
123
|
+
*
|
|
124
|
+
* Read by runs, the keys never travel: the runs' entries are read from the
|
|
125
|
+
* index's segments, each touched once, as a read of the runs reads them, and
|
|
126
|
+
* each entry's key is looked up as a key asked would be — so a reader that
|
|
127
|
+
* holds a window of an index reads another record's rows for it by the runs it
|
|
128
|
+
* already has. The runs are pinned to the record's content apart from the
|
|
129
|
+
* Dict's: a stale one is refused 409 `runs_hash_mismatch`, naming the content
|
|
130
|
+
* the record holds now (`X-Content-SHA256`), so a client knows which of the
|
|
131
|
+
* two moved. The index's entries must name the record's keys — a summary's
|
|
132
|
+
* name none — and the record's key type must be the Dict's, East deciding.
|
|
133
|
+
*
|
|
134
|
+
* The answer is held to the page byte budget, by the Dict's average row size —
|
|
135
|
+
* and, read by runs, to a page's {@link PAGE_MAX_LIMIT} entries: past it, the
|
|
136
|
+
* answer covers the keys it reached, in order, and says how many
|
|
137
|
+
* (`X-Page-Count`, and of how many the runs hold, `X-Run-Entries`); the client
|
|
138
|
+
* asks again for the rest. A batch of more than {@link DATASET_BATCH_MAX} keys
|
|
139
|
+
* or runs is refused, and so is a key that is not a literal of the Dict's key
|
|
140
|
+
* type, naming it by its place, and runs that are not ascending, disjoint and
|
|
141
|
+
* inside the index.
|
|
142
|
+
*
|
|
143
|
+
* @param storage - Storage backend
|
|
144
|
+
* @param repoPath - Repository identifier
|
|
145
|
+
* @param workspace - Workspace name
|
|
146
|
+
* @param treePath - The dataset's path: a Dict, or a record
|
|
147
|
+
* @param request - The keys, or the runs that name them, and the pin
|
|
148
|
+
* @param limits - The byte budget
|
|
149
|
+
* @returns The rows, or a JSON refusal
|
|
150
|
+
*/
|
|
151
|
+
export async function getDatasetRows(storage, repoPath, workspace, treePath, request, limits = {}) {
|
|
152
|
+
try {
|
|
153
|
+
if ('keysOf' in request)
|
|
154
|
+
return await rowsOfRuns(storage, repoPath, workspace, treePath, request, limits);
|
|
155
|
+
if (request.keys.length > DATASET_BATCH_MAX) {
|
|
156
|
+
return pageError('bad_request', `A read of rows by key takes at most ${DATASET_BATCH_MAX} keys; this one has ${request.keys.length}`);
|
|
157
|
+
}
|
|
158
|
+
const dataset = await readDataset(storage, repoPath, workspace, treePath, request.hash, 'a read of rows by key');
|
|
159
|
+
if (dataset instanceof Response)
|
|
160
|
+
return dataset;
|
|
161
|
+
if (dataset.typeValue.type !== 'Dict') {
|
|
162
|
+
return pageError('dataset_not_searchable', `A read of rows by key addresses a Dict; this dataset holds ${dataset.typeValue.type}`);
|
|
163
|
+
}
|
|
164
|
+
const { key: keyType, value: rowType } = dataset.typeValue.value;
|
|
165
|
+
const parse = parseFor(keyType);
|
|
166
|
+
const keys = [];
|
|
167
|
+
for (const [i, literal] of request.keys.entries()) {
|
|
168
|
+
const parsed = parse(literal);
|
|
169
|
+
if (!parsed.success)
|
|
170
|
+
return pageError('key_parse_error', `key ${i}: ${parsed.error}`);
|
|
171
|
+
keys.push(parsed.value);
|
|
172
|
+
}
|
|
173
|
+
const segments = await openForRead(storage, repoPath, dataset.hash, dataset.size);
|
|
174
|
+
if (segments instanceof Response)
|
|
175
|
+
return segments;
|
|
176
|
+
// The rows' share of the budget, by the Dict's average row size.
|
|
177
|
+
const byteBudget = limits.byteBudget ?? PAGE_BYTE_BUDGET_DEFAULT;
|
|
178
|
+
const avgBytes = segments.elementCount > 0 ? segments.bytes / segments.elementCount : 1;
|
|
179
|
+
const limit = Math.min(keys.length, Math.max(1, Math.floor(byteBudget / Math.max(1, avgBytes))));
|
|
180
|
+
const asked = keys.slice(0, limit);
|
|
181
|
+
let answers;
|
|
182
|
+
try {
|
|
183
|
+
answers = await rowsAt(storage, repoPath, segments, asked, keyType);
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
return corruptRefusal(err, 'dataset_not_canonical');
|
|
187
|
+
}
|
|
188
|
+
const body = encodeBeast2For(datasetRowsType(fromEastTypeValue(keyType), fromEastTypeValue(rowType)))(answers);
|
|
189
|
+
return new Response(body, {
|
|
190
|
+
status: 200,
|
|
191
|
+
headers: {
|
|
192
|
+
'Content-Type': BEAST2_CONTENT_TYPE,
|
|
193
|
+
'Cache-Control': 'no-store',
|
|
194
|
+
'X-Content-SHA256': dataset.hash,
|
|
195
|
+
'X-Total-Elements': String(segments.elementCount),
|
|
196
|
+
'X-Page-Count': String(answers.length),
|
|
197
|
+
'Content-Length': String(body.byteLength),
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
catch (err) {
|
|
202
|
+
return sendJsonError(err);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/** A Dict's rows under the keys the entries of some runs of a record's index name: {@link getDatasetRows}'s runs form. */
|
|
206
|
+
async function rowsOfRuns(storage, repoPath, workspace, treePath, request, limits) {
|
|
207
|
+
const { keysOf } = request;
|
|
208
|
+
if (keysOf.runs.length > DATASET_BATCH_MAX) {
|
|
209
|
+
return pageError('bad_request', `A read of rows by runs takes at most ${DATASET_BATCH_MAX} runs; this one has ${keysOf.runs.length}`);
|
|
210
|
+
}
|
|
211
|
+
if (keysOf.path.length === 0) {
|
|
212
|
+
return pageError('bad_request', 'A read of rows by runs names the record its runs are of: { "keysOf": { "path": ".<record>", … } }');
|
|
213
|
+
}
|
|
214
|
+
const dataset = await readDataset(storage, repoPath, workspace, treePath, request.hash, 'a read of rows by key');
|
|
215
|
+
if (dataset instanceof Response)
|
|
216
|
+
return dataset;
|
|
217
|
+
if (dataset.typeValue.type !== 'Dict') {
|
|
218
|
+
return pageError('dataset_not_searchable', `A read of rows by key addresses a Dict; this dataset holds ${dataset.typeValue.type}`);
|
|
219
|
+
}
|
|
220
|
+
const { key: keyType, value: rowType } = dataset.typeValue.value;
|
|
221
|
+
// The record the runs are positions in, pinned apart from the Dict: refused in its own words, so a client knows which moved.
|
|
222
|
+
const refPath = keysOf.path.map((segment) => segment.value).join('/');
|
|
223
|
+
const status = await workspaceGetDatasetStatus(storage, repoPath, workspace, keysOf.path);
|
|
224
|
+
const held = status.refType === 'unassigned' || status.refType === 'null' ? null : status.hash ?? null;
|
|
225
|
+
if (held !== keysOf.hash) {
|
|
226
|
+
return pageError('runs_hash_mismatch', `Dataset '${refPath}' content is ${held ?? 'no value'}, not ${keysOf.hash}: the runs are positions at content it no longer holds — refetch its status and read its runs again`, 409, held === null ? undefined : { 'X-Content-SHA256': held });
|
|
227
|
+
}
|
|
228
|
+
const resolved = await indexOf(storage, repoPath, workspace, keysOf.path, keysOf.hash, keysOf.index);
|
|
229
|
+
if (resolved instanceof Response)
|
|
230
|
+
return resolved;
|
|
231
|
+
if (resolved.summary) {
|
|
232
|
+
return pageError('bad_request', `index '${keysOf.index}' of '${refPath}' is a summary: each entry stands for every row of its key and names none to read the rows of`);
|
|
233
|
+
}
|
|
234
|
+
const recordKeyType = resolved.primaryType.value.key;
|
|
235
|
+
if (!isTypeValueEqual(recordKeyType, keyType)) {
|
|
236
|
+
return pageError('bad_request', `index '${keysOf.index}' of '${refPath}' names keys of ${printType(fromEastTypeValue(recordKeyType))}, and this Dict's keys are ${printType(fromEastTypeValue(keyType))}`);
|
|
237
|
+
}
|
|
238
|
+
const index = await cachedSegments(storage, repoPath, resolved.manifest, (await storage.objects.stat(repoPath, resolved.manifest)).size);
|
|
239
|
+
const refused = runsRefusal(keysOf.runs, index.elementCount);
|
|
240
|
+
if (refused !== undefined)
|
|
241
|
+
return pageError('bad_request', refused);
|
|
242
|
+
const entries = keysOf.runs.reduce((sum, [, count]) => sum + count, 0);
|
|
243
|
+
const segments = await openForRead(storage, repoPath, dataset.hash, dataset.size);
|
|
244
|
+
if (segments instanceof Response)
|
|
245
|
+
return segments;
|
|
246
|
+
// A page's bounds: its entries, and the rows' share of the budget by the Dict's average row size.
|
|
247
|
+
const byteBudget = limits.byteBudget ?? PAGE_BYTE_BUDGET_DEFAULT;
|
|
248
|
+
const avgBytes = segments.elementCount > 0 ? segments.bytes / segments.elementCount : 1;
|
|
249
|
+
const limit = Math.max(1, Math.min(PAGE_MAX_LIMIT, Math.floor(byteBudget / Math.max(1, avgBytes))));
|
|
250
|
+
const spans = [];
|
|
251
|
+
let room = limit;
|
|
252
|
+
for (const [row, count] of keysOf.runs) {
|
|
253
|
+
if (room === 0)
|
|
254
|
+
break;
|
|
255
|
+
const taken = Math.min(count, room);
|
|
256
|
+
spans.push({ from: row, to: row + taken });
|
|
257
|
+
room -= taken;
|
|
258
|
+
}
|
|
259
|
+
let answers;
|
|
260
|
+
try {
|
|
261
|
+
const pairs = await elementsOf(storage, repoPath, index, spans);
|
|
262
|
+
answers = await rowsAt(storage, repoPath, segments, pairs.map(([entry]) => entry.k), keyType);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
return corruptRefusal(err, 'dataset_not_canonical');
|
|
266
|
+
}
|
|
267
|
+
const body = encodeBeast2For(datasetRowsType(fromEastTypeValue(keyType), fromEastTypeValue(rowType)))(answers);
|
|
268
|
+
return new Response(body, {
|
|
269
|
+
status: 200,
|
|
270
|
+
headers: {
|
|
271
|
+
'Content-Type': BEAST2_CONTENT_TYPE,
|
|
272
|
+
'Cache-Control': 'no-store',
|
|
273
|
+
'X-Content-SHA256': dataset.hash,
|
|
274
|
+
'X-Total-Elements': String(segments.elementCount),
|
|
275
|
+
'X-Page-Count': String(answers.length),
|
|
276
|
+
'X-Run-Entries': String(entries),
|
|
277
|
+
'Content-Length': String(body.byteLength),
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/** Each key's row, or its absence, and its position, from the segments that
|
|
282
|
+
* can hold the keys, each read once. */
|
|
283
|
+
async function rowsAt(storage, repoPath, segments, keys, keyType) {
|
|
284
|
+
if (segments.segmentCount === 0)
|
|
285
|
+
return keys.map((key) => ({ key, row: none, position: 0n }));
|
|
286
|
+
const cmp = comparators(keyType);
|
|
287
|
+
const owners = await Promise.all(keys.map((key) => segments.segmentFor(key)));
|
|
288
|
+
const decoded = await decodedSegments(storage, repoPath, segments, owners);
|
|
289
|
+
return keys.map((key, i) => {
|
|
290
|
+
const owner = owners[i];
|
|
291
|
+
const segment = decoded.get(owner);
|
|
292
|
+
const base = owner === 0 ? 0 : segments.cumulative[owner - 1];
|
|
293
|
+
const at = firstWhere(segment.keys, (held) => cmp(held, key) >= 0);
|
|
294
|
+
// A key past the segment's last sits where the next segment begins.
|
|
295
|
+
if (at < segment.keys.length && cmp(segment.keys[at], key) === 0) {
|
|
296
|
+
return { key: segment.keys[at], row: some(segment.values[at]), position: BigInt(base + at) };
|
|
297
|
+
}
|
|
298
|
+
return { key, row: none, position: BigInt(base + at) };
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Why a batch's runs are not runs of a collection's rows, or `undefined` when
|
|
303
|
+
* they are: each `[row, count]` a row at least 0 and a count at least 1,
|
|
304
|
+
* ascending and disjoint, and each inside the collection.
|
|
305
|
+
*
|
|
306
|
+
* @param runs - The runs, as a batch names them
|
|
307
|
+
* @param total - The collection's row count
|
|
308
|
+
* @returns The refusal's words, naming the run by its place, or `undefined`
|
|
309
|
+
*/
|
|
310
|
+
export function runsRefusal(runs, total) {
|
|
311
|
+
let end = 0;
|
|
312
|
+
for (const [i, [row, count]] of runs.entries()) {
|
|
313
|
+
if (!Number.isSafeInteger(row) || !Number.isSafeInteger(count) || row < 0 || count < 1) {
|
|
314
|
+
return `run ${i} is [${row}, ${count}]: a run is a row at least 0 and a count at least 1`;
|
|
315
|
+
}
|
|
316
|
+
if (row < end)
|
|
317
|
+
return `run ${i} starts at row ${row}, before the run before it ends (${end}): runs are ascending and disjoint`;
|
|
318
|
+
if (row + count > total)
|
|
319
|
+
return `run ${i} ends at row ${row + count}, past the collection's ${total} rows`;
|
|
320
|
+
end = row + count;
|
|
321
|
+
}
|
|
322
|
+
return undefined;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Read the entries of several runs of a collection's rows in one request, in
|
|
326
|
+
* order, as one window: of an index, the window an index page answers
|
|
327
|
+
* (`Array<{ik, key, value, row}>`); of the dataset itself, a value of its own
|
|
328
|
+
* type holding exactly the runs' rows.
|
|
329
|
+
*
|
|
330
|
+
* @remarks
|
|
331
|
+
* The runs' rows are placed in their segments by the manifest's counts, which
|
|
332
|
+
* reads nothing, and every segment they touch is read once, several at a time,
|
|
333
|
+
* through the decoded segments the API process keeps; a joined read places
|
|
334
|
+
* each row's key in its primary segment by the primary's fences, and reads
|
|
335
|
+
* each such segment once.
|
|
336
|
+
*
|
|
337
|
+
* The answer is held to a page's bounds — {@link PAGE_MAX_LIMIT} entries, and
|
|
338
|
+
* the page byte budget by the average entry (and, joined, row) size: past
|
|
339
|
+
* them, it holds the entries it completed, in order, and says how many
|
|
340
|
+
* (`X-Page-Count`) of how many the runs hold (`X-Run-Entries`). The client asks
|
|
341
|
+
* again for the rest, the runs it named less the entries it has. Runs that are
|
|
342
|
+
* not ascending, disjoint and inside the collection are refused, as are more
|
|
343
|
+
* than {@link DATASET_BATCH_MAX} of them.
|
|
344
|
+
*
|
|
345
|
+
* @param storage - Storage backend
|
|
346
|
+
* @param repoPath - Repository identifier
|
|
347
|
+
* @param workspace - Workspace name
|
|
348
|
+
* @param treePath - The dataset's path
|
|
349
|
+
* @param request - The runs, the pin, and the index read through
|
|
350
|
+
* @param limits - The byte budget
|
|
351
|
+
* @returns The window, or a JSON refusal
|
|
352
|
+
*/
|
|
353
|
+
export async function getDatasetRuns(storage, repoPath, workspace, treePath, request, limits = {}) {
|
|
354
|
+
try {
|
|
355
|
+
if (request.runs.length > DATASET_BATCH_MAX) {
|
|
356
|
+
return pageError('bad_request', `A read of runs takes at most ${DATASET_BATCH_MAX} runs; this one has ${request.runs.length}`);
|
|
357
|
+
}
|
|
358
|
+
if (request.join === true && request.index === undefined) {
|
|
359
|
+
return pageError('bad_request', 'join fills an index entry\'s row from the record: name the index the runs are rows of');
|
|
360
|
+
}
|
|
361
|
+
const dataset = await readDataset(storage, repoPath, workspace, treePath, request.hash, 'a read of runs');
|
|
362
|
+
if (dataset instanceof Response)
|
|
363
|
+
return dataset;
|
|
364
|
+
const kind = dataset.typeValue.type;
|
|
365
|
+
if (kind !== 'Array' && kind !== 'Set' && kind !== 'Dict') {
|
|
366
|
+
return pageError('dataset_not_pageable', `Paged reads address Array, Set or Dict datasets; this dataset holds ${kind}`);
|
|
367
|
+
}
|
|
368
|
+
const resolved = request.index === undefined ? undefined
|
|
369
|
+
: await indexOf(storage, repoPath, workspace, treePath, dataset.hash, request.index, request.join === true);
|
|
370
|
+
if (resolved instanceof Response)
|
|
371
|
+
return resolved;
|
|
372
|
+
const collection = resolved === undefined
|
|
373
|
+
? await openForRead(storage, repoPath, dataset.hash, dataset.size)
|
|
374
|
+
: await cachedSegments(storage, repoPath, resolved.manifest, (await storage.objects.stat(repoPath, resolved.manifest)).size);
|
|
375
|
+
if (collection instanceof Response)
|
|
376
|
+
return collection;
|
|
377
|
+
const primary = resolved !== undefined && request.join === true
|
|
378
|
+
? await cachedSegments(storage, repoPath, resolved.primary, (await storage.objects.stat(repoPath, resolved.primary)).size)
|
|
379
|
+
: null;
|
|
380
|
+
const total = collection.elementCount;
|
|
381
|
+
const refused = runsRefusal(request.runs, total);
|
|
382
|
+
if (refused !== undefined)
|
|
383
|
+
return pageError('bad_request', refused);
|
|
384
|
+
const entries = request.runs.reduce((sum, [, count]) => sum + count, 0);
|
|
385
|
+
// A page's bounds: the entries' share of the budget by their average
|
|
386
|
+
// size, and a joined read's by the record's rows' too.
|
|
387
|
+
const byteBudget = limits.byteBudget ?? PAGE_BYTE_BUDGET_DEFAULT;
|
|
388
|
+
const perEntry = (primary !== null && primary.elementCount > 0 ? primary.bytes / primary.elementCount : 0)
|
|
389
|
+
+ (total > 0 ? collection.bytes / total : 1);
|
|
390
|
+
const limit = Math.max(1, Math.min(PAGE_MAX_LIMIT, Math.floor(byteBudget / Math.max(1, perEntry))));
|
|
391
|
+
const spans = [];
|
|
392
|
+
let room = limit;
|
|
393
|
+
for (const [row, count] of request.runs) {
|
|
394
|
+
if (room === 0)
|
|
395
|
+
break;
|
|
396
|
+
const taken = Math.min(count, room);
|
|
397
|
+
spans.push({ from: row, to: row + taken });
|
|
398
|
+
room -= taken;
|
|
399
|
+
}
|
|
400
|
+
let windowValue;
|
|
401
|
+
let answered;
|
|
402
|
+
let windowType;
|
|
403
|
+
try {
|
|
404
|
+
const elements = await elementsOf(storage, repoPath, collection, spans);
|
|
405
|
+
answered = elements.length;
|
|
406
|
+
if (resolved === undefined) {
|
|
407
|
+
windowValue = collectionOf(dataset.typeValue, elements);
|
|
408
|
+
windowType = dataset.typeValue;
|
|
409
|
+
}
|
|
410
|
+
else {
|
|
411
|
+
const pairs = elements;
|
|
412
|
+
const rows = primary !== null
|
|
413
|
+
? await rowsByKey(storage, repoPath, primary, pairs.map(([entry]) => entry.k))
|
|
414
|
+
: pairs.map(() => none);
|
|
415
|
+
windowValue = pairs.map(([entry, value], i) => ({ ik: entry.ik, key: entry.k, value, row: rows[i] }));
|
|
416
|
+
windowType = resolved.windowType;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
catch (err) {
|
|
420
|
+
return corruptRefusal(err, 'dataset_not_canonical');
|
|
421
|
+
}
|
|
422
|
+
const body = encodeBeast2For(windowType)(windowValue);
|
|
423
|
+
return new Response(body, {
|
|
424
|
+
status: 200,
|
|
425
|
+
headers: {
|
|
426
|
+
'Content-Type': BEAST2_CONTENT_TYPE,
|
|
427
|
+
'Cache-Control': 'no-store',
|
|
428
|
+
'X-Content-SHA256': dataset.hash,
|
|
429
|
+
'X-Total-Elements': String(total),
|
|
430
|
+
'X-Page-Count': String(answered),
|
|
431
|
+
'X-Run-Entries': String(entries),
|
|
432
|
+
...(request.index !== undefined && { 'X-Window-Index': request.index }),
|
|
433
|
+
...(request.join === true && { 'X-Window-Joined': 'true' }),
|
|
434
|
+
'Content-Length': String(body.byteLength),
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
catch (err) {
|
|
439
|
+
return sendJsonError(err);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
//# sourceMappingURL=dataset-batches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-batches.js","sourceRoot":"","sources":["../../../src/handlers/dataset-batches.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,eAAe,EAAE,iBAAiB,EAAE,gBAAgB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AAE,MAAM,CAAC,OAAO,CAAC;gBAChC,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC;gBACvE,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,CAAC;gBAC3D,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;aAC1C;SACF,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { TreePath } from '@elaraai/e3-types';
|
|
6
|
+
import type { StorageBackend } from '@elaraai/e3-core/portable';
|
|
7
|
+
import { type DatasetBatchLimits } from './dataset-batches.js';
|
|
8
|
+
/** What a placement places, for {@link placeDatasetRuns}. */
|
|
9
|
+
export interface DatasetPlaceRequest {
|
|
10
|
+
/** The index the runs are rows of. */
|
|
11
|
+
index: string;
|
|
12
|
+
/** The narrowing's runs of the index's rows, `[row, count]`: ascending,
|
|
13
|
+
* disjoint, each inside the index — at most {@link DATASET_BATCH_MAX}. */
|
|
14
|
+
runs: readonly (readonly [number, number])[];
|
|
15
|
+
/** The runs' first entry the placement places, counting through them as one
|
|
16
|
+
* sequence (0 when absent). */
|
|
17
|
+
offset?: number;
|
|
18
|
+
/** How many of the runs' entries it places at most; a page's bounds clamp it. */
|
|
19
|
+
limit?: number;
|
|
20
|
+
/** The record's content hash the runs are positions at: a stale one is
|
|
21
|
+
* refused with 409. */
|
|
22
|
+
hash: string;
|
|
23
|
+
}
|
|
24
|
+
/** A record segment a placement's entries fall in. */
|
|
25
|
+
export interface DatasetPlacedSegment {
|
|
26
|
+
/** The segment's number in the record's manifest. */
|
|
27
|
+
segment: number;
|
|
28
|
+
/** Its first row in the record's order. */
|
|
29
|
+
offset: number;
|
|
30
|
+
/** How many rows it holds. */
|
|
31
|
+
count: number;
|
|
32
|
+
/** How many of the placement's entries it holds. */
|
|
33
|
+
rows: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Place a window of a narrowing's runs in a record: how many of the window's
|
|
37
|
+
* entries each record segment holds.
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* The window's entries are read from the index's own segments, with no join,
|
|
41
|
+
* as a covering index page reads them, and each entry's row — its primary key,
|
|
42
|
+
* `k` — is placed in the record segment that holds it by a bisect of the
|
|
43
|
+
* record's fences, which come with its manifest: no record segment is read.
|
|
44
|
+
*
|
|
45
|
+
* The window is a page's at most: {@link PAGE_MAX_LIMIT} entries, and the page
|
|
46
|
+
* byte budget by the index's average entry. Responds with JSON
|
|
47
|
+
* `{ segments: [{ segment, offset, count, rows }], placed }`, the segments in
|
|
48
|
+
* the record's order and only those that hold some of the window's entries,
|
|
49
|
+
* `placed` how many entries it places: the caller asks again from `offset +
|
|
50
|
+
* placed`. A record Slice's runs name each row once, so a segment's rows over
|
|
51
|
+
* every window add up to the narrowing's rows in it. A summary index is
|
|
52
|
+
* refused 400, naming it: its entries stand for many rows and name none to place.
|
|
53
|
+
*
|
|
54
|
+
* @param storage - Storage backend
|
|
55
|
+
* @param repoPath - Repository identifier
|
|
56
|
+
* @param workspace - Workspace name
|
|
57
|
+
* @param treePath - The record's path
|
|
58
|
+
* @param request - The index, its runs, the window and the pin
|
|
59
|
+
* @param limits - The byte budget
|
|
60
|
+
* @returns The placement, or a JSON refusal
|
|
61
|
+
*/
|
|
62
|
+
export declare function placeDatasetRuns(storage: StorageBackend, repoPath: string, workspace: string, treePath: TreePath, request: DatasetPlaceRequest, limits?: DatasetBatchLimits): Promise<Response>;
|
|
63
|
+
/** What a membership read asks, for {@link withinDatasetRuns}. */
|
|
64
|
+
export interface DatasetWithinRequest {
|
|
65
|
+
/** The index the runs are rows of. */
|
|
66
|
+
index: string;
|
|
67
|
+
/** The narrowing's runs of the index's rows, `[row, count]`: ascending,
|
|
68
|
+
* disjoint, each inside the index — at most {@link DATASET_BATCH_MAX}. */
|
|
69
|
+
runs: readonly (readonly [number, number])[];
|
|
70
|
+
/** `.east` literals of index entries' keys, `(ik=…, k=…)` — each row's
|
|
71
|
+
* maintained index key beside its primary key — answered in this order: at
|
|
72
|
+
* most {@link DATASET_BATCH_MAX}. */
|
|
73
|
+
keys: readonly string[];
|
|
74
|
+
/** The record's content hash the runs are positions at: a stale one is
|
|
75
|
+
* refused with 409. */
|
|
76
|
+
hash: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Answer which of some index entries a narrowing's runs hold: for each entry
|
|
80
|
+
* key, whether it lies in one of the runs.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* Each run is a contiguous stretch of the index's rows, so an entry lies in it
|
|
84
|
+
* when it falls between the run's first and last entries in the index's
|
|
85
|
+
* order. Only those boundary entries are read — at most two index segments a
|
|
86
|
+
* run — and every key is placed among them by the index entry key's
|
|
87
|
+
* comparator: nothing else is decoded, and nothing is evaluated over a row. A
|
|
88
|
+
* row is in the narrowing when any of its entries is.
|
|
89
|
+
*
|
|
90
|
+
* Responds with JSON `{ within: [boolean, …] }`, one a key, in order. More than
|
|
91
|
+
* {@link DATASET_BATCH_MAX} keys or runs, runs that are not ascending, disjoint
|
|
92
|
+
* and inside the index, and a key that is not a literal of the index's entry
|
|
93
|
+
* key type are refused, naming what is wrong — and so is a summary index, whose
|
|
94
|
+
* entries stand for many rows and name none whose membership to answer.
|
|
95
|
+
*
|
|
96
|
+
* @param storage - Storage backend
|
|
97
|
+
* @param repoPath - Repository identifier
|
|
98
|
+
* @param workspace - Workspace name
|
|
99
|
+
* @param treePath - The record's path
|
|
100
|
+
* @param request - The index, its runs, the entry keys and the pin
|
|
101
|
+
* @returns The answers, or a JSON refusal
|
|
102
|
+
*/
|
|
103
|
+
export declare function withinDatasetRuns(storage: StorageBackend, repoPath: string, workspace: string, treePath: TreePath, request: DatasetWithinRequest): Promise<Response>;
|
|
104
|
+
//# sourceMappingURL=dataset-place.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataset-place.d.ts","sourceRoot":"","sources":["../../../src/handlers/dataset-place.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuBH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEjF,OAAO,EAAkC,KAAK,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAM/F,6DAA6D;AAC7D,MAAM,WAAW,mBAAmB;IAClC,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd;+EAC2E;IAC3E,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC;IAC7C;oCACgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;4BACwB;IACxB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,sDAAsD;AACtD,MAAM,WAAW,oBAAoB;IACnC,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,cAAc,EACvB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ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