@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/index.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export { doScopedSql } from './sql.js';
|
|
|
25
25
|
export { createDoTupleChecker } from './checker.js';
|
|
26
26
|
export { definePlatformSweeperDO, PLATFORM_SWEEPER_NAME } from './platform-sweeper-do.js';
|
|
27
27
|
export { defineKickCoalescerDO, kickCoalescerName, CROSS_VERTICAL_KICK_WINDOW_MS, type KickCoalescerConfig, type KickCoalescerDo, type KickOutcome, type KickProducer, } from './kick-coalescer-do.js';
|
|
28
|
+
export { defineConnectionSweepDO, connectionSweepName, spreadOf as connectionSweepSpreadOf, CONNECTION_SWEEP_INTERVAL_MS, CONNECTION_SWEEP_OVERDUE_MS, CONNECTION_SWEEP_FIRST_SPREAD_MS, type ConnectionSweepCheck, type ConnectionSweepConfig, type ConnectionSweepDo, type ConnectionSweepRef, type ConnectionSweepRun, } from './connection-sweep-do.js';
|
|
28
29
|
export type { PlatformSweeperDoConfig, PlatformSweepOutcome } from './platform-sweeper-do.js';
|
|
29
30
|
export { defineCopyJobDO, type CopyJobDo, type CopyJobDoConfig, type CopyJobDoRecord, type CopyJobStep } from './copy-job-do.js';
|
|
30
31
|
export { defineScopeSweeperDO, SCOPE_SWEEPER_NAME } from './scope-sweeper-do.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EACV,0BAA0B,EAC1B,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,YAAY,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,YAAY,EACZ,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,KAAK,mBAAmB,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AACrJ,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,uBAAuB,EA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AAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EACL,oCAAoC,EACpC,gCAAgC,EAChC,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,8 @@ export { createDoTupleChecker } from './checker.js';
|
|
|
25
25
|
export { definePlatformSweeperDO, PLATFORM_SWEEPER_NAME } from './platform-sweeper-do.js';
|
|
26
26
|
// #1705 PR 2: the global bound on the router's cross-vertical kick, one object per producer.
|
|
27
27
|
export { defineKickCoalescerDO, kickCoalescerName, CROSS_VERTICAL_KICK_WINDOW_MS, } from './kick-coalescer-do.js';
|
|
28
|
+
// K-69, step 4.2 (#3376): one object per connection, whose alarm runs that connection's sweep.
|
|
29
|
+
export { defineConnectionSweepDO, connectionSweepName, spreadOf as connectionSweepSpreadOf, CONNECTION_SWEEP_INTERVAL_MS, CONNECTION_SWEEP_OVERDUE_MS, CONNECTION_SWEEP_FIRST_SPREAD_MS, } from './connection-sweep-do.js';
|
|
28
30
|
// #2450 step 2: one object per background scope copy, stepped by alarm.
|
|
29
31
|
export { defineCopyJobDO } from './copy-job-do.js';
|
|
30
32
|
export { defineScopeSweeperDO, SCOPE_SWEEPER_NAME } from './scope-sweeper-do.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAYhD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe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uBAAuB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC1F,6FAA6F;AAC7F,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,6BAA6B,GAK9B,MAAM,wBAAwB,CAAC;AAChC,+FAA+F;AAC/F,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,QAAQ,IAAI,uBAAuB,EACnC,4BAA4B,EAC5B,2BAA2B,EAC3B,gCAAgC,GAMjC,MAAM,0BAA0B,CAAC;AAElC,wEAAwE;AACxE,OAAO,EAAE,eAAe,EAAgF,MAAM,kBAAkB,CAAC;AACjI,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAQjF,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,iGAAiG;AACjG,mGAAmG;AACnG,OAAO,EACL,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,wBAAwB,GAKzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE7E,0EAA0E;AAC1E,OAAO,EACL,oCAAoC,EACpC,gCAAgC,EAChC,sBAAsB,GACvB,MAAM,sBAAsB,CAAC"}
|
|
@@ -14,9 +14,19 @@ export interface KickProducer {
|
|
|
14
14
|
tenantId: TenantId;
|
|
15
15
|
scopeId: ScopeId;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* What the pass is asked to do, as the kicks since the last pass named it (K-69): `null` is
|
|
19
|
+
* everything, which is what a kick naming nothing asks for, as every kick did before kicks could
|
|
20
|
+
* name anything. Otherwise the union of the names the kicks gave.
|
|
21
|
+
*/
|
|
22
|
+
export type KickWants = ReadonlySet<string> | null;
|
|
17
23
|
/** The RPC surface a `defineKickCoalescerDO` class exposes over its stub. */
|
|
18
24
|
export interface KickCoalescerDo {
|
|
19
|
-
|
|
25
|
+
/**
|
|
26
|
+
* `wants` (K-69): what this kick asks the pass for. Absent, everything. A pass is handed the union
|
|
27
|
+
* of what the kicks it covers asked for, so one kind of work never runs because another was asked.
|
|
28
|
+
*/
|
|
29
|
+
kick(tenantId: TenantId, scopeId: ScopeId, wants?: readonly string[]): Promise<KickOutcome>;
|
|
20
30
|
}
|
|
21
31
|
export interface KickCoalescerConfig<Env> {
|
|
22
32
|
/** Default {@link CROSS_VERTICAL_KICK_WINDOW_MS}. */
|
|
@@ -27,8 +37,8 @@ export interface KickCoalescerConfig<Env> {
|
|
|
27
37
|
* authority lives: the deployment runs `runCrossVerticalFrom` here with the same reach and
|
|
28
38
|
* gates as its sweep, so this object decides only WHEN, never what or for whom.
|
|
29
39
|
*/
|
|
30
|
-
run(env: Env, producer: KickProducer): Promise<void | {
|
|
31
|
-
more?: boolean;
|
|
40
|
+
run(env: Env, producer: KickProducer, wants: KickWants): Promise<void | {
|
|
41
|
+
more?: boolean | readonly string[];
|
|
32
42
|
}>;
|
|
33
43
|
/**
|
|
34
44
|
* #3365: every pass runs from the alarm, never inside the kick. A kick only marks the producer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kick-coalescer-do.d.ts","sourceRoot":"","sources":["../src/kick-coalescer-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEjE;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD,kGAAkG;AAClG,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,WAAW,GAAG,UAAU,CAAC;AAE3D,8FAA8F;AAC9F,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,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IAChH;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,mGAAmG;IACnG,OAAO,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;CACxC;AAED,oGAAoG;AACpG,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAE9E;AAuBD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EACvC,MAAM,EAAE,mBAAmB,CAAC,GAAG,CAAC,GAC/B,KAAK,GAAG,EAAE,kBAAkB,EAAE,GAAG,EAAE,GAAG,KAAK,aAAa,CAAC,GAAG,CAAC,GAAG,eAAe,CAmFjF"}
|
|
@@ -10,6 +10,15 @@ export const CROSS_VERTICAL_KICK_WINDOW_MS = 5_000;
|
|
|
10
10
|
export function kickCoalescerName(tenantId, scopeId) {
|
|
11
11
|
return `${tenantId}:${scopeId}`;
|
|
12
12
|
}
|
|
13
|
+
/** Fold one kick's ask into what the next pass is asked for. Everything absorbs any list. */
|
|
14
|
+
function wantsUnion(prior, wants) {
|
|
15
|
+
if (wants === null)
|
|
16
|
+
return null;
|
|
17
|
+
const known = prior.dirty ? prior.wants : [];
|
|
18
|
+
if (known === null || known === undefined)
|
|
19
|
+
return prior.dirty ? null : [...wants];
|
|
20
|
+
return [...new Set([...known, ...wants])].sort();
|
|
21
|
+
}
|
|
13
22
|
/**
|
|
14
23
|
* `defineKickCoalescerDO` — the global bound on the router kick (#1705 PR 2).
|
|
15
24
|
*
|
|
@@ -35,9 +44,10 @@ export function defineKickCoalescerDO(config) {
|
|
|
35
44
|
return class KickCoalescerDO extends DurableObject {
|
|
36
45
|
/** The in-flight pass, when one is running. */
|
|
37
46
|
#running = null;
|
|
38
|
-
async kick(tenantId, scopeId) {
|
|
47
|
+
async kick(tenantId, scopeId, wants) {
|
|
39
48
|
const prior = await this.ctx.storage.get('state');
|
|
40
|
-
const
|
|
49
|
+
const base = prior ?? { producer: { tenantId, scopeId }, lastStartedAt: 0, dirty: false };
|
|
50
|
+
const state = { ...base, wants: wantsUnion(base, wants ?? null) };
|
|
41
51
|
if (this.#running) {
|
|
42
52
|
await this.ctx.storage.put('state', { ...state, dirty: true });
|
|
43
53
|
return 'coalesced';
|
|
@@ -75,16 +85,20 @@ export function defineKickCoalescerDO(config) {
|
|
|
75
85
|
}
|
|
76
86
|
async #pass(state) {
|
|
77
87
|
const startedAt = Date.now();
|
|
78
|
-
|
|
88
|
+
const wants = state.wants === null || state.wants === undefined ? null : new Set(state.wants);
|
|
89
|
+
await this.ctx.storage.put('state', { ...state, lastStartedAt: startedAt, dirty: false, wants: [] });
|
|
79
90
|
this.#running = (async () => {
|
|
80
91
|
try {
|
|
81
|
-
const outcome = await config.run(this.env, state.producer);
|
|
92
|
+
const outcome = await config.run(this.env, state.producer, wants);
|
|
82
93
|
// #3365: the pass stopped with work left (a deadline, its last round). Dirty again, so
|
|
83
94
|
// the alarm at this window's end runs the next one, and so on until a pass finishes.
|
|
84
|
-
|
|
95
|
+
// K-69: `more` may name the part that had more, and the next pass is asked for that part
|
|
96
|
+
// alone (beside whatever kicks arrived meanwhile); `true` asks for everything, as before.
|
|
97
|
+
const more = outcome?.more;
|
|
98
|
+
if (more === true || (Array.isArray(more) && more.length > 0)) {
|
|
85
99
|
const now = await this.ctx.storage.get('state');
|
|
86
100
|
if (now)
|
|
87
|
-
await this.ctx.storage.put('state', { ...now, dirty: true });
|
|
101
|
+
await this.ctx.storage.put('state', { ...now, wants: wantsUnion(now, more === true ? null : more), dirty: true });
|
|
88
102
|
}
|
|
89
103
|
}
|
|
90
104
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kick-coalescer-do.js","sourceRoot":"","sources":["../src/kick-coalescer-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AAC,EAAE,CAAC,CAAC;QAC9E,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The directory's answer to "may this caller place a peer call to `vertical`, and to which
|
|
3
|
+
* instance" (#1706), as one function over the directory's tables. `ControlPlaneDO.peerCallTarget`
|
|
4
|
+
* answers the router with it, and the routing read model (#3395, K-72) publishes from it, so the
|
|
5
|
+
* entry the router reads from KV and the answer it would have had from the directory are computed
|
|
6
|
+
* by the same code: there is no second copy of the rule to drift.
|
|
7
|
+
*/
|
|
8
|
+
/** One candidate instance of a vertical in a tenant (#1706), with what it dispatches as. */
|
|
9
|
+
export interface PeerCandidateRow {
|
|
10
|
+
scope_id: string;
|
|
11
|
+
tenant_id: string;
|
|
12
|
+
vertical: string | null;
|
|
13
|
+
status: string;
|
|
14
|
+
kind: string | null;
|
|
15
|
+
forked_from: string | null;
|
|
16
|
+
deployment_ref: string | null;
|
|
17
|
+
outbound_json: string | null;
|
|
18
|
+
calls_json: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** Where the CALLER stands: usable, or the one reason it is not (#1706). */
|
|
21
|
+
export type PeerCallerState = 'ok' | 'unknown' | 'not-primary' | 'inactive';
|
|
22
|
+
/** What `peerCallTarget` answers: the caller's standing, and the resolved target (or why not). */
|
|
23
|
+
export interface PeerCallTargetRow {
|
|
24
|
+
/** `tenantSlug`: the directory's slug for the caller's tenant (#2252), for the target's door. */
|
|
25
|
+
caller: {
|
|
26
|
+
state: PeerCallerState;
|
|
27
|
+
status: string | null;
|
|
28
|
+
tenantSlug: string | null;
|
|
29
|
+
};
|
|
30
|
+
outcome: 'resolved' | 'not-installed' | 'ambiguous' | 'bound-unavailable';
|
|
31
|
+
/** How many live instances, when `ambiguous`. Zero otherwise. */
|
|
32
|
+
count: number;
|
|
33
|
+
target: PeerCandidateRow | null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* What the read model needs beside the answer, and the router never sees: where the target's
|
|
37
|
+
* dispatch comes from (a serving script takes its vertical's serving policy, which the read model
|
|
38
|
+
* keeps under its own key), and whether either scope is residency-pinned (K-36).
|
|
39
|
+
*/
|
|
40
|
+
export interface PeerCallTargetSource {
|
|
41
|
+
/** The resolved target's `scopes.serving_ref`, and its bound version's own script. */
|
|
42
|
+
target: {
|
|
43
|
+
serving_ref: string | null;
|
|
44
|
+
version_ref: string | null;
|
|
45
|
+
} | null;
|
|
46
|
+
/** The caller or the resolved target is jurisdiction-pinned, or holds a region-pinned hostname. */
|
|
47
|
+
pinned: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Everything the router needs to place ONE peer call (#1706), in two SQL reads, because this sits
|
|
51
|
+
* on a request path. The binding and the tenant's slug join the caller read, so even an unbound
|
|
52
|
+
* singleton adds no round trip. The caller's record is what decides whether it may call at all —
|
|
53
|
+
* live, primary, and the vertical it claims — and it is read HERE rather than inferred from
|
|
54
|
+
* routing, so this path does not inherit #1713. The target side applies the kernel's one rule
|
|
55
|
+
* (`resolvePeerInstanceFrom`), the same rule the pure host and the local broker apply.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readPeerCallTarget(sql: SqlStorage, tenantId: string, callerScopeId: string, callerVertical: string, vertical: string): {
|
|
58
|
+
row: PeerCallTargetRow;
|
|
59
|
+
source: PeerCallTargetSource;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=peer-call-target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-call-target.d.ts","sourceRoot":"","sources":["../src/peer-call-target.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AAEH,4FAA4F;AAC5F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,IAA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kernel';
|
|
2
|
+
/** A jurisdiction that pins storage, which KV cannot honour (K-36). `global` pins nothing. */
|
|
3
|
+
const isPinned = (jurisdiction) => jurisdiction !== null && jurisdiction !== 'global';
|
|
4
|
+
/** Any active hostname of the scope is region-pinned. */
|
|
5
|
+
const PINNED_HOSTNAME = (scope) => `EXISTS (SELECT 1 FROM hostnames WHERE scope_id = ${scope} AND status = 'active' AND region IS NOT NULL)`;
|
|
6
|
+
/**
|
|
7
|
+
* Everything the router needs to place ONE peer call (#1706), in two SQL reads, because this sits
|
|
8
|
+
* on a request path. The binding and the tenant's slug join the caller read, so even an unbound
|
|
9
|
+
* singleton adds no round trip. The caller's record is what decides whether it may call at all —
|
|
10
|
+
* live, primary, and the vertical it claims — and it is read HERE rather than inferred from
|
|
11
|
+
* routing, so this path does not inherit #1713. The target side applies the kernel's one rule
|
|
12
|
+
* (`resolvePeerInstanceFrom`), the same rule the pure host and the local broker apply.
|
|
13
|
+
*/
|
|
14
|
+
export function readPeerCallTarget(sql, tenantId, callerScopeId, callerVertical, vertical) {
|
|
15
|
+
const caller = sql
|
|
16
|
+
.exec(`SELECT s.tenant_id, s.vertical, s.status, s.kind, s.forked_from, s.jurisdiction,
|
|
17
|
+
${PINNED_HOSTNAME('s.scope_id')} AS has_pinned_hostname,
|
|
18
|
+
t.status AS tenant_status, pb.target_scope_id AS bound_target_scope_id,
|
|
19
|
+
pb.invalidated AS binding_invalidated,
|
|
20
|
+
(SELECT slug FROM tenants WHERE tenant_id = ?) AS peer_tenant_slug
|
|
21
|
+
FROM scopes s
|
|
22
|
+
LEFT JOIN tenants t ON t.tenant_id = s.tenant_id
|
|
23
|
+
LEFT JOIN peer_bindings pb ON pb.tenant_id = s.tenant_id
|
|
24
|
+
AND pb.caller_scope_id = s.scope_id AND pb.vertical = ?
|
|
25
|
+
WHERE s.scope_id = ?`, tenantId, vertical, callerScopeId)
|
|
26
|
+
.toArray()[0];
|
|
27
|
+
// No caller row is refused below ('unknown'); its candidates are then read exactly.
|
|
28
|
+
const tenant = { id: tenantId, slug: caller?.peer_tenant_slug ?? null };
|
|
29
|
+
const candidates = sql
|
|
30
|
+
.exec(`SELECT s.scope_id, s.tenant_id, s.vertical, s.status, s.kind, s.forked_from,
|
|
31
|
+
COALESCE(s.serving_ref, vv.deployment_ref) AS deployment_ref,
|
|
32
|
+
CASE WHEN s.serving_ref IS NOT NULL
|
|
33
|
+
THEN json_extract(sv.manifest_json, '$.outbound')
|
|
34
|
+
ELSE json_extract(vv.manifest_json, '$.outbound') END AS outbound_json,
|
|
35
|
+
CASE WHEN s.serving_ref IS NOT NULL
|
|
36
|
+
THEN json_extract(sv.manifest_json, '$.calls')
|
|
37
|
+
ELSE json_extract(vv.manifest_json, '$.calls') END AS calls_json,
|
|
38
|
+
s.serving_ref, vv.deployment_ref AS version_ref, s.jurisdiction,
|
|
39
|
+
${PINNED_HOSTNAME('s.scope_id')} AS has_pinned_hostname
|
|
40
|
+
FROM scopes s
|
|
41
|
+
LEFT JOIN vertical_versions vv ON vv.id = s.vertical_version_id
|
|
42
|
+
LEFT JOIN verticals vr ON vr.slug = s.vertical
|
|
43
|
+
LEFT JOIN vertical_versions sv ON sv.id = vr.serving_version_id
|
|
44
|
+
WHERE s.tenant_id = ? AND s.vertical IN (SELECT value FROM json_each(?))`, tenantId, JSON.stringify(peerVerticalSpellings(vertical, tenant.slug)))
|
|
45
|
+
.toArray();
|
|
46
|
+
const resolution = resolvePeerInstanceFrom(candidates.map((r) => ({
|
|
47
|
+
id: r.scope_id,
|
|
48
|
+
tenantId: r.tenant_id,
|
|
49
|
+
vertical: r.vertical,
|
|
50
|
+
status: r.status,
|
|
51
|
+
kind: r.kind ?? '',
|
|
52
|
+
forkedFrom: r.forked_from ?? null,
|
|
53
|
+
})), tenant, vertical, caller?.bound_target_scope_id ?? null, caller?.binding_invalidated === 1);
|
|
54
|
+
const resolved = resolution.outcome === 'resolved'
|
|
55
|
+
? (candidates.find((r) => r.scope_id === resolution.instance.scopeId) ?? null)
|
|
56
|
+
: null;
|
|
57
|
+
// The caller's own state, decided HERE — this already applies the kernel's one rule for the
|
|
58
|
+
// target, and the router must not carry a second copy of "what is primary".
|
|
59
|
+
const callerState = !caller || caller.tenant_id !== tenantId || !samePeerVertical(caller.vertical, callerVertical, tenant.slug)
|
|
60
|
+
? 'unknown'
|
|
61
|
+
: !isPrimaryScopeRow(caller)
|
|
62
|
+
? 'not-primary'
|
|
63
|
+
: caller.status !== 'active' || caller.tenant_status !== 'active'
|
|
64
|
+
? 'inactive'
|
|
65
|
+
: 'ok';
|
|
66
|
+
const target = resolved
|
|
67
|
+
? {
|
|
68
|
+
scope_id: resolved.scope_id,
|
|
69
|
+
tenant_id: resolved.tenant_id,
|
|
70
|
+
vertical: resolved.vertical,
|
|
71
|
+
status: resolved.status,
|
|
72
|
+
kind: resolved.kind,
|
|
73
|
+
forked_from: resolved.forked_from,
|
|
74
|
+
deployment_ref: resolved.deployment_ref,
|
|
75
|
+
outbound_json: resolved.outbound_json,
|
|
76
|
+
calls_json: resolved.calls_json,
|
|
77
|
+
}
|
|
78
|
+
: null;
|
|
79
|
+
return {
|
|
80
|
+
row: {
|
|
81
|
+
caller: {
|
|
82
|
+
state: callerState,
|
|
83
|
+
status: caller?.tenant_status !== 'active' ? `tenant ${caller?.tenant_status ?? 'unknown'}` : caller.status,
|
|
84
|
+
// The directory's own, for the tenant this call was authenticated in.
|
|
85
|
+
tenantSlug: tenant.slug,
|
|
86
|
+
},
|
|
87
|
+
outcome: resolution.outcome,
|
|
88
|
+
count: resolution.outcome === 'ambiguous' ? resolution.count : 0,
|
|
89
|
+
target,
|
|
90
|
+
},
|
|
91
|
+
source: {
|
|
92
|
+
target: resolved ? { serving_ref: resolved.serving_ref, version_ref: resolved.version_ref } : null,
|
|
93
|
+
pinned: (caller !== undefined && (isPinned(caller.jurisdiction) || Number(caller.has_pinned_hostname) === 1)) ||
|
|
94
|
+
(resolved !== null && (isPinned(resolved.jurisdiction) || Number(resolved.has_pinned_hostname) === 1)),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=peer-call-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer-call-target.js","sourceRoot":"","sources":["../src/peer-call-target.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,gBAAgB,GAEjB,MAAM,sBAAsB,CAAC;AAiD9B,8FAA8F;AAC9F,MAAM,QAAQ,GAAG,CAAC,YAA2B,EAAW,EAAE,CAAC,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,QAAQ,CAAC;AAE9G,yDAAyD;AACzD,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,EAAE,CACxC,oDAAoD,KAAK,gDAAgD,CAAC;AAE5G;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAe,EACf,QAAgB,EAChB,aAAqB,EACrB,cAAsB,EACtB,QAAgB;IAEhB,MAAM,MAAM,GAAG,GAAG;SACf,IAAI,CACH;gBACU,eAAe,CAAC,YAAY,CAAC;;;;;;;;6BAQhB,EACvB,QAAQ,EACR,QAAQ,EACR,aAAa,CACd;SACA,OAAO,EAAE,CAAC,CAAC,CAMD,CAAC;IACd,oFAAoF;IACpF,MAAM,MAAM,GAAe,EAAE,EAAE,EAAE,QAAoB,EAAE,IAAI,EAAE,MAAM,EAAE,gBAAgB,IAAI,IAAI,EAAE,CAAC;IAChG,MAAM,UAAU,GAAG,GAAG;SACnB,IAAI,CACH;;;;;;;;;gBASU,eAAe,CAAC,YAAY,CAAC;;;;;iFAKoC,EAC3E,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAC7D;SACA,OAAO,EAEP,CAAC;IACJ,MAAM,UAAU,GAAG,uBAAuB,CACxC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,E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 -1,5 +1,6 @@
|
|
|
1
|
-
import { type RefusedRouteEntry, type RouteEntry, type ServingPolicyEntry } from './route-read-model.js';
|
|
2
|
-
type
|
|
1
|
+
import { type PeerCallEntry, type PeerCallKey, type RefusedRouteEntry, type RouteEntry, type ServingPolicyEntry } from './route-read-model.js';
|
|
2
|
+
import { type PeerCallTargetRow, type PeerCallTargetSource } from './peer-call-target.js';
|
|
3
|
+
type Entry = RouteEntry | RefusedRouteEntry | ServingPolicyEntry | PeerCallEntry;
|
|
3
4
|
/** The tables this owns. Excluded from a directory dump, and from a restore's drop. */
|
|
4
5
|
export declare const ROUTE_READ_MODEL_TABLE_GLOB = "route_read_model_*";
|
|
5
6
|
/** The slice of a KV binding the publisher writes through (and reads its ledger marker from). */
|
|
@@ -19,8 +20,12 @@ export declare function routeKvWriterOf(value: unknown): RouteKvWriter | null;
|
|
|
19
20
|
export declare const ROUTE_LEDGER_MARKER_KEY = "route/v1/meta/ledger";
|
|
20
21
|
export declare const ROUTE_READ_MODEL_TRIGGERS: string[];
|
|
21
22
|
type Sql = SqlStorage;
|
|
22
|
-
/**
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The read model's own key for an entry: `h:<hostname>` for a route, `v:<slug>` for a policy,
|
|
25
|
+
* `c:<tenant>/<caller scope>/<caller vertical>/<target>` for a peer-call answer.
|
|
26
|
+
*/
|
|
27
|
+
export type RouteReadModelKey = `h:${string}` | `v:${string}` | `c:${string}`;
|
|
28
|
+
export declare const peerCallEntryKey: (k: PeerCallKey) => RouteReadModelKey;
|
|
24
29
|
export declare const routeEntryKey: (hostname: string) => RouteReadModelKey;
|
|
25
30
|
export declare const servingPolicyEntryKey: (slug: string) => RouteReadModelKey;
|
|
26
31
|
/** What the source knows about one hostname: its row, its scope's and whether the route serves. */
|
|
@@ -62,6 +67,15 @@ export declare function routeEntryOf(f: RouteSourceFields): RouteEntry | Refused
|
|
|
62
67
|
export declare function servingPolicyEntryOf(f: {
|
|
63
68
|
serving_ref: string | null;
|
|
64
69
|
} & PolicyFields): ServingPolicyEntry;
|
|
70
|
+
/**
|
|
71
|
+
* A peer-call answer's entry, from the directory's own answer (`readPeerCallTarget`): published only
|
|
72
|
+
* when the router would DISPATCH it, and never when either scope is residency-pinned (K-36). Null
|
|
73
|
+
* otherwise, so every refusal and every pinned call is answered by the source.
|
|
74
|
+
*/
|
|
75
|
+
export declare function peerCallEntryOf(key: PeerCallKey, read: {
|
|
76
|
+
row: PeerCallTargetRow;
|
|
77
|
+
source: PeerCallTargetSource;
|
|
78
|
+
}): PeerCallEntry | null;
|
|
65
79
|
/** What has been published, by key: the digest the writer compares against. Kept by the source. */
|
|
66
80
|
export interface PublishedLedger {
|
|
67
81
|
digest(key: RouteReadModelKey): string | undefined;
|
|
@@ -113,6 +127,8 @@ export interface RouteReadModelStatus {
|
|
|
113
127
|
/** Active hostnames it holds nothing for, left to the directory: pinned, or naming a pinned sibling (K-36). */
|
|
114
128
|
pinned: number;
|
|
115
129
|
verticals: number;
|
|
130
|
+
/** Peer-call answers published (published only on a router's request). */
|
|
131
|
+
peerCalls: number;
|
|
116
132
|
}
|
|
117
133
|
export declare class RouteReadModelPublisher {
|
|
118
134
|
private readonly sql;
|
|
@@ -133,6 +149,15 @@ export declare class RouteReadModelPublisher {
|
|
|
133
149
|
* request would buy nothing.
|
|
134
150
|
*/
|
|
135
151
|
requestPublish(hostname: string): void;
|
|
152
|
+
/**
|
|
153
|
+
* The router's peer-call miss (`peerCallTarget(…, { publish: true })`): queue the answer, and its
|
|
154
|
+
* target's serving policy, when the answer dispatches and is not published already. A refusal or a
|
|
155
|
+
* pinned call has no entry to publish, so queueing it would buy nothing.
|
|
156
|
+
*/
|
|
157
|
+
requestPeerPublish(key: PeerCallKey, read: {
|
|
158
|
+
row: PeerCallTargetRow;
|
|
159
|
+
source: PeerCallTargetSource;
|
|
160
|
+
}): void;
|
|
136
161
|
pending(): boolean;
|
|
137
162
|
/**
|
|
138
163
|
* Publish up to `maxKeys` dirty keys. Throws when KV refuses a write, once every write it started
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-read-model-publisher.d.ts","sourceRoot":"","sources":["../src/route-read-model-publisher.ts"],"names":[],"mappings":"AA6BA,OAAO,
|
|
1
|
+
{"version":3,"file":"route-read-model-publisher.d.ts","sourceRoot":"","sources":["../src/route-read-model-publisher.ts"],"names":[],"mappings":"AA6BA,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAsB,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAE9G,KAAK,KAAK,GAAG,UAAU,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,aAAa,CAAC;AAEjF,uFAAuF;AACvF,eAAO,MAAM,2BAA2B,uBAAuB,CAAC;AAEhE,iGAAiG;AACjG,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAIpE;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,yBAAyB,CAAC;AA+H9D,eAAO,MAAM,yBAAyB,UAAwD,CAAC;AAgC/F,KAAK,GAAG,GAAG,UAAU,CAAC;AAmBtB;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE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IAED;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC,CAkBxC;YAEa,UAAU;IAiBxB;;;;OAIG;IACG,SAAS,CAAC,KAAK,SAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAiCzE;IAED,MAAM,IAAI,oBAAoB,CA2B7B;CACF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAItD"}
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { ROUTE_SCOPE_HOSTNAMES_MAX } from '@substrat-run/contracts';
|
|
29
29
|
import { isPrimaryScopeRow } from '@substrat-run/kernel';
|
|
30
|
-
import { ROUTE_READ_MODEL_VERSION, routeKvKey, servingPolicyKvKey, } from './route-read-model.js';
|
|
30
|
+
import { peerCallKeyPart, ROUTE_READ_MODEL_VERSION, routeKvKey, servingPolicyKvKey, } from './route-read-model.js';
|
|
31
|
+
import { readPeerCallTarget } from './peer-call-target.js';
|
|
31
32
|
/** The tables this owns. Excluded from a directory dump, and from a restore's drop. */
|
|
32
33
|
export const ROUTE_READ_MODEL_TABLE_GLOB = 'route_read_model_*';
|
|
33
34
|
/** A binding that looks like KV, or nothing: the read model is on only where one is bound. */
|
|
@@ -105,7 +106,56 @@ const TRIGGERS = [
|
|
|
105
106
|
['rrm_versions_au', `AFTER UPDATE OF id, deployment_ref, manifest_json ON vertical_versions BEGIN ${dependentsOfVersion('OLD')} ${dependentsOfVersion('NEW')} END`],
|
|
106
107
|
['rrm_versions_ad', `AFTER DELETE ON vertical_versions BEGIN ${dependentsOfVersion('OLD')} END`],
|
|
107
108
|
];
|
|
108
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Peer-call answers (`c:<tenant>/…`, #3395 follow-up) are published only once a router asked for
|
|
111
|
+
* one, so their capture re-dirties only the answers of the changed tenant that are published or
|
|
112
|
+
* queued: a range of keys, since the tenant leads the key. With no peer answer requested (every
|
|
113
|
+
* router's `PEER_READ_MODEL` off) these find nothing and append nothing. A queued key counts as well
|
|
114
|
+
* as a published one, because a flush computes a key, awaits, and only then records it in the
|
|
115
|
+
* ledger: a change landing in between still finds the key's outbox row and queues it again.
|
|
116
|
+
*
|
|
117
|
+
* A peer call is answered inside one tenant (the caller's), so every input of the answer is a row
|
|
118
|
+
* of that tenant: its scopes (the caller and every candidate), the tenant itself (status, and the
|
|
119
|
+
* slug the pinned spellings read), its peer bindings, and its scopes' hostnames (residency). The
|
|
120
|
+
* one input outside a tenant row is a legacy target's own version; its trigger finds the tenants
|
|
121
|
+
* bound to it. A promote moves the serving policy (`v:`), which no peer entry holds.
|
|
122
|
+
*/
|
|
123
|
+
const peersOfTenantsIn = (tenants) => {
|
|
124
|
+
const range = (t, k) => `${k}.key >= 'c:' || ${t}.tenant_id || '/' AND ${k}.key < 'c:' || ${t}.tenant_id || '0'`;
|
|
125
|
+
return append(`SELECT p.key FROM (${tenants}) t JOIN route_read_model_published p ON ${range('t', 'p')}
|
|
126
|
+
UNION SELECT o.key FROM (${tenants}) t JOIN route_read_model_outbox o ON ${range('t', 'o')}`);
|
|
127
|
+
};
|
|
128
|
+
const peersOfTenant = (tenant) => peersOfTenantsIn(`SELECT ${tenant} AS tenant_id`);
|
|
129
|
+
const peersOfVersion = (row) => peersOfTenantsIn(`SELECT DISTINCT tenant_id FROM scopes WHERE vertical_version_id = ${row}.id AND serving_ref IS NULL`);
|
|
130
|
+
/** New names, never an edit of a route trigger: `install` creates a trigger only when its name is missing. */
|
|
131
|
+
const PEER_TRIGGERS = [
|
|
132
|
+
['rrm_peer_scopes_ai', `AFTER INSERT ON scopes BEGIN ${peersOfTenant('NEW.tenant_id')} END`],
|
|
133
|
+
[
|
|
134
|
+
'rrm_peer_scopes_au',
|
|
135
|
+
`AFTER UPDATE OF tenant_id, status, serving_ref, vertical_version_id, vertical, kind, forked_from, jurisdiction ON scopes
|
|
136
|
+
BEGIN ${peersOfTenant('OLD.tenant_id')} ${peersOfTenant('NEW.tenant_id')} END`,
|
|
137
|
+
],
|
|
138
|
+
['rrm_peer_scopes_ad', `AFTER DELETE ON scopes BEGIN ${peersOfTenant('OLD.tenant_id')} END`],
|
|
139
|
+
['rrm_peer_tenants_ai', `AFTER INSERT ON tenants BEGIN ${peersOfTenant('NEW.tenant_id')} END`],
|
|
140
|
+
['rrm_peer_tenants_au', `AFTER UPDATE OF status, slug ON tenants BEGIN ${peersOfTenant('NEW.tenant_id')} END`],
|
|
141
|
+
['rrm_peer_tenants_ad', `AFTER DELETE ON tenants BEGIN ${peersOfTenant('OLD.tenant_id')} END`],
|
|
142
|
+
['rrm_peer_bindings_ai', `AFTER INSERT ON peer_bindings BEGIN ${peersOfTenant('NEW.tenant_id')} END`],
|
|
143
|
+
['rrm_peer_bindings_au', `AFTER UPDATE ON peer_bindings BEGIN ${peersOfTenant('OLD.tenant_id')} ${peersOfTenant('NEW.tenant_id')} END`],
|
|
144
|
+
['rrm_peer_bindings_ad', `AFTER DELETE ON peer_bindings BEGIN ${peersOfTenant('OLD.tenant_id')} END`],
|
|
145
|
+
['rrm_peer_hostnames_ai', `AFTER INSERT ON hostnames BEGIN ${peersOfTenant('NEW.tenant_id')} END`],
|
|
146
|
+
[
|
|
147
|
+
'rrm_peer_hostnames_au',
|
|
148
|
+
`AFTER UPDATE OF tenant_id, scope_id, region, status ON hostnames
|
|
149
|
+
BEGIN ${peersOfTenant('OLD.tenant_id')} ${peersOfTenant('NEW.tenant_id')} END`,
|
|
150
|
+
],
|
|
151
|
+
['rrm_peer_hostnames_ad', `AFTER DELETE ON hostnames BEGIN ${peersOfTenant('OLD.tenant_id')} END`],
|
|
152
|
+
['rrm_peer_versions_ai', `AFTER INSERT ON vertical_versions BEGIN ${peersOfVersion('NEW')} END`],
|
|
153
|
+
['rrm_peer_versions_au', `AFTER UPDATE OF id, deployment_ref, manifest_json ON vertical_versions BEGIN ${peersOfVersion('OLD')} ${peersOfVersion('NEW')} END`],
|
|
154
|
+
['rrm_peer_versions_ad', `AFTER DELETE ON vertical_versions BEGIN ${peersOfVersion('OLD')} END`],
|
|
155
|
+
];
|
|
156
|
+
/** Every published or queued peer-call key: `c:` up to the next character, `;`. */
|
|
157
|
+
const ALL_PEER_KEYS = `key >= 'c:' AND key < 'c;'`;
|
|
158
|
+
export const ROUTE_READ_MODEL_TRIGGERS = [...TRIGGERS, ...PEER_TRIGGERS].map(([name]) => name);
|
|
109
159
|
/** The route read, as the read model stores it: the same joins and gates as `READ_ROUTE_SQL`. */
|
|
110
160
|
const ROUTE_ENTRY_SQL = `SELECT h.tenant_id, h.scope_id, h.vertical_slug, h.surface, h.region, s.jurisdiction,
|
|
111
161
|
s.serving_ref, s.vertical, s.kind, s.forked_from,
|
|
@@ -136,6 +186,24 @@ const isPinned = (jurisdiction) => jurisdiction !== null && jurisdiction !== 'gl
|
|
|
136
186
|
/** An active hostname that does not route, and whether its route would be pinned. */
|
|
137
187
|
const REFUSED_ROUTE_SQL = `SELECT h.region, s.jurisdiction FROM hostnames h
|
|
138
188
|
LEFT JOIN scopes s ON s.scope_id = h.scope_id WHERE h.hostname = ? AND h.status = 'active'`;
|
|
189
|
+
export const peerCallEntryKey = (k) => `c:${peerCallKeyPart(k)}`;
|
|
190
|
+
/** A `c:` key back into what it is keyed by; undefined for one this code did not write. */
|
|
191
|
+
function peerCallKeyOf(key) {
|
|
192
|
+
const parts = key.slice(2).split('/');
|
|
193
|
+
if (parts.length !== 4 || parts.some((p) => p === ''))
|
|
194
|
+
return undefined;
|
|
195
|
+
try {
|
|
196
|
+
return {
|
|
197
|
+
tenantId: parts[0],
|
|
198
|
+
callerScopeId: parts[1],
|
|
199
|
+
callerVertical: decodeURIComponent(parts[2]),
|
|
200
|
+
vertical: decodeURIComponent(parts[3]),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
139
207
|
export const routeEntryKey = (hostname) => `h:${hostname}`;
|
|
140
208
|
export const servingPolicyEntryKey = (slug) => `v:${slug}`;
|
|
141
209
|
/**
|
|
@@ -184,6 +252,31 @@ export function servingPolicyEntryOf(f) {
|
|
|
184
252
|
scope_stores_json: f.scope_stores_json,
|
|
185
253
|
};
|
|
186
254
|
}
|
|
255
|
+
/**
|
|
256
|
+
* A peer-call answer's entry, from the directory's own answer (`readPeerCallTarget`): published only
|
|
257
|
+
* when the router would DISPATCH it, and never when either scope is residency-pinned (K-36). Null
|
|
258
|
+
* otherwise, so every refusal and every pinned call is answered by the source.
|
|
259
|
+
*/
|
|
260
|
+
export function peerCallEntryOf(key, read) {
|
|
261
|
+
const { row, source } = read;
|
|
262
|
+
const t = row.target;
|
|
263
|
+
if (source.pinned || row.caller.state !== 'ok' || row.outcome !== 'resolved')
|
|
264
|
+
return null;
|
|
265
|
+
if (!t || !source.target || t.vertical === null || !t.deployment_ref)
|
|
266
|
+
return null;
|
|
267
|
+
// The router refuses a self-call (#2252), so it is no dispatch to publish.
|
|
268
|
+
if (t.scope_id === key.callerScopeId)
|
|
269
|
+
return null;
|
|
270
|
+
const dispatch = source.target.serving_ref !== null
|
|
271
|
+
? { kind: 'serving', ref: source.target.serving_ref }
|
|
272
|
+
: { kind: 'version', ref: t.deployment_ref, outbound_json: t.outbound_json, calls_json: t.calls_json };
|
|
273
|
+
return {
|
|
274
|
+
v: ROUTE_READ_MODEL_VERSION,
|
|
275
|
+
peer: true,
|
|
276
|
+
caller_tenant_slug: row.caller.tenantSlug,
|
|
277
|
+
target: { scope_id: t.scope_id, tenant_id: t.tenant_id, vertical: t.vertical, dispatch },
|
|
278
|
+
};
|
|
279
|
+
}
|
|
187
280
|
/** The ledger as a table in the source's own SQLite (`route_read_model_published`). */
|
|
188
281
|
export function sqlPublishedLedger(sql) {
|
|
189
282
|
return {
|
|
@@ -277,6 +370,12 @@ export function computeRouteReadModelEntry(sql, key) {
|
|
|
277
370
|
scopeHasPinnedHostname: Number(r['scope_has_pinned']) === 1,
|
|
278
371
|
});
|
|
279
372
|
}
|
|
373
|
+
if (key.startsWith('c:')) {
|
|
374
|
+
const peer = peerCallKeyOf(key);
|
|
375
|
+
if (!peer)
|
|
376
|
+
return null;
|
|
377
|
+
return peerCallEntryOf(peer, readPeerCallTarget(sql, peer.tenantId, peer.callerScopeId, peer.callerVertical, peer.vertical));
|
|
378
|
+
}
|
|
280
379
|
if (key.startsWith('v:')) {
|
|
281
380
|
const r = sql.exec(SERVING_POLICY_SQL, key.slice(2)).toArray()[0];
|
|
282
381
|
if (!r)
|
|
@@ -290,7 +389,11 @@ export function computeRouteReadModelEntry(sql, key) {
|
|
|
290
389
|
}
|
|
291
390
|
return null;
|
|
292
391
|
}
|
|
293
|
-
const kvKeyOf = (key) =>
|
|
392
|
+
const kvKeyOf = (key) => key.startsWith('h:')
|
|
393
|
+
? routeKvKey(key.slice(2))
|
|
394
|
+
: key.startsWith('c:')
|
|
395
|
+
? `route/v${ROUTE_READ_MODEL_VERSION}/c/${key.slice(2)}`
|
|
396
|
+
: servingPolicyKvKey(key.slice(2));
|
|
294
397
|
async function digestOf(text) {
|
|
295
398
|
const bytes = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text)));
|
|
296
399
|
return Array.from(bytes.subarray(0, 16), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
@@ -322,6 +425,18 @@ export class RouteReadModelPublisher {
|
|
|
322
425
|
this.sql.exec(`CREATE TRIGGER IF NOT EXISTS ${name} ${ddl}`);
|
|
323
426
|
fresh = true;
|
|
324
427
|
}
|
|
428
|
+
// The peer triggers arrived after the route ones. Adding them to a directory whose routes are
|
|
429
|
+
// already published must not re-mark every route: only the peer answers (none, the first time)
|
|
430
|
+
// could have missed a change while they were absent.
|
|
431
|
+
let peerFresh = false;
|
|
432
|
+
for (const [name, ddl] of PEER_TRIGGERS) {
|
|
433
|
+
if (present.has(name))
|
|
434
|
+
continue;
|
|
435
|
+
this.sql.exec(`CREATE TRIGGER IF NOT EXISTS ${name} ${ddl}`);
|
|
436
|
+
peerFresh = true;
|
|
437
|
+
}
|
|
438
|
+
if (peerFresh && !fresh)
|
|
439
|
+
this.sql.exec(append(`SELECT key FROM route_read_model_published WHERE ${ALL_PEER_KEYS}`));
|
|
325
440
|
return fresh;
|
|
326
441
|
}
|
|
327
442
|
/** Every key the directory could publish, and every key KV may still hold. */
|
|
@@ -353,6 +468,24 @@ export class RouteReadModelPublisher {
|
|
|
353
468
|
this.sql.exec('INSERT INTO route_read_model_outbox (key) VALUES (?)', key);
|
|
354
469
|
}
|
|
355
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* The router's peer-call miss (`peerCallTarget(…, { publish: true })`): queue the answer, and its
|
|
473
|
+
* target's serving policy, when the answer dispatches and is not published already. A refusal or a
|
|
474
|
+
* pinned call has no entry to publish, so queueing it would buy nothing.
|
|
475
|
+
*/
|
|
476
|
+
requestPeerPublish(key, read) {
|
|
477
|
+
const entry = peerCallEntryOf(key, read);
|
|
478
|
+
if (!entry)
|
|
479
|
+
return;
|
|
480
|
+
const keys = [peerCallEntryKey(key)];
|
|
481
|
+
if (entry.target.dispatch.kind === 'serving')
|
|
482
|
+
keys.push(servingPolicyEntryKey(entry.target.vertical));
|
|
483
|
+
for (const k of keys) {
|
|
484
|
+
const known = this.sql.exec('SELECT 1 FROM route_read_model_published WHERE key = ?', k).toArray().length > 0;
|
|
485
|
+
if (!known)
|
|
486
|
+
this.sql.exec('INSERT INTO route_read_model_outbox (key) VALUES (?)', k);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
356
489
|
pending() {
|
|
357
490
|
return this.sql.exec('SELECT 1 FROM route_read_model_outbox LIMIT 1').toArray().length > 0;
|
|
358
491
|
}
|
|
@@ -506,6 +639,7 @@ export class RouteReadModelPublisher {
|
|
|
506
639
|
refused,
|
|
507
640
|
pinned: n(`SELECT COUNT(*) AS n FROM hostnames WHERE status = 'active'`) - routable - refused,
|
|
508
641
|
verticals: n('SELECT COUNT(*) AS n FROM verticals'),
|
|
642
|
+
peerCalls: n(`SELECT COUNT(*) AS n FROM route_read_model_published WHERE ${ALL_PEER_KEYS}`),
|
|
509
643
|
};
|
|
510
644
|
}
|
|
511
645
|
}
|