@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,351 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Key searches over a stored Set or Dict: a query compiled into the monotone
|
|
7
|
+
* bounds it locates, and the bounds of many queries located together, each
|
|
8
|
+
* segment they touch read once (#1351).
|
|
9
|
+
*
|
|
10
|
+
* Every form of a search addresses one contiguous row range in the canonical
|
|
11
|
+
* key order, so each is one or two monotone predicates — false, then true,
|
|
12
|
+
* over the keys in order — and a predicate's boundary row is found by a bisect
|
|
13
|
+
* of the manifest's fences, which reads nothing, then a binary search of the
|
|
14
|
+
* one segment that holds it. A search through an index addresses the index
|
|
15
|
+
* key, `ik`, and ranges bound the index collection's flattened key.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { compareFor, parseFor, some } from '@elaraai/east';
|
|
20
|
+
import { decodedSegments, firstWhere } from './segments.js';
|
|
21
|
+
/**
|
|
22
|
+
* A key type's leaves, in declaration order, recursing into nested structs.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Struct keys compare field by field in declaration order, so this flattening
|
|
26
|
+
* IS the key's sort order — which is what makes a bound on a leading prefix of
|
|
27
|
+
* it one contiguous row range. A scalar key flattens to one leaf with an empty
|
|
28
|
+
* path.
|
|
29
|
+
*/
|
|
30
|
+
function flattenKeyFields(keyType) {
|
|
31
|
+
if (keyType.type !== 'Struct')
|
|
32
|
+
return [{ path: [], type: keyType }];
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const field of keyType.value) {
|
|
35
|
+
for (const leaf of flattenKeyFields(field.type)) {
|
|
36
|
+
out.push({ path: [field.name, ...leaf.path], type: leaf.type });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/** The value at a flattened field path. */
|
|
42
|
+
function fieldAt(key, path) {
|
|
43
|
+
let value = key;
|
|
44
|
+
for (const segment of path)
|
|
45
|
+
value = value[segment];
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A monotone "is this key at or past the bound?" predicate over a leading
|
|
50
|
+
* prefix of the flattened key.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* Monotone over the canonical key order because it reads only the leading
|
|
54
|
+
* fields, which are exactly the ones the order sorts by first — so one fence
|
|
55
|
+
* bisect finds its boundary row, and a pair of them bound one contiguous
|
|
56
|
+
* range.
|
|
57
|
+
*/
|
|
58
|
+
function boundPredicate(leaves, values) {
|
|
59
|
+
const comparators = leaves.slice(0, values.length).map((leaf) => compareFor(leaf.type));
|
|
60
|
+
return (key) => {
|
|
61
|
+
for (let i = 0; i < values.length; i++) {
|
|
62
|
+
const order = comparators[i](fieldAt(key, leaves[i].path), values[i]);
|
|
63
|
+
if (order !== 0)
|
|
64
|
+
return order > 0;
|
|
65
|
+
}
|
|
66
|
+
return true; // equal on the prefix: at the bound, so past it
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Compiles a key search against a collection: its bounds, or why it cannot be
|
|
71
|
+
* searched.
|
|
72
|
+
*
|
|
73
|
+
* @param query - The search
|
|
74
|
+
* @param target - The collection's key type, and whether it is an index
|
|
75
|
+
* @returns The compiled search, or the refusal a route answers it with
|
|
76
|
+
*/
|
|
77
|
+
export function compileKeySearch(query, target) {
|
|
78
|
+
const { keyType: keyTypeValue, indexed, keysNoun } = target;
|
|
79
|
+
// Through an index, the key, prefix and fields forms address the index key
|
|
80
|
+
// `ik` — the key a client holds, as the record's signature names it — not
|
|
81
|
+
// the collection's `{ik, k}`, which pairs it with each row's own key. The
|
|
82
|
+
// collection sorts by `ik` first, so a predicate over it is monotone over
|
|
83
|
+
// the collection's order. The range form bounds the collection's
|
|
84
|
+
// flattened key, which begins inside `ik`.
|
|
85
|
+
const formKeyType = indexed
|
|
86
|
+
? keyTypeValue.value.find((f) => f.name === 'ik').type
|
|
87
|
+
: keyTypeValue;
|
|
88
|
+
const formKey = indexed ? (k) => k.ik : (k) => k;
|
|
89
|
+
const fields = query.fields !== undefined && query.fields.length > 0 ? query.fields : undefined;
|
|
90
|
+
const ranged = (query.from !== undefined && query.from.length > 0) || (query.to !== undefined && query.to.length > 0);
|
|
91
|
+
const forms = [query.key !== undefined, query.prefix !== undefined || fields !== undefined, ranged];
|
|
92
|
+
if (forms.filter(Boolean).length !== 1) {
|
|
93
|
+
return { type: 'bad_request', message: 'Pass a key literal, or a prefix and/or leading fields, or a from/to range — exactly one form' };
|
|
94
|
+
}
|
|
95
|
+
// The range form's bounds are leading prefixes of the FLATTENED key, which
|
|
96
|
+
// is the order the collection is sorted in, so each bounds one contiguous
|
|
97
|
+
// row range.
|
|
98
|
+
const leaves = flattenKeyFields(keyTypeValue);
|
|
99
|
+
const parseBound = (label, literals) => {
|
|
100
|
+
if (literals === undefined || literals.length === 0)
|
|
101
|
+
return { values: [] };
|
|
102
|
+
if (literals.length > leaves.length) {
|
|
103
|
+
return {
|
|
104
|
+
type: 'bad_request',
|
|
105
|
+
message: `${label} names ${literals.length} key fields, but the key flattens to ${leaves.length}: `
|
|
106
|
+
+ leaves.map((leaf) => leaf.path.join('.') || '(the key)').join(', '),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const values = [];
|
|
110
|
+
for (let i = 0; i < literals.length; i++) {
|
|
111
|
+
const parsed = parseFor(leaves[i].type)(literals[i]);
|
|
112
|
+
if (!parsed.success) {
|
|
113
|
+
return { type: 'key_parse_error', message: `${label} field '${leaves[i].path.join('.') || '(the key)'}': ${parsed.error}` };
|
|
114
|
+
}
|
|
115
|
+
values.push(parsed.value);
|
|
116
|
+
}
|
|
117
|
+
return { values };
|
|
118
|
+
};
|
|
119
|
+
const lowerBound = parseBound('from', query.from);
|
|
120
|
+
if ('type' in lowerBound)
|
|
121
|
+
return lowerBound;
|
|
122
|
+
const upperBound = parseBound('to', query.to);
|
|
123
|
+
if ('type' in upperBound)
|
|
124
|
+
return upperBound;
|
|
125
|
+
const structMeta = formKeyType.type === 'Struct'
|
|
126
|
+
? formKeyType.value
|
|
127
|
+
: null;
|
|
128
|
+
if (fields !== undefined) {
|
|
129
|
+
if (structMeta === null) {
|
|
130
|
+
return { type: 'bad_request', message: `Leading-field search addresses Struct keys; ${keysNoun} are ${formKeyType.type}` };
|
|
131
|
+
}
|
|
132
|
+
if (fields.length > structMeta.length) {
|
|
133
|
+
return { type: 'bad_request', message: `Key has ${structMeta.length} fields, got ${fields.length}` };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const fieldValues = [];
|
|
137
|
+
if (fields !== undefined && structMeta !== null) {
|
|
138
|
+
for (let j = 0; j < fields.length; j++) {
|
|
139
|
+
const parsed = parseFor(structMeta[j].type)(fields[j]);
|
|
140
|
+
if (!parsed.success) {
|
|
141
|
+
return { type: 'key_parse_error', message: `field '${structMeta[j].name}': ${parsed.error}` };
|
|
142
|
+
}
|
|
143
|
+
fieldValues.push(parsed.value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
let optionalPrefix = false;
|
|
147
|
+
let prefixValue = query.prefix;
|
|
148
|
+
if (query.prefix !== undefined) {
|
|
149
|
+
const prefixIdx = fieldValues.length;
|
|
150
|
+
const prefixFieldType = structMeta !== null
|
|
151
|
+
? (prefixIdx < structMeta.length ? structMeta[prefixIdx].type : undefined)
|
|
152
|
+
: formKeyType;
|
|
153
|
+
if (prefixFieldType === undefined) {
|
|
154
|
+
return { type: 'bad_request', message: `All ${structMeta.length} key fields are exact — nothing left for a prefix` };
|
|
155
|
+
}
|
|
156
|
+
if (prefixFieldType.type === 'Variant') {
|
|
157
|
+
const cases = prefixFieldType.value;
|
|
158
|
+
optionalPrefix = cases.length === 2
|
|
159
|
+
&& cases.some(c => c.name === 'none' && c.type.type === 'Null')
|
|
160
|
+
&& cases.some(c => c.name === 'some' && c.type.type === 'String');
|
|
161
|
+
}
|
|
162
|
+
if (prefixFieldType.type !== 'String' && !optionalPrefix) {
|
|
163
|
+
return {
|
|
164
|
+
type: 'bad_request',
|
|
165
|
+
message: structMeta !== null
|
|
166
|
+
? `prefix continues key field '${structMeta[prefixIdx].name}', which is ${prefixFieldType.type}, not String or Option<String>`
|
|
167
|
+
: `prefix search needs String or Option<String> keys; ${keysNoun} are ${formKeyType.type}`,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
if (optionalPrefix)
|
|
171
|
+
prefixValue = some(query.prefix);
|
|
172
|
+
}
|
|
173
|
+
const matchesPrefix = (value) => {
|
|
174
|
+
if (!optionalPrefix)
|
|
175
|
+
return value.startsWith(query.prefix);
|
|
176
|
+
const option = value;
|
|
177
|
+
return option.type === 'some' && option.value.startsWith(query.prefix);
|
|
178
|
+
};
|
|
179
|
+
let keyValue;
|
|
180
|
+
if (query.key !== undefined) {
|
|
181
|
+
const parsed = parseFor(formKeyType)(query.key);
|
|
182
|
+
if (!parsed.success) {
|
|
183
|
+
return { type: 'key_parse_error', message: parsed.error };
|
|
184
|
+
}
|
|
185
|
+
keyValue = parsed.value;
|
|
186
|
+
}
|
|
187
|
+
const cmp = compareFor(formKeyType);
|
|
188
|
+
if (ranged) {
|
|
189
|
+
// Two bisects, one contiguous range: `[from, to)` on the flattened
|
|
190
|
+
// prefix. An absent bound is the collection's own end.
|
|
191
|
+
const hasLower = query.from !== undefined && query.from.length > 0;
|
|
192
|
+
const hasUpper = query.to !== undefined && query.to.length > 0;
|
|
193
|
+
const bounds = [
|
|
194
|
+
...(hasLower ? [boundPredicate(leaves, lowerBound.values)] : []),
|
|
195
|
+
...(hasUpper ? [boundPredicate(leaves, upperBound.values)] : []),
|
|
196
|
+
];
|
|
197
|
+
return {
|
|
198
|
+
bounds,
|
|
199
|
+
answer(located, elementCount) {
|
|
200
|
+
const lower = hasLower ? located[0].row : 0;
|
|
201
|
+
const upper = hasUpper ? located[hasLower ? 1 : 0].row : elementCount;
|
|
202
|
+
const count = Math.max(0, upper - lower);
|
|
203
|
+
return { found: count > 0, row: lower, count };
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
if (query.key !== undefined) {
|
|
208
|
+
if (indexed) {
|
|
209
|
+
// An index holds an entry per row under a key, so a key is a run.
|
|
210
|
+
return {
|
|
211
|
+
bounds: [(k) => cmp(formKey(k), keyValue) >= 0, (k) => cmp(formKey(k), keyValue) > 0],
|
|
212
|
+
answer(located) {
|
|
213
|
+
const count = located[1].row - located[0].row;
|
|
214
|
+
return { found: count > 0, row: located[0].row, count };
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
bounds: [(k) => cmp(formKey(k), keyValue) >= 0],
|
|
220
|
+
answer(located) {
|
|
221
|
+
const at = located[0];
|
|
222
|
+
const found = at.hasKey && cmp(at.key, keyValue) === 0;
|
|
223
|
+
return { found, row: at.row, count: found ? 1 : 0 };
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// Range query — a String prefix, or a struct key's exact leading fields
|
|
228
|
+
// with an optional prefix on the next field. Both predicates depend only on
|
|
229
|
+
// the leading field tuple, and struct keys compare field-by-field in
|
|
230
|
+
// declaration order, so they are monotone over the canonical key order;
|
|
231
|
+
// prefix-extending strings form one contiguous interval in East
|
|
232
|
+
// (code-point) order.
|
|
233
|
+
let lowerPred;
|
|
234
|
+
let upperPred;
|
|
235
|
+
const prefix = query.prefix;
|
|
236
|
+
if (structMeta !== null) {
|
|
237
|
+
const fieldCmps = structMeta.map((f) => compareFor(f.type));
|
|
238
|
+
const lead = (k) => {
|
|
239
|
+
const key = formKey(k);
|
|
240
|
+
for (let j = 0; j < fieldValues.length; j++) {
|
|
241
|
+
const c = fieldCmps[j](key[structMeta[j].name], fieldValues[j]);
|
|
242
|
+
if (c !== 0)
|
|
243
|
+
return c;
|
|
244
|
+
}
|
|
245
|
+
return 0;
|
|
246
|
+
};
|
|
247
|
+
if (prefix === undefined) {
|
|
248
|
+
lowerPred = (k) => lead(k) >= 0;
|
|
249
|
+
upperPred = (k) => lead(k) > 0;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const prefixIdx = fieldValues.length;
|
|
253
|
+
const prefixName = structMeta[prefixIdx].name;
|
|
254
|
+
const prefixCmp = fieldCmps[prefixIdx];
|
|
255
|
+
lowerPred = (k) => {
|
|
256
|
+
const c = lead(k);
|
|
257
|
+
return c !== 0 ? c > 0 : prefixCmp(formKey(k)[prefixName], prefixValue) >= 0;
|
|
258
|
+
};
|
|
259
|
+
upperPred = (k) => {
|
|
260
|
+
const c = lead(k);
|
|
261
|
+
if (c !== 0)
|
|
262
|
+
return c > 0;
|
|
263
|
+
const field = formKey(k)[prefixName];
|
|
264
|
+
return prefixCmp(field, prefixValue) > 0 && !matchesPrefix(field);
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// Scalar String / Option<String> keys: none sorts before every
|
|
270
|
+
// some(String), so the same pair of monotone predicates bounds only
|
|
271
|
+
// present strings, including for an empty prefix.
|
|
272
|
+
lowerPred = (k) => cmp(formKey(k), prefixValue) >= 0;
|
|
273
|
+
upperPred = (k) => cmp(formKey(k), prefixValue) > 0 && !matchesPrefix(formKey(k));
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
bounds: [lowerPred, upperPred],
|
|
277
|
+
answer(located) {
|
|
278
|
+
const count = located[1].row - located[0].row;
|
|
279
|
+
return { found: count > 0, row: located[0].row, count };
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Where each of many monotone predicates first holds over a stored Set or
|
|
285
|
+
* Dict's keys, in canonical order — each segment the predicates land in read
|
|
286
|
+
* and decoded once, several at a time, and searched in by bisection.
|
|
287
|
+
*
|
|
288
|
+
* @remarks
|
|
289
|
+
* A predicate's segment is found by a bisect of the manifest's fences, which
|
|
290
|
+
* reads nothing: the greatest segment whose fence it does not hold at. Every
|
|
291
|
+
* segment so found is read once for all the predicates landing in it, through
|
|
292
|
+
* the kept decoded segments, and each predicate's row is a binary search of
|
|
293
|
+
* that segment's keys. When the boundary is the first row of a later segment,
|
|
294
|
+
* that segment's fence is the key there, and nothing more is read.
|
|
295
|
+
*
|
|
296
|
+
* @param storage - The backend the collection is read through
|
|
297
|
+
* @param repo - The repository it is in
|
|
298
|
+
* @param segments - The opened collection, a Set or a Dict
|
|
299
|
+
* @param preds - The predicates, each false, then true, over the keys in order
|
|
300
|
+
* @returns Each predicate's location, in order
|
|
301
|
+
*/
|
|
302
|
+
export async function locateAll(storage, repo, segments, preds) {
|
|
303
|
+
const located = new Array(preds.length);
|
|
304
|
+
const segmentCount = segments.segmentCount;
|
|
305
|
+
for (let p = 0; p < preds.length; p++) {
|
|
306
|
+
const pred = preds[p];
|
|
307
|
+
if (segmentCount === 0) {
|
|
308
|
+
located[p] = { row: 0, key: undefined, hasKey: false };
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const first = await segments.fence(0);
|
|
312
|
+
if (pred(first)) {
|
|
313
|
+
located[p] = { row: 0, key: first, hasKey: true };
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
// Greatest segment whose fence is before the boundary.
|
|
317
|
+
let lo = 0;
|
|
318
|
+
let hi = segmentCount - 1;
|
|
319
|
+
while (lo < hi) {
|
|
320
|
+
const mid = (lo + hi + 1) >> 1;
|
|
321
|
+
if (!pred(await segments.fence(mid)))
|
|
322
|
+
lo = mid;
|
|
323
|
+
else
|
|
324
|
+
hi = mid - 1;
|
|
325
|
+
}
|
|
326
|
+
located[p] = lo;
|
|
327
|
+
}
|
|
328
|
+
const decoded = await decodedSegments(storage, repo, segments, located.filter((entry) => typeof entry === 'number'));
|
|
329
|
+
const out = new Array(preds.length);
|
|
330
|
+
for (let p = 0; p < preds.length; p++) {
|
|
331
|
+
const entry = located[p];
|
|
332
|
+
if (typeof entry !== 'number') {
|
|
333
|
+
out[p] = entry;
|
|
334
|
+
continue;
|
|
335
|
+
}
|
|
336
|
+
const keys = decoded.get(entry).keys;
|
|
337
|
+
const at = firstWhere(keys, preds[p]);
|
|
338
|
+
const base = entry === 0 ? 0 : segments.cumulative[entry - 1];
|
|
339
|
+
if (at < keys.length) {
|
|
340
|
+
out[p] = { row: base + at, key: keys[at], hasKey: true };
|
|
341
|
+
}
|
|
342
|
+
else if (entry + 1 < segmentCount) {
|
|
343
|
+
out[p] = { row: segments.cumulative[entry], key: await segments.fence(entry + 1), hasKey: true };
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
out[p] = { row: segments.elementCount, key: undefined, hasKey: false };
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=key-search.js.map
|
|
@@ -0,0 +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AC;QACtC,MAAM,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;QACvC,MAAM,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAE,CAAC;QAC/D,IAAI,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YACrB,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,GAAG,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QAC3D,CAAC;aAAM,IAAI,KAAK,GAAG,CAAC,GAAG,YAAY,EAAE,CAAC;YACpC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAE,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACpG,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;QACzE,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Decoded segments, kept (#1351): what every dataset route reads a collection
|
|
7
|
+
* through.
|
|
8
|
+
*
|
|
9
|
+
* A collection is a manifest of segment objects, and a segment is the unit of
|
|
10
|
+
* every read: nothing reads inside one, so a window, a key search or a row
|
|
11
|
+
* looked up by its key costs that segment's read and decode. The routes read
|
|
12
|
+
* the segments a request touches here, several at a time, each once, and each
|
|
13
|
+
* decoded segment is kept by its content hash, bounded by its decoded weight —
|
|
14
|
+
* the measure every runtime's pager cache counts a segment by (east's
|
|
15
|
+
* `decodedWeightFor`) — so a pan, a repeated window or a second search of the
|
|
16
|
+
* same segment decodes nothing. A segment two requests ask for at once is
|
|
17
|
+
* read once, for both.
|
|
18
|
+
*
|
|
19
|
+
* A decoded segment is pure data, and it is decoded frozen: every request it
|
|
20
|
+
* serves shares it, and none can change what a later one is served. An entry
|
|
21
|
+
* is keyed by the backend it was read through and the repository it was read
|
|
22
|
+
* from as well as its hash, as the routes' cache of opened datasets is, so two
|
|
23
|
+
* backends, or two repositories, holding the same bytes never share one.
|
|
24
|
+
*
|
|
25
|
+
* @packageDocumentation
|
|
26
|
+
*/
|
|
27
|
+
import { type EastTypeValue } from '@elaraai/east';
|
|
28
|
+
import { type DatasetSegments, type StorageBackend } from '@elaraai/e3-core/portable';
|
|
29
|
+
/** How many segment objects one request reads at once. */
|
|
30
|
+
export declare const SEGMENT_READ_CONCURRENCY = 8;
|
|
31
|
+
/**
|
|
32
|
+
* The decoded weight the kept segments may hold between them, in bytes: 64
|
|
33
|
+
* MiB. The segment decoded last always stays, so one segment over the budget
|
|
34
|
+
* is still kept, alone.
|
|
35
|
+
*/
|
|
36
|
+
export declare const DECODED_SEGMENTS_MAX_WEIGHT: number;
|
|
37
|
+
/** One segment, decoded. */
|
|
38
|
+
export interface DecodedSegment {
|
|
39
|
+
/** The segment's collection, frozen: an array, a `SortedSet` or a `SortedMap`. */
|
|
40
|
+
readonly value: unknown;
|
|
41
|
+
/** A Set's elements or a Dict's keys, in order — what a search bisects. Empty
|
|
42
|
+
* for an Array, which has no key order. */
|
|
43
|
+
readonly keys: readonly unknown[];
|
|
44
|
+
/** A Dict's values, in its keys' order. Empty for a Set or an Array. */
|
|
45
|
+
readonly values: readonly unknown[];
|
|
46
|
+
/** How many elements (pairs, for a Dict) it holds. */
|
|
47
|
+
readonly count: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A storage backend's number, as the dataset routes' caches name it in their
|
|
51
|
+
* keys: every cache entry names the backend it was read through.
|
|
52
|
+
*
|
|
53
|
+
* @param storage - The backend
|
|
54
|
+
* @returns Its number, the same for as long as the backend lives
|
|
55
|
+
*/
|
|
56
|
+
export declare function backendIdOf(storage: StorageBackend): number;
|
|
57
|
+
/**
|
|
58
|
+
* Segment `i` of a collection, decoded: from the kept segments, or read and
|
|
59
|
+
* decoded once and kept.
|
|
60
|
+
*
|
|
61
|
+
* @param storage - The backend the collection is read through
|
|
62
|
+
* @param repo - The repository it is in
|
|
63
|
+
* @param segments - The opened collection
|
|
64
|
+
* @param i - The segment's index
|
|
65
|
+
* @returns The decoded segment
|
|
66
|
+
* @throws {SegmentCorruptError} When the segment does not hold what its manifest
|
|
67
|
+
* says of it: another element count, a first key that is not its fence, or
|
|
68
|
+
* a last key at or past the next segment's fence
|
|
69
|
+
*/
|
|
70
|
+
export declare function decodedSegment(storage: StorageBackend, repo: string, segments: DatasetSegments, i: number): Promise<DecodedSegment>;
|
|
71
|
+
/**
|
|
72
|
+
* The segments of a collection a request touches, decoded: each read once,
|
|
73
|
+
* {@link SEGMENT_READ_CONCURRENCY} at a time, through the kept segments.
|
|
74
|
+
*
|
|
75
|
+
* @param storage - The backend the collection is read through
|
|
76
|
+
* @param repo - The repository it is in
|
|
77
|
+
* @param segments - The opened collection
|
|
78
|
+
* @param indices - The segments, in any order, repeats and all
|
|
79
|
+
* @returns Each segment's decode, by its index
|
|
80
|
+
* @throws {SegmentCorruptError} When a segment does not hold what its manifest
|
|
81
|
+
* says of it
|
|
82
|
+
*/
|
|
83
|
+
export declare function decodedSegments(storage: StorageBackend, repo: string, segments: DatasetSegments, indices: Iterable<number>): Promise<Map<number, DecodedSegment>>;
|
|
84
|
+
/**
|
|
85
|
+
* A segment whose bytes do not decode as its collection's segment, or that
|
|
86
|
+
* does not hold what the collection's manifest says of it: the wire must hold
|
|
87
|
+
* the canonical value, split into disjoint ascending ranges, so such a segment
|
|
88
|
+
* is corrupt, or was written before that contract. A route answers it as the
|
|
89
|
+
* refusal of the read it was making: `dataset_not_canonical` for a window or a
|
|
90
|
+
* search, `dataset_not_segmented` for one writer segment.
|
|
91
|
+
*/
|
|
92
|
+
export declare class SegmentCorruptError extends Error {
|
|
93
|
+
constructor(message: string);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A key type's East comparator, built once per type object.
|
|
97
|
+
*
|
|
98
|
+
* @param keyType - The key type
|
|
99
|
+
* @returns Its comparator
|
|
100
|
+
*/
|
|
101
|
+
export declare function comparators(keyType: EastTypeValue): (a: unknown, b: unknown) => number;
|
|
102
|
+
/**
|
|
103
|
+
* The first index whose element satisfies a predicate that is false, then
|
|
104
|
+
* true, over the elements in order: a binary search.
|
|
105
|
+
*
|
|
106
|
+
* @param items - The elements, in order
|
|
107
|
+
* @param pred - The monotone predicate
|
|
108
|
+
* @returns The first index it holds at, or `items.length` when it holds at none
|
|
109
|
+
*/
|
|
110
|
+
export declare function firstWhere(items: readonly unknown[], pred: (item: unknown) => boolean): number;
|
|
111
|
+
/**
|
|
112
|
+
* What the kept segments have done, and what they hold now.
|
|
113
|
+
*
|
|
114
|
+
* @returns The decodes made, the reads the kept segments served, the segments
|
|
115
|
+
* kept, their decoded weight and the budget
|
|
116
|
+
*/
|
|
117
|
+
export declare function decodedSegmentStats(): {
|
|
118
|
+
decodes: number;
|
|
119
|
+
hits: number;
|
|
120
|
+
segments: number;
|
|
121
|
+
weight: number;
|
|
122
|
+
budget: number;
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=segments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../../src/handlers/segments.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;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