@fluidframework/container-runtime 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/.eslintrc.js +19 -8
  2. package/dist/batchTracker.d.ts +1 -2
  3. package/dist/batchTracker.d.ts.map +1 -1
  4. package/dist/batchTracker.js.map +1 -1
  5. package/dist/blobManager.d.ts +44 -33
  6. package/dist/blobManager.d.ts.map +1 -1
  7. package/dist/blobManager.js +130 -97
  8. package/dist/blobManager.js.map +1 -1
  9. package/dist/containerRuntime.d.ts +39 -8
  10. package/dist/containerRuntime.d.ts.map +1 -1
  11. package/dist/containerRuntime.js +117 -61
  12. package/dist/containerRuntime.js.map +1 -1
  13. package/dist/dataStoreContext.d.ts +1 -1
  14. package/dist/dataStoreContext.d.ts.map +1 -1
  15. package/dist/dataStoreContext.js +4 -3
  16. package/dist/dataStoreContext.js.map +1 -1
  17. package/dist/dataStores.d.ts +9 -6
  18. package/dist/dataStores.d.ts.map +1 -1
  19. package/dist/dataStores.js +30 -24
  20. package/dist/dataStores.js.map +1 -1
  21. package/dist/garbageCollection.d.ts +41 -20
  22. package/dist/garbageCollection.d.ts.map +1 -1
  23. package/dist/garbageCollection.js +205 -151
  24. package/dist/garbageCollection.js.map +1 -1
  25. package/dist/garbageCollectionConstants.d.ts +6 -3
  26. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  27. package/dist/garbageCollectionConstants.js +7 -7
  28. package/dist/garbageCollectionConstants.js.map +1 -1
  29. package/dist/garbageCollectionTombstoneUtils.d.ts +13 -0
  30. package/dist/garbageCollectionTombstoneUtils.d.ts.map +1 -0
  31. package/dist/garbageCollectionTombstoneUtils.js +28 -0
  32. package/dist/garbageCollectionTombstoneUtils.js.map +1 -0
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -5
  36. package/dist/index.js.map +1 -1
  37. package/dist/opLifecycle/batchManager.d.ts +13 -1
  38. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  39. package/dist/opLifecycle/batchManager.js +35 -1
  40. package/dist/opLifecycle/batchManager.js.map +1 -1
  41. package/dist/opLifecycle/definitions.d.ts +25 -1
  42. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  43. package/dist/opLifecycle/definitions.js.map +1 -1
  44. package/dist/opLifecycle/index.d.ts +2 -2
  45. package/dist/opLifecycle/index.d.ts.map +1 -1
  46. package/dist/opLifecycle/index.js +2 -1
  47. package/dist/opLifecycle/index.js.map +1 -1
  48. package/dist/opLifecycle/opCompressor.d.ts +1 -1
  49. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  50. package/dist/opLifecycle/opCompressor.js +24 -10
  51. package/dist/opLifecycle/opCompressor.js.map +1 -1
  52. package/dist/opLifecycle/opDecompressor.d.ts +2 -1
  53. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  54. package/dist/opLifecycle/opDecompressor.js +30 -17
  55. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  56. package/dist/opLifecycle/opSplitter.d.ts +34 -2
  57. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  58. package/dist/opLifecycle/opSplitter.js +114 -5
  59. package/dist/opLifecycle/opSplitter.js.map +1 -1
  60. package/dist/opLifecycle/outbox.d.ts +5 -0
  61. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  62. package/dist/opLifecycle/outbox.js +24 -14
  63. package/dist/opLifecycle/outbox.js.map +1 -1
  64. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  65. package/dist/opLifecycle/remoteMessageProcessor.js +17 -2
  66. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  67. package/dist/packageVersion.d.ts +1 -1
  68. package/dist/packageVersion.js +1 -1
  69. package/dist/packageVersion.js.map +1 -1
  70. package/dist/runningSummarizer.d.ts.map +1 -1
  71. package/dist/runningSummarizer.js +0 -1
  72. package/dist/runningSummarizer.js.map +1 -1
  73. package/dist/scheduleManager.d.ts +0 -1
  74. package/dist/scheduleManager.d.ts.map +1 -1
  75. package/dist/scheduleManager.js +9 -20
  76. package/dist/scheduleManager.js.map +1 -1
  77. package/dist/summarizer.d.ts +0 -1
  78. package/dist/summarizer.d.ts.map +1 -1
  79. package/dist/summarizer.js +2 -1
  80. package/dist/summarizer.js.map +1 -1
  81. package/dist/summarizerTypes.d.ts +1 -0
  82. package/dist/summarizerTypes.d.ts.map +1 -1
  83. package/dist/summarizerTypes.js.map +1 -1
  84. package/dist/summaryFormat.d.ts.map +1 -1
  85. package/dist/summaryFormat.js +1 -2
  86. package/dist/summaryFormat.js.map +1 -1
  87. package/lib/batchTracker.d.ts +1 -2
  88. package/lib/batchTracker.d.ts.map +1 -1
  89. package/lib/batchTracker.js.map +1 -1
  90. package/lib/blobManager.d.ts +44 -33
  91. package/lib/blobManager.d.ts.map +1 -1
  92. package/lib/blobManager.js +131 -98
  93. package/lib/blobManager.js.map +1 -1
  94. package/lib/containerRuntime.d.ts +39 -8
  95. package/lib/containerRuntime.d.ts.map +1 -1
  96. package/lib/containerRuntime.js +115 -59
  97. package/lib/containerRuntime.js.map +1 -1
  98. package/lib/dataStoreContext.d.ts +1 -1
  99. package/lib/dataStoreContext.d.ts.map +1 -1
  100. package/lib/dataStoreContext.js +5 -4
  101. package/lib/dataStoreContext.js.map +1 -1
  102. package/lib/dataStores.d.ts +9 -6
  103. package/lib/dataStores.d.ts.map +1 -1
  104. package/lib/dataStores.js +32 -26
  105. package/lib/dataStores.js.map +1 -1
  106. package/lib/garbageCollection.d.ts +41 -20
  107. package/lib/garbageCollection.d.ts.map +1 -1
  108. package/lib/garbageCollection.js +201 -147
  109. package/lib/garbageCollection.js.map +1 -1
  110. package/lib/garbageCollectionConstants.d.ts +6 -3
  111. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  112. package/lib/garbageCollectionConstants.js +6 -6
  113. package/lib/garbageCollectionConstants.js.map +1 -1
  114. package/lib/garbageCollectionTombstoneUtils.d.ts +13 -0
  115. package/lib/garbageCollectionTombstoneUtils.d.ts.map +1 -0
  116. package/lib/garbageCollectionTombstoneUtils.js +24 -0
  117. package/lib/garbageCollectionTombstoneUtils.js.map +1 -0
  118. package/lib/index.d.ts +0 -1
  119. package/lib/index.d.ts.map +1 -1
  120. package/lib/index.js +0 -1
  121. package/lib/index.js.map +1 -1
  122. package/lib/opLifecycle/batchManager.d.ts +13 -1
  123. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  124. package/lib/opLifecycle/batchManager.js +35 -1
  125. package/lib/opLifecycle/batchManager.js.map +1 -1
  126. package/lib/opLifecycle/definitions.d.ts +25 -1
  127. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  128. package/lib/opLifecycle/definitions.js.map +1 -1
  129. package/lib/opLifecycle/index.d.ts +2 -2
  130. package/lib/opLifecycle/index.d.ts.map +1 -1
  131. package/lib/opLifecycle/index.js +1 -1
  132. package/lib/opLifecycle/index.js.map +1 -1
  133. package/lib/opLifecycle/opCompressor.d.ts +1 -1
  134. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  135. package/lib/opLifecycle/opCompressor.js +24 -10
  136. package/lib/opLifecycle/opCompressor.js.map +1 -1
  137. package/lib/opLifecycle/opDecompressor.d.ts +2 -1
  138. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  139. package/lib/opLifecycle/opDecompressor.js +30 -17
  140. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  141. package/lib/opLifecycle/opSplitter.d.ts +34 -2
  142. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  143. package/lib/opLifecycle/opSplitter.js +112 -4
  144. package/lib/opLifecycle/opSplitter.js.map +1 -1
  145. package/lib/opLifecycle/outbox.d.ts +5 -0
  146. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  147. package/lib/opLifecycle/outbox.js +24 -14
  148. package/lib/opLifecycle/outbox.js.map +1 -1
  149. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  150. package/lib/opLifecycle/remoteMessageProcessor.js +17 -2
  151. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  152. package/lib/packageVersion.d.ts +1 -1
  153. package/lib/packageVersion.js +1 -1
  154. package/lib/packageVersion.js.map +1 -1
  155. package/lib/runningSummarizer.d.ts.map +1 -1
  156. package/lib/runningSummarizer.js +0 -1
  157. package/lib/runningSummarizer.js.map +1 -1
  158. package/lib/scheduleManager.d.ts +0 -1
  159. package/lib/scheduleManager.d.ts.map +1 -1
  160. package/lib/scheduleManager.js +9 -20
  161. package/lib/scheduleManager.js.map +1 -1
  162. package/lib/summarizer.d.ts +0 -1
  163. package/lib/summarizer.d.ts.map +1 -1
  164. package/lib/summarizer.js +2 -1
  165. package/lib/summarizer.js.map +1 -1
  166. package/lib/summarizerTypes.d.ts +1 -0
  167. package/lib/summarizerTypes.d.ts.map +1 -1
  168. package/lib/summarizerTypes.js.map +1 -1
  169. package/lib/summaryFormat.d.ts.map +1 -1
  170. package/lib/summaryFormat.js +1 -2
  171. package/lib/summaryFormat.js.map +1 -1
  172. package/package.json +37 -19
  173. package/src/batchTracker.ts +1 -1
  174. package/src/blobManager.ts +146 -103
  175. package/src/containerRuntime.ts +166 -65
  176. package/src/dataStoreContext.ts +5 -5
  177. package/src/dataStores.ts +40 -30
  178. package/src/garbageCollection.ts +254 -183
  179. package/src/garbageCollectionConstants.ts +7 -6
  180. package/src/garbageCollectionTombstoneUtils.ts +31 -0
  181. package/src/index.ts +0 -5
  182. package/src/opLifecycle/batchManager.ts +59 -1
  183. package/src/opLifecycle/definitions.ts +27 -1
  184. package/src/opLifecycle/index.ts +2 -1
  185. package/src/opLifecycle/opCompressor.ts +29 -12
  186. package/src/opLifecycle/opDecompressor.ts +39 -18
  187. package/src/opLifecycle/opSplitter.ts +141 -7
  188. package/src/opLifecycle/outbox.ts +32 -16
  189. package/src/opLifecycle/remoteMessageProcessor.ts +19 -3
  190. package/src/packageVersion.ts +1 -1
  191. package/src/runningSummarizer.ts +0 -1
  192. package/src/scheduleManager.ts +19 -30
  193. package/src/summarizer.ts +1 -1
  194. package/src/summarizerTypes.ts +1 -0
  195. package/src/summaryFormat.ts +1 -2
@@ -1 +1 @@
1
- {"version":3,"file":"runningSummarizer.js","sourceRoot":"","sources":["../src/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;AAGH,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAEH,WAAW,GACd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAI9D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAkBlE,OAAO,EACH,SAAS,EAET,sBAAsB,EACtB,gBAAgB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAE7D;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IA2E1B,YACI,UAA4B,EACX,cAAqC,EACrC,aAAoC,EACpC,qBAAuF,EACvF,aAAsC,EACtC,qBAAqD,EACrD,iBAAoC,EACpC,iBAA4C,EAC5C,sBAA8D,EAC9D,OAA2B;QAR3B,mBAAc,GAAd,cAAc,CAAuB;QACrC,kBAAa,GAAb,aAAa,CAAuB;QACpC,0BAAqB,GAArB,qBAAqB,CAAkE;QACvF,kBAAa,GAAb,aAAa,CAAyB;QACtC,0BAAqB,GAArB,qBAAqB,CAAgC;QACrD,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,sBAAiB,GAAjB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a,CAAC,oBAAoB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB;eAClF,IAAI,CAAC,eAAe,KAAK,SAAS,EACvC;YACE,uFAAuF;YACvF,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACjE,+FAA+F;QAC/F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,gBAAgB,CACjB,EAAE,MAAM,EAAE,mBAAmB,MAAM,EAAE,EAAE,EACvC,OAAO,EACP,IAAI,CAAC,iBAAiB,EACtB,cAAc,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,sBAAsB;QAC1B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;YAC7F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;SACpC;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, delay, Deferred, PromiseTimer } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport {\n ISequencedDocumentMessage,\n MessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n ISummaryConfiguration,\n} from \"./containerRuntime\";\nimport { opSize } from \"./opProperties\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics\";\nimport {\n IEnqueueSummarizeOptions,\n ISummarizeOptions,\n ISummarizeHeuristicData,\n ISummarizeHeuristicRunner,\n IOnDemandSummarizeOptions,\n EnqueueSummarizeResult,\n SummarizerStopReason,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n ISummaryCancellationToken,\n ISummarizeResults,\n ISummarizeTelemetryProperties,\n ISummarizerRuntime,\n ISummarizeRunnerTelemetry,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher, SummaryCollection } from \"./summaryCollection\";\nimport {\n raceTimer,\n SummarizeReason,\n SummarizeResultBuilder,\n SummaryGenerator,\n} from \"./summaryGenerator\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer implements IDisposable {\n public static async start(\n logger: ITelemetryLogger,\n summaryWatcher: IClientSummaryWatcher,\n configuration: ISummaryConfiguration,\n submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n heuristicData: ISummarizeHeuristicData,\n raiseSummarizingError: (errorMessage: string) => void,\n summaryCollection: SummaryCollection,\n cancellationToken: ISummaryCancellationToken,\n stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n runtime: ISummarizerRuntime,\n ): Promise<RunningSummarizer> {\n const summarizer = new RunningSummarizer(\n logger,\n summaryWatcher,\n configuration,\n submitSummaryCallback,\n heuristicData,\n raiseSummarizingError,\n summaryCollection,\n cancellationToken,\n stopSummarizerCallback,\n runtime);\n\n await summarizer.waitStart();\n\n // Update heuristic counts\n // By the time we get here, there are potentially ops missing from the heuristic summary counts\n // Examples of where this could happen:\n // 1. Op is processed during the time that we are initiating the RunningSummarizer instance but before we\n // listen for the op events (will get missed by the handlers in the current workflow)\n // 2. Op was sequenced after the last time we summarized (op sequence number > summarize ref sequence number)\n const diff = runtime.deltaManager.lastSequenceNumber - (\n heuristicData.lastSuccessfulSummary.refSequenceNumber\n + heuristicData.numNonRuntimeOps\n + heuristicData.numRuntimeOps);\n heuristicData.hasMissingOpData = diff > 0;\n\n if (heuristicData.hasMissingOpData) {\n // Split the diff 50-50 and increment the counts appropriately\n heuristicData.numNonRuntimeOps += Math.ceil(diff / 2);\n heuristicData.numRuntimeOps += Math.floor(diff / 2);\n }\n\n // Update last seq number (in case the handlers haven't processed anything yet)\n heuristicData.lastOpSequenceNumber = runtime.deltaManager.lastSequenceNumber;\n\n // Start heuristics\n summarizer.heuristicRunner?.start();\n summarizer.heuristicRunner?.run();\n\n return summarizer;\n }\n\n public get disposed() { return this._disposed; }\n private stopping = false;\n private _disposed = false;\n private summarizingLock: Promise<void> | undefined;\n private refreshSummaryAckLock: Promise<void> | undefined;\n private tryWhileSummarizing = false;\n private readonly pendingAckTimer: PromiseTimer;\n private heuristicRunner?: ISummarizeHeuristicRunner;\n private readonly generator: SummaryGenerator;\n private readonly logger: ITelemetryLogger;\n private enqueuedSummary: {\n reason: SummarizeReason;\n afterSequenceNumber: number;\n options: ISummarizeOptions;\n readonly resultsBuilder: SummarizeResultBuilder;\n } | undefined;\n private summarizeCount = 0;\n private totalSuccessfulAttempts = 0;\n private initialized = false;\n\n private constructor(\n baseLogger: ITelemetryLogger,\n private readonly summaryWatcher: IClientSummaryWatcher,\n private readonly configuration: ISummaryConfiguration,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly summaryCollection: SummaryCollection,\n private readonly cancellationToken: ISummaryCancellationToken,\n private readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n private readonly runtime: ISummarizerRuntime,\n ) {\n const telemetryProps: ISummarizeRunnerTelemetry = {\n summarizeCount: () => this.summarizeCount,\n summarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n };\n\n this.logger = ChildLogger.create(\n baseLogger, \"Running\",\n {\n all: telemetryProps,\n },\n );\n\n if (configuration.state !== \"disableHeuristics\") {\n assert(this.configuration.state === \"enabled\", 0x2ea /* \"Configuration state should be enabled\" */);\n this.heuristicRunner = new SummarizeHeuristicRunner(\n heuristicData,\n this.configuration,\n (reason) => this.trySummarize(reason),\n this.logger);\n }\n\n assert(\n this.configuration.state !== \"disabled\",\n 0x2eb /* \"Summary not supported with configuration disabled\" */,\n );\n\n // Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n // configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n\n const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);\n\n this.pendingAckTimer = new PromiseTimer(\n maxAckWaitTime,\n () => {\n // pre-0.58 error message: summaryAckWaitTimeout\n this.raiseSummarizingError(\"Pending summary ack not received in time\");\n // Note: summarizeCount (from ChildLogger definition) may be 0,\n // since this code path is hit when RunningSummarizer first starts up,\n // before this instance has kicked off a new summarize run.\n this.logger.sendErrorEvent({\n eventName: \"SummaryAckWaitTimeout\",\n maxAckWaitTime,\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n timePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n });\n });\n // Set up pending ack timeout by op timestamp differences for previous summaries.\n summaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n if (this.pendingAckTimer.hasTimer) {\n this.logger.sendTelemetryEvent({\n eventName: \"MissingSummaryAckFoundByOps\",\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n });\n this.pendingAckTimer.clear();\n }\n });\n\n this.generator = new SummaryGenerator(\n this.pendingAckTimer,\n this.heuristicData,\n this.submitSummaryCallback,\n this.raiseSummarizingError,\n () => { this.totalSuccessfulAttempts++; },\n this.summaryWatcher,\n this.logger,\n );\n\n // Listen for ops\n this.runtime.deltaManager.on(\"op\", (op) => { this.handleOp(op); });\n }\n\n public dispose(): void {\n this.runtime.deltaManager.off(\"op\", (op) => { this.handleOp(op); });\n this.summaryWatcher.dispose();\n this.heuristicRunner?.dispose();\n this.heuristicRunner = undefined;\n this.generator.dispose();\n this.pendingAckTimer.clear();\n this.disposeEnqueuedSummary();\n this._disposed = true;\n this.stopping = true;\n }\n\n /**\n * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n * If some other Summarizer code wants that event on their logs they can get it here,\n * but only if they're logging about that same summary.\n * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n */\n public tryGetCorrelatedLogger = (summaryOpRefSeq) =>\n this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n ? this.logger\n : undefined;\n\n /** We only want a single heuristic runner micro-task (will provide better optimized grouping of ops) */\n private heuristicRunnerMicroTaskExists = false;\n\n public handleOp(op: ISequencedDocumentMessage) {\n this.heuristicData.lastOpSequenceNumber = op.sequenceNumber;\n\n if (isRuntimeMessage(op)) {\n this.heuristicData.numRuntimeOps++;\n } else {\n this.heuristicData.numNonRuntimeOps++;\n }\n\n this.heuristicData.totalOpsSize += opSize(op);\n\n // Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n if (this.initialized\n && this.opCanTriggerSummary(op)\n && !this.tryRunEnqueuedSummary()\n && !this.heuristicRunnerMicroTaskExists) {\n this.heuristicRunnerMicroTaskExists = true;\n Promise.resolve().then(() => {\n this.heuristicRunner?.run();\n }).finally(() => {\n this.heuristicRunnerMicroTaskExists = false;\n });\n }\n }\n\n /**\n * Can the given op trigger a summary?\n * # Currently always prevents summaries for Summarize and SummaryAck/Nack ops\n * @param op - op to check\n * @returns true if this op can trigger a summary\n */\n private opCanTriggerSummary(op: ISequencedDocumentMessage): boolean {\n switch (op.type) {\n case MessageType.Summarize:\n case MessageType.SummaryAck:\n case MessageType.SummaryNack:\n return false;\n default:\n return isRuntimeMessage(op) || this.nonRuntimeOpCanTriggerSummary();\n }\n }\n\n private nonRuntimeOpCanTriggerSummary(): boolean {\n // eslint-disable-next-line max-len\n const opsSinceLastAck = this.heuristicData.lastOpSequenceNumber - this.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n return this.configuration.state === \"enabled\"\n && (this.configuration.nonRuntimeHeuristicThreshold === undefined\n || this.configuration.nonRuntimeHeuristicThreshold <= opsSinceLastAck);\n }\n\n public async waitStop(allowLastSummary: boolean): Promise<void> {\n if (this.stopping) {\n return;\n }\n\n this.stopping = true;\n\n this.disposeEnqueuedSummary();\n\n // This will try to run lastSummary if needed.\n if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {\n if (this.summarizingLock === undefined) {\n this.trySummarizeOnce(\n // summarizeProps\n { reason: \"lastSummary\" },\n // ISummarizeOptions, using defaults: { refreshLatestAck: false, fullTree: false }\n {});\n }\n }\n\n // Note that trySummarizeOnce() call above returns right away, without waiting.\n // So we need to wait for its completion, otherwise it would be destroyed right away.\n // That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n // submit summary. We should reconsider this flow and make summarizer move to exit faster.\n // This resolves when the current pending summary gets an ack or fails.\n await this.summarizingLock;\n }\n\n private async waitStart() {\n // Wait no longer than ack timeout for all pending\n const waitStartResult = await raceTimer(\n this.summaryWatcher.waitFlushed(),\n this.pendingAckTimer.start(),\n );\n this.pendingAckTimer.clear();\n\n // Remove pending ack wait timeout by op timestamp comparison, because\n // it has race conditions with summaries submitted by this same client.\n this.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n if (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n this.heuristicData.updateWithLastSummaryAckInfo({\n refSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n // This will be the Summarizer starting point so only use timestamps from client's machine.\n summaryTime: Date.now(),\n summarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n });\n }\n this.initialized = true;\n }\n\n /**\n * Blocks a new summarizer from running in case RefreshSummaryAck is being processed.\n * Assumes that caller checked upfront for lack of concurrent action (this.refreshSummaryAckLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * Note: The refreshSummaryAckLock makes sure no summarizer gets enqueued or processed\n * until the refresh has completed. One can't rely uniquely on the summarizingLock as the\n * refreshLatestSummaryAck also happens during the time summarizingLock !== undefined.\n * Ex. Summarizer submits a summay + op and then waits for the Summary Ack to proceed\n * with the refreshLatestSummaryAck and complete the summary.\n * @param action - action to perform.\n * @returns - result of action.\n */\n public async lockedRefreshSummaryAckAction<T>(action: () => Promise<T>) {\n assert(this.refreshSummaryAckLock === undefined,\n 0x396 /* Refresh Summary Ack - Caller is responsible for checking lock */);\n\n const refreshSummaryAckLock = new Deferred<void>();\n this.refreshSummaryAckLock = refreshSummaryAckLock.promise;\n\n return action().finally(() => {\n refreshSummaryAckLock.resolve();\n this.refreshSummaryAckLock = undefined;\n });\n }\n\n /**\n * Runs single summary action that prevents any other concurrent actions.\n * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * @param action - action to perform.\n * @returns - result of action.\n */\n private async lockedSummaryAction<T>(action: () => Promise<T>) {\n assert(this.summarizingLock === undefined, 0x25b /* \"Caller is responsible for checking lock\" */);\n\n const summarizingLock = new Deferred<void>();\n this.summarizingLock = summarizingLock.promise;\n\n this.summarizeCount++;\n // Make sure the RefreshLatestSummaryAck is not being executed.\n await this.refreshSummaryAckLock;\n\n return action().finally(() => {\n summarizingLock.resolve();\n this.summarizingLock = undefined;\n\n const retry = this.tryWhileSummarizing;\n this.tryWhileSummarizing = false;\n\n // After summarizing, we should check to see if we need to summarize again.\n // Rerun the heuristics and check for enqueued summaries.\n if (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n this.heuristicRunner?.run();\n }\n });\n }\n\n /**\n * Runs single summarize attempt\n * @param summarizeProps - props to log with each telemetry event associated with this attempt\n * @param options - summary options\n * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n * @param resultsBuilder - optional, result builder to use.\n * @returns ISummarizeResult - result of running a summary.\n */\n private trySummarizeOnce(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken = this.cancellationToken,\n resultsBuilder = new SummarizeResultBuilder()): ISummarizeResults {\n this.lockedSummaryAction(async () => {\n const summarizeResult = this.generator.summarize(\n summarizeProps,\n options,\n cancellationToken,\n resultsBuilder);\n // ensure we wait till the end of the process\n return summarizeResult.receivedSummaryAckOrNack;\n }).catch((error) => {\n // SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n // on resultsBuilder\n // We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n // and take a appropriate action.\n });\n\n return resultsBuilder.build();\n }\n\n /** Heuristics summarize attempt. */\n private trySummarize(\n reason: SummarizeReason,\n cancellationToken = this.cancellationToken): void {\n if (this.summarizingLock !== undefined) {\n // lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n // if it's still needed\n this.tryWhileSummarizing = true;\n return;\n }\n\n this.lockedSummaryAction(async () => {\n const attempts: (ISummarizeOptions & { delaySeconds?: number; })[] = [\n { refreshLatestAck: false, fullTree: false },\n { refreshLatestAck: true, fullTree: false },\n { refreshLatestAck: true, fullTree: false, delaySeconds: 2 * 60 },\n { refreshLatestAck: true, fullTree: true, delaySeconds: 10 * 60 },\n ];\n let overrideDelaySeconds: number | undefined;\n let summaryAttempts = 0;\n let summaryAttemptsPerPhase = 0;\n\n let lastResult: { message: string; error: any; } | undefined;\n\n for (let summaryAttemptPhase = 0; summaryAttemptPhase < attempts.length;) {\n if (this.cancellationToken.cancelled) {\n return;\n }\n\n // We only want to attempt 1 summary when reason is \"lastSummary\"\n if (++summaryAttempts > 1 && reason === \"lastSummary\") {\n return;\n }\n\n summaryAttemptsPerPhase++;\n\n const { delaySeconds: regularDelaySeconds = 0, ...options } = attempts[summaryAttemptPhase];\n const delaySeconds = overrideDelaySeconds ?? regularDelaySeconds;\n\n const summarizeProps: ISummarizeTelemetryProperties = {\n reason,\n summaryAttempts,\n summaryAttemptsPerPhase,\n summaryAttemptPhase: summaryAttemptPhase + 1, // make everything 1-based\n ...options,\n };\n\n if (delaySeconds > 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeAttemptDelay\",\n duration: delaySeconds,\n summaryNackDelay: overrideDelaySeconds !== undefined,\n ...summarizeProps,\n });\n await delay(delaySeconds * 1000);\n }\n\n // Make sure the refresh Summary Ack is not being executed.\n await this.refreshSummaryAckLock;\n\n // Note: no need to account for cancellationToken.waitCancelled here, as\n // this is accounted SummaryGenerator.summarizeCore that controls receivedSummaryAckOrNack.\n const resultSummarize = this.generator.summarize(summarizeProps, options, cancellationToken);\n const result = await resultSummarize.receivedSummaryAckOrNack;\n\n if (result.success) {\n return;\n }\n // Check for retryDelay that can come from summaryNack or upload summary flow.\n // Retry the same step only once per retryAfter response.\n overrideDelaySeconds = result.retryAfterSeconds;\n if (overrideDelaySeconds === undefined || summaryAttemptsPerPhase > 1) {\n summaryAttemptPhase++;\n summaryAttemptsPerPhase = 0;\n }\n lastResult = result;\n }\n\n // If all attempts failed, log error (with last attempt info) and close the summarizer container\n this.logger.sendErrorEvent({\n eventName: \"FailToSummarize\",\n reason,\n message: lastResult?.message,\n }, lastResult?.error);\n\n this.stopSummarizerCallback(\"failToSummarize\");\n }).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"UnexpectedSummarizeError\" }, error);\n });\n }\n\n /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */\n public summarizeOnDemand(\n resultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n {\n reason,\n ...options\n }: IOnDemandSummarizeOptions): ISummarizeResults {\n if (this.stopping) {\n resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n return resultsBuilder.build();\n }\n // Check for concurrent summary attempts. If one is found,\n // return a promise that caller can await before trying again.\n if (this.summarizingLock !== undefined) {\n // The heuristics are blocking concurrent summarize attempts.\n throw new UsageError(\"Attempted to run an already-running summarizer on demand\");\n }\n\n const result = this.trySummarizeOnce(\n { reason: `onDemand/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return result;\n }\n\n /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */\n public enqueueSummarize({\n reason,\n afterSequenceNumber = 0,\n override = false,\n ...options\n }: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n const onDemandReason = `enqueue;${reason}` as const;\n let overridden = false;\n if (this.enqueuedSummary !== undefined) {\n if (!override) {\n return { alreadyEnqueued: true };\n }\n // Override existing enqueued summarize attempt.\n this.enqueuedSummary.resultsBuilder.fail(\n \"Aborted; overridden by another enqueue summarize attempt\",\n undefined,\n );\n this.enqueuedSummary = undefined;\n overridden = true;\n }\n this.enqueuedSummary = {\n reason: onDemandReason,\n afterSequenceNumber,\n options,\n resultsBuilder: new SummarizeResultBuilder(),\n };\n const results = this.enqueuedSummary.resultsBuilder.build();\n this.tryRunEnqueuedSummary();\n return overridden ? {\n ...results,\n alreadyEnqueued: true,\n overridden: true,\n } : results;\n }\n\n private tryRunEnqueuedSummary() {\n if (this.stopping) {\n this.disposeEnqueuedSummary();\n return false;\n }\n if (\n this.enqueuedSummary === undefined\n || this.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber\n || this.summarizingLock !== undefined\n ) {\n // If no enqueued summary is ready or a summary is already in progress, take no action.\n return false;\n }\n const { reason, resultsBuilder, options } = this.enqueuedSummary;\n // Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n this.enqueuedSummary = undefined;\n this.trySummarizeOnce(\n { reason: `enqueuedSummary/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return true;\n }\n\n private disposeEnqueuedSummary() {\n if (this.enqueuedSummary !== undefined) {\n this.enqueuedSummary.resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n this.enqueuedSummary = undefined;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"runningSummarizer.js","sourceRoot":"","sources":["../src/runningSummarizer.ts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+FAA+F;QAC/F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,gBAAgB,CACjB,EAAE,MAAM,EAAE,mBAAmB,MAAM,EAAE,EAAE,EACvC,OAAO,EACP,IAAI,CAAC,iBAAiB,EACtB,cAAc,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,sBAAsB;QAC1B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;YAC7F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;SACpC;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, delay, Deferred, PromiseTimer } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport {\n ISequencedDocumentMessage,\n MessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport {\n ISummaryConfiguration,\n} from \"./containerRuntime\";\nimport { opSize } from \"./opProperties\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics\";\nimport {\n IEnqueueSummarizeOptions,\n ISummarizeOptions,\n ISummarizeHeuristicData,\n ISummarizeHeuristicRunner,\n IOnDemandSummarizeOptions,\n EnqueueSummarizeResult,\n SummarizerStopReason,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n ISummaryCancellationToken,\n ISummarizeResults,\n ISummarizeTelemetryProperties,\n ISummarizerRuntime,\n ISummarizeRunnerTelemetry,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher, SummaryCollection } from \"./summaryCollection\";\nimport {\n raceTimer,\n SummarizeReason,\n SummarizeResultBuilder,\n SummaryGenerator,\n} from \"./summaryGenerator\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer implements IDisposable {\n public static async start(\n logger: ITelemetryLogger,\n summaryWatcher: IClientSummaryWatcher,\n configuration: ISummaryConfiguration,\n submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n heuristicData: ISummarizeHeuristicData,\n raiseSummarizingError: (errorMessage: string) => void,\n summaryCollection: SummaryCollection,\n cancellationToken: ISummaryCancellationToken,\n stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n runtime: ISummarizerRuntime,\n ): Promise<RunningSummarizer> {\n const summarizer = new RunningSummarizer(\n logger,\n summaryWatcher,\n configuration,\n submitSummaryCallback,\n heuristicData,\n raiseSummarizingError,\n summaryCollection,\n cancellationToken,\n stopSummarizerCallback,\n runtime);\n\n await summarizer.waitStart();\n\n // Update heuristic counts\n // By the time we get here, there are potentially ops missing from the heuristic summary counts\n // Examples of where this could happen:\n // 1. Op is processed during the time that we are initiating the RunningSummarizer instance but before we\n // listen for the op events (will get missed by the handlers in the current workflow)\n // 2. Op was sequenced after the last time we summarized (op sequence number > summarize ref sequence number)\n const diff = runtime.deltaManager.lastSequenceNumber - (\n heuristicData.lastSuccessfulSummary.refSequenceNumber\n + heuristicData.numNonRuntimeOps\n + heuristicData.numRuntimeOps);\n heuristicData.hasMissingOpData = diff > 0;\n\n if (heuristicData.hasMissingOpData) {\n // Split the diff 50-50 and increment the counts appropriately\n heuristicData.numNonRuntimeOps += Math.ceil(diff / 2);\n heuristicData.numRuntimeOps += Math.floor(diff / 2);\n }\n\n // Update last seq number (in case the handlers haven't processed anything yet)\n heuristicData.lastOpSequenceNumber = runtime.deltaManager.lastSequenceNumber;\n\n // Start heuristics\n summarizer.heuristicRunner?.start();\n summarizer.heuristicRunner?.run();\n\n return summarizer;\n }\n\n public get disposed() { return this._disposed; }\n private stopping = false;\n private _disposed = false;\n private summarizingLock: Promise<void> | undefined;\n private refreshSummaryAckLock: Promise<void> | undefined;\n private tryWhileSummarizing = false;\n private readonly pendingAckTimer: PromiseTimer;\n private heuristicRunner?: ISummarizeHeuristicRunner;\n private readonly generator: SummaryGenerator;\n private readonly logger: ITelemetryLogger;\n private enqueuedSummary: {\n reason: SummarizeReason;\n afterSequenceNumber: number;\n options: ISummarizeOptions;\n readonly resultsBuilder: SummarizeResultBuilder;\n } | undefined;\n private summarizeCount = 0;\n private totalSuccessfulAttempts = 0;\n private initialized = false;\n\n private constructor(\n baseLogger: ITelemetryLogger,\n private readonly summaryWatcher: IClientSummaryWatcher,\n private readonly configuration: ISummaryConfiguration,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly summaryCollection: SummaryCollection,\n private readonly cancellationToken: ISummaryCancellationToken,\n private readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n private readonly runtime: ISummarizerRuntime,\n ) {\n const telemetryProps: ISummarizeRunnerTelemetry = {\n summarizeCount: () => this.summarizeCount,\n summarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n };\n\n this.logger = ChildLogger.create(\n baseLogger, \"Running\",\n {\n all: telemetryProps,\n },\n );\n\n if (configuration.state !== \"disableHeuristics\") {\n assert(this.configuration.state === \"enabled\", 0x2ea /* \"Configuration state should be enabled\" */);\n this.heuristicRunner = new SummarizeHeuristicRunner(\n heuristicData,\n this.configuration,\n (reason) => this.trySummarize(reason),\n this.logger);\n }\n\n assert(\n this.configuration.state !== \"disabled\",\n 0x2eb /* \"Summary not supported with configuration disabled\" */,\n );\n\n // Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n // configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n\n const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);\n\n this.pendingAckTimer = new PromiseTimer(\n maxAckWaitTime,\n () => {\n // pre-0.58 error message: summaryAckWaitTimeout\n this.raiseSummarizingError(\"Pending summary ack not received in time\");\n // Note: summarizeCount (from ChildLogger definition) may be 0,\n // since this code path is hit when RunningSummarizer first starts up,\n // before this instance has kicked off a new summarize run.\n this.logger.sendErrorEvent({\n eventName: \"SummaryAckWaitTimeout\",\n maxAckWaitTime,\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n timePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n });\n });\n // Set up pending ack timeout by op timestamp differences for previous summaries.\n summaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n if (this.pendingAckTimer.hasTimer) {\n this.logger.sendTelemetryEvent({\n eventName: \"MissingSummaryAckFoundByOps\",\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n });\n this.pendingAckTimer.clear();\n }\n });\n\n this.generator = new SummaryGenerator(\n this.pendingAckTimer,\n this.heuristicData,\n this.submitSummaryCallback,\n this.raiseSummarizingError,\n () => { this.totalSuccessfulAttempts++; },\n this.summaryWatcher,\n this.logger,\n );\n\n // Listen for ops\n this.runtime.deltaManager.on(\"op\", (op) => { this.handleOp(op); });\n }\n\n public dispose(): void {\n this.runtime.deltaManager.off(\"op\", (op) => { this.handleOp(op); });\n this.summaryWatcher.dispose();\n this.heuristicRunner?.dispose();\n this.heuristicRunner = undefined;\n this.generator.dispose();\n this.pendingAckTimer.clear();\n this.disposeEnqueuedSummary();\n this._disposed = true;\n this.stopping = true;\n }\n\n /**\n * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n * If some other Summarizer code wants that event on their logs they can get it here,\n * but only if they're logging about that same summary.\n * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n */\n public tryGetCorrelatedLogger = (summaryOpRefSeq) =>\n this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n ? this.logger\n : undefined;\n\n /** We only want a single heuristic runner micro-task (will provide better optimized grouping of ops) */\n private heuristicRunnerMicroTaskExists = false;\n\n public handleOp(op: ISequencedDocumentMessage) {\n this.heuristicData.lastOpSequenceNumber = op.sequenceNumber;\n\n if (isRuntimeMessage(op)) {\n this.heuristicData.numRuntimeOps++;\n } else {\n this.heuristicData.numNonRuntimeOps++;\n }\n\n this.heuristicData.totalOpsSize += opSize(op);\n\n // Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n if (this.initialized\n && this.opCanTriggerSummary(op)\n && !this.tryRunEnqueuedSummary()\n && !this.heuristicRunnerMicroTaskExists) {\n this.heuristicRunnerMicroTaskExists = true;\n Promise.resolve().then(() => {\n this.heuristicRunner?.run();\n }).finally(() => {\n this.heuristicRunnerMicroTaskExists = false;\n });\n }\n }\n\n /**\n * Can the given op trigger a summary?\n * # Currently always prevents summaries for Summarize and SummaryAck/Nack ops\n * @param op - op to check\n * @returns true if this op can trigger a summary\n */\n private opCanTriggerSummary(op: ISequencedDocumentMessage): boolean {\n switch (op.type) {\n case MessageType.Summarize:\n case MessageType.SummaryAck:\n case MessageType.SummaryNack:\n return false;\n default:\n return isRuntimeMessage(op) || this.nonRuntimeOpCanTriggerSummary();\n }\n }\n\n private nonRuntimeOpCanTriggerSummary(): boolean {\n const opsSinceLastAck = this.heuristicData.lastOpSequenceNumber - this.heuristicData.lastSuccessfulSummary.refSequenceNumber;\n return this.configuration.state === \"enabled\"\n && (this.configuration.nonRuntimeHeuristicThreshold === undefined\n || this.configuration.nonRuntimeHeuristicThreshold <= opsSinceLastAck);\n }\n\n public async waitStop(allowLastSummary: boolean): Promise<void> {\n if (this.stopping) {\n return;\n }\n\n this.stopping = true;\n\n this.disposeEnqueuedSummary();\n\n // This will try to run lastSummary if needed.\n if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {\n if (this.summarizingLock === undefined) {\n this.trySummarizeOnce(\n // summarizeProps\n { reason: \"lastSummary\" },\n // ISummarizeOptions, using defaults: { refreshLatestAck: false, fullTree: false }\n {});\n }\n }\n\n // Note that trySummarizeOnce() call above returns right away, without waiting.\n // So we need to wait for its completion, otherwise it would be destroyed right away.\n // That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n // submit summary. We should reconsider this flow and make summarizer move to exit faster.\n // This resolves when the current pending summary gets an ack or fails.\n await this.summarizingLock;\n }\n\n private async waitStart() {\n // Wait no longer than ack timeout for all pending\n const waitStartResult = await raceTimer(\n this.summaryWatcher.waitFlushed(),\n this.pendingAckTimer.start(),\n );\n this.pendingAckTimer.clear();\n\n // Remove pending ack wait timeout by op timestamp comparison, because\n // it has race conditions with summaries submitted by this same client.\n this.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n if (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n this.heuristicData.updateWithLastSummaryAckInfo({\n refSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n // This will be the Summarizer starting point so only use timestamps from client's machine.\n summaryTime: Date.now(),\n summarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n });\n }\n this.initialized = true;\n }\n\n /**\n * Blocks a new summarizer from running in case RefreshSummaryAck is being processed.\n * Assumes that caller checked upfront for lack of concurrent action (this.refreshSummaryAckLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * Note: The refreshSummaryAckLock makes sure no summarizer gets enqueued or processed\n * until the refresh has completed. One can't rely uniquely on the summarizingLock as the\n * refreshLatestSummaryAck also happens during the time summarizingLock !== undefined.\n * Ex. Summarizer submits a summay + op and then waits for the Summary Ack to proceed\n * with the refreshLatestSummaryAck and complete the summary.\n * @param action - action to perform.\n * @returns - result of action.\n */\n public async lockedRefreshSummaryAckAction<T>(action: () => Promise<T>) {\n assert(this.refreshSummaryAckLock === undefined,\n 0x396 /* Refresh Summary Ack - Caller is responsible for checking lock */);\n\n const refreshSummaryAckLock = new Deferred<void>();\n this.refreshSummaryAckLock = refreshSummaryAckLock.promise;\n\n return action().finally(() => {\n refreshSummaryAckLock.resolve();\n this.refreshSummaryAckLock = undefined;\n });\n }\n\n /**\n * Runs single summary action that prevents any other concurrent actions.\n * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * @param action - action to perform.\n * @returns - result of action.\n */\n private async lockedSummaryAction<T>(action: () => Promise<T>) {\n assert(this.summarizingLock === undefined, 0x25b /* \"Caller is responsible for checking lock\" */);\n\n const summarizingLock = new Deferred<void>();\n this.summarizingLock = summarizingLock.promise;\n\n this.summarizeCount++;\n // Make sure the RefreshLatestSummaryAck is not being executed.\n await this.refreshSummaryAckLock;\n\n return action().finally(() => {\n summarizingLock.resolve();\n this.summarizingLock = undefined;\n\n const retry = this.tryWhileSummarizing;\n this.tryWhileSummarizing = false;\n\n // After summarizing, we should check to see if we need to summarize again.\n // Rerun the heuristics and check for enqueued summaries.\n if (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n this.heuristicRunner?.run();\n }\n });\n }\n\n /**\n * Runs single summarize attempt\n * @param summarizeProps - props to log with each telemetry event associated with this attempt\n * @param options - summary options\n * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n * @param resultsBuilder - optional, result builder to use.\n * @returns ISummarizeResult - result of running a summary.\n */\n private trySummarizeOnce(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken = this.cancellationToken,\n resultsBuilder = new SummarizeResultBuilder()): ISummarizeResults {\n this.lockedSummaryAction(async () => {\n const summarizeResult = this.generator.summarize(\n summarizeProps,\n options,\n cancellationToken,\n resultsBuilder);\n // ensure we wait till the end of the process\n return summarizeResult.receivedSummaryAckOrNack;\n }).catch((error) => {\n // SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n // on resultsBuilder\n // We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n // and take a appropriate action.\n });\n\n return resultsBuilder.build();\n }\n\n /** Heuristics summarize attempt. */\n private trySummarize(\n reason: SummarizeReason,\n cancellationToken = this.cancellationToken): void {\n if (this.summarizingLock !== undefined) {\n // lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n // if it's still needed\n this.tryWhileSummarizing = true;\n return;\n }\n\n this.lockedSummaryAction(async () => {\n const attempts: (ISummarizeOptions & { delaySeconds?: number; })[] = [\n { refreshLatestAck: false, fullTree: false },\n { refreshLatestAck: true, fullTree: false },\n { refreshLatestAck: true, fullTree: false, delaySeconds: 2 * 60 },\n { refreshLatestAck: true, fullTree: true, delaySeconds: 10 * 60 },\n ];\n let overrideDelaySeconds: number | undefined;\n let summaryAttempts = 0;\n let summaryAttemptsPerPhase = 0;\n\n let lastResult: { message: string; error: any; } | undefined;\n\n for (let summaryAttemptPhase = 0; summaryAttemptPhase < attempts.length;) {\n if (this.cancellationToken.cancelled) {\n return;\n }\n\n // We only want to attempt 1 summary when reason is \"lastSummary\"\n if (++summaryAttempts > 1 && reason === \"lastSummary\") {\n return;\n }\n\n summaryAttemptsPerPhase++;\n\n const { delaySeconds: regularDelaySeconds = 0, ...options } = attempts[summaryAttemptPhase];\n const delaySeconds = overrideDelaySeconds ?? regularDelaySeconds;\n\n const summarizeProps: ISummarizeTelemetryProperties = {\n reason,\n summaryAttempts,\n summaryAttemptsPerPhase,\n summaryAttemptPhase: summaryAttemptPhase + 1, // make everything 1-based\n ...options,\n };\n\n if (delaySeconds > 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeAttemptDelay\",\n duration: delaySeconds,\n summaryNackDelay: overrideDelaySeconds !== undefined,\n ...summarizeProps,\n });\n await delay(delaySeconds * 1000);\n }\n\n // Make sure the refresh Summary Ack is not being executed.\n await this.refreshSummaryAckLock;\n\n // Note: no need to account for cancellationToken.waitCancelled here, as\n // this is accounted SummaryGenerator.summarizeCore that controls receivedSummaryAckOrNack.\n const resultSummarize = this.generator.summarize(summarizeProps, options, cancellationToken);\n const result = await resultSummarize.receivedSummaryAckOrNack;\n\n if (result.success) {\n return;\n }\n // Check for retryDelay that can come from summaryNack or upload summary flow.\n // Retry the same step only once per retryAfter response.\n overrideDelaySeconds = result.retryAfterSeconds;\n if (overrideDelaySeconds === undefined || summaryAttemptsPerPhase > 1) {\n summaryAttemptPhase++;\n summaryAttemptsPerPhase = 0;\n }\n lastResult = result;\n }\n\n // If all attempts failed, log error (with last attempt info) and close the summarizer container\n this.logger.sendErrorEvent({\n eventName: \"FailToSummarize\",\n reason,\n message: lastResult?.message,\n }, lastResult?.error);\n\n this.stopSummarizerCallback(\"failToSummarize\");\n }).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"UnexpectedSummarizeError\" }, error);\n });\n }\n\n /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */\n public summarizeOnDemand(\n resultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n {\n reason,\n ...options\n }: IOnDemandSummarizeOptions): ISummarizeResults {\n if (this.stopping) {\n resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n return resultsBuilder.build();\n }\n // Check for concurrent summary attempts. If one is found,\n // return a promise that caller can await before trying again.\n if (this.summarizingLock !== undefined) {\n // The heuristics are blocking concurrent summarize attempts.\n throw new UsageError(\"Attempted to run an already-running summarizer on demand\");\n }\n\n const result = this.trySummarizeOnce(\n { reason: `onDemand/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return result;\n }\n\n /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */\n public enqueueSummarize({\n reason,\n afterSequenceNumber = 0,\n override = false,\n ...options\n }: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n const onDemandReason = `enqueue;${reason}` as const;\n let overridden = false;\n if (this.enqueuedSummary !== undefined) {\n if (!override) {\n return { alreadyEnqueued: true };\n }\n // Override existing enqueued summarize attempt.\n this.enqueuedSummary.resultsBuilder.fail(\n \"Aborted; overridden by another enqueue summarize attempt\",\n undefined,\n );\n this.enqueuedSummary = undefined;\n overridden = true;\n }\n this.enqueuedSummary = {\n reason: onDemandReason,\n afterSequenceNumber,\n options,\n resultsBuilder: new SummarizeResultBuilder(),\n };\n const results = this.enqueuedSummary.resultsBuilder.build();\n this.tryRunEnqueuedSummary();\n return overridden ? {\n ...results,\n alreadyEnqueued: true,\n overridden: true,\n } : results;\n }\n\n private tryRunEnqueuedSummary() {\n if (this.stopping) {\n this.disposeEnqueuedSummary();\n return false;\n }\n if (\n this.enqueuedSummary === undefined\n || this.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber\n || this.summarizingLock !== undefined\n ) {\n // If no enqueued summary is ready or a summary is already in progress, take no action.\n return false;\n }\n const { reason, resultsBuilder, options } = this.enqueuedSummary;\n // Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n this.enqueuedSummary = undefined;\n this.trySummarizeOnce(\n { reason: `enqueuedSummary/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return true;\n }\n\n private disposeEnqueuedSummary() {\n if (this.enqueuedSummary !== undefined) {\n this.enqueuedSummary.resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n this.enqueuedSummary = undefined;\n }\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  /*!
3
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
3
  * Licensed under the MIT License.
@@ -1 +1 @@
1
- {"version":3,"file":"scheduleManager.d.ts","sourceRoot":"","sources":["../src/scheduleManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,C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AC,QAAQ,CAAC,MAAM;IAR3B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,QAAQ,CAAS;gBAGJ,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,OAAO,EAAE,YAAY,EAC7B,WAAW,EAAE,MAAM,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,gBAAgB;IAStC,kBAAkB,CAAC,OAAO,EAAE,yBAAyB;IAcrD,iBAAiB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,EAAE,OAAO,EAAE,yBAAyB;CAwBtF"}
@@ -4,7 +4,6 @@ import { isRuntimeMessage } from "@fluidframework/driver-utils";
4
4
  import { DataCorruptionError, DataProcessingError, extractSafePropertiesFromMessage, } from "@fluidframework/container-utils";
5
5
  import { DeltaScheduler } from "./deltaScheduler";
6
6
  import { pkgVersion } from "./packageVersion";
7
- import { latencyThreshold } from "./connectionTelemetry";
8
7
  /**
9
8
  * This class has the following responsibilities:
10
9
  *
@@ -157,15 +156,6 @@ class ScheduleManagerCore {
157
156
  return;
158
157
  }
159
158
  this.localPaused = false;
160
- // Random round number - we want to know when batch waiting paused op processing.
161
- if (duration !== undefined && duration > latencyThreshold) {
162
- this.logger.sendErrorEvent({
163
- eventName: "MaxBatchWaitTimeExceeded",
164
- duration,
165
- sequenceNumber: endBatch,
166
- length: endBatch - startBatch,
167
- });
168
- }
169
159
  this.deltaManager.inbound.resume();
170
160
  }
171
161
  /**
@@ -175,6 +165,8 @@ class ScheduleManagerCore {
175
165
  assert(this.deltaManager.inbound.length !== 0, 0x298 /* "we have something in the queue that generates this event" */);
176
166
  assert((this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined), 0x299 /* "non-synchronized state" */);
177
167
  const metadata = message.metadata;
168
+ // batchMetadata will be true for the message that starts a batch, false for the one that ends it, and
169
+ // undefined for all other messages.
178
170
  const batchMetadata = metadata === null || metadata === void 0 ? void 0 : metadata.batch;
179
171
  // Protocol messages are never part of a runtime batch of messages
180
172
  if (!isRuntimeMessage(message)) {
@@ -197,20 +189,17 @@ class ScheduleManagerCore {
197
189
  assert(!this.localPaused, 0x29d /* "we should be processing ops when there is no active batch" */);
198
190
  return;
199
191
  }
200
- // If the client ID changes then we can move the pause point. If it stayed the same then we need to check.
201
- // If batchMetadata is not undefined then if it's true we've begun a new batch - if false we've ended
202
- // the previous one
203
- if (this.currentBatchClientId !== undefined || batchMetadata === false) {
204
- if (this.currentBatchClientId !== message.clientId) {
205
- // "Batch not closed, yet message from another client!"
206
- throw new DataCorruptionError("OpBatchIncomplete", Object.assign({ runtimeVersion: pkgVersion, batchClientId: this.currentBatchClientId, pauseSequenceNumber: this.pauseSequenceNumber, localBatch: this.currentBatchClientId === this.getClientId(), localMessage: message.clientId === this.getClientId() }, extractSafePropertiesFromMessage(message)));
207
- }
192
+ // If we got here, the message is part of a batch. Either starting, in progress, or ending.
193
+ // If this is not the start of the batch, error out if the message was sent by a client other than the one that
194
+ // started the current batch (it should not be possible for ops from other clients to get interleaved with a batch).
195
+ if (this.currentBatchClientId !== undefined && this.currentBatchClientId !== message.clientId) {
196
+ throw new DataCorruptionError("OpBatchIncomplete", Object.assign({ runtimeVersion: pkgVersion, batchClientId: this.currentBatchClientId, pauseSequenceNumber: this.pauseSequenceNumber, localBatch: this.currentBatchClientId === this.getClientId(), localMessage: message.clientId === this.getClientId() }, extractSafePropertiesFromMessage(message)));
208
197
  }
209
198
  // The queue is
210
199
  // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:
211
200
  // - in afterOpProcessing() - processing ops until reaching start of incomplete batch
212
- // - here (batchMetadata == false below), when queue was empty and start of batch showed up.
213
- // 2. resumed when batch end comes in (batchMetadata === true case below)
201
+ // - here, when queue was empty and start of batch showed up (batchMetadata === true below).
202
+ // 2. resumed when batch end comes in (batchMetadata === false below)
214
203
  if (batchMetadata) {
215
204
  assert(this.currentBatchClientId === undefined, 0x29e /* "there can't be active batch" */);
216
205
  assert(!this.localPaused, 0x29f /* "we should be processing ops when there is no active batch" */);
@@ -1 +1 @@
1
- {"version":3,"file":"scheduleManager.js","sourceRoot":"","sources":["../src/scheduleManager.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACH,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,GACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAMzD;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAKxB,YACqB,YAAwE,EACxE,OAAqB,EAC7B,WAAqC,EAC7B,MAAwB;QAHxB,iBAAY,GAAZ,YAAY,CAA4D;QACxE,YAAO,GAAP,OAAO,CAAc;QAC7B,gBAAW,GAAX,WAAW,CAA0B;QAC7B,WAAM,GAAN,MAAM,CAAkB;QANrC,aAAQ,GAAG,KAAK,CAAC;QAQrB,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CACpC,IAAI,CAAC,YAAY,EACjB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CACpD,CAAC;QACF,KAAK,IAAI,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;IAEM,kBAAkB,CAAC,OAAkC;;QACxD,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,CAAC,QAAQ,EAAE;YACzC,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,EACnC,KAAK,CAAC,mFAAm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,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;SACzC;aAAM;YACH,4CAA4C;YAC5C,MAAM,CAAC,IAAI,CAAC,oBAAoB,KAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;SAC9E;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport {\n DataCorruptionError,\n DataProcessingError,\n extractSafePropertiesFromMessage,\n} from \"@fluidframework/container-utils\";\nimport { DeltaScheduler } from \"./deltaScheduler\";\nimport { pkgVersion } from \"./packageVersion\";\nimport { latencyThreshold } from \"./connectionTelemetry\";\n\ntype IRuntimeMessageMetadata = undefined | {\n batch?: boolean;\n};\n\n/**\n * This class has the following responsibilities:\n *\n * 1. It tracks batches as we process ops and raises \"batchBegin\" and \"batchEnd\" events.\n * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)\n *\n * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch\n * unless all ops of the batch are in.\n */\nexport class ScheduleManager {\n private readonly deltaScheduler: DeltaScheduler;\n private batchClientId: string | undefined;\n private hitError = false;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly emitter: EventEmitter,\n readonly getClientId: () => string | undefined,\n private readonly logger: ITelemetryLogger,\n ) {\n this.deltaScheduler = new DeltaScheduler(\n this.deltaManager,\n ChildLogger.create(this.logger, \"DeltaScheduler\"),\n );\n void new ScheduleManagerCore(deltaManager, getClientId, logger);\n }\n\n public beforeOpProcessing(message: ISequencedDocumentMessage) {\n if (this.batchClientId !== message.clientId) {\n assert(this.batchClientId === undefined,\n 0x2a2 /* \"Batch is interrupted by other client op. Should be caught by trackPending()\" */);\n\n // This could be the beginning of a new batch or an individual message.\n this.emitter.emit(\"batchBegin\", message);\n this.deltaScheduler.batchBegin(message);\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n this.batchClientId = batch ? message.clientId : undefined;\n }\n }\n\n public afterOpProcessing(error: any | undefined, message: ISequencedDocumentMessage) {\n // If this is no longer true, we need to revisit what we do where we set this.hitError.\n assert(!this.hitError, 0x2a3 /* \"container should be closed on any error\" */);\n\n if (error) {\n // We assume here that loader will close container and stop processing all future ops.\n // This is implicit dependency. If this flow changes, this code might no longer be correct.\n this.hitError = true;\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", error, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n // If no batchClientId has been set then we're in an individual batch. Else, if we get\n // batch end metadata, this is end of the current batch.\n if (this.batchClientId === undefined || batch === false) {\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", undefined, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n }\n}\n\n/**\n * This class controls pausing and resuming of inbound queue to ensure that we never\n * start processing ops in a batch IF we do not have all ops in the batch.\n */\nclass ScheduleManagerCore {\n private pauseSequenceNumber: number | undefined;\n private currentBatchClientId: string | undefined;\n private localPaused = false;\n private timePaused = 0;\n private batchCount = 0;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly getClientId: () => string | undefined,\n private readonly logger: ITelemetryLogger,\n ) {\n // Listen for delta manager sends and add batch metadata to messages\n this.deltaManager.on(\"prepareSend\", (messages: IDocumentMessage[]) => {\n if (messages.length === 0) {\n return;\n }\n\n // First message will have the batch flag set to true if doing a batched send\n const firstMessageMetadata = messages[0].metadata as IRuntimeMessageMetadata;\n if (!firstMessageMetadata?.batch) {\n return;\n }\n\n // If the batch contains only a single op, clear the batch flag.\n if (messages.length === 1) {\n delete firstMessageMetadata.batch;\n return;\n }\n\n // Set the batch flag to false on the last message to indicate the end of the send batch\n const lastMessage = messages[messages.length - 1];\n lastMessage.metadata = { ...lastMessage.metadata, batch: false };\n });\n\n // Listen for updates and peek at the inbound\n this.deltaManager.inbound.on(\n \"push\",\n (message: ISequencedDocumentMessage) => {\n this.trackPending(message);\n });\n\n // Start with baseline - empty inbound queue.\n assert(!this.localPaused, 0x293 /* \"initial state\" */);\n\n const allPending = this.deltaManager.inbound.toArray();\n for (const pending of allPending) {\n this.trackPending(pending);\n }\n\n // We are intentionally directly listening to the \"op\" to inspect system ops as well.\n // If we do not observe system ops, we are likely to hit 0x296 assert when system ops\n // precedes start of incomplete batch.\n this.deltaManager.on(\"op\", (message) => this.afterOpProcessing(message.sequenceNumber));\n }\n\n /**\n * The only public function in this class - called when we processed an op,\n * to make decision if op processing should be paused or not after that.\n */\n public afterOpProcessing(sequenceNumber: number) {\n assert(!this.localPaused, 0x294 /* \"can't have op processing paused if we are processing an op\" */);\n\n // If the inbound queue is ever empty, nothing to do!\n if (this.deltaManager.inbound.length === 0) {\n assert(this.pauseSequenceNumber === undefined,\n 0x295 /* \"there should be no pending batch if we have no ops\" */);\n return;\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - here (processing ops until reaching start of incomplete batch)\n // - in trackPending(), when queue was empty and start of batch showed up.\n // 2. resumed when batch end comes in (in trackPending())\n\n // do we have incomplete batch to worry about?\n if (this.pauseSequenceNumber !== undefined) {\n assert(sequenceNumber < this.pauseSequenceNumber,\n 0x296 /* \"we should never start processing incomplete batch!\" */);\n // If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!\n if (sequenceNumber + 1 === this.pauseSequenceNumber) {\n this.pauseQueue();\n }\n }\n }\n\n private pauseQueue() {\n assert(!this.localPaused, 0x297 /* \"always called from resumed state\" */);\n this.localPaused = true;\n this.timePaused = performance.now();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.deltaManager.inbound.pause();\n }\n\n private resumeQueue(startBatch: number, messageEndBatch: ISequencedDocumentMessage) {\n const endBatch = messageEndBatch.sequenceNumber;\n const duration = this.localPaused ? (performance.now() - this.timePaused) : undefined;\n\n this.batchCount++;\n if (this.batchCount % 1000 === 1) {\n this.logger.sendTelemetryEvent({\n eventName: \"BatchStats\",\n sequenceNumber: endBatch,\n length: endBatch - startBatch + 1,\n msnDistance: endBatch - messageEndBatch.minimumSequenceNumber,\n duration,\n batchCount: this.batchCount,\n interrupted: this.localPaused,\n });\n }\n\n // Return early if no change in value\n if (!this.localPaused) {\n return;\n }\n\n this.localPaused = false;\n\n // Random round number - we want to know when batch waiting paused op processing.\n if (duration !== undefined && duration > latencyThreshold) {\n this.logger.sendErrorEvent({\n eventName: \"MaxBatchWaitTimeExceeded\",\n duration,\n sequenceNumber: endBatch,\n length: endBatch - startBatch,\n });\n }\n\n this.deltaManager.inbound.resume();\n }\n\n /**\n * Called for each incoming op (i.e. inbound \"push\" notification)\n */\n private trackPending(message: ISequencedDocumentMessage) {\n assert(this.deltaManager.inbound.length !== 0,\n 0x298 /* \"we have something in the queue that generates this event\" */);\n\n assert((this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined),\n 0x299 /* \"non-synchronized state\" */);\n\n const metadata = message.metadata as IRuntimeMessageMetadata;\n const batchMetadata = metadata?.batch;\n\n // Protocol messages are never part of a runtime batch of messages\n if (!isRuntimeMessage(message)) {\n // Protocol messages should never show up in the middle of the batch!\n if (this.currentBatchClientId !== undefined) {\n throw DataProcessingError.create(\n \"Received a system message during batch processing\", // Formerly known as assert 0x29a\n \"trackPending\",\n message,\n {\n runtimeVersion: pkgVersion,\n batchClientId: this.currentBatchClientId,\n pauseSequenceNumber: this.pauseSequenceNumber,\n localBatch: this.currentBatchClientId === this.getClientId(),\n messageType: message.type,\n });\n }\n\n assert(batchMetadata === undefined, 0x29b /* \"system op in a batch?\" */);\n assert(!this.localPaused, 0x29c /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n if (this.currentBatchClientId === undefined && batchMetadata === undefined) {\n assert(!this.localPaused, 0x29d /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n // If the client ID changes then we can move the pause point. If it stayed the same then we need to check.\n // If batchMetadata is not undefined then if it's true we've begun a new batch - if false we've ended\n // the previous one\n if (this.currentBatchClientId !== undefined || batchMetadata === false) {\n if (this.currentBatchClientId !== message.clientId) {\n // \"Batch not closed, yet message from another client!\"\n throw new DataCorruptionError(\n \"OpBatchIncomplete\",\n {\n runtimeVersion: pkgVersion,\n batchClientId: this.currentBatchClientId,\n pauseSequenceNumber: this.pauseSequenceNumber,\n localBatch: this.currentBatchClientId === this.getClientId(),\n localMessage: message.clientId === this.getClientId(),\n ...extractSafePropertiesFromMessage(message),\n });\n }\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - in afterOpProcessing() - processing ops until reaching start of incomplete batch\n // - here (batchMetadata == false below), when queue was empty and start of batch showed up.\n // 2. resumed when batch end comes in (batchMetadata === true case below)\n\n if (batchMetadata) {\n assert(this.currentBatchClientId === undefined, 0x29e /* \"there can't be active batch\" */);\n assert(!this.localPaused, 0x29f /* \"we should be processing ops when there is no active batch\" */);\n this.pauseSequenceNumber = message.sequenceNumber;\n this.currentBatchClientId = message.clientId;\n // Start of the batch\n // Only pause processing if queue has no other ops!\n // If there are any other ops in the queue, processing will be stopped when they are processed!\n if (this.deltaManager.inbound.length === 1) {\n this.pauseQueue();\n }\n } else if (batchMetadata === false) {\n assert(this.pauseSequenceNumber !== undefined, 0x2a0 /* \"batch presence was validated above\" */);\n // Batch is complete, we can process it!\n this.resumeQueue(this.pauseSequenceNumber, message);\n this.pauseSequenceNumber = undefined;\n this.currentBatchClientId = undefined;\n } else {\n // Continuation of current batch. Do nothing\n assert(this.currentBatchClientId !== undefined, 0x2a1 /* \"logic error\" */);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"scheduleManager.js","sourceRoot":"","sources":["../src/scheduleManager.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACH,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,GACnC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAM9C;;;;;;;;GAQG;AACH,MAAM,OAAO,eAAe;IAKxB,YACqB,YAAwE,EACxE,OAAqB,EAC7B,WAAqC,EAC7B,MAAwB;QAHxB,iBAAY,GAAZ,YAAY,CAA4D;QACxE,YAAO,GAAP,OAAO,CAAc;QAC7B,gBAAW,GAAX,WAAW,CAA0B;QAC7B,WAAM,GAAN,MAAM,CAAkB;QANrC,aAAQ,GAAG,KAAK,CAAC;QAQrB,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CACpC,IAAI,CAAC,YAAY,EACjB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,gBAAgB,CAAC,CACpD,CAAC;QACF,KAAK,IAAI,mBAAmB,CAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACpE,CAAC;IAEM,kBAAkB,CAAC,OAAkC;;QACxD,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,CAAC,QAAQ,EAAE;YACzC,MAAM,CAAC,IAAI,CAAC,aAAa,KAAK,SAAS,EACnC,KAAK,CAAC,mFAAmF,CAAC,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copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport {\n DataCorruptionError,\n DataProcessingError,\n extractSafePropertiesFromMessage,\n} from \"@fluidframework/container-utils\";\nimport { DeltaScheduler } from \"./deltaScheduler\";\nimport { pkgVersion } from \"./packageVersion\";\n\ntype IRuntimeMessageMetadata = undefined | {\n batch?: boolean;\n};\n\n/**\n * This class has the following responsibilities:\n *\n * 1. It tracks batches as we process ops and raises \"batchBegin\" and \"batchEnd\" events.\n * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)\n *\n * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch\n * unless all ops of the batch are in.\n */\nexport class ScheduleManager {\n private readonly deltaScheduler: DeltaScheduler;\n private batchClientId: string | undefined;\n private hitError = false;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly emitter: EventEmitter,\n readonly getClientId: () => string | undefined,\n private readonly logger: ITelemetryLogger,\n ) {\n this.deltaScheduler = new DeltaScheduler(\n this.deltaManager,\n ChildLogger.create(this.logger, \"DeltaScheduler\"),\n );\n void new ScheduleManagerCore(deltaManager, getClientId, logger);\n }\n\n public beforeOpProcessing(message: ISequencedDocumentMessage) {\n if (this.batchClientId !== message.clientId) {\n assert(this.batchClientId === undefined,\n 0x2a2 /* \"Batch is interrupted by other client op. Should be caught by trackPending()\" */);\n\n // This could be the beginning of a new batch or an individual message.\n this.emitter.emit(\"batchBegin\", message);\n this.deltaScheduler.batchBegin(message);\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n this.batchClientId = batch ? message.clientId : undefined;\n }\n }\n\n public afterOpProcessing(error: any | undefined, message: ISequencedDocumentMessage) {\n // If this is no longer true, we need to revisit what we do where we set this.hitError.\n assert(!this.hitError, 0x2a3 /* \"container should be closed on any error\" */);\n\n if (error) {\n // We assume here that loader will close container and stop processing all future ops.\n // This is implicit dependency. If this flow changes, this code might no longer be correct.\n this.hitError = true;\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", error, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n // If no batchClientId has been set then we're in an individual batch. Else, if we get\n // batch end metadata, this is end of the current batch.\n if (this.batchClientId === undefined || batch === false) {\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", undefined, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n }\n}\n\n/**\n * This class controls pausing and resuming of inbound queue to ensure that we never\n * start processing ops in a batch IF we do not have all ops in the batch.\n */\nclass ScheduleManagerCore {\n private pauseSequenceNumber: number | undefined;\n private currentBatchClientId: string | undefined;\n private localPaused = false;\n private timePaused = 0;\n private batchCount = 0;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly getClientId: () => string | undefined,\n private readonly logger: ITelemetryLogger,\n ) {\n // Listen for delta manager sends and add batch metadata to messages\n this.deltaManager.on(\"prepareSend\", (messages: IDocumentMessage[]) => {\n if (messages.length === 0) {\n return;\n }\n\n // First message will have the batch flag set to true if doing a batched send\n const firstMessageMetadata = messages[0].metadata as IRuntimeMessageMetadata;\n if (!firstMessageMetadata?.batch) {\n return;\n }\n\n // If the batch contains only a single op, clear the batch flag.\n if (messages.length === 1) {\n delete firstMessageMetadata.batch;\n return;\n }\n\n // Set the batch flag to false on the last message to indicate the end of the send batch\n const lastMessage = messages[messages.length - 1];\n lastMessage.metadata = { ...lastMessage.metadata, batch: false };\n });\n\n // Listen for updates and peek at the inbound\n this.deltaManager.inbound.on(\n \"push\",\n (message: ISequencedDocumentMessage) => {\n this.trackPending(message);\n });\n\n // Start with baseline - empty inbound queue.\n assert(!this.localPaused, 0x293 /* \"initial state\" */);\n\n const allPending = this.deltaManager.inbound.toArray();\n for (const pending of allPending) {\n this.trackPending(pending);\n }\n\n // We are intentionally directly listening to the \"op\" to inspect system ops as well.\n // If we do not observe system ops, we are likely to hit 0x296 assert when system ops\n // precedes start of incomplete batch.\n this.deltaManager.on(\"op\", (message) => this.afterOpProcessing(message.sequenceNumber));\n }\n\n /**\n * The only public function in this class - called when we processed an op,\n * to make decision if op processing should be paused or not after that.\n */\n public afterOpProcessing(sequenceNumber: number) {\n assert(!this.localPaused, 0x294 /* \"can't have op processing paused if we are processing an op\" */);\n\n // If the inbound queue is ever empty, nothing to do!\n if (this.deltaManager.inbound.length === 0) {\n assert(this.pauseSequenceNumber === undefined,\n 0x295 /* \"there should be no pending batch if we have no ops\" */);\n return;\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - here (processing ops until reaching start of incomplete batch)\n // - in trackPending(), when queue was empty and start of batch showed up.\n // 2. resumed when batch end comes in (in trackPending())\n\n // do we have incomplete batch to worry about?\n if (this.pauseSequenceNumber !== undefined) {\n assert(sequenceNumber < this.pauseSequenceNumber,\n 0x296 /* \"we should never start processing incomplete batch!\" */);\n // If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!\n if (sequenceNumber + 1 === this.pauseSequenceNumber) {\n this.pauseQueue();\n }\n }\n }\n\n private pauseQueue() {\n assert(!this.localPaused, 0x297 /* \"always called from resumed state\" */);\n this.localPaused = true;\n this.timePaused = performance.now();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.deltaManager.inbound.pause();\n }\n\n private resumeQueue(startBatch: number, messageEndBatch: ISequencedDocumentMessage) {\n const endBatch = messageEndBatch.sequenceNumber;\n const duration = this.localPaused ? (performance.now() - this.timePaused) : undefined;\n\n this.batchCount++;\n if (this.batchCount % 1000 === 1) {\n this.logger.sendTelemetryEvent({\n eventName: \"BatchStats\",\n sequenceNumber: endBatch,\n length: endBatch - startBatch + 1,\n msnDistance: endBatch - messageEndBatch.minimumSequenceNumber,\n duration,\n batchCount: this.batchCount,\n interrupted: this.localPaused,\n });\n }\n\n // Return early if no change in value\n if (!this.localPaused) {\n return;\n }\n\n this.localPaused = false;\n\n this.deltaManager.inbound.resume();\n }\n\n /**\n * Called for each incoming op (i.e. inbound \"push\" notification)\n */\n private trackPending(message: ISequencedDocumentMessage) {\n assert(this.deltaManager.inbound.length !== 0,\n 0x298 /* \"we have something in the queue that generates this event\" */);\n\n assert((this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined),\n 0x299 /* \"non-synchronized state\" */);\n\n const metadata = message.metadata as IRuntimeMessageMetadata;\n // batchMetadata will be true for the message that starts a batch, false for the one that ends it, and\n // undefined for all other messages.\n const batchMetadata = metadata?.batch;\n\n // Protocol messages are never part of a runtime batch of messages\n if (!isRuntimeMessage(message)) {\n // Protocol messages should never show up in the middle of the batch!\n if (this.currentBatchClientId !== undefined) {\n throw DataProcessingError.create(\n \"Received a system message during batch processing\", // Formerly known as assert 0x29a\n \"trackPending\",\n message,\n {\n runtimeVersion: pkgVersion,\n batchClientId: this.currentBatchClientId,\n pauseSequenceNumber: this.pauseSequenceNumber,\n localBatch: this.currentBatchClientId === this.getClientId(),\n messageType: message.type,\n });\n }\n\n assert(batchMetadata === undefined, 0x29b /* \"system op in a batch?\" */);\n assert(!this.localPaused, 0x29c /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n if (this.currentBatchClientId === undefined && batchMetadata === undefined) {\n assert(!this.localPaused, 0x29d /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n // If we got here, the message is part of a batch. Either starting, in progress, or ending.\n\n // If this is not the start of the batch, error out if the message was sent by a client other than the one that\n // started the current batch (it should not be possible for ops from other clients to get interleaved with a batch).\n if (this.currentBatchClientId !== undefined && this.currentBatchClientId !== message.clientId) {\n throw new DataCorruptionError(\n \"OpBatchIncomplete\",\n {\n runtimeVersion: pkgVersion,\n batchClientId: this.currentBatchClientId,\n pauseSequenceNumber: this.pauseSequenceNumber,\n localBatch: this.currentBatchClientId === this.getClientId(),\n localMessage: message.clientId === this.getClientId(),\n ...extractSafePropertiesFromMessage(message),\n });\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - in afterOpProcessing() - processing ops until reaching start of incomplete batch\n // - here, when queue was empty and start of batch showed up (batchMetadata === true below).\n // 2. resumed when batch end comes in (batchMetadata === false below)\n\n if (batchMetadata) {\n assert(this.currentBatchClientId === undefined, 0x29e /* \"there can't be active batch\" */);\n assert(!this.localPaused, 0x29f /* \"we should be processing ops when there is no active batch\" */);\n this.pauseSequenceNumber = message.sequenceNumber;\n this.currentBatchClientId = message.clientId;\n // Start of the batch\n // Only pause processing if queue has no other ops!\n // If there are any other ops in the queue, processing will be stopped when they are processed!\n if (this.deltaManager.inbound.length === 1) {\n this.pauseQueue();\n }\n } else if (batchMetadata === false) {\n assert(this.pauseSequenceNumber !== undefined, 0x2a0 /* \"batch presence was validated above\" */);\n // Batch is complete, we can process it!\n this.resumeQueue(this.pauseSequenceNumber, message);\n this.pauseSequenceNumber = undefined;\n this.currentBatchClientId = undefined;\n } else {\n // Continuation of current batch. Do nothing\n assert(this.currentBatchClientId !== undefined, 0x2a1 /* \"logic error\" */);\n }\n }\n}\n"]}
@@ -2,7 +2,6 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- /// <reference types="node" />
6
5
  import { EventEmitter } from "events";
7
6
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
8
7
  import { ILoader } from "@fluidframework/container-definitions";
@@ -1 +1 @@
1
- {"version":3,"file":"summarizer.d.ts","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH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AEY,iBAAiB;CAqDlC"}
package/lib/summarizer.js CHANGED
@@ -161,10 +161,11 @@ export class Summarizer extends EventEmitter {
161
161
  this.stopDeferred.resolve(reason);
162
162
  }
163
163
  close() {
164
+ var _a;
164
165
  // This will result in "summarizerClientDisconnected" stop reason recorded in telemetry,
165
166
  // unless stop() was called earlier
166
167
  this.dispose();
167
- this.runtime.closeFn();
168
+ ((_a = this.runtime.disposeFn) !== null && _a !== void 0 ? _a : this.runtime.closeFn)();
168
169
  }
169
170
  async runCore(onBehalfOf) {
170
171
  const runCoordinator = await this.runCoordinatorCreateFn(this.runtime);
@@ -1 +1 @@
1
- {"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAW,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACH,WAAW,EAEX,YAAY,EACZ,YAAY,EACZ,eAAe,GAClB,MAAM,iCAAiC,CAAC;AASzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAIhD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Ae,CAAC,+BAA+B,EAAE;wBACxE,aAAa,CAAC,kBAAkB,CAAC;4BAC7B,SAAS,EAAE,8BAA8B;4BACzC,uBAAuB,EAAE,iBAAiB;4BAC1C,cAAc,EAAE,eAAe;4BAC/B,SAAS,EAAE,gBAAgB;yBAC9B,EAAE,KAAK,CAAC,CAAC;qBACb;yBAAM;wBACH,MAAM,KAAK,CAAC;qBACf;gBACL,CAAC,CAAC,CACL,CAAC;aACL;YAAC,OAAO,KAAK,EAAE;gBACZ,aAAa,CAAC,cAAc,CAAC;oBACzB,SAAS,EAAE,uBAAuB;oBAClC,uBAAuB,EAAE,iBAAiB;oBAC1C,MAAM,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,0CAAE,QAAQ,0CAAE,MAAM;oBACxC,SAAS,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,QAAQ,0CAAE,MAAM;iBAC/C,EAAE,KAAK,CAAC,CAAC;aACb;YACD,iBAAiB,EAAE,CAAC;SACvB;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ILoader, LoaderHeader } from \"@fluidframework/container-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { DriverErrorType, DriverHeader } from \"@fluidframework/driver-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport {\n ChildLogger,\n IFluidErrorBase,\n isFluidError,\n LoggingError,\n wrapErrorAndLog,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n FluidObject,\n IFluidHandleContext,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport { ISummaryConfiguration } from \"./containerRuntime\";\nimport { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { IAckedSummary, SummaryCollection } from \"./summaryCollection\";\nimport { SummarizerHandle } from \"./summarizerHandle\";\nimport { RunningSummarizer } from \"./runningSummarizer\";\nimport {\n ISummarizer,\n ISummarizerInternalsProvider,\n ISummarizerRuntime,\n ISummarizingWarning,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics\";\nimport { SummarizeResultBuilder } from \"./summaryGenerator\";\nimport { IConnectableRuntime } from \".\";\n\nconst summarizingError = \"summarizingError\";\n\nexport class SummarizingWarning extends LoggingError implements ISummarizingWarning, IFluidErrorBase {\n readonly errorType = summarizingError;\n readonly canRetry = true;\n\n constructor(\n errorMessage: string,\n readonly logged: boolean = false,\n ) {\n super(errorMessage);\n }\n\n static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {\n const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);\n return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n }\n}\n\nexport const createSummarizingWarning =\n (errorMessage: string, logged: boolean) => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n */\nexport class Summarizer extends EventEmitter implements ISummarizer {\n public get IFluidLoadable() { return this; }\n public get ISummarizer() { return this; }\n\n private readonly logger: ITelemetryLogger;\n private runningSummarizer?: RunningSummarizer;\n private _disposed: boolean = false;\n private starting: boolean = false;\n\n private readonly innerHandle: IFluidHandle<this>;\n\n public get handle(): IFluidHandle<this> { return this.innerHandle; }\n private readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n constructor(\n url: string,\n /** Reference to runtime that created this object.\n * i.e. runtime with clientType === \"summarizer\"\n */\n private readonly runtime: ISummarizerRuntime,\n private readonly configurationGetter: () => ISummaryConfiguration,\n /** Represents an object that can generate summary.\n * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n */\n private readonly internalsProvider: ISummarizerInternalsProvider,\n handleContext: IFluidHandleContext,\n public readonly summaryCollection: SummaryCollection,\n private readonly runCoordinatorCreateFn:\n (runtime: IConnectableRuntime) => Promise<ICancellableSummarizerController>,\n ) {\n super();\n this.logger = ChildLogger.create(this.runtime.logger, \"Summarizer\");\n this.innerHandle = new SummarizerHandle(this, url, handleContext);\n }\n\n /**\n * Creates a Summarizer and its underlying client.\n * Note that different implementations of ILoader will handle the URL differently.\n * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's\n * starting with \"/\" as relative to the Container. The general ILoader\n * interface will expect an absolute URL and will not handle \"/\".\n * @param loader - the loader that resolves the request\n * @param url - the URL used to resolve the container\n */\n public static async create(\n loader: ILoader,\n url: string): Promise<ISummarizer> {\n const request: IRequest = {\n headers: {\n [LoaderHeader.cache]: false,\n [LoaderHeader.clientDetails]: {\n capabilities: { interactive: false },\n type: summarizerClientType,\n },\n [DriverHeader.summarizingClient]: true,\n [LoaderHeader.reconnect]: false,\n },\n url,\n };\n\n const resolvedContainer = await loader.resolve(request);\n const fluidObject =\n await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, { url: \"_summarizer\" });\n if (fluidObject.ISummarizer === undefined) {\n throw new UsageError(\"Fluid object does not implement ISummarizer\");\n }\n return fluidObject.ISummarizer;\n }\n\n public async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n try {\n return await this.runCore(onBehalfOf);\n } catch (error) {\n this.stop(\"summarizerException\");\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n } finally {\n this.close();\n }\n }\n\n /**\n * Stops the summarizer from running. This will complete\n * the run promise, and also close the container.\n * @param reason - reason code for stopping\n */\n public stop(reason: SummarizerStopReason) {\n this.stopDeferred.resolve(reason);\n }\n\n public close() {\n // This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n // unless stop() was called earlier\n this.dispose();\n this.runtime.closeFn();\n }\n\n private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(this.runtime);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n void stopP.then((reason) => {\n this.logger.sendTelemetryEvent({\n eventName: \"StoppingSummarizer\",\n onBehalfOf,\n reason,\n });\n });\n\n if (runCoordinator.cancelled) {\n return runCoordinator.waitCancelled;\n }\n\n const runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopReason = await stopP;\n\n // There are two possible approaches here:\n // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n // faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n // The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n // In general, it's more wasted resources.\n // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n // substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n // conflict with new summarizer client starting on different client.\n // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n // cons of #2 substantially.\n\n // Cleanup after running\n await runningSummarizer.waitStop(\n !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));\n\n // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n runCoordinator.stop(stopReason);\n\n return stopReason;\n }\n\n /**\n * Should we try to run a last summary for the given stop reason?\n * Currently only allows \"parentNotConnected\"\n * @param stopReason - SummarizerStopReason\n * @returns - true if the stop reason can run a last summary\n */\n public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n return stopReason === \"parentNotConnected\";\n }\n\n /**\n * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n * (in the on-demand case).\n * @param onBehalfOf - ID of the client that requested that the summarizer start\n * @param runCoordinator - cancellation token\n * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n * @returns - Promise that is fulfilled when the RunningSummarizer is ready\n */\n private async start(\n onBehalfOf: string,\n runCoordinator: ICancellableSummarizerController): Promise<RunningSummarizer> {\n if (this.runningSummarizer) {\n if (this.runningSummarizer.disposed) {\n throw new UsageError(\"Starting a disposed summarizer\");\n }\n return this.runningSummarizer;\n }\n if (this.starting) {\n throw new UsageError(\"Attempting to start a summarizer that is already starting\");\n }\n this.starting = true;\n // Initialize values and first ack (time is not exact)\n this.logger.sendTelemetryEvent({\n eventName: \"RunningSummarizer\",\n onBehalfOf,\n initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n config: JSON.stringify(this.configurationGetter()),\n });\n\n // Summarizing container ID (with clientType === \"summarizer\")\n const clientId = this.runtime.clientId;\n if (clientId === undefined) {\n throw new UsageError(\"clientId should be defined if connected.\");\n }\n\n const runningSummarizer = await RunningSummarizer.start(\n this.logger,\n this.summaryCollection.createWatcher(clientId),\n this.configurationGetter(),\n async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n new SummarizeHeuristicData(\n this.runtime.deltaManager.lastSequenceNumber,\n { /** summary attempt baseline for heuristics */\n refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n summaryTime: Date.now(),\n } as const,\n ),\n (errorMessage: string) => {\n if (!this._disposed) {\n this.logger.sendErrorEvent({ eventName: \"summarizingError\" },\n createSummarizingWarning(errorMessage, true));\n }\n },\n this.summaryCollection,\n runCoordinator /* cancellationToken */,\n (reason) => runCoordinator.stop(reason), /* stopSummarizerCallback */\n this.runtime,\n );\n this.runningSummarizer = runningSummarizer;\n this.starting = false;\n\n // Handle summary acks\n // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions\n this.handleSummaryAcks().catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"HandleSummaryAckFatalError\" }, error);\n });\n\n return runningSummarizer;\n }\n\n /**\n * Disposes of resources after running. This cleanup will\n * clear any outstanding timers and reset some of the state\n * properties.\n * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n */\n public dispose() {\n // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n this.stop(\"summarizerClientDisconnected\");\n\n this._disposed = true;\n if (this.runningSummarizer) {\n this.runningSummarizer.dispose();\n this.runningSummarizer = undefined;\n }\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n try {\n if (this._disposed || this.runningSummarizer?.disposed) {\n throw new UsageError(\"Summarizer is already disposed.\");\n }\n if (this.runtime.summarizerClientId !== undefined &&\n this.runtime.summarizerClientId !== this.runtime.clientId) {\n // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n // This is to prevent the on-demand summary and heuristic-based summary from stepping on\n // each other.\n throw new UsageError(\"On-demand summary attempted while an elected summarizer is present\");\n }\n const builder = new SummarizeResultBuilder();\n if (this.runningSummarizer) {\n // Summarizer is already running. Go ahead and start.\n return this.runningSummarizer.summarizeOnDemand(builder, ...args);\n }\n\n // Summarizer isn't running, so we need to start it, which is an async operation.\n // Manage the promise related to creating the cancellation token here.\n // The promises related to starting, summarizing,\n // and submitting are communicated to the caller through the results builder.\n const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n coordinatorCreateP.then((runCoordinator) => {\n // Successfully created the cancellation token. Start the summarizer.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const startP = this.start(this.runtime.clientId!, runCoordinator);\n startP.then(async (runningSummarizer) => {\n // Successfully started the summarizer. Run it.\n runningSummarizer.summarizeOnDemand(builder, ...args);\n // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n const stopReason = await Promise.race([this.stopDeferred.promise, runCoordinator.waitCancelled]);\n await runningSummarizer.waitStop(false);\n runCoordinator.stop(stopReason);\n this.close();\n }).catch((reason) => {\n builder.fail(\"Failed to start summarizer\", reason);\n });\n }).catch((reason) => {\n builder.fail(\"Failed to create cancellation token\", reason);\n });\n\n return builder.build();\n } catch (error) {\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n }\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this._disposed || this.runningSummarizer === undefined || this.runningSummarizer.disposed) {\n throw new UsageError(\"Summarizer is not running or already disposed.\");\n }\n return this.runningSummarizer.enqueueSummarize(...args);\n };\n\n private async handleSummaryAcks() {\n let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;\n let ack: IAckedSummary | undefined;\n while (this.runningSummarizer) {\n const summaryLogger = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;\n try {\n // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,\n // we record undefined, not previous handles.\n ack = undefined;\n ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);\n refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n const summaryOpHandle = ack.summaryOp.contents.handle;\n const summaryAckHandle = ack.summaryAck.contents.handle;\n // Make sure we block any summarizer from being executed/enqueued while\n // executing the refreshLatestSummaryAck.\n // https://dev.azure.com/fluidframework/internal/_workitems/edit/779\n await this.runningSummarizer.lockedRefreshSummaryAckAction(async () =>\n this.internalsProvider.refreshLatestSummaryAck({\n proposalHandle: summaryOpHandle,\n ackHandle: summaryAckHandle,\n summaryRefSeq: refSequenceNumber,\n summaryLogger },\n ).catch(async (error) => {\n // If the error is 404, so maybe the fetched version no longer exists on server. We just\n // ignore this error in that case, as that means we will have another summaryAck for the\n // latest version with which we will refresh the state. However in case of single commit\n // summary, we might me missing a summary ack, so in that case we are still fine as the\n // code in `submitSummary` function in container runtime, will refresh the latest state\n // by calling `refreshLatestSummaryAckFromServer` and we will be fine.\n if (isFluidError(error)\n && error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError) {\n summaryLogger.sendTelemetryEvent({\n eventName: \"HandleSummaryAckErrorIgnored\",\n referenceSequenceNumber: refSequenceNumber,\n proposalHandle: summaryOpHandle,\n ackHandle: summaryAckHandle,\n }, error);\n } else {\n throw error;\n }\n }),\n );\n } catch (error) {\n summaryLogger.sendErrorEvent({\n eventName: \"HandleSummaryAckError\",\n referenceSequenceNumber: refSequenceNumber,\n handle: ack?.summaryOp?.contents?.handle,\n ackHandle: ack?.summaryAck?.contents?.handle,\n }, error);\n }\n refSequenceNumber++;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAW,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACH,WAAW,EAEX,YAAY,EACZ,YAAY,EACZ,eAAe,GAClB,MAAM,iCAAiC,CAAC;AASzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE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vF,uFAAuF;oBACvF,sEAAsE;oBACtE,IAAI,YAAY,CAAC,KAAK,CAAC;2BAChB,KAAK,CAAC,SAAS,KAAK,eAAe,CAAC,+BAA+B,EAAE;wBACxE,aAAa,CAAC,kBAAkB,CAAC;4BAC7B,SAAS,EAAE,8BAA8B;4BACzC,uBAAuB,EAAE,iBAAiB;4BAC1C,cAAc,EAAE,eAAe;4BAC/B,SAAS,EAAE,gBAAgB;yBAC9B,EAAE,KAAK,CAAC,CAAC;qBACb;yBAAM;wBACH,MAAM,KAAK,CAAC;qBACf;gBACL,CAAC,CAAC,CACL,CAAC;aACL;YAAC,OAAO,KAAK,EAAE;gBACZ,aAAa,CAAC,cAAc,CAAC;oBACzB,SAAS,EAAE,uBAAuB;oBAClC,uBAAuB,EAAE,iBAAiB;oBAC1C,MAAM,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,0CAAE,QAAQ,0CAAE,MAAM;oBACxC,SAAS,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,QAAQ,0CAAE,MAAM;iBAC/C,EAAE,KAAK,CAAC,CAAC;aACb;YACD,iBAAiB,EAAE,CAAC;SACvB;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ILoader, LoaderHeader } from \"@fluidframework/container-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { DriverErrorType, DriverHeader } from \"@fluidframework/driver-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport {\n ChildLogger,\n IFluidErrorBase,\n isFluidError,\n LoggingError,\n wrapErrorAndLog,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n FluidObject,\n IFluidHandleContext,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport { ISummaryConfiguration } from \"./containerRuntime\";\nimport { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { IAckedSummary, SummaryCollection } from \"./summaryCollection\";\nimport { SummarizerHandle } from \"./summarizerHandle\";\nimport { RunningSummarizer } from \"./runningSummarizer\";\nimport {\n ISummarizer,\n ISummarizerInternalsProvider,\n ISummarizerRuntime,\n ISummarizingWarning,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics\";\nimport { SummarizeResultBuilder } from \"./summaryGenerator\";\nimport { IConnectableRuntime } from \".\";\n\nconst summarizingError = \"summarizingError\";\n\nexport class SummarizingWarning extends LoggingError implements ISummarizingWarning, IFluidErrorBase {\n readonly errorType = summarizingError;\n readonly canRetry = true;\n\n constructor(\n errorMessage: string,\n readonly logged: boolean = false,\n ) {\n super(errorMessage);\n }\n\n static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {\n const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);\n return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n }\n}\n\nexport const createSummarizingWarning =\n (errorMessage: string, logged: boolean) => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n */\nexport class Summarizer extends EventEmitter implements ISummarizer {\n public get IFluidLoadable() { return this; }\n public get ISummarizer() { return this; }\n\n private readonly logger: ITelemetryLogger;\n private runningSummarizer?: RunningSummarizer;\n private _disposed: boolean = false;\n private starting: boolean = false;\n\n private readonly innerHandle: IFluidHandle<this>;\n\n public get handle(): IFluidHandle<this> { return this.innerHandle; }\n private readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n constructor(\n url: string,\n /** Reference to runtime that created this object.\n * i.e. runtime with clientType === \"summarizer\"\n */\n private readonly runtime: ISummarizerRuntime,\n private readonly configurationGetter: () => ISummaryConfiguration,\n /** Represents an object that can generate summary.\n * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n */\n private readonly internalsProvider: ISummarizerInternalsProvider,\n handleContext: IFluidHandleContext,\n public readonly summaryCollection: SummaryCollection,\n private readonly runCoordinatorCreateFn:\n (runtime: IConnectableRuntime) => Promise<ICancellableSummarizerController>,\n ) {\n super();\n this.logger = ChildLogger.create(this.runtime.logger, \"Summarizer\");\n this.innerHandle = new SummarizerHandle(this, url, handleContext);\n }\n\n /**\n * Creates a Summarizer and its underlying client.\n * Note that different implementations of ILoader will handle the URL differently.\n * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's\n * starting with \"/\" as relative to the Container. The general ILoader\n * interface will expect an absolute URL and will not handle \"/\".\n * @param loader - the loader that resolves the request\n * @param url - the URL used to resolve the container\n */\n public static async create(\n loader: ILoader,\n url: string): Promise<ISummarizer> {\n const request: IRequest = {\n headers: {\n [LoaderHeader.cache]: false,\n [LoaderHeader.clientDetails]: {\n capabilities: { interactive: false },\n type: summarizerClientType,\n },\n [DriverHeader.summarizingClient]: true,\n [LoaderHeader.reconnect]: false,\n },\n url,\n };\n\n const resolvedContainer = await loader.resolve(request);\n const fluidObject =\n await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, { url: \"_summarizer\" });\n if (fluidObject.ISummarizer === undefined) {\n throw new UsageError(\"Fluid object does not implement ISummarizer\");\n }\n return fluidObject.ISummarizer;\n }\n\n public async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n try {\n return await this.runCore(onBehalfOf);\n } catch (error) {\n this.stop(\"summarizerException\");\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n } finally {\n this.close();\n }\n }\n\n /**\n * Stops the summarizer from running. This will complete\n * the run promise, and also close the container.\n * @param reason - reason code for stopping\n */\n public stop(reason: SummarizerStopReason) {\n this.stopDeferred.resolve(reason);\n }\n\n public close() {\n // This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n // unless stop() was called earlier\n this.dispose();\n (this.runtime.disposeFn ?? this.runtime.closeFn)()\n }\n\n private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(this.runtime);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n void stopP.then((reason) => {\n this.logger.sendTelemetryEvent({\n eventName: \"StoppingSummarizer\",\n onBehalfOf,\n reason,\n });\n });\n\n if (runCoordinator.cancelled) {\n return runCoordinator.waitCancelled;\n }\n\n const runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopReason = await stopP;\n\n // There are two possible approaches here:\n // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n // faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n // The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n // In general, it's more wasted resources.\n // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n // substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n // conflict with new summarizer client starting on different client.\n // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n // cons of #2 substantially.\n\n // Cleanup after running\n await runningSummarizer.waitStop(\n !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));\n\n // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n runCoordinator.stop(stopReason);\n\n return stopReason;\n }\n\n /**\n * Should we try to run a last summary for the given stop reason?\n * Currently only allows \"parentNotConnected\"\n * @param stopReason - SummarizerStopReason\n * @returns - true if the stop reason can run a last summary\n */\n public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n return stopReason === \"parentNotConnected\";\n }\n\n /**\n * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n * (in the on-demand case).\n * @param onBehalfOf - ID of the client that requested that the summarizer start\n * @param runCoordinator - cancellation token\n * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n * @returns - Promise that is fulfilled when the RunningSummarizer is ready\n */\n private async start(\n onBehalfOf: string,\n runCoordinator: ICancellableSummarizerController): Promise<RunningSummarizer> {\n if (this.runningSummarizer) {\n if (this.runningSummarizer.disposed) {\n throw new UsageError(\"Starting a disposed summarizer\");\n }\n return this.runningSummarizer;\n }\n if (this.starting) {\n throw new UsageError(\"Attempting to start a summarizer that is already starting\");\n }\n this.starting = true;\n // Initialize values and first ack (time is not exact)\n this.logger.sendTelemetryEvent({\n eventName: \"RunningSummarizer\",\n onBehalfOf,\n initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n config: JSON.stringify(this.configurationGetter()),\n });\n\n // Summarizing container ID (with clientType === \"summarizer\")\n const clientId = this.runtime.clientId;\n if (clientId === undefined) {\n throw new UsageError(\"clientId should be defined if connected.\");\n }\n\n const runningSummarizer = await RunningSummarizer.start(\n this.logger,\n this.summaryCollection.createWatcher(clientId),\n this.configurationGetter(),\n async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n new SummarizeHeuristicData(\n this.runtime.deltaManager.lastSequenceNumber,\n { /** summary attempt baseline for heuristics */\n refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n summaryTime: Date.now(),\n } as const,\n ),\n (errorMessage: string) => {\n if (!this._disposed) {\n this.logger.sendErrorEvent({ eventName: \"summarizingError\" },\n createSummarizingWarning(errorMessage, true));\n }\n },\n this.summaryCollection,\n runCoordinator /* cancellationToken */,\n (reason) => runCoordinator.stop(reason), /* stopSummarizerCallback */\n this.runtime,\n );\n this.runningSummarizer = runningSummarizer;\n this.starting = false;\n\n // Handle summary acks\n // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions\n this.handleSummaryAcks().catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"HandleSummaryAckFatalError\" }, error);\n });\n\n return runningSummarizer;\n }\n\n /**\n * Disposes of resources after running. This cleanup will\n * clear any outstanding timers and reset some of the state\n * properties.\n * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n */\n public dispose() {\n // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n this.stop(\"summarizerClientDisconnected\");\n\n this._disposed = true;\n if (this.runningSummarizer) {\n this.runningSummarizer.dispose();\n this.runningSummarizer = undefined;\n }\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n try {\n if (this._disposed || this.runningSummarizer?.disposed) {\n throw new UsageError(\"Summarizer is already disposed.\");\n }\n if (this.runtime.summarizerClientId !== undefined &&\n this.runtime.summarizerClientId !== this.runtime.clientId) {\n // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n // This is to prevent the on-demand summary and heuristic-based summary from stepping on\n // each other.\n throw new UsageError(\"On-demand summary attempted while an elected summarizer is present\");\n }\n const builder = new SummarizeResultBuilder();\n if (this.runningSummarizer) {\n // Summarizer is already running. Go ahead and start.\n return this.runningSummarizer.summarizeOnDemand(builder, ...args);\n }\n\n // Summarizer isn't running, so we need to start it, which is an async operation.\n // Manage the promise related to creating the cancellation token here.\n // The promises related to starting, summarizing,\n // and submitting are communicated to the caller through the results builder.\n const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n coordinatorCreateP.then((runCoordinator) => {\n // Successfully created the cancellation token. Start the summarizer.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const startP = this.start(this.runtime.clientId!, runCoordinator);\n startP.then(async (runningSummarizer) => {\n // Successfully started the summarizer. Run it.\n runningSummarizer.summarizeOnDemand(builder, ...args);\n // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n const stopReason = await Promise.race([this.stopDeferred.promise, runCoordinator.waitCancelled]);\n await runningSummarizer.waitStop(false);\n runCoordinator.stop(stopReason);\n this.close();\n }).catch((reason) => {\n builder.fail(\"Failed to start summarizer\", reason);\n });\n }).catch((reason) => {\n builder.fail(\"Failed to create cancellation token\", reason);\n });\n\n return builder.build();\n } catch (error) {\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n }\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this._disposed || this.runningSummarizer === undefined || this.runningSummarizer.disposed) {\n throw new UsageError(\"Summarizer is not running or already disposed.\");\n }\n return this.runningSummarizer.enqueueSummarize(...args);\n };\n\n private async handleSummaryAcks() {\n let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;\n let ack: IAckedSummary | undefined;\n while (this.runningSummarizer) {\n const summaryLogger = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;\n try {\n // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,\n // we record undefined, not previous handles.\n ack = undefined;\n ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);\n refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n const summaryOpHandle = ack.summaryOp.contents.handle;\n const summaryAckHandle = ack.summaryAck.contents.handle;\n // Make sure we block any summarizer from being executed/enqueued while\n // executing the refreshLatestSummaryAck.\n // https://dev.azure.com/fluidframework/internal/_workitems/edit/779\n await this.runningSummarizer.lockedRefreshSummaryAckAction(async () =>\n this.internalsProvider.refreshLatestSummaryAck({\n proposalHandle: summaryOpHandle,\n ackHandle: summaryAckHandle,\n summaryRefSeq: refSequenceNumber,\n summaryLogger },\n ).catch(async (error) => {\n // If the error is 404, so maybe the fetched version no longer exists on server. We just\n // ignore this error in that case, as that means we will have another summaryAck for the\n // latest version with which we will refresh the state. However in case of single commit\n // summary, we might me missing a summary ack, so in that case we are still fine as the\n // code in `submitSummary` function in container runtime, will refresh the latest state\n // by calling `refreshLatestSummaryAckFromServer` and we will be fine.\n if (isFluidError(error)\n && error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError) {\n summaryLogger.sendTelemetryEvent({\n eventName: \"HandleSummaryAckErrorIgnored\",\n referenceSequenceNumber: refSequenceNumber,\n proposalHandle: summaryOpHandle,\n ackHandle: summaryAckHandle,\n }, error);\n } else {\n throw error;\n }\n }),\n );\n } catch (error) {\n summaryLogger.sendErrorEvent({\n eventName: \"HandleSummaryAckError\",\n referenceSequenceNumber: refSequenceNumber,\n handle: ack?.summaryOp?.contents?.handle,\n ackHandle: ack?.summaryAck?.contents?.handle,\n }, error);\n }\n refSequenceNumber++;\n }\n }\n}\n"]}
@@ -71,6 +71,7 @@ export interface ISummarizerRuntime extends IConnectableRuntime {
71
71
  readonly logger: ITelemetryLogger;
72
72
  /** clientId of parent (non-summarizing) container that owns summarizer container */
73
73
  readonly summarizerClientId: string | undefined;
74
+ disposeFn?(): void;
74
75
  closeFn(): void;
75
76
  /** @deprecated 1.0, please remove all implementations and usage */
76
77
  on(event: "batchEnd", listener: (error: any, op: ISequencedDocumentMessage) => void): this;