@fluidframework/container-runtime 2.0.0-internal.5.4.2 → 2.0.0-internal.6.0.1

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 (196) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/dist/batchTracker.d.ts +2 -1
  3. package/dist/batchTracker.d.ts.map +1 -1
  4. package/dist/batchTracker.js.map +1 -1
  5. package/dist/blobManager.d.ts +4 -1
  6. package/dist/blobManager.d.ts.map +1 -1
  7. package/dist/blobManager.js +61 -26
  8. package/dist/blobManager.js.map +1 -1
  9. package/dist/connectionTelemetry.js +10 -2
  10. package/dist/connectionTelemetry.js.map +1 -1
  11. package/dist/containerRuntime.d.ts +26 -11
  12. package/dist/containerRuntime.d.ts.map +1 -1
  13. package/dist/containerRuntime.js +177 -123
  14. package/dist/containerRuntime.js.map +1 -1
  15. package/dist/dataStore.js +8 -2
  16. package/dist/dataStore.js.map +1 -1
  17. package/dist/dataStoreContext.js +23 -24
  18. package/dist/dataStoreContext.js.map +1 -1
  19. package/dist/dataStores.d.ts +20 -4
  20. package/dist/dataStores.d.ts.map +1 -1
  21. package/dist/dataStores.js +107 -53
  22. package/dist/dataStores.js.map +1 -1
  23. package/dist/gc/garbageCollection.js +17 -20
  24. package/dist/gc/garbageCollection.js.map +1 -1
  25. package/dist/gc/gcConfigs.js +13 -11
  26. package/dist/gc/gcConfigs.js.map +1 -1
  27. package/dist/gc/gcHelpers.js +4 -6
  28. package/dist/gc/gcHelpers.js.map +1 -1
  29. package/dist/gc/gcSummaryStateTracker.js +4 -6
  30. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  31. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  32. package/dist/gc/gcTelemetry.js +55 -37
  33. package/dist/gc/gcTelemetry.js.map +1 -1
  34. package/dist/id-compressor/idCompressor.js +49 -51
  35. package/dist/id-compressor/idCompressor.js.map +1 -1
  36. package/dist/id-compressor/idRange.js +2 -2
  37. package/dist/id-compressor/idRange.js.map +1 -1
  38. package/dist/id-compressor/sessionIdNormalizer.js +11 -16
  39. package/dist/id-compressor/sessionIdNormalizer.js.map +1 -1
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/opLifecycle/batchManager.js +10 -6
  44. package/dist/opLifecycle/batchManager.js.map +1 -1
  45. package/dist/opLifecycle/opCompressor.js +6 -1
  46. package/dist/opLifecycle/opCompressor.js.map +1 -1
  47. package/dist/opLifecycle/opDecompressor.js +11 -9
  48. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  49. package/dist/opLifecycle/opGroupingManager.js +13 -5
  50. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  51. package/dist/opLifecycle/opSplitter.js +10 -6
  52. package/dist/opLifecycle/opSplitter.js.map +1 -1
  53. package/dist/opLifecycle/outbox.js +1 -2
  54. package/dist/opLifecycle/outbox.js.map +1 -1
  55. package/dist/opLifecycle/remoteMessageProcessor.js +1 -1
  56. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  57. package/dist/opProperties.js +1 -2
  58. package/dist/opProperties.js.map +1 -1
  59. package/dist/packageVersion.d.ts +1 -1
  60. package/dist/packageVersion.js +1 -1
  61. package/dist/packageVersion.js.map +1 -1
  62. package/dist/pendingStateManager.d.ts +2 -2
  63. package/dist/pendingStateManager.d.ts.map +1 -1
  64. package/dist/pendingStateManager.js +22 -22
  65. package/dist/pendingStateManager.js.map +1 -1
  66. package/dist/scheduleManager.js +14 -10
  67. package/dist/scheduleManager.js.map +1 -1
  68. package/dist/summary/orderedClientElection.d.ts +2 -1
  69. package/dist/summary/orderedClientElection.d.ts.map +1 -1
  70. package/dist/summary/orderedClientElection.js +17 -18
  71. package/dist/summary/orderedClientElection.js.map +1 -1
  72. package/dist/summary/runningSummarizer.js +32 -38
  73. package/dist/summary/runningSummarizer.js.map +1 -1
  74. package/dist/summary/summarizer.js +4 -7
  75. package/dist/summary/summarizer.js.map +1 -1
  76. package/dist/summary/summarizerClientElection.js +5 -9
  77. package/dist/summary/summarizerClientElection.js.map +1 -1
  78. package/dist/summary/summarizerHeuristics.js +8 -12
  79. package/dist/summary/summarizerHeuristics.js.map +1 -1
  80. package/dist/summary/summarizerNode/summarizerNode.js +22 -15
  81. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  82. package/dist/summary/summarizerNode/summarizerNodeUtils.js +2 -4
  83. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  84. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +17 -16
  85. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  86. package/dist/summary/summaryCollection.js +3 -5
  87. package/dist/summary/summaryCollection.js.map +1 -1
  88. package/dist/summary/summaryFormat.js +1 -2
  89. package/dist/summary/summaryFormat.js.map +1 -1
  90. package/dist/summary/summaryGenerator.js +62 -20
  91. package/dist/summary/summaryGenerator.js.map +1 -1
  92. package/dist/summary/summaryManager.js +3 -5
  93. package/dist/summary/summaryManager.js.map +1 -1
  94. package/lib/batchTracker.d.ts +2 -1
  95. package/lib/batchTracker.d.ts.map +1 -1
  96. package/lib/batchTracker.js.map +1 -1
  97. package/lib/blobManager.d.ts +4 -1
  98. package/lib/blobManager.d.ts.map +1 -1
  99. package/lib/blobManager.js +61 -26
  100. package/lib/blobManager.js.map +1 -1
  101. package/lib/connectionTelemetry.js +10 -2
  102. package/lib/connectionTelemetry.js.map +1 -1
  103. package/lib/containerRuntime.d.ts +26 -11
  104. package/lib/containerRuntime.d.ts.map +1 -1
  105. package/lib/containerRuntime.js +177 -123
  106. package/lib/containerRuntime.js.map +1 -1
  107. package/lib/dataStore.js +8 -2
  108. package/lib/dataStore.js.map +1 -1
  109. package/lib/dataStoreContext.js +23 -24
  110. package/lib/dataStoreContext.js.map +1 -1
  111. package/lib/dataStores.d.ts +20 -4
  112. package/lib/dataStores.d.ts.map +1 -1
  113. package/lib/dataStores.js +107 -53
  114. package/lib/dataStores.js.map +1 -1
  115. package/lib/gc/garbageCollection.js +17 -20
  116. package/lib/gc/garbageCollection.js.map +1 -1
  117. package/lib/gc/gcConfigs.js +13 -11
  118. package/lib/gc/gcConfigs.js.map +1 -1
  119. package/lib/gc/gcHelpers.js +4 -6
  120. package/lib/gc/gcHelpers.js.map +1 -1
  121. package/lib/gc/gcSummaryStateTracker.js +4 -6
  122. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  123. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  124. package/lib/gc/gcTelemetry.js +55 -37
  125. package/lib/gc/gcTelemetry.js.map +1 -1
  126. package/lib/id-compressor/idCompressor.js +49 -51
  127. package/lib/id-compressor/idCompressor.js.map +1 -1
  128. package/lib/id-compressor/idRange.js +2 -2
  129. package/lib/id-compressor/idRange.js.map +1 -1
  130. package/lib/id-compressor/sessionIdNormalizer.js +11 -16
  131. package/lib/id-compressor/sessionIdNormalizer.js.map +1 -1
  132. package/lib/index.d.ts +1 -1
  133. package/lib/index.d.ts.map +1 -1
  134. package/lib/index.js.map +1 -1
  135. package/lib/opLifecycle/batchManager.js +10 -6
  136. package/lib/opLifecycle/batchManager.js.map +1 -1
  137. package/lib/opLifecycle/opCompressor.js +6 -1
  138. package/lib/opLifecycle/opCompressor.js.map +1 -1
  139. package/lib/opLifecycle/opDecompressor.js +11 -9
  140. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  141. package/lib/opLifecycle/opGroupingManager.js +13 -5
  142. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  143. package/lib/opLifecycle/opSplitter.js +10 -6
  144. package/lib/opLifecycle/opSplitter.js.map +1 -1
  145. package/lib/opLifecycle/outbox.js +1 -2
  146. package/lib/opLifecycle/outbox.js.map +1 -1
  147. package/lib/opLifecycle/remoteMessageProcessor.js +1 -1
  148. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  149. package/lib/opProperties.js +1 -2
  150. package/lib/opProperties.js.map +1 -1
  151. package/lib/packageVersion.d.ts +1 -1
  152. package/lib/packageVersion.js +1 -1
  153. package/lib/packageVersion.js.map +1 -1
  154. package/lib/pendingStateManager.d.ts +2 -2
  155. package/lib/pendingStateManager.d.ts.map +1 -1
  156. package/lib/pendingStateManager.js +22 -22
  157. package/lib/pendingStateManager.js.map +1 -1
  158. package/lib/scheduleManager.js +14 -10
  159. package/lib/scheduleManager.js.map +1 -1
  160. package/lib/summary/orderedClientElection.d.ts +2 -1
  161. package/lib/summary/orderedClientElection.d.ts.map +1 -1
  162. package/lib/summary/orderedClientElection.js +17 -18
  163. package/lib/summary/orderedClientElection.js.map +1 -1
  164. package/lib/summary/runningSummarizer.js +32 -38
  165. package/lib/summary/runningSummarizer.js.map +1 -1
  166. package/lib/summary/summarizer.js +4 -7
  167. package/lib/summary/summarizer.js.map +1 -1
  168. package/lib/summary/summarizerClientElection.js +5 -9
  169. package/lib/summary/summarizerClientElection.js.map +1 -1
  170. package/lib/summary/summarizerHeuristics.js +8 -12
  171. package/lib/summary/summarizerHeuristics.js.map +1 -1
  172. package/lib/summary/summarizerNode/summarizerNode.js +22 -15
  173. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  174. package/lib/summary/summarizerNode/summarizerNodeUtils.js +2 -4
  175. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  176. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +17 -16
  177. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  178. package/lib/summary/summaryCollection.js +3 -5
  179. package/lib/summary/summaryCollection.js.map +1 -1
  180. package/lib/summary/summaryFormat.js +1 -2
  181. package/lib/summary/summaryFormat.js.map +1 -1
  182. package/lib/summary/summaryGenerator.js +62 -20
  183. package/lib/summary/summaryGenerator.js.map +1 -1
  184. package/lib/summary/summaryManager.js +3 -5
  185. package/lib/summary/summaryManager.js.map +1 -1
  186. package/package.json +17 -17
  187. package/src/batchTracker.ts +2 -1
  188. package/src/blobManager.ts +43 -2
  189. package/src/containerRuntime.ts +74 -51
  190. package/src/dataStore.ts +7 -1
  191. package/src/dataStores.ts +95 -55
  192. package/src/gc/gcTelemetry.ts +1 -2
  193. package/src/index.ts +0 -1
  194. package/src/packageVersion.ts +1 -1
  195. package/src/pendingStateManager.ts +12 -15
  196. package/src/summary/orderedClientElection.ts +2 -1
@@ -1 +1 @@
1
- {"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../../src/summary/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EACN,iBAAiB,EAEjB,gBAAgB,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAKrE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,qBAAqB,GAAG,IAAI,CAAC;AACnC,MAAM,8BAA8B,GAAG,IAAI,CAAC;AAE5C,MAAM,CAAN,IAAY,mBAKX;AALD,WAAY,mBAAmB;IAC9B,2DAAO,CAAA;IACP,qEAAY,CAAA;IACZ,mEAAW,CAAA;IACX,qEAAY,CAAA;AACb,CAAC,EALW,mBAAmB,KAAnB,mBAAmB,QAK9B;AA0CD;;;;GAIG;AACH,MAAM,OAAO,cAAc;IAiB1B,YACkB,cAAyC,EACzC,cAA+B,EAC/B,iBAGhB,EACD,YAAkC;IAClC;2CACuC;IACtB,mBAA+C,EAC/C,cAA0B,EAC3C,EACC,cAAc,GAAG,qBAAqB,EACtC,uBAAuB,GAAG,8BAA8B,MACX,EAAE,EAC/B,iBAA2B;QAf3B,mBAAc,GAAd,cAAc,CAA2B;QACzC,mBAAc,GAAd,cAAc,CAAiB;QAC/B,sBAAiB,GAAjB,iBAAiB,CAGjC;QAIgB,wBAAmB,GAAnB,mBAAmB,CAA4B;QAC/C,mBAAc,GAAd,cAAc,CAAY;QAK1B,sBAAiB,GAAjB,iBAAiB,CAAU;QA5BrC,U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,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC5E,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC3D,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IACvB,CAAC;;AAxRuB,kCAAmB,GAAG,CAAC,KAA0B,EAAE,EAAE,CAC5E,KAAK,KAAK,mBAAmB,CAAC,QAAQ,IAAI,KAAK,KAAK,mBAAmB,CAAC,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider } from \"@fluidframework/common-definitions\";\nimport { IDisposable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tcreateChildLogger,\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { IThrottler } from \"../throttler\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { ISummarizer, SummarizerStopReason } from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\nimport { Summarizer } from \"./summarizer\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n\tOff = 0,\n\tStarting = 1,\n\tRunning = 2,\n\tStopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<\n\tSummarizerStopReason,\n\t\"parentNotConnected\" | \"notElectedParent\" | \"notElectedClient\"\n>;\ntype ShouldSummarizeState =\n\t| { shouldSummarize: true }\n\t| { shouldSummarize: false; stopReason: StopReason };\n\nexport interface IConnectedEvents extends IEvent {\n\t(event: \"connected\", listener: (clientId: string) => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n\treadonly connected: boolean;\n\n\t/**\n\t * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n\t * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n\t * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n\t * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n\t * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n\t */\n\treadonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n\tinitialDelayMs: number;\n\topsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager implements IDisposable {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly opsToBypassInitialDelay: number;\n\tprivate readonly initialDelayMs: number;\n\tprivate latestClientId: string | undefined;\n\tprivate state = SummaryManagerState.Off;\n\tprivate summarizer?: ISummarizer;\n\tprivate _disposed = false;\n\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\n\tpublic get currentState() {\n\t\treturn this.state;\n\t}\n\n\tconstructor(\n\t\tprivate readonly clientElection: ISummarizerClientElection,\n\t\tprivate readonly connectedState: IConnectedState,\n\t\tprivate readonly summaryCollection: Pick<\n\t\t\tSummaryCollection,\n\t\t\t\"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\"\n\t\t>,\n\t\tparentLogger: ITelemetryBaseLogger,\n\t\t/** Creates summarizer by asking interactive container to spawn summarizing container and\n\t\t * get back its Summarizer instance. */\n\t\tprivate readonly requestSummarizerFn: () => Promise<ISummarizer>,\n\t\tprivate readonly startThrottler: IThrottler,\n\t\t{\n\t\t\tinitialDelayMs = defaultInitialDelayMs,\n\t\t\topsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n\t\t}: Readonly<Partial<ISummaryManagerConfig>> = {},\n\t\tprivate readonly disableHeuristics?: boolean,\n\t) {\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: parentLogger,\n\t\t\tnamespace: \"SummaryManager\",\n\t\t\tproperties: {\n\t\t\t\tall: { clientId: () => this.latestClientId },\n\t\t\t},\n\t\t});\n\n\t\tthis.connectedState.on(\"connected\", this.handleConnected);\n\t\tthis.connectedState.on(\"disconnected\", this.handleDisconnected);\n\t\tthis.latestClientId = this.connectedState.clientId;\n\n\t\tthis.opsToBypassInitialDelay = opsToBypassInitialDelay;\n\t\tthis.initialDelayMs = initialDelayMs;\n\t}\n\n\t/**\n\t * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n\t * a window between construction and starting where the caller can attach listeners.\n\t */\n\tpublic start(): void {\n\t\tthis.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.refreshSummarizer();\n\t}\n\n\tprivate readonly handleConnected = (clientId: string) => {\n\t\tthis.latestClientId = clientId;\n\t\t// If we have a summarizer, it should have been either cancelled on disconnected by now.\n\t\t// But because of lastSummary process, it can still hang around, so there is not much we can\n\t\t// check or assert.\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate readonly handleDisconnected = () => {\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n\t\tstate === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n\tprivate getShouldSummarizeState(): ShouldSummarizeState {\n\t\t// Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n\t\t// enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n\t\t// only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n\t\t// changing the electedParent will just cause us to transition to Starting again.\n\n\t\t// New Parent has been elected and it is not the current client, or\n\t\tif (this.connectedState.clientId !== this.clientElection.electedParentId) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedParent\" };\n\t\t}\n\n\t\t// We are not already running the summarizer and we are not the current elected client id.\n\t\tif (\n\t\t\tthis.state !== SummaryManagerState.Running &&\n\t\t\tthis.connectedState.clientId !== this.clientElection.electedClientId\n\t\t) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedClient\" };\n\t\t}\n\n\t\tif (!this.connectedState.connected) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tassert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n\t\t} else {\n\t\t\treturn { shouldSummarize: true };\n\t\t}\n\t}\n\n\tprivate readonly refreshSummarizer = () => {\n\t\t// Transition states depending on shouldSummarize, which is a calculated property\n\t\t// that is only true if this client is connected and is the elected summarizer.\n\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\tswitch (this.state) {\n\t\t\tcase SummaryManagerState.Off: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Starting: {\n\t\t\t\t// Cannot take any action until summarizer is created\n\t\t\t\t// state transition will occur after creation\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Running: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\tthis.stop(shouldSummarizeState.stopReason);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Stopping: {\n\t\t\t\t// Cannot take any action until running summarizer finishes\n\t\t\t\t// state transition will occur after it stops\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate startSummarization() {\n\t\tassert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n\t\tthis.state = SummaryManagerState.Starting;\n\n\t\tassert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n\t\tthis.delayBeforeCreatingSummarizer()\n\t\t\t.then(async (startWithInitialDelay: boolean) => {\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// but only if creation was delayed. If it was not, then we want to ensure we always create\n\t\t\t\t// a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n\t\t\t\t// document out of broken state if it has too many ops and ordering service keeps nacking main\n\t\t\t\t// container (and thus it goes into cycle of reconnects)\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();\n\t\t\t\tif (\n\t\t\t\t\tstartWithInitialDelay &&\n\t\t\t\t\tshouldSummarizeStateEarlyStage.shouldSummarize === false\n\t\t\t\t) {\n\t\t\t\t\treturn `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;\n\t\t\t\t}\n\n\t\t\t\t// We transition to Running before requesting the summarizer, because after requesting we can't predict\n\t\t\t\t// when the electedClient will be replaced with the new summarizer client.\n\t\t\t\t// The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n\t\t\t\t// state === Starting || state === Running.\n\t\t\t\tassert(\n\t\t\t\t\tthis.state === SummaryManagerState.Starting,\n\t\t\t\t\t0x263 /* \"Expected: starting\" */,\n\t\t\t\t);\n\t\t\t\tthis.state = SummaryManagerState.Running;\n\n\t\t\t\tconst summarizer = await this.requestSummarizerFn();\n\t\t\t\tthis.summarizer = summarizer;\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\t// In order to allow the last summary to run, we not only need a stop reason that would\n\t\t\t\t\t// allow it but also, startWithInitialDelay to be false (start the summarization immediately),\n\t\t\t\t\t// which would happen when we have a high enough number of unsummarized ops.\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartWithInitialDelay ||\n\t\t\t\t\t\t!Summarizer.stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.state = SummaryManagerState.Starting;\n\t\t\t\t\t\tsummarizer.stop(shouldSummarizeState.stopReason);\n\t\t\t\t\t\treturn `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;\n\t\t\t\t\t}\n\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"LastAttemptToSummarize\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst clientId = this.latestClientId!;\n\n\t\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{ eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n\t\t\t\t\tasync () => summarizer.run(clientId, this.disableHeuristics),\n\t\t\t\t);\n\t\t\t})\n\t\t\t.then((reason: string) => {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\treason,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\t\treason: \"exception\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\t// Most of exceptions happen due to container being closed while loading it, due to\n\t\t\t\t// summarizer container loosing connection while load.\n\t\t\t\t// Not worth reporting such errors as errors. That said, we might miss some real errors if\n\t\t\t\t// we ignore blindly, so try to narrow signature we are looking for - skip logging\n\t\t\t\t// error only if this client should no longer be a summarizer (which in practice\n\t\t\t\t// means it also lost connection), and error happened on load (we do not have summarizer).\n\t\t\t\t// We could annotate the error raised in Container.load where the container closed during load with no error\n\t\t\t\t// and check for that case here, but that does not seem to be necessary.\n\t\t\t\tif (\n\t\t\t\t\tthis.getShouldSummarizeState().shouldSummarize ||\n\t\t\t\t\tthis.summarizer !== undefined\n\t\t\t\t) {\n\t\t\t\t\t// Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n\t\t\t\t\t// If failure happened on container load, we may not yet realized that socket disconnected, so check\n\t\t\t\t\t// offlineError.\n\t\t\t\t\tconst category =\n\t\t\t\t\t\terror?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizerException\",\n\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tassert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n\t\t\t\tthis.state = SummaryManagerState.Off;\n\n\t\t\t\tthis.summarizer?.close();\n\t\t\t\tthis.summarizer = undefined;\n\n\t\t\t\tif (this.getShouldSummarizeState().shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\tprivate stop(reason: SummarizerStopReason) {\n\t\tif (!SummaryManager.isStartingOrRunning(this.state)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.state = SummaryManagerState.Stopping;\n\n\t\t// Stopping the running summarizer client should trigger a change\n\t\t// in states when the running summarizer closes\n\t\tthis.summarizer?.stop(reason);\n\t}\n\n\t/**\n\t * Implements initial delay before creating summarizer\n\t * @returns `true`, if creation is delayed due to heuristics (not many ops to summarize).\n\t * `false` if summarizer should start immediately due to too many unsummarized ops.\n\t */\n\tprivate async delayBeforeCreatingSummarizer(): Promise<boolean> {\n\t\t// throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n\t\tlet delayMs = this.startThrottler.getDelay();\n\n\t\t// We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n\t\t// now we play it safe and launch a second copy.\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"CreatingSummarizer\",\n\t\t\tthrottlerDelay: delayMs,\n\t\t\tinitialDelay: this.initialDelayMs,\n\t\t\tstartThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n\t\t\topsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n\t\t\topsToBypassInitialDelay: this.opsToBypassInitialDelay,\n\t\t\telectedParentId: this.clientElection.electedParentId,\n\t\t\telectedClientId: this.clientElection.electedClientId,\n\t\t});\n\n\t\t// This delay helps ensure that last summarizer that might be left from previous client\n\t\t// has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n\t\t// If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n\t\t// understanding that we may see nacks because of such quick action.\n\t\t// A better design would be for summarizer election logic to always select current summarizer as\n\t\t// summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n\t\t// summarizer while it finishes its work and moves to exit.\n\t\t// It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n\t\t// critical boot sequence.\n\t\tlet startWithInitialDelay = false;\n\t\tif (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n\t\t\tstartWithInitialDelay = true;\n\t\t\tdelayMs = Math.max(delayMs, this.initialDelayMs);\n\t\t}\n\n\t\tif (delayMs > 0) {\n\t\t\tlet timer;\n\t\t\tlet resolveOpPromiseFn;\n\t\t\t// Create a listener that will break the delay if we've exceeded the initial delay ops count.\n\t\t\tconst opsListenerFn = () => {\n\t\t\t\tif (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolveOpPromiseFn();\n\t\t\t\t}\n\t\t\t};\n\t\t\t// Create a Promise that will resolve when the delay expires.\n\t\t\tconst delayPromise = new Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => resolve(), delayMs);\n\t\t\t});\n\t\t\t// Create a Promise that will resolve if the ops count passes the threshold.\n\t\t\tconst opPromise = new Promise<void>((resolve) => {\n\t\t\t\tresolveOpPromiseFn = resolve;\n\t\t\t});\n\t\t\tthis.summaryCollection.addOpListener(opsListenerFn);\n\t\t\tawait Promise.race([delayPromise, opPromise]);\n\t\t\tthis.summaryCollection.removeOpListener(opsListenerFn);\n\t\t}\n\t\treturn startWithInitialDelay;\n\t}\n\n\tpublic readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.summarizeOnDemand(...args);\n\t};\n\n\tpublic readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.enqueueSummarize(...args);\n\t};\n\n\tpublic dispose() {\n\t\tthis.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.connectedState.off(\"connected\", this.handleConnected);\n\t\tthis.connectedState.off(\"disconnected\", this.handleDisconnected);\n\t\tthis._disposed = true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"summaryManager.js","sourceRoot":"","sources":["../../src/summary/summaryManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,MAAM,EAAE,MA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O,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IEvent, IEventProvider } from \"@fluidframework/common-definitions\";\nimport { IDisposable, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport {\n\tcreateChildLogger,\n\tITelemetryLoggerExt,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport { DriverErrorType } from \"@fluidframework/driver-definitions\";\nimport { IThrottler } from \"../throttler\";\nimport { ISummarizerClientElection } from \"./summarizerClientElection\";\nimport { ISummarizer, SummarizerStopReason } from \"./summarizerTypes\";\nimport { SummaryCollection } from \"./summaryCollection\";\nimport { Summarizer } from \"./summarizer\";\n\nconst defaultInitialDelayMs = 5000;\nconst defaultOpsToBypassInitialDelay = 4000;\n\nexport enum SummaryManagerState {\n\tOff = 0,\n\tStarting = 1,\n\tRunning = 2,\n\tStopping = 3,\n}\n\n// Please note that all reasons in this list are not errors,\n// and thus they are not raised today to parent container as error.\n// If this needs to be changed in future, we should re-evaluate what and how we raise to summarizer\ntype StopReason = Extract<\n\tSummarizerStopReason,\n\t\"parentNotConnected\" | \"notElectedParent\" | \"notElectedClient\"\n>;\ntype ShouldSummarizeState =\n\t| { shouldSummarize: true }\n\t| { shouldSummarize: false; stopReason: StopReason };\n\nexport interface IConnectedEvents extends IEvent {\n\t(event: \"connected\", listener: (clientId: string) => void);\n\t(event: \"disconnected\", listener: () => void);\n}\n\n/**\n * IConnectedState describes an object that SummaryManager can watch to observe connection/disconnection.\n *\n * Under current implementation, its role will be fulfilled by the ContainerRuntime, but this could be replaced\n * with anything else that fulfills the contract if we want to shift the layer that the SummaryManager lives at.\n */\nexport interface IConnectedState extends IEventProvider<IConnectedEvents> {\n\treadonly connected: boolean;\n\n\t/**\n\t * Under current implementation this is undefined if we've never connected, otherwise it's the clientId from our\n\t * latest connection (even if we've since disconnected!). Although this happens to be the behavior we want in\n\t * SummaryManager, I suspect that globally we may eventually want to modify this behavior (e.g. make clientId\n\t * undefined while disconnected). To protect against this, let's assume this field can't be trusted while\n\t * disconnected and instead separately track \"latest clientId\" in SummaryManager.\n\t */\n\treadonly clientId: string | undefined;\n}\n\nexport interface ISummaryManagerConfig {\n\tinitialDelayMs: number;\n\topsToBypassInitialDelay: number;\n}\n\n/**\n * SummaryManager is created by parent container (i.e. interactive container with clientType !== \"summarizer\") only.\n * It observes changes in calculated summarizer and reacts to changes by either creating summarizer client or\n * stopping existing summarizer client.\n */\nexport class SummaryManager implements IDisposable {\n\tprivate readonly logger: ITelemetryLoggerExt;\n\tprivate readonly opsToBypassInitialDelay: number;\n\tprivate readonly initialDelayMs: number;\n\tprivate latestClientId: string | undefined;\n\tprivate state = SummaryManagerState.Off;\n\tprivate summarizer?: ISummarizer;\n\tprivate _disposed = false;\n\n\tpublic get disposed() {\n\t\treturn this._disposed;\n\t}\n\n\tpublic get currentState() {\n\t\treturn this.state;\n\t}\n\n\tconstructor(\n\t\tprivate readonly clientElection: ISummarizerClientElection,\n\t\tprivate readonly connectedState: IConnectedState,\n\t\tprivate readonly summaryCollection: Pick<\n\t\t\tSummaryCollection,\n\t\t\t\"opsSinceLastAck\" | \"addOpListener\" | \"removeOpListener\"\n\t\t>,\n\t\tparentLogger: ITelemetryBaseLogger,\n\t\t/** Creates summarizer by asking interactive container to spawn summarizing container and\n\t\t * get back its Summarizer instance. */\n\t\tprivate readonly requestSummarizerFn: () => Promise<ISummarizer>,\n\t\tprivate readonly startThrottler: IThrottler,\n\t\t{\n\t\t\tinitialDelayMs = defaultInitialDelayMs,\n\t\t\topsToBypassInitialDelay = defaultOpsToBypassInitialDelay,\n\t\t}: Readonly<Partial<ISummaryManagerConfig>> = {},\n\t\tprivate readonly disableHeuristics?: boolean,\n\t) {\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: parentLogger,\n\t\t\tnamespace: \"SummaryManager\",\n\t\t\tproperties: {\n\t\t\t\tall: { clientId: () => this.latestClientId },\n\t\t\t},\n\t\t});\n\n\t\tthis.connectedState.on(\"connected\", this.handleConnected);\n\t\tthis.connectedState.on(\"disconnected\", this.handleDisconnected);\n\t\tthis.latestClientId = this.connectedState.clientId;\n\n\t\tthis.opsToBypassInitialDelay = opsToBypassInitialDelay;\n\t\tthis.initialDelayMs = initialDelayMs;\n\t}\n\n\t/**\n\t * Until start is called, the SummaryManager won't begin attempting to start summarization. This ensures there's\n\t * a window between construction and starting where the caller can attach listeners.\n\t */\n\tpublic start(): void {\n\t\tthis.clientElection.on(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.refreshSummarizer();\n\t}\n\n\tprivate readonly handleConnected = (clientId: string) => {\n\t\tthis.latestClientId = clientId;\n\t\t// If we have a summarizer, it should have been either cancelled on disconnected by now.\n\t\t// But because of lastSummary process, it can still hang around, so there is not much we can\n\t\t// check or assert.\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate readonly handleDisconnected = () => {\n\t\tthis.refreshSummarizer();\n\t};\n\n\tprivate static readonly isStartingOrRunning = (state: SummaryManagerState) =>\n\t\tstate === SummaryManagerState.Starting || state === SummaryManagerState.Running;\n\n\tprivate getShouldSummarizeState(): ShouldSummarizeState {\n\t\t// Note that if we're in the Running state, the electedClient may be a summarizer client, so we can't\n\t\t// enforce connectedState.clientId === clientElection.electedClientId. But once we're Running, we should\n\t\t// only transition to Stopping when the electedParentId changes. Stopping the summarizer without\n\t\t// changing the electedParent will just cause us to transition to Starting again.\n\n\t\t// New Parent has been elected and it is not the current client, or\n\t\tif (this.connectedState.clientId !== this.clientElection.electedParentId) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedParent\" };\n\t\t}\n\n\t\t// We are not already running the summarizer and we are not the current elected client id.\n\t\tif (\n\t\t\tthis.state !== SummaryManagerState.Running &&\n\t\t\tthis.connectedState.clientId !== this.clientElection.electedClientId\n\t\t) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"notElectedClient\" };\n\t\t}\n\n\t\tif (!this.connectedState.connected) {\n\t\t\treturn { shouldSummarize: false, stopReason: \"parentNotConnected\" };\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tassert(false, 0x260 /* \"Disposed should mean disconnected!\" */);\n\t\t} else {\n\t\t\treturn { shouldSummarize: true };\n\t\t}\n\t}\n\n\tprivate readonly refreshSummarizer = () => {\n\t\t// Transition states depending on shouldSummarize, which is a calculated property\n\t\t// that is only true if this client is connected and is the elected summarizer.\n\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\tswitch (this.state) {\n\t\t\tcase SummaryManagerState.Off: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Starting: {\n\t\t\t\t// Cannot take any action until summarizer is created\n\t\t\t\t// state transition will occur after creation\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Running: {\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\tthis.stop(shouldSummarizeState.stopReason);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase SummaryManagerState.Stopping: {\n\t\t\t\t// Cannot take any action until running summarizer finishes\n\t\t\t\t// state transition will occur after it stops\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t};\n\n\tprivate startSummarization() {\n\t\tassert(this.state === SummaryManagerState.Off, 0x261 /* \"Expected: off\" */);\n\t\tthis.state = SummaryManagerState.Starting;\n\n\t\tassert(this.summarizer === undefined, 0x262 /* \"Old summarizer is still working!\" */);\n\n\t\tthis.delayBeforeCreatingSummarizer()\n\t\t\t.then(async (startWithInitialDelay: boolean) => {\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// but only if creation was delayed. If it was not, then we want to ensure we always create\n\t\t\t\t// a summarizer to kick off lastSummary. Without that, we would not be able to summarize and get\n\t\t\t\t// document out of broken state if it has too many ops and ordering service keeps nacking main\n\t\t\t\t// container (and thus it goes into cycle of reconnects)\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeStateEarlyStage = this.getShouldSummarizeState();\n\t\t\t\tif (\n\t\t\t\t\tstartWithInitialDelay &&\n\t\t\t\t\tshouldSummarizeStateEarlyStage.shouldSummarize === false\n\t\t\t\t) {\n\t\t\t\t\treturn `early exit ${shouldSummarizeStateEarlyStage.stopReason}`;\n\t\t\t\t}\n\n\t\t\t\t// We transition to Running before requesting the summarizer, because after requesting we can't predict\n\t\t\t\t// when the electedClient will be replaced with the new summarizer client.\n\t\t\t\t// The alternative would be to let connectedState.clientId !== clientElection.electedClientId when\n\t\t\t\t// state === Starting || state === Running.\n\t\t\t\tassert(\n\t\t\t\t\tthis.state === SummaryManagerState.Starting,\n\t\t\t\t\t0x263 /* \"Expected: starting\" */,\n\t\t\t\t);\n\t\t\t\tthis.state = SummaryManagerState.Running;\n\n\t\t\t\tconst summarizer = await this.requestSummarizerFn();\n\t\t\t\tthis.summarizer = summarizer;\n\n\t\t\t\t// Re-validate that it need to be running. Due to asynchrony, it may be not the case anymore\n\t\t\t\t// If we can't run the LastSummary, simply return as to avoid paying the cost of launching\n\t\t\t\t// the summarizer at all.\n\t\t\t\tconst shouldSummarizeState = this.getShouldSummarizeState();\n\t\t\t\tif (shouldSummarizeState.shouldSummarize === false) {\n\t\t\t\t\t// In order to allow the last summary to run, we not only need a stop reason that would\n\t\t\t\t\t// allow it but also, startWithInitialDelay to be false (start the summarization immediately),\n\t\t\t\t\t// which would happen when we have a high enough number of unsummarized ops.\n\t\t\t\t\tif (\n\t\t\t\t\t\tstartWithInitialDelay ||\n\t\t\t\t\t\t!Summarizer.stopReasonCanRunLastSummary(shouldSummarizeState.stopReason)\n\t\t\t\t\t) {\n\t\t\t\t\t\tthis.state = SummaryManagerState.Starting;\n\t\t\t\t\t\tsummarizer.stop(shouldSummarizeState.stopReason);\n\t\t\t\t\t\treturn `early exit after starting summarizer ${shouldSummarizeState.stopReason}`;\n\t\t\t\t\t}\n\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"LastAttemptToSummarize\",\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst clientId = this.latestClientId!;\n\n\t\t\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\t\t\tthis.logger,\n\t\t\t\t\t{ eventName: \"RunningSummarizer\", attempt: this.startThrottler.numAttempts },\n\t\t\t\t\tasync () => summarizer.run(clientId, this.disableHeuristics),\n\t\t\t\t);\n\t\t\t})\n\t\t\t.then((reason: string) => {\n\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\treason,\n\t\t\t\t});\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t{\n\t\t\t\t\t\teventName: \"EndingSummarizer\",\n\t\t\t\t\t\treason: \"exception\",\n\t\t\t\t\t},\n\t\t\t\t\terror,\n\t\t\t\t);\n\n\t\t\t\t// Most of exceptions happen due to container being closed while loading it, due to\n\t\t\t\t// summarizer container loosing connection while load.\n\t\t\t\t// Not worth reporting such errors as errors. That said, we might miss some real errors if\n\t\t\t\t// we ignore blindly, so try to narrow signature we are looking for - skip logging\n\t\t\t\t// error only if this client should no longer be a summarizer (which in practice\n\t\t\t\t// means it also lost connection), and error happened on load (we do not have summarizer).\n\t\t\t\t// We could annotate the error raised in Container.load where the container closed during load with no error\n\t\t\t\t// and check for that case here, but that does not seem to be necessary.\n\t\t\t\tif (\n\t\t\t\t\tthis.getShouldSummarizeState().shouldSummarize ||\n\t\t\t\t\tthis.summarizer !== undefined\n\t\t\t\t) {\n\t\t\t\t\t// Report any failure as an error unless it was due to cancellation (like \"disconnected\" error)\n\t\t\t\t\t// If failure happened on container load, we may not yet realized that socket disconnected, so check\n\t\t\t\t\t// offlineError.\n\t\t\t\t\tconst category =\n\t\t\t\t\t\terror?.errorType === DriverErrorType.offlineError ? \"generic\" : \"error\";\n\t\t\t\t\tthis.logger.sendTelemetryEvent(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\teventName: \"SummarizerException\",\n\t\t\t\t\t\t\tcategory,\n\t\t\t\t\t\t},\n\t\t\t\t\t\terror,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tassert(this.state !== SummaryManagerState.Off, 0x264 /* \"Expected: Not Off\" */);\n\t\t\t\tthis.state = SummaryManagerState.Off;\n\n\t\t\t\tthis.summarizer?.close();\n\t\t\t\tthis.summarizer = undefined;\n\n\t\t\t\tif (this.getShouldSummarizeState().shouldSummarize) {\n\t\t\t\t\tthis.startSummarization();\n\t\t\t\t}\n\t\t\t});\n\t}\n\n\tprivate stop(reason: SummarizerStopReason) {\n\t\tif (!SummaryManager.isStartingOrRunning(this.state)) {\n\t\t\treturn;\n\t\t}\n\t\tthis.state = SummaryManagerState.Stopping;\n\n\t\t// Stopping the running summarizer client should trigger a change\n\t\t// in states when the running summarizer closes\n\t\tthis.summarizer?.stop(reason);\n\t}\n\n\t/**\n\t * Implements initial delay before creating summarizer\n\t * @returns `true`, if creation is delayed due to heuristics (not many ops to summarize).\n\t * `false` if summarizer should start immediately due to too many unsummarized ops.\n\t */\n\tprivate async delayBeforeCreatingSummarizer(): Promise<boolean> {\n\t\t// throttle creation of new summarizer containers to prevent spamming the server with websocket connections\n\t\tlet delayMs = this.startThrottler.getDelay();\n\n\t\t// We have been elected the summarizer. Some day we may be able to summarize with a live document but for\n\t\t// now we play it safe and launch a second copy.\n\t\tthis.logger.sendTelemetryEvent({\n\t\t\teventName: \"CreatingSummarizer\",\n\t\t\tthrottlerDelay: delayMs,\n\t\t\tinitialDelay: this.initialDelayMs,\n\t\t\tstartThrottlerMaxDelayMs: this.startThrottler.maxDelayMs,\n\t\t\topsSinceLastAck: this.summaryCollection.opsSinceLastAck,\n\t\t\topsToBypassInitialDelay: this.opsToBypassInitialDelay,\n\t\t\telectedParentId: this.clientElection.electedParentId,\n\t\t\telectedClientId: this.clientElection.electedClientId,\n\t\t});\n\n\t\t// This delay helps ensure that last summarizer that might be left from previous client\n\t\t// has enough time to complete its last summary and thus new summarizer not conflict with previous one.\n\t\t// If, however, there are too many unsummarized ops, try to resolve it as quickly as possible, with\n\t\t// understanding that we may see nacks because of such quick action.\n\t\t// A better design would be for summarizer election logic to always select current summarizer as\n\t\t// summarizing client (i.e. clientType === \"summarizer\" can be elected) to ensure that nobody else can\n\t\t// summarizer while it finishes its work and moves to exit.\n\t\t// It also helps with pure boot scenario (single client) to offset expensive work a bit out from\n\t\t// critical boot sequence.\n\t\tlet startWithInitialDelay = false;\n\t\tif (this.summaryCollection.opsSinceLastAck < this.opsToBypassInitialDelay) {\n\t\t\tstartWithInitialDelay = true;\n\t\t\tdelayMs = Math.max(delayMs, this.initialDelayMs);\n\t\t}\n\n\t\tif (delayMs > 0) {\n\t\t\tlet timer;\n\t\t\tlet resolveOpPromiseFn;\n\t\t\t// Create a listener that will break the delay if we've exceeded the initial delay ops count.\n\t\t\tconst opsListenerFn = () => {\n\t\t\t\tif (this.summaryCollection.opsSinceLastAck >= this.opsToBypassInitialDelay) {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolveOpPromiseFn();\n\t\t\t\t}\n\t\t\t};\n\t\t\t// Create a Promise that will resolve when the delay expires.\n\t\t\tconst delayPromise = new Promise<void>((resolve) => {\n\t\t\t\ttimer = setTimeout(() => resolve(), delayMs);\n\t\t\t});\n\t\t\t// Create a Promise that will resolve if the ops count passes the threshold.\n\t\t\tconst opPromise = new Promise<void>((resolve) => {\n\t\t\t\tresolveOpPromiseFn = resolve;\n\t\t\t});\n\t\t\tthis.summaryCollection.addOpListener(opsListenerFn);\n\t\t\tawait Promise.race([delayPromise, opPromise]);\n\t\t\tthis.summaryCollection.removeOpListener(opsListenerFn);\n\t\t}\n\t\treturn startWithInitialDelay;\n\t}\n\n\tpublic readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.summarizeOnDemand(...args);\n\t};\n\n\tpublic readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n\t\tif (this.summarizer === undefined) {\n\t\t\tthrow Error(\"No running summarizer client\");\n\t\t\t// TODO: could spawn a summarizer client temporarily.\n\t\t}\n\t\treturn this.summarizer.enqueueSummarize(...args);\n\t};\n\n\tpublic dispose() {\n\t\tthis.clientElection.off(\"electedSummarizerChanged\", this.refreshSummarizer);\n\t\tthis.connectedState.off(\"connected\", this.handleConnected);\n\t\tthis.connectedState.off(\"disconnected\", this.handleDisconnected);\n\t\tthis._disposed = true;\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/container-runtime",
3
- "version": "2.0.0-internal.5.4.2",
3
+ "version": "2.0.0-internal.6.0.1",
4
4
  "description": "Fluid container runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -37,18 +37,18 @@
37
37
  "dependencies": {
38
38
  "@fluidframework/common-definitions": "^0.20.1",
39
39
  "@fluidframework/common-utils": "^1.1.1",
40
- "@fluidframework/container-definitions": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
41
- "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
42
- "@fluidframework/container-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
43
- "@fluidframework/core-interfaces": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
44
- "@fluidframework/core-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
45
- "@fluidframework/datastore": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
46
- "@fluidframework/driver-definitions": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
47
- "@fluidframework/driver-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
40
+ "@fluidframework/container-definitions": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
41
+ "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
42
+ "@fluidframework/container-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
43
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
44
+ "@fluidframework/core-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
45
+ "@fluidframework/datastore": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
46
+ "@fluidframework/driver-definitions": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
47
+ "@fluidframework/driver-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
48
48
  "@fluidframework/protocol-definitions": "^1.1.0",
49
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
50
- "@fluidframework/runtime-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
51
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
49
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
50
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
51
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
52
52
  "double-ended-queue": "^2.1.0-0",
53
53
  "events": "^3.1.0",
54
54
  "lz4js": "^0.2.0",
@@ -56,15 +56,15 @@
56
56
  "uuid": "^8.3.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
59
+ "@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
60
60
  "@fluid-tools/benchmark": "^0.48.0",
61
61
  "@fluid-tools/build-cli": "^0.21.0",
62
- "@fluidframework/build-common": "^1.2.0",
62
+ "@fluidframework/build-common": "^2.0.0",
63
63
  "@fluidframework/build-tools": "^0.21.0",
64
- "@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@2.0.0-internal.5.2.0",
64
+ "@fluidframework/container-runtime-previous": "npm:@fluidframework/container-runtime@2.0.0-internal.6.0.0",
65
65
  "@fluidframework/eslint-config-fluid": "^2.0.0",
66
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
67
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.5.4.2 <2.0.0-internal.5.5.0",
66
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
67
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.0.1 <2.0.0-internal.6.1.0",
68
68
  "@microsoft/api-extractor": "^7.34.4",
69
69
  "@types/double-ended-queue": "^2.1.0",
70
70
  "@types/events": "^3.0.0",
@@ -7,6 +7,7 @@ import { EventEmitter } from "events";
7
7
  import { ITelemetryLoggerExt, createChildLogger } from "@fluidframework/telemetry-utils";
8
8
  import { assert, performance } from "@fluidframework/common-utils";
9
9
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
10
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
10
11
 
11
12
  export class BatchTracker {
12
13
  private readonly logger: ITelemetryLoggerExt;
@@ -16,7 +17,7 @@ export class BatchTracker {
16
17
 
17
18
  constructor(
18
19
  private readonly batchEventEmitter: EventEmitter,
19
- logger: ITelemetryLoggerExt,
20
+ logger: ITelemetryBaseLogger,
20
21
  batchLengthThreshold: number,
21
22
  batchCountSamplingRate: number,
22
23
  dateTimeProvider: () => number = () => performance.now(),
@@ -150,6 +150,7 @@ interface PendingBlob {
150
150
  export interface IPendingBlobs {
151
151
  [id: string]: {
152
152
  blob: string;
153
+ storageId?: string;
153
154
  uploadTime?: number;
154
155
  minTTLInSeconds?: number;
155
156
  attached?: boolean;
@@ -253,6 +254,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
253
254
  const blob = stringToBuffer(entry.blob, "base64");
254
255
  const attached = entry.attached;
255
256
  const acked = entry.acked;
257
+ const storageId = entry.storageId; // entry.storageId = response.id
256
258
  if (entry.minTTLInSeconds && entry.uploadTime) {
257
259
  const timeLapseSinceLocalUpload = (Date.now() - entry.uploadTime) / 1000;
258
260
  // stashed entries with more than half-life in storage will not be reuploaded
@@ -261,6 +263,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
261
263
  blob,
262
264
  status: PendingBlobStatus.OfflinePendingOp,
263
265
  handleP: new Deferred(),
266
+ storageId,
264
267
  uploadP: undefined,
265
268
  uploadTime: entry.uploadTime,
266
269
  minTTLInSeconds: entry.minTTLInSeconds,
@@ -327,6 +330,15 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
327
330
  return this.pendingOfflineUploads.length > 0;
328
331
  }
329
332
 
333
+ public get allBlobsAttached(): boolean {
334
+ for (const [, entry] of this.pendingBlobs) {
335
+ if (entry.attached === false) {
336
+ return false;
337
+ }
338
+ }
339
+ return true;
340
+ }
341
+
330
342
  public get hasPendingBlobs(): boolean {
331
343
  return (
332
344
  (this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||
@@ -372,6 +384,28 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
372
384
  }
373
385
  }
374
386
 
387
+ private async shutdownPendingBlobs(): Promise<void> {
388
+ for (const [localId, entry] of this.pendingBlobs) {
389
+ if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
390
+ this.sendBlobAttachOp(localId, entry.storageId);
391
+ entry.status = PendingBlobStatus.OfflinePendingUpload;
392
+ entry.handleP.resolve(this.getBlobHandle(localId));
393
+ } else if (entry.status === PendingBlobStatus.OnlinePendingOp) {
394
+ entry.status = PendingBlobStatus.OfflinePendingOp;
395
+ entry.handleP.resolve(this.getBlobHandle(localId));
396
+ }
397
+ }
398
+ return new Promise<void>((resolve) => {
399
+ if (this.allBlobsAttached) {
400
+ resolve();
401
+ } else {
402
+ this.once("allBlobsAttached", () => {
403
+ resolve();
404
+ });
405
+ }
406
+ });
407
+ }
408
+
375
409
  /**
376
410
  * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is
377
411
  * detached or there are no (non-pending) attachment blobs in the document
@@ -438,6 +472,9 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
438
472
  ? () => {
439
473
  pending.attached = true;
440
474
  this.deletePendingBlobMaybe(id);
475
+ if (this.allBlobsAttached) {
476
+ this.emit("allBlobsAttached");
477
+ }
441
478
  }
442
479
  : undefined;
443
480
  return new BlobHandle(
@@ -672,7 +709,7 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
672
709
  !!pendingEntry?.storageId,
673
710
  0x38d /* blob must be uploaded before resubmitting BlobAttach op */,
674
711
  );
675
- return this.sendBlobAttachOp(localId, pendingEntry.storageId);
712
+ return this.sendBlobAttachOp(localId, pendingEntry?.storageId);
676
713
  }
677
714
  return this.sendBlobAttachOp(localId, blobId);
678
715
  }
@@ -1000,11 +1037,15 @@ export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
1000
1037
  }
1001
1038
  }
1002
1039
 
1003
- public getPendingBlobs(): IPendingBlobs {
1040
+ public async getPendingBlobs(waitBlobsToAttach?: boolean): Promise<IPendingBlobs> {
1041
+ if (waitBlobsToAttach) {
1042
+ await this.shutdownPendingBlobs();
1043
+ }
1004
1044
  const blobs = {};
1005
1045
  for (const [key, entry] of this.pendingBlobs) {
1006
1046
  blobs[key] = {
1007
1047
  blob: bufferToString(entry.blob, "base64"),
1048
+ storageId: entry.storageId,
1008
1049
  attached: entry.attached,
1009
1050
  acked: entry.acked,
1010
1051
  minTTLInSeconds: entry.minTTLInSeconds,
@@ -445,14 +445,6 @@ export interface IContainerRuntimeOptions {
445
445
  readonly enableGroupedBatching?: boolean;
446
446
  }
447
447
 
448
- /**
449
- * The summary tree returned by the root node. It adds state relevant to the root of the tree.
450
- */
451
- export interface IRootSummaryTreeWithStats extends ISummaryTreeWithStats {
452
- /** The garbage collection stats if GC ran, undefined otherwise. */
453
- gcStats?: IGCStats;
454
- }
455
-
456
448
  /**
457
449
  * Accepted header keys for requests coming to the runtime.
458
450
  */
@@ -616,6 +608,9 @@ export class ContainerRuntime
616
608
  extends TypedEventEmitter<IContainerRuntimeEvents>
617
609
  implements IContainerRuntime, IRuntime, ISummarizerRuntime, ISummarizerInternalsProvider
618
610
  {
611
+ /**
612
+ * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
613
+ */
619
614
  public get IFluidRouter() {
620
615
  return this;
621
616
  }
@@ -743,8 +738,6 @@ export class ContainerRuntime
743
738
  tryFetchBlob<SerializedIdCompressorWithNoSession>(idCompressorBlobName),
744
739
  ]);
745
740
 
746
- const loadExisting = existing === true || context.existing === true;
747
-
748
741
  // read snapshot blobs needed for BlobManager to load
749
742
  const blobManagerSnapshot = await BlobManager.load(
750
743
  context.baseSnapshot?.trees[blobsTreeName],
@@ -779,9 +772,7 @@ export class ContainerRuntime
779
772
  if (loadSequenceNumberVerification === "log") {
780
773
  logger.sendErrorEvent({ eventName: "SequenceNumberMismatch" }, error);
781
774
  } else {
782
- // Call both close and dispose as closeFn implementation will no longer dispose runtime in future
783
775
  context.closeFn(error);
784
- context.disposeFn?.(error);
785
776
  }
786
777
  }
787
778
  }
@@ -818,7 +809,7 @@ export class ContainerRuntime
818
809
  },
819
810
  containerScope,
820
811
  logger,
821
- loadExisting,
812
+ existing,
822
813
  blobManagerSnapshot,
823
814
  context.storage,
824
815
  idCompressor,
@@ -1178,13 +1169,7 @@ export class ContainerRuntime
1178
1169
  // In old loaders without dispose functionality, closeFn is equivalent but will also switch container to readonly mode
1179
1170
  this.disposeFn = disposeFn ?? closeFn;
1180
1171
  // In cases of summarizer, we want to dispose instead since consumer doesn't interact with this container
1181
- this.closeFn = this.isSummarizerClient
1182
- ? this.disposeFn
1183
- : (error?: ICriticalContainerError) => {
1184
- closeFn(error);
1185
- // Also call disposeFn to retain functionality of runtime being disposed on close
1186
- disposeFn?.(error);
1187
- };
1172
+ this.closeFn = this.isSummarizerClient ? this.disposeFn : closeFn;
1188
1173
 
1189
1174
  this.mc = createChildMonitoringContext({
1190
1175
  logger: this.logger,
@@ -1693,6 +1678,7 @@ export class ContainerRuntime
1693
1678
  /**
1694
1679
  * Notifies this object about the request made to the container.
1695
1680
  * @param request - Request made to the handler.
1681
+ * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
1696
1682
  */
1697
1683
  public async request(request: IRequest): Promise<IResponse> {
1698
1684
  try {
@@ -2274,6 +2260,12 @@ export class ContainerRuntime
2274
2260
  this.dataStores.processSignal(envelope.address, transformed, local);
2275
2261
  }
2276
2262
 
2263
+ /**
2264
+ * Returns the runtime of the data store.
2265
+ * @param id - Id supplied during creating the data store.
2266
+ * @param wait - True if you want to wait for it.
2267
+ * @deprecated - Use getAliasedDataStoreEntryPoint instead to get an aliased data store's entry point.
2268
+ */
2277
2269
  public async getRootDataStore(id: string, wait = true): Promise<IFluidRouter> {
2278
2270
  return this.getRootDataStoreChannel(id, wait);
2279
2271
  }
@@ -2349,15 +2341,30 @@ export class ContainerRuntime
2349
2341
  return result;
2350
2342
  }
2351
2343
 
2352
- public async createDataStore(pkg: string | string[]): Promise<IDataStore> {
2353
- const internalId = uuid();
2354
- return channelToDataStore(
2355
- await this._createDataStore(pkg, internalId),
2356
- internalId,
2357
- this,
2358
- this.dataStores,
2359
- this.mc.logger,
2360
- );
2344
+ /**
2345
+ * Returns the aliased data store's entryPoint, given the alias.
2346
+ * @param alias - The alias for the data store.
2347
+ * @returns - The data store's entry point (IFluidHandle) if it exists and is aliased. Returns undefined if no
2348
+ * data store has been assigned the given alias.
2349
+ */
2350
+ public async getAliasedDataStoreEntryPoint(
2351
+ alias: string,
2352
+ ): Promise<IFluidHandle<FluidObject> | undefined> {
2353
+ await this.dataStores.waitIfPendingAlias(alias);
2354
+ const internalId = this.internalId(alias);
2355
+ const context = await this.dataStores.getDataStoreIfAvailable(internalId, { wait: false });
2356
+ // If the data store is not available or not an alias, return undefined.
2357
+ if (context === undefined || !(await context.isRoot())) {
2358
+ return undefined;
2359
+ }
2360
+
2361
+ const channel = await context.realize();
2362
+ if (channel.entryPoint === undefined) {
2363
+ throw new UsageError(
2364
+ "entryPoint must be defined on data store runtime for using getAliasedDataStoreEntryPoint",
2365
+ );
2366
+ }
2367
+ return channel.entryPoint;
2361
2368
  }
2362
2369
 
2363
2370
  public createDetachedRootDataStore(
@@ -2374,25 +2381,37 @@ export class ContainerRuntime
2374
2381
  return this.dataStores.createDetachedDataStoreCore(pkg, false);
2375
2382
  }
2376
2383
 
2384
+ public async createDataStore(pkg: string | string[]): Promise<IDataStore> {
2385
+ const id = uuid();
2386
+ return channelToDataStore(
2387
+ await this.dataStores
2388
+ ._createFluidDataStoreContext(Array.isArray(pkg) ? pkg : [pkg], id)
2389
+ .realize(),
2390
+ id,
2391
+ this,
2392
+ this.dataStores,
2393
+ this.mc.logger,
2394
+ );
2395
+ }
2396
+
2397
+ /**
2398
+ * @deprecated 0.16 Issue #1537, #3631
2399
+ * @internal
2400
+ */
2377
2401
  public async _createDataStoreWithProps(
2378
2402
  pkg: string | string[],
2379
2403
  props?: any,
2380
2404
  id = uuid(),
2381
2405
  ): Promise<IDataStore> {
2382
- const fluidDataStore = await this.dataStores
2383
- ._createFluidDataStoreContext(Array.isArray(pkg) ? pkg : [pkg], id, props)
2384
- .realize();
2385
- return channelToDataStore(fluidDataStore, id, this, this.dataStores, this.mc.logger);
2386
- }
2387
-
2388
- private async _createDataStore(
2389
- pkg: string | string[],
2390
- id = uuid(),
2391
- props?: any,
2392
- ): Promise<IFluidDataStoreChannel> {
2393
- return this.dataStores
2394
- ._createFluidDataStoreContext(Array.isArray(pkg) ? pkg : [pkg], id, props)
2395
- .realize();
2406
+ return channelToDataStore(
2407
+ await this.dataStores
2408
+ ._createFluidDataStoreContext(Array.isArray(pkg) ? pkg : [pkg], id, props)
2409
+ .realize(),
2410
+ id,
2411
+ this,
2412
+ this.dataStores,
2413
+ this.mc.logger,
2414
+ );
2396
2415
  }
2397
2416
 
2398
2417
  private canSendOps() {
@@ -2573,7 +2592,7 @@ export class ContainerRuntime
2573
2592
  fullGC?: boolean;
2574
2593
  /** True to run GC sweep phase after the mark phase */
2575
2594
  runSweep?: boolean;
2576
- }): Promise<IRootSummaryTreeWithStats> {
2595
+ }): Promise<ISummaryTreeWithStats> {
2577
2596
  this.verifyNotClosed();
2578
2597
 
2579
2598
  const {
@@ -2596,9 +2615,8 @@ export class ContainerRuntime
2596
2615
  });
2597
2616
 
2598
2617
  try {
2599
- let gcStats: IGCStats | undefined;
2600
2618
  if (runGC) {
2601
- gcStats = await this.collectGarbage(
2619
+ await this.collectGarbage(
2602
2620
  { logger: summaryLogger, runSweep, fullGC },
2603
2621
  telemetryContext,
2604
2622
  );
@@ -2615,7 +2633,7 @@ export class ContainerRuntime
2615
2633
  0x12f /* "Container Runtime's summarize should always return a tree" */,
2616
2634
  );
2617
2635
 
2618
- return { stats, summary, gcStats };
2636
+ return { stats, summary };
2619
2637
  } finally {
2620
2638
  this.mc.logger.sendTelemetryEvent({
2621
2639
  eventName: "SummarizeTelemetry",
@@ -2915,7 +2933,7 @@ export class ContainerRuntime
2915
2933
  }
2916
2934
 
2917
2935
  const trace = Trace.start();
2918
- let summarizeResult: IRootSummaryTreeWithStats;
2936
+ let summarizeResult: ISummaryTreeWithStats;
2919
2937
  // If the GC state needs to be reset, we need to force a full tree summary and update the unreferenced
2920
2938
  // state of all the nodes.
2921
2939
  const forcedFullTree = this.garbageCollector.summaryStateNeedsReset;
@@ -3516,7 +3534,7 @@ export class ContainerRuntime
3516
3534
  fetchedSnapshotRefSeq: fetchResult.latestSnapshotRefSeq,
3517
3535
  },
3518
3536
  );
3519
- this.closeFn(error);
3537
+ this.disposeFn(error);
3520
3538
  throw error;
3521
3539
  }
3522
3540
 
@@ -3678,10 +3696,15 @@ export class ContainerRuntime
3678
3696
 
3679
3697
  public notifyAttaching() {} // do nothing (deprecated method)
3680
3698
 
3681
- public getPendingLocalState(): unknown {
3699
+ public async getPendingLocalState(props?: {
3700
+ notifyImminentClosure: boolean;
3701
+ }): Promise<unknown> {
3702
+ this.verifyNotClosed();
3703
+ const waitBlobsToAttach = props?.notifyImminentClosure;
3682
3704
  if (this._orderSequentiallyCalls !== 0) {
3683
3705
  throw new UsageError("can't get state during orderSequentially");
3684
3706
  }
3707
+ const pendingAttachmentBlobs = await this.blobManager.getPendingBlobs(waitBlobsToAttach);
3685
3708
  // Flush pending batch.
3686
3709
  // getPendingLocalState() is only exposed through Container.closeAndGetPendingLocalState(), so it's safe
3687
3710
  // to close current batch.
@@ -3689,7 +3712,7 @@ export class ContainerRuntime
3689
3712
 
3690
3713
  return {
3691
3714
  pending: this.pendingStateManager.getLocalState(),
3692
- pendingAttachmentBlobs: this.blobManager.getPendingBlobs(),
3715
+ pendingAttachmentBlobs,
3693
3716
  };
3694
3717
  }
3695
3718
 
package/src/dataStore.ts CHANGED
@@ -161,7 +161,10 @@ class DataStore implements IDataStore {
161
161
  return "Success";
162
162
  }
163
163
 
164
- async request(request: IRequest): Promise<IResponse> {
164
+ /**
165
+ * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
166
+ */
167
+ public async request(request: IRequest): Promise<IResponse> {
165
168
  return this.fluidDataStoreChannel.request(request);
166
169
  }
167
170
 
@@ -182,6 +185,9 @@ class DataStore implements IDataStore {
182
185
  this.pendingAliases = datastores.pendingAliases;
183
186
  }
184
187
 
188
+ /**
189
+ * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
190
+ */
185
191
  public get IFluidRouter() {
186
192
  return this.fluidDataStoreChannel;
187
193
  }