@lunora/do 1.0.0-alpha.296 → 1.0.0-alpha.298
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/dist/index.d.mts
CHANGED
|
@@ -1876,6 +1876,12 @@ declare abstract class ShardDO {
|
|
|
1876
1876
|
* requirement it places on the `ShardHost`.
|
|
1877
1877
|
*/
|
|
1878
1878
|
private readonly inFlightClaims;
|
|
1879
|
+
/**
|
|
1880
|
+
* The CDC presence and epoch memos, and the once-per-wake fork seal. Built
|
|
1881
|
+
* from a `sql` thunk, so this field initializer can run before the
|
|
1882
|
+
* constructor assigns the storage it reads.
|
|
1883
|
+
*/
|
|
1884
|
+
private readonly cdcMeta;
|
|
1879
1885
|
/**
|
|
1880
1886
|
* Changelog retention: the throttled sweep that bounds `__cdc_log` and the
|
|
1881
1887
|
* archive-backed read that serves a consumer once it can no longer be
|
|
@@ -1969,6 +1975,15 @@ declare abstract class ShardDO {
|
|
|
1969
1975
|
private readonly attachmentCache;
|
|
1970
1976
|
/** Sockets whose `serializeAttachment` already reports into {@link ShardDO.attachmentCache}. */
|
|
1971
1977
|
private readonly cacheWiredSockets;
|
|
1978
|
+
/**
|
|
1979
|
+
* Sockets whose attachment the runtime refused to grow by a table set: the sets were shed for a
|
|
1980
|
+
* registration, or a widening write threw. Near the size limit every push would otherwise retry a
|
|
1981
|
+
* refused serialize; the mark lifts when an unsubscribe makes the attachment smaller, and a wake
|
|
1982
|
+
* clears it, which costs one more attempt.
|
|
1983
|
+
*/
|
|
1984
|
+
private readonly tableSetsRefused;
|
|
1985
|
+
/** One-shot warning for the first socket that could not hold its table sets. */
|
|
1986
|
+
private tableSetsRefusedWarned;
|
|
1972
1987
|
/**
|
|
1973
1988
|
* Subscriptions whose refresh keeps throwing, so a deterministic failure is
|
|
1974
1989
|
* not re-run (and re-announced) on every write flush. In memory only, like
|
|
@@ -2212,13 +2227,6 @@ declare abstract class ShardDO {
|
|
|
2212
2227
|
* for why a shared cursor leaves no cheaper recovery.
|
|
2213
2228
|
*/
|
|
2214
2229
|
private globalResyncRequested;
|
|
2215
|
-
/**
|
|
2216
|
-
* Whether this wake has already re-minted the epoch to seal a rolled-back
|
|
2217
|
-
* timeline. In-memory on purpose — see {@link ShardDO.sealForkedTimeline} for
|
|
2218
|
-
* why the seal is capped at one per wake, and why losing the flag on eviction
|
|
2219
|
-
* is the correct direction.
|
|
2220
|
-
*/
|
|
2221
|
-
private forkSealed;
|
|
2222
2230
|
/**
|
|
2223
2231
|
* Wall-clock millis of the last unconditional `.global()` membership pass.
|
|
2224
2232
|
* Bounds how long a write this deployment cannot see in its own changelog —
|
|
@@ -2241,53 +2249,11 @@ declare abstract class ShardDO {
|
|
|
2241
2249
|
*/
|
|
2242
2250
|
private shardBinding;
|
|
2243
2251
|
/**
|
|
2244
|
-
*
|
|
2245
|
-
*
|
|
2246
|
-
*
|
|
2247
|
-
* only saves round trips; it resets with the instance.
|
|
2248
|
-
*/
|
|
2249
|
-
private readonly registeredTables;
|
|
2250
|
-
/**
|
|
2251
|
-
* The hand-offs awaiting the scheduler, per outbox id. `retryOutboxEntry` makes them `stale`
|
|
2252
|
-
* (their failure must not overwrite the reset). Whether one was dropped is read from
|
|
2253
|
-
* {@link ShardDO.scheduleOutboxDroppedThrough} by its token, not inferred from the row, because a
|
|
2254
|
-
* row can also vanish for an innocent reason. In memory is enough: an attempt never outlives the
|
|
2255
|
-
* instance that started it.
|
|
2256
|
-
*/
|
|
2257
|
-
private readonly scheduleOutboxAttempts;
|
|
2258
|
-
/**
|
|
2259
|
-
* Outbox entries an operator is dropping right now. The drop first asks the
|
|
2260
|
-
* scheduler to cancel the job (it may already hold it), and the retry loop must
|
|
2261
|
-
* not hand the entry over again while that is awaiting.
|
|
2262
|
-
*/
|
|
2263
|
-
private readonly scheduleOutboxDrops;
|
|
2264
|
-
/**
|
|
2265
|
-
* Per id, the newest recording an operator dropped: a drop covers every call recorded up to the
|
|
2266
|
-
* row it acted on (including calls of one mutation that a later same-id record replaced), and
|
|
2267
|
-
* no call recorded after it. A missing row alone cannot say "dropped": two calls of one mutation
|
|
2268
|
-
* that share an explicit id share one row, and the first hand-off releases it. Pruned by
|
|
2269
|
-
* {@link ShardDO.pruneScheduleOutboxDropMarker} once no call or attempt it could affect is left.
|
|
2252
|
+
* This shard's registrations with the shard registry. Built from thunks, so
|
|
2253
|
+
* this field initializer can run before the constructor assigns `state` and
|
|
2254
|
+
* `env`, and `shardRegistry` stays the subclass's hook, asked per write.
|
|
2270
2255
|
*/
|
|
2271
|
-
private readonly
|
|
2272
|
-
/**
|
|
2273
|
-
* Calls recorded for an id whose hand-off has not finished (or whose window has not rolled back).
|
|
2274
|
-
* A drop marker is needed exactly that long, so it is pruned when this reaches zero instead of by
|
|
2275
|
-
* count: evicting a marker early would let a queued call of a dropped job run.
|
|
2276
|
-
*/
|
|
2277
|
-
private readonly scheduleOutboxPendingHandOffs;
|
|
2278
|
-
/** The `created_at` last handed to `recordScheduleOutbox`; see {@link ShardDO.scheduleOutbox}. */
|
|
2279
|
-
private lastScheduleOutboxRecordAt;
|
|
2280
|
-
/**
|
|
2281
|
-
* Epoch millis before which registration is not retried, set when one
|
|
2282
|
-
* fails: a registry outage costs one attempt per window rather than one per
|
|
2283
|
-
* write, against the single DO that has to recover.
|
|
2284
|
-
*/
|
|
2285
|
-
private registryRetryAt;
|
|
2286
|
-
/**
|
|
2287
|
-
* Every registry round trip this shard makes, in order — see
|
|
2288
|
-
* {@link ShardDO.serializeRegistry}. Never rejects.
|
|
2289
|
-
*/
|
|
2290
|
-
private registryTail;
|
|
2256
|
+
private readonly shardRegistration;
|
|
2291
2257
|
/**
|
|
2292
2258
|
* Memoised {@link ShardDO.currentAdminBinding} result, keyed by the token it
|
|
2293
2259
|
* was derived from so a rotation within one isolate re-derives rather than
|
|
@@ -2321,19 +2287,11 @@ declare abstract class ShardDO {
|
|
|
2321
2287
|
*/
|
|
2322
2288
|
private readonly usedIndexes;
|
|
2323
2289
|
/**
|
|
2324
|
-
* Per-function
|
|
2325
|
-
*
|
|
2326
|
-
*
|
|
2327
|
-
* hibernation/restart. `functionPath` is caller-controlled (the runtime
|
|
2328
|
-
* forwards it unchecked), so the map is NOT bounded by the app's registered
|
|
2329
|
-
* function count — every path that reaches a metrics-recording dispatch
|
|
2330
|
-
* lands here, including one that resolves to nothing. `recordFunctionCall`
|
|
2331
|
-
* therefore caps it at {@link FUNCTION_METRICS_MAX_PATHS} the same way the
|
|
2332
|
-
* durable `__lunora_metrics` twin caps its table. Maintained by
|
|
2333
|
-
* `recordFunctionCall` at the one dispatch site that also bumps the
|
|
2334
|
-
* aggregate `metrics` counters.
|
|
2290
|
+
* Per-function counters and the coalesced durable delta. Built from thunks,
|
|
2291
|
+
* so this field initializer can run before the constructor assigns `env`
|
|
2292
|
+
* and `shardHost`.
|
|
2335
2293
|
*/
|
|
2336
|
-
private readonly
|
|
2294
|
+
private readonly functionMetrics;
|
|
2337
2295
|
/**
|
|
2338
2296
|
* Recent RPC errors on this shard instance, surfaced by the
|
|
2339
2297
|
* `__lunora_admin__:getLogs` RPC. In-memory only and bounded — like
|
|
@@ -2343,6 +2301,12 @@ declare abstract class ShardDO {
|
|
|
2343
2301
|
* "recent RPC errors on this instance" feed, not a general application log.
|
|
2344
2302
|
*/
|
|
2345
2303
|
private readonly logs;
|
|
2304
|
+
/**
|
|
2305
|
+
* Custody for deferred `ctx.scheduler` calls. Built from thunks, so this field
|
|
2306
|
+
* initializer can run before the constructor assigns the hosts, and the
|
|
2307
|
+
* `scheduleOutboxScheduler` hook stays the subclass's, asked per attempt.
|
|
2308
|
+
*/
|
|
2309
|
+
private readonly scheduleOutboxRunner;
|
|
2346
2310
|
/**
|
|
2347
2311
|
* Recent `ctx.trace` spans (plus the synthetic per-dispatch root), powering
|
|
2348
2312
|
* the studio's Traces panel. In-memory and hibernation-volatile like
|
|
@@ -2389,7 +2353,7 @@ declare abstract class ShardDO {
|
|
|
2389
2353
|
* that queries in a loop reuses the SAME prepared-statement text on every
|
|
2390
2354
|
* iteration (bind parameters travel separately via `...params`, never
|
|
2391
2355
|
* inlined into `query`), so folding each call into its entry as it lands
|
|
2392
|
-
* collapses the loop to one entry — {@link
|
|
2356
|
+
* collapses the loop to one entry — {@link FunctionMetrics.foldStmtSamples} then
|
|
2393
2357
|
* pays one upsert per DISTINCT statement instead of one per raw execution.
|
|
2394
2358
|
* Bounded at {@link MAX_STMT_SAMPLES_PER_DISPATCH} distinct entries; past
|
|
2395
2359
|
* that, a brand-new statement shape (ad-hoc SQL built per iteration) is
|
|
@@ -2401,30 +2365,6 @@ declare abstract class ShardDO {
|
|
|
2401
2365
|
* result-set size only on a host that doesn't expose them.
|
|
2402
2366
|
*/
|
|
2403
2367
|
private currentStmtSamples;
|
|
2404
|
-
/**
|
|
2405
|
-
* Exact per-path metric deltas not yet written to `__lunora_metrics*`. Every
|
|
2406
|
-
* dispatch folds in here; {@link ShardDO.maybeFlushMetrics} writes the sum once
|
|
2407
|
-
* every N dispatches ({@link ShardDO.metricsFlushEvery}, default 8), so rates stay exact
|
|
2408
|
-
* and only write frequency drops. In memory only: an evicted DO loses at most
|
|
2409
|
-
* N-1 dispatches of counters (no alarm flush).
|
|
2410
|
-
*/
|
|
2411
|
-
private pendingFunctionMetrics;
|
|
2412
|
-
/**
|
|
2413
|
-
* Per-statement samples folded from `currentStmtSamples`, written with
|
|
2414
|
-
* {@link ShardDO.pendingFunctionMetrics}. Keyed by statement AND the latency
|
|
2415
|
-
* bucket of each dispatch's own average: `recordQueryMetric` places an entry in the
|
|
2416
|
-
* histogram by its average, so only dispatches in the same bucket may merge (summing 19
|
|
2417
|
-
* fast and 1 slow dispatch would flatten the tail percentiles). The key count also
|
|
2418
|
-
* drives the width-based flush.
|
|
2419
|
-
*/
|
|
2420
|
-
private pendingStmtSamples;
|
|
2421
|
-
/** Dispatches folded since the last flush. */
|
|
2422
|
-
private dispatchesSinceFlush;
|
|
2423
|
-
/** Whether an errored/conflicted dispatch is pending (forces the next flush). */
|
|
2424
|
-
private pendingForceFlush;
|
|
2425
|
-
/** Time of the first / latest dispatch in the pending delta; `undefined` when empty. */
|
|
2426
|
-
private pendingStartedAt;
|
|
2427
|
-
private pendingLastAt;
|
|
2428
2368
|
/**
|
|
2429
2369
|
* The instrumented `sql` proxy built for {@link ShardDO.currentStmtSamples},
|
|
2430
2370
|
* and the samples map it was built for.
|
|
@@ -2437,19 +2377,6 @@ declare abstract class ShardDO {
|
|
|
2437
2377
|
* exists to remove.
|
|
2438
2378
|
*/
|
|
2439
2379
|
private instrumentedSql;
|
|
2440
|
-
/**
|
|
2441
|
-
* Memos for {@link ShardDO.cdcEnabled} and {@link ShardDO.cachedCdcEpoch},
|
|
2442
|
-
* which every flush and resume consults.
|
|
2443
|
-
*
|
|
2444
|
-
* Instance fields, never module state: a native PITR restore reverts
|
|
2445
|
-
* `__cdc_meta` but only takes effect when the object restarts, so a fresh
|
|
2446
|
-
* instance is what guarantees the restored row is read. Presence is
|
|
2447
|
-
* remembered only once TRUE — a migration creates `__cdc_log` mid-instance,
|
|
2448
|
-
* and nothing outside a restore drops it, so a cached `false` is the one
|
|
2449
|
-
* answer that can go stale.
|
|
2450
|
-
*/
|
|
2451
|
-
private cdcLogPresent;
|
|
2452
|
-
private cdcEpochCache;
|
|
2453
2380
|
/**
|
|
2454
2381
|
* Set when `currentStmtSamples` hit {@link MAX_STMT_SAMPLES_PER_DISPATCH}
|
|
2455
2382
|
* distinct statements and a brand-new shape was dropped this dispatch.
|
|
@@ -3350,49 +3277,7 @@ declare abstract class ShardDO {
|
|
|
3350
3277
|
/**
|
|
3351
3278
|
* Mint a fresh CDC epoch because a resume claim just proved this shard's
|
|
3352
3279
|
* changelog forked under it, and return the new value for the outgoing frame.
|
|
3353
|
-
*
|
|
3354
|
-
* The trigger is a client presenting `sinceEpoch === epoch` with `sinceSeq >
|
|
3355
|
-
* cursor`: it holds a cursor this shard once issued on THIS timeline and can
|
|
3356
|
-
* no longer account for. Only a rollback produces that — in practice a native
|
|
3357
|
-
* PITR restore, which is armed in {@link handlePitrAdminOp}.
|
|
3358
|
-
*
|
|
3359
|
-
* **Why the signal has to come from outside SQLite.** A restore reverts the
|
|
3360
|
-
* whole SQLite database, `__cdc_meta` included, so the proactive bump
|
|
3361
|
-
* `pitrRestore` performs is rolled back along with everything else — the
|
|
3362
|
-
* epoch cannot detect the one event it exists for. Nothing durable inside a
|
|
3363
|
-
* SQLite-backed Durable Object escapes that: the KV half of `state.storage`
|
|
3364
|
-
* is the same database, and an alarm is a row in it. So every record of the
|
|
3365
|
-
* pre-restore timeline that survives is somewhere the restore could not
|
|
3366
|
-
* reach, and this shard has exactly two: the cursor a CONSUMER cached (a
|
|
3367
|
-
* subscriber's `sinceSeq` here, a connector's in
|
|
3368
|
-
* {@link ShardDO.runShardCdcSync}, a follower's in `replica.ts`), and the
|
|
3369
|
-
* changelog ARCHIVE's own segments, which R2 keeps while the watermark
|
|
3370
|
-
* naming them rolls back (`cdcArchiveRewound`, consulted by the retention
|
|
3371
|
-
* sweep). Either one calls this, and turning one witness into a shard-wide
|
|
3372
|
-
* epoch bump is what extends the protection to clients that reconnect later,
|
|
3373
|
-
* after post-restore writes have climbed the AUTOINCREMENT back past their
|
|
3374
|
-
* own `sinceSeq` and the `sinceSeq > cursor` guard no longer fires for them.
|
|
3375
|
-
*
|
|
3376
|
-
* **What it detects.** Any rollback under a live subscriber base, promptly: a
|
|
3377
|
-
* restore restarts the object (`ctx.abort()`, or the eviction that lets a
|
|
3378
|
-
* deferred restore apply), which drops every hibernated socket, so the whole
|
|
3379
|
-
* subscriber set reconnects with pre-restore cursors while the restored
|
|
3380
|
-
* cursor is still low. The first of them seals the fork for the rest.
|
|
3381
|
-
*
|
|
3382
|
-
* **What it cannot detect.** A rollback on a shard whose consumers ALL stay
|
|
3383
|
-
* offline until the cursor has climbed back past their cursors, and which
|
|
3384
|
-
* archives nothing — nobody is left to present the proof. A shard with no
|
|
3385
|
-
* subscribers, no connector, no follower and no archive bucket is the
|
|
3386
|
-
* degenerate case of that, and is also the case where nothing is stale.
|
|
3387
|
-
*
|
|
3388
|
-
* **On trusting `sinceSeq`.** It is client-supplied, so a caller that already
|
|
3389
|
-
* knows this shard's epoch can force a bump, and a bump is shard-wide: every
|
|
3390
|
-
* subscriber takes a full snapshot instead of a resume on its NEXT reconnect.
|
|
3391
|
-
* The cost is bounded (the once-per-wake latch below) and deferred — nothing
|
|
3392
|
-
* is pushed and no live subscription is interrupted — and it stays strictly
|
|
3393
|
-
* less than what the same caller can already spend by subscribing without a
|
|
3394
|
-
* `sinceSeq` at all.
|
|
3395
|
-
* @returns the freshly minted epoch, to stamp on the frame this verdict produces
|
|
3280
|
+
* At most once per wake; see {@link CdcMeta.sealForkedTimeline} for why.
|
|
3396
3281
|
*/
|
|
3397
3282
|
protected sealForkedTimeline(): string;
|
|
3398
3283
|
/**
|
|
@@ -3934,25 +3819,9 @@ declare abstract class ShardDO {
|
|
|
3934
3819
|
protected scheduleTtlSweep(): Promise<void>;
|
|
3935
3820
|
/**
|
|
3936
3821
|
* Durable custody for this shard's deferred `ctx.scheduler` calls — the
|
|
3937
|
-
* `ScheduleOutbox` the generated `buildCtx` hands to
|
|
3938
|
-
* `
|
|
3939
|
-
*
|
|
3940
|
-
* The two halves land on opposite sides of the COMMIT on purpose:
|
|
3941
|
-
*
|
|
3942
|
-
* - `record` runs while the handler is still inside its transaction, so the
|
|
3943
|
-
* entry is durable exactly when the writes are and rolls back with them.
|
|
3944
|
-
* It deliberately does NOT swallow: a failure here is still inside the span,
|
|
3945
|
-
* so letting it throw rolls the mutation back — the one moment at which
|
|
3946
|
-
* failing is free. Swallowing would put us back where we started, committing
|
|
3947
|
-
* writes whose job nothing is holding.
|
|
3948
|
-
* - `forget` runs after the dispatch, so it must never fail the response. A
|
|
3949
|
-
* delete that does not land leaves an entry the retry loop re-offers, which
|
|
3950
|
-
* the scheduler refuses as a duplicate and which is then dropped — the error
|
|
3951
|
-
* self-heals into one wasted RPC.
|
|
3952
|
-
*
|
|
3953
|
-
* What survives a settle is therefore exactly the set of jobs that were
|
|
3954
|
-
* promised and not enqueued, which is what {@link ShardDO.pollScheduleOutbox}
|
|
3955
|
-
* drains.
|
|
3822
|
+
* `ScheduleOutbox` the generated `buildCtx` hands to `withDeferredSchedules`.
|
|
3823
|
+
* See {@link ScheduleOutboxRunner.scheduleOutbox} for why `record` and
|
|
3824
|
+
* `forget` land on opposite sides of the COMMIT.
|
|
3956
3825
|
*/
|
|
3957
3826
|
protected scheduleOutbox(): ScheduleOutbox;
|
|
3958
3827
|
/**
|
|
@@ -3970,29 +3839,8 @@ declare abstract class ShardDO {
|
|
|
3970
3839
|
protected scheduleOutboxScheduler(): SchedulerLike | undefined;
|
|
3971
3840
|
/**
|
|
3972
3841
|
* Re-offer the deferred schedules that were promised to a caller and never
|
|
3973
|
-
* reached the scheduler
|
|
3974
|
-
*
|
|
3975
|
-
* earliest next-due time the same way, so a shard with an empty outbox (the
|
|
3976
|
-
* steady state — an entry lives only between a COMMIT and its dispatch) arms
|
|
3977
|
-
* nothing.
|
|
3978
|
-
*
|
|
3979
|
-
* Each attempt reuses the id the caller was already handed, so an entry whose
|
|
3980
|
-
* original dispatch DID land — the failure was the `forget`, or the isolate
|
|
3981
|
-
* died between the two — is refused as a duplicate rather than scheduled
|
|
3982
|
-
* twice. A refusal and an acceptance are therefore both "the scheduler has
|
|
3983
|
-
* it", and both end custody.
|
|
3984
|
-
*
|
|
3985
|
-
* The default bound is {@link SCHEDULE_OUTBOX_MAX_ATTEMPTS}: a job the
|
|
3986
|
-
* scheduler will never accept stops costing alarms and becomes a reported
|
|
3987
|
-
* fact instead — parked, logged at `error` with its id and target, and kept
|
|
3988
|
-
* for {@link SCHEDULE_OUTBOX_RETENTION_MS} so an operator can see what was
|
|
3989
|
-
* promised and never enqueued. A call made with `retry.forever` opts out of
|
|
3990
|
-
* that ceiling: it stays live, paced by the ladder's last rung, until the
|
|
3991
|
-
* scheduler accepts it or refuses it as invalid. The retention sweep only
|
|
3992
|
-
* ever drops parked rows. The sweep rides whatever tick reaches this tier, so a shard
|
|
3993
|
-
* holding ONLY parked entries keeps them until something else wakes it —
|
|
3994
|
-
* which is the right trade: they are one row per genuinely lost job, not a
|
|
3995
|
-
* loop that grows on its own.
|
|
3842
|
+
* reached the scheduler; see {@link ScheduleOutboxRunner.pollScheduleOutbox}.
|
|
3843
|
+
* Reports the earliest next-due time, like the other poll tiers.
|
|
3996
3844
|
*/
|
|
3997
3845
|
protected pollScheduleOutbox(trace?: TraceRefLike): Promise<number | undefined>;
|
|
3998
3846
|
/** This DO's shard key (its DO name), or `__root__` for the single-DO default. The `tenantBy` mapper binds it into the source query. */
|
|
@@ -4519,6 +4367,24 @@ declare abstract class ShardDO {
|
|
|
4519
4367
|
* trace ids to needs a way to say so.
|
|
4520
4368
|
*/
|
|
4521
4369
|
protected makeFetch(functionPath: string, anchor: TraceAnchor, sink?: TelemetrySink, scope?: SensitiveScope): ContextFetch;
|
|
4370
|
+
/**
|
|
4371
|
+
* Build `ctx.span` — the handle onto the **dispatch's own span**, and with it
|
|
4372
|
+
* the wide-event surface.
|
|
4373
|
+
*
|
|
4374
|
+
* `ctx.trace(...)` creates a *new* child span for a sub-operation; this
|
|
4375
|
+
* attaches to the one that already exists for the request. That is the
|
|
4376
|
+
* distinction between "time this thing" and "record a fact about this
|
|
4377
|
+
* request", and conflating them is why instrumentation usually degrades into
|
|
4378
|
+
* log spam: with nowhere to put a fact, people reach for `ctx.log.info`.
|
|
4379
|
+
*
|
|
4380
|
+
* Attributes accumulate across the whole dispatch and are folded into the
|
|
4381
|
+
* root span in `recordDispatchRootSpan` — the OTel-native form of a
|
|
4382
|
+
* wide event, needing no non-standard "canonical log line" convention on the
|
|
4383
|
+
* collector side.
|
|
4384
|
+
*
|
|
4385
|
+
* Keyed by `dispatchSpanKey` — trace id AND root span id — so two concurrent
|
|
4386
|
+
* dispatches forwarded under the same client trace accumulate separately.
|
|
4387
|
+
*/
|
|
4522
4388
|
protected makeDispatchSpan(anchor: TraceAnchor, sink?: TelemetrySink, scope?: SensitiveScope): SpanHandle;
|
|
4523
4389
|
/**
|
|
4524
4390
|
* Build the `ctx.metrics` recorder for one dispatched function. Thin wiring
|
|
@@ -4552,24 +4418,6 @@ declare abstract class ShardDO {
|
|
|
4552
4418
|
* as the host-specific handler while the engine is progressively extracted.
|
|
4553
4419
|
*/
|
|
4554
4420
|
protected handleAlarmCloudflare(): Promise<void>;
|
|
4555
|
-
/**
|
|
4556
|
-
* Build `ctx.span` — the handle onto the **dispatch's own span**, and with it
|
|
4557
|
-
* the wide-event surface.
|
|
4558
|
-
*
|
|
4559
|
-
* `ctx.trace(...)` creates a *new* child span for a sub-operation; this
|
|
4560
|
-
* attaches to the one that already exists for the request. That is the
|
|
4561
|
-
* distinction between "time this thing" and "record a fact about this
|
|
4562
|
-
* request", and conflating them is why instrumentation usually degrades into
|
|
4563
|
-
* log spam: with nowhere to put a fact, people reach for `ctx.log.info`.
|
|
4564
|
-
*
|
|
4565
|
-
* Attributes accumulate across the whole dispatch and are folded into the
|
|
4566
|
-
* root span in `recordDispatchRootSpan` — the OTel-native form of a
|
|
4567
|
-
* wide event, needing no non-standard "canonical log line" convention on the
|
|
4568
|
-
* collector side.
|
|
4569
|
-
*
|
|
4570
|
-
* Keyed by `dispatchSpanKey` — trace id AND root span id — so two concurrent
|
|
4571
|
-
* dispatches forwarded under the same client trace accumulate separately.
|
|
4572
|
-
*/
|
|
4573
4421
|
/**
|
|
4574
4422
|
* Snapshot the per-request identity/replay fields into a {@link RequestScope}.
|
|
4575
4423
|
* Paired with {@link ShardDO.restoreRequestScope}; see that type's docstring
|
|
@@ -4585,6 +4433,22 @@ declare abstract class ShardDO {
|
|
|
4585
4433
|
* as this request's. The dispatch path re-pins its own afterwards.
|
|
4586
4434
|
*/
|
|
4587
4435
|
protected restoreRequestScope(scope: RequestScope): void;
|
|
4436
|
+
/** The `connect` control frame: verify a pending socket, send its identity, and fire `onConnect` once. */
|
|
4437
|
+
private handleConnectFrame;
|
|
4438
|
+
/** A live-query `subscribe` frame: gate it, register it on the socket, and seed it. */
|
|
4439
|
+
private handleSubscribeFrame;
|
|
4440
|
+
/** A `shape_subscribe` frame: decode its args and hand it to {@link ShardDO.handleShapeSubscribe}. */
|
|
4441
|
+
private handleShapeSubscribeFrame;
|
|
4442
|
+
/** A `shape_unsubscribe` frame. */
|
|
4443
|
+
private handleShapeUnsubscribeFrame;
|
|
4444
|
+
/** A `stream` frame: refuse admin and paid functions, decode the args, and start the stream without awaiting it. */
|
|
4445
|
+
private handleStreamFrame;
|
|
4446
|
+
/** A `whisper_subscribe` / `whisper_unsubscribe` frame: join or leave a topic, running a room's `onJoin` / `onLeave`. */
|
|
4447
|
+
private handleWhisperMembershipFrame;
|
|
4448
|
+
/** A `whisper` frame: relay it to the topic, or dispatch a room's `onMessage`. */
|
|
4449
|
+
private handleWhisperFrame;
|
|
4450
|
+
/** An `unsubscribe` frame: cancel a stream with that id, if any, and drop the subscription. */
|
|
4451
|
+
private handleUnsubscribeFrame;
|
|
4588
4452
|
/**
|
|
4589
4453
|
* Load `functionPath`'s module before a live-query gate reads its registry entry: a lazy
|
|
4590
4454
|
* registry's stub carries no `perDispatch` until then, so the gate would wave a cold per-dispatch
|
|
@@ -4847,106 +4711,6 @@ declare abstract class ShardDO {
|
|
|
4847
4711
|
* the close path.
|
|
4848
4712
|
*/
|
|
4849
4713
|
private purgeDurableSocketBaselines;
|
|
4850
|
-
/**
|
|
4851
|
-
* Fold one dispatch into the per-function counters keyed by `functionPath`,
|
|
4852
|
-
* creating the entry on first sight. `errorMessage` is supplied only when
|
|
4853
|
-
* the handler threw, in which case the failure counters advance too. The
|
|
4854
|
-
* caller is expected to have already redacted `errorMessage` (via
|
|
4855
|
-
* `redactArgs`, the same `standardRules` treatment the request-log sinks
|
|
4856
|
-
* use) — this method persists/caches it verbatim into BOTH the durable
|
|
4857
|
-
* `__lunora_metrics.last_error_message` column and the in-memory
|
|
4858
|
-
* `functionStats.lastErrorMessage` served by `getFunctionStats`, so an
|
|
4859
|
-
* un-redacted message reaching here leaks into the Studio.
|
|
4860
|
-
* `scannedTables` carries the tables the dispatch full-scanned (collected by
|
|
4861
|
-
* `getCtxDbReadHook`), which advance the causal scan attribution.
|
|
4862
|
-
* `indexHits` carries the declared indexes it exercised (collected by
|
|
4863
|
-
* `getCtxDbIndexUseHook`, NUL-free `JSON.stringify([table, index])` keys),
|
|
4864
|
-
* which advance the durable `__lunora_metrics_index` hit counter behind the
|
|
4865
|
-
* dead-index lint. Called once per `/rpc` dispatch alongside the aggregate
|
|
4866
|
-
* `metrics` update.
|
|
4867
|
-
*
|
|
4868
|
-
* Two writes happen here. The in-memory {@link functionStats} map is kept
|
|
4869
|
-
* for the fast warm-instance path, and the durable `__lunora_metrics`
|
|
4870
|
-
* table is upserted so the counters survive hibernation/restart — the
|
|
4871
|
-
* persisted table is the source of truth the admin RPCs read from. The
|
|
4872
|
-
* persist is best-effort: a SQL failure (e.g. a test double without a
|
|
4873
|
-
* `sql` handle) must never turn a successful dispatch into a failed one,
|
|
4874
|
-
* so it is swallowed and the in-memory counters still advance.
|
|
4875
|
-
*
|
|
4876
|
-
* The durable write is COALESCED, not per-dispatch: the call is folded into
|
|
4877
|
-
* {@link ShardDO.pendingFunctionMetrics} (exact counts, durations, scans and
|
|
4878
|
-
* index hits) and {@link ShardDO.maybeFlushMetrics} writes the whole delta once
|
|
4879
|
-
* every N dispatches ({@link ShardDO.metricsFlushEvery}; default 8; 1 = every dispatch),
|
|
4880
|
-
* so the durable counters stay exact and only the write frequency drops.
|
|
4881
|
-
*/
|
|
4882
|
-
private recordFunctionCall;
|
|
4883
|
-
/**
|
|
4884
|
-
* Fold the per-DISTINCT-statement SQL samples accumulated during the current
|
|
4885
|
-
* dispatch into {@link ShardDO.pendingStmtSamples}. Called after
|
|
4886
|
-
* `recordFunctionCall` on both the success and error paths, followed by
|
|
4887
|
-
* {@link ShardDO.maybeFlushMetrics}.
|
|
4888
|
-
*
|
|
4889
|
-
* Already folded by the instrumented `sql` getter (see `currentStmtSamples`);
|
|
4890
|
-
* `count` carries the real execution count so the durable
|
|
4891
|
-
* `exec_count`/`total_duration_ms` still reflect every execution. Pure
|
|
4892
|
-
* in-memory; nothing is written until the flush. Clearing `currentStmtSamples`
|
|
4893
|
-
* happens in the `finally` block of the dispatch path, not here.
|
|
4894
|
-
*/
|
|
4895
|
-
private foldStmtSamples;
|
|
4896
|
-
/** Fold one completed dispatch into {@link ShardDO.pendingFunctionMetrics}. */
|
|
4897
|
-
private foldFunctionMetric;
|
|
4898
|
-
/**
|
|
4899
|
-
* Write the pending metric delta when this dispatch is due: every
|
|
4900
|
-
* N dispatches ({@link ShardDO.metricsFlushEvery}), immediately after an errored or
|
|
4901
|
-
* conflicted one, or when the pending statement set is as wide as one
|
|
4902
|
-
* dispatch may be. (A minute-boundary crossing flushes earlier, inside
|
|
4903
|
-
* {@link ShardDO.foldFunctionMetric}.) Counts are exact either way; at most
|
|
4904
|
-
* N-1 dispatches of counters are lost if the DO is evicted before a flush.
|
|
4905
|
-
*/
|
|
4906
|
-
private maybeFlushMetrics;
|
|
4907
|
-
/**
|
|
4908
|
-
* Persist the pending delta: one `recordFunctionMetric` per path and one
|
|
4909
|
-
* `recordQueryMetric` per (statement, latency bucket) key, so the
|
|
4910
|
-
* histogram still sees each dispatch's own average. The accumulators are swapped out
|
|
4911
|
-
* first, so a write that throws DROPS that path's (or entry's) delta and the rest
|
|
4912
|
-
* of the batch is still written. There is deliberately no retry: metrics are
|
|
4913
|
-
* best-effort, `recordFunctionMetric` is several statements per path and the host
|
|
4914
|
-
* exposes no synchronous transaction, so a retry after a partial write would double
|
|
4915
|
-
* count, and a persistent failure would grow the pending set without bound. One
|
|
4916
|
-
* warning per flush reports what was dropped. Never fails the request.
|
|
4917
|
-
*/
|
|
4918
|
-
private flushPendingMetrics;
|
|
4919
|
-
/** Write any coalesced delta so an admin read of the durable metric tables is never stale. */
|
|
4920
|
-
private flushUnwrittenMetrics;
|
|
4921
|
-
/**
|
|
4922
|
-
* Dispatches per durable metric write (env `LUNORA_METRICS_FLUSH_EVERY`): a positive
|
|
4923
|
-
* integer, default {@link DEFAULT_METRICS_FLUSH_EVERY} (8). Unset, blank, fractional,
|
|
4924
|
-
* non-numeric or < 1 values fall back to the default. An evicted DO loses at most N-1
|
|
4925
|
-
* dispatches of un-flushed counters (7 by default); errored or conflicted dispatches
|
|
4926
|
-
* and minute-boundary crossings still flush immediately. Set 1 to write every dispatch.
|
|
4927
|
-
*/
|
|
4928
|
-
private metricsFlushEvery;
|
|
4929
|
-
/**
|
|
4930
|
-
* Assemble the per-function readout served by
|
|
4931
|
-
* `__lunora_admin__:getFunctionStats`, sorted most-recently-called first so
|
|
4932
|
-
* the busiest functions surface at the top of the studio table.
|
|
4933
|
-
*
|
|
4934
|
-
* Reads from the durable `__lunora_metrics` table — the source of truth —
|
|
4935
|
-
* so the counts reflect the function's lifetime, not just calls since this
|
|
4936
|
-
* instance woke. Falls back to the in-memory map only if the durable read
|
|
4937
|
-
* throws (e.g. a test double without a usable `sql` handle), keeping the
|
|
4938
|
-
* warm-instance counters available even then. The wire shape is unchanged
|
|
4939
|
-
* (`{ functions, sinceMs }`), so existing studio/runtime consumers keep
|
|
4940
|
-
* working; the rows are now backed by persisted data.
|
|
4941
|
-
*/
|
|
4942
|
-
private collectFunctionStats;
|
|
4943
|
-
/**
|
|
4944
|
-
* Per-function coarse time-series served additively by the metrics RPC, so
|
|
4945
|
-
* the studio can chart call/error history. Reads the durable
|
|
4946
|
-
* `__lunora_metrics_buckets` table; returns an empty, non-truncated result
|
|
4947
|
-
* when persistence is unavailable so the response stays well-formed.
|
|
4948
|
-
*/
|
|
4949
|
-
private collectFunctionMetricBuckets;
|
|
4950
4714
|
private maybeWarnRootSize;
|
|
4951
4715
|
/**
|
|
4952
4716
|
* Map a thrown value to a JSON response. `ValidationError` from
|
|
@@ -5354,38 +5118,14 @@ declare abstract class ShardDO {
|
|
|
5354
5118
|
private handleRecordQueueMessage;
|
|
5355
5119
|
/**
|
|
5356
5120
|
* Serve `dropOutboxEntry` — cancel a deferred schedule the scheduler never
|
|
5357
|
-
* confirmed
|
|
5358
|
-
* SchedulerDO holds, so this is the only way to stop a `retry.forever` entry
|
|
5359
|
-
* that is still waiting.
|
|
5360
|
-
*
|
|
5361
|
-
* The shard cannot always tell that the scheduler never got the job: the accept
|
|
5362
|
-
* may have been lost on the way back, or an attempt may be awaiting it right now.
|
|
5363
|
-
* So the drop cancels the id at the scheduler FIRST and deletes the row only once
|
|
5364
|
-
* that settled. A cancel that fails (the scheduler is often the very thing that is down)
|
|
5365
|
-
* parks the entry so it can never be handed over, and the error goes to the operator;
|
|
5366
|
-
* dropping again completes it. And an attempt that was already in the air takes the job back out
|
|
5367
|
-
* when it lands, see {@link ShardDO.retryScheduleOutboxEntry}. Admin-gated by the caller.
|
|
5121
|
+
* confirmed; see {@link ScheduleOutboxRunner.drop}. Admin-gated by the caller.
|
|
5368
5122
|
*/
|
|
5369
5123
|
private handleDropOutboxEntry;
|
|
5370
5124
|
/**
|
|
5371
|
-
*
|
|
5372
|
-
*
|
|
5373
|
-
*
|
|
5374
|
-
*
|
|
5375
|
-
*/
|
|
5376
|
-
private auditAppliedScheduleOutboxDrop;
|
|
5377
|
-
/**
|
|
5378
|
-
* With no scheduler to ask, waiting never confirms the cancel. The first drop parked the row (a
|
|
5379
|
-
* job may have been accepted under a binding that has since gone); dropping a row that was already
|
|
5380
|
-
* parked, with nothing in flight, is the operator accepting that, and removes it.
|
|
5381
|
-
* @returns whether the row was removed
|
|
5382
|
-
*/
|
|
5383
|
-
private removeUnconfirmableScheduleOutboxDrop;
|
|
5384
|
-
/**
|
|
5385
|
-
* Serve `retryOutboxEntry` — put an entry back on the retry ladder, due now:
|
|
5386
|
-
* the way back for a parked entry, and a way to skip a long backoff once the
|
|
5387
|
-
* scheduler is healthy. Arms the poll alarm for now, because nothing else is
|
|
5388
|
-
* due to wake a shard whose entries were all parked. Admin-gated by the caller.
|
|
5125
|
+
* Serve `retryOutboxEntry` — put an entry back on the retry ladder, due now
|
|
5126
|
+
* (see {@link ScheduleOutboxRunner.retry}), and arm the poll alarm for now,
|
|
5127
|
+
* because nothing else is due to wake a shard whose entries were all parked.
|
|
5128
|
+
* Admin-gated by the caller.
|
|
5389
5129
|
*/
|
|
5390
5130
|
private handleRetryOutboxEntry;
|
|
5391
5131
|
/** Empty the dev queue consumed-message log (studio "clear log" action). Admin-gated by the caller. */
|
|
@@ -5883,51 +5623,13 @@ declare abstract class ShardDO {
|
|
|
5883
5623
|
* middleware. Identity-scoping the key is what keeps that impossible.
|
|
5884
5624
|
*/
|
|
5885
5625
|
private attachDurableStream;
|
|
5886
|
-
/**
|
|
5887
|
-
* Run one registry step after every step before it. Registration and release
|
|
5888
|
-
* both go through here, so a release's emptiness check and unregister can
|
|
5889
|
-
* never interleave with a registration: a write that lands mid-release
|
|
5890
|
-
* registers AFTER the unregister, not before it.
|
|
5891
|
-
*/
|
|
5892
|
-
private serializeRegistry;
|
|
5893
|
-
/** The registry stub, pinned to this DO's own jurisdiction — the subnamespace the worker pins the registry it reads. */
|
|
5894
|
-
private registryStub;
|
|
5895
|
-
/**
|
|
5896
|
-
* Where this shard's registry writes go. A Durable Object namespace is this app's own
|
|
5897
|
-
* registry: signed directly with this worker's secret. Anything else is the RPC surface of
|
|
5898
|
-
* the worker that hosts the registry, reached through its service binding, so the binding
|
|
5899
|
-
* itself is the capability and no secret is needed. `undefined` when a namespace is not in
|
|
5900
|
-
* this shard's jurisdiction.
|
|
5901
|
-
*/
|
|
5902
|
-
private registryWriter;
|
|
5903
|
-
/**
|
|
5904
|
-
* Tell the shard registry this shard holds rows of each `.shardBy()` table
|
|
5905
|
-
* the flushed write touched, once per table per instance. The cross-shard
|
|
5906
|
-
* fan-outs (export, CDC sync, migrations) only reach the shards the registry
|
|
5907
|
-
* lists, so a shard that never registers is left out of every one of them.
|
|
5908
|
-
*
|
|
5909
|
-
* Runs past the response (see `flushChangedTables`) and never rejects: the
|
|
5910
|
-
* write has already committed, so a failure is logged, the table's claim
|
|
5911
|
-
* released, and the first write after {@link SHARD_REGISTRY_RETRY_MS} retries.
|
|
5912
|
-
*/
|
|
5913
|
-
private registerWrittenShard;
|
|
5914
5626
|
/**
|
|
5915
5627
|
* `__lunora_admin__:releaseShardRegistration`: drop this shard from the
|
|
5916
5628
|
* registry for each named table it holds no rows of, and keep it for the rest.
|
|
5917
|
-
*
|
|
5918
|
-
*
|
|
5919
|
-
* be ordered against this shard's own writes. It runs on the registry chain
|
|
5920
|
-
* (see {@link ShardDO.serializeRegistry}) and clears the table's claim, so a
|
|
5921
|
-
* row written before the check is seen by it and keeps the table, and one
|
|
5922
|
-
* written after re-registers once the unregister has landed. A caller that
|
|
5923
|
-
* probed first and unregistered second could hide a shard written in between:
|
|
5924
|
-
* its claim would say "registered" while the registry said otherwise.
|
|
5925
|
-
*
|
|
5926
|
-
* A soft-deleted row still counts as a row — the shard is kept.
|
|
5629
|
+
* See {@link ShardRegistration.release} for why the shard, not the caller,
|
|
5630
|
+
* decides.
|
|
5927
5631
|
*/
|
|
5928
5632
|
private handleReleaseShardRegistration;
|
|
5929
|
-
/** Whether this shard's SQLite holds at least one row of `table` — `false` for a table it never created. */
|
|
5930
|
-
private tableHasRows;
|
|
5931
5633
|
/**
|
|
5932
5634
|
* Drain the tables written during the in-flight RPC and re-run every
|
|
5933
5635
|
* subscription that depends on one of them. Called after `handleRpc`
|
|
@@ -6423,74 +6125,6 @@ declare abstract class ShardDO {
|
|
|
6423
6125
|
* deferral itself is the caller's job: this only reports it.
|
|
6424
6126
|
*/
|
|
6425
6127
|
private recordScheduleRateDeferral;
|
|
6426
|
-
/**
|
|
6427
|
-
* One outbox attempt: replay the stored call, then either end custody or push
|
|
6428
|
-
* the entry out along {@link SCHEDULE_OUTBOX_BACKOFF_MS}. The default policy
|
|
6429
|
-
* parks once the ladder runs out; `retry.forever` keeps a valid call live.
|
|
6430
|
-
*
|
|
6431
|
-
* An envelope that will not parse is parked immediately rather than retried:
|
|
6432
|
-
* no number of attempts turns malformed JSON into a job, and the log line is
|
|
6433
|
-
* the only useful output left.
|
|
6434
|
-
*/
|
|
6435
|
-
private retryScheduleOutboxEntry;
|
|
6436
|
-
/**
|
|
6437
|
-
* The post-commit hand-off of a deferred schedule, run as a recorded attempt like every retry:
|
|
6438
|
-
* a drop that arrives while the call awaits the scheduler is seen here and the job is cancelled
|
|
6439
|
-
* when it lands (the row stays parked if that cancel fails). A failure leaves the row for the
|
|
6440
|
-
* retry loop, unless a drop already ended the entry, in which case the row goes.
|
|
6441
|
-
*/
|
|
6442
|
-
private runScheduleOutboxHandOff;
|
|
6443
|
-
private handOffRecordedScheduleOutboxCall;
|
|
6444
|
-
private markScheduleOutboxDropped;
|
|
6445
|
-
private isScheduleOutboxBeingDropped;
|
|
6446
|
-
/** One recorded call is done with: handed off, skipped, or rolled back with its window. */
|
|
6447
|
-
private finishScheduleOutboxHandOff;
|
|
6448
|
-
/**
|
|
6449
|
-
* Forget the drop marker of `id` once nothing it could still decide is left: no recorded call
|
|
6450
|
-
* waiting for its hand-off, no attempt awaiting the scheduler, no drop in flight. Pruned by that
|
|
6451
|
-
* condition rather than by count, because evicting a marker early would let a queued call of a
|
|
6452
|
-
* dropped job go out.
|
|
6453
|
-
*/
|
|
6454
|
-
private pruneScheduleOutboxDropMarker;
|
|
6455
|
-
/** Whether a drop covers the recording `token` names: recorded no later than the row it acted on. */
|
|
6456
|
-
private isScheduleOutboxTokenDropped;
|
|
6457
|
-
/** Whether the entry this attempt was made for has been dropped, now or while it was in the air. */
|
|
6458
|
-
private wasScheduleOutboxDropped;
|
|
6459
|
-
private releaseScheduleOutboxAttempt;
|
|
6460
|
-
/** A hand-off that threw: end custody if the scheduler turns out to hold the job, else defer or park the entry. */
|
|
6461
|
-
private settleFailedScheduleOutboxAttempt;
|
|
6462
|
-
/**
|
|
6463
|
-
* The scheduler holds the job: end custody. If the entry was dropped while the
|
|
6464
|
-
* hand-off was awaiting (or a drop is cancelling it right now), the operator asked
|
|
6465
|
-
* for the job NOT to run, so take it back out of the scheduler. `landed` says the scheduler
|
|
6466
|
-
* is known to hold (or to have held) the job, which is what makes a "not found" cancel a failure.
|
|
6467
|
-
*/
|
|
6468
|
-
private settleScheduleOutboxHandOff;
|
|
6469
|
-
/** Park `id` if it is still live, keeping its attempt count; a parked or absent row is left as it is. */
|
|
6470
|
-
private parkLiveScheduleOutboxEntry;
|
|
6471
|
-
/**
|
|
6472
|
-
* Push one entry out along the ladder. A `retry.forever` entry that reaches
|
|
6473
|
-
* the attempts a default entry would have parked at says so once, at `warn`:
|
|
6474
|
-
* past that point nothing else reports that the job is still not enqueued.
|
|
6475
|
-
*/
|
|
6476
|
-
private deferScheduleOutboxEntry;
|
|
6477
|
-
/** Park one entry and say so at `error` — a job was promised to a caller and will not be enqueued. */
|
|
6478
|
-
private parkScheduleOutboxEntry;
|
|
6479
|
-
/**
|
|
6480
|
-
* Arm the poll alarm once per warm instance if this shard is holding deferred
|
|
6481
|
-
* schedules nobody has enqueued.
|
|
6482
|
-
*
|
|
6483
|
-
* The settle asks for a wake when its own dispatch fails, but the window that
|
|
6484
|
-
* loses a job most quietly is the one where no settle ran at all: the DO is
|
|
6485
|
-
* evicted between the COMMIT and the dispatch, and the entry sits with nothing
|
|
6486
|
-
* pointing at it. Every entry point into this object goes through shard init,
|
|
6487
|
-
* so hooking it here means the next time anything wakes this shard the retry
|
|
6488
|
-
* loop starts — for the cost of one indexed read per cold start.
|
|
6489
|
-
*
|
|
6490
|
-
* Swallows: a shard whose store predates the table (or a harness with a stub
|
|
6491
|
-
* handle) simply has no custody to resume, and init must not fail for it.
|
|
6492
|
-
*/
|
|
6493
|
-
private armScheduleOutboxRetry;
|
|
6494
6128
|
/**
|
|
6495
6129
|
* When the TTL tier should next wake for `specs`: 1 ms past the earliest live
|
|
6496
6130
|
* expiry (the sweep's `expiry < now` is strict), but never before `now +`
|
|
@@ -6859,6 +6493,33 @@ declare abstract class ShardDO {
|
|
|
6859
6493
|
* write-flush can diff against it.
|
|
6860
6494
|
*/
|
|
6861
6495
|
private seedSubscriptionMemo;
|
|
6496
|
+
/**
|
|
6497
|
+
* Lift `ws`'s `tableSetsRefused` mark ahead of a subscribe that replaces an id, which can shrink the
|
|
6498
|
+
* attachment enough to fit table sets again. Lifted before the write, so a write that has to shed the
|
|
6499
|
+
* sets marks the socket again; the returned call puts the mark back when that write fails and rolls back.
|
|
6500
|
+
*/
|
|
6501
|
+
private liftRefusedMark;
|
|
6502
|
+
private markTableSetsRefused;
|
|
6503
|
+
/**
|
|
6504
|
+
* Remove `subId`'s persisted table set, if it has one, so after a wake it counts as unknown and
|
|
6505
|
+
* re-runs. The attachment without the entry is smaller than the one the runtime holds, so it fits.
|
|
6506
|
+
*/
|
|
6507
|
+
private dropSubscriptionTables;
|
|
6508
|
+
/**
|
|
6509
|
+
* Fold the tables `subId`'s memo just recorded into the attachment's `subTables`, the
|
|
6510
|
+
* copy of its dependency set that outlives hibernation. Every memo table write goes
|
|
6511
|
+
* through here: the persisted set may over-cover a cold memo, never under-cover it.
|
|
6512
|
+
* Writes only when the set grows, so a steady subscription costs no attachment write.
|
|
6513
|
+
*
|
|
6514
|
+
* A memo that re-runs on every write (admin wildcard, `retryData`) leaves no entry, and
|
|
6515
|
+
* so does a widened set the runtime refuses to store: keeping the older, smaller set
|
|
6516
|
+
* would let a write to the newly read table skip the subscription after a wake. The
|
|
6517
|
+
* attachment without the entry is smaller than the one the runtime already holds, so
|
|
6518
|
+
* it fits. A socket the runtime refused once is not widened again until an unsubscribe
|
|
6519
|
+
* frees room (see `tableSetsRefused`). Never throws: a lost entry only costs a re-run
|
|
6520
|
+
* after the next wake.
|
|
6521
|
+
*/
|
|
6522
|
+
private persistSubscriptionTables;
|
|
6862
6523
|
/**
|
|
6863
6524
|
* Memoise `outcome` for `(ws, subId)` and push it to the socket, unless an
|
|
6864
6525
|
* identical result was already sent. Always refreshes the memo's table set
|
|
@@ -7007,27 +6668,6 @@ declare abstract class ShardDO {
|
|
|
7007
6668
|
private reauthenticateSocket;
|
|
7008
6669
|
private routeNonRpc;
|
|
7009
6670
|
private handleWebSocketUpgrade;
|
|
7010
|
-
/**
|
|
7011
|
-
* Whether this shard has a `__cdc_log` table. The single source of the
|
|
7012
|
-
* "is CDC on here?" probe shared by {@link currentCdcCursor},
|
|
7013
|
-
* {@link currentCdcEpoch}, {@link evaluateResume}, and the PITR-restore epoch
|
|
7014
|
-
* bump. Returns `false` (rather than throwing) on a stub `sql` handle (unit
|
|
7015
|
-
* harness double) or a pre-CDC shard, so callers degrade to the no-CDC path.
|
|
7016
|
-
*/
|
|
7017
|
-
private cdcEnabled;
|
|
7018
|
-
/**
|
|
7019
|
-
* The `__cdc_meta` epoch, read from SQLite at most once until
|
|
7020
|
-
* {@link invalidateCdcMetaCache} runs. Callers gate on {@link cdcEnabled}
|
|
7021
|
-
* first, except {@link sealForkedTimeline}, whose callers already proved it.
|
|
7022
|
-
*/
|
|
7023
|
-
private cachedCdcEpoch;
|
|
7024
|
-
/** Bump the CDC epoch and drop the CDC memos in one step, so no caller can bump without invalidating. */
|
|
7025
|
-
private bumpCdcEpochUncached;
|
|
7026
|
-
/**
|
|
7027
|
-
* Drop both CDC memos — the single exit for every path that can change
|
|
7028
|
-
* `__cdc_log`'s presence or the `__cdc_meta` row behind this instance's back.
|
|
7029
|
-
*/
|
|
7030
|
-
private invalidateCdcMetaCache;
|
|
7031
6671
|
/**
|
|
7032
6672
|
* A route upgrade refused before anything it would run is registered. A route that requires a verified session
|
|
7033
6673
|
* refuses an anonymous caller with a plain 401 (the default route allows anonymous sockets, like every other
|
|
@@ -7409,9 +7049,15 @@ declare abstract class ShardDO {
|
|
|
7409
7049
|
private readAttachmentCopy;
|
|
7410
7050
|
/**
|
|
7411
7051
|
* Persist `value` as the socket's attachment and cache it; `undefined` clears
|
|
7412
|
-
* both. The caller must not mutate `value` afterwards.
|
|
7413
|
-
*
|
|
7414
|
-
*
|
|
7052
|
+
* both. The caller must not mutate `value` afterwards.
|
|
7053
|
+
*
|
|
7054
|
+
* The table sets in `subTables` are optional and share the size limit with
|
|
7055
|
+
* everything a socket must hold, so a write the runtime refuses is retried
|
|
7056
|
+
* once as a copy without them: a registration never fails for
|
|
7057
|
+
* their sake, and their subscriptions re-run after a wake until a run records
|
|
7058
|
+
* them again. `shedTableSets: false` refuses that retry, for the write that
|
|
7059
|
+
* only widens one set. A write that still fails drops the cache entry and
|
|
7060
|
+
* rethrows, so the next read decodes what storage actually holds.
|
|
7415
7061
|
*/
|
|
7416
7062
|
private writeAttachment;
|
|
7417
7063
|
}
|