@fluidframework/container-runtime 0.57.2 → 0.58.1000
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/batchTracker.d.ts +26 -0
- package/dist/batchTracker.d.ts.map +1 -0
- package/dist/batchTracker.js +59 -0
- package/dist/batchTracker.js.map +1 -0
- package/dist/containerRuntime.d.ts +2 -1
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +63 -27
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreContext.js +1 -1
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStores.js +1 -1
- package/dist/dataStores.js.map +1 -1
- package/dist/garbageCollection.d.ts +1 -0
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +6 -4
- package/dist/garbageCollection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +1 -6
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/runningSummarizer.d.ts +1 -1
- package/dist/runningSummarizer.d.ts.map +1 -1
- package/dist/runningSummarizer.js +1 -1
- package/dist/runningSummarizer.js.map +1 -1
- package/dist/summarizer.d.ts +3 -4
- package/dist/summarizer.d.ts.map +1 -1
- package/dist/summarizer.js +8 -9
- package/dist/summarizer.js.map +1 -1
- package/dist/summaryGenerator.d.ts +1 -1
- package/dist/summaryGenerator.d.ts.map +1 -1
- package/dist/summaryGenerator.js +1 -1
- package/dist/summaryGenerator.js.map +1 -1
- package/dist/summaryManager.d.ts +2 -6
- package/dist/summaryManager.d.ts.map +1 -1
- package/dist/summaryManager.js +4 -10
- package/dist/summaryManager.js.map +1 -1
- package/lib/batchTracker.d.ts +26 -0
- package/lib/batchTracker.d.ts.map +1 -0
- package/lib/batchTracker.js +54 -0
- package/lib/batchTracker.js.map +1 -0
- package/lib/containerRuntime.d.ts +2 -1
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +63 -27
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreContext.js +2 -2
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStores.js +1 -1
- package/lib/dataStores.js.map +1 -1
- package/lib/garbageCollection.d.ts +1 -0
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +4 -2
- package/lib/garbageCollection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +1 -6
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/runningSummarizer.d.ts +1 -1
- package/lib/runningSummarizer.d.ts.map +1 -1
- package/lib/runningSummarizer.js +1 -1
- package/lib/runningSummarizer.js.map +1 -1
- package/lib/summarizer.d.ts +3 -4
- package/lib/summarizer.d.ts.map +1 -1
- package/lib/summarizer.js +8 -9
- package/lib/summarizer.js.map +1 -1
- package/lib/summaryGenerator.d.ts +1 -1
- package/lib/summaryGenerator.d.ts.map +1 -1
- package/lib/summaryGenerator.js +1 -1
- package/lib/summaryGenerator.js.map +1 -1
- package/lib/summaryManager.d.ts +2 -6
- package/lib/summaryManager.d.ts.map +1 -1
- package/lib/summaryManager.js +5 -11
- package/lib/summaryManager.js.map +1 -1
- package/package.json +15 -15
- package/src/batchTracker.ts +80 -0
- package/src/containerRuntime.ts +84 -31
- package/src/dataStoreContext.ts +2 -2
- package/src/dataStores.ts +1 -1
- package/src/garbageCollection.ts +11 -10
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +4 -8
- package/src/runningSummarizer.ts +3 -3
- package/src/summarizer.ts +8 -8
- package/src/summaryGenerator.ts +2 -2
- package/src/summaryManager.ts +5 -20
package/lib/summaryManager.d.ts
CHANGED
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
6
|
-
import { TypedEventEmitter } from "@fluidframework/common-utils";
|
|
7
6
|
import { ISummarizerClientElection } from "./summarizerClientElection";
|
|
8
7
|
import { IThrottler } from "./throttler";
|
|
9
|
-
import { ISummarizer, ISummarizerOptions
|
|
8
|
+
import { ISummarizer, ISummarizerOptions } from "./summarizerTypes";
|
|
10
9
|
import { SummaryCollection } from "./summaryCollection";
|
|
11
10
|
export declare enum SummaryManagerState {
|
|
12
11
|
Off = 0,
|
|
@@ -35,9 +34,6 @@ export interface IConnectedState extends IEventProvider<IConnectedEvents> {
|
|
|
35
34
|
*/
|
|
36
35
|
readonly clientId: string | undefined;
|
|
37
36
|
}
|
|
38
|
-
export interface ISummaryManagerEvents extends IEvent {
|
|
39
|
-
(event: "summarizerWarning", listener: (warning: ISummarizingWarning) => void): any;
|
|
40
|
-
}
|
|
41
37
|
export interface ISummaryManagerConfig {
|
|
42
38
|
initialDelayMs: number;
|
|
43
39
|
opsToBypassInitialDelay: number;
|
|
@@ -47,7 +43,7 @@ export interface ISummaryManagerConfig {
|
|
|
47
43
|
* It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or
|
|
48
44
|
* stopping existing summarizer client.
|
|
49
45
|
*/
|
|
50
|
-
export declare class SummaryManager
|
|
46
|
+
export declare class SummaryManager implements IDisposable {
|
|
51
47
|
private readonly clientElection;
|
|
52
48
|
private readonly connectedState;
|
|
53
49
|
private readonly summaryCollection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryManager.d.ts","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,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,WAAW,CAAC,kBAAkB,CAAC,CAM/D;IAEK,OAAO;CAMjB"}
|
package/lib/summaryManager.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { assert } from "@fluidframework/common-utils";
|
|
6
6
|
import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
7
7
|
import { DriverErrorType } from "@fluidframework/driver-definitions";
|
|
8
|
-
import { createSummarizingWarning } from "./summarizer";
|
|
9
8
|
const defaultInitialDelayMs = 5000;
|
|
10
9
|
const defaultOpsToBypassInitialDelay = 4000;
|
|
11
10
|
export var SummaryManagerState;
|
|
@@ -20,12 +19,11 @@ export var SummaryManagerState;
|
|
|
20
19
|
* It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or
|
|
21
20
|
* stopping existing summarizer client.
|
|
22
21
|
*/
|
|
23
|
-
export class SummaryManager
|
|
22
|
+
export class SummaryManager {
|
|
24
23
|
constructor(clientElection, connectedState, summaryCollection, parentLogger,
|
|
25
24
|
/** Creates summarizer by asking interactive container to spawn summarizing container and
|
|
26
25
|
* get back its Summarizer instance. */
|
|
27
26
|
requestSummarizerFn, startThrottler, { initialDelayMs = defaultInitialDelayMs, opsToBypassInitialDelay = defaultOpsToBypassInitialDelay, } = {}, summarizerOptions) {
|
|
28
|
-
super();
|
|
29
27
|
this.clientElection = clientElection;
|
|
30
28
|
this.connectedState = connectedState;
|
|
31
29
|
this.summaryCollection = summaryCollection;
|
|
@@ -146,7 +144,6 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
146
144
|
}
|
|
147
145
|
assert(this.state === SummaryManagerState.Starting, 0x263 /* "Expected: starting" */);
|
|
148
146
|
this.state = SummaryManagerState.Running;
|
|
149
|
-
summarizer.on("summarizingError", (warning) => this.emit("summarizerWarning", warning));
|
|
150
147
|
this.summarizer = summarizer;
|
|
151
148
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
152
149
|
const clientId = this.latestClientId;
|
|
@@ -158,8 +155,8 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
158
155
|
// we ignore blindly, so try to narrow signature we are looking for - skip logging
|
|
159
156
|
// error only if this client should no longer be a summarizer (which in practice
|
|
160
157
|
// means it also lost connection), and error happened on load (we do not have summarizer).
|
|
161
|
-
// We could
|
|
162
|
-
// but that does not seem to be necessary.
|
|
158
|
+
// We could annotate the error raised in Container.load where the container closed during load with no error
|
|
159
|
+
// and check for that case here, but that does not seem to be necessary.
|
|
163
160
|
if (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {
|
|
164
161
|
// Report any failure as an error unless it was due to cancellation (like "disconnected" error)
|
|
165
162
|
// If failure happened on container load, we may not yet realized that socket disconnected, so check
|
|
@@ -169,7 +166,6 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
169
166
|
eventName: "SummarizerException",
|
|
170
167
|
category,
|
|
171
168
|
}, error);
|
|
172
|
-
this.emit("summarizerWarning", error);
|
|
173
169
|
// Note that summarizer may keep going (like doing last summary).
|
|
174
170
|
// Ideally we await stopping process, but this code path is due to a bug
|
|
175
171
|
// that needs to be fixed either way.
|
|
@@ -208,15 +204,13 @@ export class SummaryManager extends TypedEventEmitter {
|
|
|
208
204
|
async delayBeforeCreatingSummarizer() {
|
|
209
205
|
// throttle creation of new summarizer containers to prevent spamming the server with websocket connections
|
|
210
206
|
let delayMs = this.startThrottler.getDelay();
|
|
211
|
-
if (delayMs > 0 && delayMs > this.startThrottler.maxDelayMs) {
|
|
212
|
-
this.emit("summarizerWarning", createSummarizingWarning("summaryManagerCreateSummarizerMaxThrottleDelay", false));
|
|
213
|
-
}
|
|
214
207
|
// We have been elected the summarizer. Some day we may be able to summarize with a live document but for
|
|
215
208
|
// now we play it safe and launch a second copy.
|
|
216
209
|
this.logger.sendTelemetryEvent({
|
|
217
210
|
eventName: "CreatingSummarizer",
|
|
218
211
|
throttlerDelay: delayMs,
|
|
219
212
|
initialDelay: this.initialDelayMs,
|
|
213
|
+
startThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,
|
|
220
214
|
opsSinceLastAck: this.summaryCollection.opsSinceLastAck,
|
|
221
215
|
opsToBypassInitialDelay: this.opsToBypassInitialDelay,
|
|
222
216
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAWxD,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC3B,2DAAO,CAAA;IACP,qEAAY,CAAA;IACZ,mEAAW,CAAA;IACX,qEAAY,CAAA;AAChB,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AA2CD;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,iBAAwC;IAexE,YACqB,cAAyC,EACzC,cAA+B,EAC/B,iBACoE,EACrF,YAA8B;IAC9B;2CACuC;IACtB,mBAA+C,EAC/C,cAA0B,EAC3C,EACI,cAAc,GAAG,qBAAqB,EACtC,uBAAuB,GAAG,8BAA8B,MACd,EAAE,EAC/B,iBAAyD;QAE1E,KAAK,EAAE,CAAC;QAfS,mBAAc,GAAd,cAAc,CAA2B;QACzC,mBAAc,GAAd,cAAc,CAAiB;QAC/B,sBAAiB,GAAjB,iBAAiB,CACmD;QAIpE,wBAAmB,GAAnB,mB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;iBACxB;YACL,CAAC,CAAC;YACF,6DAA6D;YAC7D,MAAM,YAAY,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;gBAC/C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YACH,4EAA4E;YAC5E,MAAM,SAAS,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,GAAG,kBAAkB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACpF,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;YACpD,MAAM,OAAO,CAAC,IAAI,CAAC,CAAE,YAAY,EAAE,SAAS,CAAE,CAAC,CAAC;YAChD,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC;SAC1D;QACD,OAAO,qBAAqB,CAAC;IACjC,CAAC;IAkBM,OAAO;QACV,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,0BAA0B,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC5E,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC3D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;;AAvOuB,kCAAmB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACzE,KAAK,KAAK,mBAAmB,CAAC,QAAQ,IAAI,KAAK,KAAK,mBAAmB,CAAC,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter, assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { createSummarizingWarning } from \"./summarizer\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { IThrottler } from \"./throttler\";\nimport {\n ISummarizer,\n ISummarizerOptions,\n ISummarizingWarning,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n Off = 0,\n Starting = 1,\n Running = 2,\n Stopping = 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<SummarizerStopReason, \"parentNotConnected\" | \"parentShouldNotSummarize\">;\ntype ShouldSummarizeState =\n | { shouldSummarize: true; }\n | { shouldSummarize: false; stopReason: StopReason; };\n\nexport interface IConnectedEvents extends IEvent {\n (event: \"connected\", listener: (clientId: string) => void);\n (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 readonly connected: boolean;\n\n /**\n * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n */\n readonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerEvents extends IEvent {\n (event: \"summarizerWarning\", listener: (warning: ISummarizingWarning) => void);\n}\n\nexport interface ISummaryManagerConfig {\n initialDelayMs: number;\n opsToBypassInitialDelay: 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 extends TypedEventEmitter<ISummaryManagerEvents> implements IDisposable {\n private readonly logger: ITelemetryLogger;\n private readonly opsToBypassInitialDelay: number;\n private readonly initialDelayMs: number;\n private latestClientId: string | undefined;\n private state = SummaryManagerState.Off;\n private summarizer?: ISummarizer;\n private _disposed = false;\n\n public get disposed() {\n return this._disposed;\n }\n\n public get currentState() { return this.state; }\n\n constructor(\n private readonly clientElection: ISummarizerClientElection,\n private readonly connectedState: IConnectedState,\n private readonly summaryCollection:\n Pick<SummaryCollection, \"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\">,\n parentLogger: ITelemetryLogger,\n /** Creates summarizer by asking interactive container to spawn summarizing container and\n * get back its Summarizer instance. */\n private readonly requestSummarizerFn: () => Promise<ISummarizer>,\n private readonly startThrottler: IThrottler,\n {\n initialDelayMs = defaultInitialDelayMs,\n opsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n }: Readonly<Partial<ISummaryManagerConfig>> = {},\n private readonly summarizerOptions?: Readonly<Partial<ISummarizerOptions>>,\n ) {\n super();\n\n this.logger = ChildLogger.create(\n parentLogger,\n \"SummaryManager\",\n {all:{ clientId: () => this.latestClientId }});\n\n this.connectedState.on(\"connected\", this.handleConnected);\n this.connectedState.on(\"disconnected\", this.handleDisconnected);\n this.latestClientId = this.connectedState.clientId;\n\n this.opsToBypassInitialDelay = opsToBypassInitialDelay;\n this.initialDelayMs = initialDelayMs;\n }\n\n /**\n * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n * a window between construction and starting where the caller can attach listeners.\n */\n public start(): void {\n this.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.refreshSummarizer();\n }\n\n private readonly handleConnected = (clientId: string) => {\n this.latestClientId = clientId;\n // If we have a summarizer, it should have been either cancelled on disconnected by now.\n // But because of lastSummary process, it can still hang around, so there is not much we can\n // check or assert.\n this.refreshSummarizer();\n };\n\n private readonly handleDisconnected = () => {\n this.refreshSummarizer();\n };\n\n private static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n state === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n private getShouldSummarizeState(): ShouldSummarizeState {\n if (!this.connectedState.connected) {\n return { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n } else if (this.connectedState.clientId !== this.clientElection.electedClientId) {\n return { shouldSummarize: false, stopReason: \"parentShouldNotSummarize\" };\n } else if (this.disposed) {\n assert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n } else {\n return { shouldSummarize: true };\n }\n }\n\n private readonly refreshSummarizer = () => {\n // Transition states depending on shouldSummarize, which is a calculated property\n // that is only true if this client is connected and is the elected summarizer.\n const shouldSummarizeState = this.getShouldSummarizeState();\n switch (this.state) {\n case SummaryManagerState.Off: {\n if (shouldSummarizeState.shouldSummarize) {\n this.startSummarization();\n }\n return;\n }\n case SummaryManagerState.Starting: {\n // Cannot take any action until summarizer is created\n // state transition will occur after creation\n return;\n }\n case SummaryManagerState.Running: {\n if (shouldSummarizeState.shouldSummarize === false) {\n this.stop(shouldSummarizeState.stopReason);\n }\n return;\n }\n case SummaryManagerState.Stopping: {\n // Cannot take any action until running summarizer finishes\n // state transition will occur after it stops\n return;\n }\n default: {\n return;\n }\n }\n };\n\n private startSummarization() {\n assert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n this.state = SummaryManagerState.Starting;\n\n assert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n let reason = \"unknown\";\n\n this.delayBeforeCreatingSummarizer().then(async (startWithInitialDelay: boolean) => {\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n // but only if creation was delayed. If it was not, then we want to ensure we always create\n // a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n // document out of broken state if it has too many ops and ordering service keeps nacking main\n // container (and thus it goes into cycle of reconnects)\n if (startWithInitialDelay && this.getShouldSummarizeState().shouldSummarize === false) {\n return;\n }\n\n const summarizer = await this.requestSummarizerFn();\n\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n const shouldSummarizeState = this.getShouldSummarizeState();\n if (shouldSummarizeState.shouldSummarize === false) {\n summarizer.stop(shouldSummarizeState.stopReason);\n return;\n }\n\n assert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n this.state = SummaryManagerState.Running;\n\n summarizer.on(\"summarizingError\",\n (warning: ISummarizingWarning) => this.emit(\"summarizerWarning\", warning));\n this.summarizer = summarizer;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const clientId = this.latestClientId!;\n\n reason = await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n async () => summarizer.run(clientId, this.summarizerOptions),\n );\n }).catch((error) => {\n // Most of exceptions happen due to container being closed while loading it, due to\n // summarizer container loosing connection while load.\n // Not worth reporting such errors as errors. That said, we might miss some real errors if\n // we ignore blindly, so try to narrow signature we are looking for - skip logging\n // error only if this client should no longer be a summarizer (which in practice\n // means it also lost connection), and error happened on load (we do not have summarizer).\n // We could add error.fluidErrorCode !== \"containerClosedWithoutErrorDuringLoad\" check to narrow it down,\n // but that does not seem to be necessary.\n if (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on container load, we may not yet realized that socket disconnected, so check\n // offlineError.\n const category = error?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n this.logger.sendTelemetryEvent(\n {\n eventName: \"SummarizerException\",\n category,\n },\n error);\n this.emit(\"summarizerWarning\", error);\n\n // Note that summarizer may keep going (like doing last summary).\n // Ideally we await stopping process, but this code path is due to a bug\n // that needs to be fixed either way.\n if (SummaryManager.isStartingOrRunning(this.state)) {\n this.stop(\"summarizerException\");\n }\n }\n }).finally(() => {\n assert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n this.state = SummaryManagerState.Off;\n\n this.summarizer = undefined;\n\n this.logger.sendTelemetryEvent({\n eventName: \"EndingSummarizer\",\n reason,\n });\n\n if (this.getShouldSummarizeState().shouldSummarize) {\n this.startSummarization();\n }\n });\n }\n\n private stop(reason: SummarizerStopReason) {\n if (!SummaryManager.isStartingOrRunning(this.state)) {\n return;\n }\n this.state = SummaryManagerState.Stopping;\n\n // Stopping the running summarizer client should trigger a change\n // in states when the running summarizer closes\n this.summarizer?.stop(reason);\n }\n\n /**\n * Implements initial delay before creating summarizer\n * @returns true, if creation is delayed due to heuristics (not many ops to summarize).\n * False if summarizer should start immediately due to too many unsummarized ops.\n */\n private async delayBeforeCreatingSummarizer(): Promise<boolean> {\n // throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n let delayMs = this.startThrottler.getDelay();\n if (delayMs > 0 && delayMs > this.startThrottler.maxDelayMs) {\n this.emit(\n \"summarizerWarning\",\n createSummarizingWarning(\"summaryManagerCreateSummarizerMaxThrottleDelay\", false),\n );\n }\n\n // We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n // now we play it safe and launch a second copy.\n this.logger.sendTelemetryEvent({\n eventName: \"CreatingSummarizer\",\n throttlerDelay: delayMs,\n initialDelay: this.initialDelayMs,\n opsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n opsToBypassInitialDelay: this.opsToBypassInitialDelay,\n });\n\n // This delay helps ensure that last summarizer that might be left from previous client\n // has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n // If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n // understanding that we may see nacks because of such quick action.\n // A better design would be for summarizer election logic to always select current summarizer as\n // summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n // summarizer while it finishes its work and moves to exit.\n // It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n // critical boot sequence.\n let startWithInitialDelay = false;\n if (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n startWithInitialDelay = true;\n delayMs = Math.max(delayMs, this.initialDelayMs);\n }\n\n if (delayMs > 0) {\n let timer;\n let resolveOpPromiseFn;\n // Create a listener that will break the delay if we've exceeded the initial delay ops count.\n const opsListenerFn = () => {\n if (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n clearTimeout(timer);\n resolveOpPromiseFn();\n }\n };\n // Create a Promise that will resolve when the delay expires.\n const delayPromise = new Promise<void>((resolve) => {\n timer = setTimeout(() => resolve(), delayMs);\n });\n // Create a Promise that will resolve if the ops count passes the threshold.\n const opPromise = new Promise<void>((resolve) => { resolveOpPromiseFn = resolve; });\n this.summaryCollection.addOpListener(opsListenerFn);\n await Promise.race([ delayPromise, opPromise ]);\n this.summaryCollection.removeOpListener(opsListenerFn);\n }\n return startWithInitialDelay;\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.summarizeOnDemand(...args);\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.enqueueSummarize(...args);\n };\n\n public dispose() {\n this.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.connectedState.off(\"connected\", this.handleConnected);\n this.connectedState.off(\"disconnected\", this.handleDisconnected);\n this._disposed = true;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW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kB,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;;AA/NuB,kCAAmB,GAAG,CAAC,KAA0B,EAAE,EAAE,CACzE,KAAK,KAAK,mBAAmB,CAAC,QAAQ,IAAI,KAAK,KAAK,mBAAmB,CAAC,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { IThrottler } from \"./throttler\";\nimport {\n ISummarizer,\n ISummarizerOptions,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n Off = 0,\n Starting = 1,\n Running = 2,\n Stopping = 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<SummarizerStopReason, \"parentNotConnected\" | \"parentShouldNotSummarize\">;\ntype ShouldSummarizeState =\n | { shouldSummarize: true; }\n | { shouldSummarize: false; stopReason: StopReason; };\n\nexport interface IConnectedEvents extends IEvent {\n (event: \"connected\", listener: (clientId: string) => void);\n (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 readonly connected: boolean;\n\n /**\n * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n */\n readonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n initialDelayMs: number;\n opsToBypassInitialDelay: 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 implements IDisposable {\n private readonly logger: ITelemetryLogger;\n private readonly opsToBypassInitialDelay: number;\n private readonly initialDelayMs: number;\n private latestClientId: string | undefined;\n private state = SummaryManagerState.Off;\n private summarizer?: ISummarizer;\n private _disposed = false;\n\n public get disposed() {\n return this._disposed;\n }\n\n public get currentState() { return this.state; }\n\n constructor(\n private readonly clientElection: ISummarizerClientElection,\n private readonly connectedState: IConnectedState,\n private readonly summaryCollection:\n Pick<SummaryCollection, \"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\">,\n parentLogger: ITelemetryLogger,\n /** Creates summarizer by asking interactive container to spawn summarizing container and\n * get back its Summarizer instance. */\n private readonly requestSummarizerFn: () => Promise<ISummarizer>,\n private readonly startThrottler: IThrottler,\n {\n initialDelayMs = defaultInitialDelayMs,\n opsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n }: Readonly<Partial<ISummaryManagerConfig>> = {},\n private readonly summarizerOptions?: Readonly<Partial<ISummarizerOptions>>,\n ) {\n\n this.logger = ChildLogger.create(\n parentLogger,\n \"SummaryManager\",\n {all:{ clientId: () => this.latestClientId }});\n\n this.connectedState.on(\"connected\", this.handleConnected);\n this.connectedState.on(\"disconnected\", this.handleDisconnected);\n this.latestClientId = this.connectedState.clientId;\n\n this.opsToBypassInitialDelay = opsToBypassInitialDelay;\n this.initialDelayMs = initialDelayMs;\n }\n\n /**\n * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n * a window between construction and starting where the caller can attach listeners.\n */\n public start(): void {\n this.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.refreshSummarizer();\n }\n\n private readonly handleConnected = (clientId: string) => {\n this.latestClientId = clientId;\n // If we have a summarizer, it should have been either cancelled on disconnected by now.\n // But because of lastSummary process, it can still hang around, so there is not much we can\n // check or assert.\n this.refreshSummarizer();\n };\n\n private readonly handleDisconnected = () => {\n this.refreshSummarizer();\n };\n\n private static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n state === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n private getShouldSummarizeState(): ShouldSummarizeState {\n if (!this.connectedState.connected) {\n return { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n } else if (this.connectedState.clientId !== this.clientElection.electedClientId) {\n return { shouldSummarize: false, stopReason: \"parentShouldNotSummarize\" };\n } else if (this.disposed) {\n assert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n } else {\n return { shouldSummarize: true };\n }\n }\n\n private readonly refreshSummarizer = () => {\n // Transition states depending on shouldSummarize, which is a calculated property\n // that is only true if this client is connected and is the elected summarizer.\n const shouldSummarizeState = this.getShouldSummarizeState();\n switch (this.state) {\n case SummaryManagerState.Off: {\n if (shouldSummarizeState.shouldSummarize) {\n this.startSummarization();\n }\n return;\n }\n case SummaryManagerState.Starting: {\n // Cannot take any action until summarizer is created\n // state transition will occur after creation\n return;\n }\n case SummaryManagerState.Running: {\n if (shouldSummarizeState.shouldSummarize === false) {\n this.stop(shouldSummarizeState.stopReason);\n }\n return;\n }\n case SummaryManagerState.Stopping: {\n // Cannot take any action until running summarizer finishes\n // state transition will occur after it stops\n return;\n }\n default: {\n return;\n }\n }\n };\n\n private startSummarization() {\n assert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n this.state = SummaryManagerState.Starting;\n\n assert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n let reason = \"unknown\";\n\n this.delayBeforeCreatingSummarizer().then(async (startWithInitialDelay: boolean) => {\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n // but only if creation was delayed. If it was not, then we want to ensure we always create\n // a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n // document out of broken state if it has too many ops and ordering service keeps nacking main\n // container (and thus it goes into cycle of reconnects)\n if (startWithInitialDelay && this.getShouldSummarizeState().shouldSummarize === false) {\n return;\n }\n\n const summarizer = await this.requestSummarizerFn();\n\n // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n const shouldSummarizeState = this.getShouldSummarizeState();\n if (shouldSummarizeState.shouldSummarize === false) {\n summarizer.stop(shouldSummarizeState.stopReason);\n return;\n }\n\n assert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n this.state = SummaryManagerState.Running;\n\n this.summarizer = summarizer;\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const clientId = this.latestClientId!;\n\n reason = await PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n async () => summarizer.run(clientId, this.summarizerOptions),\n );\n }).catch((error) => {\n // Most of exceptions happen due to container being closed while loading it, due to\n // summarizer container loosing connection while load.\n // Not worth reporting such errors as errors. That said, we might miss some real errors if\n // we ignore blindly, so try to narrow signature we are looking for - skip logging\n // error only if this client should no longer be a summarizer (which in practice\n // means it also lost connection), and error happened on load (we do not have summarizer).\n // We could annotate the error raised in Container.load where the container closed during load with no error\n // and check for that case here, but that does not seem to be necessary.\n if (this.getShouldSummarizeState().shouldSummarize || this.summarizer !== undefined) {\n // Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n // If failure happened on container load, we may not yet realized that socket disconnected, so check\n // offlineError.\n const category = error?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n this.logger.sendTelemetryEvent(\n {\n eventName: \"SummarizerException\",\n category,\n },\n error);\n\n // Note that summarizer may keep going (like doing last summary).\n // Ideally we await stopping process, but this code path is due to a bug\n // that needs to be fixed either way.\n if (SummaryManager.isStartingOrRunning(this.state)) {\n this.stop(\"summarizerException\");\n }\n }\n }).finally(() => {\n assert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n this.state = SummaryManagerState.Off;\n\n this.summarizer = undefined;\n\n this.logger.sendTelemetryEvent({\n eventName: \"EndingSummarizer\",\n reason,\n });\n\n if (this.getShouldSummarizeState().shouldSummarize) {\n this.startSummarization();\n }\n });\n }\n\n private stop(reason: SummarizerStopReason) {\n if (!SummaryManager.isStartingOrRunning(this.state)) {\n return;\n }\n this.state = SummaryManagerState.Stopping;\n\n // Stopping the running summarizer client should trigger a change\n // in states when the running summarizer closes\n this.summarizer?.stop(reason);\n }\n\n /**\n * Implements initial delay before creating summarizer\n * @returns true, if creation is delayed due to heuristics (not many ops to summarize).\n * False if summarizer should start immediately due to too many unsummarized ops.\n */\n private async delayBeforeCreatingSummarizer(): Promise<boolean> {\n // throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n let delayMs = this.startThrottler.getDelay();\n\n // We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n // now we play it safe and launch a second copy.\n this.logger.sendTelemetryEvent({\n eventName: \"CreatingSummarizer\",\n throttlerDelay: delayMs,\n initialDelay: this.initialDelayMs,\n startThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n opsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n opsToBypassInitialDelay: this.opsToBypassInitialDelay,\n });\n\n // This delay helps ensure that last summarizer that might be left from previous client\n // has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n // If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n // understanding that we may see nacks because of such quick action.\n // A better design would be for summarizer election logic to always select current summarizer as\n // summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n // summarizer while it finishes its work and moves to exit.\n // It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n // critical boot sequence.\n let startWithInitialDelay = false;\n if (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n startWithInitialDelay = true;\n delayMs = Math.max(delayMs, this.initialDelayMs);\n }\n\n if (delayMs > 0) {\n let timer;\n let resolveOpPromiseFn;\n // Create a listener that will break the delay if we've exceeded the initial delay ops count.\n const opsListenerFn = () => {\n if (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n clearTimeout(timer);\n resolveOpPromiseFn();\n }\n };\n // Create a Promise that will resolve when the delay expires.\n const delayPromise = new Promise<void>((resolve) => {\n timer = setTimeout(() => resolve(), delayMs);\n });\n // Create a Promise that will resolve if the ops count passes the threshold.\n const opPromise = new Promise<void>((resolve) => { resolveOpPromiseFn = resolve; });\n this.summaryCollection.addOpListener(opsListenerFn);\n await Promise.race([ delayPromise, opPromise ]);\n this.summaryCollection.removeOpListener(opsListenerFn);\n }\n return startWithInitialDelay;\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.summarizeOnDemand(...args);\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this.summarizer === undefined) {\n throw Error(\"No running summarizer client\");\n // TODO: could spawn a summarizer client temporarily.\n }\n return this.summarizer.enqueueSummarize(...args);\n };\n\n public dispose() {\n this.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n this.connectedState.off(\"connected\", this.handleConnected);\n this.connectedState.off(\"disconnected\", this.handleDisconnected);\n this._disposed = true;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/container-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.58.1000",
|
|
4
4
|
"description": "Fluid container runtime",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -58,27 +58,27 @@
|
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
60
60
|
"@fluidframework/common-utils": "^0.32.1",
|
|
61
|
-
"@fluidframework/container-definitions": "^0.
|
|
62
|
-
"@fluidframework/container-runtime-definitions": "^0.
|
|
63
|
-
"@fluidframework/container-utils": "^0.
|
|
61
|
+
"@fluidframework/container-definitions": "^0.47.1000",
|
|
62
|
+
"@fluidframework/container-runtime-definitions": "^0.58.1000",
|
|
63
|
+
"@fluidframework/container-utils": "^0.58.1000",
|
|
64
64
|
"@fluidframework/core-interfaces": "^0.42.0",
|
|
65
|
-
"@fluidframework/datastore": "^0.
|
|
66
|
-
"@fluidframework/driver-definitions": "^0.
|
|
67
|
-
"@fluidframework/driver-utils": "^0.
|
|
68
|
-
"@fluidframework/garbage-collector": "^0.
|
|
69
|
-
"@fluidframework/protocol-base": "^0.
|
|
70
|
-
"@fluidframework/protocol-definitions": "^0.
|
|
71
|
-
"@fluidframework/runtime-definitions": "^0.
|
|
72
|
-
"@fluidframework/runtime-utils": "^0.
|
|
73
|
-
"@fluidframework/telemetry-utils": "^0.
|
|
65
|
+
"@fluidframework/datastore": "^0.58.1000",
|
|
66
|
+
"@fluidframework/driver-definitions": "^0.45.1000",
|
|
67
|
+
"@fluidframework/driver-utils": "^0.58.1000",
|
|
68
|
+
"@fluidframework/garbage-collector": "^0.58.1000",
|
|
69
|
+
"@fluidframework/protocol-base": "^0.1035.1000",
|
|
70
|
+
"@fluidframework/protocol-definitions": "^0.1027.1000",
|
|
71
|
+
"@fluidframework/runtime-definitions": "^0.58.1000",
|
|
72
|
+
"@fluidframework/runtime-utils": "^0.58.1000",
|
|
73
|
+
"@fluidframework/telemetry-utils": "^0.58.1000",
|
|
74
74
|
"double-ended-queue": "^2.1.0-0",
|
|
75
75
|
"uuid": "^8.3.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@fluidframework/build-common": "^0.23.0",
|
|
79
79
|
"@fluidframework/eslint-config-fluid": "^0.26.0",
|
|
80
|
-
"@fluidframework/mocha-test-setup": "^0.
|
|
81
|
-
"@fluidframework/test-runtime-utils": "^0.
|
|
80
|
+
"@fluidframework/mocha-test-setup": "^0.58.1000",
|
|
81
|
+
"@fluidframework/test-runtime-utils": "^0.58.1000",
|
|
82
82
|
"@microsoft/api-extractor": "^7.16.1",
|
|
83
83
|
"@rushstack/eslint-config": "^2.5.1",
|
|
84
84
|
"@types/double-ended-queue": "^2.1.0",
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
7
|
+
import { assert, performance } from "@fluidframework/common-utils";
|
|
8
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
9
|
+
import { ChildLogger } from "@fluidframework/telemetry-utils";
|
|
10
|
+
import EventEmitter from "events";
|
|
11
|
+
|
|
12
|
+
export class BatchTracker {
|
|
13
|
+
private readonly logger: ITelemetryLogger;
|
|
14
|
+
private startBatchSequenceNumber: number | undefined;
|
|
15
|
+
private trackedBatchCount: number = 0;
|
|
16
|
+
private batchProcessingStartTimeStamp: number | undefined;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
private readonly batchEventEmitter: EventEmitter,
|
|
20
|
+
logger: ITelemetryLogger,
|
|
21
|
+
batchLengthThreshold: number,
|
|
22
|
+
batchCountSamplingRate: number,
|
|
23
|
+
dateTimeProvider: () => number = () => performance.now(),
|
|
24
|
+
) {
|
|
25
|
+
this.logger = ChildLogger.create(logger, "Batching");
|
|
26
|
+
|
|
27
|
+
this.batchEventEmitter.on("batchBegin", (message: ISequencedDocumentMessage) => {
|
|
28
|
+
this.startBatchSequenceNumber = message.sequenceNumber;
|
|
29
|
+
this.batchProcessingStartTimeStamp = dateTimeProvider();
|
|
30
|
+
this.trackedBatchCount++;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
this.batchEventEmitter.on("batchEnd", (error: any | undefined, message: ISequencedDocumentMessage) => {
|
|
34
|
+
assert(
|
|
35
|
+
this.startBatchSequenceNumber !== undefined && this.batchProcessingStartTimeStamp !== undefined,
|
|
36
|
+
0x2ba /* "batchBegin must fire before batchEnd" */);
|
|
37
|
+
|
|
38
|
+
const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;
|
|
39
|
+
if (length >= batchLengthThreshold) {
|
|
40
|
+
this.logger.sendErrorEvent({
|
|
41
|
+
eventName: "LengthTooBig",
|
|
42
|
+
length,
|
|
43
|
+
threshold: batchLengthThreshold,
|
|
44
|
+
batchEndSequenceNumber: message.sequenceNumber,
|
|
45
|
+
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
|
|
46
|
+
batchError: error !== undefined,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (this.trackedBatchCount % batchCountSamplingRate === 0) {
|
|
51
|
+
this.logger.sendPerformanceEvent({
|
|
52
|
+
eventName: "Length",
|
|
53
|
+
length,
|
|
54
|
+
samplingRate: batchCountSamplingRate,
|
|
55
|
+
batchEndSequenceNumber: message.sequenceNumber,
|
|
56
|
+
duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.startBatchSequenceNumber = undefined;
|
|
61
|
+
this.batchProcessingStartTimeStamp = undefined;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Track batch sizes in terms of op counts and processing times
|
|
68
|
+
*
|
|
69
|
+
* @param batchEventEmitter - event emitter which tracks the lifecycle of batch operations
|
|
70
|
+
* @param logger - logger
|
|
71
|
+
* @param batchLengthThreshold - threshold for the length of a batch when to send an error event
|
|
72
|
+
* @param batchCountSamplingRate - rate for batches for which to send an event with its characteristics
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
export const BindBatchTracker = (
|
|
76
|
+
batchEventEmitter: EventEmitter,
|
|
77
|
+
logger: ITelemetryLogger,
|
|
78
|
+
batchLengthThreshold: number = 128,
|
|
79
|
+
batchCountSamplingRate: number = 1000,
|
|
80
|
+
) => new BatchTracker(batchEventEmitter, logger, batchLengthThreshold, batchCountSamplingRate)
|
package/src/containerRuntime.ts
CHANGED
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
IDeltaManager,
|
|
23
23
|
IDeltaSender,
|
|
24
24
|
IRuntime,
|
|
25
|
-
ContainerWarning,
|
|
26
25
|
ICriticalContainerError,
|
|
27
26
|
AttachState,
|
|
28
27
|
ILoaderOptions,
|
|
@@ -152,6 +151,7 @@ import {
|
|
|
152
151
|
IDataStoreAliasMessage,
|
|
153
152
|
isDataStoreAliasMessage,
|
|
154
153
|
} from "./dataStore";
|
|
154
|
+
import { BindBatchTracker } from "./batchTracker";
|
|
155
155
|
|
|
156
156
|
export enum ContainerMessageType {
|
|
157
157
|
// An op to be delivered to store
|
|
@@ -329,15 +329,24 @@ export enum RuntimeHeaders {
|
|
|
329
329
|
* have the untagged logger, so to accommodate that scenario the below interface is used. It can be removed once
|
|
330
330
|
* its usage is removed from TaggedLoggerAdapter fallback.
|
|
331
331
|
*/
|
|
332
|
-
interface OldContainerContextWithLogger extends IContainerContext {
|
|
332
|
+
interface OldContainerContextWithLogger extends Omit<IContainerContext, "taggedLogger"> {
|
|
333
333
|
logger: ITelemetryBaseLogger;
|
|
334
|
+
taggedLogger: undefined;
|
|
334
335
|
}
|
|
335
336
|
|
|
336
|
-
// Local storage key to set the default flush mode to TurnBased
|
|
337
|
-
const turnBasedFlushModeKey = "Fluid.ContainerRuntime.FlushModeTurnBased";
|
|
338
337
|
const useDataStoreAliasingKey = "Fluid.ContainerRuntime.UseDataStoreAliasing";
|
|
339
338
|
const maxConsecutiveReconnectsKey = "Fluid.ContainerRuntime.MaxConsecutiveReconnects";
|
|
340
339
|
|
|
340
|
+
// Feature gate for the max op size. If the value is negative, chunking is enabled
|
|
341
|
+
// and all ops over 16k would be chunked. If the value is positive, all ops with
|
|
342
|
+
// a size strictly larger will be rejected and the container closed with an error.
|
|
343
|
+
const maxOpSizeInBytesKey = "Fluid.ContainerRuntime.MaxOpSizeInBytes";
|
|
344
|
+
|
|
345
|
+
// By default, we should reject any op larger than 768KB,
|
|
346
|
+
// in order to account for some extra overhead from serialization
|
|
347
|
+
// to not reach the 1MB limits in socket.io and Kafka.
|
|
348
|
+
const defaultMaxOpSizeInBytes = 768000;
|
|
349
|
+
|
|
341
350
|
export enum RuntimeMessage {
|
|
342
351
|
FluidDataStoreOp = "component",
|
|
343
352
|
Attach = "attach",
|
|
@@ -687,8 +696,9 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
687
696
|
): Promise<ContainerRuntime> {
|
|
688
697
|
// If taggedLogger exists, use it. Otherwise, wrap the vanilla logger:
|
|
689
698
|
// back-compat: Remove the TaggedLoggerAdapter fallback once all the host are using loader > 0.45
|
|
690
|
-
const
|
|
691
|
-
|
|
699
|
+
const backCompatContext: IContainerContext | OldContainerContextWithLogger = context;
|
|
700
|
+
const passLogger = backCompatContext.taggedLogger ??
|
|
701
|
+
new TaggedLoggerAdapter((backCompatContext as OldContainerContextWithLogger).logger);
|
|
692
702
|
const logger = ChildLogger.create(passLogger, undefined, {
|
|
693
703
|
all: {
|
|
694
704
|
runtimeVersion: pkgVersion,
|
|
@@ -770,7 +780,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
770
780
|
if (loadSequenceNumberVerification !== "bypass" && runtimeSequenceNumber !== protocolSequenceNumber) {
|
|
771
781
|
// "Load from summary, runtime metadata sequenceNumber !== initialSequenceNumber"
|
|
772
782
|
const error = new DataCorruptionError(
|
|
773
|
-
"
|
|
783
|
+
"Summary metadata mismatch",
|
|
774
784
|
{ runtimeSequenceNumber, protocolSequenceNumber },
|
|
775
785
|
);
|
|
776
786
|
|
|
@@ -892,12 +902,13 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
892
902
|
|
|
893
903
|
private readonly summarizerNode: IRootSummarizerNodeWithGC;
|
|
894
904
|
private readonly _aliasingEnabled: boolean;
|
|
905
|
+
private readonly _maxOpSizeInBytes: number;
|
|
895
906
|
|
|
896
907
|
private readonly maxConsecutiveReconnects: number;
|
|
897
908
|
private readonly defaultMaxConsecutiveReconnects = 15;
|
|
898
909
|
|
|
899
910
|
private _orderSequentiallyCalls: number = 0;
|
|
900
|
-
private _flushMode: FlushMode;
|
|
911
|
+
private _flushMode: FlushMode = FlushMode.TurnBased;
|
|
901
912
|
private needsFlush = false;
|
|
902
913
|
private flushTrigger = false;
|
|
903
914
|
|
|
@@ -933,8 +944,6 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
933
944
|
private dirtyContainer: boolean;
|
|
934
945
|
private emitDirtyDocumentEvent = true;
|
|
935
946
|
|
|
936
|
-
private readonly summarizerWarning = (warning: ContainerWarning) =>
|
|
937
|
-
this.mc.logger.sendTelemetryEvent({ eventName: "summarizerWarning" }, warning);
|
|
938
947
|
/**
|
|
939
948
|
* Summarizer is responsible for coordinating when to send generate and send summaries.
|
|
940
949
|
* It is the main entry point for summary work.
|
|
@@ -1019,14 +1028,11 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1019
1028
|
this.mc = loggerToMonitoringContext(
|
|
1020
1029
|
ChildLogger.create(this.logger, "ContainerRuntime"));
|
|
1021
1030
|
|
|
1022
|
-
this._flushMode =
|
|
1023
|
-
this.mc.config.getBoolean(turnBasedFlushModeKey) ?? false
|
|
1024
|
-
? FlushMode.TurnBased : FlushMode.Immediate;
|
|
1025
|
-
|
|
1026
1031
|
this._aliasingEnabled =
|
|
1027
1032
|
(this.mc.config.getBoolean(useDataStoreAliasingKey) ?? false) ||
|
|
1028
1033
|
(runtimeOptions.useDataStoreAliasing ?? false);
|
|
1029
1034
|
|
|
1035
|
+
this._maxOpSizeInBytes = (this.mc.config.getNumber(maxOpSizeInBytesKey) ?? defaultMaxOpSizeInBytes);
|
|
1030
1036
|
this.maxConsecutiveReconnects =
|
|
1031
1037
|
this.mc.config.getNumber(maxConsecutiveReconnectsKey) ?? this.defaultMaxConsecutiveReconnects;
|
|
1032
1038
|
|
|
@@ -1219,7 +1225,6 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1219
1225
|
},
|
|
1220
1226
|
this.runtimeOptions.summaryOptions.summarizerOptions,
|
|
1221
1227
|
);
|
|
1222
|
-
this.summaryManager.on("summarizerWarning", this.summarizerWarning);
|
|
1223
1228
|
this.summaryManager.start();
|
|
1224
1229
|
}
|
|
1225
1230
|
}
|
|
@@ -1269,6 +1274,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1269
1274
|
});
|
|
1270
1275
|
|
|
1271
1276
|
ReportOpPerfTelemetry(this.context.clientId, this.deltaManager, this.logger);
|
|
1277
|
+
BindBatchTracker(this, this.logger);
|
|
1272
1278
|
}
|
|
1273
1279
|
|
|
1274
1280
|
public dispose(error?: Error): void {
|
|
@@ -1285,7 +1291,6 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1285
1291
|
}, error);
|
|
1286
1292
|
|
|
1287
1293
|
if (this.summaryManager !== undefined) {
|
|
1288
|
-
this.summaryManager.off("summarizerWarning", this.summarizerWarning);
|
|
1289
1294
|
this.summaryManager.dispose();
|
|
1290
1295
|
}
|
|
1291
1296
|
this.garbageCollector.dispose();
|
|
@@ -1477,7 +1482,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1477
1482
|
if (this.consecutiveReconnects === Math.floor(this.maxConsecutiveReconnects / 2)) {
|
|
1478
1483
|
// If we're halfway through the max reconnects, send an event in order
|
|
1479
1484
|
// to better identify false positives, if any. If the rate of this event
|
|
1480
|
-
// matches
|
|
1485
|
+
// matches Container Close count below, we can safely cut down
|
|
1481
1486
|
// maxConsecutiveReconnects to half.
|
|
1482
1487
|
this.mc.logger.sendTelemetryEvent({
|
|
1483
1488
|
eventName: "ReconnectsWithNoProgress",
|
|
@@ -1574,7 +1579,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1574
1579
|
this.context.pendingLocalState = undefined;
|
|
1575
1580
|
if (!this.shouldContinueReconnecting()) {
|
|
1576
1581
|
this.closeFn(new GenericError(
|
|
1577
|
-
"
|
|
1582
|
+
"Runtime detected too many reconnects with no progress syncing local ops",
|
|
1578
1583
|
undefined, // error
|
|
1579
1584
|
{ attempts: this.consecutiveReconnects }));
|
|
1580
1585
|
return;
|
|
@@ -1757,7 +1762,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
1757
1762
|
this._orderSequentiallyCalls++;
|
|
1758
1763
|
callback();
|
|
1759
1764
|
} catch (error) {
|
|
1760
|
-
this.closeFn(new GenericError("
|
|
1765
|
+
this.closeFn(new GenericError("orderSequentially callback exception", error));
|
|
1761
1766
|
throw error; // throw the original error for the consumer of the runtime
|
|
1762
1767
|
} finally {
|
|
1763
1768
|
this._orderSequentiallyCalls--;
|
|
@@ -2137,6 +2142,15 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
2137
2142
|
const summaryRefSeqNum = this.deltaManager.lastSequenceNumber;
|
|
2138
2143
|
const message = `Summary @${summaryRefSeqNum}:${this.deltaManager.minimumSequenceNumber}`;
|
|
2139
2144
|
|
|
2145
|
+
// We should be here is we haven't processed be here. If we are of if the last message's sequence number
|
|
2146
|
+
// doesn't match the last processed sequence number, log an error.
|
|
2147
|
+
if (summaryRefSeqNum !== this.deltaManager.lastMessage?.sequenceNumber) {
|
|
2148
|
+
summaryLogger.sendErrorEvent({
|
|
2149
|
+
eventName: "LastSequenceMismatch",
|
|
2150
|
+
message,
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2140
2154
|
this.summarizerNode.startSummary(summaryRefSeqNum, summaryLogger);
|
|
2141
2155
|
|
|
2142
2156
|
// Helper function to check whether we should still continue between each async step.
|
|
@@ -2406,18 +2420,13 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
2406
2420
|
}
|
|
2407
2421
|
}
|
|
2408
2422
|
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
/* batch: */ this._flushMode === FlushMode.TurnBased,
|
|
2417
|
-
opMetadataInternal);
|
|
2418
|
-
} else {
|
|
2419
|
-
clientSequenceNumber = this.submitChunkedMessage(type, serializedContent, maxOpSize);
|
|
2420
|
-
}
|
|
2423
|
+
clientSequenceNumber = this.submitMaybeChunkedMessages(
|
|
2424
|
+
type,
|
|
2425
|
+
content,
|
|
2426
|
+
serializedContent,
|
|
2427
|
+
maxOpSize,
|
|
2428
|
+
this._flushMode === FlushMode.TurnBased,
|
|
2429
|
+
opMetadataInternal);
|
|
2421
2430
|
}
|
|
2422
2431
|
|
|
2423
2432
|
// Let the PendingStateManager know that a message was submitted.
|
|
@@ -2434,6 +2443,48 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
2434
2443
|
}
|
|
2435
2444
|
}
|
|
2436
2445
|
|
|
2446
|
+
private submitMaybeChunkedMessages(
|
|
2447
|
+
type: ContainerMessageType,
|
|
2448
|
+
content: any,
|
|
2449
|
+
serializedContent: string,
|
|
2450
|
+
serverMaxOpSize: number,
|
|
2451
|
+
batch: boolean,
|
|
2452
|
+
opMetadataInternal: unknown = undefined,
|
|
2453
|
+
): number {
|
|
2454
|
+
if (this._maxOpSizeInBytes >= 0) {
|
|
2455
|
+
// Chunking disabled
|
|
2456
|
+
if (!serializedContent || serializedContent.length <= this._maxOpSizeInBytes) {
|
|
2457
|
+
return this.submitRuntimeMessage(type, content, batch, opMetadataInternal);
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
// When chunking is disabled, we ignore the server max message size
|
|
2461
|
+
// and if the content length is larger than the client configured message size
|
|
2462
|
+
// instead of splitting the content, we will fail by explicitly close the container
|
|
2463
|
+
this.closeFn(new GenericError(
|
|
2464
|
+
"OpTooLarge",
|
|
2465
|
+
/* error */ undefined,
|
|
2466
|
+
{
|
|
2467
|
+
length: {
|
|
2468
|
+
value: serializedContent.length,
|
|
2469
|
+
tag: TelemetryDataTag.PackageData,
|
|
2470
|
+
},
|
|
2471
|
+
limit: {
|
|
2472
|
+
value: this._maxOpSizeInBytes,
|
|
2473
|
+
tag: TelemetryDataTag.PackageData,
|
|
2474
|
+
},
|
|
2475
|
+
}));
|
|
2476
|
+
return -1;
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2479
|
+
// Chunking enabled, fallback on the server's max message size
|
|
2480
|
+
// and split the content accordingly
|
|
2481
|
+
if (!serializedContent || serializedContent.length <= serverMaxOpSize) {
|
|
2482
|
+
return this.submitRuntimeMessage(type, content, batch, opMetadataInternal);
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
return this.submitChunkedMessage(type, serializedContent, serverMaxOpSize);
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2437
2488
|
private submitChunkedMessage(type: ContainerMessageType, content: string, maxOpSize: number): number {
|
|
2438
2489
|
const contentLength = content.length;
|
|
2439
2490
|
const chunkN = Math.floor((contentLength - 1) / maxOpSize) + 1;
|
|
@@ -2549,6 +2600,8 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
|
|
|
2549
2600
|
summaryRefSeq,
|
|
2550
2601
|
async () => this.fetchSnapshotFromStorage(ackHandle, summaryLogger, {
|
|
2551
2602
|
eventName: "RefreshLatestSummaryGetSnapshot",
|
|
2603
|
+
ackHandle,
|
|
2604
|
+
summaryRefSeq,
|
|
2552
2605
|
fetchLatest: false,
|
|
2553
2606
|
}),
|
|
2554
2607
|
readAndParseBlob,
|
package/src/dataStoreContext.ts
CHANGED
|
@@ -66,7 +66,7 @@ import {
|
|
|
66
66
|
TelemetryDataTag,
|
|
67
67
|
ThresholdCounter,
|
|
68
68
|
} from "@fluidframework/telemetry-utils";
|
|
69
|
-
import {
|
|
69
|
+
import { DataProcessingError } from "@fluidframework/container-utils";
|
|
70
70
|
|
|
71
71
|
import { ContainerRuntime } from "./containerRuntime";
|
|
72
72
|
import {
|
|
@@ -310,7 +310,7 @@ export abstract class FluidDataStoreContext extends TypedEventEmitter<IFluidData
|
|
|
310
310
|
if (!this.channelDeferred) {
|
|
311
311
|
this.channelDeferred = new Deferred<IFluidDataStoreChannel>();
|
|
312
312
|
this.realizeCore(this.existing).catch((error) => {
|
|
313
|
-
const errorWrapped =
|
|
313
|
+
const errorWrapped = DataProcessingError.wrapIfUnrecognized(error, "realizeFluidDataStoreContext");
|
|
314
314
|
errorWrapped.addTelemetryProperties({ fluidDataStoreId: { value: this.id, tag: "PackageData"} });
|
|
315
315
|
this.channelDeferred?.reject(errorWrapped);
|
|
316
316
|
this.logger.sendErrorEvent({ eventName: "RealizeError"}, errorWrapped);
|