@fluidframework/container-runtime 2.82.0 → 2.83.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/CHANGELOG.md +4 -0
- package/container-runtime.test-files.tar +0 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/runtimeLayerCompatState.d.ts +1 -1
- package/dist/runtimeLayerCompatState.d.ts.map +1 -1
- package/dist/runtimeLayerCompatState.js +11 -6
- package/dist/runtimeLayerCompatState.js.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summarizer.d.ts.map +1 -1
- package/dist/summary/summaryDelayLoadedModule/summarizer.js +39 -3
- package/dist/summary/summaryDelayLoadedModule/summarizer.js.map +1 -1
- package/dist/summary/summaryManager.d.ts +2 -0
- package/dist/summary/summaryManager.d.ts.map +1 -1
- package/dist/summary/summaryManager.js +34 -7
- package/dist/summary/summaryManager.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/runtimeLayerCompatState.d.ts +1 -1
- package/lib/runtimeLayerCompatState.d.ts.map +1 -1
- package/lib/runtimeLayerCompatState.js +12 -7
- package/lib/runtimeLayerCompatState.js.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summarizer.d.ts.map +1 -1
- package/lib/summary/summaryDelayLoadedModule/summarizer.js +40 -4
- package/lib/summary/summaryDelayLoadedModule/summarizer.js.map +1 -1
- package/lib/summary/summaryManager.d.ts +2 -0
- package/lib/summary/summaryManager.d.ts.map +1 -1
- package/lib/summary/summaryManager.js +34 -7
- package/lib/summary/summaryManager.js.map +1 -1
- package/package.json +20 -20
- package/src/packageVersion.ts +1 -1
- package/src/runtimeLayerCompatState.ts +18 -6
- package/src/summary/summaryDelayLoadedModule/summarizer.ts +48 -5
- package/src/summary/summaryManager.ts +39 -8
- package/api-extractor-lint.json +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeLayerCompatState.d.ts","sourceRoot":"","sources":["../src/runtimeLayerCompatState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"runtimeLayerCompatState.d.ts","sourceRoot":"","sources":["../src/runtimeLayerCompatState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGN,KAAK,mBAAmB,EACxB,KAAK,+BAA+B,EACpC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAKrF,OAAO,EAEN,KAAK,iBAAiB,EACtB,MAAM,0CAA0C,CAAC;AAIlD;;GAEG;AACH,eAAO,MAAM,6CAA6C,sEACU,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,wBAAwB;IACpC;;OAEG;;IAEH;;OAEG;;CAEM,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,mBAM3C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mCAAmC,EAAE,+BAejD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gCAAgC,EAAE,mBAM9C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,sCAAsC,EAAE,+BAgBpD,CAAC;AAEF;;;GAGG;AACH,wBAAgB,2BAA2B,CAC1C,kCAAkC,EAAE,mBAAmB,GAAG,SAAS,EACnE,SAAS,EAAE,CAAC,KAAK,CAAC,EAAE,uBAAuB,KAAK,IAAI,EACpD,EAAE,EAAE,iBAAiB,GACnB,IAAI,CAmBN;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC7C,qCAAqC,EAAE,mBAAmB,GAAG,SAAS,EACtE,SAAS,EAAE,MAAM,IAAI,EACrB,EAAE,EAAE,iBAAiB,GACnB,IAAI,CAUN"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { generation, } from "@fluid-internal/client-utils";
|
|
5
|
+
import { generation, LayerCompatibilityPolicyWindowMonths, } from "@fluid-internal/client-utils";
|
|
6
6
|
import { encodeHandlesInContainerRuntime, notifiesReadOnlyState, } from "@fluidframework/runtime-definitions/internal";
|
|
7
7
|
import { validateLayerCompatibility, } from "@fluidframework/telemetry-utils/internal";
|
|
8
8
|
import { pkgVersion } from "./packageVersion.js";
|
|
@@ -41,10 +41,12 @@ export const runtimeCompatDetailsForLoader = {
|
|
|
41
41
|
*/
|
|
42
42
|
export const loaderSupportRequirementsForRuntime = {
|
|
43
43
|
/**
|
|
44
|
-
* Minimum generation that Loader must be at to be compatible with Runtime.
|
|
45
|
-
*
|
|
44
|
+
* Minimum generation that Loader must be at to be compatible with this Runtime. This is calculated
|
|
45
|
+
* based on the LayerCompatibilityPolicyWindowMonths.RuntimeLoader value which defines how many months old can
|
|
46
|
+
* the Loader layer be compared to the Runtime layer for them to still be considered compatible.
|
|
47
|
+
* The minimum valid generation value is 0.
|
|
46
48
|
*/
|
|
47
|
-
minSupportedGeneration: 0,
|
|
49
|
+
minSupportedGeneration: Math.max(0, runtimeCoreCompatDetails.generation - LayerCompatibilityPolicyWindowMonths.RuntimeLoader),
|
|
48
50
|
/**
|
|
49
51
|
* The features that the Loader must support to be compatible with Runtime.
|
|
50
52
|
*/
|
|
@@ -67,10 +69,13 @@ export const runtimeCompatDetailsForDataStore = {
|
|
|
67
69
|
*/
|
|
68
70
|
export const dataStoreSupportRequirementsForRuntime = {
|
|
69
71
|
/**
|
|
70
|
-
* Minimum generation that DataStore must be at to be compatible with Runtime.
|
|
71
|
-
*
|
|
72
|
+
* Minimum generation that DataStore must be at to be compatible with this Runtime. This is calculated
|
|
73
|
+
* based on the LayerCompatibilityPolicyWindowMonths.RuntimeDataStore value which defines how many months old can
|
|
74
|
+
* the DataStore layer be compared to the Runtime layer for them to still be considered compatible.
|
|
75
|
+
* The minimum valid generation value is 0.
|
|
72
76
|
*/
|
|
73
|
-
minSupportedGeneration: 0,
|
|
77
|
+
minSupportedGeneration: Math.max(0, runtimeCoreCompatDetails.generation -
|
|
78
|
+
LayerCompatibilityPolicyWindowMonths.RuntimeDataStore),
|
|
74
79
|
/**
|
|
75
80
|
* The features that the DataStore must support to be compatible with Runtime.
|
|
76
81
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeLayerCompatState.js","sourceRoot":"","sources":["../src/runtimeLayerCompatState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,UAAU,
|
|
1
|
+
{"version":3,"file":"runtimeLayerCompatState.js","sourceRoot":"","sources":["../src/runtimeLayerCompatState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,UAAU,EACV,oCAAoC,GAGpC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACN,+BAA+B,EAC/B,qBAAqB,GACrB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,0BAA0B,GAE1B,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,6CAA6C,GACzD,mEAAmE,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC;;OAEG;IACH,UAAU;IACV;;OAEG;IACH,UAAU;CACD,CAAC;AAEX;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAwB;IACjE,GAAG,wBAAwB;IAC3B;;OAEG;IACH,iBAAiB,EAAE,IAAI,GAAG,EAAU;CACpC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAoC;IACnF;;;;;OAKG;IACH,sBAAsB,EAAE,IAAI,CAAC,GAAG,CAC/B,CAAC,EACD,wBAAwB,CAAC,UAAU,GAAG,oCAAoC,CAAC,aAAa,CACxF;IACD;;OAEG;IACH,gBAAgB,EAAE,EAAE;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAwB;IACpE,GAAG,wBAAwB;IAC3B;;OAEG;IACH,iBAAiB,EAAE,IAAI,GAAG,CAAS,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,CAAC;CAC5F,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAoC;IACtF;;;;;OAKG;IACH,sBAAsB,EAAE,IAAI,CAAC,GAAG,CAC/B,CAAC,EACD,wBAAwB,CAAC,UAAU;QAClC,oCAAoC,CAAC,gBAAgB,CACtD;IACD;;OAEG;IACH,gBAAgB,EAAE,EAAE;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAC1C,kCAAmE,EACnE,SAAoD,EACpD,EAAqB;IAErB,uGAAuG;IACvG,wEAAwE;IACxE,8DAA8D;IAC9D,8EAA8E;IAC9E,MAAM,0CAA0C,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CACtE,6CAA6C,CAC7C,CAAC;IAEF,0BAA0B,CACzB,SAAS,EACT,QAAQ,EACR,6BAA6B,EAC7B,mCAAmC,EACnC,kCAAkC,EAClC,SAAS,EACT,EAAE,EACF,0CAA0C,KAAK,IAAI,CAAC,8BAA8B,CAClF,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC7C,qCAAsE,EACtE,SAAqB,EACrB,EAAqB;IAErB,0BAA0B,CACzB,SAAS,EACT,WAAW,EACX,gCAAgC,EAChC,sCAAsC,EACtC,qCAAqC,EACrC,SAAS,EACT,EAAE,CACF,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tgeneration,\n\tLayerCompatibilityPolicyWindowMonths,\n\ttype ILayerCompatDetails,\n\ttype ILayerCompatSupportRequirements,\n} from \"@fluid-internal/client-utils\";\nimport type { ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tencodeHandlesInContainerRuntime,\n\tnotifiesReadOnlyState,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tvalidateLayerCompatibility,\n\ttype MonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * The config key to disable strict loader layer compatibility check.\n */\nexport const disableStrictLoaderLayerCompatibilityCheckKey =\n\t\"Fluid.ContainerRuntime.DisableStrictLoaderLayerCompatibilityCheck\";\n\n/**\n * The core compatibility details of the Runtime layer that is the same across all layer boundaries.\n * @internal\n */\nexport const runtimeCoreCompatDetails = {\n\t/**\n\t * The package version of the Runtime layer.\n\t */\n\tpkgVersion,\n\t/**\n\t * The current generation of the Runtime layer.\n\t */\n\tgeneration,\n} as const;\n\n/**\n * Runtime's compatibility details that is exposed to the Loader layer.\n * @internal\n */\nexport const runtimeCompatDetailsForLoader: ILayerCompatDetails = {\n\t...runtimeCoreCompatDetails,\n\t/**\n\t * The features supported by the Runtime layer across the Runtime / Loader boundary.\n\t */\n\tsupportedFeatures: new Set<string>(),\n};\n\n/**\n * The requirements that the Loader layer must meet to be compatible with this Runtime.\n * @internal\n */\nexport const loaderSupportRequirementsForRuntime: ILayerCompatSupportRequirements = {\n\t/**\n\t * Minimum generation that Loader must be at to be compatible with this Runtime. This is calculated\n\t * based on the LayerCompatibilityPolicyWindowMonths.RuntimeLoader value which defines how many months old can\n\t * the Loader layer be compared to the Runtime layer for them to still be considered compatible.\n\t * The minimum valid generation value is 0.\n\t */\n\tminSupportedGeneration: Math.max(\n\t\t0,\n\t\truntimeCoreCompatDetails.generation - LayerCompatibilityPolicyWindowMonths.RuntimeLoader,\n\t),\n\t/**\n\t * The features that the Loader must support to be compatible with Runtime.\n\t */\n\trequiredFeatures: [],\n};\n\n/**\n * Runtime's compatibility details that is exposed to the DataStore layer.\n * @internal\n */\nexport const runtimeCompatDetailsForDataStore: ILayerCompatDetails = {\n\t...runtimeCoreCompatDetails,\n\t/**\n\t * The features supported by the Runtime layer across the Runtime / DataStore boundary.\n\t */\n\tsupportedFeatures: new Set<string>([encodeHandlesInContainerRuntime, notifiesReadOnlyState]),\n};\n\n/**\n * The requirements that the DataStore layer must meet to be compatible with this Runtime.\n * @internal\n */\nexport const dataStoreSupportRequirementsForRuntime: ILayerCompatSupportRequirements = {\n\t/**\n\t * Minimum generation that DataStore must be at to be compatible with this Runtime. This is calculated\n\t * based on the LayerCompatibilityPolicyWindowMonths.RuntimeDataStore value which defines how many months old can\n\t * the DataStore layer be compared to the Runtime layer for them to still be considered compatible.\n\t * The minimum valid generation value is 0.\n\t */\n\tminSupportedGeneration: Math.max(\n\t\t0,\n\t\truntimeCoreCompatDetails.generation -\n\t\t\tLayerCompatibilityPolicyWindowMonths.RuntimeDataStore,\n\t),\n\t/**\n\t * The features that the DataStore must support to be compatible with Runtime.\n\t */\n\trequiredFeatures: [],\n};\n\n/**\n * Validates that the Loader layer is compatible with this Runtime.\n * @internal\n */\nexport function validateLoaderCompatibility(\n\tmaybeLoaderCompatDetailsForRuntime: ILayerCompatDetails | undefined,\n\tdisposeFn: (error?: ICriticalContainerError) => void,\n\tmc: MonitoringContext,\n): void {\n\t// By default, use strictCompatibilityCheck here - If the Loader doesn't provide compatibility details,\n\t// assume it's a very old version and should be considered incompatible,\n\t// since Loader can drift far from the Runtime causing issues.\n\t// Can be disabled via config `disableStrictLoaderLayerCompatibilityCheckKey`.\n\tconst disableStrictLoaderLayerCompatibilityCheck = mc.config.getBoolean(\n\t\tdisableStrictLoaderLayerCompatibilityCheckKey,\n\t);\n\n\tvalidateLayerCompatibility(\n\t\t\"runtime\",\n\t\t\"loader\",\n\t\truntimeCompatDetailsForLoader,\n\t\tloaderSupportRequirementsForRuntime,\n\t\tmaybeLoaderCompatDetailsForRuntime,\n\t\tdisposeFn,\n\t\tmc,\n\t\tdisableStrictLoaderLayerCompatibilityCheck !== true /* strictCompatibilityCheck */,\n\t);\n}\n\n/**\n * Validates that the DataStore layer is compatible with this Runtime.\n * @internal\n */\nexport function validateDatastoreCompatibility(\n\tmaybeDataStoreCompatDetailsForRuntime: ILayerCompatDetails | undefined,\n\tdisposeFn: () => void,\n\tmc: MonitoringContext,\n): void {\n\tvalidateLayerCompatibility(\n\t\t\"runtime\",\n\t\t\"dataStore\",\n\t\truntimeCompatDetailsForDataStore,\n\t\tdataStoreSupportRequirementsForRuntime,\n\t\tmaybeDataStoreCompatDetailsForRuntime,\n\t\tdisposeFn,\n\t\tmc,\n\t);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarizer.d.ts","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACX,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,wDAAwD,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAEpF,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,YAAY,EAIZ,MAAM,0CAA0C,CAAC;AAElD,OAAO,KAAK,EACX,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EAEzB,WAAW,EACX,4BAA4B,EAC5B,kBAAkB,EAClB,mBAAmB,EAEnB,qBAAqB,EACrB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAI1F,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEzF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC;;;GAGG;AACH,eAAO,MAAM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IAE5D;;;;;;;;OAQG;YACW,KAAK;IA0DnB;;;;;OAKG;IACI,OAAO,IAAI,IAAI;IAYf,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,GAAG,iBAAiB;IA4DxE,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,sBAAsB;IAW3E,oBAAoB,CAAC,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI;IAI7D,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAsB;IAE7D,OAAO,CAAC,oBAAoB;IAc5B,OAAO,CAAC,sBAAsB;CAM9B"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { TypedEventEmitter } from "@fluid-internal/client-utils";
|
|
6
|
-
import { Deferred } from "@fluidframework/core-utils/internal";
|
|
6
|
+
import { assert, Deferred } from "@fluidframework/core-utils/internal";
|
|
7
7
|
import { LoggingError, UsageError, createChildLogger, wrapErrorAndLog, } from "@fluidframework/telemetry-utils/internal";
|
|
8
8
|
import { RunningSummarizer } from "./runningSummarizer.js";
|
|
9
9
|
import { SummarizeHeuristicData } from "./summarizerHeuristics.js";
|
|
@@ -106,7 +106,33 @@ export class Summarizer extends TypedEventEmitter {
|
|
|
106
106
|
this.runtime.disposeFn();
|
|
107
107
|
}
|
|
108
108
|
async runCore(onBehalfOf) {
|
|
109
|
-
|
|
109
|
+
// Race coordinator creation against a timeout to ensure we don't hang indefinitely
|
|
110
|
+
// if the summarizer container fails to connect.
|
|
111
|
+
let coordinatorTimedOut = false;
|
|
112
|
+
const coordinatorTimeoutMs = 2 * 60 * 1000; // 2 minutes
|
|
113
|
+
const coordinatorResult = await Promise.race([
|
|
114
|
+
this.runCoordinatorCreateFn(this.runtime).then((coordinator) => {
|
|
115
|
+
if (coordinatorTimedOut) {
|
|
116
|
+
coordinator.stop("summarizerClientDisconnected");
|
|
117
|
+
}
|
|
118
|
+
return coordinator;
|
|
119
|
+
}),
|
|
120
|
+
new Promise((resolve) => setTimeout(() => {
|
|
121
|
+
coordinatorTimedOut = true;
|
|
122
|
+
resolve(undefined);
|
|
123
|
+
}, coordinatorTimeoutMs)),
|
|
124
|
+
]);
|
|
125
|
+
// If we timed out before coordinator was created, exit early
|
|
126
|
+
if (coordinatorTimedOut) {
|
|
127
|
+
this.logger.sendTelemetryEvent({
|
|
128
|
+
eventName: "CreateRunCoordinatorTimeout",
|
|
129
|
+
onBehalfOf,
|
|
130
|
+
timeoutMs: coordinatorTimeoutMs,
|
|
131
|
+
});
|
|
132
|
+
return "summarizerClientDisconnected";
|
|
133
|
+
}
|
|
134
|
+
assert(coordinatorResult !== undefined, 0xcd6 /* Expect coordinatorResult to be defined */);
|
|
135
|
+
const runCoordinator = coordinatorResult;
|
|
110
136
|
// Wait for either external signal to cancel, or loss of connectivity.
|
|
111
137
|
const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);
|
|
112
138
|
// eslint-disable-next-line no-void
|
|
@@ -148,8 +174,18 @@ export class Summarizer extends TypedEventEmitter {
|
|
|
148
174
|
// As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new
|
|
149
175
|
// summarizer client to not be created until current summarizer fully moves to exit, and that would reduce
|
|
150
176
|
// cons of #2 substantially.
|
|
151
|
-
// Cleanup after running
|
|
152
|
-
|
|
177
|
+
// Cleanup after running with a timeout to prevent hanging
|
|
178
|
+
const waitStopPromise = runningSummarizer.waitStop(!runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));
|
|
179
|
+
const summarizerStopTimeoutMs = 2 * 60 * 1000; // 2 minutes
|
|
180
|
+
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve("timeout"), summarizerStopTimeoutMs));
|
|
181
|
+
const waitStopResult = await Promise.race([waitStopPromise, timeoutPromise]);
|
|
182
|
+
if (waitStopResult === "timeout") {
|
|
183
|
+
this.logger.sendTelemetryEvent({
|
|
184
|
+
eventName: "SummarizerStopTimeout",
|
|
185
|
+
onBehalfOf,
|
|
186
|
+
timeoutMs: summarizerStopTimeoutMs,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
153
189
|
// Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit
|
|
154
190
|
runCoordinator.stop(stopReason);
|
|
155
191
|
return stopReason;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMjE,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,EAGN,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,eAAe,GACf,MAAM,0CAA0C,CAAC;AAiBlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,MAAM,OAAO,kBACZ,SAAQ,YAAY;IAMpB,YACC,YAAoB,EACX,SAAkB,KAAK;QAEhC,KAAK,CAAC,YAAY,CAAC,CAAC;QAFX,WAAM,GAAN,MAAM,CAAiB;QALxB,cAAS,GAAG,kBAAkB,CAAC;QAC/B,aAAQ,GAAG,IAAI,CAAC;IAOzB,CAAC;IAED,MAAM,CAAC,IAAI,CACV,KAAc,EACd,SAAkB,KAAK,EACvB,MAA2B;QAE3B,MAAM,UAAU,GAAG,CAAC,MAAc,EAAsB,EAAE,CACzD,IAAI,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxC,OAAO,eAAe,CAAqB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AAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAEO,sBAAsB;QAC7B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YACnD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,IAAI,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IACxC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IFluidHandleContext } from \"@fluidframework/core-interfaces/internal\";\nimport { Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IFluidErrorBase,\n\ttype ITelemetryLoggerExt,\n\tLoggingError,\n\tUsageError,\n\tcreateChildLogger,\n\twrapErrorAndLog,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tIConnectableRuntime,\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tISummarizeHeuristicData,\n\tISummarizer,\n\tISummarizerInternalsProvider,\n\tISummarizerRuntime,\n\tISummarizingWarning,\n\tIRetriableFailureError,\n\tISummaryConfiguration,\n} from \"../summarizerTypes.js\";\nimport type { SummaryCollection } from \"../summaryCollection.js\";\n\nimport type { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator.js\";\nimport { RunningSummarizer } from \"./runningSummarizer.js\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics.js\";\nimport { SummarizeResultBuilder } from \"./summaryResultBuilder.js\";\nimport type { EnqueueSummarizeResult, ISummarizeResults } from \"./summaryResultTypes.js\";\n\n/**\n * The maximum number of summarization attempts that will be done by default in case of failures\n * that can be retried.\n */\nexport const defaultMaxAttempts = 2;\n/**\n * The default value for maximum number of summarization attempts that will be done for summarization failures where\n * submit fails and the failure can be retried.\n */\nexport const defaultMaxAttemptsForSubmitFailures = 5;\n\nexport class SummarizingWarning\n\textends LoggingError\n\timplements ISummarizingWarning, IFluidErrorBase\n{\n\treadonly errorType = \"summarizingError\";\n\treadonly canRetry = true;\n\n\tconstructor(\n\t\terrorMessage: string,\n\t\treadonly logged: boolean = false,\n\t) {\n\t\tsuper(errorMessage);\n\t}\n\n\tstatic wrap(\n\t\terror: unknown,\n\t\tlogged: boolean = false,\n\t\tlogger: ITelemetryLoggerExt,\n\t): SummarizingWarning {\n\t\tconst newErrorFn = (errMsg: string): SummarizingWarning =>\n\t\t\tnew SummarizingWarning(errMsg, logged);\n\t\treturn wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n\t}\n}\n\nexport const createSummarizingWarning = (\n\terrorMessage: string,\n\tlogged: boolean,\n): SummarizingWarning => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n * @internal\n */\nexport class Summarizer extends TypedEventEmitter<ISummarizerEvents> implements ISummarizer {\n\tpublic get ISummarizer(): this {\n\t\treturn this;\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate runningSummarizer?: RunningSummarizer;\n\tprivate _disposed: boolean = false;\n\tprivate starting: boolean = false;\n\n\tprivate readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n\tconstructor(\n\t\t/**\n\t\t * Reference to runtime that created this object.\n\t\t * i.e. runtime with clientType === \"summarizer\"\n\t\t */\n\n\t\tprivate readonly runtime: ISummarizerRuntime,\n\t\tprivate readonly configurationGetter: () => ISummaryConfiguration,\n\t\t/**\n\t\t * Represents an object that can generate summary.\n\t\t * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n\t\t */\n\n\t\tprivate readonly internalsProvider: ISummarizerInternalsProvider,\n\t\thandleContext: IFluidHandleContext,\n\t\tpublic readonly summaryCollection: SummaryCollection,\n\t\tprivate readonly runCoordinatorCreateFn: (\n\t\t\truntime: IConnectableRuntime,\n\t\t) => Promise<ICancellableSummarizerController>,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: this.runtime.baseLogger,\n\t\t\tnamespace: \"Summarizer\",\n\t\t});\n\t}\n\n\tpublic async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n\t\ttry {\n\t\t\tconst stopReason = await this.runCore(onBehalfOf);\n\t\t\tthis.emit(\"summarizerStop\", {\n\t\t\t\tstopReason,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn stopReason;\n\t\t} catch (error) {\n\t\t\tthis.stop(\"summarizerException\");\n\t\t\tthis.emit(\"summarizerStop\", {\n\t\t\t\tstopReason: \"summarizerException\",\n\t\t\t\terror,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\tthrow SummarizingWarning.wrap(error, false /* logged */, this.logger);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Stops the summarizer from running. This will complete\n\t * the run promise, and also close the container.\n\t * @param reason - reason code for stopping\n\t */\n\tpublic stop(reason: SummarizerStopReason): void {\n\t\tthis.stopDeferred.resolve(reason);\n\t}\n\n\tpublic close(): void {\n\t\t// This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n\t\t// unless stop() was called earlier\n\t\tthis.dispose();\n\t\tthis.runtime.disposeFn();\n\t}\n\n\tprivate async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n\t\tconst runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(\n\t\t\tthis.runtime,\n\t\t);\n\n\t\t// Wait for either external signal to cancel, or loss of connectivity.\n\t\tconst stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n\t\t// eslint-disable-next-line no-void\n\t\tvoid stopP.then((reason) => {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"StoppingSummarizer\",\n\t\t\t\tonBehalfOf,\n\t\t\t\treason,\n\t\t\t});\n\t\t});\n\n\t\tif (runCoordinator.cancelled) {\n\t\t\tthis.emit(\"summarizerStartupFailed\", {\n\t\t\t\treason: await runCoordinator.waitCancelled,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn runCoordinator.waitCancelled;\n\t\t}\n\n\t\tthis.emit(\"summarizerStart\", {\n\t\t\tonBehalfOf,\n\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t});\n\n\t\tconst runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n\t\t// Wait for either external signal to cancel, or loss of connectivity.\n\t\tconst stopReason = await stopP;\n\n\t\t// There are two possible approaches here:\n\t\t// 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n\t\t// faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n\t\t// We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n\t\t// The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n\t\t// did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n\t\t// that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n\t\t// In general, it's more wasted resources.\n\t\t// 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n\t\t// that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n\t\t// substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n\t\t// conflict with new summarizer client starting on different client.\n\t\t// As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n\t\t// summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n\t\t// cons of #2 substantially.\n\n\t\t// Cleanup after running\n\t\tawait runningSummarizer.waitStop(\n\t\t\t!runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason),\n\t\t);\n\n\t\t// Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n\t\trunCoordinator.stop(stopReason);\n\n\t\treturn stopReason;\n\t}\n\n\t/**\n\t * Should we try to run a last summary for the given stop reason?\n\t * Currently only allows \"parentNotConnected\"\n\t * @param stopReason - SummarizerStopReason\n\t * @returns `true` if the stop reason can run a last summary, otherwise `false`.\n\t */\n\tpublic static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n\t\treturn stopReason === \"parentNotConnected\";\n\t}\n\n\tprivate _heuristicData: ISummarizeHeuristicData | undefined;\n\n\t/**\n\t * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n\t * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n\t * (in the on-demand case).\n\t * @param onBehalfOf - ID of the client that requested that the summarizer start\n\t * @param runCoordinator - cancellation token\n\t * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n\t * @returns A promise that is fulfilled when the RunningSummarizer is ready.\n\t */\n\tprivate async start(\n\t\tonBehalfOf: string,\n\n\t\trunCoordinator: ICancellableSummarizerController,\n\t): Promise<RunningSummarizer> {\n\t\tif (this.runningSummarizer) {\n\t\t\tif (this.runningSummarizer.disposed) {\n\t\t\t\tthrow new UsageError(\"Starting a disposed summarizer\");\n\t\t\t}\n\t\t\treturn this.runningSummarizer;\n\t\t}\n\t\tif (this.starting) {\n\t\t\tthrow new UsageError(\"Attempting to start a summarizer that is already starting\");\n\t\t}\n\t\tthis.starting = true;\n\t\t// Initialize values and first ack (time is not exact)\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"RunningSummarizer\",\n\t\t\tonBehalfOf,\n\t\t\tinitSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n\t\t\tconfig: JSON.stringify(this.configurationGetter()),\n\t\t});\n\n\t\t// Summarizing container ID (with clientType === \"summarizer\")\n\t\tconst clientId = this.runtime.clientId;\n\t\tif (clientId === undefined) {\n\t\t\tthrow new UsageError(\"clientId should be defined if connected.\");\n\t\t}\n\n\t\tthis._heuristicData = new SummarizeHeuristicData(\n\t\t\tthis.runtime.deltaManager.lastSequenceNumber,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * summary attempt baseline for heuristics\n\t\t\t\t */\n\t\t\t\trefSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n\t\t\t\tsummaryTime: Date.now(),\n\t\t\t} as const,\n\t\t);\n\n\t\tconst runningSummarizer = await RunningSummarizer.start(\n\t\t\tthis.logger,\n\t\t\tthis.summaryCollection.createWatcher(clientId),\n\t\t\tthis.configurationGetter(),\n\t\t\tasync (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n\t\t\tasync (...args) => this.internalsProvider.refreshLatestSummaryAck(...args), // refreshLatestSummaryAckCallback\n\t\t\tthis._heuristicData,\n\t\t\tthis.summaryCollection,\n\t\t\trunCoordinator /* cancellationToken */,\n\t\t\t(reason) => runCoordinator.stop(reason) /* stopSummarizerCallback */,\n\t\t\tthis.runtime,\n\t\t);\n\t\tthis.runningSummarizer = runningSummarizer;\n\t\tthis.setupForwardedEvents(runningSummarizer);\n\t\tthis.starting = false;\n\t\treturn runningSummarizer;\n\t}\n\n\t/**\n\t * Disposes of resources after running. This cleanup will\n\t * clear any outstanding timers and reset some of the state\n\t * properties.\n\t * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n\t */\n\tpublic dispose(): void {\n\t\t// Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n\t\tthis.stop(\"summarizerClientDisconnected\");\n\n\t\tthis._disposed = true;\n\t\tif (this.runningSummarizer) {\n\t\t\tthis.cleanupForwardedEvents();\n\t\t\tthis.runningSummarizer.dispose();\n\t\t\tthis.runningSummarizer = undefined;\n\t\t}\n\t}\n\n\tpublic summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults {\n\t\ttry {\n\t\t\tif (this._disposed || this.runningSummarizer?.disposed === true) {\n\t\t\t\tthrow new UsageError(\"Summarizer is already disposed.\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tthis.runtime.summarizerClientId !== undefined &&\n\t\t\t\tthis.runtime.summarizerClientId !== this.runtime.clientId\n\t\t\t) {\n\t\t\t\t// If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n\t\t\t\t// This is to prevent the on-demand summary and heuristic-based summary from stepping on\n\t\t\t\t// each other.\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"On-demand summary attempted while an elected summarizer is present\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst builder = new SummarizeResultBuilder();\n\t\t\tif (this.runningSummarizer) {\n\t\t\t\t// Summarizer is already running. Go ahead and start.\n\t\t\t\treturn this.runningSummarizer.summarizeOnDemand(options, builder);\n\t\t\t}\n\n\t\t\t// Summarizer isn't running, so we need to start it, which is an async operation.\n\t\t\t// Manage the promise related to creating the cancellation token here.\n\t\t\t// The promises related to starting, summarizing,\n\t\t\t// and submitting are communicated to the caller through the results builder.\n\t\t\tconst coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n\t\t\tcoordinatorCreateP\n\t\t\t\t.then((runCoordinator) => {\n\t\t\t\t\t// Successfully created the cancellation token. Start the summarizer.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst startP = this.start(this.runtime.clientId!, runCoordinator);\n\t\t\t\t\tstartP\n\t\t\t\t\t\t.then(async (runningSummarizer) => {\n\t\t\t\t\t\t\t// Successfully started the summarizer. Run it.\n\t\t\t\t\t\t\trunningSummarizer.summarizeOnDemand(options, builder);\n\t\t\t\t\t\t\t// Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n\t\t\t\t\t\t\tconst stopReason = await Promise.race([\n\t\t\t\t\t\t\t\tthis.stopDeferred.promise,\n\t\t\t\t\t\t\t\trunCoordinator.waitCancelled,\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\tawait runningSummarizer.waitStop(false);\n\t\t\t\t\t\t\trunCoordinator.stop(stopReason);\n\t\t\t\t\t\t\tthis.close();\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch((error: IRetriableFailureError) => {\n\t\t\t\t\t\t\tbuilder.fail(\"Failed to start summarizer\", error);\n\t\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.catch((error: IRetriableFailureError) => {\n\t\t\t\t\tbuilder.fail(\"Failed to create cancellation token\", error);\n\t\t\t\t});\n\n\t\t\treturn builder.build();\n\t\t} catch (error) {\n\t\t\tthrow SummarizingWarning.wrap(error, false /* logged */, this.logger);\n\t\t}\n\t}\n\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tif (\n\t\t\tthis._disposed ||\n\t\t\tthis.runningSummarizer === undefined ||\n\t\t\tthis.runningSummarizer.disposed\n\t\t) {\n\t\t\tthrow new UsageError(\"Summarizer is not running or already disposed.\");\n\t\t}\n\t\treturn this.runningSummarizer.enqueueSummarize(options);\n\t}\n\n\tpublic recordSummaryAttempt?(summaryRefSeqNum?: number): void {\n\t\tthis._heuristicData?.recordAttempt(summaryRefSeqNum);\n\t}\n\n\tprivate readonly forwardedEventsCleanup: (() => void)[] = [];\n\n\tprivate setupForwardedEvents(runningSummarizer: RunningSummarizer): void {\n\t\tfor (const event of [\n\t\t\t\"summarize\",\n\t\t\t\"summarizeAllAttemptsFailed\",\n\t\t\t\"summarizeTimeout\",\n\t\t] as const) {\n\t\t\tconst listener = (...args: unknown[]): void => {\n\t\t\t\tthis.emit(event, ...args);\n\t\t\t};\n\t\t\trunningSummarizer.on(event, listener);\n\t\t\tthis.forwardedEventsCleanup.push(() => runningSummarizer.off(event, listener));\n\t\t}\n\t}\n\n\tprivate cleanupForwardedEvents(): void {\n\t\tfor (const cleanup of this.forwardedEventsCleanup) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.forwardedEventsCleanup.length = 0;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../../../src/summary/summaryDelayLoadedModule/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMjE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAGN,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,eAAe,GACf,MAAM,0CAA0C,CAAC;AAiBlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC;;;GAGG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,MAAM,OAAO,kBACZ,SAAQ,YAAY;IAMpB,YACC,YAAoB,EACX,SAAkB,KAAK;QAEhC,KAAK,CAAC,YAAY,CAAC,CAAC;QAFX,WAAM,GAAN,MAAM,CAAiB;QALxB,cAAS,GAAG,kBAAkB,CAAC;QAC/B,aAAQ,GAAG,IAAI,CAAC;IAOzB,CAAC;IAED,MAAM,CAAC,IAAI,CACV,KAAc,EACd,SAAkB,KAAK,EACvB,MAA2B;QAE3B,MAAM,UAAU,GAAG,CAAC,MAAc,EAAsB,EAAE,CACzD,IAAI,kBAAkB,CAAC,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,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;gBAC7C,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;YAC3B,CAAC,CAAC;YACF,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YACtC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAEO,sBAAsB;QAC7B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YACnD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,IAAI,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IACxC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type { IFluidHandleContext } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\ttype IFluidErrorBase,\n\ttype ITelemetryLoggerExt,\n\tLoggingError,\n\tUsageError,\n\tcreateChildLogger,\n\twrapErrorAndLog,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type {\n\tIConnectableRuntime,\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tISummarizeHeuristicData,\n\tISummarizer,\n\tISummarizerInternalsProvider,\n\tISummarizerRuntime,\n\tISummarizingWarning,\n\tIRetriableFailureError,\n\tISummaryConfiguration,\n} from \"../summarizerTypes.js\";\nimport type { SummaryCollection } from \"../summaryCollection.js\";\n\nimport type { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator.js\";\nimport { RunningSummarizer } from \"./runningSummarizer.js\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics.js\";\nimport { SummarizeResultBuilder } from \"./summaryResultBuilder.js\";\nimport type { EnqueueSummarizeResult, ISummarizeResults } from \"./summaryResultTypes.js\";\n\n/**\n * The maximum number of summarization attempts that will be done by default in case of failures\n * that can be retried.\n */\nexport const defaultMaxAttempts = 2;\n/**\n * The default value for maximum number of summarization attempts that will be done for summarization failures where\n * submit fails and the failure can be retried.\n */\nexport const defaultMaxAttemptsForSubmitFailures = 5;\n\nexport class SummarizingWarning\n\textends LoggingError\n\timplements ISummarizingWarning, IFluidErrorBase\n{\n\treadonly errorType = \"summarizingError\";\n\treadonly canRetry = true;\n\n\tconstructor(\n\t\terrorMessage: string,\n\t\treadonly logged: boolean = false,\n\t) {\n\t\tsuper(errorMessage);\n\t}\n\n\tstatic wrap(\n\t\terror: unknown,\n\t\tlogged: boolean = false,\n\t\tlogger: ITelemetryLoggerExt,\n\t): SummarizingWarning {\n\t\tconst newErrorFn = (errMsg: string): SummarizingWarning =>\n\t\t\tnew SummarizingWarning(errMsg, logged);\n\t\treturn wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n\t}\n}\n\nexport const createSummarizingWarning = (\n\terrorMessage: string,\n\tlogged: boolean,\n): SummarizingWarning => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n * @internal\n */\nexport class Summarizer extends TypedEventEmitter<ISummarizerEvents> implements ISummarizer {\n\tpublic get ISummarizer(): this {\n\t\treturn this;\n\t}\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate runningSummarizer?: RunningSummarizer;\n\tprivate _disposed: boolean = false;\n\tprivate starting: boolean = false;\n\n\tprivate readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n\tconstructor(\n\t\t/**\n\t\t * Reference to runtime that created this object.\n\t\t * i.e. runtime with clientType === \"summarizer\"\n\t\t */\n\n\t\tprivate readonly runtime: ISummarizerRuntime,\n\t\tprivate readonly configurationGetter: () => ISummaryConfiguration,\n\t\t/**\n\t\t * Represents an object that can generate summary.\n\t\t * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n\t\t */\n\n\t\tprivate readonly internalsProvider: ISummarizerInternalsProvider,\n\t\thandleContext: IFluidHandleContext,\n\t\tpublic readonly summaryCollection: SummaryCollection,\n\t\tprivate readonly runCoordinatorCreateFn: (\n\t\t\truntime: IConnectableRuntime,\n\t\t) => Promise<ICancellableSummarizerController>,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: this.runtime.baseLogger,\n\t\t\tnamespace: \"Summarizer\",\n\t\t});\n\t}\n\n\tpublic async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n\t\ttry {\n\t\t\tconst stopReason = await this.runCore(onBehalfOf);\n\t\t\tthis.emit(\"summarizerStop\", {\n\t\t\t\tstopReason,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn stopReason;\n\t\t} catch (error) {\n\t\t\tthis.stop(\"summarizerException\");\n\t\t\tthis.emit(\"summarizerStop\", {\n\t\t\t\tstopReason: \"summarizerException\",\n\t\t\t\terror,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\tthrow SummarizingWarning.wrap(error, false /* logged */, this.logger);\n\t\t} finally {\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\t/**\n\t * Stops the summarizer from running. This will complete\n\t * the run promise, and also close the container.\n\t * @param reason - reason code for stopping\n\t */\n\tpublic stop(reason: SummarizerStopReason): void {\n\t\tthis.stopDeferred.resolve(reason);\n\t}\n\n\tpublic close(): void {\n\t\t// This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n\t\t// unless stop() was called earlier\n\t\tthis.dispose();\n\t\tthis.runtime.disposeFn();\n\t}\n\n\tprivate async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n\t\t// Race coordinator creation against a timeout to ensure we don't hang indefinitely\n\t\t// if the summarizer container fails to connect.\n\t\tlet coordinatorTimedOut = false;\n\t\tconst coordinatorTimeoutMs = 2 * 60 * 1000; // 2 minutes\n\t\tconst coordinatorResult = await Promise.race([\n\t\t\tthis.runCoordinatorCreateFn(this.runtime).then((coordinator) => {\n\t\t\t\tif (coordinatorTimedOut) {\n\t\t\t\t\tcoordinator.stop(\"summarizerClientDisconnected\");\n\t\t\t\t}\n\t\t\t\treturn coordinator;\n\t\t\t}),\n\t\t\tnew Promise<undefined>((resolve) =>\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tcoordinatorTimedOut = true;\n\t\t\t\t\tresolve(undefined);\n\t\t\t\t}, coordinatorTimeoutMs),\n\t\t\t),\n\t\t]);\n\n\t\t// If we timed out before coordinator was created, exit early\n\t\tif (coordinatorTimedOut) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"CreateRunCoordinatorTimeout\",\n\t\t\t\tonBehalfOf,\n\t\t\t\ttimeoutMs: coordinatorTimeoutMs,\n\t\t\t});\n\t\t\treturn \"summarizerClientDisconnected\";\n\t\t}\n\n\t\tassert(\n\t\t\tcoordinatorResult !== undefined,\n\t\t\t0xcd6 /* Expect coordinatorResult to be defined */,\n\t\t);\n\t\tconst runCoordinator = coordinatorResult;\n\n\t\t// Wait for either external signal to cancel, or loss of connectivity.\n\t\tconst stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n\t\t// eslint-disable-next-line no-void\n\t\tvoid stopP.then((reason) => {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"StoppingSummarizer\",\n\t\t\t\tonBehalfOf,\n\t\t\t\treason,\n\t\t\t});\n\t\t});\n\n\t\tif (runCoordinator.cancelled) {\n\t\t\tthis.emit(\"summarizerStartupFailed\", {\n\t\t\t\treason: await runCoordinator.waitCancelled,\n\t\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t\t});\n\t\t\treturn runCoordinator.waitCancelled;\n\t\t}\n\n\t\tthis.emit(\"summarizerStart\", {\n\t\t\tonBehalfOf,\n\t\t\tnumUnsummarizedRuntimeOps: this._heuristicData?.numRuntimeOps,\n\t\t\tnumUnsummarizedNonRuntimeOps: this._heuristicData?.numNonRuntimeOps,\n\t\t});\n\n\t\tconst runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n\t\t// Wait for either external signal to cancel, or loss of connectivity.\n\t\tconst stopReason = await stopP;\n\n\t\t// There are two possible approaches here:\n\t\t// 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n\t\t// faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n\t\t// We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n\t\t// The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n\t\t// did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n\t\t// that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n\t\t// In general, it's more wasted resources.\n\t\t// 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n\t\t// that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n\t\t// substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n\t\t// conflict with new summarizer client starting on different client.\n\t\t// As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n\t\t// summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n\t\t// cons of #2 substantially.\n\n\t\t// Cleanup after running with a timeout to prevent hanging\n\t\tconst waitStopPromise = runningSummarizer.waitStop(\n\t\t\t!runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason),\n\t\t);\n\t\tconst summarizerStopTimeoutMs = 2 * 60 * 1000; // 2 minutes\n\t\tconst timeoutPromise = new Promise<\"timeout\">((resolve) =>\n\t\t\tsetTimeout(() => resolve(\"timeout\"), summarizerStopTimeoutMs),\n\t\t);\n\t\tconst waitStopResult = await Promise.race([waitStopPromise, timeoutPromise]);\n\t\tif (waitStopResult === \"timeout\") {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"SummarizerStopTimeout\",\n\t\t\t\tonBehalfOf,\n\t\t\t\ttimeoutMs: summarizerStopTimeoutMs,\n\t\t\t});\n\t\t}\n\n\t\t// Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n\t\trunCoordinator.stop(stopReason);\n\n\t\treturn stopReason;\n\t}\n\n\t/**\n\t * Should we try to run a last summary for the given stop reason?\n\t * Currently only allows \"parentNotConnected\"\n\t * @param stopReason - SummarizerStopReason\n\t * @returns `true` if the stop reason can run a last summary, otherwise `false`.\n\t */\n\tpublic static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n\t\treturn stopReason === \"parentNotConnected\";\n\t}\n\n\tprivate _heuristicData: ISummarizeHeuristicData | undefined;\n\n\t/**\n\t * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n\t * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n\t * (in the on-demand case).\n\t * @param onBehalfOf - ID of the client that requested that the summarizer start\n\t * @param runCoordinator - cancellation token\n\t * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n\t * @returns A promise that is fulfilled when the RunningSummarizer is ready.\n\t */\n\tprivate async start(\n\t\tonBehalfOf: string,\n\n\t\trunCoordinator: ICancellableSummarizerController,\n\t): Promise<RunningSummarizer> {\n\t\tif (this.runningSummarizer) {\n\t\t\tif (this.runningSummarizer.disposed) {\n\t\t\t\tthrow new UsageError(\"Starting a disposed summarizer\");\n\t\t\t}\n\t\t\treturn this.runningSummarizer;\n\t\t}\n\t\tif (this.starting) {\n\t\t\tthrow new UsageError(\"Attempting to start a summarizer that is already starting\");\n\t\t}\n\t\tthis.starting = true;\n\t\t// Initialize values and first ack (time is not exact)\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"RunningSummarizer\",\n\t\t\tonBehalfOf,\n\t\t\tinitSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n\t\t\tconfig: JSON.stringify(this.configurationGetter()),\n\t\t});\n\n\t\t// Summarizing container ID (with clientType === \"summarizer\")\n\t\tconst clientId = this.runtime.clientId;\n\t\tif (clientId === undefined) {\n\t\t\tthrow new UsageError(\"clientId should be defined if connected.\");\n\t\t}\n\n\t\tthis._heuristicData = new SummarizeHeuristicData(\n\t\t\tthis.runtime.deltaManager.lastSequenceNumber,\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * summary attempt baseline for heuristics\n\t\t\t\t */\n\t\t\t\trefSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n\t\t\t\tsummaryTime: Date.now(),\n\t\t\t} as const,\n\t\t);\n\n\t\tconst runningSummarizer = await RunningSummarizer.start(\n\t\t\tthis.logger,\n\t\t\tthis.summaryCollection.createWatcher(clientId),\n\t\t\tthis.configurationGetter(),\n\t\t\tasync (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n\t\t\tasync (...args) => this.internalsProvider.refreshLatestSummaryAck(...args), // refreshLatestSummaryAckCallback\n\t\t\tthis._heuristicData,\n\t\t\tthis.summaryCollection,\n\t\t\trunCoordinator /* cancellationToken */,\n\t\t\t(reason) => runCoordinator.stop(reason) /* stopSummarizerCallback */,\n\t\t\tthis.runtime,\n\t\t);\n\t\tthis.runningSummarizer = runningSummarizer;\n\t\tthis.setupForwardedEvents(runningSummarizer);\n\t\tthis.starting = false;\n\t\treturn runningSummarizer;\n\t}\n\n\t/**\n\t * Disposes of resources after running. This cleanup will\n\t * clear any outstanding timers and reset some of the state\n\t * properties.\n\t * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n\t */\n\tpublic dispose(): void {\n\t\t// Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n\t\tthis.stop(\"summarizerClientDisconnected\");\n\n\t\tthis._disposed = true;\n\t\tif (this.runningSummarizer) {\n\t\t\tthis.cleanupForwardedEvents();\n\t\t\tthis.runningSummarizer.dispose();\n\t\t\tthis.runningSummarizer = undefined;\n\t\t}\n\t}\n\n\tpublic summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults {\n\t\ttry {\n\t\t\tif (this._disposed || this.runningSummarizer?.disposed === true) {\n\t\t\t\tthrow new UsageError(\"Summarizer is already disposed.\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tthis.runtime.summarizerClientId !== undefined &&\n\t\t\t\tthis.runtime.summarizerClientId !== this.runtime.clientId\n\t\t\t) {\n\t\t\t\t// If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n\t\t\t\t// This is to prevent the on-demand summary and heuristic-based summary from stepping on\n\t\t\t\t// each other.\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"On-demand summary attempted while an elected summarizer is present\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst builder = new SummarizeResultBuilder();\n\t\t\tif (this.runningSummarizer) {\n\t\t\t\t// Summarizer is already running. Go ahead and start.\n\t\t\t\treturn this.runningSummarizer.summarizeOnDemand(options, builder);\n\t\t\t}\n\n\t\t\t// Summarizer isn't running, so we need to start it, which is an async operation.\n\t\t\t// Manage the promise related to creating the cancellation token here.\n\t\t\t// The promises related to starting, summarizing,\n\t\t\t// and submitting are communicated to the caller through the results builder.\n\t\t\tconst coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n\t\t\tcoordinatorCreateP\n\t\t\t\t.then((runCoordinator) => {\n\t\t\t\t\t// Successfully created the cancellation token. Start the summarizer.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst startP = this.start(this.runtime.clientId!, runCoordinator);\n\t\t\t\t\tstartP\n\t\t\t\t\t\t.then(async (runningSummarizer) => {\n\t\t\t\t\t\t\t// Successfully started the summarizer. Run it.\n\t\t\t\t\t\t\trunningSummarizer.summarizeOnDemand(options, builder);\n\t\t\t\t\t\t\t// Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n\t\t\t\t\t\t\tconst stopReason = await Promise.race([\n\t\t\t\t\t\t\t\tthis.stopDeferred.promise,\n\t\t\t\t\t\t\t\trunCoordinator.waitCancelled,\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\tawait runningSummarizer.waitStop(false);\n\t\t\t\t\t\t\trunCoordinator.stop(stopReason);\n\t\t\t\t\t\t\tthis.close();\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.catch((error: IRetriableFailureError) => {\n\t\t\t\t\t\t\tbuilder.fail(\"Failed to start summarizer\", error);\n\t\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.catch((error: IRetriableFailureError) => {\n\t\t\t\t\tbuilder.fail(\"Failed to create cancellation token\", error);\n\t\t\t\t});\n\n\t\t\treturn builder.build();\n\t\t} catch (error) {\n\t\t\tthrow SummarizingWarning.wrap(error, false /* logged */, this.logger);\n\t\t}\n\t}\n\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tif (\n\t\t\tthis._disposed ||\n\t\t\tthis.runningSummarizer === undefined ||\n\t\t\tthis.runningSummarizer.disposed\n\t\t) {\n\t\t\tthrow new UsageError(\"Summarizer is not running or already disposed.\");\n\t\t}\n\t\treturn this.runningSummarizer.enqueueSummarize(options);\n\t}\n\n\tpublic recordSummaryAttempt?(summaryRefSeqNum?: number): void {\n\t\tthis._heuristicData?.recordAttempt(summaryRefSeqNum);\n\t}\n\n\tprivate readonly forwardedEventsCleanup: (() => void)[] = [];\n\n\tprivate setupForwardedEvents(runningSummarizer: RunningSummarizer): void {\n\t\tfor (const event of [\n\t\t\t\"summarize\",\n\t\t\t\"summarizeAllAttemptsFailed\",\n\t\t\t\"summarizeTimeout\",\n\t\t] as const) {\n\t\t\tconst listener = (...args: unknown[]): void => {\n\t\t\t\tthis.emit(event, ...args);\n\t\t\t};\n\t\t\trunningSummarizer.on(event, listener);\n\t\t\tthis.forwardedEventsCleanup.push(() => runningSummarizer.off(event, listener));\n\t\t}\n\t}\n\n\tprivate cleanupForwardedEvents(): void {\n\t\tfor (const cleanup of this.forwardedEventsCleanup) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.forwardedEventsCleanup.length = 0;\n\t}\n}\n"]}
|
|
@@ -63,6 +63,7 @@ export declare class SummaryManager extends TypedEventEmitter<ISummarizerEvents>
|
|
|
63
63
|
private state;
|
|
64
64
|
private summarizer?;
|
|
65
65
|
private _disposed;
|
|
66
|
+
private summarizerStopTimeout?;
|
|
66
67
|
get disposed(): boolean;
|
|
67
68
|
get currentState(): SummaryManagerState;
|
|
68
69
|
constructor(clientElection: ISummarizerClientElection, connectedState: IConnectedState, summaryCollection: Pick<SummaryCollection, "opsSinceLastAck" | "addOpListener" | "removeOpListener">, parentLogger: ITelemetryBaseLogger,
|
|
@@ -82,6 +83,7 @@ export declare class SummaryManager extends TypedEventEmitter<ISummarizerEvents>
|
|
|
82
83
|
private getShouldSummarizeState;
|
|
83
84
|
private readonly refreshSummarizer;
|
|
84
85
|
private startSummarization;
|
|
86
|
+
private cleanupAfterSummarizerStop;
|
|
85
87
|
private stop;
|
|
86
88
|
/**
|
|
87
89
|
* Implements initial delay before creating summarizer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryManager.d.ts","sourceRoot":"","sources":["../../src/summary/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EACX,iBAAiB,EAEjB,MAAM,wDAAwD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0BAA0B;IAkBlC,OAAO,CAAC,IAAI;IA4BZ;;;;OAIG;YACW,6BAA6B;IAyDpC,iBAAiB,CAAC,OAAO,EAAE,yBAAyB,GAAG,iBAAiB;IAQxE,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,sBAAsB;IAQ3E,OAAO,IAAI,IAAI;IAWtB,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAsB;IAE7D,OAAO,CAAC,oBAAoB;IAoB5B,OAAO,CAAC,sBAAsB;CAM9B"}
|
|
@@ -214,15 +214,23 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
214
214
|
})
|
|
215
215
|
.finally(() => {
|
|
216
216
|
assert(this.state !== SummaryManagerState.Off, 0x264 /* "Expected: Not Off" */);
|
|
217
|
-
this.
|
|
218
|
-
this.cleanupForwardedEvents();
|
|
219
|
-
this.summarizer?.close();
|
|
220
|
-
this.summarizer = undefined;
|
|
221
|
-
if (this.getShouldSummarizeState().shouldSummarize) {
|
|
222
|
-
this.startSummarization();
|
|
223
|
-
}
|
|
217
|
+
this.cleanupAfterSummarizerStop();
|
|
224
218
|
});
|
|
225
219
|
}
|
|
220
|
+
cleanupAfterSummarizerStop() {
|
|
221
|
+
this.state = SummaryManagerState.Off;
|
|
222
|
+
// Clear any pending stop timeout to avoid it firing for a different summarizer
|
|
223
|
+
if (this.summarizerStopTimeout !== undefined) {
|
|
224
|
+
clearTimeout(this.summarizerStopTimeout);
|
|
225
|
+
this.summarizerStopTimeout = undefined;
|
|
226
|
+
}
|
|
227
|
+
this.cleanupForwardedEvents();
|
|
228
|
+
this.summarizer?.close();
|
|
229
|
+
this.summarizer = undefined;
|
|
230
|
+
if (this.getShouldSummarizeState().shouldSummarize) {
|
|
231
|
+
this.startSummarization();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
226
234
|
stop(reason) {
|
|
227
235
|
if (!SummaryManager.isStartingOrRunning(this.state)) {
|
|
228
236
|
return;
|
|
@@ -231,6 +239,22 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
231
239
|
// Stopping the running summarizer client should trigger a change
|
|
232
240
|
// in states when the running summarizer closes
|
|
233
241
|
this.summarizer?.stop(reason);
|
|
242
|
+
const summarizerCloseTimeoutMs = 2 * 60 * 1000; // 2 minutes
|
|
243
|
+
// Clear any existing timeout before setting a new one
|
|
244
|
+
if (this.summarizerStopTimeout !== undefined) {
|
|
245
|
+
clearTimeout(this.summarizerStopTimeout);
|
|
246
|
+
}
|
|
247
|
+
// Set a timeout to force cleanup if the summarizer doesn't close in time
|
|
248
|
+
this.summarizerStopTimeout = setTimeout(() => {
|
|
249
|
+
if (this.state === SummaryManagerState.Stopping && this.summarizer !== undefined) {
|
|
250
|
+
this.logger.sendTelemetryEvent({
|
|
251
|
+
eventName: "SummarizerStopTimeout",
|
|
252
|
+
timeoutMs: summarizerCloseTimeoutMs,
|
|
253
|
+
stopReason: reason,
|
|
254
|
+
});
|
|
255
|
+
this.cleanupAfterSummarizerStop();
|
|
256
|
+
}
|
|
257
|
+
}, summarizerCloseTimeoutMs);
|
|
234
258
|
}
|
|
235
259
|
/**
|
|
236
260
|
* Implements initial delay before creating summarizer
|
|
@@ -309,6 +333,9 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
309
333
|
this.connectedState.off("connected", this.handleConnected);
|
|
310
334
|
this.connectedState.off("disconnected", this.handleDisconnected);
|
|
311
335
|
this.cleanupForwardedEvents();
|
|
336
|
+
if (this.summarizerStopTimeout !== undefined) {
|
|
337
|
+
clearTimeout(this.summarizerStopTimeout);
|
|
338
|
+
}
|
|
312
339
|
this._disposed = true;
|
|
313
340
|
}
|
|
314
341
|
setupForwardedEvents(summarizer) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../../src/summary/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAWjE,OAAO,EAAE,MAAM,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ft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tIDisposable,\n\tIEvent,\n\tIEventProvider,\n\tITelemetryBaseLogger,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { DriverErrorTypes } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tPerformanceEvent,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IThrottler } from \"../throttler.js\";\n\nimport type { ISummarizerClientElection } from \"./summarizerClientElection.js\";\nimport type {\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tISummarizer,\n} from \"./summarizerTypes.js\";\nimport { stopReasonCanRunLastSummary } from \"./summarizerUtils.js\";\nimport type { SummaryCollection } from \"./summaryCollection.js\";\nimport type {\n\tEnqueueSummarizeResult,\n\tISummarizeResults,\n} from \"./summaryDelayLoadedModule/index.js\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n\tOff = 0,\n\tStarting = 1,\n\tRunning = 2,\n\tStopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<\n\tSummarizerStopReason,\n\t\"parentNotConnected\" | \"notElectedParent\" | \"notElectedClient\"\n>;\ntype ShouldSummarizeState =\n\t| { shouldSummarize: true }\n\t| { shouldSummarize: false; stopReason: StopReason };\n\nexport interface IConnectedEvents extends IEvent {\n\t(event: \"connected\", listener: (clientId: string) => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n\treadonly connected: boolean;\n\n\t/**\n\t * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n\t * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n\t * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n\t * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n\t * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n\t */\n\treadonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n\tinitialDelayMs: number;\n\topsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager\n\textends TypedEventEmitter<ISummarizerEvents>\n\timplements IDisposable\n{\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly opsToBypassInitialDelay: number;\n\tprivate readonly initialDelayMs: number;\n\tprivate latestClientId: string | undefined;\n\tprivate state = SummaryManagerState.Off;\n\tprivate summarizer?: ISummarizer;\n\tprivate _disposed = false;\n\n\tpublic get disposed(): boolean {\n\t\treturn this._disposed;\n\t}\n\n\tpublic get currentState(): SummaryManagerState {\n\t\treturn this.state;\n\t}\n\n\tconstructor(\n\t\tprivate readonly clientElection: ISummarizerClientElection,\n\t\tprivate readonly connectedState: IConnectedState,\n\t\tprivate readonly summaryCollection: Pick<\n\t\t\tSummaryCollection,\n\t\t\t\"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\"\n\t\t>,\n\t\tparentLogger: ITelemetryBaseLogger,\n\t\t/**\n\t\t * Creates summarizer by asking interactive container to spawn summarizing container and\n\t\t * get back its Summarizer instance.\n\t\t */\n\t\tprivate readonly createSummarizerFn: () => Promise<ISummarizer>,\n\t\tprivate readonly startThrottler: IThrottler,\n\t\t{\n\t\t\tinitialDelayMs = defaultInitialDelayMs,\n\t\t\topsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n\t\t}: Readonly<Partial<ISummaryManagerConfig>> = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: parentLogger,\n\t\t\tnamespace: \"SummaryManager\",\n\t\t\tproperties: {\n\t\t\t\tall: { clientId: () => this.latestClientId },\n\t\t\t},\n\t\t});\n\n\t\tthis.connectedState.on(\"connected\", this.handleConnected);\n\t\tthis.connectedState.on(\"disconnected\", this.handleDisconnected);\n\t\tthis.latestClientId = this.connectedState.clientId;\n\n\t\tthis.opsToBypassInitialDelay = opsToBypassInitialDelay;\n\t\tthis.initialDelayMs = initialDelayMs;\n\t}\n\n\t/**\n\t * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n\t * a window between construction and starting where the caller can attach listeners.\n\t */\n\tpublic start(): void {\n\t\tthis.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.refreshSummarizer();\n\t}\n\n\tprivate readonly handleConnected = (clientId: string): void => {\n\t\tthis.latestClientId = clientId;\n\t\t// If we have a summarizer, it should have been either cancelled on disconnected by now.\n\t\t// But because of lastSummary process, it can still hang around, so there is not much we can\n\t\t// check or assert.\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate readonly handleDisconnected = (): void => {\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate static readonly isStartingOrRunning = (\n\t\tstate: SummaryManagerState,\n\t): state is SummaryManagerState.Starting | SummaryManagerState.Running =>\n\t\tstate === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n\tprivate getShouldSummarizeState(): ShouldSummarizeState {\n\t\tif (this.disposed) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\t// Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n\t\t// enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n\t\t// only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n\t\t// changing the electedParent will just cause us to transition to Starting again.\n\n\t\t// New Parent has been elected and it is not the current client, or\n\t\tif (this.connectedState.clientId !== this.clientElection.electedParentId) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedParent\" };\n\t\t}\n\n\t\t// We are not already running the summarizer and we are not the current elected client id.\n\t\tif (\n\t\t\tthis.state !== SummaryManagerState.Running &&\n\t\t\tthis.connectedState.clientId !== this.clientElection.electedClientId\n\t\t) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedClient\" };\n\t\t}\n\n\t\tif (!this.connectedState.connected) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\treturn { shouldSummarize: true };\n\t}\n\n\tprivate readonly refreshSummarizer = (): void => {\n\t\t// Transition states depending on shouldSummarize, which is a calculated property\n\t\t// that is only true if this client is connected and is the elected summarizer.\n\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\tswitch (this.state) {\n\t\t\tcase SummaryManagerState.Off: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Starting: {\n\t\t\t\t// Cannot take any action until summarizer is created\n\t\t\t\t// state transition will occur after creation\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Running: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\tthis.stop(shouldSummarizeState.stopReason);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Stopping: {\n\t\t\t\t// Cannot take any action until running summarizer finishes\n\t\t\t\t// state transition will occur after it stops\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate startSummarization(): void {\n\t\tassert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n\t\tthis.state = SummaryManagerState.Starting;\n\n\t\tassert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n\t\tthis.delayBeforeCreatingSummarizer()\n\t\t\t.then(async (startWithInitialDelay: boolean) => {\n\t\t\t\tif (this.disposed) {\n\t\t\t\t\treturn \"early exit (disposed)\";\n\t\t\t\t}\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// but only if creation was delayed. If it was not, then we want to ensure we always create\n\t\t\t\t// a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n\t\t\t\t// document out of broken state if it has too many ops and ordering service keeps nacking main\n\t\t\t\t// container (and thus it goes into cycle of reconnects)\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();\n\t\t\t\tif (\n\t\t\t\t\tstartWithInitialDelay &&\n\t\t\t\t\tshouldSummarizeStateEarlyStage.shouldSummarize === false\n\t\t\t\t) {\n\t\t\t\t\treturn `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;\n\t\t\t\t}\n\n\t\t\t\t// We transition to Running before requesting the summarizer, because after requesting we can't predict\n\t\t\t\t// when the electedClient will be replaced with the new summarizer client.\n\t\t\t\t// The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n\t\t\t\t// state === Starting || state === Running.\n\t\t\t\tassert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n\t\t\t\tthis.state = SummaryManagerState.Running;\n\n\t\t\t\tconst summarizer = await this.createSummarizerFn();\n\t\t\t\tthis.summarizer = summarizer;\n\t\t\t\tthis.setupForwardedEvents(summarizer);\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\t// In order to allow the last summary to run, we not only need a stop reason that would\n\t\t\t\t\t// allow it but also, startWithInitialDelay to be false (start the summarization immediately),\n\t\t\t\t\t// which would happen when we have a high enough number of unsummarized ops.\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartWithInitialDelay ||\n\t\t\t\t\t\t!stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.state = SummaryManagerState.Starting;\n\t\t\t\t\t\tsummarizer.stop(shouldSummarizeState.stopReason);\n\t\t\t\t\t\treturn `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;\n\t\t\t\t\t}\n\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"LastAttemptToSummarize\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst clientId = this.latestClientId!;\n\n\t\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{ eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n\t\t\t\t\tasync () => summarizer.run(clientId),\n\t\t\t\t);\n\t\t\t})\n\t\t\t.then((reason: string) => {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\treason,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\t\treason: \"exception\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\t// Most of exceptions happen due to container being closed while loading it, due to\n\t\t\t\t// summarizer container loosing connection while load.\n\t\t\t\t// Not worth reporting such errors as errors. That said, we might miss some real errors if\n\t\t\t\t// we ignore blindly, so try to narrow signature we are looking for - skip logging\n\t\t\t\t// error only if this client should no longer be a summarizer (which in practice\n\t\t\t\t// means it also lost connection), and error happened on load (we do not have summarizer).\n\t\t\t\t// We could annotate the error raised in Container.load where the container closed during load with no error\n\t\t\t\t// and check for that case here, but that does not seem to be necessary.\n\t\t\t\tif (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n\t\t\t\t\t// Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n\t\t\t\t\t// If failure happened on container load, we may not yet realized that socket disconnected, so check\n\t\t\t\t\t// offlineError.\n\t\t\t\t\tconst category =\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\terror?.errorType === DriverErrorTypes.offlineError ? \"generic\" : \"error\";\n\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizerException\",\n\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tassert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n\t\t\t\tthis.state = SummaryManagerState.Off;\n\n\t\t\t\tthis.cleanupForwardedEvents();\n\t\t\t\tthis.summarizer?.close();\n\t\t\t\tthis.summarizer = undefined;\n\n\t\t\t\tif (this.getShouldSummarizeState().shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\tprivate stop(reason: SummarizerStopReason): void {\n\t\tif (!SummaryManager.isStartingOrRunning(this.state)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.state = SummaryManagerState.Stopping;\n\n\t\t// Stopping the running summarizer client should trigger a change\n\t\t// in states when the running summarizer closes\n\t\tthis.summarizer?.stop(reason);\n\t}\n\n\t/**\n\t * Implements initial delay before creating summarizer\n\t * @returns `true`, if creation is delayed due to heuristics (not many ops to summarize).\n\t * `false` if summarizer should start immediately due to too many unsummarized ops.\n\t */\n\tprivate async delayBeforeCreatingSummarizer(): Promise<boolean> {\n\t\t// throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n\t\tlet delayMs = this.startThrottler.getDelay();\n\n\t\t// We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n\t\t// now we play it safe and launch a second copy.\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"CreatingSummarizer\",\n\t\t\tthrottlerDelay: delayMs,\n\t\t\tinitialDelay: this.initialDelayMs,\n\t\t\tstartThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n\t\t\topsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n\t\t\topsToBypassInitialDelay: this.opsToBypassInitialDelay,\n\t\t\telectedParentId: this.clientElection.electedParentId,\n\t\t\telectedClientId: this.clientElection.electedClientId,\n\t\t});\n\n\t\t// This delay helps ensure that last summarizer that might be left from previous client\n\t\t// has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n\t\t// If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n\t\t// understanding that we may see nacks because of such quick action.\n\t\t// A better design would be for summarizer election logic to always select current summarizer as\n\t\t// summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n\t\t// summarizer while it finishes its work and moves to exit.\n\t\t// It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n\t\t// critical boot sequence.\n\t\tlet startWithInitialDelay = false;\n\t\tif (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n\t\t\tstartWithInitialDelay = true;\n\t\t\tdelayMs = Math.max(delayMs, this.initialDelayMs);\n\t\t}\n\n\t\tif (delayMs > 0) {\n\t\t\tlet timer: number | undefined;\n\t\t\tlet resolveOpPromiseFn: (value: void | PromiseLike<void>) => void;\n\t\t\t// Create a listener that will break the delay if we've exceeded the initial delay ops count.\n\t\t\tconst opsListenerFn = (): void => {\n\t\t\t\tif (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolveOpPromiseFn();\n\t\t\t\t}\n\t\t\t};\n\t\t\t// Create a Promise that will resolve when the delay expires.\n\t\t\tconst delayPromise = new Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => resolve(), delayMs);\n\t\t\t});\n\t\t\t// Create a Promise that will resolve if the ops count passes the threshold.\n\t\t\tconst opPromise = new Promise<void>((resolve) => {\n\t\t\t\tresolveOpPromiseFn = resolve;\n\t\t\t});\n\t\t\tthis.summaryCollection.addOpListener(opsListenerFn);\n\t\t\tawait Promise.race([delayPromise, opPromise]);\n\t\t\tthis.summaryCollection.removeOpListener(opsListenerFn);\n\t\t}\n\t\treturn startWithInitialDelay;\n\t}\n\n\tpublic summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow new Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.summarizeOnDemand(options);\n\t}\n\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow new Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.enqueueSummarize(options);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.connectedState.off(\"connected\", this.handleConnected);\n\t\tthis.connectedState.off(\"disconnected\", this.handleDisconnected);\n\t\tthis.cleanupForwardedEvents();\n\t\tthis._disposed = true;\n\t}\n\n\tprivate readonly forwardedEventsCleanup: (() => void)[] = [];\n\n\tprivate setupForwardedEvents(summarizer: ISummarizer): void {\n\t\tfor (const event of [\n\t\t\t\"summarize\",\n\t\t\t\"summarizeAllAttemptsFailed\",\n\t\t\t\"summarizerStop\",\n\t\t\t\"summarizerStart\",\n\t\t\t\"summarizerStartupFailed\",\n\t\t\t\"summarizeTimeout\",\n\t\t] as const) {\n\t\t\tconst listener = (...args: unknown[]): void => {\n\t\t\t\tthis.emit(event, ...args);\n\t\t\t};\n\t\t\t// TODO: better typing here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n\t\t\tsummarizer.on(event as any, listener);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n\t\t\tthis.forwardedEventsCleanup.push(() => summarizer.off(event as any, listener));\n\t\t}\n\t}\n\n\tprivate cleanupForwardedEvents(): void {\n\t\tfor (const cleanup of this.forwardedEventsCleanup) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.forwardedEventsCleanup.length = 0;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../../src/summary/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAWjE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6CAA6C,CAAC;AAC/E,OAAO,EAEN,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,0CAA0C,CAAC;AAUlD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AAOnE,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC9B,2DAAO,CAAA;IACP,qEAAY,CAAA;IACZ,mEAAW,CAAA;IACX,qEAAY,CAAA;AAC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ACrG,UAAU,CAAC,EAAE,CAAC,KAAY,EAAE,QAAQ,CAAC,CAAC;YACtC,qGAAqG;YACrG,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAY,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChF,CAAC;IACF,CAAC;IAEO,sBAAsB;QAC7B,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,sBAAsB,EAAE,CAAC;YACnD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,IAAI,CAAC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IACxC,CAAC;;AAvVuB,kCAAmB,GAAG,CAC7C,KAA0B,EAC4C,EAAE,CACxE,KAAK,KAAK,mBAAmB,CAAC,QAAQ,IAAI,KAAK,KAAK,mBAAmB,CAAC,OAAO,AAHrC,CAGsC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport type {\n\tISummarizerEvents,\n\tSummarizerStopReason,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tIDisposable,\n\tIEvent,\n\tIEventProvider,\n\tITelemetryBaseLogger,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { DriverErrorTypes } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ITelemetryLoggerExt,\n\tPerformanceEvent,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { IThrottler } from \"../throttler.js\";\n\nimport type { ISummarizerClientElection } from \"./summarizerClientElection.js\";\nimport type {\n\tIEnqueueSummarizeOptions,\n\tIOnDemandSummarizeOptions,\n\tISummarizer,\n} from \"./summarizerTypes.js\";\nimport { stopReasonCanRunLastSummary } from \"./summarizerUtils.js\";\nimport type { SummaryCollection } from \"./summaryCollection.js\";\nimport type {\n\tEnqueueSummarizeResult,\n\tISummarizeResults,\n} from \"./summaryDelayLoadedModule/index.js\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n\tOff = 0,\n\tStarting = 1,\n\tRunning = 2,\n\tStopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<\n\tSummarizerStopReason,\n\t\"parentNotConnected\" | \"notElectedParent\" | \"notElectedClient\"\n>;\ntype ShouldSummarizeState =\n\t| { shouldSummarize: true }\n\t| { shouldSummarize: false; stopReason: StopReason };\n\nexport interface IConnectedEvents extends IEvent {\n\t(event: \"connected\", listener: (clientId: string) => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n\treadonly connected: boolean;\n\n\t/**\n\t * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n\t * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n\t * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n\t * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n\t * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n\t */\n\treadonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n\tinitialDelayMs: number;\n\topsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager\n\textends TypedEventEmitter<ISummarizerEvents>\n\timplements IDisposable\n{\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly opsToBypassInitialDelay: number;\n\tprivate readonly initialDelayMs: number;\n\tprivate latestClientId: string | undefined;\n\tprivate state = SummaryManagerState.Off;\n\tprivate summarizer?: ISummarizer;\n\tprivate _disposed = false;\n\tprivate summarizerStopTimeout?: ReturnType<typeof setTimeout>;\n\n\tpublic get disposed(): boolean {\n\t\treturn this._disposed;\n\t}\n\n\tpublic get currentState(): SummaryManagerState {\n\t\treturn this.state;\n\t}\n\n\tconstructor(\n\t\tprivate readonly clientElection: ISummarizerClientElection,\n\t\tprivate readonly connectedState: IConnectedState,\n\t\tprivate readonly summaryCollection: Pick<\n\t\t\tSummaryCollection,\n\t\t\t\"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\"\n\t\t>,\n\t\tparentLogger: ITelemetryBaseLogger,\n\t\t/**\n\t\t * Creates summarizer by asking interactive container to spawn summarizing container and\n\t\t * get back its Summarizer instance.\n\t\t */\n\t\tprivate readonly createSummarizerFn: () => Promise<ISummarizer>,\n\t\tprivate readonly startThrottler: IThrottler,\n\t\t{\n\t\t\tinitialDelayMs = defaultInitialDelayMs,\n\t\t\topsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n\t\t}: Readonly<Partial<ISummaryManagerConfig>> = {},\n\t) {\n\t\tsuper();\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: parentLogger,\n\t\t\tnamespace: \"SummaryManager\",\n\t\t\tproperties: {\n\t\t\t\tall: { clientId: () => this.latestClientId },\n\t\t\t},\n\t\t});\n\n\t\tthis.connectedState.on(\"connected\", this.handleConnected);\n\t\tthis.connectedState.on(\"disconnected\", this.handleDisconnected);\n\t\tthis.latestClientId = this.connectedState.clientId;\n\n\t\tthis.opsToBypassInitialDelay = opsToBypassInitialDelay;\n\t\tthis.initialDelayMs = initialDelayMs;\n\t}\n\n\t/**\n\t * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n\t * a window between construction and starting where the caller can attach listeners.\n\t */\n\tpublic start(): void {\n\t\tthis.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.refreshSummarizer();\n\t}\n\n\tprivate readonly handleConnected = (clientId: string): void => {\n\t\tthis.latestClientId = clientId;\n\t\t// If we have a summarizer, it should have been either cancelled on disconnected by now.\n\t\t// But because of lastSummary process, it can still hang around, so there is not much we can\n\t\t// check or assert.\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate readonly handleDisconnected = (): void => {\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate static readonly isStartingOrRunning = (\n\t\tstate: SummaryManagerState,\n\t): state is SummaryManagerState.Starting | SummaryManagerState.Running =>\n\t\tstate === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n\tprivate getShouldSummarizeState(): ShouldSummarizeState {\n\t\tif (this.disposed) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\t// Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n\t\t// enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n\t\t// only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n\t\t// changing the electedParent will just cause us to transition to Starting again.\n\n\t\t// New Parent has been elected and it is not the current client, or\n\t\tif (this.connectedState.clientId !== this.clientElection.electedParentId) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedParent\" };\n\t\t}\n\n\t\t// We are not already running the summarizer and we are not the current elected client id.\n\t\tif (\n\t\t\tthis.state !== SummaryManagerState.Running &&\n\t\t\tthis.connectedState.clientId !== this.clientElection.electedClientId\n\t\t) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedClient\" };\n\t\t}\n\n\t\tif (!this.connectedState.connected) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\treturn { shouldSummarize: true };\n\t}\n\n\tprivate readonly refreshSummarizer = (): void => {\n\t\t// Transition states depending on shouldSummarize, which is a calculated property\n\t\t// that is only true if this client is connected and is the elected summarizer.\n\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\tswitch (this.state) {\n\t\t\tcase SummaryManagerState.Off: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Starting: {\n\t\t\t\t// Cannot take any action until summarizer is created\n\t\t\t\t// state transition will occur after creation\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Running: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\tthis.stop(shouldSummarizeState.stopReason);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Stopping: {\n\t\t\t\t// Cannot take any action until running summarizer finishes\n\t\t\t\t// state transition will occur after it stops\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate startSummarization(): void {\n\t\tassert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n\t\tthis.state = SummaryManagerState.Starting;\n\n\t\tassert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n\t\tthis.delayBeforeCreatingSummarizer()\n\t\t\t.then(async (startWithInitialDelay: boolean) => {\n\t\t\t\tif (this.disposed) {\n\t\t\t\t\treturn \"early exit (disposed)\";\n\t\t\t\t}\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// but only if creation was delayed. If it was not, then we want to ensure we always create\n\t\t\t\t// a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n\t\t\t\t// document out of broken state if it has too many ops and ordering service keeps nacking main\n\t\t\t\t// container (and thus it goes into cycle of reconnects)\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();\n\t\t\t\tif (\n\t\t\t\t\tstartWithInitialDelay &&\n\t\t\t\t\tshouldSummarizeStateEarlyStage.shouldSummarize === false\n\t\t\t\t) {\n\t\t\t\t\treturn `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;\n\t\t\t\t}\n\n\t\t\t\t// We transition to Running before requesting the summarizer, because after requesting we can't predict\n\t\t\t\t// when the electedClient will be replaced with the new summarizer client.\n\t\t\t\t// The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n\t\t\t\t// state === Starting || state === Running.\n\t\t\t\tassert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n\t\t\t\tthis.state = SummaryManagerState.Running;\n\n\t\t\t\tconst summarizer = await this.createSummarizerFn();\n\t\t\t\tthis.summarizer = summarizer;\n\t\t\t\tthis.setupForwardedEvents(summarizer);\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\t// In order to allow the last summary to run, we not only need a stop reason that would\n\t\t\t\t\t// allow it but also, startWithInitialDelay to be false (start the summarization immediately),\n\t\t\t\t\t// which would happen when we have a high enough number of unsummarized ops.\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartWithInitialDelay ||\n\t\t\t\t\t\t!stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.state = SummaryManagerState.Starting;\n\t\t\t\t\t\tsummarizer.stop(shouldSummarizeState.stopReason);\n\t\t\t\t\t\treturn `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;\n\t\t\t\t\t}\n\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"LastAttemptToSummarize\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst clientId = this.latestClientId!;\n\n\t\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{ eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n\t\t\t\t\tasync () => summarizer.run(clientId),\n\t\t\t\t);\n\t\t\t})\n\t\t\t.then((reason: string) => {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\treason,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\t\treason: \"exception\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\t// Most of exceptions happen due to container being closed while loading it, due to\n\t\t\t\t// summarizer container loosing connection while load.\n\t\t\t\t// Not worth reporting such errors as errors. That said, we might miss some real errors if\n\t\t\t\t// we ignore blindly, so try to narrow signature we are looking for - skip logging\n\t\t\t\t// error only if this client should no longer be a summarizer (which in practice\n\t\t\t\t// means it also lost connection), and error happened on load (we do not have summarizer).\n\t\t\t\t// We could annotate the error raised in Container.load where the container closed during load with no error\n\t\t\t\t// and check for that case here, but that does not seem to be necessary.\n\t\t\t\tif (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n\t\t\t\t\t// Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n\t\t\t\t\t// If failure happened on container load, we may not yet realized that socket disconnected, so check\n\t\t\t\t\t// offlineError.\n\t\t\t\t\tconst category =\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\terror?.errorType === DriverErrorTypes.offlineError ? \"generic\" : \"error\";\n\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizerException\",\n\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tassert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n\t\t\t\tthis.cleanupAfterSummarizerStop();\n\t\t\t});\n\t}\n\n\tprivate cleanupAfterSummarizerStop(): void {\n\t\tthis.state = SummaryManagerState.Off;\n\n\t\t// Clear any pending stop timeout to avoid it firing for a different summarizer\n\t\tif (this.summarizerStopTimeout !== undefined) {\n\t\t\tclearTimeout(this.summarizerStopTimeout);\n\t\t\tthis.summarizerStopTimeout = undefined;\n\t\t}\n\n\t\tthis.cleanupForwardedEvents();\n\t\tthis.summarizer?.close();\n\t\tthis.summarizer = undefined;\n\n\t\tif (this.getShouldSummarizeState().shouldSummarize) {\n\t\t\tthis.startSummarization();\n\t\t}\n\t}\n\n\tprivate stop(reason: SummarizerStopReason): void {\n\t\tif (!SummaryManager.isStartingOrRunning(this.state)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.state = SummaryManagerState.Stopping;\n\n\t\t// Stopping the running summarizer client should trigger a change\n\t\t// in states when the running summarizer closes\n\t\tthis.summarizer?.stop(reason);\n\n\t\tconst summarizerCloseTimeoutMs = 2 * 60 * 1000; // 2 minutes\n\t\t// Clear any existing timeout before setting a new one\n\t\tif (this.summarizerStopTimeout !== undefined) {\n\t\t\tclearTimeout(this.summarizerStopTimeout);\n\t\t}\n\t\t// Set a timeout to force cleanup if the summarizer doesn't close in time\n\t\tthis.summarizerStopTimeout = setTimeout(() => {\n\t\t\tif (this.state === SummaryManagerState.Stopping && this.summarizer !== undefined) {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"SummarizerStopTimeout\",\n\t\t\t\t\ttimeoutMs: summarizerCloseTimeoutMs,\n\t\t\t\t\tstopReason: reason,\n\t\t\t\t});\n\t\t\t\tthis.cleanupAfterSummarizerStop();\n\t\t\t}\n\t\t}, summarizerCloseTimeoutMs);\n\t}\n\n\t/**\n\t * Implements initial delay before creating summarizer\n\t * @returns `true`, if creation is delayed due to heuristics (not many ops to summarize).\n\t * `false` if summarizer should start immediately due to too many unsummarized ops.\n\t */\n\tprivate async delayBeforeCreatingSummarizer(): Promise<boolean> {\n\t\t// throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n\t\tlet delayMs = this.startThrottler.getDelay();\n\n\t\t// We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n\t\t// now we play it safe and launch a second copy.\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"CreatingSummarizer\",\n\t\t\tthrottlerDelay: delayMs,\n\t\t\tinitialDelay: this.initialDelayMs,\n\t\t\tstartThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n\t\t\topsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n\t\t\topsToBypassInitialDelay: this.opsToBypassInitialDelay,\n\t\t\telectedParentId: this.clientElection.electedParentId,\n\t\t\telectedClientId: this.clientElection.electedClientId,\n\t\t});\n\n\t\t// This delay helps ensure that last summarizer that might be left from previous client\n\t\t// has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n\t\t// If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n\t\t// understanding that we may see nacks because of such quick action.\n\t\t// A better design would be for summarizer election logic to always select current summarizer as\n\t\t// summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n\t\t// summarizer while it finishes its work and moves to exit.\n\t\t// It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n\t\t// critical boot sequence.\n\t\tlet startWithInitialDelay = false;\n\t\tif (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n\t\t\tstartWithInitialDelay = true;\n\t\t\tdelayMs = Math.max(delayMs, this.initialDelayMs);\n\t\t}\n\n\t\tif (delayMs > 0) {\n\t\t\tlet timer: number | undefined;\n\t\t\tlet resolveOpPromiseFn: (value: void | PromiseLike<void>) => void;\n\t\t\t// Create a listener that will break the delay if we've exceeded the initial delay ops count.\n\t\t\tconst opsListenerFn = (): void => {\n\t\t\t\tif (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolveOpPromiseFn();\n\t\t\t\t}\n\t\t\t};\n\t\t\t// Create a Promise that will resolve when the delay expires.\n\t\t\tconst delayPromise = new Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => resolve(), delayMs);\n\t\t\t});\n\t\t\t// Create a Promise that will resolve if the ops count passes the threshold.\n\t\t\tconst opPromise = new Promise<void>((resolve) => {\n\t\t\t\tresolveOpPromiseFn = resolve;\n\t\t\t});\n\t\t\tthis.summaryCollection.addOpListener(opsListenerFn);\n\t\t\tawait Promise.race([delayPromise, opPromise]);\n\t\t\tthis.summaryCollection.removeOpListener(opsListenerFn);\n\t\t}\n\t\treturn startWithInitialDelay;\n\t}\n\n\tpublic summarizeOnDemand(options: IOnDemandSummarizeOptions): ISummarizeResults {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow new Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.summarizeOnDemand(options);\n\t}\n\n\tpublic enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow new Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.enqueueSummarize(options);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.connectedState.off(\"connected\", this.handleConnected);\n\t\tthis.connectedState.off(\"disconnected\", this.handleDisconnected);\n\t\tthis.cleanupForwardedEvents();\n\t\tif (this.summarizerStopTimeout !== undefined) {\n\t\t\tclearTimeout(this.summarizerStopTimeout);\n\t\t}\n\t\tthis._disposed = true;\n\t}\n\n\tprivate readonly forwardedEventsCleanup: (() => void)[] = [];\n\n\tprivate setupForwardedEvents(summarizer: ISummarizer): void {\n\t\tfor (const event of [\n\t\t\t\"summarize\",\n\t\t\t\"summarizeAllAttemptsFailed\",\n\t\t\t\"summarizerStop\",\n\t\t\t\"summarizerStart\",\n\t\t\t\"summarizerStartupFailed\",\n\t\t\t\"summarizeTimeout\",\n\t\t] as const) {\n\t\t\tconst listener = (...args: unknown[]): void => {\n\t\t\t\tthis.emit(event, ...args);\n\t\t\t};\n\t\t\t// TODO: better typing here\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n\t\t\tsummarizer.on(event as any, listener);\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument\n\t\t\tthis.forwardedEventsCleanup.push(() => summarizer.off(event as any, listener));\n\t\t}\n\t}\n\n\tprivate cleanupForwardedEvents(): void {\n\t\tfor (const cleanup of this.forwardedEventsCleanup) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.forwardedEventsCleanup.length = 0;\n\t}\n}\n"]}
|