@substrat-run/adapter-cloudflare 0.214.0 → 0.216.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/connection-sweep-do.d.ts +83 -0
- package/dist/connection-sweep-do.d.ts.map +1 -0
- package/dist/connection-sweep-do.js +89 -0
- package/dist/connection-sweep-do.js.map +1 -0
- package/dist/control-plane-do.d.ts +33 -42
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +104 -81
- package/dist/control-plane-do.js.map +1 -1
- package/dist/directory-mirror-apply.d.ts +59 -0
- package/dist/directory-mirror-apply.d.ts.map +1 -0
- package/dist/directory-mirror-apply.js +158 -0
- package/dist/directory-mirror-apply.js.map +1 -0
- package/dist/directory-mirror-claims.d.ts +77 -0
- package/dist/directory-mirror-claims.d.ts.map +1 -0
- package/dist/directory-mirror-claims.js +129 -0
- package/dist/directory-mirror-claims.js.map +1 -0
- package/dist/directory-mirror.d.ts +201 -0
- package/dist/directory-mirror.d.ts.map +1 -0
- package/dist/directory-mirror.js +557 -0
- package/dist/directory-mirror.js.map +1 -0
- package/dist/directory-objects.d.ts +24 -0
- package/dist/directory-objects.d.ts.map +1 -1
- package/dist/directory-objects.js +125 -1
- package/dist/directory-objects.js.map +1 -1
- package/dist/directory-placement.d.ts +17 -0
- package/dist/directory-placement.d.ts.map +1 -1
- package/dist/directory-placement.js +23 -2
- package/dist/directory-placement.js.map +1 -1
- package/dist/directory-split-inventory.d.ts +4 -1
- package/dist/directory-split-inventory.d.ts.map +1 -1
- package/dist/directory-split-inventory.js +7 -1
- package/dist/directory-split-inventory.js.map +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +43 -0
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/kick-coalescer-do.d.ts +13 -3
- package/dist/kick-coalescer-do.d.ts.map +1 -1
- package/dist/kick-coalescer-do.js +20 -6
- package/dist/kick-coalescer-do.js.map +1 -1
- package/dist/peer-call-target.d.ts +61 -0
- package/dist/peer-call-target.d.ts.map +1 -0
- package/dist/peer-call-target.js +98 -0
- package/dist/peer-call-target.js.map +1 -0
- package/dist/route-read-model-publisher.d.ts +29 -4
- package/dist/route-read-model-publisher.d.ts.map +1 -1
- package/dist/route-read-model-publisher.js +137 -3
- package/dist/route-read-model-publisher.js.map +1 -1
- package/dist/route-read-model.d.ts +75 -1
- package/dist/route-read-model.d.ts.map +1 -1
- package/dist/route-read-model.js +118 -0
- package/dist/route-read-model.js.map +1 -1
- package/dist/route-resolver.d.ts +33 -5
- package/dist/route-resolver.d.ts.map +1 -1
- package/dist/route-resolver.js +130 -70
- package/dist/route-resolver.js.map +1 -1
- package/dist/scope-do.d.ts +8 -0
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +95 -4
- package/dist/scope-do.js.map +1 -1
- package/dist/scope-wake.d.ts +127 -0
- package/dist/scope-wake.d.ts.map +1 -0
- package/dist/scope-wake.js +204 -0
- package/dist/scope-wake.js.map +1 -0
- package/package.json +7 -7
package/dist/control-plane-do.js
CHANGED
|
@@ -10,6 +10,10 @@ import { autoAdmittedProdRefusal, listedPromoteRefusal, opsFailureReferenceWhere
|
|
|
10
10
|
import { canonicalInstant } from '@substrat-run/kernel';
|
|
11
11
|
import { doBuiltColumnsOf, doRedactionSql } from './sql.js';
|
|
12
12
|
import { ROUTE_READ_MODEL_TABLE_GLOB, RouteReadModelPublisher, routeKvWriterOf, uninstallRouteReadModel, } from './route-read-model-publisher.js';
|
|
13
|
+
import { readPeerCallTarget } from './peer-call-target.js';
|
|
14
|
+
// K-68 step 3b: the directory's dual-write to the registry and the tenant objects (off by default).
|
|
15
|
+
import { DIRECTORY_MIRROR_TABLE_GLOB, directoryMirrorFor, isDirectoryMirrorTable } from './directory-mirror.js';
|
|
16
|
+
import { durableMirrorSender } from './directory-objects.js';
|
|
13
17
|
import { assertReplayableDump, AUTO_ADMISSION_NOTE, instant, opsFailureFingerprint, ROUTE_SCOPE_HOSTNAMES_MAX, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_GATE_REASONS, substratError } from '@substrat-run/contracts';
|
|
14
18
|
/**
|
|
15
19
|
* The router's per-request directory read (`readRoute`), lifted out so its plan can be asked for
|
|
@@ -803,7 +807,12 @@ const SCOPE_COLUMNS_ADDED = [
|
|
|
803
807
|
*/
|
|
804
808
|
export function planDirectoryDdl(ddl) {
|
|
805
809
|
const all = executableSqlStatements(ddl);
|
|
806
|
-
|
|
810
|
+
// The sweep-runs dedupe index names `request_id` (#1232) and `kind` (#1572). On a directory whose
|
|
811
|
+
// `_substrat_sweep_runs` predates `request_id`, the loop meets the index before
|
|
812
|
+
// `ensureDirectoryColumns` adds the column: "no such column: request_id", on every construction,
|
|
813
|
+
// so the column is never added and the directory never starts again (the test directory, from
|
|
814
|
+
// 2026-09-07, #3395). Held back to run once the columns exist.
|
|
815
|
+
const afterColumns = [...executableSqlStatements(VERSION_MIGRATIONS_DDL), ...executableSqlStatements(SWEEP_RUNS_INTENT_INDEX)];
|
|
807
816
|
const held = new Set(afterColumns);
|
|
808
817
|
return {
|
|
809
818
|
loop: all.filter((stmt) => !held.has(stmt)),
|
|
@@ -814,7 +823,7 @@ export function planDirectoryDdl(ddl) {
|
|
|
814
823
|
/** Refuses a plan whose held-back statements the DDL does not carry; returns it otherwise. */
|
|
815
824
|
export function assertDirectoryDdlPlan(plan) {
|
|
816
825
|
if (plan.missing.length > 0) {
|
|
817
|
-
throw new Error(`the directory DDL does not carry ${plan.missing.length} statement(s)
|
|
826
|
+
throw new Error(`the directory DDL does not carry ${plan.missing.length} statement(s) it holds back until the columns exist (VERSION_MIGRATIONS_DDL, the sweep-runs index) — ` +
|
|
818
827
|
`interpolate the fragment whole: ${plan.missing[0]}`);
|
|
819
828
|
}
|
|
820
829
|
return plan;
|
|
@@ -989,8 +998,32 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
989
998
|
this.kernelSql = switchSqlOver(this.sql);
|
|
990
999
|
this.applyDirectorySchema();
|
|
991
1000
|
this.installRouteReadModel(routeKvWriterOf(Reflect.get(env, 'ROUTES')));
|
|
1001
|
+
this.directoryMirror = directoryMirrorFor(env, durableMirrorSender(env), {
|
|
1002
|
+
sql: this.sql,
|
|
1003
|
+
transaction: (fn) => ctx.storage.transactionSync(fn),
|
|
1004
|
+
quiet: () => this.routeCallDepth === 0,
|
|
1005
|
+
armRetry: async (at) => {
|
|
1006
|
+
const current = await ctx.storage.getAlarm();
|
|
1007
|
+
if (current === null || current > at)
|
|
1008
|
+
await ctx.storage.setAlarm(at);
|
|
1009
|
+
},
|
|
1010
|
+
});
|
|
992
1011
|
this.backfillArmed = ctx.blockConcurrencyWhile(() => this.armVersionMigrationsBackfill());
|
|
993
1012
|
}
|
|
1013
|
+
// -- K-68 step 3b: the dual-write to the split's objects (directory-mirror.ts) -----
|
|
1014
|
+
/** Set where `DIRECTORY_MIRROR` is on and the two object namespaces are bound; null otherwise. */
|
|
1015
|
+
directoryMirror;
|
|
1016
|
+
/** Flush what the outbox holds. Called when the outermost method returns, like the route kick. */
|
|
1017
|
+
kickDirectoryMirror() {
|
|
1018
|
+
this.directoryMirror?.kick();
|
|
1019
|
+
}
|
|
1020
|
+
/** Drain the outbox now, for a caller (and a test) that must see the copy land. */
|
|
1021
|
+
async settleDirectoryMirror() {
|
|
1022
|
+
return this.directoryMirror ? this.directoryMirror.settle() : null;
|
|
1023
|
+
}
|
|
1024
|
+
directoryMirrorStatus() {
|
|
1025
|
+
return this.directoryMirror ? this.directoryMirror.status() : { enabled: false };
|
|
1026
|
+
}
|
|
994
1027
|
// -- the routing read model (#3395) -------------------------------------------
|
|
995
1028
|
/** Set where a `ROUTES` KV namespace is bound; null otherwise, and the read model is off. */
|
|
996
1029
|
routePublisher = null;
|
|
@@ -1222,6 +1255,8 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1222
1255
|
// #3395: the routing read model's retry. It lifts the backoff (and redoes a failed namespace
|
|
1223
1256
|
// check); the flush itself starts when this alarm returns, as after any directory method.
|
|
1224
1257
|
await this.retryRouteReadModel().catch((err) => console.error('route read model: retry failed', err));
|
|
1258
|
+
// K-68 step 3b: the dual-write's retry after a send an object refused.
|
|
1259
|
+
this.directoryMirror?.retry();
|
|
1225
1260
|
let more;
|
|
1226
1261
|
try {
|
|
1227
1262
|
more = this.ctx.storage.transactionSync(() => splitVersionMigrationsBatch(this.kernelSql)).more;
|
|
@@ -1466,7 +1501,12 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1466
1501
|
const row = this.sql
|
|
1467
1502
|
.exec("SELECT sql FROM sqlite_master WHERE type = 'index' AND name = ?", '_substrat_sweep_runs_intent')
|
|
1468
1503
|
.toArray()[0];
|
|
1469
|
-
|
|
1504
|
+
// None at all (a fresh or restored directory, or one whose index never got built): the held-back
|
|
1505
|
+
// `DIRECTORY_DDL_PLAN.afterColumns` creates it right after this. Nothing to rebuild, and a restore's
|
|
1506
|
+
// async transaction could not hold the `transactionSync` a rebuild takes.
|
|
1507
|
+
if (!row)
|
|
1508
|
+
return;
|
|
1509
|
+
if (sweepRunsIntentHasKind(row.sql))
|
|
1470
1510
|
return;
|
|
1471
1511
|
this.rebuildAtomically(['DROP INDEX IF EXISTS _substrat_sweep_runs_intent', SWEEP_RUNS_INTENT_INDEX]);
|
|
1472
1512
|
}
|
|
@@ -1636,6 +1676,10 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1636
1676
|
*/
|
|
1637
1677
|
async exportDumpPage(cursor, opts = {}) {
|
|
1638
1678
|
const maxBytes = opts.maxBytes ?? SCOPE_DUMP_PAGE_MAX_BYTES;
|
|
1679
|
+
// #3422: a copy whose pass was cut off leaves its whole snapshot here. Dropped inside the
|
|
1680
|
+
// snapshot's own transaction, it doubled that transaction, which then failed every retry.
|
|
1681
|
+
if (cursor === null)
|
|
1682
|
+
await this.dropLeftoverSnapshot();
|
|
1639
1683
|
const taken = cursor === null ? this.snapshotDirectory(opts.byReference ?? 'off') : null;
|
|
1640
1684
|
// Right after the snapshot's transaction: the storage call holds this object's input gate, so
|
|
1641
1685
|
// no write lands between the copy's instant and the bookmark's.
|
|
@@ -1771,9 +1815,10 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1771
1815
|
return this.sql.exec(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`, COPY_TABLE).toArray().length > 0;
|
|
1772
1816
|
}
|
|
1773
1817
|
/**
|
|
1774
|
-
* Copy every dumped table into a fresh snapshot (#2868),
|
|
1775
|
-
* and
|
|
1776
|
-
*
|
|
1818
|
+
* Copy every dumped table into a fresh snapshot (#2868), and return the cursor of its first page
|
|
1819
|
+
* and how many tables it holds. One synchronous transaction, so no write lands between two
|
|
1820
|
+
* tables' reads. A snapshot a copy left unfinished is dropped before it (`dropLeftoverSnapshot`,
|
|
1821
|
+
* #3422); the drop here only catches one a concurrent first page made in between.
|
|
1777
1822
|
*
|
|
1778
1823
|
* #3325: under `on`, a by-reference table is not copied; its horizon (largest rowid) and row
|
|
1779
1824
|
* count are recorded instead, which costs no row written. Under `verify` it is copied as before,
|
|
@@ -1815,6 +1860,21 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1815
1860
|
return { cursor: { copyId, ord: 0, after: 0 }, tables: defs.length };
|
|
1816
1861
|
});
|
|
1817
1862
|
}
|
|
1863
|
+
/**
|
|
1864
|
+
* #3422: drop the snapshot a copy left unfinished, one table per turn. Writes with no `await`
|
|
1865
|
+
* between them commit as one transaction, so each drop is followed by a timer, which ends the turn
|
|
1866
|
+
* and commits it. The snapshot's own transaction then has nothing left to drop. A failed
|
|
1867
|
+
* snapshot rolls back only its own writes, so the leftover stays gone.
|
|
1868
|
+
*/
|
|
1869
|
+
async dropLeftoverSnapshot() {
|
|
1870
|
+
const tables = this.sql
|
|
1871
|
+
.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name GLOB ?`, COPY_GLOB)
|
|
1872
|
+
.toArray();
|
|
1873
|
+
for (const { name } of tables) {
|
|
1874
|
+
this.sql.exec(`DROP TABLE IF EXISTS "${name}"`);
|
|
1875
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1818
1878
|
dropDirectorySnapshot() {
|
|
1819
1879
|
const tables = this.sql
|
|
1820
1880
|
.exec(`SELECT name FROM sqlite_master WHERE type = 'table' AND name GLOB ?`, COPY_GLOB)
|
|
@@ -1831,10 +1891,12 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1831
1891
|
return this.sql
|
|
1832
1892
|
.exec(`SELECT name, sql FROM sqlite_master
|
|
1833
1893
|
WHERE type = 'table' AND name NOT GLOB 'sqlite_*' AND name NOT GLOB '_cf_*'
|
|
1834
|
-
AND name NOT GLOB ? AND name NOT GLOB ? AND sql IS NOT NULL
|
|
1894
|
+
AND name NOT GLOB ? AND name NOT GLOB ? AND name NOT GLOB ? AND sql IS NOT NULL
|
|
1835
1895
|
ORDER BY name`, COPY_GLOB,
|
|
1836
1896
|
// #3395: the read model's ledger describes KV, not the directory (route-read-model-publisher.ts).
|
|
1837
|
-
ROUTE_READ_MODEL_TABLE_GLOB
|
|
1897
|
+
ROUTE_READ_MODEL_TABLE_GLOB,
|
|
1898
|
+
// K-68 step 3b: the dual-write's queue and version describe the objects (directory-mirror.ts).
|
|
1899
|
+
DIRECTORY_MIRROR_TABLE_GLOB)
|
|
1838
1900
|
.toArray();
|
|
1839
1901
|
}
|
|
1840
1902
|
/**
|
|
@@ -1865,7 +1927,7 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1865
1927
|
// #3395: the routing read model's tables describe KV, survive a restore, and are never in a dump
|
|
1866
1928
|
// this code exported. One a dump names (in any case: SQLite's names are) is crafted, and loading
|
|
1867
1929
|
// it would make the ledger lie about what KV holds.
|
|
1868
|
-
const routeTable = tables.find((t) => t.name.toLowerCase().startsWith('route_read_model_'));
|
|
1930
|
+
const routeTable = tables.find((t) => t.name.toLowerCase().startsWith('route_read_model_') || isDirectoryMirrorTable(t.name));
|
|
1869
1931
|
if (routeTable) {
|
|
1870
1932
|
throw substratError('validation_failed', `refusing this dump: it names ${routeTable.name}, a table no directory dump carries`);
|
|
1871
1933
|
}
|
|
@@ -1878,7 +1940,9 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1878
1940
|
// restore does not change, and the re-publish below needs it to delete what KV no longer may.
|
|
1879
1941
|
const existing = this.sql
|
|
1880
1942
|
.exec(`SELECT name FROM sqlite_master
|
|
1881
|
-
WHERE type = 'table' AND name NOT GLOB 'sqlite_*' AND name NOT GLOB '_cf_*' AND name NOT GLOB ?`, ROUTE_READ_MODEL_TABLE_GLOB
|
|
1943
|
+
WHERE type = 'table' AND name NOT GLOB 'sqlite_*' AND name NOT GLOB '_cf_*' AND name NOT GLOB ? AND name NOT GLOB ?`, ROUTE_READ_MODEL_TABLE_GLOB,
|
|
1944
|
+
// K-68 step 3b: the dual-write's version must never go back, so its tables survive too.
|
|
1945
|
+
DIRECTORY_MIRROR_TABLE_GLOB)
|
|
1882
1946
|
.toArray();
|
|
1883
1947
|
for (const { name } of existing)
|
|
1884
1948
|
this.sql.exec(`DROP TABLE IF EXISTS "${name}"`);
|
|
@@ -1914,6 +1978,11 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1914
1978
|
// #3395: every key the restored directory routes, and every key KV was given before it —
|
|
1915
1979
|
// a route the restored directory does not hold is deleted, not left serving.
|
|
1916
1980
|
this.routePublisher?.markAll();
|
|
1981
|
+
// K-68 step 3b: the triggers went with the tables. Back AFTER the load, so the restore writes
|
|
1982
|
+
// what it wrote before; the objects now differ from the restored directory, which is recorded
|
|
1983
|
+
// for 3c's backfill to fill again, not sent row by row.
|
|
1984
|
+
this.directoryMirror?.install();
|
|
1985
|
+
this.directoryMirror?.markRestored();
|
|
1917
1986
|
});
|
|
1918
1987
|
// A restore is a new #1764 backfill episode. It replaced the data the old failure count and
|
|
1919
1988
|
// backoff were about, so neither may delay or silence it: the count is cleared and the next
|
|
@@ -2785,78 +2854,28 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
2785
2854
|
return { ok: true, changed: true, previous };
|
|
2786
2855
|
}
|
|
2787
2856
|
/**
|
|
2788
|
-
* Everything the router needs to place ONE peer call (#1706), in one round trip: the
|
|
2789
|
-
*
|
|
2790
|
-
*
|
|
2857
|
+
* Everything the router needs to place ONE peer call (#1706), in one round trip: the CALLER's
|
|
2858
|
+
* own scope record, and the target instance of `vertical` in that tenant with the script and
|
|
2859
|
+
* dispatch parameters that instance runs under (`readPeerCallTarget`, which the routing read
|
|
2860
|
+
* model publishes from too).
|
|
2791
2861
|
*
|
|
2792
|
-
*
|
|
2793
|
-
*
|
|
2794
|
-
*
|
|
2795
|
-
* the vertical it claims — and it is read HERE rather than inferred from routing, so this
|
|
2796
|
-
* path does not inherit #1713.
|
|
2797
|
-
* The target side applies the kernel's one rule (`resolvePeerInstanceFrom`), the same
|
|
2798
|
-
* rule the pure host and the local broker apply.
|
|
2862
|
+
* `publish` (#3395, K-72) is the router's read-model miss: a dispatchable answer is queued for
|
|
2863
|
+
* publishing unless it is published already. A directory that predates it ignores the argument.
|
|
2864
|
+
* The answer is the same either way.
|
|
2799
2865
|
*/
|
|
2800
|
-
peerCallTarget(tenantId, callerScopeId, callerVertical, vertical) {
|
|
2801
|
-
const
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
const tenant = { id: tenantId, slug: caller?.peer_tenant_slug ?? null };
|
|
2814
|
-
const candidates = this.sql
|
|
2815
|
-
.exec(`SELECT s.scope_id, s.tenant_id, s.vertical, s.status, s.kind, s.forked_from,
|
|
2816
|
-
COALESCE(s.serving_ref, vv.deployment_ref) AS deployment_ref,
|
|
2817
|
-
CASE WHEN s.serving_ref IS NOT NULL
|
|
2818
|
-
THEN json_extract(sv.manifest_json, '$.outbound')
|
|
2819
|
-
ELSE json_extract(vv.manifest_json, '$.outbound') END AS outbound_json,
|
|
2820
|
-
CASE WHEN s.serving_ref IS NOT NULL
|
|
2821
|
-
THEN json_extract(sv.manifest_json, '$.calls')
|
|
2822
|
-
ELSE json_extract(vv.manifest_json, '$.calls') END AS calls_json
|
|
2823
|
-
FROM scopes s
|
|
2824
|
-
LEFT JOIN vertical_versions vv ON vv.id = s.vertical_version_id
|
|
2825
|
-
LEFT JOIN verticals vr ON vr.slug = s.vertical
|
|
2826
|
-
LEFT JOIN vertical_versions sv ON sv.id = vr.serving_version_id
|
|
2827
|
-
WHERE s.tenant_id = ? AND s.vertical IN (SELECT value FROM json_each(?))`, tenantId, JSON.stringify(peerVerticalSpellings(vertical, tenant.slug)))
|
|
2828
|
-
.toArray();
|
|
2829
|
-
const resolution = resolvePeerInstanceFrom(candidates.map((r) => ({
|
|
2830
|
-
id: r.scope_id,
|
|
2831
|
-
tenantId: r.tenant_id,
|
|
2832
|
-
vertical: r.vertical,
|
|
2833
|
-
status: r.status,
|
|
2834
|
-
kind: r.kind ?? '',
|
|
2835
|
-
forkedFrom: r.forked_from ?? null,
|
|
2836
|
-
})), tenant, vertical, caller?.bound_target_scope_id ?? null, caller?.binding_invalidated === 1);
|
|
2837
|
-
const target = resolution.outcome === 'resolved'
|
|
2838
|
-
? (candidates.find((r) => r.scope_id === resolution.instance.scopeId) ?? null)
|
|
2839
|
-
: null;
|
|
2840
|
-
// The caller's own state, decided HERE — this DO already applies the kernel's one rule
|
|
2841
|
-
// for the target, and the router must not carry a second copy of "what is primary".
|
|
2842
|
-
const callerState = !caller || caller.tenant_id !== tenantId || !samePeerVertical(caller.vertical, callerVertical, tenant.slug)
|
|
2843
|
-
? 'unknown'
|
|
2844
|
-
: !isPrimaryScopeRow(caller)
|
|
2845
|
-
? 'not-primary'
|
|
2846
|
-
: caller.status !== 'active' || caller.tenant_status !== 'active'
|
|
2847
|
-
? 'inactive'
|
|
2848
|
-
: 'ok';
|
|
2849
|
-
return {
|
|
2850
|
-
caller: {
|
|
2851
|
-
state: callerState,
|
|
2852
|
-
status: caller?.tenant_status !== 'active' ? `tenant ${caller?.tenant_status ?? 'unknown'}` : caller.status,
|
|
2853
|
-
// The directory's own, for the tenant this call was authenticated in.
|
|
2854
|
-
tenantSlug: tenant.slug,
|
|
2855
|
-
},
|
|
2856
|
-
outcome: resolution.outcome,
|
|
2857
|
-
count: resolution.outcome === 'ambiguous' ? resolution.count : 0,
|
|
2858
|
-
target,
|
|
2859
|
-
};
|
|
2866
|
+
peerCallTarget(tenantId, callerScopeId, callerVertical, vertical, opts) {
|
|
2867
|
+
const read = readPeerCallTarget(this.sql, tenantId, callerScopeId, callerVertical, vertical);
|
|
2868
|
+
if (opts?.publish === true && this.routePublisher) {
|
|
2869
|
+
// Optional, as `readRoute`'s: a fill that cannot be queued must not fail a read that succeeded.
|
|
2870
|
+
// This method's own return starts the flush (`kickRouteReadModelAfterEveryCall`).
|
|
2871
|
+
try {
|
|
2872
|
+
this.routePublisher.requestPeerPublish({ tenantId, callerScopeId, callerVertical, vertical }, read);
|
|
2873
|
+
}
|
|
2874
|
+
catch (err) {
|
|
2875
|
+
console.error('route read model: could not queue a peer-call miss for publishing', err);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
return read.row;
|
|
2860
2879
|
}
|
|
2861
2880
|
/**
|
|
2862
2881
|
* Request-path gate: only an active hostname, correctly paired active scope and active
|
|
@@ -5530,6 +5549,8 @@ const ROUTE_KICK_EXEMPT = new Set([
|
|
|
5530
5549
|
// The retry path: its own return must not start a flush, or a failure is retried at once rather than
|
|
5531
5550
|
// after `ROUTE_PUBLISH_RETRY_MS`; the alarm starts it (`retryRouteReadModel`).
|
|
5532
5551
|
'armRouteReadModelRetry', 'retryRouteReadModel',
|
|
5552
|
+
// K-68 step 3b: the dual-write's flush is kicked by the same return, and drives itself.
|
|
5553
|
+
'kickDirectoryMirror', 'settleDirectoryMirror',
|
|
5533
5554
|
]);
|
|
5534
5555
|
for (const name of Object.getOwnPropertyNames(ControlPlaneDO.prototype)) {
|
|
5535
5556
|
if (ROUTE_KICK_EXEMPT.has(name))
|
|
@@ -5545,8 +5566,10 @@ for (const name of Object.getOwnPropertyNames(ControlPlaneDO.prototype)) {
|
|
|
5545
5566
|
// transaction (`bumpLifecycleRevision` within `writeAndAudit`) must not start a flush there.
|
|
5546
5567
|
const leave = () => {
|
|
5547
5568
|
this.routeCallDepth -= 1;
|
|
5548
|
-
if (this.routeCallDepth === 0)
|
|
5569
|
+
if (this.routeCallDepth === 0) {
|
|
5549
5570
|
this.kickRouteReadModel();
|
|
5571
|
+
this.kickDirectoryMirror();
|
|
5572
|
+
}
|
|
5550
5573
|
};
|
|
5551
5574
|
this.routeCallDepth += 1;
|
|
5552
5575
|
let out;
|