@gusto/baerly-storage 0.2.0 → 0.4.0
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/LICENSE +202 -0
- package/NOTICE +29 -0
- package/README.md +176 -70
- package/dist/API.md +213 -139
- package/dist/CHANGELOG.md +434 -0
- package/dist/RECIPES.md +125 -0
- package/dist/THIRD-PARTY-LICENSES.txt +238 -0
- package/dist/{app-config-C0Bbw_Z6.d.ts → app-config-DyiFK3_k.d.ts} +55 -11
- package/dist/app-config.d.ts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +301 -301
- package/dist/auth.js.map +1 -1
- package/dist/aws4fetch.esm-p7eEzLCs.js +1702 -0
- package/dist/aws4fetch.esm-p7eEzLCs.js.map +1 -0
- package/dist/baerly.js +35 -15
- package/dist/baerly.js.map +1 -1
- package/dist/baerly.spec.json +342 -0
- package/dist/bytes-BXdamO3L.js.map +1 -1
- package/dist/{client-DYZfoZb9.d.ts → client-Fe8CwB73.d.ts} +10 -10
- package/dist/client-react.d.ts +3 -3
- package/dist/client-react.js +4 -4
- package/dist/client-react.js.map +1 -1
- package/dist/client.d.ts +4 -4
- package/dist/client.js +3 -3
- package/dist/client.js.map +1 -1
- package/dist/{cloudflare-CINJPKCW.js → cloudflare-DzKBrUlg.js} +178 -2
- package/dist/cloudflare-DzKBrUlg.js.map +1 -0
- package/dist/cloudflare.d.ts +49 -6
- package/dist/cloudflare.js +59 -26
- package/dist/cloudflare.js.map +1 -1
- package/dist/config-1tv0-Yzm.js +2693 -0
- package/dist/config-1tv0-Yzm.js.map +1 -0
- package/dist/constants-CfeMWQWk.js +222 -0
- package/dist/constants-CfeMWQWk.js.map +1 -0
- package/dist/context-DRZ3tZ5l.js.map +1 -1
- package/dist/{cost-CQt1YRkA.js → cost-DSMIVqzL.js} +43 -42
- package/dist/cost-DSMIVqzL.js.map +1 -0
- package/dist/current-json-C6nhPOm1.js +190 -0
- package/dist/current-json-C6nhPOm1.js.map +1 -0
- package/dist/{db-BM3y2JQw.d.ts → db-DsPkOVEH.d.ts} +26 -108
- package/dist/{deploy-CrAbfgCq.js → deploy-DonTr-CV.js} +12 -5
- package/dist/deploy-DonTr-CV.js.map +1 -0
- package/dist/dev-vite.d.ts +11 -7
- package/dist/dev-vite.js +7 -6
- package/dist/dev-vite.js.map +1 -1
- package/dist/dev.d.ts +1 -1
- package/dist/dev.js +1 -1
- package/dist/{doctor-Db-hzPmE.js → doctor-DSIyCDg_.js} +14 -136
- package/dist/doctor-DSIyCDg_.js.map +1 -0
- package/dist/{dump-BYA55NLP.js → dump-Bh5k26VQ.js} +10 -31
- package/dist/dump-Bh5k26VQ.js.map +1 -0
- package/dist/{errors-DOdL95kK.js → errors-Dfa3p78c.js} +25 -5
- package/dist/errors-Dfa3p78c.js.map +1 -0
- package/dist/{export-Bhbz90-z.js → export-DtF5tDIM.js} +11 -32
- package/dist/{export-Bhbz90-z.js.map → export-DtF5tDIM.js.map} +1 -1
- package/dist/{fsck-CPPZWt9p.js → fsck-D_djMO5D.js} +28 -39
- package/dist/fsck-D_djMO5D.js.map +1 -0
- package/dist/{http-Cw8p6y5b.js → http-DxM9MflO.js} +151 -79
- package/dist/http-DxM9MflO.js.map +1 -0
- package/dist/http.d.ts +42 -26
- package/dist/http.js +3 -2
- package/dist/{index-DwDTWPSU.d.ts → index-0rZcMBwy.d.ts} +10 -7
- package/dist/{index-C3JAH1Yo.d.ts → index-B6oexfOB.d.ts} +9 -9
- package/dist/{index-cUY-36AN.d.ts → index-BNRh23K9.d.ts} +21 -5
- package/dist/{index-DSvwEUeF.d.ts → index-BYk9oCNf.d.ts} +240 -202
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -5
- package/dist/{indexes-DAu2AkTW.d.ts → indexes-Dn9hbGQG.d.ts} +2 -2
- package/dist/{inspect-Bdbzvi-_.js → inspect-6WZ-pC7-.js} +21 -36
- package/dist/inspect-6WZ-pC7-.js.map +1 -0
- package/dist/key-Di6yyxFu.js +35 -0
- package/dist/key-Di6yyxFu.js.map +1 -0
- package/dist/{snapshot-SS8USDUF.js → log-tail-D98U1JBo.js} +179 -84
- package/dist/log-tail-D98U1JBo.js.map +1 -0
- package/dist/{maintenance-ClzBC1Vv.js → maintenance-B4Dki6Ig.js} +438 -176
- package/dist/maintenance-B4Dki6Ig.js.map +1 -0
- package/dist/{maintenance-BRrThz8V.d.ts → maintenance-B_e0T99L.d.ts} +114 -26
- package/dist/{maintenance-BvOv6BMM.js → maintenance-C7coQp4c.js} +217 -94
- package/dist/maintenance-C7coQp4c.js.map +1 -0
- package/dist/maintenance.d.ts +3 -2
- package/dist/maintenance.js +3 -2
- package/dist/node.d.ts +176 -68
- package/dist/node.js +3 -2
- package/dist/{normalize-XWY25_sG.js → normalize-rjnZLwS4.js} +2 -2
- package/dist/normalize-rjnZLwS4.js.map +1 -0
- package/dist/{observability-CpOiEN0k.js → observability-wzs3-BL_.js} +279 -109
- package/dist/observability-wzs3-BL_.js.map +1 -0
- package/dist/observability.d.ts +3 -3
- package/dist/observability.js +1 -1
- package/dist/{plan-DOTl21vq.js → plan-a7PJHBCy.js} +7 -4
- package/dist/plan-a7PJHBCy.js.map +1 -0
- package/dist/{query-BmiQy328.js → query-rAtXNQQB.js} +1063 -1202
- package/dist/query-rAtXNQQB.js.map +1 -0
- package/dist/{rebuild-index-DC_nR6wP.js → rebuild-index-BVzQSZlm.js} +10 -32
- package/dist/rebuild-index-BVzQSZlm.js.map +1 -0
- package/dist/{request-BEF_OvMh.js → request-u0M51mhJ.js} +3 -3
- package/dist/{request-BEF_OvMh.js.map → request-u0M51mhJ.js.map} +1 -1
- package/dist/restore-R-4rbciV.js +778 -0
- package/dist/restore-R-4rbciV.js.map +1 -0
- package/dist/runtime-spec-qL3_lTTU.js +391 -0
- package/dist/runtime-spec-qL3_lTTU.js.map +1 -0
- package/dist/s3-http-B-z8th6O.d.ts +60 -0
- package/dist/s3.d.ts +47 -0
- package/dist/s3.js +45 -0
- package/dist/s3.js.map +1 -0
- package/dist/{shared-secret-BJdSwpgw.js → shared-secret-DgEicd3x.js} +13 -5
- package/dist/shared-secret-DgEicd3x.js.map +1 -0
- package/dist/src-BG20LZs7.js +2271 -0
- package/dist/src-BG20LZs7.js.map +1 -0
- package/dist/{src-zhEAmmF7.js → src-CYHFDrKz.js} +82 -99
- package/dist/src-CYHFDrKz.js.map +1 -0
- package/dist/{src-QQ7jDeL2.js → src-DYZ4H1aF.js} +44 -23
- package/dist/src-DYZ4H1aF.js.map +1 -0
- package/dist/subcommand-DoDA-K7d.js +197 -0
- package/dist/subcommand-DoDA-K7d.js.map +1 -0
- package/dist/time-DUqvFMHq.js +119 -0
- package/dist/time-DUqvFMHq.js.map +1 -0
- package/dist/{usage-CLjirdD-.js → usage-DBV1eQHC.js} +7 -22
- package/dist/usage-DBV1eQHC.js.map +1 -0
- package/dist/{validate-DCq_0DIn.js → validate-DtljsCh1.js} +51 -51
- package/dist/{validate-DCq_0DIn.js.map → validate-DtljsCh1.js.map} +1 -1
- package/dist/wire-izfGZDvr.js.map +1 -1
- package/package.json +77 -42
- package/dist/cloudflare-CINJPKCW.js.map +0 -1
- package/dist/config-DVfDGyw1.js +0 -278
- package/dist/config-DVfDGyw1.js.map +0 -1
- package/dist/cost-CQt1YRkA.js.map +0 -1
- package/dist/current-json-C-EyJqs0.js +0 -354
- package/dist/current-json-C-EyJqs0.js.map +0 -1
- package/dist/deploy-CrAbfgCq.js.map +0 -1
- package/dist/doctor-Db-hzPmE.js.map +0 -1
- package/dist/dump-BYA55NLP.js.map +0 -1
- package/dist/errors-DOdL95kK.js.map +0 -1
- package/dist/fsck-CPPZWt9p.js.map +0 -1
- package/dist/http-Cw8p6y5b.js.map +0 -1
- package/dist/inspect-Bdbzvi-_.js.map +0 -1
- package/dist/maintenance-BvOv6BMM.js.map +0 -1
- package/dist/maintenance-ClzBC1Vv.js.map +0 -1
- package/dist/normalize-XWY25_sG.js.map +0 -1
- package/dist/observability-CpOiEN0k.js.map +0 -1
- package/dist/plan-DOTl21vq.js.map +0 -1
- package/dist/query-BmiQy328.js.map +0 -1
- package/dist/rebuild-index-DC_nR6wP.js.map +0 -1
- package/dist/restore-C6IcmLeA.js +0 -771
- package/dist/restore-C6IcmLeA.js.map +0 -1
- package/dist/shared-secret-BJdSwpgw.js.map +0 -1
- package/dist/snapshot-SS8USDUF.js.map +0 -1
- package/dist/src-DU1sCMlr.js +0 -6236
- package/dist/src-DU1sCMlr.js.map +0 -1
- package/dist/src-QQ7jDeL2.js.map +0 -1
- package/dist/src-zhEAmmF7.js.map +0 -1
- package/dist/subcommand-DZcHcsYp.js +0 -5122
- package/dist/subcommand-DZcHcsYp.js.map +0 -1
- package/dist/usage-CLjirdD-.js.map +0 -1
- /package/dist/{chunk-EAsCxrDo.js → rolldown-runtime-EAsCxrDo.js} +0 -0
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { n as encodeJsonBytes, t as decodeJsonBytes } from "./bytes-BXdamO3L.js";
|
|
2
|
-
import {
|
|
3
|
-
import { c as
|
|
4
|
-
import { n as matchesWire, t as validateWire } from "./validate-
|
|
2
|
+
import { l as GC_MAX_PENDING_CANDIDATES, m as MAINTENANCE_PROFILE_CF_PAID, p as MAINTENANCE_PROFILE_CF_FREE, u as GC_PENDING_CONTENT_TYPE } from "./config-1tv0-Yzm.js";
|
|
3
|
+
import { a as walkLogRange, c as loadSnapshotAsMap, d as logObjectKey, f as casUpdateCurrentJson, h as readCurrentJson, l as snapshotKey, m as logSeqStartOf, n as probeTailFrom, o as walkLogRangeWithBytes, r as foldLogEntriesOnto, s as encodeSnapshotBody, u as snapshotHash } from "./log-tail-D98U1JBo.js";
|
|
4
|
+
import { n as matchesWire, t as validateWire } from "./validate-DtljsCh1.js";
|
|
5
5
|
import { o as BaerlyError } from "./baerly.js";
|
|
6
|
+
import { l as assertNameNotReserved } from "./subcommand-DoDA-K7d.js";
|
|
6
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
8
|
//#region ../protocol/src/coordination/gc-pending.ts
|
|
8
9
|
/**
|
|
@@ -75,44 +76,112 @@ const createGcPending = async (storage, key, initial, opts) => {
|
|
|
75
76
|
};
|
|
76
77
|
};
|
|
77
78
|
/**
|
|
78
|
-
* Read-modify-write `gc/pending.json` under CAS
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
79
|
+
* Read-modify-write `gc/pending.json` under CAS, with a bounded retry
|
|
80
|
+
* loop. Each attempt re-reads the latest body, hands the `mutator`
|
|
81
|
+
* that latest value, and writes the result with
|
|
82
|
+
* `If-Match: <latest etag>`. On `Conflict` (a concurrent writer landed
|
|
83
|
+
* between this attempt's read and write) the loop re-reads and
|
|
84
|
+
* re-applies the mutator, up to {@link GC_PENDING_CAS_MAX_ATTEMPTS}
|
|
85
|
+
* total attempts, then surfaces `Conflict`.
|
|
86
|
+
*
|
|
87
|
+
* `mutator` MUST be a pure, deterministic MERGE of this pass's results
|
|
88
|
+
* INTO the `latest` value it is handed — it is called once per attempt
|
|
89
|
+
* (so it must not have side effects), and it MUST read `latest` rather
|
|
90
|
+
* than ignore it and write a precomputed set. Ignoring `latest` would
|
|
91
|
+
* silently overwrite a concurrent pass's candidates: the
|
|
92
|
+
* If-Match succeeds (it used the fresh etag), so no conflict is
|
|
93
|
+
* raised, and the concurrent marks are lost. See {@link mergeGcPending}.
|
|
94
|
+
*
|
|
95
|
+
* @throws BaerlyError{code:"Conflict"} — another writer kept landing a
|
|
96
|
+
* write between this function's read and write for every
|
|
97
|
+
* attempt.
|
|
89
98
|
* @throws BaerlyError{code:"InvalidResponse"} — `key` does not exist
|
|
90
99
|
* (use {@link createGcPending} instead) or body doesn't
|
|
91
100
|
* parse / fails the shape guard.
|
|
92
101
|
*/
|
|
93
102
|
const casUpdateGcPending = async (storage, key, mutator, opts) => {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
let lastConflict;
|
|
104
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
105
|
+
const existing = await readGcPending(storage, key, opts);
|
|
106
|
+
if (existing === null) throw new BaerlyError("InvalidResponse", `gc/pending.json at ${key} does not exist; use createGcPending first`);
|
|
107
|
+
const next = mutator(structuredClone(existing.json));
|
|
108
|
+
assertGcPending(next, key);
|
|
109
|
+
const body = encodeJsonBytes(next);
|
|
110
|
+
const putOpts = {
|
|
111
|
+
ifMatch: existing.etag,
|
|
112
|
+
contentType: GC_PENDING_CONTENT_TYPE,
|
|
113
|
+
...opts?.signal !== void 0 && { signal: opts.signal }
|
|
114
|
+
};
|
|
115
|
+
try {
|
|
116
|
+
return {
|
|
117
|
+
json: next,
|
|
118
|
+
etag: (await storage.put(key, body, putOpts)).etag
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const translated = translateCasError(error, key);
|
|
122
|
+
if (translated.code !== "Conflict") throw translated;
|
|
123
|
+
lastConflict = translated;
|
|
124
|
+
}
|
|
109
125
|
}
|
|
126
|
+
throw lastConflict;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Pure merge of one GC pass's results INTO the `latest`
|
|
130
|
+
* `gc/pending.json` value, used as the {@link casUpdateGcPending}
|
|
131
|
+
* mutator. Deterministic, no I/O — the kernel unit + mutation test
|
|
132
|
+
* surface. Splitting it out is what makes the CAS write correct under
|
|
133
|
+
* concurrency: each retry re-merges against fresh `latest` rather than
|
|
134
|
+
* overwriting it with a stale precomputed set.
|
|
135
|
+
*
|
|
136
|
+
* Semantics:
|
|
137
|
+
* - **candidates**: start from `latest.candidates`, DROP any whose key
|
|
138
|
+
* this pass already DELETED (`sweptKeys`), then APPEND every fresh
|
|
139
|
+
* mark whose key is not already present AND was not itself swept
|
|
140
|
+
* this pass (a `graceMillis: 0` pass can mark-and-sweep a key in one
|
|
141
|
+
* go — re-adding it to the ledger after deleting it would be wrong;
|
|
142
|
+
* dedup also drops a key a concurrent pass already marked). Capped at
|
|
143
|
+
* `maxCandidates`.
|
|
144
|
+
* - **last_swept_at**: the lexicographically LATER of `latest`'s and
|
|
145
|
+
* this pass's (ISO-8601 UTC; `""` sorts lowest so a real timestamp
|
|
146
|
+
* always wins). Never regress a concurrent pass's newer sweep time.
|
|
147
|
+
* - **content_scan_cursor**: rotation cursor — liveness, not
|
|
148
|
+
* correctness; just don't regress forward progress. The two sides
|
|
149
|
+
* are NOT symmetric: `pass.nextContentCursor === undefined` means
|
|
150
|
+
* THIS pass examined to the END of the keyspace (WRAP — the most-
|
|
151
|
+
* advanced position), whereas `latest.content_scan_cursor` absent
|
|
152
|
+
* means the stored ledger has no cursor yet (start-from-beginning).
|
|
153
|
+
* So:
|
|
154
|
+
* - our pass WRAPPED ⇒ result wraps (key omitted) — our pass is
|
|
155
|
+
* the most advanced; this is the single-writer rotation reset.
|
|
156
|
+
* - else (our pass advanced to a defined cursor):
|
|
157
|
+
* - latest cursor defined ⇒ take the lexicographically GREATER
|
|
158
|
+
* (don't regress a concurrent pass's advance);
|
|
159
|
+
* - latest cursor absent ⇒ keep OUR advance (don't lose it).
|
|
160
|
+
*/
|
|
161
|
+
const mergeGcPending = (latest, pass) => {
|
|
162
|
+
const surviving = latest.candidates.filter((c) => !pass.sweptKeys.has(c.key));
|
|
163
|
+
const present = new Set(surviving.map((c) => c.key));
|
|
164
|
+
const appended = [];
|
|
165
|
+
for (const c of pass.newCandidates) if (!pass.sweptKeys.has(c.key) && !present.has(c.key)) {
|
|
166
|
+
present.add(c.key);
|
|
167
|
+
appended.push(c);
|
|
168
|
+
}
|
|
169
|
+
const candidates = [...surviving, ...appended].slice(0, pass.maxCandidates);
|
|
170
|
+
const lastSweptAt = pass.lastSweptAt > latest.last_swept_at ? pass.lastSweptAt : latest.last_swept_at;
|
|
171
|
+
const latestCursor = latest.content_scan_cursor;
|
|
172
|
+
const passCursor = pass.nextContentCursor;
|
|
173
|
+
let cursor;
|
|
174
|
+
if (passCursor === void 0) cursor = void 0;
|
|
175
|
+
else if (latestCursor !== void 0) cursor = passCursor > latestCursor ? passCursor : latestCursor;
|
|
176
|
+
else cursor = passCursor;
|
|
110
177
|
return {
|
|
111
|
-
|
|
112
|
-
|
|
178
|
+
schema_version: 1,
|
|
179
|
+
candidates,
|
|
180
|
+
last_swept_at: lastSweptAt,
|
|
181
|
+
...cursor !== void 0 && { content_scan_cursor: cursor }
|
|
113
182
|
};
|
|
114
183
|
};
|
|
115
|
-
const VALID_REASONS = new Set([
|
|
184
|
+
const VALID_REASONS = /* @__PURE__ */ new Set([
|
|
116
185
|
"stale-log",
|
|
117
186
|
"orphan-snapshot",
|
|
118
187
|
"orphan-content"
|
|
@@ -203,12 +272,6 @@ const noopMetricsRecorder = {
|
|
|
203
272
|
histogram: () => {}
|
|
204
273
|
};
|
|
205
274
|
//#endregion
|
|
206
|
-
//#region ../server/src/names.ts
|
|
207
|
-
/** Reject names in the system-reserved leading-"_" namespace. See docs/adr/007-layout-versioning-cordon.md. */
|
|
208
|
-
const assertNameNotReserved = (name, context) => {
|
|
209
|
-
if (name.startsWith("_")) throw new BaerlyError("InvalidConfig", `${context}: "${name}" is reserved — names beginning with "_" are reserved for system use. See docs/adr/007-layout-versioning-cordon.md.`);
|
|
210
|
-
};
|
|
211
|
-
//#endregion
|
|
212
275
|
//#region ../server/src/indexes.ts
|
|
213
276
|
/**
|
|
214
277
|
* Secondary indexes — declarative collection-config-driven
|
|
@@ -236,8 +299,7 @@ const assertNameNotReserved = (name, context) => {
|
|
|
236
299
|
*
|
|
237
300
|
* `<logPrefix>/index/<indexName>/<value-b32>/<docId>.json`
|
|
238
301
|
*
|
|
239
|
-
* Wire shape (composite
|
|
240
|
-
* the read path today):
|
|
302
|
+
* Wire shape (composite):
|
|
241
303
|
*
|
|
242
304
|
* `<logPrefix>/index/<indexName>/<a-b32>/<b-b32>/<docId>.json`
|
|
243
305
|
*
|
|
@@ -258,11 +320,13 @@ const assertNameNotReserved = (name, context) => {
|
|
|
258
320
|
* and `$in` walks over numeric fields are first-class — no
|
|
259
321
|
* planner fall-back to full-scan).
|
|
260
322
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
323
|
+
* Composite read routing is left-anchored. The planner may consume an
|
|
324
|
+
* equality prefix plus a range / `$in` tail slot; predicates that do
|
|
325
|
+
* not match a routable prefix fall back to the snapshot+log fold.
|
|
263
326
|
*
|
|
264
|
-
* @see docs/spec/sync-protocol.md —
|
|
265
|
-
*
|
|
327
|
+
* @see docs/spec/sync-protocol.md — index emission is hybrid around
|
|
328
|
+
* the commit: additive (new) keys are PUT before the committing
|
|
329
|
+
* `log/<seq>` create, and stale-key DELETEs land after it.
|
|
266
330
|
*/
|
|
267
331
|
/** Path-safe segment name. */
|
|
268
332
|
const INDEX_NAME_RE = /^[a-z][a-z0-9_]*$/;
|
|
@@ -274,7 +338,7 @@ const INDEX_NAME_RE = /^[a-z][a-z0-9_]*$/;
|
|
|
274
338
|
const B32_ALPHABET = "0123456789abcdefghijklmnopqrstuv";
|
|
275
339
|
/**
|
|
276
340
|
* Reject malformed {@link IndexDefinition} shapes synchronously, at
|
|
277
|
-
* writer construction. See docs/adr/
|
|
341
|
+
* writer construction. See docs/adr/003-layout-versioning-cordon.md.
|
|
278
342
|
*
|
|
279
343
|
* @throws BaerlyError code="InvalidConfig" — reserved leading-`_` `name`.
|
|
280
344
|
* @throws BaerlyError code="SchemaError" — `name` fails the regex, or `on` is empty.
|
|
@@ -441,8 +505,8 @@ const indexKeyPrefix = (logPrefix, indexName) => `${logPrefix}/index/${indexName
|
|
|
441
505
|
* Single-field: `<logPrefix>/index/<name>/<v0-b32>/<docId>.json`.
|
|
442
506
|
* Composite: `<logPrefix>/index/<name>/<v0-b32>/<v1-b32>/.../<docId>.json`.
|
|
443
507
|
*
|
|
444
|
-
* Composite
|
|
445
|
-
*
|
|
508
|
+
* Composite entries are read-path routable when the planner can consume
|
|
509
|
+
* a left-anchored prefix of the indexed tuple.
|
|
446
510
|
*/
|
|
447
511
|
const indexKeyFor = (logPrefix, def, values, docId) => {
|
|
448
512
|
const segments = values.map(encodeIndexValue).join("/");
|
|
@@ -456,7 +520,7 @@ const indexKeyFor = (logPrefix, def, values, docId) => {
|
|
|
456
520
|
*
|
|
457
521
|
* @throws BaerlyError code="SchemaError" — `on` contains a dotted
|
|
458
522
|
* path, or the indexed field's value is an array. Both restrictions
|
|
459
|
-
* are
|
|
523
|
+
* are current 0.x limitations; multi-value (array) indexes are a follow-up.
|
|
460
524
|
*/
|
|
461
525
|
const projectIndexValues = (def, body) => {
|
|
462
526
|
if (body === void 0) return;
|
|
@@ -563,8 +627,7 @@ const getCurrentContext = () => als.getStore();
|
|
|
563
627
|
* "missing." The atomic moment is the CAS-swap of
|
|
564
628
|
* `current.json.snapshot`, which is a single conditional PUT.
|
|
565
629
|
*
|
|
566
|
-
* Order of operations
|
|
567
|
-
* REVERSED ordering): PUT snapshot body → CAS-advance `current.json`.
|
|
630
|
+
* Order of operations: PUT snapshot body → CAS-advance `current.json`.
|
|
568
631
|
* A crash before the swap leaves an orphan snapshot file; the swap
|
|
569
632
|
* succeeds iff our captured ETag still matches.
|
|
570
633
|
*
|
|
@@ -572,7 +635,7 @@ const getCurrentContext = () => als.getStore();
|
|
|
572
635
|
* single monolithic snapshot (every compaction rewrites one well-
|
|
573
636
|
* known key) makes partial writes catastrophic and serializes every
|
|
574
637
|
* writer on one key. WAL-checkpointing in the rqlite / Raft tradition
|
|
575
|
-
* requires a consensus layer
|
|
638
|
+
* requires a consensus layer baerly-storage doesn't have. The Litestream-
|
|
576
639
|
* style multi-level scheme — small fixed number of levels, chunked
|
|
577
640
|
* files keyed by sequence range — keeps random GETs cheap on
|
|
578
641
|
* S3-compatible storage and avoids LIST. Current ship is single-
|
|
@@ -637,7 +700,8 @@ const compact = async (args, options = {}) => {
|
|
|
637
700
|
const current = read.json;
|
|
638
701
|
const baseEtag = read.etag;
|
|
639
702
|
const logSeqStartBefore = logSeqStartOf(current);
|
|
640
|
-
const
|
|
703
|
+
const discoveredTail = (await probeTailFrom(storage, collectionPrefix, Math.max(logSeqStartBefore, current.tail_hint, internal.knownTail ?? 0), { ...options.signal !== void 0 && { signal: options.signal } })).tail;
|
|
704
|
+
const nextSeq = discoveredTail;
|
|
641
705
|
if (nextSeq - logSeqStartBefore < minToCompact) return {
|
|
642
706
|
written: false,
|
|
643
707
|
skippedReason: "below-min-threshold",
|
|
@@ -698,13 +762,15 @@ const compact = async (args, options = {}) => {
|
|
|
698
762
|
...options.signal !== void 0 && { signal: options.signal }
|
|
699
763
|
};
|
|
700
764
|
await storage.put(newKey, bodyBytes, putOpts);
|
|
765
|
+
const entriesFolded = foldEnd - logSeqStartBefore;
|
|
701
766
|
const nextBody = encodeJsonBytes({
|
|
702
767
|
...current,
|
|
703
768
|
snapshot: newKey,
|
|
704
769
|
log_seq_start: foldEnd,
|
|
770
|
+
tail_hint: Math.max(current.tail_hint, discoveredTail),
|
|
705
771
|
snapshot_bytes: bodyBytes.byteLength,
|
|
706
772
|
snapshot_rows: base.size,
|
|
707
|
-
|
|
773
|
+
mean_entry_bytes: entriesFolded > 0 ? Math.round(foldedSliceBytes / entriesFolded) : current.mean_entry_bytes ?? 0
|
|
708
774
|
});
|
|
709
775
|
const casOpts = {
|
|
710
776
|
ifMatch: baseEtag,
|
|
@@ -728,10 +794,9 @@ const compact = async (args, options = {}) => {
|
|
|
728
794
|
}
|
|
729
795
|
throw error;
|
|
730
796
|
}
|
|
731
|
-
const entriesFolded = foldEnd - logSeqStartBefore;
|
|
732
797
|
const metrics = ctxMetrics$2();
|
|
733
798
|
metrics.histogram("db.compact.entries_folded", entriesFolded, { collection: collectionName });
|
|
734
|
-
metrics.gauge("db.manifest.lag_window_depth",
|
|
799
|
+
metrics.gauge("db.manifest.lag_window_depth", discoveredTail - foldEnd, { collection: collectionName });
|
|
735
800
|
return {
|
|
736
801
|
written: true,
|
|
737
802
|
previousSnapshotKey: current.snapshot,
|
|
@@ -915,8 +980,8 @@ const runGc = async (args, options = {}) => {
|
|
|
915
980
|
for (const cand of sweepCandidates) if (toSweep.length < maxSweeps && Date.parse(cand.due_at) <= nowMs) toSweep.push(cand);
|
|
916
981
|
else remaining.push(cand);
|
|
917
982
|
await Promise.all(toSweep.map((c) => storage.delete(c.key, signalOpts)));
|
|
918
|
-
const
|
|
919
|
-
const lastSweptAt = toSweep.length > 0 ? now().toISOString() :
|
|
983
|
+
const sweptKeys = new Set(toSweep.map((c) => c.key));
|
|
984
|
+
const lastSweptAt = toSweep.length > 0 ? now().toISOString() : "";
|
|
920
985
|
const markedSummary = {
|
|
921
986
|
stale_log: markedStaleLog,
|
|
922
987
|
orphan_snapshot: markedOrphanSnapshot,
|
|
@@ -924,11 +989,12 @@ const runGc = async (args, options = {}) => {
|
|
|
924
989
|
};
|
|
925
990
|
let pendingDepth;
|
|
926
991
|
try {
|
|
927
|
-
pendingDepth = (await casUpdateGcPending(storage, gcPendingKey, () => ({
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
992
|
+
pendingDepth = (await casUpdateGcPending(storage, gcPendingKey, (latest) => mergeGcPending(latest, {
|
|
993
|
+
sweptKeys,
|
|
994
|
+
newCandidates,
|
|
995
|
+
lastSweptAt,
|
|
996
|
+
nextContentCursor,
|
|
997
|
+
maxCandidates: GC_MAX_PENDING_CANDIDATES
|
|
932
998
|
}), signalOpts)).json.candidates.length;
|
|
933
999
|
} catch (error) {
|
|
934
1000
|
if (error instanceof BaerlyError && error.code === "Conflict") pendingDepth = remaining.length;
|
|
@@ -997,7 +1063,7 @@ const computeDueAt = (entry, now, graceMs) => {
|
|
|
997
1063
|
};
|
|
998
1064
|
/**
|
|
999
1065
|
* Build the live content-hash set. The set covers every live
|
|
1000
|
-
* post-image: every `entry.after` in `[logSeqStart,
|
|
1066
|
+
* post-image: every `entry.after` in `[logSeqStart, tail_hint)` plus
|
|
1001
1067
|
* every row body in the current snapshot.
|
|
1002
1068
|
*
|
|
1003
1069
|
* A snapshot read that throws (corrupt body, hash mismatch) is
|
|
@@ -1009,9 +1075,9 @@ const computeDueAt = (entry, now, graceMs) => {
|
|
|
1009
1075
|
const collectLiveContentHashes = async (storage, collectionPrefix, collectionName, current, logSeqStart, signal) => {
|
|
1010
1076
|
const hashes = /* @__PURE__ */ new Set();
|
|
1011
1077
|
const getOpts = signal !== void 0 ? { signal } : void 0;
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1014
|
-
const got = await storage.get(
|
|
1078
|
+
const { tail } = await probeTailFrom(storage, collectionPrefix, Math.max(logSeqStart, current.tail_hint), { signal });
|
|
1079
|
+
const ingestLogEntry = async (s) => {
|
|
1080
|
+
const got = await storage.get(logObjectKey(collectionPrefix, s), getOpts);
|
|
1015
1081
|
if (got === null) return;
|
|
1016
1082
|
let entry;
|
|
1017
1083
|
try {
|
|
@@ -1022,8 +1088,14 @@ const collectLiveContentHashes = async (storage, collectionPrefix, collectionNam
|
|
|
1022
1088
|
if (entry.after === void 0) return;
|
|
1023
1089
|
const bodyBytes = encodeJsonBytes(entry.after);
|
|
1024
1090
|
hashes.add(await versionFromContent(bodyBytes));
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1091
|
+
};
|
|
1092
|
+
for (let chunkStart = logSeqStart; chunkStart < tail; chunkStart += 16) {
|
|
1093
|
+
signal?.throwIfAborted();
|
|
1094
|
+
const chunkEnd = Math.min(chunkStart + 16, tail);
|
|
1095
|
+
const chunk = [];
|
|
1096
|
+
for (let s = chunkStart; s < chunkEnd; s++) chunk.push(ingestLogEntry(s));
|
|
1097
|
+
await Promise.all(chunk);
|
|
1098
|
+
}
|
|
1027
1099
|
if (current.snapshot !== null) try {
|
|
1028
1100
|
const map = await loadSnapshotAsMap(storage, current.snapshot, collectionName, signal);
|
|
1029
1101
|
const rowReads = [];
|
|
@@ -1067,10 +1139,10 @@ const collectLiveContentHashes = async (storage, collectionPrefix, collectionNam
|
|
|
1067
1139
|
*
|
|
1068
1140
|
* @see ./indexes.ts — `IndexDefinition`, `allIndexKeysFor`,
|
|
1069
1141
|
* `indexKeyPrefix`.
|
|
1070
|
-
* @see ./writer.ts — the
|
|
1071
|
-
*
|
|
1142
|
+
* @see ./writer.ts — the hybrid index emission path this command
|
|
1143
|
+
* reconciles.
|
|
1072
1144
|
*/
|
|
1073
|
-
const EMPTY_BODY = new Uint8Array(0);
|
|
1145
|
+
const EMPTY_BODY = /* @__PURE__ */ new Uint8Array(0);
|
|
1074
1146
|
const APPLICATION_JSON = "application/json";
|
|
1075
1147
|
/**
|
|
1076
1148
|
* Idempotently reconcile one secondary index for one collection.
|
|
@@ -1089,7 +1161,7 @@ const APPLICATION_JSON = "application/json";
|
|
|
1089
1161
|
* @throws BaerlyError code="InvalidResponse" — `current.json` missing.
|
|
1090
1162
|
* @throws BaerlyError code="Internal" — protocol-invariant
|
|
1091
1163
|
* violation (snapshot hash mismatch, missing log entry inside
|
|
1092
|
-
* `[log_seq_start,
|
|
1164
|
+
* `[log_seq_start, tail_hint)`).
|
|
1093
1165
|
*/
|
|
1094
1166
|
const rebuildIndex = async (storage, currentJsonKey, def, opts = {}) => {
|
|
1095
1167
|
const read = await readCurrentJson(storage, currentJsonKey);
|
|
@@ -1099,9 +1171,11 @@ const rebuildIndex = async (storage, currentJsonKey, def, opts = {}) => {
|
|
|
1099
1171
|
const collectionPrefix = currentJsonKey.slice(0, lastSlash);
|
|
1100
1172
|
const collection = collectionPrefix.slice(collectionPrefix.lastIndexOf("/") + 1);
|
|
1101
1173
|
const logSeqStart = logSeqStartOf(read.json);
|
|
1102
|
-
const
|
|
1174
|
+
const hint = read.json.tail_hint;
|
|
1103
1175
|
const live = read.json.snapshot === null ? /* @__PURE__ */ new Map() : await loadSnapshotAsMap(storage, read.json.snapshot, collection);
|
|
1104
|
-
foldLogEntriesOnto(live, await walkLogRange(storage, collectionPrefix, logSeqStart,
|
|
1176
|
+
foldLogEntriesOnto(live, await walkLogRange(storage, collectionPrefix, logSeqStart, hint), { collection });
|
|
1177
|
+
const probeOpts = opts.signal !== void 0 ? { signal: opts.signal } : void 0;
|
|
1178
|
+
foldLogEntriesOnto(live, (await probeTailFrom(storage, collectionPrefix, Math.max(logSeqStart, hint), probeOpts)).entries, { collection });
|
|
1105
1179
|
const expected = /* @__PURE__ */ new Set();
|
|
1106
1180
|
for (const [docId, body] of live) for (const k of allIndexKeysFor(collectionPrefix, [def], body, docId)) expected.add(k);
|
|
1107
1181
|
const actual = /* @__PURE__ */ new Set();
|
|
@@ -1169,26 +1243,60 @@ const rebuildIndex = async (storage, currentJsonKey, def, opts = {}) => {
|
|
|
1169
1243
|
* pattern uses exactly that.
|
|
1170
1244
|
*/
|
|
1171
1245
|
const ctxMetrics = () => getCurrentContext()?.recorder ?? noopMetricsRecorder;
|
|
1246
|
+
const profileToScheduledOptions = (profile) => ({
|
|
1247
|
+
compact: {
|
|
1248
|
+
maxEntriesPerRun: profile.maxFoldEntriesPerPass,
|
|
1249
|
+
minEntriesToCompact: 50
|
|
1250
|
+
},
|
|
1251
|
+
gc: {
|
|
1252
|
+
maxMarksPerRun: profile.gcMaxMarks,
|
|
1253
|
+
maxSweepsPerRun: profile.gcMaxSweeps
|
|
1254
|
+
}
|
|
1255
|
+
});
|
|
1256
|
+
profileToScheduledOptions(MAINTENANCE_PROFILE_CF_FREE);
|
|
1257
|
+
profileToScheduledOptions(MAINTENANCE_PROFILE_CF_PAID);
|
|
1172
1258
|
/**
|
|
1173
|
-
* Floor-based GC-cadence boundary crossing.
|
|
1174
|
-
*
|
|
1175
|
-
*
|
|
1176
|
-
* trips on any interval boundary inside `(prevSeq, nextSeq]
|
|
1259
|
+
* Floor-based GC-cadence boundary crossing. Every commit advances the
|
|
1260
|
+
* writer-observed tail by one logical slot; `tail_hint` remains a
|
|
1261
|
+
* lower bound and may be refreshed later by maintenance. The floor test
|
|
1262
|
+
* trips on any interval boundary inside `(prevSeq, nextSeq]`, so it
|
|
1263
|
+
* stays correct whether the observed/probed tail advances by one or
|
|
1264
|
+
* catches up by a larger step.
|
|
1177
1265
|
*/
|
|
1178
1266
|
const crossesGcBoundary = (prevSeq, nextSeq, interval) => Math.floor(prevSeq / interval) !== Math.floor(nextSeq / interval);
|
|
1179
1267
|
/**
|
|
1268
|
+
* Derived live-tail byte size — the ratio TRIGGER input that replaces the
|
|
1269
|
+
* formerly-stored exact byte count. `(observedTail − log_seq_start) ×
|
|
1270
|
+
* mean_entry_bytes`. `observedTail` is a param so write-tick callers can
|
|
1271
|
+
* pass the writer-observed tail and scheduled callers can pass a
|
|
1272
|
+
* probe-discovered true tail. Cold-start (no mean yet) falls back to
|
|
1273
|
+
* {@link MAINTENANCE_COLD_START_ENTRY_BYTES}, never 0 (see that constant).
|
|
1274
|
+
* TRIGGER-only — structurally barred from `foldViable` (the exact-bytes CPU-kill
|
|
1275
|
+
* ceiling).
|
|
1276
|
+
*/
|
|
1277
|
+
const estimateTailBytes = (current, observedTail) => Math.max(0, observedTail - current.log_seq_start) * (current.mean_entry_bytes ?? 128);
|
|
1278
|
+
/**
|
|
1180
1279
|
* The cheap DISPATCH gate the writer calls after a commit — zero
|
|
1181
|
-
* storage ops; it reads the post-
|
|
1280
|
+
* storage ops; it reads the post-commit {@link CurrentJson} already in
|
|
1182
1281
|
* scope. Ratio-OR-boundary, WITHOUT the entry floor (the floor is part
|
|
1183
1282
|
* of the fold-trigger Gate 1 checked inside {@link runBoundedMaintenance}).
|
|
1184
|
-
* Returning `false` lets the writer skip the dispatch entirely.
|
|
1283
|
+
* Returning `false` lets the writer skip the dispatch entirely. Ratio
|
|
1284
|
+
* numerator is the DERIVED {@link estimateTailBytes};
|
|
1285
|
+
* `observedTail` threads from the caller (the writer's in-memory observed
|
|
1286
|
+
* tail `seq+1` under single-write commit). Both the boundary check and the
|
|
1287
|
+
* ratio key off `observedTail`, since the stored `tail_hint` is now only a
|
|
1288
|
+
* non-authoritative lower bound (compactor-advanced).
|
|
1185
1289
|
*/
|
|
1186
|
-
const shouldFireMaintenance = (current, prevSeq, gcInterval) => crossesGcBoundary(prevSeq,
|
|
1290
|
+
const shouldFireMaintenance = (current, prevSeq, gcInterval, observedTail) => crossesGcBoundary(prevSeq, observedTail, gcInterval) || estimateTailBytes(current, observedTail) / Math.max(current.snapshot_bytes, 65536) >= 1;
|
|
1187
1291
|
/**
|
|
1188
1292
|
* The write-tick maintenance runner: a bounded, single-attempt
|
|
1189
1293
|
* composition of {@link compact} and {@link runGc} for one collection,
|
|
1190
1294
|
* sized to fit a CPU-killable Cloudflare free-tier isolate by default.
|
|
1191
1295
|
*
|
|
1296
|
+
* INVARIANT: a {@link MaintenanceProfile} changes only maintenance rate +
|
|
1297
|
+
* defer threshold — never data/API/query/wire/correctness; reads stay pure.
|
|
1298
|
+
* See `maintenance-profile-equivalence.test.ts`.
|
|
1299
|
+
*
|
|
1192
1300
|
* Never throws — the write-tick caller must never see a maintenance
|
|
1193
1301
|
* failure. Expected signals (CAS contention, an over-ceiling deferral)
|
|
1194
1302
|
* are swallowed quietly; unexpected throws bump
|
|
@@ -1196,7 +1304,8 @@ const shouldFireMaintenance = (current, prevSeq, gcInterval) => crossesGcBoundar
|
|
|
1196
1304
|
* swallowed.
|
|
1197
1305
|
*
|
|
1198
1306
|
* Control flow (fold-priority with a stateless GC-starvation guard):
|
|
1199
|
-
* 0. `disabled` →
|
|
1307
|
+
* 0. `disabled` → skip fold/GC, but still allow the rate-limited
|
|
1308
|
+
* tail_hint refresh that bounds read/write forward-probes.
|
|
1200
1309
|
* 1. Read `current.json` once.
|
|
1201
1310
|
* 2. Hard-GC starvation boundary (`"single"` only) → GC slice, skip fold.
|
|
1202
1311
|
* 3. Gate 1 (ratio AND entry floor) trips → fold if viable, else
|
|
@@ -1205,17 +1314,14 @@ const shouldFireMaintenance = (current, prevSeq, gcInterval) => crossesGcBoundar
|
|
|
1205
1314
|
* 4. Otherwise (or on `"both"`) → GC iff the cadence boundary crossed.
|
|
1206
1315
|
*/
|
|
1207
1316
|
const runBoundedMaintenance = async (args, options) => {
|
|
1208
|
-
if (args.disabled === true) return;
|
|
1209
1317
|
const { storage, currentJsonKey, prevSeq } = args;
|
|
1210
|
-
const
|
|
1318
|
+
const profile = options?.profile ?? MAINTENANCE_PROFILE_CF_FREE;
|
|
1319
|
+
const { maxFoldEntriesPerPass, gcMaxMarks, gcMaxSweeps, gcInterval } = profile;
|
|
1211
1320
|
const minEntriesToCompact = options?.minEntriesToCompact ?? 50;
|
|
1212
|
-
const gcMaxMarks = options?.gcMaxMarks ?? 20;
|
|
1213
|
-
const gcMaxSweeps = options?.gcMaxSweeps ?? 10;
|
|
1214
|
-
const gcInterval = options?.gcInterval ?? 4;
|
|
1215
1321
|
const phasesPerTick = options?.phasesPerTick ?? "single";
|
|
1216
1322
|
const signal = options?.signal;
|
|
1217
|
-
const C = args.maxFoldBytes ??
|
|
1218
|
-
const E =
|
|
1323
|
+
const C = args.maxFoldBytes ?? profile.maxFoldBytes;
|
|
1324
|
+
const E = profile.maxFoldRows;
|
|
1219
1325
|
const collectionPrefix = currentJsonKey.slice(0, currentJsonKey.lastIndexOf("/"));
|
|
1220
1326
|
const collection = collectionPrefix.slice(collectionPrefix.lastIndexOf("/") + 1);
|
|
1221
1327
|
const gcOpts = {
|
|
@@ -1229,14 +1335,29 @@ const runBoundedMaintenance = async (args, options) => {
|
|
|
1229
1335
|
const read = await readCurrentJson(storage, currentJsonKey, signal !== void 0 ? { signal } : void 0);
|
|
1230
1336
|
if (read === null) return;
|
|
1231
1337
|
const current = read.json;
|
|
1232
|
-
const tailBytes = current.tail_bytes;
|
|
1233
1338
|
const snapshotBytes = current.snapshot_bytes;
|
|
1234
1339
|
const snapshotRows = current.snapshot_rows;
|
|
1235
|
-
const nextSeq = current.next_seq;
|
|
1236
1340
|
const logSeqStart = current.log_seq_start;
|
|
1237
|
-
const
|
|
1341
|
+
const probeFloor = Math.max(logSeqStart, current.tail_hint);
|
|
1342
|
+
let nextSeq;
|
|
1343
|
+
if (args.observedTail !== void 0) nextSeq = Math.max(args.observedTail, probeFloor);
|
|
1344
|
+
else nextSeq = (await probeTailFrom(storage, collectionPrefix, probeFloor, signal !== void 0 ? { signal } : void 0)).tail;
|
|
1345
|
+
const gate1 = estimateTailBytes(current, nextSeq) / Math.max(snapshotBytes, 65536) >= 1 && nextSeq - logSeqStart >= minEntriesToCompact;
|
|
1238
1346
|
const foldViable = snapshotBytes <= C && snapshotRows + maxFoldEntriesPerPass <= E;
|
|
1239
1347
|
const gcDue = crossesGcBoundary(prevSeq, nextSeq, gcInterval);
|
|
1348
|
+
const refreshTailHintIfNeeded = async () => {
|
|
1349
|
+
if (nextSeq - current.tail_hint < 128) return;
|
|
1350
|
+
try {
|
|
1351
|
+
await casUpdateCurrentJson(storage, currentJsonKey, (c) => ({
|
|
1352
|
+
...c,
|
|
1353
|
+
tail_hint: Math.max(c.tail_hint, nextSeq)
|
|
1354
|
+
}), signal !== void 0 ? { signal } : void 0);
|
|
1355
|
+
} catch {}
|
|
1356
|
+
};
|
|
1357
|
+
if (args.disabled === true) {
|
|
1358
|
+
await refreshTailHintIfNeeded();
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1240
1361
|
const hardGc = crossesGcBoundary(prevSeq, nextSeq, gcInterval * 4);
|
|
1241
1362
|
if (phasesPerTick === "single" && hardGc) {
|
|
1242
1363
|
await runGc({
|
|
@@ -1254,6 +1375,7 @@ const runBoundedMaintenance = async (args, options) => {
|
|
|
1254
1375
|
minEntriesToCompact,
|
|
1255
1376
|
ceilingBytes: C,
|
|
1256
1377
|
ceilingEntries: E,
|
|
1378
|
+
knownTail: nextSeq,
|
|
1257
1379
|
...signal !== void 0 && { signal }
|
|
1258
1380
|
});
|
|
1259
1381
|
if (phasesPerTick === "single") return;
|
|
@@ -1262,8 +1384,9 @@ const runBoundedMaintenance = async (args, options) => {
|
|
|
1262
1384
|
collection,
|
|
1263
1385
|
dimension: snapshotBytes > C ? "bytes" : "rows"
|
|
1264
1386
|
});
|
|
1387
|
+
await refreshTailHintIfNeeded();
|
|
1265
1388
|
if (nextSeq - (current.last_warned_seq ?? 0) >= 1e3) {
|
|
1266
|
-
console.warn(`baerly-storage: collection "${collection}" is deferring compaction — its snapshot exceeds the fold ceiling (${snapshotBytes > C ?
|
|
1389
|
+
console.warn(`baerly-storage: collection "${collection}" is deferring compaction — its snapshot exceeds the fold ceiling (${snapshotBytes > C ? `${C} bytes` : `${E} rows`}), so the tail keeps growing and read amplification will climb. The dataset has outgrown the maintenance envelope. On paid Cloudflare / Node you can raise BAERLY_MAINTENANCE_MAX_FOLD_BYTES — but on Cloudflare a cap above what a single isolate can fold makes folds get CPU-killed mid-flight and silently not land (no clean metric — watch snapshot age / object count); see docs/about/graduation.md. Otherwise, move to a database service (D1 / Postgres).`);
|
|
1267
1390
|
try {
|
|
1268
1391
|
await casUpdateCurrentJson(storage, currentJsonKey, (c) => ({
|
|
1269
1392
|
...c,
|
|
@@ -1292,4 +1415,4 @@ const dispatchInlineAwaited = (task) => task();
|
|
|
1292
1415
|
//#endregion
|
|
1293
1416
|
export { getCurrentContext as a, noopMetricsRecorder as c, rebuildIndex as i, versionFromContent as l, runBoundedMaintenance as n, allIndexKeysFor as o, shouldFireMaintenance as r, validateIndexDefinition as s, dispatchInlineAwaited as t };
|
|
1294
1417
|
|
|
1295
|
-
//# sourceMappingURL=maintenance-
|
|
1418
|
+
//# sourceMappingURL=maintenance-C7coQp4c.js.map
|