@substrat-run/adapter-cloudflare 0.218.0 → 0.220.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/dist/control-plane-do.d.ts +69 -5
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +126 -9
- package/dist/control-plane-do.js.map +1 -1
- package/dist/directory-mirror-backfill.d.ts +143 -0
- package/dist/directory-mirror-backfill.d.ts.map +1 -0
- package/dist/directory-mirror-backfill.js +467 -0
- package/dist/directory-mirror-backfill.js.map +1 -0
- package/dist/directory-mirror-verify.d.ts +166 -0
- package/dist/directory-mirror-verify.d.ts.map +1 -0
- package/dist/directory-mirror-verify.js +478 -0
- package/dist/directory-mirror-verify.js.map +1 -0
- package/dist/directory-mirror.d.ts +101 -3
- package/dist/directory-mirror.d.ts.map +1 -1
- package/dist/directory-mirror.js +143 -37
- package/dist/directory-mirror.js.map +1 -1
- package/dist/directory-objects.d.ts +14 -0
- package/dist/directory-objects.d.ts.map +1 -1
- package/dist/directory-objects.js +34 -0
- package/dist/directory-objects.js.map +1 -1
- package/dist/directory-placement.d.ts.map +1 -1
- package/dist/directory-placement.js +7 -1
- package/dist/directory-placement.js.map +1 -1
- package/dist/directory-split-inventory.d.ts +2 -1
- package/dist/directory-split-inventory.d.ts.map +1 -1
- package/dist/directory-split-inventory.js +3 -1
- package/dist/directory-split-inventory.js.map +1 -1
- package/dist/host.d.ts +39 -6
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +136 -15
- package/dist/host.js.map +1 -1
- package/dist/peer-call-target.d.ts.map +1 -1
- package/dist/peer-call-target.js +3 -2
- package/dist/peer-call-target.js.map +1 -1
- package/dist/route-read-model-publisher.d.ts +37 -1
- package/dist/route-read-model-publisher.d.ts.map +1 -1
- package/dist/route-read-model-publisher.js +127 -44
- package/dist/route-read-model-publisher.js.map +1 -1
- package/dist/route-read-model.d.ts +15 -0
- package/dist/route-read-model.d.ts.map +1 -1
- package/dist/route-read-model.js +21 -9
- package/dist/route-read-model.js.map +1 -1
- package/dist/scope-do.d.ts +31 -1
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +235 -24
- package/dist/scope-do.js.map +1 -1
- package/dist/scope-sweeper-do.d.ts +18 -0
- package/dist/scope-sweeper-do.d.ts.map +1 -1
- package/dist/scope-sweeper-do.js +72 -1
- package/dist/scope-sweeper-do.js.map +1 -1
- package/dist/scope-work.d.ts +2 -2
- package/dist/scope-work.js +2 -2
- package/dist/scope-work.js.map +1 -1
- package/package.json +18 -13
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { type DirectoryMirror, type MirrorBackfillPass, type MirrorBackfillRunner, type MirrorChange, type MirrorSender } from './directory-mirror.js';
|
|
2
|
+
export declare const BACKFILL_DDL: string[];
|
|
3
|
+
/** The budget of one page and one pass, and the pacing between them. */
|
|
4
|
+
export interface BackfillLimits {
|
|
5
|
+
pageRows: number;
|
|
6
|
+
pageBytes: number;
|
|
7
|
+
pagesPerPass: number;
|
|
8
|
+
pauseMs: number;
|
|
9
|
+
retryMs: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const BACKFILL_LIMITS: BackfillLimits;
|
|
12
|
+
/**
|
|
13
|
+
* The switch as the control plane's environment spells it, read like `DIRECTORY_MIRROR`: unset, empty
|
|
14
|
+
* or `off` fills nothing; `all` every mirrored table; otherwise a comma list of `MIRRORED_TABLES`. A
|
|
15
|
+
* name it does not know is refused rather than ignored, so a typo cannot read as "on".
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseDirectoryBackfill(value: unknown): string[];
|
|
18
|
+
export type BackfillPhase = 'walk' | 'retry' | 'done';
|
|
19
|
+
export interface BackfillOwner {
|
|
20
|
+
owner: string;
|
|
21
|
+
run: number;
|
|
22
|
+
/** The table being filled (null once filled), and the last key sent in it. */
|
|
23
|
+
table: string | null;
|
|
24
|
+
after: string | null;
|
|
25
|
+
rows: number;
|
|
26
|
+
pages: number;
|
|
27
|
+
/** Changes the object parked (for want of a parent, mostly): 3d lists them, they are not lost. */
|
|
28
|
+
parked: number;
|
|
29
|
+
failures: number;
|
|
30
|
+
error: string | null;
|
|
31
|
+
retryAt: string | null;
|
|
32
|
+
startedAt: string;
|
|
33
|
+
filledAt: string | null;
|
|
34
|
+
}
|
|
35
|
+
export interface BackfillStatus {
|
|
36
|
+
enabled: true;
|
|
37
|
+
/** The tables this run fills, in the order it fills them. */
|
|
38
|
+
tables: string[];
|
|
39
|
+
run: number | null;
|
|
40
|
+
phase: BackfillPhase | null;
|
|
41
|
+
/** The owner a page is being read for, and the last tenant the walk reached. */
|
|
42
|
+
current: string | null;
|
|
43
|
+
afterTenant: string | null;
|
|
44
|
+
startedAt: string | null;
|
|
45
|
+
finishedAt: string | null;
|
|
46
|
+
/** Tenants in the directory, and this run's owners by where they stand (the registry included). */
|
|
47
|
+
tenants: number;
|
|
48
|
+
registryFilled: boolean;
|
|
49
|
+
filled: number;
|
|
50
|
+
filling: number;
|
|
51
|
+
failing: number;
|
|
52
|
+
rows: number;
|
|
53
|
+
/** The owners whose last page an object refused, oldest retry first. */
|
|
54
|
+
failingSample: BackfillOwner[];
|
|
55
|
+
}
|
|
56
|
+
export interface DirectoryBackfillOptions {
|
|
57
|
+
sql: SqlStorage;
|
|
58
|
+
transaction: <T>(fn: () => T) => T;
|
|
59
|
+
sender: MirrorSender;
|
|
60
|
+
/** No directory method is running, so a read sees only committed writes. */
|
|
61
|
+
quiet: () => boolean;
|
|
62
|
+
/** The tables `DIRECTORY_BACKFILL` names; filled where the mirror copies them too. */
|
|
63
|
+
tables: readonly string[];
|
|
64
|
+
limits?: Partial<BackfillLimits>;
|
|
65
|
+
now?: () => number;
|
|
66
|
+
}
|
|
67
|
+
/** One owner's rows, read from a cursor: what the backfill sends and what 3d's comparison digests. */
|
|
68
|
+
export interface OwnerRowsPage {
|
|
69
|
+
changes: MirrorChange[];
|
|
70
|
+
/** Where the cursor stands after these rows: the table (by index into `tables`) and its last key. */
|
|
71
|
+
ord: number;
|
|
72
|
+
after: string | null;
|
|
73
|
+
/** The cursor is past the last of `tables`. */
|
|
74
|
+
done: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* An owner's rows of `tables`, in key order from `from`: at most `rows` of them and about `bytes`,
|
|
78
|
+
* across as many tables as fit (`spanTables`) or within the cursor's one table. A row is the owner's
|
|
79
|
+
* when `? IN (<the table's targets>)` (the placement the triggers and the flush use), with the indexed
|
|
80
|
+
* filter (`mirrorOwnerRowsSql`) in front so a read is an index range. Each row is the capture's own
|
|
81
|
+
* `SELECT t.*`, decoded by `decodeMirrorRow`, keyed as the triggers key it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readOwnerRows(sql: SqlStorage, keysOf: (table: string) => string[], tables: readonly string[], owner: string, from: {
|
|
84
|
+
ord: number;
|
|
85
|
+
after: string | null;
|
|
86
|
+
}, limits: {
|
|
87
|
+
rows: number;
|
|
88
|
+
bytes: number;
|
|
89
|
+
spanTables: boolean;
|
|
90
|
+
}): OwnerRowsPage;
|
|
91
|
+
/** The directory's half of 3c, one per `ControlPlaneDO` instance while both switches are on. */
|
|
92
|
+
export declare class DirectoryBackfill implements MirrorBackfillRunner {
|
|
93
|
+
private readonly options;
|
|
94
|
+
private readonly sql;
|
|
95
|
+
private readonly limits;
|
|
96
|
+
private readonly keys;
|
|
97
|
+
constructor(options: DirectoryBackfillOptions);
|
|
98
|
+
private now;
|
|
99
|
+
private iso;
|
|
100
|
+
/** The tables, in the run's order: backfilled AND mirrored now, as `directory_mirror_tables` says. */
|
|
101
|
+
private target;
|
|
102
|
+
private runRow;
|
|
103
|
+
/** The run in effect, a new one when the signature moved. Inside the caller's transaction. */
|
|
104
|
+
private ensureRun;
|
|
105
|
+
/** A pass is wanted: the switch names a mirrored table, and the run is not done (or has moved). */
|
|
106
|
+
wanted(): boolean;
|
|
107
|
+
/** The tables of the run an owner of `kind` takes, in the run's order. */
|
|
108
|
+
private tablesOf;
|
|
109
|
+
private keyColumns;
|
|
110
|
+
private fillRow;
|
|
111
|
+
/**
|
|
112
|
+
* The owner the next page is for, inside the caller's transaction: the one in progress; else the
|
|
113
|
+
* registry, then the next tenant in id order; then the unfilled ones whose retry is due. Null with
|
|
114
|
+
* `waitUntil` when only owners waiting out a retry are left, and null alone when the run is done.
|
|
115
|
+
*/
|
|
116
|
+
private nextOwner;
|
|
117
|
+
/**
|
|
118
|
+
* One owner's next page, read in the caller's transaction: rows in key order from its cursor, as
|
|
119
|
+
* many tables on as fit, then the version they are sent with. The version is taken in the same
|
|
120
|
+
* synchronous transaction as the reads, so no directory write falls between them.
|
|
121
|
+
*/
|
|
122
|
+
private readPage;
|
|
123
|
+
/** The owner's page landed: its cursor moves, its claims are due, and it is filled at its end. */
|
|
124
|
+
private acknowledge;
|
|
125
|
+
/** The object refused the page: recorded on the owner, retried later, and the walk moves on. */
|
|
126
|
+
private refuse;
|
|
127
|
+
/** One pass: up to `pagesPerPass` pages, each its own read, send and acknowledgement. */
|
|
128
|
+
pass(): Promise<MirrorBackfillPass>;
|
|
129
|
+
status(): BackfillStatus;
|
|
130
|
+
/** A page of owners as the run records them, in owner order after `after`: per tenant, filled or not. */
|
|
131
|
+
owners(query?: {
|
|
132
|
+
after?: string;
|
|
133
|
+
limit?: number;
|
|
134
|
+
}): BackfillOwner[];
|
|
135
|
+
private ownerOf;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The directory's backfill as its environment sets it, attached to its mirror: null when
|
|
139
|
+
* `DIRECTORY_BACKFILL` is off or refused, or when there is no mirror (`DIRECTORY_MIRROR` off). Its
|
|
140
|
+
* tables are created only when it is on. Called once, from `ControlPlaneDO`'s constructor.
|
|
141
|
+
*/
|
|
142
|
+
export declare function directoryBackfillFor(env: unknown, mirror: DirectoryMirror | null, limits?: Partial<BackfillLimits>): DirectoryBackfill | null;
|
|
143
|
+
//# sourceMappingURL=directory-mirror-backfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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,CAMtE;IAED,OAAO,CAAC,OAAO;CAQhB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,iBAAiB,GAAG,IAAI,CAoB7I"}
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Step 3c of the directory split (K-68, directory split; rfc/tenant-scale.md §12): BACKFILL. The rows
|
|
3
|
+
* the directory held before its dual-write (step 3b, `directory-mirror.ts`) was switched on reached no
|
|
4
|
+
* object. This copies them, owner by owner (the registry, then each tenant in id order), into the
|
|
5
|
+
* object each row is placed in, and records per owner that it is filled.
|
|
6
|
+
*
|
|
7
|
+
* **Off by default, and only beside the mirror.** `DIRECTORY_BACKFILL` unset (or `off`) attaches
|
|
8
|
+
* nothing. `all` fills every table the mirror copies; a comma list fills those tables only. It does
|
|
9
|
+
* nothing while `DIRECTORY_MIRROR` is off: a row written then would reach no object, so the copy would
|
|
10
|
+
* be stale the moment it landed. Switching it off stops the work after the page in flight. What it
|
|
11
|
+
* leaves is its own bookkeeping, which nothing reads and nothing waits on: a half-filled owner is an
|
|
12
|
+
* owner the next run starts again.
|
|
13
|
+
*
|
|
14
|
+
* **The same apply path as the dual-write.** A page is read like a flush batch: in one synchronous
|
|
15
|
+
* transaction, the rows (the capture's own `SELECT t.*`, decoded by the same `decodeMirrorRow`) and a
|
|
16
|
+
* new mirror version (`takeMirrorVersion`). It is sent through the same `applyMirror`, which applies a
|
|
17
|
+
* key only at a version above the one it holds and keeps a tombstone for a delete. So:
|
|
18
|
+
* - a row written after the page was read is sent by the flush with a larger version, and wins;
|
|
19
|
+
* - a row written before it is in the page already, as it stood;
|
|
20
|
+
* - a key deleted after the page was read left a tombstone with a larger version, so the page cannot
|
|
21
|
+
* bring it back.
|
|
22
|
+
* The backfill and the dual-write therefore need no coordination and share no cursor. A `tenants` or
|
|
23
|
+
* `hostnames` row the object did not hold makes its registry claim in the object, as a mirrored one
|
|
24
|
+
* does (`directory-mirror-claims.ts`); the owner is recorded due in the same transaction as the page's
|
|
25
|
+
* progress, and the flush after the pass drains it. So the registry's claims are backfilled too.
|
|
26
|
+
*
|
|
27
|
+
* **Which rows are an owner's.** `? IN (<the table's targets>)`, the same SQL the triggers and the flush
|
|
28
|
+
* place a row with (`mirrorTargetsSql`), so the backfill cannot disagree with them about placement. An
|
|
29
|
+
* indexed filter (`mirrorOwnerRowsSql`: `tenant_id = ?`, or the scope or connection the row hangs off)
|
|
30
|
+
* is ANDed in front of it so a page is an index range, not a scan of the whole table. Rows no object
|
|
31
|
+
* takes (a tenant-placed row with no tenant) are read by no owner, as the flush counts them `unplaced`.
|
|
32
|
+
*
|
|
33
|
+
* **A page at a time, resumable, inside a pass's budget.** A page holds one owner's rows, at most
|
|
34
|
+
* `pageRows` of them and about `pageBytes` (a `vertical_versions` manifest is large), in key order
|
|
35
|
+
* from the owner's cursor, across as many of its tables as fit. Its progress commits after the object
|
|
36
|
+
* acknowledged it, so a page that fails, or a pass the isolate dropped, is read again. A pass is at most
|
|
37
|
+
* `pagesPerPass` pages; the next is armed on the directory's alarm `pauseMs` later. The walk is the
|
|
38
|
+
* directory's own alarm, never a phase of the scheduled pass (K-69: no new phase in the pass that walks
|
|
39
|
+
* every scope).
|
|
40
|
+
*
|
|
41
|
+
* **One owner never holds back the rest.** A page an object refuses is recorded on the owner (its
|
|
42
|
+
* error, its failures, when it is tried again) and the walk moves on. Once every owner has been
|
|
43
|
+
* reached, the ones still unfilled are retried, `retryMs` apart, until each is filled.
|
|
44
|
+
*
|
|
45
|
+
* **A run is the tables it fills.** A run's signature is the tables it fills, the time each was
|
|
46
|
+
* switched on in the mirror (`directory_mirror_tables.since`), and the directory's last restore. When
|
|
47
|
+
* any of them changes (a table added to either switch, the mirror switched off and on, a restore), the
|
|
48
|
+
* next pass starts a new run and every owner is filled again: rows written while a table was not
|
|
49
|
+
* mirrored reached no object.
|
|
50
|
+
*/
|
|
51
|
+
import { REGISTRY_OWNER, tenantOwnerOf } from '@substrat-run/kernel';
|
|
52
|
+
import { decodeMirrorRow, MIRROR_CLAIMS_DUE_TABLE, MIRRORED_TABLES, mirrorKeyColumns, mirrorKeySql, mirrorOwnerRowsSql, mirrorTargetsSql, objectKindOfOwner, quoteIdent, takeMirrorVersion, } from './directory-mirror.js';
|
|
53
|
+
const RUN = 'directory_mirror_fill_run';
|
|
54
|
+
const FILL = 'directory_mirror_fill';
|
|
55
|
+
export const BACKFILL_DDL = [
|
|
56
|
+
// One row: the run in progress. `run` only grows; an owner row of an older run is not filled.
|
|
57
|
+
`CREATE TABLE IF NOT EXISTS ${RUN} (
|
|
58
|
+
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
59
|
+
run INTEGER NOT NULL,
|
|
60
|
+
signature TEXT NOT NULL,
|
|
61
|
+
tables TEXT NOT NULL,
|
|
62
|
+
phase TEXT NOT NULL,
|
|
63
|
+
current TEXT,
|
|
64
|
+
after_tenant TEXT,
|
|
65
|
+
started_at TEXT NOT NULL,
|
|
66
|
+
finished_at TEXT
|
|
67
|
+
)`,
|
|
68
|
+
// One row per owner the run reached: where its fill stands. Grows with tenants, never with time.
|
|
69
|
+
`CREATE TABLE IF NOT EXISTS ${FILL} (
|
|
70
|
+
owner TEXT PRIMARY KEY,
|
|
71
|
+
run INTEGER NOT NULL,
|
|
72
|
+
ord INTEGER NOT NULL,
|
|
73
|
+
after TEXT,
|
|
74
|
+
rows INTEGER NOT NULL,
|
|
75
|
+
pages INTEGER NOT NULL,
|
|
76
|
+
parked INTEGER NOT NULL,
|
|
77
|
+
failures INTEGER NOT NULL,
|
|
78
|
+
error TEXT,
|
|
79
|
+
retry_at TEXT,
|
|
80
|
+
started_at TEXT NOT NULL,
|
|
81
|
+
filled_at TEXT
|
|
82
|
+
)`,
|
|
83
|
+
];
|
|
84
|
+
export const BACKFILL_LIMITS = {
|
|
85
|
+
pageRows: 100,
|
|
86
|
+
// Under DO RPC's 32 MiB message, with room for the batch's own envelope.
|
|
87
|
+
pageBytes: 4 * 1024 * 1024,
|
|
88
|
+
pagesPerPass: 20,
|
|
89
|
+
pauseMs: 1_000,
|
|
90
|
+
retryMs: 60_000,
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The switch as the control plane's environment spells it, read like `DIRECTORY_MIRROR`: unset, empty
|
|
94
|
+
* or `off` fills nothing; `all` every mirrored table; otherwise a comma list of `MIRRORED_TABLES`. A
|
|
95
|
+
* name it does not know is refused rather than ignored, so a typo cannot read as "on".
|
|
96
|
+
*/
|
|
97
|
+
export function parseDirectoryBackfill(value) {
|
|
98
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
99
|
+
if (text === '' || text === 'off')
|
|
100
|
+
return [];
|
|
101
|
+
if (text === 'all')
|
|
102
|
+
return [...MIRRORED_TABLES];
|
|
103
|
+
const names = [...new Set(text.split(',').map((s) => s.trim()).filter((s) => s !== ''))];
|
|
104
|
+
const unknown = names.filter((n) => !MIRRORED_TABLES.includes(n));
|
|
105
|
+
if (unknown.length > 0)
|
|
106
|
+
throw new Error(`directory backfill: unknown or unmirrored table ${unknown.join(', ')} (or all, or off)`);
|
|
107
|
+
return names;
|
|
108
|
+
}
|
|
109
|
+
const tenantPrefix = tenantOwnerOf('');
|
|
110
|
+
/**
|
|
111
|
+
* An owner's rows of `tables`, in key order from `from`: at most `rows` of them and about `bytes`,
|
|
112
|
+
* across as many tables as fit (`spanTables`) or within the cursor's one table. A row is the owner's
|
|
113
|
+
* when `? IN (<the table's targets>)` (the placement the triggers and the flush use), with the indexed
|
|
114
|
+
* filter (`mirrorOwnerRowsSql`) in front so a read is an index range. Each row is the capture's own
|
|
115
|
+
* `SELECT t.*`, decoded by `decodeMirrorRow`, keyed as the triggers key it.
|
|
116
|
+
*/
|
|
117
|
+
export function readOwnerRows(sql, keysOf, tables, owner, from, limits) {
|
|
118
|
+
const kind = objectKindOfOwner(owner);
|
|
119
|
+
const tenantId = kind === 'tenant' ? owner.slice(tenantPrefix.length) : null;
|
|
120
|
+
const changes = [];
|
|
121
|
+
let bytes = 0;
|
|
122
|
+
let ord = from.ord;
|
|
123
|
+
let after = from.after;
|
|
124
|
+
while (ord < tables.length && changes.length < limits.rows && bytes < limits.bytes) {
|
|
125
|
+
const table = tables[ord];
|
|
126
|
+
const keys = keysOf(table);
|
|
127
|
+
const filter = mirrorOwnerRowsSql(table, 't', kind);
|
|
128
|
+
if (!filter)
|
|
129
|
+
throw new Error(`directory backfill: ${table} holds no row of a ${kind} object`);
|
|
130
|
+
const targets = mirrorTargetsSql(table, 't');
|
|
131
|
+
const keyExprs = keys.map((k) => (k === 'rowid' ? 't.rowid' : `t.${quoteIdent(k)}`));
|
|
132
|
+
const cursor = after === null ? null : JSON.parse(after);
|
|
133
|
+
if (cursor && cursor.some((v) => v === null))
|
|
134
|
+
throw new Error(`directory backfill: ${table} has a key holding NULL (${after}), which no cursor can resume after`);
|
|
135
|
+
const rowid = keys[0] === 'rowid' ? ', t.rowid AS "__mirror_rowid"' : '';
|
|
136
|
+
const limit = limits.rows - changes.length;
|
|
137
|
+
const statement = `SELECT t.*${rowid}, ${mirrorKeySql(keys, 't')} AS "__mirror_key" FROM ${quoteIdent(table)} t` +
|
|
138
|
+
` WHERE (${filter.sql}) AND ? IN (${targets.join(', ')})` +
|
|
139
|
+
(cursor ? ` AND (${keyExprs.join(', ')}) > (${keyExprs.map(() => '?').join(', ')})` : '') +
|
|
140
|
+
` ORDER BY ${keyExprs.join(', ')} LIMIT ?`;
|
|
141
|
+
const params = [...Array.from({ length: filter.binds }, () => tenantId), owner, ...(cursor ?? []), limit];
|
|
142
|
+
let read = 0;
|
|
143
|
+
let full = false;
|
|
144
|
+
for (const found of sql.exec(statement, ...params)) {
|
|
145
|
+
read += 1;
|
|
146
|
+
const { row } = decodeMirrorRow(table, found);
|
|
147
|
+
const key = String(found['__mirror_key']);
|
|
148
|
+
changes.push({ table, key, row });
|
|
149
|
+
after = key;
|
|
150
|
+
for (const v of Object.values(row))
|
|
151
|
+
bytes += typeof v === 'string' ? v.length : 8;
|
|
152
|
+
if (bytes >= limits.bytes) {
|
|
153
|
+
full = true;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (full || read === limit)
|
|
158
|
+
break;
|
|
159
|
+
ord += 1;
|
|
160
|
+
after = null;
|
|
161
|
+
if (!limits.spanTables)
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
return { changes, ord, after, done: ord >= tables.length };
|
|
165
|
+
}
|
|
166
|
+
/** The directory's half of 3c, one per `ControlPlaneDO` instance while both switches are on. */
|
|
167
|
+
export class DirectoryBackfill {
|
|
168
|
+
options;
|
|
169
|
+
sql;
|
|
170
|
+
limits;
|
|
171
|
+
keys = new Map();
|
|
172
|
+
constructor(options) {
|
|
173
|
+
this.options = options;
|
|
174
|
+
this.sql = options.sql;
|
|
175
|
+
this.limits = { ...BACKFILL_LIMITS, ...options.limits };
|
|
176
|
+
}
|
|
177
|
+
now() {
|
|
178
|
+
return (this.options.now ?? Date.now)();
|
|
179
|
+
}
|
|
180
|
+
iso(ms = this.now()) {
|
|
181
|
+
return new Date(ms).toISOString();
|
|
182
|
+
}
|
|
183
|
+
/** The tables, in the run's order: backfilled AND mirrored now, as `directory_mirror_tables` says. */
|
|
184
|
+
target() {
|
|
185
|
+
const since = new Map(this.sql.exec(`SELECT tbl, since FROM directory_mirror_tables`).toArray().map((r) => [r.tbl, r.since]));
|
|
186
|
+
const wanted = new Set(this.options.tables);
|
|
187
|
+
const tables = MIRRORED_TABLES.filter((t) => wanted.has(t) && since.has(t));
|
|
188
|
+
const restored = this.sql.exec(`SELECT restored_at FROM directory_mirror_state WHERE id = 1`).toArray()[0]?.restored_at ?? null;
|
|
189
|
+
return { tables, signature: JSON.stringify({ tables: tables.map((t) => [t, since.get(t)]), restored }) };
|
|
190
|
+
}
|
|
191
|
+
runRow() {
|
|
192
|
+
return this.sql.exec(`SELECT run, signature, tables, phase, current, after_tenant, started_at, finished_at FROM ${RUN} WHERE id = 1`).toArray()[0] ?? null;
|
|
193
|
+
}
|
|
194
|
+
/** The run in effect, a new one when the signature moved. Inside the caller's transaction. */
|
|
195
|
+
ensureRun() {
|
|
196
|
+
const { tables, signature } = this.target();
|
|
197
|
+
if (tables.length === 0)
|
|
198
|
+
return null;
|
|
199
|
+
const held = this.runRow();
|
|
200
|
+
if (held && held.signature === signature)
|
|
201
|
+
return held;
|
|
202
|
+
const run = (held?.run ?? 0) + 1;
|
|
203
|
+
this.sql.exec(`INSERT INTO ${RUN} (id, run, signature, tables, phase, current, after_tenant, started_at, finished_at) VALUES (1, ?, ?, ?, 'walk', NULL, NULL, ?, NULL)
|
|
204
|
+
ON CONFLICT (id) DO UPDATE SET run = excluded.run, signature = excluded.signature, tables = excluded.tables, phase = 'walk',
|
|
205
|
+
current = NULL, after_tenant = NULL, started_at = excluded.started_at, finished_at = NULL`, run, signature, JSON.stringify(tables), this.iso());
|
|
206
|
+
return this.runRow();
|
|
207
|
+
}
|
|
208
|
+
/** A pass is wanted: the switch names a mirrored table, and the run is not done (or has moved). */
|
|
209
|
+
wanted() {
|
|
210
|
+
const { tables, signature } = this.target();
|
|
211
|
+
if (tables.length === 0)
|
|
212
|
+
return false;
|
|
213
|
+
const held = this.runRow();
|
|
214
|
+
return !held || held.signature !== signature || held.phase !== 'done';
|
|
215
|
+
}
|
|
216
|
+
/** The tables of the run an owner of `kind` takes, in the run's order. */
|
|
217
|
+
tablesOf(run, kind) {
|
|
218
|
+
return JSON.parse(run.tables).filter((t) => mirrorOwnerRowsSql(t, 't', kind) !== null);
|
|
219
|
+
}
|
|
220
|
+
keyColumns(table) {
|
|
221
|
+
let keys = this.keys.get(table);
|
|
222
|
+
if (!keys)
|
|
223
|
+
this.keys.set(table, (keys = mirrorKeyColumns(this.sql, table)));
|
|
224
|
+
return keys;
|
|
225
|
+
}
|
|
226
|
+
fillRow(owner) {
|
|
227
|
+
return this.sql.exec(`SELECT * FROM ${FILL} WHERE owner = ?`, owner).toArray()[0] ?? null;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* The owner the next page is for, inside the caller's transaction: the one in progress; else the
|
|
231
|
+
* registry, then the next tenant in id order; then the unfilled ones whose retry is due. Null with
|
|
232
|
+
* `waitUntil` when only owners waiting out a retry are left, and null alone when the run is done.
|
|
233
|
+
*/
|
|
234
|
+
nextOwner(run) {
|
|
235
|
+
if (run.current)
|
|
236
|
+
return { owner: run.current, waitUntil: null };
|
|
237
|
+
let owner = null;
|
|
238
|
+
if (run.phase === 'walk') {
|
|
239
|
+
const registry = this.fillRow(REGISTRY_OWNER);
|
|
240
|
+
if (!registry || registry.run !== run.run) {
|
|
241
|
+
owner = REGISTRY_OWNER;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
const next = this.sql.exec(`SELECT tenant_id FROM tenants WHERE tenant_id > ? ORDER BY tenant_id LIMIT 1`, run.after_tenant ?? '').toArray()[0];
|
|
245
|
+
if (next) {
|
|
246
|
+
owner = tenantOwnerOf(next.tenant_id);
|
|
247
|
+
this.sql.exec(`UPDATE ${RUN} SET after_tenant = ? WHERE id = 1`, next.tenant_id);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.sql.exec(`UPDATE ${RUN} SET phase = 'retry' WHERE id = 1`);
|
|
251
|
+
run.phase = 'retry';
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (!owner && run.phase === 'retry') {
|
|
256
|
+
const due = this.sql.exec(`SELECT owner FROM ${FILL} WHERE run = ? AND filled_at IS NULL AND (retry_at IS NULL OR retry_at <= ?) ORDER BY retry_at, owner LIMIT 1`, run.run, this.iso()).toArray()[0];
|
|
257
|
+
if (due) {
|
|
258
|
+
owner = due.owner;
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
const wait = this.sql.exec(`SELECT MIN(retry_at) AS at FROM ${FILL} WHERE run = ? AND filled_at IS NULL`, run.run).one();
|
|
262
|
+
if (wait.at !== null)
|
|
263
|
+
return { owner: null, waitUntil: Date.parse(wait.at) };
|
|
264
|
+
this.sql.exec(`UPDATE ${RUN} SET phase = 'done', finished_at = ? WHERE id = 1`, this.iso());
|
|
265
|
+
run.phase = 'done';
|
|
266
|
+
return { owner: null, waitUntil: null };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (owner) {
|
|
270
|
+
this.sql.exec(`UPDATE ${RUN} SET current = ? WHERE id = 1`, owner);
|
|
271
|
+
const held = this.fillRow(owner);
|
|
272
|
+
if (!held || held.run !== run.run) {
|
|
273
|
+
this.sql.exec(`INSERT INTO ${FILL} (owner, run, ord, after, rows, pages, parked, failures, error, retry_at, started_at, filled_at)
|
|
274
|
+
VALUES (?, ?, 0, NULL, 0, 0, 0, 0, NULL, NULL, ?, NULL)
|
|
275
|
+
ON CONFLICT (owner) DO UPDATE SET run = excluded.run, ord = 0, after = NULL, rows = 0, pages = 0, parked = 0, failures = 0,
|
|
276
|
+
error = NULL, retry_at = NULL, started_at = excluded.started_at, filled_at = NULL`, owner, run.run, this.iso());
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return { owner, waitUntil: null };
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* One owner's next page, read in the caller's transaction: rows in key order from its cursor, as
|
|
283
|
+
* many tables on as fit, then the version they are sent with. The version is taken in the same
|
|
284
|
+
* synchronous transaction as the reads, so no directory write falls between them.
|
|
285
|
+
*/
|
|
286
|
+
readPage(run, owner, fill) {
|
|
287
|
+
const tables = this.tablesOf(run, objectKindOfOwner(owner));
|
|
288
|
+
const page = readOwnerRows(this.sql, (t) => this.keyColumns(t), tables, owner, { ord: fill.ord, after: fill.after }, {
|
|
289
|
+
rows: this.limits.pageRows, bytes: this.limits.pageBytes, spanTables: true,
|
|
290
|
+
});
|
|
291
|
+
const version = page.changes.length > 0 ? takeMirrorVersion(this.sql) : 0;
|
|
292
|
+
return { version, ...page };
|
|
293
|
+
}
|
|
294
|
+
/** The owner's page landed: its cursor moves, its claims are due, and it is filled at its end. */
|
|
295
|
+
acknowledge(run, owner, page, parked, claims) {
|
|
296
|
+
let rows = 0;
|
|
297
|
+
const at = this.iso();
|
|
298
|
+
rows += this.sql.exec(`UPDATE ${FILL} SET ord = ?, after = ?, rows = rows + ?, pages = pages + ?, parked = parked + ?, failures = 0, error = NULL, retry_at = NULL,
|
|
299
|
+
filled_at = ? WHERE owner = ?`, page.ord, page.after, page.changes.length, page.changes.length > 0 ? 1 : 0, parked, page.done ? at : null, owner).rowsWritten;
|
|
300
|
+
if (claims)
|
|
301
|
+
rows += this.sql.exec(`INSERT OR IGNORE INTO ${MIRROR_CLAIMS_DUE_TABLE} (owner, since) VALUES (?, ?)`, owner, at).rowsWritten;
|
|
302
|
+
if (page.done)
|
|
303
|
+
rows += this.sql.exec(`UPDATE ${RUN} SET current = NULL WHERE id = 1 AND run = ?`, run.run).rowsWritten;
|
|
304
|
+
return { rows, filled: page.done };
|
|
305
|
+
}
|
|
306
|
+
/** The object refused the page: recorded on the owner, retried later, and the walk moves on. */
|
|
307
|
+
refuse(run, owner, err) {
|
|
308
|
+
const error = String(err?.message ?? err).slice(0, 500);
|
|
309
|
+
return (this.sql.exec(`UPDATE ${FILL} SET failures = failures + 1, error = ?, retry_at = ? WHERE owner = ?`, error, this.iso(this.now() + this.limits.retryMs), owner).rowsWritten + this.sql.exec(`UPDATE ${RUN} SET current = NULL WHERE id = 1 AND run = ?`, run.run).rowsWritten);
|
|
310
|
+
}
|
|
311
|
+
/** One pass: up to `pagesPerPass` pages, each its own read, send and acknowledgement. */
|
|
312
|
+
async pass() {
|
|
313
|
+
const out = {
|
|
314
|
+
pages: 0, rows: 0, filled: 0, failed: 0, claims: false, more: false, nextAt: null, deferred: false, rowsWrittenDirectory: 0, rowsWrittenObjects: 0,
|
|
315
|
+
};
|
|
316
|
+
const { transaction, sender } = this.options;
|
|
317
|
+
for (let i = 0; i < this.limits.pagesPerPass; i++) {
|
|
318
|
+
if (!this.options.quiet()) {
|
|
319
|
+
out.deferred = true;
|
|
320
|
+
out.more = true;
|
|
321
|
+
return out;
|
|
322
|
+
}
|
|
323
|
+
// Read in one transaction: which owner, its page, and the version the page goes with.
|
|
324
|
+
const read = transaction(() => {
|
|
325
|
+
const run = this.ensureRun();
|
|
326
|
+
if (!run || run.phase === 'done')
|
|
327
|
+
return { run, owner: null, waitUntil: null, page: null, error: null };
|
|
328
|
+
const { owner, waitUntil } = this.nextOwner(run);
|
|
329
|
+
if (!owner)
|
|
330
|
+
return { run, owner, waitUntil, page: null, error: null };
|
|
331
|
+
try {
|
|
332
|
+
return { run, owner, waitUntil, page: this.readPage(run, owner, this.fillRow(owner)), error: null };
|
|
333
|
+
}
|
|
334
|
+
catch (err) {
|
|
335
|
+
return { run, owner, waitUntil, page: null, error: err };
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
if (!read.run || !read.owner) {
|
|
339
|
+
out.more = read.waitUntil !== null;
|
|
340
|
+
out.nextAt = read.waitUntil;
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
const { run, owner } = read;
|
|
344
|
+
if (read.error !== null || !read.page) {
|
|
345
|
+
out.rowsWrittenDirectory += transaction(() => this.refuse(run, owner, read.error));
|
|
346
|
+
out.failed += 1;
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
const page = read.page;
|
|
350
|
+
out.rowsWrittenDirectory += page.changes.length > 0 ? 1 : 0; // the version
|
|
351
|
+
let parked = 0;
|
|
352
|
+
let claims = false;
|
|
353
|
+
if (page.changes.length > 0) {
|
|
354
|
+
try {
|
|
355
|
+
const applied = await sender.send(owner, { version: page.version, changes: page.changes });
|
|
356
|
+
parked = applied.parked;
|
|
357
|
+
claims = !!applied.claims && (applied.claims.crossings.length > 0 || applied.claims.releases.length > 0);
|
|
358
|
+
out.rowsWrittenObjects += applied.rowsWritten;
|
|
359
|
+
}
|
|
360
|
+
catch (err) {
|
|
361
|
+
console.error(`directory backfill: ${owner} refused a page; retried after ${this.limits.retryMs} ms`, err);
|
|
362
|
+
out.rowsWrittenDirectory += transaction(() => this.refuse(run, owner, err));
|
|
363
|
+
out.failed += 1;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// The run may have moved while the page was out (a restore, a switch): acknowledge only the run it was read for.
|
|
368
|
+
const done = transaction(() => {
|
|
369
|
+
const held = this.runRow();
|
|
370
|
+
const fill = this.fillRow(owner);
|
|
371
|
+
if (!held || held.run !== run.run || !fill || fill.run !== run.run)
|
|
372
|
+
return null;
|
|
373
|
+
return this.acknowledge(run, owner, page, parked, claims);
|
|
374
|
+
});
|
|
375
|
+
if (!done)
|
|
376
|
+
break;
|
|
377
|
+
out.rowsWrittenDirectory += done.rows;
|
|
378
|
+
out.pages += page.changes.length > 0 ? 1 : 0;
|
|
379
|
+
out.rows += page.changes.length;
|
|
380
|
+
out.claims ||= claims;
|
|
381
|
+
if (done.filled)
|
|
382
|
+
out.filled += 1;
|
|
383
|
+
}
|
|
384
|
+
out.more = this.wanted();
|
|
385
|
+
if (out.more)
|
|
386
|
+
out.nextAt = this.now() + this.limits.pauseMs;
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
status() {
|
|
390
|
+
const run = this.runRow();
|
|
391
|
+
const tables = run ? JSON.parse(run.tables) : this.target().tables;
|
|
392
|
+
const tenants = Number(this.sql.exec(`SELECT COUNT(*) AS n FROM tenants`).one().n);
|
|
393
|
+
const counts = run
|
|
394
|
+
? this.sql.exec(`SELECT COUNT(filled_at) AS filled, SUM(CASE WHEN filled_at IS NULL AND failures = 0 THEN 1 ELSE 0 END) AS filling,
|
|
395
|
+
SUM(CASE WHEN filled_at IS NULL AND failures > 0 THEN 1 ELSE 0 END) AS failing, COALESCE(SUM(rows), 0) AS rows
|
|
396
|
+
FROM ${FILL} WHERE run = ?`, run.run).one()
|
|
397
|
+
: { filled: 0, filling: 0, failing: 0, rows: 0 };
|
|
398
|
+
const registry = this.fillRow(REGISTRY_OWNER);
|
|
399
|
+
const failing = run
|
|
400
|
+
? this.sql.exec(`SELECT * FROM ${FILL} WHERE run = ? AND filled_at IS NULL AND failures > 0 ORDER BY retry_at, owner LIMIT 20`, run.run).toArray()
|
|
401
|
+
: [];
|
|
402
|
+
return {
|
|
403
|
+
enabled: true,
|
|
404
|
+
tables,
|
|
405
|
+
run: run?.run ?? null,
|
|
406
|
+
phase: run?.phase ?? null,
|
|
407
|
+
current: run?.current ?? null,
|
|
408
|
+
afterTenant: run?.after_tenant ?? null,
|
|
409
|
+
startedAt: run?.started_at ?? null,
|
|
410
|
+
finishedAt: run?.finished_at ?? null,
|
|
411
|
+
tenants,
|
|
412
|
+
registryFilled: !!run && !!registry && registry.run === run.run && registry.filled_at !== null,
|
|
413
|
+
filled: Number(counts.filled),
|
|
414
|
+
filling: Number(counts.filling ?? 0),
|
|
415
|
+
failing: Number(counts.failing ?? 0),
|
|
416
|
+
rows: Number(counts.rows),
|
|
417
|
+
failingSample: failing.map((r) => this.ownerOf(r, run)),
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
/** A page of owners as the run records them, in owner order after `after`: per tenant, filled or not. */
|
|
421
|
+
owners(query = {}) {
|
|
422
|
+
const run = this.runRow();
|
|
423
|
+
if (!run)
|
|
424
|
+
return [];
|
|
425
|
+
const limit = Math.max(1, Math.min(query.limit ?? 100, 500));
|
|
426
|
+
const rows = this.sql.exec(`SELECT * FROM ${FILL} WHERE run = ? AND owner > ? ORDER BY owner LIMIT ?`, run.run, query.after ?? '', limit).toArray();
|
|
427
|
+
return rows.map((r) => this.ownerOf(r, run));
|
|
428
|
+
}
|
|
429
|
+
ownerOf(r, run) {
|
|
430
|
+
const tables = this.tablesOf(run, objectKindOfOwner(r.owner));
|
|
431
|
+
return {
|
|
432
|
+
owner: r.owner, run: Number(r.run), table: r.filled_at === null ? (tables[Number(r.ord)] ?? null) : null, after: r.after,
|
|
433
|
+
rows: Number(r.rows), pages: Number(r.pages), parked: Number(r.parked), failures: Number(r.failures),
|
|
434
|
+
error: r.error, retryAt: r.retry_at, startedAt: r.started_at, filledAt: r.filled_at,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* The directory's backfill as its environment sets it, attached to its mirror: null when
|
|
440
|
+
* `DIRECTORY_BACKFILL` is off or refused, or when there is no mirror (`DIRECTORY_MIRROR` off). Its
|
|
441
|
+
* tables are created only when it is on. Called once, from `ControlPlaneDO`'s constructor.
|
|
442
|
+
*/
|
|
443
|
+
export function directoryBackfillFor(env, mirror, limits) {
|
|
444
|
+
let tables;
|
|
445
|
+
try {
|
|
446
|
+
tables = parseDirectoryBackfill(Reflect.get(env, 'DIRECTORY_BACKFILL'));
|
|
447
|
+
}
|
|
448
|
+
catch (err) {
|
|
449
|
+
console.error('directory backfill: DIRECTORY_BACKFILL refused, the backfill stays off:', err.message);
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
if (tables.length === 0)
|
|
453
|
+
return null;
|
|
454
|
+
if (!mirror) {
|
|
455
|
+
console.error('directory backfill: DIRECTORY_BACKFILL is on but the mirror is off (DIRECTORY_MIRROR); nothing is filled');
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
const { sql, transaction, sender, quiet, now } = mirror.options;
|
|
459
|
+
const backfill = new DirectoryBackfill({ sql, transaction, sender, quiet, tables, ...(limits ? { limits } : {}), ...(now ? { now } : {}) });
|
|
460
|
+
transaction(() => {
|
|
461
|
+
for (const stmt of BACKFILL_DDL)
|
|
462
|
+
sql.exec(stmt);
|
|
463
|
+
});
|
|
464
|
+
mirror.attachBackfill(backfill);
|
|
465
|
+
return backfill;
|
|
466
|
+
}
|
|
467
|
+
//# sourceMappingURL=directory-mirror-backfill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-mirror-backf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