@tearleads/client-sdk 0.1.252 → 0.1.253
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/Tearleads.js +3 -3
- package/Tearleads.js.map +1 -1
- package/client/containerContents/index.d.ts +2 -0
- package/client/containerContents/index.js +4 -9
- package/client/containerContents/index.js.map +1 -1
- package/client/containerContents/storeRuntime.d.ts +17 -0
- package/client/containerContents/storeRuntime.js +31 -0
- package/client/containerContents/storeRuntime.js.map +1 -0
- package/client/deviceFirst/index.d.ts +2 -3
- package/client/deviceFirst/index.js +44 -22
- package/client/deviceFirst/index.js.map +1 -1
- package/client/runtime/workflowRuntime.d.ts +2 -0
- package/client/runtime/workflowRuntime.js +13 -6
- package/client/runtime/workflowRuntime.js.map +1 -1
- package/data/sync/syncCoordinator.js +17 -10
- package/data/sync/syncCoordinator.js.map +1 -1
- package/package.json +1 -1
- package/stores/container-contents/containerContentsStore.d.ts +3 -9
- package/stores/container-contents/containerContentsStore.js +24 -21
- package/stores/container-contents/containerContentsStore.js.map +1 -1
- package/stores/container-contents/containerState/storeScope.js +6 -0
- package/stores/container-contents/containerState/storeScope.js.map +1 -0
- package/stores/container-contents/hydration/backgroundHydration.js +2 -1
- package/stores/container-contents/hydration/backgroundHydration.js.map +1 -1
- package/stores/container-contents/hydration/reconnectRefresh.d.ts +10 -0
- package/stores/container-contents/hydration/reconnectRefresh.js +68 -0
- package/stores/container-contents/hydration/reconnectRefresh.js.map +1 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js +49 -0
- package/stores/container-contents/hydration/reconnectRefreshMachine.js.map +1 -0
- package/stores/container-contents/hydration/remoteHydrationRefresh.js +4 -1
- package/stores/container-contents/hydration/remoteHydrationRefresh.js.map +1 -1
- package/stores/container-contents/hydration/remoteHydrationRequest.js +79 -10
- package/stores/container-contents/hydration/remoteHydrationRequest.js.map +1 -1
- package/stores/container-contents/hydration/startupHydration.js +2 -9
- package/stores/container-contents/hydration/startupHydration.js.map +1 -1
- package/stores/container-contents/hydration/treeResetMachine.js +61 -0
- package/stores/container-contents/hydration/treeResetMachine.js.map +1 -0
- package/stores/container-contents/localRefresh.js +28 -12
- package/stores/container-contents/localRefresh.js.map +1 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js +4 -1
- package/stores/container-contents/remoteEvents/remoteContainerIngestion.js.map +1 -1
- package/stores/container-contents/remoteWrites/writeGeneration.js +5 -2
- package/stores/container-contents/remoteWrites/writeGeneration.js.map +1 -1
- package/stores/container-contents/state.d.ts +3 -7
- package/stores/container-contents/state.js +27 -16
- package/stores/container-contents/state.js.map +1 -1
- package/stores/container-contents/syncAgent/index.d.ts +7 -2
- package/stores/container-contents/syncAgent/index.js +77 -49
- package/stores/container-contents/syncAgent/index.js.map +1 -1
- package/stores/container-contents/syncAgent/syncAgentTypes.d.ts +5 -2
- package/stores/container-contents/syncAgent/syncAgentTypes.js.map +1 -1
- package/stores/container-contents/syncAgent/syncLaneIteration.js +6 -3
- package/stores/container-contents/syncAgent/syncLaneIteration.js.map +1 -1
- package/stores/local-projection/localProjectionStore.js +24 -15
- package/stores/local-projection/localProjectionStore.js.map +1 -1
- package/stores/local-projection/registry.js +2 -2
- package/stores/local-projection/registry.js.map +1 -1
- package/workflows/container-contents/container-state/create/createChild.js +3 -15
- package/workflows/container-contents/container-state/create/createChild.js.map +1 -1
- package/workflows/container-contents/containerPersistence.d.ts +4 -8
- package/workflows/container-contents/containerPersistence.js +22 -12
- package/workflows/container-contents/containerPersistence.js.map +1 -1
- package/workflows/container-contents/localState.js +3 -0
- package/workflows/container-contents/localState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.d.ts +12 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js +93 -0
- package/workflows/container-contents/remoteHydration/hydrateRemoteContainers.js.map +1 -0
- package/workflows/container-contents/remoteHydration/index.d.ts +3 -11
- package/workflows/container-contents/remoteHydration/index.js +17 -66
- package/workflows/container-contents/remoteHydration/index.js.map +1 -1
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js +3 -2
- package/workflows/container-contents/remoteHydration/lanes/parentLaneFetch.js.map +1 -1
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js +57 -5
- package/workflows/container-contents/remoteHydration/principalPolicyCache.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js +105 -62
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerPageHydration.js.map +1 -1
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js +15 -5
- package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js.map +1 -1
- package/workflows/container-contents/remoteHydration/types.d.ts +13 -0
- package/workflows/container-contents/remoteHydration/types.js.map +1 -1
- package/workflows/container-contents/runtime.d.ts +3 -0
- package/workflows/container-contents/runtime.js.map +1 -1
- package/workflows/container-contents/storedContainerState.js +17 -7
- package/workflows/container-contents/storedContainerState.js.map +1 -1
- package/workflows/container-contents/syncLane.d.ts +1 -0
- package/workflows/container-contents/syncLane.js +9 -1
- package/workflows/container-contents/syncLane.js.map +1 -1
- package/workflows/shared/runtimeInput.d.ts +2 -0
- package/workflows/shared/runtimeInput.js.map +1 -1
- package/workflows/container-contents/remoteHydration/completeHydration.js +0 -25
- package/workflows/container-contents/remoteHydration/completeHydration.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principalPolicyCache.js","sourceRoot":"","sources":["principalPolicyCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iFAAiF,CAAC;
|
|
1
|
+
{"version":3,"file":"principalPolicyCache.js","sourceRoot":"","sources":["principalPolicyCache.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iFAAiF,CAAC;AAC/H,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAUnF,KAAK,UAAU,iBAAiB,CAC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ACZ,GAAG,CAAC,iBAAiB,IAAI;YACvB,SAAS,EAAE,CAAC,GAAW,EAAE,GAAuB,EAAE,KAAY,EAAE,EAAE;gBAChE,iBAAiB,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;YAC7B,CAAC;SACF,CAAC;KACH,CAAC,CAAC;IACH,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IACzD,OAAO;QACL,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,KAAK,CAAC,MAAM,CACjB,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9C,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,CAC3C,CACJ;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ReferencedPrincipalPolicyWarmer } from \"../../../data/keyingProjectionVerification\";\nimport { referencedPrincipalPolicyKey } from \"../../../data/keyingProjectionVerification/principalPolicy/principalPolicyCache\";\nimport { isKeyingVerificationError } from \"../../../data/shared/securityIncidents\";\nimport type { RemoteContainer } from \"./types\";\n\ntype RemoteContainerPrincipalReferences = Pick<\n RemoteContainer,\n \"metadataReferencedPrincipals\" | \"organizationId\"\n>;\ntype PrincipalReference =\n RemoteContainer[\"metadataReferencedPrincipals\"][number];\n\nasync function readPolicyRefusal(\n warm: () => Promise<void>,\n): Promise<Error | undefined> {\n try {\n await warm();\n return undefined;\n } catch (error) {\n if (isKeyingVerificationError(error)) return error;\n throw error;\n }\n}\n\nexport async function cacheRemoteContainerPrincipalPolicies(input: {\n readonly cacheReferencedPrincipalPolicies?:\n | ReferencedPrincipalPolicyWarmer\n | undefined;\n readonly onRefused?: (\n organizationId: string,\n reference: PrincipalReference,\n error: Error,\n ) => void;\n readonly remoteContainers: readonly RemoteContainerPrincipalReferences[];\n readonly stillCurrent?: (() => boolean) | undefined;\n}): Promise<void> {\n const cacheReferencedPrincipalPolicies =\n input.cacheReferencedPrincipalPolicies;\n if (!cacheReferencedPrincipalPolicies) {\n return;\n }\n\n const referencesByOrganizationId = new Map<\n string,\n Map<string, PrincipalReference>\n >();\n\n for (const remoteContainer of input.remoteContainers) {\n const references = remoteContainer.metadataReferencedPrincipals;\n const { organizationId } = remoteContainer;\n if (references.length === 0 || !organizationId) {\n continue;\n }\n\n const organizationReferences =\n referencesByOrganizationId.get(organizationId) ?? new Map();\n for (const reference of references) {\n organizationReferences.set(\n referencedPrincipalPolicyKey(reference),\n reference,\n );\n }\n referencesByOrganizationId.set(organizationId, organizationReferences);\n }\n\n await Promise.all(\n [...referencesByOrganizationId].map(\n async ([organizationId, referencesByKey]) => {\n const references = [...referencesByKey.values()];\n const warm = (group: readonly PrincipalReference[]) =>\n cacheReferencedPrincipalPolicies({\n organizationId,\n references: group,\n stillCurrent: input.stillCurrent,\n });\n if (!input.onRefused) return warm(references);\n const batchError = await readPolicyRefusal(() => warm(references));\n if (!batchError) return;\n // A failed batch identifies no individual reference. Isolate it\n // without excluding independent containers in the same organization.\n for (const reference of references) {\n if (input.stillCurrent?.() === false) return;\n const error =\n references.length === 1\n ? batchError\n : await readPolicyRefusal(() => warm([reference]));\n if (error) input.onRefused(organizationId, reference, error);\n }\n },\n ),\n );\n}\n\nexport async function warmListedContainerPolicies<\n T extends RemoteContainerPrincipalReferences,\n>(\n items: readonly T[],\n warmer: ReferencedPrincipalPolicyWarmer,\n recordManualError?: (error: Error) => void,\n stillCurrent?: () => boolean,\n): Promise<{ items: readonly T[]; outcome: \"complete\" | \"refused\" }> {\n const refused = new Set<string>();\n const key = (organizationId: string, reference: PrincipalReference) =>\n JSON.stringify([organizationId, referencedPrincipalPolicyKey(reference)]);\n await cacheRemoteContainerPrincipalPolicies({\n cacheReferencedPrincipalPolicies: warmer,\n remoteContainers: items,\n stillCurrent,\n ...(recordManualError && {\n onRefused: (org: string, ref: PrincipalReference, error: Error) => {\n recordManualError(error);\n refused.add(key(org, ref));\n },\n }),\n });\n if (!refused.size) return { items, outcome: \"complete\" };\n return {\n outcome: \"refused\",\n items: items.filter(\n (item) =>\n !item.metadataReferencedPrincipals.some((ref) =>\n refused.has(key(item.organizationId, ref)),\n ),\n ),\n };\n}\n"]}
|
|
@@ -3,12 +3,20 @@ import { prefetchDestinationProjections } from "../destination/destinationPrefet
|
|
|
3
3
|
import { cachedDestinationRole } from "../destination/destinationRoleCache.js";
|
|
4
4
|
import { markContainerParentLaneFetched } from "../lanes/laneFetchMarkers.js";
|
|
5
5
|
import { fetchContainerParentLaneBatch } from "../lanes/parentLaneFetch.js";
|
|
6
|
-
import {
|
|
6
|
+
import { warmListedContainerPolicies } from "../principalPolicyCache.js";
|
|
7
7
|
import { applyContainerTombstones, getApplicableRemoteContainerItems, } from "../tombstoneApplication.js";
|
|
8
8
|
import { containerStateMatchesFingerprint } from "./containerStateFingerprint.js";
|
|
9
9
|
import { loadPausedContainerFilter } from "./organizationSyncPauseFilter.js";
|
|
10
10
|
import { listRemoteContainerIdsWithPendingMetadataUpdates, listRemoteContainerIdsWithPendingStructuralIntents, upsertIsolatedRemoteContainerState, } from "./remoteContainerState.js";
|
|
11
11
|
const CONTAINER_PARENT_HYDRATION_CONCURRENCY = 4;
|
|
12
|
+
/** A retryable lane takes precedence over a refused proof elsewhere in the crawl. */
|
|
13
|
+
function combineOutcomes(a, b) {
|
|
14
|
+
if (a === "retry" || b === "retry")
|
|
15
|
+
return "retry";
|
|
16
|
+
if (a === "refused" || b === "refused")
|
|
17
|
+
return "refused";
|
|
18
|
+
return "complete";
|
|
19
|
+
}
|
|
12
20
|
// Re-checked inside the commit: a pause from another device can land after
|
|
13
21
|
// the page was filtered, and its cleanup may already have run.
|
|
14
22
|
function currentUnlessPaused(input, container) {
|
|
@@ -22,18 +30,15 @@ function matchesListedState(state, expectedContainerStates, containerId) {
|
|
|
22
30
|
});
|
|
23
31
|
}
|
|
24
32
|
async function applyRemoteContainerPage(input) {
|
|
25
|
-
const {
|
|
33
|
+
const { expectedContainerStates, expectedHydrationTombstones, queueParentLane, seenContainerIds, state, } = input;
|
|
26
34
|
let hydratedCount = 0;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
remoteContainers: items,
|
|
33
|
-
stillCurrent: input.isCurrent,
|
|
34
|
-
});
|
|
35
|
+
const policies = await warmListedContainerPolicies(input.items, state.runtime.principalPolicies.createWarmer({
|
|
36
|
+
operation: input.policyOperation,
|
|
37
|
+
}), input.reconnect?.recordManualError, input.isCurrent);
|
|
38
|
+
const { items } = policies;
|
|
39
|
+
let outcome = policies.outcome;
|
|
35
40
|
if (input.isCurrent?.() === false) {
|
|
36
|
-
return { changedCount: 0,
|
|
41
|
+
return { changedCount: 0, outcome: "retry" };
|
|
37
42
|
}
|
|
38
43
|
const [containerIdsWithPendingMetadataUpdates, containerIdsWithPendingStructuralIntents,] = await Promise.all([
|
|
39
44
|
listRemoteContainerIdsWithPendingMetadataUpdates({
|
|
@@ -46,7 +51,7 @@ async function applyRemoteContainerPage(input) {
|
|
|
46
51
|
}),
|
|
47
52
|
]);
|
|
48
53
|
if (input.isCurrent?.() === false) {
|
|
49
|
-
return { changedCount: 0,
|
|
54
|
+
return { changedCount: 0, outcome: "retry" };
|
|
50
55
|
}
|
|
51
56
|
const prefetchedProjections = await prefetchDestinationProjections({
|
|
52
57
|
containers: items.filter((item) => !seenContainerIds.has(item.id) &&
|
|
@@ -58,51 +63,97 @@ async function applyRemoteContainerPage(input) {
|
|
|
58
63
|
});
|
|
59
64
|
for (const container of items) {
|
|
60
65
|
if (input.isCurrent?.() === false) {
|
|
61
|
-
return { changedCount: hydratedCount,
|
|
66
|
+
return { changedCount: hydratedCount, outcome: "retry" };
|
|
62
67
|
}
|
|
63
68
|
if (seenContainerIds.has(container.id)) {
|
|
64
69
|
queueParentLane(container.id);
|
|
65
70
|
continue;
|
|
66
71
|
}
|
|
67
72
|
if (!matchesListedState(state, expectedContainerStates, container.id)) {
|
|
68
|
-
|
|
73
|
+
outcome = "retry";
|
|
69
74
|
continue;
|
|
70
75
|
}
|
|
76
|
+
let failure = "retry";
|
|
71
77
|
const upserted = await upsertIsolatedRemoteContainerState({
|
|
72
|
-
childIdsByParentId,
|
|
78
|
+
childIdsByParentId: input.childIdsByParentId,
|
|
73
79
|
containerIdsWithPendingMetadataUpdates,
|
|
74
80
|
containerIdsWithPendingStructuralIntents,
|
|
75
|
-
host,
|
|
81
|
+
host: input.host,
|
|
76
82
|
isCurrent: currentUnlessPaused(input, container),
|
|
77
83
|
expectedHydrationTombstone: expectedHydrationTombstones.get(container.id) ?? null,
|
|
78
84
|
prefetchedProjection: prefetchedProjections.get(container.id),
|
|
79
85
|
remoteContainer: container,
|
|
80
86
|
state,
|
|
81
|
-
})
|
|
87
|
+
}, (outcome) => {
|
|
88
|
+
failure = outcome;
|
|
89
|
+
}, input.reconnect?.recordManualError);
|
|
82
90
|
if (!upserted) {
|
|
83
|
-
|
|
91
|
+
outcome = combineOutcomes(outcome, failure);
|
|
84
92
|
continue;
|
|
85
93
|
}
|
|
86
94
|
seenContainerIds.add(container.id);
|
|
87
95
|
hydratedCount += 1;
|
|
88
96
|
if (input.isCurrent?.() === false) {
|
|
89
|
-
return { changedCount: hydratedCount,
|
|
97
|
+
return { changedCount: hydratedCount, outcome: "retry" };
|
|
90
98
|
}
|
|
91
99
|
queueParentLane(container.id);
|
|
92
100
|
}
|
|
93
|
-
return { changedCount: hydratedCount,
|
|
101
|
+
return { changedCount: hydratedCount, outcome };
|
|
94
102
|
}
|
|
95
103
|
export function canHydrateRemoteContainers(state) {
|
|
96
104
|
return (state.runtime.auth.isAuthenticated &&
|
|
97
105
|
state.runtime.state.online &&
|
|
98
106
|
state.runtime.infra.dbStatus === "ready");
|
|
99
107
|
}
|
|
108
|
+
function cursorKey(watermark) {
|
|
109
|
+
return JSON.stringify([watermark.updatedAt, watermark.id]);
|
|
110
|
+
}
|
|
111
|
+
function hasUnusableContinuation({ lane, response, }) {
|
|
112
|
+
const next = response.nextWatermark;
|
|
113
|
+
if (!next)
|
|
114
|
+
return response.hasMore;
|
|
115
|
+
// Opaque positions can advance with an older business timestamp.
|
|
116
|
+
// A drained lane may echo its current position, but never an earlier one.
|
|
117
|
+
if (next.id === lane.watermark?.id &&
|
|
118
|
+
next.updatedAt === lane.watermark.updatedAt)
|
|
119
|
+
return response.hasMore;
|
|
120
|
+
return lane.continuationCursors?.has(cursorKey(next)) === true;
|
|
121
|
+
}
|
|
122
|
+
function queueNextPage({ lane, response }, skipWatermarkWrite, queueContinuationLane) {
|
|
123
|
+
if (response.hasMore && response.nextWatermark) {
|
|
124
|
+
const continuationCursors = lane.continuationCursors ?? new Set();
|
|
125
|
+
if (lane.watermark)
|
|
126
|
+
continuationCursors.add(cursorKey(lane.watermark));
|
|
127
|
+
continuationCursors.add(cursorKey(response.nextWatermark));
|
|
128
|
+
queueContinuationLane({
|
|
129
|
+
parentId: lane.parentId,
|
|
130
|
+
watermark: response.nextWatermark,
|
|
131
|
+
skipWatermarkWrite,
|
|
132
|
+
continuationCursors,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
async function checkpointPage(input) {
|
|
137
|
+
const { lane, response, syncLane } = input.fetchedPage;
|
|
138
|
+
// Only a drained chain can advance a reconnect checkpoint. Otherwise a
|
|
139
|
+
// cycle can alternate the durable cursor between successive attempts.
|
|
140
|
+
if (input.reconnect && response.hasMore)
|
|
141
|
+
return true;
|
|
142
|
+
const nextWatermark = response.nextWatermark ??
|
|
143
|
+
(lane.continuationCursors ? (lane.watermark ?? null) : null);
|
|
144
|
+
return markContainerParentLaneFetched({
|
|
145
|
+
isCurrent: input.isCurrent,
|
|
146
|
+
response: { ...response, nextWatermark },
|
|
147
|
+
state: input.state,
|
|
148
|
+
syncLane,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
100
151
|
async function applyContainerParentLanePage(input) {
|
|
101
152
|
const { childIdsByParentId, fetchedPage, host, queueContinuationLane, queueParentLane, seenContainerIds, state, } = input;
|
|
102
|
-
const { expectedContainerStates, expectedHydrationTombstones, lane, response,
|
|
153
|
+
const { expectedContainerStates, expectedHydrationTombstones, lane, response, } = fetchedPage;
|
|
103
154
|
let changedCount = 0;
|
|
104
155
|
if (input.isCurrent?.() === false) {
|
|
105
|
-
return { changedCount,
|
|
156
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
106
157
|
}
|
|
107
158
|
const remoteContainerItems = getApplicableRemoteContainerItems(response);
|
|
108
159
|
const tombstoneResult = await applyContainerTombstones({
|
|
@@ -114,11 +165,11 @@ async function applyContainerParentLanePage(input) {
|
|
|
114
165
|
state,
|
|
115
166
|
});
|
|
116
167
|
if (!tombstoneResult.current) {
|
|
117
|
-
return { changedCount,
|
|
168
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
118
169
|
}
|
|
119
170
|
changedCount += tombstoneResult.changedCount;
|
|
120
171
|
if (input.isCurrent?.() === false) {
|
|
121
|
-
return { changedCount,
|
|
172
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
122
173
|
}
|
|
123
174
|
if (tombstoneResult.changedCount > 0) {
|
|
124
175
|
// A live tombstone cascade may have orphaned documents (row 3); re-arm
|
|
@@ -131,6 +182,7 @@ async function applyContainerParentLanePage(input) {
|
|
|
131
182
|
// lane complete and its watermark advance; their children are never queued.
|
|
132
183
|
const isPaused = await loadPausedContainerFilter(state);
|
|
133
184
|
const appliedPage = await applyRemoteContainerPage({
|
|
185
|
+
reconnect: input.reconnect,
|
|
134
186
|
childIdsByParentId,
|
|
135
187
|
expectedContainerStates,
|
|
136
188
|
expectedHydrationTombstones,
|
|
@@ -144,35 +196,23 @@ async function applyContainerParentLanePage(input) {
|
|
|
144
196
|
state,
|
|
145
197
|
});
|
|
146
198
|
changedCount += appliedPage.changedCount;
|
|
147
|
-
|
|
148
|
-
// Keep this page retryable without discarding independent lanes, including
|
|
149
|
-
// children of roots first discovered here. Otherwise the root becomes known
|
|
150
|
-
// but its children are never fetched by subsequent root-only refreshes.
|
|
151
|
-
return { changedCount, complete: false, shouldStop: false };
|
|
152
|
-
}
|
|
199
|
+
const outcome = tombstoneResult.completed ? appliedPage.outcome : "retry";
|
|
153
200
|
if (input.isCurrent?.() === false) {
|
|
154
|
-
return { changedCount,
|
|
155
|
-
}
|
|
156
|
-
const didMarkFetched = await markContainerParentLaneFetched({
|
|
157
|
-
isCurrent: input.isCurrent,
|
|
158
|
-
response,
|
|
159
|
-
state,
|
|
160
|
-
syncLane,
|
|
161
|
-
});
|
|
162
|
-
if (!didMarkFetched) {
|
|
163
|
-
return { changedCount, complete: false, shouldStop: true };
|
|
164
|
-
}
|
|
165
|
-
if (!response.hasMore) {
|
|
166
|
-
return { changedCount, complete: true, shouldStop: false };
|
|
201
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
167
202
|
}
|
|
168
|
-
|
|
169
|
-
|
|
203
|
+
// A bad continuation invalidates the cursor, independently verified rows still apply.
|
|
204
|
+
if (hasUnusableContinuation(fetchedPage))
|
|
205
|
+
return { changedCount, outcome: "retry", shouldStop: false };
|
|
206
|
+
// A refused item leaves a gap in this lane. Later pages can still discover
|
|
207
|
+
// independent children, but none may move its durable cursor past the gap.
|
|
208
|
+
if (outcome !== "complete" && !input.reconnect)
|
|
209
|
+
return { changedCount, outcome, shouldStop: false };
|
|
210
|
+
const skipWatermarkWrite = lane.skipWatermarkWrite || outcome !== "complete";
|
|
211
|
+
if (!skipWatermarkWrite && !(await checkpointPage(input))) {
|
|
212
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
170
213
|
}
|
|
171
|
-
queueContinuationLane
|
|
172
|
-
|
|
173
|
-
watermark: response.nextWatermark,
|
|
174
|
-
});
|
|
175
|
-
return { changedCount, complete: true, shouldStop: false };
|
|
214
|
+
queueNextPage(fetchedPage, skipWatermarkWrite, queueContinuationLane);
|
|
215
|
+
return { changedCount, outcome, shouldStop: false };
|
|
176
216
|
}
|
|
177
217
|
function takeContainerParentLaneBatch(input) {
|
|
178
218
|
const { lanes, state } = input;
|
|
@@ -190,16 +230,17 @@ function takeContainerParentLaneBatch(input) {
|
|
|
190
230
|
async function applyContainerParentLaneBatch(input) {
|
|
191
231
|
const { childIdsByParentId, fetchedPages, host, lanes, queueParentLane, seenContainerIds, state, } = input;
|
|
192
232
|
let changedCount = 0;
|
|
193
|
-
let
|
|
233
|
+
let outcome = "complete";
|
|
194
234
|
for (const fetchedPage of fetchedPages) {
|
|
195
235
|
if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {
|
|
196
|
-
return { changedCount,
|
|
236
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
197
237
|
}
|
|
198
238
|
if (fetchedPage.lane.parentId !== null &&
|
|
199
239
|
!state.containersById.has(fetchedPage.lane.parentId)) {
|
|
200
240
|
continue;
|
|
201
241
|
}
|
|
202
242
|
const result = await applyContainerParentLanePage({
|
|
243
|
+
reconnect: input.reconnect,
|
|
203
244
|
childIdsByParentId,
|
|
204
245
|
fetchedPage,
|
|
205
246
|
host,
|
|
@@ -211,22 +252,22 @@ async function applyContainerParentLaneBatch(input) {
|
|
|
211
252
|
state,
|
|
212
253
|
});
|
|
213
254
|
changedCount += result.changedCount;
|
|
214
|
-
|
|
255
|
+
outcome = combineOutcomes(outcome, result.outcome);
|
|
215
256
|
if (result.shouldStop) {
|
|
216
|
-
return { changedCount,
|
|
257
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
217
258
|
}
|
|
218
259
|
}
|
|
219
|
-
return { changedCount,
|
|
260
|
+
return { changedCount, outcome, shouldStop: false };
|
|
220
261
|
}
|
|
221
262
|
export async function hydrateContainerParentLanes(input) {
|
|
222
263
|
const { childIdsByParentId, host, lanes, queueParentLane, seenContainerIds, state, } = input;
|
|
223
264
|
let changedCount = 0;
|
|
224
|
-
let
|
|
265
|
+
let outcome = "complete";
|
|
225
266
|
// One hydration pass is one policy operation: its pages share a discovery.
|
|
226
267
|
const policyOperation = createPrincipalPolicyOperation();
|
|
227
268
|
while (lanes.length > 0) {
|
|
228
269
|
if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {
|
|
229
|
-
return { changedCount,
|
|
270
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
230
271
|
}
|
|
231
272
|
const batch = takeContainerParentLaneBatch({ lanes, state });
|
|
232
273
|
if (batch.length === 0) {
|
|
@@ -234,16 +275,18 @@ export async function hydrateContainerParentLanes(input) {
|
|
|
234
275
|
}
|
|
235
276
|
const fetchedPages = await fetchContainerParentLaneBatch({
|
|
236
277
|
batch,
|
|
278
|
+
laneIdPrefix: input.reconnect?.laneIdPrefix,
|
|
237
279
|
isCurrent: input.isCurrent,
|
|
238
280
|
state,
|
|
239
281
|
});
|
|
240
282
|
if (!fetchedPages) {
|
|
241
|
-
return { changedCount,
|
|
283
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
242
284
|
}
|
|
243
285
|
if (input.isCurrent?.() === false) {
|
|
244
|
-
return { changedCount,
|
|
286
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
245
287
|
}
|
|
246
288
|
const result = await applyContainerParentLaneBatch({
|
|
289
|
+
reconnect: input.reconnect,
|
|
247
290
|
childIdsByParentId,
|
|
248
291
|
fetchedPages,
|
|
249
292
|
host,
|
|
@@ -255,11 +298,11 @@ export async function hydrateContainerParentLanes(input) {
|
|
|
255
298
|
state,
|
|
256
299
|
});
|
|
257
300
|
changedCount += result.changedCount;
|
|
258
|
-
|
|
301
|
+
outcome = combineOutcomes(outcome, result.outcome);
|
|
259
302
|
if (result.shouldStop) {
|
|
260
|
-
return { changedCount,
|
|
303
|
+
return { changedCount, outcome: "retry", shouldStop: true };
|
|
261
304
|
}
|
|
262
305
|
}
|
|
263
|
-
return { changedCount,
|
|
306
|
+
return { changedCount, outcome, shouldStop: false };
|
|
264
307
|
}
|
|
265
308
|
//# sourceMappingURL=remoteContainerPageHydration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteContainerPageHydration.js","sourceRoot":"","sources":["remoteContainerPageHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,GAE/B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,qCAAqC,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AAWjC,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,gDAAgD,EAChD,kDAAkD,EAClD,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAEhC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAOjD,2EAA2E;AAC3E,+DAA+D;AAC/D,SAAS,mBAAmB,CAC1B,KAGC,EACD,SAAwC;IAExC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED,6EAA6E;AAC7E,SAAS,kBAAkB,CACzB,KAAoC,EACpC,uBAAoE,EACpE,WAAmB;IAEnB,OAAO,gCAAgC,CAAC;QACtC,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;QACnD,mBAAmB,EAAE,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N,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;QACD,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;YAClC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAAC;YACjD,kBAAkB;YAClB,YAAY;YACZ,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK;YACL,eAAe;YACf,eAAe;YACf,gBAAgB;YAChB,KAAK;SACN,CAAC,CAAC;QACH,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;QACpC,QAAQ,KAAK,MAAM,CAAC,QAAQ,CAAC;QAE7B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACvD,CAAC","sourcesContent":["import {\n createPrincipalPolicyOperation,\n type PrincipalPolicyOperation,\n} from \"../../../principals/principalPolicyService\";\nimport { prefetchDestinationProjections } from \"../destination/destinationPrefetch\";\nimport { cachedDestinationRole } from \"../destination/destinationRoleCache\";\nimport { markContainerParentLaneFetched } from \"../lanes/laneFetchMarkers\";\nimport { fetchContainerParentLaneBatch } from \"../lanes/parentLaneFetch\";\nimport { cacheRemoteContainerPrincipalPolicies } from \"../principalPolicyCache\";\nimport {\n applyContainerTombstones,\n getApplicableRemoteContainerItems,\n} from \"../tombstoneApplication\";\nimport type {\n ContainerChildIndex,\n ContainerParentHydrationLane,\n ExpectedContainerState,\n FetchedContainerParentLanePage,\n ListedRemoteContainerPageItem,\n QueueContainerParentLane,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { containerStateMatchesFingerprint } from \"./containerStateFingerprint\";\nimport { loadPausedContainerFilter } from \"./organizationSyncPauseFilter\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainerState\";\n\nconst CONTAINER_PARENT_HYDRATION_CONCURRENCY = 4;\n\ninterface HydrationProgress {\n changedCount: number;\n complete: boolean;\n shouldStop: boolean;\n}\n// Re-checked inside the commit: a pause from another device can land after\n// the page was filtered, and its cleanup may already have run.\nfunction currentUnlessPaused(\n input: {\n isCurrent?: (() => boolean) | undefined;\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n },\n container: ListedRemoteContainerPageItem,\n): () => boolean {\n return () => input.isCurrent?.() !== false && !input.isPaused(container);\n}\n\n/** The local state still matches the fingerprint the listing was read at. */\nfunction matchesListedState(\n state: RemoteContainerHydrationState,\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>,\n containerId: string,\n): boolean {\n return containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint: expectedContainerStates.get(containerId)?.fingerprint,\n });\n}\n\nasync function applyRemoteContainerPage(input: {\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: FetchedContainerParentLanePage[\"expectedHydrationTombstones\"];\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n /** Live pause check; a pause arriving mid-page stops the commit. */\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n items: ReadonlyArray<ListedRemoteContainerPageItem>;\n /** The hydration pass's token: its pages share one directory discovery. */\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; completed: boolean }> {\n const {\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n items,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let hydratedCount = 0;\n let pageCompleted = true;\n await cacheRemoteContainerPrincipalPolicies({\n cacheReferencedPrincipalPolicies:\n state.runtime.principalPolicies.createWarmer({\n operation: input.policyOperation,\n }),\n remoteContainers: items,\n stillCurrent: input.isCurrent,\n });\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, completed: false };\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: items,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: items,\n state,\n }),\n ]);\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, completed: false };\n }\n const prefetchedProjections = await prefetchDestinationProjections({\n containers: items.filter(\n (item) =>\n !seenContainerIds.has(item.id) &&\n !state.containersById.has(item.id) &&\n !expectedHydrationTombstones.get(item.id) &&\n !cachedDestinationRole(state.runtime.infra.execSql, item),\n ),\n isCurrent: input.isCurrent,\n runtime: state.runtime,\n });\n for (const container of items) {\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, completed: false };\n }\n if (seenContainerIds.has(container.id)) {\n queueParentLane(container.id);\n continue;\n }\n if (!matchesListedState(state, expectedContainerStates, container.id)) {\n pageCompleted = false;\n continue;\n }\n const upserted = await upsertIsolatedRemoteContainerState({\n childIdsByParentId,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host,\n isCurrent: currentUnlessPaused(input, container),\n expectedHydrationTombstone:\n expectedHydrationTombstones.get(container.id) ?? null,\n prefetchedProjection: prefetchedProjections.get(container.id),\n remoteContainer: container,\n state,\n });\n if (!upserted) {\n pageCompleted = false;\n continue;\n }\n seenContainerIds.add(container.id);\n hydratedCount += 1;\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, completed: false };\n }\n queueParentLane(container.id);\n }\n\n return { changedCount: hydratedCount, completed: pageCompleted };\n}\n\nexport function canHydrateRemoteContainers(\n state: RemoteContainerHydrationState,\n): boolean {\n return (\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online &&\n state.runtime.infra.dbStatus === \"ready\"\n );\n}\n\nasync function applyContainerParentLanePage(input: {\n childIdsByParentId: ContainerChildIndex;\n fetchedPage: FetchedContainerParentLanePage;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n policyOperation: PrincipalPolicyOperation;\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPage,\n host,\n queueContinuationLane,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n const {\n expectedContainerStates,\n expectedHydrationTombstones,\n lane,\n response,\n syncLane,\n } = fetchedPage;\n let changedCount = 0;\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const remoteContainerItems = getApplicableRemoteContainerItems(response);\n const tombstoneResult = await applyContainerTombstones({\n childIdsByParentId,\n expectedContainerStates,\n isCurrent: input.isCurrent,\n remoteContainerItems,\n response,\n state,\n });\n if (!tombstoneResult.current) {\n return { changedCount, complete: false, shouldStop: true };\n }\n changedCount += tombstoneResult.changedCount;\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (tombstoneResult.changedCount > 0) {\n // A live tombstone cascade may have orphaned documents (row 3); re-arm\n // document priming so their null-scoped passes run now rather than on\n // the next startup.\n host.requestDocumentPriming?.();\n }\n\n // A paused organization's containers stay as the device last saw them.\n // Skipping them here, after tombstones saw the full page, still lets the\n // lane complete and its watermark advance; their children are never queued.\n const isPaused = await loadPausedContainerFilter(state);\n const appliedPage = await applyRemoteContainerPage({\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n isCurrent: input.isCurrent,\n isPaused,\n items: remoteContainerItems.filter((item) => !isPaused(item)),\n policyOperation: input.policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += appliedPage.changedCount;\n if (!tombstoneResult.completed || !appliedPage.completed) {\n // Keep this page retryable without discarding independent lanes, including\n // children of roots first discovered here. Otherwise the root becomes known\n // but its children are never fetched by subsequent root-only refreshes.\n return { changedCount, complete: false, shouldStop: false };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const didMarkFetched = await markContainerParentLaneFetched({\n isCurrent: input.isCurrent,\n response,\n state,\n syncLane,\n });\n if (!didMarkFetched) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n if (!response.hasMore) {\n return { changedCount, complete: true, shouldStop: false };\n }\n if (!response.nextWatermark) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n queueContinuationLane({\n parentId: lane.parentId,\n watermark: response.nextWatermark,\n });\n return { changedCount, complete: true, shouldStop: false };\n}\n\nfunction takeContainerParentLaneBatch(input: {\n lanes: ContainerParentHydrationLane[];\n state: RemoteContainerHydrationState;\n}): ContainerParentHydrationLane[] {\n const { lanes, state } = input;\n const batch: ContainerParentHydrationLane[] = [];\n\n while (\n lanes.length > 0 &&\n batch.length < CONTAINER_PARENT_HYDRATION_CONCURRENCY\n ) {\n const lane = lanes.shift();\n if (\n lane &&\n (lane.parentId === null || state.containersById.has(lane.parentId))\n ) {\n batch.push(lane);\n }\n }\n\n return batch;\n}\n\nasync function applyContainerParentLaneBatch(input: {\n childIdsByParentId: ContainerChildIndex;\n fetchedPages: ReadonlyArray<FetchedContainerParentLanePage>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPages,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let complete = true;\n\n for (const fetchedPage of fetchedPages) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (\n fetchedPage.lane.parentId !== null &&\n !state.containersById.has(fetchedPage.lane.parentId)\n ) {\n continue;\n }\n\n const result = await applyContainerParentLanePage({\n childIdsByParentId,\n fetchedPage,\n host,\n isCurrent: input.isCurrent,\n policyOperation: input.policyOperation,\n queueContinuationLane: (lane) => lanes.push(lane),\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n complete &&= result.complete;\n\n if (result.shouldStop) {\n return { changedCount, complete: false, shouldStop: true };\n }\n }\n\n return { changedCount, complete, shouldStop: false };\n}\n\nexport async function hydrateContainerParentLanes(input: {\n childIdsByParentId: ContainerChildIndex;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let complete = true;\n // One hydration pass is one policy operation: its pages share a discovery.\n const policyOperation = createPrincipalPolicyOperation();\n\n while (lanes.length > 0) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const batch = takeContainerParentLaneBatch({ lanes, state });\n if (batch.length === 0) {\n continue;\n }\n\n const fetchedPages = await fetchContainerParentLaneBatch({\n batch,\n isCurrent: input.isCurrent,\n state,\n });\n if (!fetchedPages) {\n return { changedCount, complete: false, shouldStop: true };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, complete: false, shouldStop: true };\n }\n\n const result = await applyContainerParentLaneBatch({\n childIdsByParentId,\n fetchedPages,\n host,\n isCurrent: input.isCurrent,\n lanes,\n policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n complete &&= result.complete;\n\n if (result.shouldStop) {\n return { changedCount, complete: false, shouldStop: true };\n }\n }\n\n return { changedCount, complete, shouldStop: false };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"remoteContainerPageHydration.js","sourceRoot":"","sources":["remoteContainerPageHydration.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,8BAA8B,GAE/B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,wBAAwB,EACxB,iCAAiC,GAClC,MAAM,yBAAyB,CAAC;AAajC,OAAO,EAAE,gCAAgC,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,gDAAgD,EAChD,kDAAkD,EAClD,kCAAkC,GACnC,MAAM,wBAAwB,CAAC;AAEhC,MAAM,sCAAsC,GAAG,CAAC,CAAC;AAOjD,qFAAqF;AACrF,SAAS,eAAe,CACtB,CAAmB,EACnB,CAAmB;IAEnB,IAAI,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,OAAO;QAAE,OAAO,OAAO,CAAC;IACnD,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACzD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,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,YAAY,EAAE,CAAC;YAClB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;QACD,IAAI,KAAK,CAAC,SAAS,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;YAClC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAAC;YACjD,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,kBAAkB;YAClB,YAAY;YACZ,IAAI;YACJ,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,KAAK;YACL,eAAe;YACf,eAAe;YACf,gBAAgB;YAChB,KAAK;SACN,CAAC,CAAC;QACH,YAAY,IAAI,MAAM,CAAC,YAAY,CAAC;QACpC,OAAO,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnD,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AACtD,CAAC","sourcesContent":["import {\n createPrincipalPolicyOperation,\n type PrincipalPolicyOperation,\n} from \"../../../principals/principalPolicyService\";\nimport { prefetchDestinationProjections } from \"../destination/destinationPrefetch\";\nimport { cachedDestinationRole } from \"../destination/destinationRoleCache\";\nimport { markContainerParentLaneFetched } from \"../lanes/laneFetchMarkers\";\nimport { fetchContainerParentLaneBatch } from \"../lanes/parentLaneFetch\";\nimport { warmListedContainerPolicies } from \"../principalPolicyCache\";\nimport {\n applyContainerTombstones,\n getApplicableRemoteContainerItems,\n} from \"../tombstoneApplication\";\nimport type {\n ContainerChildIndex,\n ContainerParentHydrationLane,\n ExpectedContainerState,\n FetchedContainerParentLanePage,\n HydrationOutcome,\n ListedRemoteContainerPageItem,\n QueueContainerParentLane,\n ReconnectPages,\n RemoteContainerHydrationHost,\n RemoteContainerHydrationState,\n} from \"../types\";\nimport { containerStateMatchesFingerprint } from \"./containerStateFingerprint\";\nimport { loadPausedContainerFilter } from \"./organizationSyncPauseFilter\";\nimport {\n listRemoteContainerIdsWithPendingMetadataUpdates,\n listRemoteContainerIdsWithPendingStructuralIntents,\n upsertIsolatedRemoteContainerState,\n} from \"./remoteContainerState\";\n\nconst CONTAINER_PARENT_HYDRATION_CONCURRENCY = 4;\n\ninterface HydrationProgress {\n changedCount: number;\n outcome: HydrationOutcome;\n shouldStop: boolean;\n}\n/** A retryable lane takes precedence over a refused proof elsewhere in the crawl. */\nfunction combineOutcomes(\n a: HydrationOutcome,\n b: HydrationOutcome,\n): HydrationOutcome {\n if (a === \"retry\" || b === \"retry\") return \"retry\";\n if (a === \"refused\" || b === \"refused\") return \"refused\";\n return \"complete\";\n}\n\n// Re-checked inside the commit: a pause from another device can land after\n// the page was filtered, and its cleanup may already have run.\nfunction currentUnlessPaused(\n input: {\n isCurrent?: (() => boolean) | undefined;\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n },\n container: ListedRemoteContainerPageItem,\n): () => boolean {\n return () => input.isCurrent?.() !== false && !input.isPaused(container);\n}\n\n/** The local state still matches the fingerprint the listing was read at. */\nfunction matchesListedState(\n state: RemoteContainerHydrationState,\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>,\n containerId: string,\n): boolean {\n return containerStateMatchesFingerprint({\n currentState: state.containersById.get(containerId),\n expectedFingerprint: expectedContainerStates.get(containerId)?.fingerprint,\n });\n}\n\nasync function applyRemoteContainerPage(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n expectedContainerStates: ReadonlyMap<string, ExpectedContainerState>;\n expectedHydrationTombstones: FetchedContainerParentLanePage[\"expectedHydrationTombstones\"];\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n /** Live pause check; a pause arriving mid-page stops the commit. */\n isPaused: (container: ListedRemoteContainerPageItem) => boolean;\n items: ReadonlyArray<ListedRemoteContainerPageItem>;\n /** The hydration pass's token: its pages share one directory discovery. */\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<{ changedCount: number; outcome: HydrationOutcome }> {\n const {\n expectedContainerStates,\n expectedHydrationTombstones,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let hydratedCount = 0;\n const policies = await warmListedContainerPolicies(\n input.items,\n state.runtime.principalPolicies.createWarmer({\n operation: input.policyOperation,\n }),\n input.reconnect?.recordManualError,\n input.isCurrent,\n );\n const { items } = policies;\n let outcome: HydrationOutcome = policies.outcome;\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, outcome: \"retry\" };\n }\n const [\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n ] = await Promise.all([\n listRemoteContainerIdsWithPendingMetadataUpdates({\n remoteContainers: items,\n state,\n }),\n listRemoteContainerIdsWithPendingStructuralIntents({\n remoteContainers: items,\n state,\n }),\n ]);\n if (input.isCurrent?.() === false) {\n return { changedCount: 0, outcome: \"retry\" };\n }\n const prefetchedProjections = await prefetchDestinationProjections({\n containers: items.filter(\n (item) =>\n !seenContainerIds.has(item.id) &&\n !state.containersById.has(item.id) &&\n !expectedHydrationTombstones.get(item.id) &&\n !cachedDestinationRole(state.runtime.infra.execSql, item),\n ),\n isCurrent: input.isCurrent,\n runtime: state.runtime,\n });\n for (const container of items) {\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, outcome: \"retry\" };\n }\n if (seenContainerIds.has(container.id)) {\n queueParentLane(container.id);\n continue;\n }\n if (!matchesListedState(state, expectedContainerStates, container.id)) {\n outcome = \"retry\";\n continue;\n }\n let failure: HydrationOutcome = \"retry\";\n const upserted = await upsertIsolatedRemoteContainerState(\n {\n childIdsByParentId: input.childIdsByParentId,\n containerIdsWithPendingMetadataUpdates,\n containerIdsWithPendingStructuralIntents,\n host: input.host,\n isCurrent: currentUnlessPaused(input, container),\n expectedHydrationTombstone:\n expectedHydrationTombstones.get(container.id) ?? null,\n prefetchedProjection: prefetchedProjections.get(container.id),\n remoteContainer: container,\n state,\n },\n (outcome) => {\n failure = outcome;\n },\n input.reconnect?.recordManualError,\n );\n if (!upserted) {\n outcome = combineOutcomes(outcome, failure);\n continue;\n }\n seenContainerIds.add(container.id);\n hydratedCount += 1;\n if (input.isCurrent?.() === false) {\n return { changedCount: hydratedCount, outcome: \"retry\" };\n }\n queueParentLane(container.id);\n }\n\n return { changedCount: hydratedCount, outcome };\n}\n\nexport function canHydrateRemoteContainers(\n state: RemoteContainerHydrationState,\n): boolean {\n return (\n state.runtime.auth.isAuthenticated &&\n state.runtime.state.online &&\n state.runtime.infra.dbStatus === \"ready\"\n );\n}\n\nfunction cursorKey(\n watermark: NonNullable<ContainerParentHydrationLane[\"watermark\"]>,\n): string {\n return JSON.stringify([watermark.updatedAt, watermark.id]);\n}\n\nfunction hasUnusableContinuation({\n lane,\n response,\n}: FetchedContainerParentLanePage): boolean {\n const next = response.nextWatermark;\n if (!next) return response.hasMore;\n // Opaque positions can advance with an older business timestamp.\n // A drained lane may echo its current position, but never an earlier one.\n if (\n next.id === lane.watermark?.id &&\n next.updatedAt === lane.watermark.updatedAt\n )\n return response.hasMore;\n return lane.continuationCursors?.has(cursorKey(next)) === true;\n}\n\nfunction queueNextPage(\n { lane, response }: FetchedContainerParentLanePage,\n skipWatermarkWrite: boolean,\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void,\n): void {\n if (response.hasMore && response.nextWatermark) {\n const continuationCursors = lane.continuationCursors ?? new Set<string>();\n if (lane.watermark) continuationCursors.add(cursorKey(lane.watermark));\n continuationCursors.add(cursorKey(response.nextWatermark));\n queueContinuationLane({\n parentId: lane.parentId,\n watermark: response.nextWatermark,\n skipWatermarkWrite,\n continuationCursors,\n });\n }\n}\n\nasync function checkpointPage(input: {\n reconnect?: ReconnectPages | undefined;\n fetchedPage: FetchedContainerParentLanePage;\n isCurrent?: (() => boolean) | undefined;\n state: RemoteContainerHydrationState;\n}): Promise<boolean> {\n const { lane, response, syncLane } = input.fetchedPage;\n // Only a drained chain can advance a reconnect checkpoint. Otherwise a\n // cycle can alternate the durable cursor between successive attempts.\n if (input.reconnect && response.hasMore) return true;\n const nextWatermark =\n response.nextWatermark ??\n (lane.continuationCursors ? (lane.watermark ?? null) : null);\n return markContainerParentLaneFetched({\n isCurrent: input.isCurrent,\n response: { ...response, nextWatermark },\n state: input.state,\n syncLane,\n });\n}\n\nasync function applyContainerParentLanePage(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n fetchedPage: FetchedContainerParentLanePage;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n policyOperation: PrincipalPolicyOperation;\n queueContinuationLane: (lane: ContainerParentHydrationLane) => void;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPage,\n host,\n queueContinuationLane,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n const {\n expectedContainerStates,\n expectedHydrationTombstones,\n lane,\n response,\n } = fetchedPage;\n let changedCount = 0;\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n const remoteContainerItems = getApplicableRemoteContainerItems(response);\n const tombstoneResult = await applyContainerTombstones({\n childIdsByParentId,\n expectedContainerStates,\n isCurrent: input.isCurrent,\n remoteContainerItems,\n response,\n state,\n });\n if (!tombstoneResult.current) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n changedCount += tombstoneResult.changedCount;\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (tombstoneResult.changedCount > 0) {\n // A live tombstone cascade may have orphaned documents (row 3); re-arm\n // document priming so their null-scoped passes run now rather than on\n // the next startup.\n host.requestDocumentPriming?.();\n }\n\n // A paused organization's containers stay as the device last saw them.\n // Skipping them here, after tombstones saw the full page, still lets the\n // lane complete and its watermark advance; their children are never queued.\n const isPaused = await loadPausedContainerFilter(state);\n const appliedPage = await applyRemoteContainerPage({\n reconnect: input.reconnect,\n childIdsByParentId,\n expectedContainerStates,\n expectedHydrationTombstones,\n host,\n isCurrent: input.isCurrent,\n isPaused,\n items: remoteContainerItems.filter((item) => !isPaused(item)),\n policyOperation: input.policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += appliedPage.changedCount;\n const outcome = tombstoneResult.completed ? appliedPage.outcome : \"retry\";\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n // A bad continuation invalidates the cursor, independently verified rows still apply.\n if (hasUnusableContinuation(fetchedPage))\n return { changedCount, outcome: \"retry\", shouldStop: false };\n // A refused item leaves a gap in this lane. Later pages can still discover\n // independent children, but none may move its durable cursor past the gap.\n if (outcome !== \"complete\" && !input.reconnect)\n return { changedCount, outcome, shouldStop: false };\n const skipWatermarkWrite = lane.skipWatermarkWrite || outcome !== \"complete\";\n if (!skipWatermarkWrite && !(await checkpointPage(input))) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n queueNextPage(fetchedPage, skipWatermarkWrite, queueContinuationLane);\n return { changedCount, outcome, shouldStop: false };\n}\n\nfunction takeContainerParentLaneBatch(input: {\n lanes: ContainerParentHydrationLane[];\n state: RemoteContainerHydrationState;\n}): ContainerParentHydrationLane[] {\n const { lanes, state } = input;\n const batch: ContainerParentHydrationLane[] = [];\n\n while (\n lanes.length > 0 &&\n batch.length < CONTAINER_PARENT_HYDRATION_CONCURRENCY\n ) {\n const lane = lanes.shift();\n if (\n lane &&\n (lane.parentId === null || state.containersById.has(lane.parentId))\n ) {\n batch.push(lane);\n }\n }\n\n return batch;\n}\n\nasync function applyContainerParentLaneBatch(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n fetchedPages: ReadonlyArray<FetchedContainerParentLanePage>;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n policyOperation: PrincipalPolicyOperation;\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n fetchedPages,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let outcome: HydrationOutcome = \"complete\";\n\n for (const fetchedPage of fetchedPages) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (\n fetchedPage.lane.parentId !== null &&\n !state.containersById.has(fetchedPage.lane.parentId)\n ) {\n continue;\n }\n\n const result = await applyContainerParentLanePage({\n reconnect: input.reconnect,\n childIdsByParentId,\n fetchedPage,\n host,\n isCurrent: input.isCurrent,\n policyOperation: input.policyOperation,\n queueContinuationLane: (lane) => lanes.push(lane),\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n outcome = combineOutcomes(outcome, result.outcome);\n\n if (result.shouldStop) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n }\n\n return { changedCount, outcome, shouldStop: false };\n}\n\nexport async function hydrateContainerParentLanes(input: {\n reconnect?: ReconnectPages | undefined;\n childIdsByParentId: ContainerChildIndex;\n host: RemoteContainerHydrationHost;\n isCurrent?: (() => boolean) | undefined;\n lanes: ContainerParentHydrationLane[];\n queueParentLane: QueueContainerParentLane;\n seenContainerIds: Set<string>;\n state: RemoteContainerHydrationState;\n}): Promise<HydrationProgress> {\n const {\n childIdsByParentId,\n host,\n lanes,\n queueParentLane,\n seenContainerIds,\n state,\n } = input;\n let changedCount = 0;\n let outcome: HydrationOutcome = \"complete\";\n // One hydration pass is one policy operation: its pages share a discovery.\n const policyOperation = createPrincipalPolicyOperation();\n\n while (lanes.length > 0) {\n if (!canHydrateRemoteContainers(state) || input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n const batch = takeContainerParentLaneBatch({ lanes, state });\n if (batch.length === 0) {\n continue;\n }\n\n const fetchedPages = await fetchContainerParentLaneBatch({\n batch,\n laneIdPrefix: input.reconnect?.laneIdPrefix,\n isCurrent: input.isCurrent,\n state,\n });\n if (!fetchedPages) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n if (input.isCurrent?.() === false) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n\n const result = await applyContainerParentLaneBatch({\n reconnect: input.reconnect,\n childIdsByParentId,\n fetchedPages,\n host,\n isCurrent: input.isCurrent,\n lanes,\n policyOperation,\n queueParentLane,\n seenContainerIds,\n state,\n });\n changedCount += result.changedCount;\n outcome = combineOutcomes(outcome, result.outcome);\n\n if (result.shouldStop) {\n return { changedCount, outcome: \"retry\", shouldStop: true };\n }\n }\n\n return { changedCount, outcome, shouldStop: false };\n}\n"]}
|
package/workflows/container-contents/remoteHydration/remoteContainers/remoteContainerState.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { decodeVersionVector, encodeVersionVector, satisfiesVersionVector, } from "../../../../internal/loro/index.js";
|
|
2
2
|
import { isProjectionVerificationCancelledError } from "../../../../data/keyingProjectionVerification/types.js";
|
|
3
3
|
import { heldContainerBinding, listingRepeatsHeldOrdinaryBinding, } from "../../../../data/persistence/container-contents/containerBinding.js";
|
|
4
|
+
import { ProjectionDependencyUnavailableError } from "../../../../data/shared/dependencyUnavailable.js";
|
|
4
5
|
import { isKeyingVerificationError, runWithSecurityIncidentReporting, } from "../../../../data/shared/securityIncidents.js";
|
|
5
6
|
import { invalidateContainerProjectionCaches } from "../../container-state/projectionCache.js";
|
|
6
7
|
import { installContainerMetadataRecord } from "../../metadata/metadataPersistence.js";
|
|
@@ -274,15 +275,24 @@ export async function upsertRemoteContainerState(input) {
|
|
|
274
275
|
* was already reported; returning no state leaves the item unapplied without
|
|
275
276
|
* blocking independent folders.
|
|
276
277
|
*/
|
|
277
|
-
export async function upsertIsolatedRemoteContainerState(input) {
|
|
278
|
+
export async function upsertIsolatedRemoteContainerState(input, recordIncompleteItem, recordUnavailable) {
|
|
278
279
|
try {
|
|
279
280
|
return await upsertRemoteContainerState(input);
|
|
280
281
|
}
|
|
281
282
|
catch (error) {
|
|
282
|
-
if (
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
283
|
+
if (isKeyingVerificationError(error)) {
|
|
284
|
+
recordIncompleteItem?.("refused");
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
if (isProjectionVerificationCancelledError(error))
|
|
288
|
+
return null;
|
|
289
|
+
if (error instanceof ProjectionDependencyUnavailableError &&
|
|
290
|
+
recordUnavailable) {
|
|
291
|
+
recordUnavailable(error);
|
|
292
|
+
recordIncompleteItem?.("retry");
|
|
293
|
+
return null;
|
|
294
|
+
}
|
|
295
|
+
throw error;
|
|
286
296
|
}
|
|
287
297
|
}
|
|
288
298
|
function persistVerifiedRemoteContainer(input) {
|