@fluidframework/container-runtime 0.59.1000-61898 → 0.59.1001

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.
Files changed (62) hide show
  1. package/dist/containerRuntime.d.ts +2 -2
  2. package/dist/containerRuntime.d.ts.map +1 -1
  3. package/dist/containerRuntime.js +12 -13
  4. package/dist/containerRuntime.js.map +1 -1
  5. package/dist/dataStores.d.ts +4 -2
  6. package/dist/dataStores.d.ts.map +1 -1
  7. package/dist/dataStores.js +12 -5
  8. package/dist/dataStores.js.map +1 -1
  9. package/dist/garbageCollection.d.ts +1 -0
  10. package/dist/garbageCollection.d.ts.map +1 -1
  11. package/dist/garbageCollection.js +3 -1
  12. package/dist/garbageCollection.js.map +1 -1
  13. package/dist/orderedClientElection.d.ts +6 -57
  14. package/dist/orderedClientElection.d.ts.map +1 -1
  15. package/dist/orderedClientElection.js +25 -140
  16. package/dist/orderedClientElection.js.map +1 -1
  17. package/dist/packageVersion.d.ts +1 -1
  18. package/dist/packageVersion.d.ts.map +1 -1
  19. package/dist/packageVersion.js +1 -1
  20. package/dist/packageVersion.js.map +1 -1
  21. package/dist/summarizerClientElection.d.ts +0 -2
  22. package/dist/summarizerClientElection.d.ts.map +1 -1
  23. package/dist/summarizerClientElection.js +2 -7
  24. package/dist/summarizerClientElection.js.map +1 -1
  25. package/dist/summaryManager.d.ts.map +1 -1
  26. package/dist/summaryManager.js +3 -14
  27. package/dist/summaryManager.js.map +1 -1
  28. package/lib/containerRuntime.d.ts +2 -2
  29. package/lib/containerRuntime.d.ts.map +1 -1
  30. package/lib/containerRuntime.js +12 -13
  31. package/lib/containerRuntime.js.map +1 -1
  32. package/lib/dataStores.d.ts +4 -2
  33. package/lib/dataStores.d.ts.map +1 -1
  34. package/lib/dataStores.js +12 -5
  35. package/lib/dataStores.js.map +1 -1
  36. package/lib/garbageCollection.d.ts +1 -0
  37. package/lib/garbageCollection.d.ts.map +1 -1
  38. package/lib/garbageCollection.js +3 -1
  39. package/lib/garbageCollection.js.map +1 -1
  40. package/lib/orderedClientElection.d.ts +6 -57
  41. package/lib/orderedClientElection.d.ts.map +1 -1
  42. package/lib/orderedClientElection.js +25 -140
  43. package/lib/orderedClientElection.js.map +1 -1
  44. package/lib/packageVersion.d.ts +1 -1
  45. package/lib/packageVersion.d.ts.map +1 -1
  46. package/lib/packageVersion.js +1 -1
  47. package/lib/packageVersion.js.map +1 -1
  48. package/lib/summarizerClientElection.d.ts +0 -2
  49. package/lib/summarizerClientElection.d.ts.map +1 -1
  50. package/lib/summarizerClientElection.js +2 -7
  51. package/lib/summarizerClientElection.js.map +1 -1
  52. package/lib/summaryManager.d.ts.map +1 -1
  53. package/lib/summaryManager.js +3 -14
  54. package/lib/summaryManager.js.map +1 -1
  55. package/package.json +17 -17
  56. package/src/containerRuntime.ts +11 -13
  57. package/src/dataStores.ts +13 -5
  58. package/src/garbageCollection.ts +3 -1
  59. package/src/orderedClientElection.ts +25 -154
  60. package/src/packageVersion.ts +1 -1
  61. package/src/summarizerClientElection.ts +2 -7
  62. package/src/summaryManager.ts +4 -15
@@ -1 +1 @@
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,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAUrE,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;AAuCD;;;;GAIG;AACH,MAAM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IAC1B,CAAC;;AA1OuB,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 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 // Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n // enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n // only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n // changing the electedParent will just cause us to transition to Starting again.\n if (!this.connectedState.connected) {\n return { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n } else if (this.connectedState.clientId !== this.clientElection.electedParentId ||\n (this.state !== SummaryManagerState.Running &&\n 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 // We transition to Running before requesting the summarizer, because after requesting we can't predict\n // when the electedClient will be replaced with the new summarizer client.\n // The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n // state === Starting || state === Running.\n assert(this.state === SummaryManagerState.Starting, 0x263 /* \"Expected: starting\" */);\n this.state = SummaryManagerState.Running;\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 this.state = SummaryManagerState.Starting;\n summarizer.stop(shouldSummarizeState.stopReason);\n return;\n }\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"]}
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,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAUrE,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;AAuCD;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAevB,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;QAbzD,mBAAc,GAAd,cAAc,CAA2B;QACzC,mBAAc,GAAd,cAAc,CAAiB;QAC/B,sBAAiB,GAAjB,iBAAiB,CACmD;QAIpE,wBAAmB,GAAnB,mBAAmB,CAA4B;QAC/C,mBAAc,GAAd,cAAc,CAAY;QAK1B,sBAAiB,GAAjB,iBAAiB,CAAwC;QAxBtE,UAAK,GAAG,mBAAmB,CAAC,GAAG,CAAC;QAEhC,cAAS,GAAG,KAAK,CAAC;QA8CT,oBAAe,GAAG,CAAC,QAAgB,EAAE,EAAE;YACpD,IAAI,CAAC,cAAc,G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D,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;;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 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.59.1000-61898",
3
+ "version": "0.59.1001",
4
4
  "description": "Fluid container runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -64,19 +64,19 @@
64
64
  "dependencies": {
65
65
  "@fluidframework/common-definitions": "^0.20.1",
66
66
  "@fluidframework/common-utils": "^0.32.1",
67
- "@fluidframework/container-definitions": "^0.48.1000-0",
68
- "@fluidframework/container-runtime-definitions": "0.59.1000-61898",
69
- "@fluidframework/container-utils": "0.59.1000-61898",
70
- "@fluidframework/core-interfaces": "^0.43.1000-0",
71
- "@fluidframework/datastore": "0.59.1000-61898",
72
- "@fluidframework/driver-definitions": "^0.46.1000-0",
73
- "@fluidframework/driver-utils": "0.59.1000-61898",
74
- "@fluidframework/garbage-collector": "0.59.1000-61898",
75
- "@fluidframework/protocol-base": "^0.1036.1000-0",
76
- "@fluidframework/protocol-definitions": "^0.1028.1000-0",
77
- "@fluidframework/runtime-definitions": "0.59.1000-61898",
78
- "@fluidframework/runtime-utils": "0.59.1000-61898",
79
- "@fluidframework/telemetry-utils": "0.59.1000-61898",
67
+ "@fluidframework/container-definitions": "^0.48.1000",
68
+ "@fluidframework/container-runtime-definitions": "^0.59.1001",
69
+ "@fluidframework/container-utils": "^0.59.1001",
70
+ "@fluidframework/core-interfaces": "^0.43.1000",
71
+ "@fluidframework/datastore": "^0.59.1001",
72
+ "@fluidframework/driver-definitions": "^0.46.1000",
73
+ "@fluidframework/driver-utils": "^0.59.1001",
74
+ "@fluidframework/garbage-collector": "^0.59.1001",
75
+ "@fluidframework/protocol-base": "^0.1036.1000",
76
+ "@fluidframework/protocol-definitions": "^0.1028.1000",
77
+ "@fluidframework/runtime-definitions": "^0.59.1001",
78
+ "@fluidframework/runtime-utils": "^0.59.1001",
79
+ "@fluidframework/telemetry-utils": "^0.59.1001",
80
80
  "double-ended-queue": "^2.1.0-0",
81
81
  "uuid": "^8.3.1"
82
82
  },
@@ -84,9 +84,9 @@
84
84
  "@fluidframework/build-common": "^0.23.0",
85
85
  "@fluidframework/build-tools": "^0.2.61288",
86
86
  "@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@^0.58.0",
87
- "@fluidframework/eslint-config-fluid": "^0.28.1000-61189",
88
- "@fluidframework/mocha-test-setup": "0.59.1000-61898",
89
- "@fluidframework/test-runtime-utils": "0.59.1000-61898",
87
+ "@fluidframework/eslint-config-fluid": "^0.28.1000",
88
+ "@fluidframework/mocha-test-setup": "^0.59.1001",
89
+ "@fluidframework/test-runtime-utils": "^0.59.1001",
90
90
  "@microsoft/api-extractor": "^7.16.1",
91
91
  "@rushstack/eslint-config": "^2.5.1",
92
92
  "@types/double-ended-queue": "^2.1.0",
@@ -2180,18 +2180,14 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
2180
2180
  }
2181
2181
 
2182
2182
  /**
2183
- * Returns the type of the GC node. Currently, there are nodes that belong to data store and nodes that belong
2184
- * to the blob manager.
2183
+ * Returns the type of the GC node. Currently, there are nodes that belong to the root ("/"), data stores or
2184
+ * blob manager.
2185
2185
  */
2186
2186
  public getNodeType(nodePath: string): GCNodeType {
2187
2187
  if (this.isBlobPath(nodePath)) {
2188
2188
  return GCNodeType.Blob;
2189
2189
  }
2190
- if (this.dataStores.isDataStoreNode(nodePath)) {
2191
- return GCNodeType.DataStore;
2192
- }
2193
- // Root node ("/") and DDS nodes belong to "Other" node types.
2194
- return GCNodeType.Other;
2190
+ return this.dataStores.getGCNodeType(nodePath) ?? GCNodeType.Other;
2195
2191
  }
2196
2192
 
2197
2193
  /**
@@ -2199,13 +2195,15 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
2199
2195
  * data store or an attachment blob.
2200
2196
  */
2201
2197
  public getGCNodePackagePath(nodePath: string): readonly string[] | undefined {
2202
- // If the node is a blob, return "_blobs" as the package path.
2203
- if (this.isBlobPath(nodePath)) {
2204
- return ["_blobs"];
2198
+ switch (this.getNodeType(nodePath)) {
2199
+ case GCNodeType.Blob:
2200
+ return ["_blobs"];
2201
+ case GCNodeType.DataStore:
2202
+ case GCNodeType.SubDataStore:
2203
+ return this.dataStores.getDataStorePackagePath(nodePath);
2204
+ default:
2205
+ assert(false, 0x2d8 /* "Package path requested for unsupported node type." */);
2205
2206
  }
2206
- const dataStorePkgPath = this.dataStores.getDataStorePackagePath(nodePath);
2207
- assert(dataStorePkgPath !== undefined, 0x2d6 /* "Package path requested for unknown node type." */);
2208
- return dataStorePkgPath;
2209
2207
  }
2210
2208
 
2211
2209
  /**
package/src/dataStores.ts CHANGED
@@ -50,6 +50,7 @@ import {
50
50
  } from "./dataStoreContext";
51
51
  import { IContainerRuntimeMetadata, nonDataStorePaths, rootHasIsolatedChannels } from "./summaryFormat";
52
52
  import { IDataStoreAliasMessage, isDataStoreAliasMessage } from "./dataStore";
53
+ import { GCNodeType } from "./garbageCollection";
53
54
 
54
55
  type PendingAliasResolve = (success: boolean) => void;
55
56
 
@@ -633,14 +634,21 @@ export class DataStores implements IDisposable {
633
634
  }
634
635
 
635
636
  /**
636
- * Called by GC to know if a node is a data store or not. Data store ids are of the format "/dataStoreId".
637
+ * Called by GC to determine if a node is for a data store or for an object within a data store (for e.g. DDS).
638
+ * @returns the GC node type if the node belongs to a data store or object within data store, undefined otherwise.
637
639
  */
638
- public isDataStoreNode(nodePath: string): boolean {
640
+ public getGCNodeType(nodePath: string): GCNodeType | undefined {
639
641
  const pathParts = nodePath.split("/");
640
- if (pathParts.length === 2 && this.contexts.has(pathParts[1])) {
641
- return true;
642
+ if (!this.contexts.has(pathParts[1])) {
643
+ return undefined;
642
644
  }
643
- return false;
645
+
646
+ // Data stores paths are of the format "/dataStoreId".
647
+ // Sub data store paths are of the format "/dataStoreId/subPath/...".
648
+ if (pathParts.length === 2) {
649
+ return GCNodeType.DataStore;
650
+ }
651
+ return GCNodeType.SubDataStore;
644
652
  }
645
653
  }
646
654
 
@@ -96,9 +96,11 @@ export interface IGCStats {
96
96
  export const GCNodeType = {
97
97
  // Nodes that are for data stores.
98
98
  DataStore: "DataStore",
99
+ // Nodes that are within a data store. For example, DDS nodes.
100
+ SubDataStore: "SubDataStore",
99
101
  // Nodes that are for attachment blobs, i.e., blobs uploaded via BlobManager.
100
102
  Blob: "Blob",
101
- // Nodes that are neither data store not blobs. For example, root node and DDS nodes.
103
+ // Nodes that are neither of the above. For example, root node.
102
104
  Other: "Other",
103
105
  };
104
106
  export type GCNodeType = typeof GCNodeType[keyof typeof GCNodeType];
@@ -6,10 +6,8 @@
6
6
  import { IEvent, IEventProvider, ITelemetryLogger } from "@fluidframework/common-definitions";
7
7
  import { assert, TypedEventEmitter } from "@fluidframework/common-utils";
8
8
  import { IDeltaManager } from "@fluidframework/container-definitions";
9
- import { UsageError } from "@fluidframework/container-utils";
10
9
  import { IClient, IQuorumClients, ISequencedClient } from "@fluidframework/protocol-definitions";
11
10
  import { ChildLogger } from "@fluidframework/telemetry-utils";
12
- import { summarizerClientType } from "./summarizerClientElection";
13
11
 
14
12
  // helper types for recursive readonly.
15
13
  // eslint-disable-next-line @typescript-eslint/ban-types
@@ -208,26 +206,16 @@ export interface IOrderedClientElectionEvents extends IEvent {
208
206
  export interface ISerializedElection {
209
207
  /** Sequence number at the time of the latest election. */
210
208
  readonly electionSequenceNumber: number;
211
- /** Most recently elected client id. This is either:
212
- * 1. the interactive elected parent client, in which case electedClientId === electedParentId,
213
- * and the SummaryManager on the elected client will spawn a summarizer client, or
214
- * 2. the non-interactive summarizer client itself. */
209
+ /** Most recently elected client id. */
215
210
  readonly electedClientId: string | undefined;
216
- /** Most recently elected parent client id. This is always an interactive client. */
217
- readonly electedParentId: string | undefined;
218
211
  }
219
212
 
220
213
  /** Contract for maintaining a deterministic client election based on eligibility. */
221
214
  export interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {
222
215
  /** Count of eligible clients in the collection. */
223
216
  readonly eligibleCount: number;
224
- /** Currently elected client. This is either:
225
- * 1. the interactive elected parent client, in which case electedClientId === electedParentId,
226
- * and the SummaryManager on the elected client will spawn a summarizer client, or
227
- * 2. the non-interactive summarizer client itself. */
217
+ /** Currently elected client. */
228
218
  readonly electedClient: ITrackedClient | undefined;
229
- /** Currently elected parent client. This is always an interactive client. */
230
- readonly electedParent: ITrackedClient | undefined;
231
219
  /** Sequence number of most recent election. */
232
220
  readonly electionSequenceNumber: number;
233
221
  /** Marks the currently elected client as invalid, and elects the next eligible client. */
@@ -253,50 +241,16 @@ export class OrderedClientElection
253
241
  implements IOrderedClientElection {
254
242
  private _eligibleCount: number = 0;
255
243
  private _electedClient: ILinkedClient | undefined;
256
- private _electedParent: ILinkedClient | undefined;
257
244
  private _electionSequenceNumber: number;
258
245
 
259
246
  public get eligibleCount() {
260
247
  return this._eligibleCount;
261
248
  }
262
- public get electionSequenceNumber() {
263
- return this._electionSequenceNumber;
264
- }
265
-
266
- /**
267
- * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case
268
- * where a new interactive parent client has been elected, but the summarizer is still doing work, so
269
- * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager
270
- * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has
271
- * left the quorum.
272
- *
273
- * Details:
274
- *
275
- * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest
276
- * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.
277
- * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that
278
- * it spawned stops producing summaries, at which point a new electedParent will be chosen.
279
- *
280
- * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to
281
- * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new
282
- * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until
283
- * electedClient leaves the quorum.
284
- *
285
- * A typical sequence looks like this:
286
- * i. Begin by electing A. electedParent === A, electedClient === A.
287
- * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'
288
- * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'
289
- * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'
290
- * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.
291
- * v. A' completes its summary, and the summarizer and backing client are torn down.
292
- * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B
293
- * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'
294
- */
295
249
  public get electedClient() {
296
250
  return this._electedClient;
297
251
  }
298
- public get electedParent() {
299
- return this._electedParent;
252
+ public get electionSequenceNumber() {
253
+ return this._electionSequenceNumber;
300
254
  }
301
255
 
302
256
  constructor(
@@ -308,20 +262,11 @@ export class OrderedClientElection
308
262
  ) {
309
263
  super();
310
264
  let initialClient: ILinkedClient | undefined;
311
- let initialParent: ILinkedClient | undefined;
312
265
  for (const client of orderedClientCollection.getAllClients()) {
313
266
  this.addClient(client, 0);
314
267
  if (typeof initialState !== "number") {
315
268
  if (client.clientId === initialState.electedClientId) {
316
269
  initialClient = client;
317
- if (initialState.electedParentId === undefined &&
318
- client.client.details.type !== summarizerClientType) {
319
- // If there was no elected parent in the serialized data, use this one.
320
- initialParent = client;
321
- }
322
- }
323
- if (client.clientId === initialState.electedParentId) {
324
- initialParent = client;
325
270
  }
326
271
  }
327
272
  }
@@ -343,7 +288,7 @@ export class OrderedClientElection
343
288
  });
344
289
  } else if (initialClient !== undefined && !isEligibleFn(initialClient)) {
345
290
  // Initially elected client is ineligible, so elect next eligible client.
346
- initialClient = initialParent = this.findFirstEligibleParent(initialParent);
291
+ initialClient = this.findFirstEligibleClient(initialClient);
347
292
  logger.sendErrorEvent({
348
293
  eventName: "InitialElectedClientIneligible",
349
294
  electionSequenceNumber: initialState.electionSequenceNumber,
@@ -351,53 +296,31 @@ export class OrderedClientElection
351
296
  electedClientId: initialClient?.clientId,
352
297
  });
353
298
  }
354
- this._electedParent = initialParent;
355
299
  this._electedClient = initialClient;
356
300
  this._electionSequenceNumber = initialState.electionSequenceNumber;
357
301
  }
358
302
  }
359
303
 
360
- /** Tries changing the elected client, raising an event if it is different.
361
- * Note that this function does no eligibility or suitability checks. If we get here, then
362
- * we will set _electedClient, and we will set _electedParent if this is an interactive client.
363
- */
304
+ /** Tries changing the elected client, raising an event if it is different. */
364
305
  private tryElectingClient(client: ILinkedClient | undefined, sequenceNumber: number): void {
365
- let change = false;
366
- const isSummarizerClient = client?.client.details.type === summarizerClientType;
367
- const prevClient = this._electedClient;
368
- if (this._electedClient !== client) {
369
- // Changing the elected client. Record the sequence number and note that we have to fire an event.
370
- this._electionSequenceNumber = sequenceNumber;
371
- this._electedClient = client;
372
- change = true;
373
- }
374
- if (this._electedParent !== client && !isSummarizerClient) {
375
- // Changing the elected parent as well.
376
- this._electedParent = client;
377
- change = true;
378
- }
379
- if (change) {
380
- this.emit("election", client, sequenceNumber, prevClient);
381
- }
382
- }
383
-
384
- private tryElectingParent(client: ILinkedClient | undefined, sequenceNumber: number): void {
385
- if (this._electedParent !== client) {
386
- this._electedParent = client;
387
- this.emit("election", this._electedClient, sequenceNumber, this._electedClient);
306
+ this._electionSequenceNumber = sequenceNumber;
307
+ if (this._electedClient === client) {
308
+ return;
388
309
  }
310
+ const prevClient = this._electedClient;
311
+ this._electedClient = client;
312
+ this.emit("election", client, sequenceNumber, prevClient);
389
313
  }
390
314
 
391
315
  /**
392
- * Helper function to find the first eligible parent client starting with the passed in client,
316
+ * Helper function to find the first eligible client starting with the passed in client,
393
317
  * or undefined if none are eligible.
394
318
  * @param client - client to start checking
395
319
  * @returns oldest eligible client starting with passed in client or undefined if none.
396
320
  */
397
- private findFirstEligibleParent(client: ILinkedClient | undefined): ILinkedClient | undefined {
321
+ private findFirstEligibleClient(client: ILinkedClient | undefined): ILinkedClient | undefined {
398
322
  let candidateClient = client;
399
- while (candidateClient !== undefined &&
400
- (!this.isEligibleFn(candidateClient) || candidateClient.client.details.type === summarizerClientType)) {
323
+ while (candidateClient !== undefined && !this.isEligibleFn(candidateClient)) {
401
324
  candidateClient = candidateClient.youngerClient;
402
325
  }
403
326
  return candidateClient;
@@ -412,16 +335,10 @@ export class OrderedClientElection
412
335
  private addClient(client: ILinkedClient, sequenceNumber: number): void {
413
336
  if (this.isEligibleFn(client)) {
414
337
  this._eligibleCount++;
415
- const newClientIsSummarizer = client.client.details.type === summarizerClientType;
416
- const electedClientIsSummarizer = this._electedClient?.client.details.type === summarizerClientType;
417
- // Note that we allow a summarizer client to supercede an interactive client as elected client.
418
- if (this._electedClient === undefined || (!electedClientIsSummarizer && newClientIsSummarizer)) {
338
+ if (this._electedClient === undefined) {
339
+ // Automatically elect latest client
419
340
  this.tryElectingClient(client, sequenceNumber);
420
341
  }
421
- else if (this._electedParent === undefined && !newClientIsSummarizer) {
422
- // This is an odd case. If the _electedClient is set, the _electedParent should be as well.
423
- this.tryElectingParent(client, sequenceNumber);
424
- }
425
342
  }
426
343
  }
427
344
 
@@ -435,33 +352,9 @@ export class OrderedClientElection
435
352
  if (this.isEligibleFn(client)) {
436
353
  this._eligibleCount--;
437
354
  if (this._electedClient === client) {
438
- // Removing the _electedClient. There are 2 possible cases:
439
- if (this._electedParent !== client) {
440
- // 1. The _electedClient is a summarizer that we've been allowing to finish its work.
441
- // Let the _electedParent become the _electedClient so that it can start its own summarizer.
442
- if (this._electedClient.client.details.type !== summarizerClientType) {
443
- throw new UsageError("Elected client should be a summarizer client 1");
444
- }
445
- this.tryElectingClient(this._electedParent, sequenceNumber);
446
- }
447
- else {
448
- // 2. The _electedClient is an interactive client that has left the quorum.
449
- // Automatically shift to next oldest client.
450
- const nextClient = this.findFirstEligibleParent(this._electedParent?.youngerClient) ??
451
- this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
452
- this.tryElectingClient(nextClient, sequenceNumber);
453
- }
454
- }
455
- else if (this._electedParent === client) {
456
- // Removing the _electedParent (but not _electedClient).
457
- // Shift to the next oldest parent, but do not replace the _electedClient,
458
- // which is a summarizer that is still doing work.
459
- if (this._electedClient?.client.details.type !== summarizerClientType) {
460
- throw new UsageError("Elected client should be a summarizer client 2");
461
- }
462
- const nextParent = this.findFirstEligibleParent(this._electedParent?.youngerClient) ??
463
- this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
464
- this.tryElectingParent(nextParent, sequenceNumber);
355
+ // Automatically shift to next oldest client
356
+ const nextClient = this.findFirstEligibleClient(this._electedClient.youngerClient);
357
+ this.tryElectingClient(nextClient, sequenceNumber);
465
358
  }
466
359
  }
467
360
  }
@@ -470,46 +363,24 @@ export class OrderedClientElection
470
363
  return this.orderedClientCollection.getAllClients().filter(this.isEligibleFn);
471
364
  }
472
365
 
473
- /** Advance election to the next-oldest client. This is called if the current parent is leaving the quorum,
474
- * or if the current summarizer is not responsive and we want to stop it and spawn a new one.
475
- */
476
366
  public incrementElectedClient(sequenceNumber: number): void {
477
- const nextClient = this.findFirstEligibleParent(this._electedParent?.youngerClient) ??
478
- this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
479
- if (this._electedClient === undefined || this._electedClient === this._electedParent) {
480
- this.tryElectingClient(nextClient, sequenceNumber);
481
- }
482
- else {
483
- // The _electedClient is a summarizer and should not be replaced until it leaves the quorum.
484
- // Changing the _electedParent will stop the summarizer.
485
- this.tryElectingParent(nextClient, sequenceNumber);
486
- }
367
+ const nextClient = this.findFirstEligibleClient(this._electedClient?.youngerClient);
368
+ this.tryElectingClient(nextClient, sequenceNumber);
487
369
  }
488
370
 
489
- /** (Re-)start election with the oldest client in the quorum. This is called if we need to summarize
490
- * and no client has been elected.
491
- */
492
371
  public resetElectedClient(sequenceNumber: number): void {
493
- const firstClient = this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
494
- if (this._electedClient === undefined || this._electedClient === this._electedParent) {
495
- this.tryElectingClient(firstClient, sequenceNumber);
496
- }
497
- else {
498
- // The _electedClient is a summarizer and should not be replaced until it leaves the quorum.
499
- // Changing the _electedParent will stop the summarizer.
500
- this.tryElectingParent(firstClient, sequenceNumber);
501
- }
372
+ const firstClient = this.findFirstEligibleClient(this.orderedClientCollection.oldestClient);
373
+ this.tryElectingClient(firstClient, sequenceNumber);
502
374
  }
503
375
 
504
376
  public peekNextElectedClient(): ITrackedClient | undefined {
505
- return this.findFirstEligibleParent(this._electedParent?.youngerClient);
377
+ return this.findFirstEligibleClient(this._electedClient?.youngerClient);
506
378
  }
507
379
 
508
380
  public serialize(): ISerializedElection {
509
381
  return {
510
382
  electionSequenceNumber: this.electionSequenceNumber,
511
383
  electedClientId: this.electedClient?.clientId,
512
- electedParentId: this.electedParent?.clientId,
513
384
  };
514
385
  }
515
386
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/container-runtime";
9
- export const pkgVersion = "0.59.1000-61898";
9
+ export const pkgVersion = "0.59.1001";
@@ -17,7 +17,6 @@ export interface ISummarizerClientElectionEvents extends IEvent {
17
17
 
18
18
  export interface ISummarizerClientElection extends IEventProvider<ISummarizerClientElectionEvents> {
19
19
  readonly electedClientId: string | undefined;
20
- readonly electedParentId: string | undefined;
21
20
  }
22
21
 
23
22
  /**
@@ -45,9 +44,6 @@ export class SummarizerClientElection
45
44
  public get electedClientId() {
46
45
  return this.clientElection.electedClient?.clientId;
47
46
  }
48
- public get electedParentId() {
49
- return this.clientElection.electedParent?.clientId;
50
- }
51
47
 
52
48
  constructor(
53
49
  private readonly logger: ITelemetryLogger,
@@ -131,10 +127,9 @@ export class SummarizerClientElection
131
127
  }
132
128
 
133
129
  public serialize(): ISerializedElection {
134
- const { electedClientId, electedParentId, electionSequenceNumber } = this.clientElection.serialize();
130
+ const { electedClientId, electionSequenceNumber } = this.clientElection.serialize();
135
131
  return {
136
132
  electedClientId,
137
- electedParentId,
138
133
  electionSequenceNumber: this.lastSummaryAckSeqForClient ?? electionSequenceNumber,
139
134
  };
140
135
  }
@@ -149,5 +144,5 @@ export class SummarizerClientElection
149
144
  }
150
145
 
151
146
  public static readonly clientDetailsPermitElection = (details: IClientDetails): boolean =>
152
- details.capabilities.interactive || details.type === summarizerClientType;
147
+ details.capabilities.interactive && details.type !== summarizerClientType;
153
148
  }