@fluidframework/container-runtime 0.59.1000-61898 → 0.59.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.
Files changed (35) hide show
  1. package/dist/orderedClientElection.d.ts +6 -57
  2. package/dist/orderedClientElection.d.ts.map +1 -1
  3. package/dist/orderedClientElection.js +25 -140
  4. package/dist/orderedClientElection.js.map +1 -1
  5. package/dist/packageVersion.d.ts +1 -1
  6. package/dist/packageVersion.d.ts.map +1 -1
  7. package/dist/packageVersion.js +1 -1
  8. package/dist/packageVersion.js.map +1 -1
  9. package/dist/summarizerClientElection.d.ts +0 -2
  10. package/dist/summarizerClientElection.d.ts.map +1 -1
  11. package/dist/summarizerClientElection.js +2 -7
  12. package/dist/summarizerClientElection.js.map +1 -1
  13. package/dist/summaryManager.d.ts.map +1 -1
  14. package/dist/summaryManager.js +3 -14
  15. package/dist/summaryManager.js.map +1 -1
  16. package/lib/orderedClientElection.d.ts +6 -57
  17. package/lib/orderedClientElection.d.ts.map +1 -1
  18. package/lib/orderedClientElection.js +25 -140
  19. package/lib/orderedClientElection.js.map +1 -1
  20. package/lib/packageVersion.d.ts +1 -1
  21. package/lib/packageVersion.d.ts.map +1 -1
  22. package/lib/packageVersion.js +1 -1
  23. package/lib/packageVersion.js.map +1 -1
  24. package/lib/summarizerClientElection.d.ts +0 -2
  25. package/lib/summarizerClientElection.d.ts.map +1 -1
  26. package/lib/summarizerClientElection.js +2 -7
  27. package/lib/summarizerClientElection.js.map +1 -1
  28. package/lib/summaryManager.d.ts.map +1 -1
  29. package/lib/summaryManager.js +3 -14
  30. package/lib/summaryManager.js.map +1 -1
  31. package/package.json +17 -17
  32. package/src/orderedClientElection.ts +25 -154
  33. package/src/packageVersion.ts +1 -1
  34. package/src/summarizerClientElection.ts +2 -7
  35. package/src/summaryManager.ts +4 -15
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerClientElection.js","sourceRoot":"","sources":["../src/summarizerClientElection.ts"],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GAAG,SAAS,CAAC;YAC5C,IAAI,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,cAAc,CAAC,aAAa,GAAG,CAAC,EAAE;gBAC/D,iEAAiE;gBACjE,kEAAkE;gBAClE,mEAAmE;gBACnE,4BAA4B;gBAC5B,IAAI,CAAC,cAAc,CAAC,kBAAkB,CAAC,cAAc,CAAC,CAAC;aAC1D;YACD,yDAAyD;YACzD,IAAI,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACP,CAAC;IAtFD,IAAW,eAAe;;QACtB,aAAO,IAAI,CAAC,cAAc,CAAC,aAAa,0CAAE,QAAQ,CAAC;IACvD,CAAC;IACD,IAAW,eAAe;;QACtB,aAAO,IAAI,CAAC,cAAc,CAAC,aAAa,0CAAE,QAAQ,CAAC;IACvD,CAAC;IAmFM,SAAS;;QACZ,MAAM,EAAE,eAAe,EAAE,eAAe,EAAE,sBAAsB,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;QACrG,OAAO;YACH,eAAe;YACf,eAAe;YACf,sBAAsB,QAAE,IAAI,CAAC,0BAA0B,mCAAI,sBAAsB;SACpF,CAAC;IACN,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,MAAsB;QACjD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QACtC,IAAI,OAAO,KAAK,SAAS,EAAE;YACvB,+BAA+B;YAC/B,OAAO,IAAI,CAAC;SACf;QACD,OAAO,wBAAwB,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;;AAzHL,4DA6HC;AAF0B,oDAA2B,GAAG,CAAC,OAAuB,EAAW,EAAE,CACtF,OAAO,CAAC,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,4BAAoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IClientDetails, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { IOrderedClientElection, ISerializedElection, ITrackedClient } from \"./orderedClientElection\";\nimport { ISummaryCollectionOpEvents } from \"./summaryCollection\";\n\nexport const summarizerClientType = \"summarizer\";\n\nexport interface ISummarizerClientElectionEvents extends IEvent {\n (event: \"electedSummarizerChanged\", handler: () => void): void;\n}\n\nexport interface ISummarizerClientElection extends IEventProvider<ISummarizerClientElectionEvents> {\n readonly electedClientId: string | undefined;\n readonly electedParentId: string | undefined;\n}\n\n/**\n * This class encapsulates logic around tracking the elected summarizer client.\n * It will handle updating the elected client when a summary ack hasn't been seen\n * for some configured number of ops.\n */\nexport class SummarizerClientElection\n extends TypedEventEmitter<ISummarizerClientElectionEvents>\n implements ISummarizerClientElection {\n /**\n * Used to calculate number of ops since last summary ack for the current elected client.\n * This will be undefined if there is no elected summarizer, or no summary ack has been\n * observed since this client was elected.\n * When a summary ack comes in, this will be set to the sequence number of the summary ack.\n */\n private lastSummaryAckSeqForClient: number | undefined;\n /**\n * Used to prevent excess logging by recording the sequence number that we last reported at,\n * and making sure we don't report another event to telemetry. If things work as intended,\n * this is not needed, otherwise it could report an event on every op in worst case scenario.\n */\n private lastReportedSeq = 0;\n\n public get electedClientId() {\n return this.clientElection.electedClient?.clientId;\n }\n public get electedParentId() {\n return this.clientElection.electedParent?.clientId;\n }\n\n constructor(\n private readonly logger: ITelemetryLogger,\n private readonly summaryCollection: IEventProvider<ISummaryCollectionOpEvents>,\n public readonly clientElection: IOrderedClientElection,\n private readonly maxOpsSinceLastSummary: number,\n private readonly electionEnabled: boolean,\n ) {\n super();\n // On every inbound op, if enough ops pass without seeing a summary ack (per elected client),\n // elect a new client and log to telemetry.\n this.summaryCollection.on(\"default\", ({ sequenceNumber }) => {\n const electedClientId = this.electedClientId;\n if (electedClientId === undefined) {\n // Reset election if no elected client, but eligible clients are connected.\n // This should be uncommon, but is possible if the initial state of the\n // ordered client election contains an undefined client id or one not found\n // in the quorum (the latter would already log an error).\n if (this.clientElection.eligibleCount > 0) {\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n return;\n }\n let electionSequenceNumber = this.clientElection.electionSequenceNumber;\n const opsWithoutSummary = sequenceNumber - (this.lastSummaryAckSeqForClient ?? electionSequenceNumber);\n if (opsWithoutSummary > this.maxOpsSinceLastSummary) {\n // Log and elect a new summarizer client.\n const opsSinceLastReport = sequenceNumber - this.lastReportedSeq;\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"ElectedClientNotSummarizing\",\n electedClientId,\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n electionSequenceNumber,\n nextElectedClientId: this.clientElection.peekNextElectedClient()?.clientId,\n electionEnabled: this.electionEnabled,\n });\n this.lastReportedSeq = sequenceNumber;\n }\n\n if (this.electionEnabled) {\n this.clientElection.incrementElectedClient(sequenceNumber);\n\n // Verify that state incremented as expected. This should be reliable,\n // since all of OrderedClientElection is synchronous.\n electionSequenceNumber = this.clientElection.electionSequenceNumber;\n if (sequenceNumber > (this.lastSummaryAckSeqForClient ?? electionSequenceNumber)) {\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"UnexpectedElectionSequenceNumber\",\n // Expected to be undefined\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n // Expected to be same as op sequenceNumber\n electionSequenceNumber,\n });\n }\n }\n }\n }\n });\n\n // When a summary ack comes in, reset our op seq counter.\n this.summaryCollection.on(MessageType.SummaryAck, (op) => {\n this.lastSummaryAckSeqForClient = op.sequenceNumber;\n });\n\n // Use oldest client election for unanimously and deterministically deciding\n // which client should summarize.\n this.clientElection.on(\"election\", (client, sequenceNumber) => {\n this.lastSummaryAckSeqForClient = undefined;\n if (client === undefined && this.clientElection.eligibleCount > 0) {\n // If no client is valid for election, reset to the oldest again.\n // Also make extra sure not to get stuck in an infinite loop here:\n // If there are no eligible clients, just wait until a client joins\n // and will be auto-elected.\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n // Election can trigger a change in SummaryManager state.\n this.emit(\"electedSummarizerChanged\");\n });\n }\n\n public serialize(): ISerializedElection {\n const { electedClientId, electedParentId, electionSequenceNumber } = this.clientElection.serialize();\n return {\n electedClientId,\n electedParentId,\n electionSequenceNumber: this.lastSummaryAckSeqForClient ?? electionSequenceNumber,\n };\n }\n\n public static isClientEligible(client: ITrackedClient): boolean {\n const details = client.client.details;\n if (details === undefined) {\n // Very old clients back-compat\n return true;\n }\n return SummarizerClientElection.clientDetailsPermitElection(details);\n }\n\n public static readonly clientDetailsPermitElection = (details: IClientDetails): boolean =>\n details.capabilities.interactive || details.type === summarizerClientType;\n}\n"]}
1
+ {"version":3,"file":"summarizerClientElection.js","sourceRoot":"","sources":["../src/summarizerClientElection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAiE;AACjE,+EAAmF;AAItE,QAAA,oBAAoB,GAAG,YAAY,CAAC;AAUjD;;;;GAIG;AACH,MAAa,wBACT,SAAQ,gCAAkD;IAoB1D,YACqB,MAAwB,EACxB,iBAA6D,EAC9D,cAAsC,EACrC,sBAA8B,EAC9B,eAAwB;QAEzC,KAAK,EAAE,CAAC;QANS,WAAM,GAAN,MAAM,CAAkB;QACxB,sBAAiB,GAAjB,iBAAiB,CAA4C;QAC9D,mBAAc,GAAd,cAAc,CAAwB;QACrC,2BAAsB,GAAtB,sBAAsB,CAAQ;QAC9B,oBAAe,GAAf,eAAe,CAAS;QAhB7C;;;;WAIG;QACK,oBAAe,GAAG,CAAC,CAAC;QAcxB,6FAA6F;QAC7F,2CAA2C;QAC3C,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;;YACxD,MAAM,eAAe,GAAG,IAAI,C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C;IACN,CAAC;IAEM,MAAM,CAAC,gBAAgB,CAAC,MAAsB;QACjD,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QACtC,IAAI,OAAO,KAAK,SAAS,EAAE;YACvB,+BAA+B;YAC/B,OAAO,IAAI,CAAC;SACf;QACD,OAAO,wBAAwB,CAAC,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACzE,CAAC;;AArHL,4DAyHC;AAF0B,oDAA2B,GAAG,CAAC,OAAuB,EAAW,EAAE,CACtF,OAAO,CAAC,YAAY,CAAC,WAAW,IAAI,OAAO,CAAC,IAAI,KAAK,4BAAoB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IClientDetails, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { IOrderedClientElection, ISerializedElection, ITrackedClient } from \"./orderedClientElection\";\nimport { ISummaryCollectionOpEvents } from \"./summaryCollection\";\n\nexport const summarizerClientType = \"summarizer\";\n\nexport interface ISummarizerClientElectionEvents extends IEvent {\n (event: \"electedSummarizerChanged\", handler: () => void): void;\n}\n\nexport interface ISummarizerClientElection extends IEventProvider<ISummarizerClientElectionEvents> {\n readonly electedClientId: string | undefined;\n}\n\n/**\n * This class encapsulates logic around tracking the elected summarizer client.\n * It will handle updating the elected client when a summary ack hasn't been seen\n * for some configured number of ops.\n */\nexport class SummarizerClientElection\n extends TypedEventEmitter<ISummarizerClientElectionEvents>\n implements ISummarizerClientElection {\n /**\n * Used to calculate number of ops since last summary ack for the current elected client.\n * This will be undefined if there is no elected summarizer, or no summary ack has been\n * observed since this client was elected.\n * When a summary ack comes in, this will be set to the sequence number of the summary ack.\n */\n private lastSummaryAckSeqForClient: number | undefined;\n /**\n * Used to prevent excess logging by recording the sequence number that we last reported at,\n * and making sure we don't report another event to telemetry. If things work as intended,\n * this is not needed, otherwise it could report an event on every op in worst case scenario.\n */\n private lastReportedSeq = 0;\n\n public get electedClientId() {\n return this.clientElection.electedClient?.clientId;\n }\n\n constructor(\n private readonly logger: ITelemetryLogger,\n private readonly summaryCollection: IEventProvider<ISummaryCollectionOpEvents>,\n public readonly clientElection: IOrderedClientElection,\n private readonly maxOpsSinceLastSummary: number,\n private readonly electionEnabled: boolean,\n ) {\n super();\n // On every inbound op, if enough ops pass without seeing a summary ack (per elected client),\n // elect a new client and log to telemetry.\n this.summaryCollection.on(\"default\", ({ sequenceNumber }) => {\n const electedClientId = this.electedClientId;\n if (electedClientId === undefined) {\n // Reset election if no elected client, but eligible clients are connected.\n // This should be uncommon, but is possible if the initial state of the\n // ordered client election contains an undefined client id or one not found\n // in the quorum (the latter would already log an error).\n if (this.clientElection.eligibleCount > 0) {\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n return;\n }\n let electionSequenceNumber = this.clientElection.electionSequenceNumber;\n const opsWithoutSummary = sequenceNumber - (this.lastSummaryAckSeqForClient ?? electionSequenceNumber);\n if (opsWithoutSummary > this.maxOpsSinceLastSummary) {\n // Log and elect a new summarizer client.\n const opsSinceLastReport = sequenceNumber - this.lastReportedSeq;\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"ElectedClientNotSummarizing\",\n electedClientId,\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n electionSequenceNumber,\n nextElectedClientId: this.clientElection.peekNextElectedClient()?.clientId,\n electionEnabled: this.electionEnabled,\n });\n this.lastReportedSeq = sequenceNumber;\n }\n\n if (this.electionEnabled) {\n this.clientElection.incrementElectedClient(sequenceNumber);\n\n // Verify that state incremented as expected. This should be reliable,\n // since all of OrderedClientElection is synchronous.\n electionSequenceNumber = this.clientElection.electionSequenceNumber;\n if (sequenceNumber > (this.lastSummaryAckSeqForClient ?? electionSequenceNumber)) {\n if (opsSinceLastReport > this.maxOpsSinceLastSummary) {\n this.logger.sendErrorEvent({\n eventName: \"UnexpectedElectionSequenceNumber\",\n // Expected to be undefined\n lastSummaryAckSeqForClient: this.lastSummaryAckSeqForClient,\n // Expected to be same as op sequenceNumber\n electionSequenceNumber,\n });\n }\n }\n }\n }\n });\n\n // When a summary ack comes in, reset our op seq counter.\n this.summaryCollection.on(MessageType.SummaryAck, (op) => {\n this.lastSummaryAckSeqForClient = op.sequenceNumber;\n });\n\n // Use oldest client election for unanimously and deterministically deciding\n // which client should summarize.\n this.clientElection.on(\"election\", (client, sequenceNumber) => {\n this.lastSummaryAckSeqForClient = undefined;\n if (client === undefined && this.clientElection.eligibleCount > 0) {\n // If no client is valid for election, reset to the oldest again.\n // Also make extra sure not to get stuck in an infinite loop here:\n // If there are no eligible clients, just wait until a client joins\n // and will be auto-elected.\n this.clientElection.resetElectedClient(sequenceNumber);\n }\n // Election can trigger a change in SummaryManager state.\n this.emit(\"electedSummarizerChanged\");\n });\n }\n\n public serialize(): ISerializedElection {\n const { electedClientId, electionSequenceNumber } = this.clientElection.serialize();\n return {\n electedClientId,\n electionSequenceNumber: this.lastSummaryAckSeqForClient ?? electionSequenceNumber,\n };\n }\n\n public static isClientEligible(client: ITrackedClient): boolean {\n const details = client.client.details;\n if (details === undefined) {\n // Very old clients back-compat\n return true;\n }\n return SummarizerClientElection.clientDetailsPermitElection(details);\n }\n\n public static readonly clientDetailsPermitElection = (details: IClientDetails): boolean =>\n details.capabilities.interactive && details.type !== summarizerClientType;\n}\n"]}
@@ -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,oCAAoC,CAAC;AAI3G,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,aA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AC3C,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,UAAU,CAAC,CAAc;IACjC,OAAO,CAAC,SAAS,CAAS;IAE1B,IAAW,QAAQ,YAElB;IAED,IAAW,YAAY,wBAAyB;gBAG3B,cAAc,EAAE,yBAAyB,EACzC,cAAc,EAAE,eAAe,EAC/B,iBAAiB,EAC9B,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,eAAe,GAAG,kBAAkB,CAAC,EACrF,YAAY,EAAE,gBAAgB;IAC9B;2CACuC;IACtB,mBAAmB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,EAC/C,cAAc,EAAE,UAAU,EAC3C,EACI,cAAsC,EACtC,uBAAwD,GAC3D,GAAE,QAAQ,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAM,EAC/B,iBAAiB,CAAC,mDAAuC;IAe9E;;;OAGG;IACI,KAAK,IAAI,IAAI;IAKpB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAM9B;IAEF,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAEjC;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CACyC;IAEpF,OAAO,CAAC,uBAAuB;IAY/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CA+BhC;IAEF,OAAO,CAAC,kBAAkB;IAqF1B,OAAO,CAAC,IAAI;IAWZ;;;;OAIG;YACW,6BAA6B;IAqD3C,SAAgB,iBAAiB,EAAE,WAAW,CAAC,mBAAmB,CAAC,CAMjE;IAEF,SAAgB,gBAAgB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAM/D;IAEK,OAAO;CAMjB"}
@@ -111,16 +111,10 @@ class SummaryManager {
111
111
  this.refreshSummarizer();
112
112
  }
113
113
  getShouldSummarizeState() {
114
- // Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't
115
- // enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should
116
- // only transition to Stopping when the electedParentId changes. Stopping the summarizer without
117
- // changing the electedParent will just cause us to transition to Starting again.
118
114
  if (!this.connectedState.connected) {
119
115
  return { shouldSummarize: false, stopReason: "parentNotConnected" };
120
116
  }
121
- else if (this.connectedState.clientId !== this.clientElection.electedParentId ||
122
- (this.state !== SummaryManagerState.Running &&
123
- this.connectedState.clientId !== this.clientElection.electedClientId)) {
117
+ else if (this.connectedState.clientId !== this.clientElection.electedClientId) {
124
118
  return { shouldSummarize: false, stopReason: "parentShouldNotSummarize" };
125
119
  }
126
120
  else if (this.disposed) {
@@ -144,20 +138,15 @@ class SummaryManager {
144
138
  if (startWithInitialDelay && this.getShouldSummarizeState().shouldSummarize === false) {
145
139
  return;
146
140
  }
147
- // We transition to Running before requesting the summarizer, because after requesting we can't predict
148
- // when the electedClient will be replaced with the new summarizer client.
149
- // The alternative would be to let connectedState.clientId !== clientElection.electedClientId when
150
- // state === Starting || state === Running.
151
- common_utils_1.assert(this.state === SummaryManagerState.Starting, 0x263 /* "Expected: starting" */);
152
- this.state = SummaryManagerState.Running;
153
141
  const summarizer = await this.requestSummarizerFn();
154
142
  // Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore
155
143
  const shouldSummarizeState = this.getShouldSummarizeState();
156
144
  if (shouldSummarizeState.shouldSummarize === false) {
157
- this.state = SummaryManagerState.Starting;
158
145
  summarizer.stop(shouldSummarizeState.stopReason);
159
146
  return;
160
147
  }
148
+ common_utils_1.assert(this.state === SummaryManagerState.Starting, 0x263 /* "Expected: starting" */);
149
+ this.state = SummaryManagerState.Running;
161
150
  this.summarizer = summarizer;
162
151
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
163
152
  const clientId = this.latestClientId;
@@ -1 +1 @@
1
- {"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../src/summaryManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAAsD;AACtD,qEAAgF;AAChF,2EAAqE;AAUrE,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,G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AC,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;;AA3SL,wCA4SC;AA3O2B,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,+DAAsD;AACtD,qEAAgF;AAChF,2EAAqE;AAUrE,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC3B,2DAAO,CAAA;IACP,qEAAY,CAAA;IACZ,mEAAW,CAAA;IACX,qEAAY,CAAA;AAChB,CAAC,EALW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAK9B;AAuCD;;;;GAIG;AACH,MAAa,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,CA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AI,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;;AAhSL,wCAiSC;AAhO2B,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"]}
@@ -84,25 +84,15 @@ export interface IOrderedClientElectionEvents extends IEvent {
84
84
  export interface ISerializedElection {
85
85
  /** Sequence number at the time of the latest election. */
86
86
  readonly electionSequenceNumber: number;
87
- /** Most recently elected client id. This is either:
88
- * 1. the interactive elected parent client, in which case electedClientId === electedParentId,
89
- * and the SummaryManager on the elected client will spawn a summarizer client, or
90
- * 2. the non-interactive summarizer client itself. */
87
+ /** Most recently elected client id. */
91
88
  readonly electedClientId: string | undefined;
92
- /** Most recently elected parent client id. This is always an interactive client. */
93
- readonly electedParentId: string | undefined;
94
89
  }
95
90
  /** Contract for maintaining a deterministic client election based on eligibility. */
96
91
  export interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {
97
92
  /** Count of eligible clients in the collection. */
98
93
  readonly eligibleCount: number;
99
- /** Currently elected client. This is either:
100
- * 1. the interactive elected parent client, in which case electedClientId === electedParentId,
101
- * and the SummaryManager on the elected client will spawn a summarizer client, or
102
- * 2. the non-interactive summarizer client itself. */
94
+ /** Currently elected client. */
103
95
  readonly electedClient: ITrackedClient | undefined;
104
- /** Currently elected parent client. This is always an interactive client. */
105
- readonly electedParent: ITrackedClient | undefined;
106
96
  /** Sequence number of most recent election. */
107
97
  readonly electionSequenceNumber: number;
108
98
  /** Marks the currently elected client as invalid, and elects the next eligible client. */
@@ -127,57 +117,22 @@ export declare class OrderedClientElection extends TypedEventEmitter<IOrderedCli
127
117
  private readonly isEligibleFn;
128
118
  private _eligibleCount;
129
119
  private _electedClient;
130
- private _electedParent;
131
120
  private _electionSequenceNumber;
132
121
  get eligibleCount(): number;
133
- get electionSequenceNumber(): number;
134
- /**
135
- * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case
136
- * where a new interactive parent client has been elected, but the summarizer is still doing work, so
137
- * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager
138
- * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has
139
- * left the quorum.
140
- *
141
- * Details:
142
- *
143
- * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest
144
- * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.
145
- * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that
146
- * it spawned stops producing summaries, at which point a new electedParent will be chosen.
147
- *
148
- * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to
149
- * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new
150
- * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until
151
- * electedClient leaves the quorum.
152
- *
153
- * A typical sequence looks like this:
154
- * i. Begin by electing A. electedParent === A, electedClient === A.
155
- * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'
156
- * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'
157
- * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'
158
- * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.
159
- * v. A' completes its summary, and the summarizer and backing client are torn down.
160
- * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B
161
- * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'
162
- */
163
122
  get electedClient(): ILinkedClient | undefined;
164
- get electedParent(): ILinkedClient | undefined;
123
+ get electionSequenceNumber(): number;
165
124
  constructor(logger: ITelemetryLogger, orderedClientCollection: IOrderedClientCollection,
166
125
  /** Serialized state from summary or current sequence number at time of load if new. */
167
126
  initialState: ISerializedElection | number, isEligibleFn: (c: ITrackedClient) => boolean);
168
- /** Tries changing the elected client, raising an event if it is different.
169
- * Note that this function does no eligibility or suitability checks. If we get here, then
170
- * we will set _electedClient, and we will set _electedParent if this is an interactive client.
171
- */
127
+ /** Tries changing the elected client, raising an event if it is different. */
172
128
  private tryElectingClient;
173
- private tryElectingParent;
174
129
  /**
175
- * Helper function to find the first eligible parent client starting with the passed in client,
130
+ * Helper function to find the first eligible client starting with the passed in client,
176
131
  * or undefined if none are eligible.
177
132
  * @param client - client to start checking
178
133
  * @returns oldest eligible client starting with passed in client or undefined if none.
179
134
  */
180
- private findFirstEligibleParent;
135
+ private findFirstEligibleClient;
181
136
  /**
182
137
  * Updates tracking for when a new client is added to the collection.
183
138
  * Will automatically elect that new client if none is elected currently.
@@ -193,13 +148,7 @@ export declare class OrderedClientElection extends TypedEventEmitter<IOrderedCli
193
148
  */
194
149
  private removeClient;
195
150
  getAllEligibleClients(): ITrackedClient[];
196
- /** Advance election to the next-oldest client. This is called if the current parent is leaving the quorum,
197
- * or if the current summarizer is not responsive and we want to stop it and spawn a new one.
198
- */
199
151
  incrementElectedClient(sequenceNumber: number): void;
200
- /** (Re-)start election with the oldest client in the quorum. This is called if we need to summarize
201
- * and no client has been elected.
202
- */
203
152
  resetElectedClient(sequenceNumber: number): void;
204
153
  peekNextElectedClient(): ITrackedClient | undefined;
205
154
  serialize(): ISerializedElection;
@@ -1 +1 @@
1
- {"version":3,"file":"orderedClientElection.d.ts","sourceRoot":"","sources":["../src/orderedClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAoB,MAAM,sCAAsC,CAAC;AAMjG,oBAAY,mBAAmB,GAAG,SAAS,GAAG,I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,EAAE,gBAAgB,EACP,uBAAuB,EAAE,wBAAwB;IAClE,uFAAuF;IACvF,YAAY,EAAE,mBAAmB,GAAG,MAAM,EACzB,YAAY,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,OAAO;IA2CjE,8EAA8E;IAC9E,OAAO,CAAC,iBAAiB;IAUzB;;;;;OAKG;IACH,OAAO,CAAC,uBAAuB;IAQ/B;;;;;OAKG;IACH,OAAO,CAAC,SAAS;IAUjB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;IAWb,qBAAqB,IAAI,cAAc,EAAE;IAIzC,sBAAsB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAKpD,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAKhD,qBAAqB,IAAI,cAAc,GAAG,SAAS;IAInD,SAAS,IAAI,mBAAmB;CAM1C"}
@@ -3,9 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert, TypedEventEmitter } from "@fluidframework/common-utils";
6
- import { UsageError } from "@fluidframework/container-utils";
7
6
  import { ChildLogger } from "@fluidframework/telemetry-utils";
8
- import { summarizerClientType } from "./summarizerClientElection";
9
7
  /**
10
8
  * Tracks clients in the Quorum. It maintains their order using their join op
11
9
  * sequence numbers.
@@ -127,20 +125,11 @@ export class OrderedClientElection extends TypedEventEmitter {
127
125
  this.isEligibleFn = isEligibleFn;
128
126
  this._eligibleCount = 0;
129
127
  let initialClient;
130
- let initialParent;
131
128
  for (const client of orderedClientCollection.getAllClients()) {
132
129
  this.addClient(client, 0);
133
130
  if (typeof initialState !== "number") {
134
131
  if (client.clientId === initialState.electedClientId) {
135
132
  initialClient = client;
136
- if (initialState.electedParentId === undefined &&
137
- client.client.details.type !== summarizerClientType) {
138
- // If there was no elected parent in the serialized data, use this one.
139
- initialParent = client;
140
- }
141
- }
142
- if (client.clientId === initialState.electedParentId) {
143
- initialParent = client;
144
133
  }
145
134
  }
146
135
  }
@@ -163,7 +152,7 @@ export class OrderedClientElection extends TypedEventEmitter {
163
152
  }
164
153
  else if (initialClient !== undefined && !isEligibleFn(initialClient)) {
165
154
  // Initially elected client is ineligible, so elect next eligible client.
166
- initialClient = initialParent = this.findFirstEligibleParent(initialParent);
155
+ initialClient = this.findFirstEligibleClient(initialClient);
167
156
  logger.sendErrorEvent({
168
157
  eventName: "InitialElectedClientIneligible",
169
158
  electionSequenceNumber: initialState.electionSequenceNumber,
@@ -171,7 +160,6 @@ export class OrderedClientElection extends TypedEventEmitter {
171
160
  electedClientId: initialClient === null || initialClient === void 0 ? void 0 : initialClient.clientId,
172
161
  });
173
162
  }
174
- this._electedParent = initialParent;
175
163
  this._electedClient = initialClient;
176
164
  this._electionSequenceNumber = initialState.electionSequenceNumber;
177
165
  }
@@ -179,83 +167,31 @@ export class OrderedClientElection extends TypedEventEmitter {
179
167
  get eligibleCount() {
180
168
  return this._eligibleCount;
181
169
  }
182
- get electionSequenceNumber() {
183
- return this._electionSequenceNumber;
184
- }
185
- /**
186
- * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case
187
- * where a new interactive parent client has been elected, but the summarizer is still doing work, so
188
- * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager
189
- * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has
190
- * left the quorum.
191
- *
192
- * Details:
193
- *
194
- * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest
195
- * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.
196
- * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that
197
- * it spawned stops producing summaries, at which point a new electedParent will be chosen.
198
- *
199
- * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to
200
- * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new
201
- * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until
202
- * electedClient leaves the quorum.
203
- *
204
- * A typical sequence looks like this:
205
- * i. Begin by electing A. electedParent === A, electedClient === A.
206
- * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'
207
- * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'
208
- * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'
209
- * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.
210
- * v. A' completes its summary, and the summarizer and backing client are torn down.
211
- * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B
212
- * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'
213
- */
214
170
  get electedClient() {
215
171
  return this._electedClient;
216
172
  }
217
- get electedParent() {
218
- return this._electedParent;
173
+ get electionSequenceNumber() {
174
+ return this._electionSequenceNumber;
219
175
  }
220
- /** Tries changing the elected client, raising an event if it is different.
221
- * Note that this function does no eligibility or suitability checks. If we get here, then
222
- * we will set _electedClient, and we will set _electedParent if this is an interactive client.
223
- */
176
+ /** Tries changing the elected client, raising an event if it is different. */
224
177
  tryElectingClient(client, sequenceNumber) {
225
- let change = false;
226
- const isSummarizerClient = (client === null || client === void 0 ? void 0 : client.client.details.type) === summarizerClientType;
227
- const prevClient = this._electedClient;
228
- if (this._electedClient !== client) {
229
- // Changing the elected client. Record the sequence number and note that we have to fire an event.
230
- this._electionSequenceNumber = sequenceNumber;
231
- this._electedClient = client;
232
- change = true;
233
- }
234
- if (this._electedParent !== client && !isSummarizerClient) {
235
- // Changing the elected parent as well.
236
- this._electedParent = client;
237
- change = true;
238
- }
239
- if (change) {
240
- this.emit("election", client, sequenceNumber, prevClient);
241
- }
242
- }
243
- tryElectingParent(client, sequenceNumber) {
244
- if (this._electedParent !== client) {
245
- this._electedParent = client;
246
- this.emit("election", this._electedClient, sequenceNumber, this._electedClient);
178
+ this._electionSequenceNumber = sequenceNumber;
179
+ if (this._electedClient === client) {
180
+ return;
247
181
  }
182
+ const prevClient = this._electedClient;
183
+ this._electedClient = client;
184
+ this.emit("election", client, sequenceNumber, prevClient);
248
185
  }
249
186
  /**
250
- * Helper function to find the first eligible parent client starting with the passed in client,
187
+ * Helper function to find the first eligible client starting with the passed in client,
251
188
  * or undefined if none are eligible.
252
189
  * @param client - client to start checking
253
190
  * @returns oldest eligible client starting with passed in client or undefined if none.
254
191
  */
255
- findFirstEligibleParent(client) {
192
+ findFirstEligibleClient(client) {
256
193
  let candidateClient = client;
257
- while (candidateClient !== undefined &&
258
- (!this.isEligibleFn(candidateClient) || candidateClient.client.details.type === summarizerClientType)) {
194
+ while (candidateClient !== undefined && !this.isEligibleFn(candidateClient)) {
259
195
  candidateClient = candidateClient.youngerClient;
260
196
  }
261
197
  return candidateClient;
@@ -267,19 +203,12 @@ export class OrderedClientElection extends TypedEventEmitter {
267
203
  * @param sequenceNumber - sequence number when client was added
268
204
  */
269
205
  addClient(client, sequenceNumber) {
270
- var _a;
271
206
  if (this.isEligibleFn(client)) {
272
207
  this._eligibleCount++;
273
- const newClientIsSummarizer = client.client.details.type === summarizerClientType;
274
- const electedClientIsSummarizer = ((_a = this._electedClient) === null || _a === void 0 ? void 0 : _a.client.details.type) === summarizerClientType;
275
- // Note that we allow a summarizer client to supercede an interactive client as elected client.
276
- if (this._electedClient === undefined || (!electedClientIsSummarizer && newClientIsSummarizer)) {
208
+ if (this._electedClient === undefined) {
209
+ // Automatically elect latest client
277
210
  this.tryElectingClient(client, sequenceNumber);
278
211
  }
279
- else if (this._electedParent === undefined && !newClientIsSummarizer) {
280
- // This is an odd case. If the _electedClient is set, the _electedParent should be as well.
281
- this.tryElectingParent(client, sequenceNumber);
282
- }
283
212
  }
284
213
  }
285
214
  /**
@@ -289,80 +218,36 @@ export class OrderedClientElection extends TypedEventEmitter {
289
218
  * @param sequenceNumber - sequence number when client was removed
290
219
  */
291
220
  removeClient(client, sequenceNumber) {
292
- var _a, _b, _c, _d, _e;
293
221
  if (this.isEligibleFn(client)) {
294
222
  this._eligibleCount--;
295
223
  if (this._electedClient === client) {
296
- // Removing the _electedClient. There are 2 possible cases:
297
- if (this._electedParent !== client) {
298
- // 1. The _electedClient is a summarizer that we've been allowing to finish its work.
299
- // Let the _electedParent become the _electedClient so that it can start its own summarizer.
300
- if (this._electedClient.client.details.type !== summarizerClientType) {
301
- throw new UsageError("Elected client should be a summarizer client 1");
302
- }
303
- this.tryElectingClient(this._electedParent, sequenceNumber);
304
- }
305
- else {
306
- // 2. The _electedClient is an interactive client that has left the quorum.
307
- // Automatically shift to next oldest client.
308
- const nextClient = (_b = this.findFirstEligibleParent((_a = this._electedParent) === null || _a === void 0 ? void 0 : _a.youngerClient)) !== null && _b !== void 0 ? _b : this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
309
- this.tryElectingClient(nextClient, sequenceNumber);
310
- }
311
- }
312
- else if (this._electedParent === client) {
313
- // Removing the _electedParent (but not _electedClient).
314
- // Shift to the next oldest parent, but do not replace the _electedClient,
315
- // which is a summarizer that is still doing work.
316
- if (((_c = this._electedClient) === null || _c === void 0 ? void 0 : _c.client.details.type) !== summarizerClientType) {
317
- throw new UsageError("Elected client should be a summarizer client 2");
318
- }
319
- const nextParent = (_e = this.findFirstEligibleParent((_d = this._electedParent) === null || _d === void 0 ? void 0 : _d.youngerClient)) !== null && _e !== void 0 ? _e : this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
320
- this.tryElectingParent(nextParent, sequenceNumber);
224
+ // Automatically shift to next oldest client
225
+ const nextClient = this.findFirstEligibleClient(this._electedClient.youngerClient);
226
+ this.tryElectingClient(nextClient, sequenceNumber);
321
227
  }
322
228
  }
323
229
  }
324
230
  getAllEligibleClients() {
325
231
  return this.orderedClientCollection.getAllClients().filter(this.isEligibleFn);
326
232
  }
327
- /** Advance election to the next-oldest client. This is called if the current parent is leaving the quorum,
328
- * or if the current summarizer is not responsive and we want to stop it and spawn a new one.
329
- */
330
233
  incrementElectedClient(sequenceNumber) {
331
- var _a, _b;
332
- const nextClient = (_b = this.findFirstEligibleParent((_a = this._electedParent) === null || _a === void 0 ? void 0 : _a.youngerClient)) !== null && _b !== void 0 ? _b : this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
333
- if (this._electedClient === undefined || this._electedClient === this._electedParent) {
334
- this.tryElectingClient(nextClient, sequenceNumber);
335
- }
336
- else {
337
- // The _electedClient is a summarizer and should not be replaced until it leaves the quorum.
338
- // Changing the _electedParent will stop the summarizer.
339
- this.tryElectingParent(nextClient, sequenceNumber);
340
- }
234
+ var _a;
235
+ const nextClient = this.findFirstEligibleClient((_a = this._electedClient) === null || _a === void 0 ? void 0 : _a.youngerClient);
236
+ this.tryElectingClient(nextClient, sequenceNumber);
341
237
  }
342
- /** (Re-)start election with the oldest client in the quorum. This is called if we need to summarize
343
- * and no client has been elected.
344
- */
345
238
  resetElectedClient(sequenceNumber) {
346
- const firstClient = this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
347
- if (this._electedClient === undefined || this._electedClient === this._electedParent) {
348
- this.tryElectingClient(firstClient, sequenceNumber);
349
- }
350
- else {
351
- // The _electedClient is a summarizer and should not be replaced until it leaves the quorum.
352
- // Changing the _electedParent will stop the summarizer.
353
- this.tryElectingParent(firstClient, sequenceNumber);
354
- }
239
+ const firstClient = this.findFirstEligibleClient(this.orderedClientCollection.oldestClient);
240
+ this.tryElectingClient(firstClient, sequenceNumber);
355
241
  }
356
242
  peekNextElectedClient() {
357
243
  var _a;
358
- return this.findFirstEligibleParent((_a = this._electedParent) === null || _a === void 0 ? void 0 : _a.youngerClient);
244
+ return this.findFirstEligibleClient((_a = this._electedClient) === null || _a === void 0 ? void 0 : _a.youngerClient);
359
245
  }
360
246
  serialize() {
361
- var _a, _b;
247
+ var _a;
362
248
  return {
363
249
  electionSequenceNumber: this.electionSequenceNumber,
364
250
  electedClientId: (_a = this.electedClient) === null || _a === void 0 ? void 0 : _a.clientId,
365
- electedParentId: (_b = this.electedParent) === null || _b === void 0 ? void 0 : _b.clientId,
366
251
  };
367
252
  }
368
253
  }