@fluidframework/container-runtime 2.1.0 → 2.2.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 (196) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +2 -2
  3. package/api-report/container-runtime.legacy.alpha.api.md +4 -3
  4. package/container-runtime.test-files.tar +0 -0
  5. package/dist/batchTracker.d.ts.map +1 -1
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager/blobManager.d.ts.map +1 -1
  8. package/dist/blobManager/blobManager.js +9 -0
  9. package/dist/blobManager/blobManager.js.map +1 -1
  10. package/dist/channelCollection.d.ts +0 -14
  11. package/dist/channelCollection.d.ts.map +1 -1
  12. package/dist/channelCollection.js +2 -12
  13. package/dist/channelCollection.js.map +1 -1
  14. package/dist/containerRuntime.d.ts +34 -6
  15. package/dist/containerRuntime.d.ts.map +1 -1
  16. package/dist/containerRuntime.js +176 -81
  17. package/dist/containerRuntime.js.map +1 -1
  18. package/dist/dataStoreContext.d.ts +9 -18
  19. package/dist/dataStoreContext.d.ts.map +1 -1
  20. package/dist/dataStoreContext.js +40 -78
  21. package/dist/dataStoreContext.js.map +1 -1
  22. package/dist/gc/garbageCollection.d.ts +0 -6
  23. package/dist/gc/garbageCollection.d.ts.map +1 -1
  24. package/dist/gc/garbageCollection.js +23 -66
  25. package/dist/gc/garbageCollection.js.map +1 -1
  26. package/dist/gc/gcConfigs.d.ts.map +1 -1
  27. package/dist/gc/gcConfigs.js +11 -34
  28. package/dist/gc/gcConfigs.js.map +1 -1
  29. package/dist/gc/gcDefinitions.d.ts +9 -52
  30. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  31. package/dist/gc/gcDefinitions.js +3 -23
  32. package/dist/gc/gcDefinitions.js.map +1 -1
  33. package/dist/gc/gcHelpers.d.ts.map +1 -1
  34. package/dist/gc/gcHelpers.js +2 -6
  35. package/dist/gc/gcHelpers.js.map +1 -1
  36. package/dist/gc/gcSummaryStateTracker.d.ts +1 -1
  37. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  38. package/dist/gc/gcSummaryStateTracker.js +4 -8
  39. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  40. package/dist/gc/gcTelemetry.d.ts +1 -9
  41. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  42. package/dist/gc/gcTelemetry.js +3 -25
  43. package/dist/gc/gcTelemetry.js.map +1 -1
  44. package/dist/gc/index.d.ts +2 -2
  45. package/dist/gc/index.d.ts.map +1 -1
  46. package/dist/gc/index.js +2 -7
  47. package/dist/gc/index.js.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -2
  51. package/dist/index.js.map +1 -1
  52. package/dist/messageTypes.d.ts +6 -5
  53. package/dist/messageTypes.d.ts.map +1 -1
  54. package/dist/messageTypes.js.map +1 -1
  55. package/dist/metadata.d.ts +9 -1
  56. package/dist/metadata.d.ts.map +1 -1
  57. package/dist/metadata.js +6 -1
  58. package/dist/metadata.js.map +1 -1
  59. package/dist/opLifecycle/index.d.ts +1 -1
  60. package/dist/opLifecycle/index.d.ts.map +1 -1
  61. package/dist/opLifecycle/index.js.map +1 -1
  62. package/dist/opLifecycle/opGroupingManager.d.ts +8 -0
  63. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  64. package/dist/opLifecycle/opGroupingManager.js +34 -2
  65. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  66. package/dist/opLifecycle/outbox.d.ts +1 -0
  67. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  68. package/dist/opLifecycle/outbox.js +20 -0
  69. package/dist/opLifecycle/outbox.js.map +1 -1
  70. package/dist/opLifecycle/remoteMessageProcessor.d.ts +34 -15
  71. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  72. package/dist/opLifecycle/remoteMessageProcessor.js +59 -46
  73. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  74. package/dist/packageVersion.d.ts +1 -1
  75. package/dist/packageVersion.js +1 -1
  76. package/dist/packageVersion.js.map +1 -1
  77. package/dist/pendingStateManager.d.ts +28 -27
  78. package/dist/pendingStateManager.d.ts.map +1 -1
  79. package/dist/pendingStateManager.js +143 -112
  80. package/dist/pendingStateManager.js.map +1 -1
  81. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  82. package/dist/summary/summarizerNode/summarizerNode.js +5 -1
  83. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  84. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +3 -4
  85. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  86. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +16 -15
  87. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  88. package/lib/batchTracker.d.ts.map +1 -1
  89. package/lib/batchTracker.js.map +1 -1
  90. package/lib/blobManager/blobManager.d.ts.map +1 -1
  91. package/lib/blobManager/blobManager.js +9 -0
  92. package/lib/blobManager/blobManager.js.map +1 -1
  93. package/lib/channelCollection.d.ts +0 -14
  94. package/lib/channelCollection.d.ts.map +1 -1
  95. package/lib/channelCollection.js +2 -11
  96. package/lib/channelCollection.js.map +1 -1
  97. package/lib/containerRuntime.d.ts +34 -6
  98. package/lib/containerRuntime.d.ts.map +1 -1
  99. package/lib/containerRuntime.js +176 -81
  100. package/lib/containerRuntime.js.map +1 -1
  101. package/lib/dataStoreContext.d.ts +9 -18
  102. package/lib/dataStoreContext.d.ts.map +1 -1
  103. package/lib/dataStoreContext.js +27 -65
  104. package/lib/dataStoreContext.js.map +1 -1
  105. package/lib/gc/garbageCollection.d.ts +0 -6
  106. package/lib/gc/garbageCollection.d.ts.map +1 -1
  107. package/lib/gc/garbageCollection.js +25 -68
  108. package/lib/gc/garbageCollection.js.map +1 -1
  109. package/lib/gc/gcConfigs.d.ts.map +1 -1
  110. package/lib/gc/gcConfigs.js +12 -35
  111. package/lib/gc/gcConfigs.js.map +1 -1
  112. package/lib/gc/gcDefinitions.d.ts +9 -52
  113. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  114. package/lib/gc/gcDefinitions.js +2 -22
  115. package/lib/gc/gcDefinitions.js.map +1 -1
  116. package/lib/gc/gcHelpers.d.ts.map +1 -1
  117. package/lib/gc/gcHelpers.js +2 -6
  118. package/lib/gc/gcHelpers.js.map +1 -1
  119. package/lib/gc/gcSummaryStateTracker.d.ts +1 -1
  120. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  121. package/lib/gc/gcSummaryStateTracker.js +4 -8
  122. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  123. package/lib/gc/gcTelemetry.d.ts +1 -9
  124. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  125. package/lib/gc/gcTelemetry.js +3 -24
  126. package/lib/gc/gcTelemetry.js.map +1 -1
  127. package/lib/gc/index.d.ts +2 -2
  128. package/lib/gc/index.d.ts.map +1 -1
  129. package/lib/gc/index.js +2 -2
  130. package/lib/gc/index.js.map +1 -1
  131. package/lib/index.d.ts +1 -1
  132. package/lib/index.d.ts.map +1 -1
  133. package/lib/index.js +1 -1
  134. package/lib/index.js.map +1 -1
  135. package/lib/messageTypes.d.ts +6 -5
  136. package/lib/messageTypes.d.ts.map +1 -1
  137. package/lib/messageTypes.js.map +1 -1
  138. package/lib/metadata.d.ts +9 -1
  139. package/lib/metadata.d.ts.map +1 -1
  140. package/lib/metadata.js +4 -0
  141. package/lib/metadata.js.map +1 -1
  142. package/lib/opLifecycle/index.d.ts +1 -1
  143. package/lib/opLifecycle/index.d.ts.map +1 -1
  144. package/lib/opLifecycle/index.js.map +1 -1
  145. package/lib/opLifecycle/opGroupingManager.d.ts +8 -0
  146. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  147. package/lib/opLifecycle/opGroupingManager.js +34 -2
  148. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  149. package/lib/opLifecycle/outbox.d.ts +1 -0
  150. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  151. package/lib/opLifecycle/outbox.js +20 -0
  152. package/lib/opLifecycle/outbox.js.map +1 -1
  153. package/lib/opLifecycle/remoteMessageProcessor.d.ts +34 -15
  154. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  155. package/lib/opLifecycle/remoteMessageProcessor.js +59 -46
  156. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  157. package/lib/packageVersion.d.ts +1 -1
  158. package/lib/packageVersion.js +1 -1
  159. package/lib/packageVersion.js.map +1 -1
  160. package/lib/pendingStateManager.d.ts +28 -27
  161. package/lib/pendingStateManager.d.ts.map +1 -1
  162. package/lib/pendingStateManager.js +144 -113
  163. package/lib/pendingStateManager.js.map +1 -1
  164. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  165. package/lib/summary/summarizerNode/summarizerNode.js +5 -1
  166. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  167. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +3 -4
  168. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  169. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +16 -15
  170. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  171. package/package.json +22 -31
  172. package/src/batchTracker.ts +4 -2
  173. package/src/blobManager/blobManager.ts +9 -0
  174. package/src/channelCollection.ts +2 -11
  175. package/src/containerRuntime.ts +211 -109
  176. package/src/dataStoreContext.ts +29 -93
  177. package/src/gc/garbageCollection.ts +26 -79
  178. package/src/gc/gcConfigs.ts +12 -45
  179. package/src/gc/gcDefinitions.ts +10 -55
  180. package/src/gc/gcHelpers.ts +10 -8
  181. package/src/gc/gcSummaryStateTracker.ts +6 -9
  182. package/src/gc/gcTelemetry.ts +3 -38
  183. package/src/gc/index.ts +2 -6
  184. package/src/index.ts +0 -1
  185. package/src/messageTypes.ts +12 -11
  186. package/src/metadata.ts +16 -2
  187. package/src/opLifecycle/index.ts +1 -0
  188. package/src/opLifecycle/opGroupingManager.ts +42 -3
  189. package/src/opLifecycle/outbox.ts +30 -0
  190. package/src/opLifecycle/remoteMessageProcessor.ts +98 -62
  191. package/src/packageVersion.ts +1 -1
  192. package/src/pendingStateManager.ts +199 -177
  193. package/src/summary/README.md +31 -28
  194. package/src/summary/summarizerNode/summarizerNode.ts +6 -1
  195. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +20 -43
  196. package/src/summary/summaryFormats.md +25 -22
@@ -1 +1 @@
1
- {"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAIH,kEAAmE;AAEnE,uEAKkD;AAClD,4EAAuC;AACvC,+BAAkC;AAGlC,+CAAgE;AAChE,qDAAgF;AAChF,2DAAiD;AAsEjD,SAAS,0BAA0B;AAClC,wEAAwE;AACxE,kCAAkC;AAClC,OAAmE;IAEnE,kFAAkF;IAClF,+BAA+B;IAC/B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAClD,sEAAsE;IACtE,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAwB;IACvD,OAAO;QACN,GAAG,OAAO;QACV,eAAe,EAAE,SAAS;KAC1B,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAa,mBAAmB;IA6B/B;;;OAGG;IACH,IAAW,oBAAoB;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;IAClE,CAAC;IAED;;;;OAIG;IACH,IAAW,mCAAmC;QAC7C,OAAO,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,EAAE,uBAAuB,CAAC;IAClE,CAAC;IAED;;;O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IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC;gBAC/B,SAAS,EAAE,uBAAuB;gBAClC,KAAK,EAAE,2BAA2B;gBAClC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;aACtC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD;AA7cD,kDA6cC;AAED,kFAAkF;AAClF,SAAS,mBAAmB,CAC3B,OAAiC;IAEjC,MAAM,cAAc,GAA+C,OAAO,CAAC,cAAc,CAAC;IAC1F,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;QAClC,gEAAgE;QAChE,OAAO,CAAC,cAAc,GAAG,EAAE,QAAQ,EAAE,IAAA,SAAI,GAAE,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,CAAC;IAClE,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { assert, Lazy } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tDataProcessingError,\n\tLoggingError,\n\textractSafePropertiesFromMessage,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { type InboundSequencedContainerRuntimeMessage } from \"./messageTypes.js\";\nimport { asBatchMetadata, IBatchMetadata } from \"./metadata.js\";\nimport { BatchId, BatchMessage, generateBatchId } from \"./opLifecycle/index.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n *\n * @remarks This is the current serialization format for pending local state when a Container is serialized.\n */\nexport interface IPendingMessage {\n\ttype: \"message\";\n\treferenceSequenceNumber: number;\n\tcontent: string;\n\tlocalOpMetadata: unknown;\n\topMetadata: Record<string, unknown> | undefined;\n\tsequenceNumber?: number;\n\t/** Info needed to compute the batchId on reconnect */\n\tbatchIdContext: {\n\t\t/** The Batch's original clientId, from when it was first flushed to be submitted */\n\t\tclientId: string;\n\t\t/**\n\t\t * The Batch's original clientSequenceNumber, from when it was first flushed to be submitted\n\t\t *\t@remarks A negative value means it was not yet submitted when queued here (e.g. disconnected right before flush fired)\n\t\t */\n\t\tbatchStartCsn: number;\n\t};\n}\n\ntype Patch<T, U> = U & Omit<T, keyof U>;\n\n/** First version of the type (pre-dates batchIdContext) */\ntype IPendingMessageV0 = Patch<IPendingMessage, { batchIdContext?: undefined }>;\n\n/**\n * Union of all supported schemas for when applying stashed ops\n *\n * @remarks When the format changes, this type should update to reflect all possible schemas.\n */\ntype IPendingMessageFromStash = IPendingMessageV0 | IPendingMessage;\n\nexport interface IPendingLocalState {\n\t/**\n\t * list of pending states, including ops and batch information\n\t */\n\tpendingStates: IPendingMessage[];\n}\n\n/** Info needed to replay/resubmit a pending message */\nexport type PendingMessageResubmitData = Pick<\n\tIPendingMessage,\n\t\"content\" | \"localOpMetadata\" | \"opMetadata\"\n>;\n\nexport interface IRuntimeStateHandler {\n\tconnected(): boolean;\n\tclientId(): string | undefined;\n\tclose(error?: ICriticalContainerError): void;\n\tapplyStashedOp(content: string): Promise<unknown>;\n\treSubmitBatch(batch: PendingMessageResubmitData[], batchId: BatchId): void;\n\tisActiveConnection: () => boolean;\n\tisAttached: () => boolean;\n}\n\n/** Union of keys of T */\ntype KeysOfUnion<T extends object> = T extends T ? keyof T : never;\n/** *Partial* type all possible combinations of properties and values of union T.\n * This loosens typing allowing access to all possible properties without\n * narrowing.\n */\ntype AnyComboFromUnion<T extends object> = { [P in KeysOfUnion<T>]?: T[P] };\n\nfunction buildPendingMessageContent(\n\t// AnyComboFromUnion is needed need to gain access to compatDetails that\n\t// is only defined for some cases.\n\tmessage: AnyComboFromUnion<InboundSequencedContainerRuntimeMessage>,\n): string {\n\t// IMPORTANT: Order matters here, this must match the order of the properties used\n\t// when submitting the message.\n\tconst { type, contents, compatDetails } = message;\n\t// Any properties that are not defined, won't be emitted by stringify.\n\treturn JSON.stringify({ type, contents, compatDetails });\n}\n\nfunction withoutLocalOpMetadata(message: IPendingMessage): IPendingMessage {\n\treturn {\n\t\t...message,\n\t\tlocalOpMetadata: undefined,\n\t};\n}\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n\t/** Messages that will need to be resubmitted if not ack'd before the next reconnection */\n\tprivate readonly pendingMessages = new Deque<IPendingMessage>();\n\t/** Messages stashed from a previous container, now being rehydrated. Need to be resubmitted. */\n\tprivate readonly initialMessages = new Deque<IPendingMessageFromStash>();\n\n\t/**\n\t * Sequenced local ops that are saved when stashing since pending ops may depend on them\n\t */\n\tprivate savedOps: IPendingMessage[] = [];\n\n\t/** Used to stand in for batchStartCsn for messages that weren't submitted (so no CSN) */\n\tprivate negativeCounter: number = -1;\n\n\tprivate readonly disposeOnce = new Lazy<void>(() => {\n\t\tthis.initialMessages.clear();\n\t\tthis.pendingMessages.clear();\n\t});\n\n\t// Indicates whether we are processing a batch.\n\tprivate isProcessingBatch: boolean = false;\n\n\t// This stores the first message in the batch that we are processing. This is used to verify that we get\n\t// the correct batch metadata.\n\tprivate pendingBatchBeginMessage: ISequencedDocumentMessage | undefined;\n\n\t/** Used to ensure we don't replay ops on the same connection twice */\n\tprivate clientIdFromLastReplay: string | undefined;\n\n\t/**\n\t * The pending messages count. Includes `pendingMessages` and `initialMessages` to keep in sync with\n\t * 'hasPendingMessages'.\n\t */\n\tpublic get pendingMessagesCount(): number {\n\t\treturn this.pendingMessages.length + this.initialMessages.length;\n\t}\n\n\t/**\n\t * The minimumPendingMessageSequenceNumber is the minimum of the first pending message and the first initial message.\n\t *\n\t * We need this so that we can properly keep local data and maintain the correct sequence window.\n\t */\n\tpublic get minimumPendingMessageSequenceNumber(): number | undefined {\n\t\treturn this.pendingMessages.peekFront()?.referenceSequenceNumber;\n\t}\n\n\t/**\n\t * Called to check if there are any pending messages in the pending message queue.\n\t * @returns A boolean indicating whether there are messages or not.\n\t */\n\tpublic hasPendingMessages(): boolean {\n\t\treturn this.pendingMessagesCount !== 0;\n\t}\n\n\tpublic getLocalState(snapshotSequenceNumber?: number): IPendingLocalState {\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x2e9 /* \"Must call getLocalState() after applying initial states\" */,\n\t\t);\n\t\t// Using snapshot sequence number to filter ops older than our latest snapshot.\n\t\t// Such ops should not be declared in pending/stashed state. Snapshot seq num will not\n\t\t// be available when the container is not attached. Therefore, no filtering is needed.\n\t\tconst newSavedOps = [...this.savedOps].filter((message) => {\n\t\t\tassert(\n\t\t\t\tmessage.sequenceNumber !== undefined,\n\t\t\t\t0x97c /* saved op should already have a sequence number */,\n\t\t\t);\n\t\t\treturn message.sequenceNumber > (snapshotSequenceNumber ?? 0);\n\t\t});\n\t\tthis.pendingMessages.toArray().forEach((message) => {\n\t\t\tif (\n\t\t\t\tsnapshotSequenceNumber !== undefined &&\n\t\t\t\tmessage.referenceSequenceNumber < snapshotSequenceNumber\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"trying to stash ops older than our latest snapshot\");\n\t\t\t}\n\t\t});\n\t\treturn {\n\t\t\tpendingStates: [\n\t\t\t\t...newSavedOps,\n\t\t\t\t...this.pendingMessages.toArray().map(withoutLocalOpMetadata),\n\t\t\t],\n\t\t};\n\t}\n\n\tconstructor(\n\t\tprivate readonly stateHandler: IRuntimeStateHandler,\n\t\tstashedLocalState: IPendingLocalState | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tif (stashedLocalState?.pendingStates) {\n\t\t\tthis.initialMessages.push(...stashedLocalState.pendingStates);\n\t\t}\n\t}\n\n\tpublic get disposed() {\n\t\treturn this.disposeOnce.evaluated;\n\t}\n\tpublic readonly dispose = () => this.disposeOnce.value;\n\n\t/**\n\t * The given batch has been flushed, and needs to be tracked locally until the corresponding\n\t * acks are processed, to ensure it is successfully sent.\n\t * @param batch - The batch that was flushed\n\t * @param clientSequenceNumber - The CSN of the first message in the batch,\n\t * or undefined if the batch was not yet sent (e.g. by the time we flushed we lost the connection)\n\t */\n\tpublic onFlushBatch(batch: BatchMessage[], clientSequenceNumber: number | undefined) {\n\t\t// If we're connected this is the client of the current connection,\n\t\t// otherwise it's the clientId that just disconnected\n\t\t// It's only undefined if we've NEVER connected. This is a tight corner case and we can\n\t\t// simply make up a unique ID in this case.\n\t\tconst clientId = this.stateHandler.clientId() ?? uuid();\n\n\t\t// If the batch was not yet sent, we need to assign a unique batchStartCsn\n\t\t// Use a negative number to distinguish these from real CSNs\n\t\tconst batchStartCsn = clientSequenceNumber ?? this.negativeCounter--;\n\n\t\tfor (const message of batch) {\n\t\t\tconst {\n\t\t\t\tcontents: content = \"\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\tmetadata: opMetadata,\n\t\t\t} = message;\n\t\t\tconst pendingMessage: IPendingMessage = {\n\t\t\t\ttype: \"message\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tcontent,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\topMetadata,\n\t\t\t\t// Note: We only need this on the first message.\n\t\t\t\tbatchIdContext: { clientId, batchStartCsn },\n\t\t\t};\n\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n\t * @param seqNum - Sequence number at which to apply ops. Will apply all ops if seqNum is undefined.\n\t */\n\tpublic async applyStashedOpsAt(seqNum?: number) {\n\t\t// apply stashed ops at sequence number\n\t\twhile (!this.initialMessages.isEmpty()) {\n\t\t\tif (seqNum !== undefined) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst peekMessage = this.initialMessages.peekFront()!;\n\t\t\t\tif (peekMessage.referenceSequenceNumber > seqNum) {\n\t\t\t\t\tbreak; // nothing left to do at this sequence number\n\t\t\t\t}\n\t\t\t\tif (peekMessage.referenceSequenceNumber < seqNum) {\n\t\t\t\t\tthrow new Error(\"loaded from snapshot too recent to apply stashed ops\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nextMessage = this.initialMessages.shift()!;\n\t\t\ttry {\n\t\t\t\t// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n\t\t\t\tconst localOpMetadata = await this.stateHandler.applyStashedOp(nextMessage.content);\n\t\t\t\tif (!this.stateHandler.isAttached()) {\n\t\t\t\t\tif (localOpMetadata !== undefined) {\n\t\t\t\t\t\tthrow new Error(\"Local Op Metadata must be undefined when not attached\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextMessage.localOpMetadata = localOpMetadata;\n\t\t\t\t\t// then we push onto pendingMessages which will cause PendingStateManager to resubmit when we connect\n\t\t\t\t\tpatchBatchIdContext(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow DataProcessingError.wrapIfUnrecognized(error, \"applyStashedOp\", nextMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Processes the incoming batch from the server. It verifies that messages are received in the right order and\n\t * that the batch information is correct.\n\t * @param batch - The batch that is being processed.\n\t * @param batchStartCsn - The clientSequenceNumber of the start of this message's batch\n\t */\n\tpublic processPendingLocalBatch(\n\t\tbatch: InboundSequencedContainerRuntimeMessage[],\n\t\tbatchStartCsn: number,\n\t): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata: unknown;\n\t}[] {\n\t\treturn batch.map((message) => ({\n\t\t\tmessage,\n\t\t\tlocalOpMetadata: this.processPendingLocalMessage(message, batchStartCsn),\n\t\t}));\n\t}\n\n\t/**\n\t * Processes a local message once its ack'd by the server. It verifies that there was no data corruption and that\n\t * the batch information was preserved for batch messages.\n\t * @param message - The message that got ack'd and needs to be processed.\n\t * @param batchStartCsn - The clientSequenceNumber of the start of this message's batch (assigned during submit)\n\t * (not to be confused with message.clientSequenceNumber - the overwritten value in case of grouped batching)\n\t */\n\tprivate processPendingLocalMessage(\n\t\tmessage: InboundSequencedContainerRuntimeMessage,\n\t\tbatchStartCsn: number,\n\t): unknown {\n\t\t// Get the next message from the pending queue. Verify a message exists.\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0x169 /* \"No pending message found for this remote message\" */,\n\t\t);\n\n\t\t// This may be the start of a batch.\n\t\tthis.maybeProcessBatchBegin(message, batchStartCsn, pendingMessage);\n\n\t\tpendingMessage.sequenceNumber = message.sequenceNumber;\n\t\tthis.savedOps.push(withoutLocalOpMetadata(pendingMessage));\n\n\t\tthis.pendingMessages.shift();\n\n\t\tconst messageContent = buildPendingMessageContent(message);\n\n\t\t// Stringified content should match\n\t\tif (pendingMessage.content !== messageContent) {\n\t\t\tthis.stateHandler.close(\n\t\t\t\tDataProcessingError.create(\n\t\t\t\t\t\"pending local message content mismatch\",\n\t\t\t\t\t\"unexpectedAckReceived\",\n\t\t\t\t\tmessage,\n\t\t\t\t\t{\n\t\t\t\t\t\texpectedMessageType: JSON.parse(pendingMessage.content).type,\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// Post-processing part - If we are processing a batch then this could be the last message in the batch.\n\t\tthis.maybeProcessBatchEnd(message);\n\n\t\treturn pendingMessage.localOpMetadata;\n\t}\n\n\t/**\n\t * This message could be the first message in batch. If so, set batch state marking the beginning of a batch.\n\t * @param message - The message that is being processed.\n\t * @param batchStartCsn - The clientSequenceNumber of the start of this message's batch (assigned during submit)\n\t * @param pendingMessage - The corresponding pendingMessage.\n\t */\n\tprivate maybeProcessBatchBegin(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tbatchStartCsn: number,\n\t\tpendingMessage: IPendingMessage,\n\t) {\n\t\tif (!this.isProcessingBatch) {\n\t\t\t// Expecting the start of a batch (maybe single-message).\n\t\t\tif (pendingMessage.batchIdContext.batchStartCsn !== batchStartCsn) {\n\t\t\t\tthis.logger?.sendErrorEvent({\n\t\t\t\t\teventName: \"BatchClientSequenceNumberMismatch\",\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tprocessingBatch: !!this.pendingBatchBeginMessage,\n\t\t\t\t\t\tpendingBatchCsn: pendingMessage.batchIdContext.batchStartCsn,\n\t\t\t\t\t\tbatchStartCsn,\n\t\t\t\t\t\tmessageBatchMetadata: (message.metadata as any)?.batch,\n\t\t\t\t\t\tpendingMessageBatchMetadata: (pendingMessage.opMetadata as any)?.batch,\n\t\t\t\t\t},\n\t\t\t\t\tmessageDetails: extractSafePropertiesFromMessage(message),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// This message is the first in a batch if the \"batch\" property on the metadata is set to true\n\t\tif ((message.metadata as IBatchMetadata | undefined)?.batch) {\n\t\t\t// We should not already be processing a batch and there should be no pending batch begin message.\n\t\t\tassert(\n\t\t\t\t!this.isProcessingBatch && this.pendingBatchBeginMessage === undefined,\n\t\t\t\t0x16b /* \"The pending batch state indicates we are already processing a batch\" */,\n\t\t\t);\n\n\t\t\t// Set the pending batch state indicating we have started processing a batch.\n\t\t\tthis.pendingBatchBeginMessage = message;\n\t\t\tthis.isProcessingBatch = true;\n\t\t}\n\t}\n\n\t/**\n\t * This message could be the last message in batch. If so, clear batch state since the batch is complete.\n\t * @param message - The message that is being processed.\n\t */\n\tprivate maybeProcessBatchEnd(message: ISequencedDocumentMessage) {\n\t\tif (!this.isProcessingBatch) {\n\t\t\treturn;\n\t\t}\n\n\t\t// There should be a pending batch begin message.\n\t\tassert(\n\t\t\tthis.pendingBatchBeginMessage !== undefined,\n\t\t\t0x16d /* \"There is no pending batch begin message\" */,\n\t\t);\n\n\t\tconst batchEndMetadata = (message.metadata as IBatchMetadata | undefined)?.batch;\n\t\tif (this.pendingMessages.isEmpty() || batchEndMetadata === false) {\n\t\t\t// Get the batch begin metadata from the first message in the batch.\n\t\t\tconst batchBeginMetadata = (\n\t\t\t\tthis.pendingBatchBeginMessage.metadata as IBatchMetadata | undefined\n\t\t\t)?.batch;\n\n\t\t\t// There could be just a single message in the batch. If so, it should not have any batch metadata. If there\n\t\t\t// are multiple messages in the batch, verify that we got the correct batch begin and end metadata.\n\t\t\tif (this.pendingBatchBeginMessage === message) {\n\t\t\t\tassert(\n\t\t\t\t\tbatchBeginMetadata === undefined,\n\t\t\t\t\t0x16e /* \"Batch with single message should not have batch metadata\" */,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tif (batchBeginMetadata !== true || batchEndMetadata !== false) {\n\t\t\t\t\tthis.stateHandler.close(\n\t\t\t\t\t\tDataProcessingError.create(\n\t\t\t\t\t\t\t\"Pending batch inconsistency\", // Formerly known as asserts 0x16f and 0x170\n\t\t\t\t\t\t\t\"processPendingLocalMessage\",\n\t\t\t\t\t\t\tmessage,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\truntimeVersion: pkgVersion,\n\t\t\t\t\t\t\t\tbatchClientId:\n\t\t\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\t\t\t\t\t\tthis.pendingBatchBeginMessage.clientId === null\n\t\t\t\t\t\t\t\t\t\t? \"null\"\n\t\t\t\t\t\t\t\t\t\t: this.pendingBatchBeginMessage.clientId,\n\t\t\t\t\t\t\t\tclientId: this.stateHandler.clientId(),\n\t\t\t\t\t\t\t\thasBatchStart: batchBeginMetadata === true,\n\t\t\t\t\t\t\t\thasBatchEnd: batchEndMetadata === false,\n\t\t\t\t\t\t\t\tmessageType: message.type,\n\t\t\t\t\t\t\t\tpendingMessagesCount: this.pendingMessagesCount,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Clear the pending batch state now that we have processed the entire batch.\n\t\t\tthis.pendingBatchBeginMessage = undefined;\n\t\t\tthis.isProcessingBatch = false;\n\t\t}\n\t}\n\n\t/**\n\t * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n\t * states in its queue. This includes triggering resubmission of unacked ops.\n\t * ! Note: successfully resubmitting an op that has been successfully sequenced is not possible due to checks in the ConnectionStateHandler (Loader layer)\n\t */\n\tpublic replayPendingStates() {\n\t\tassert(\n\t\t\tthis.stateHandler.connected(),\n\t\t\t0x172 /* \"The connection state is not consistent with the runtime\" */,\n\t\t);\n\n\t\t// This assert suggests we are about to send same ops twice, which will result in data loss.\n\t\tassert(\n\t\t\tthis.clientIdFromLastReplay !== this.stateHandler.clientId(),\n\t\t\t0x173 /* \"replayPendingStates called twice for same clientId!\" */,\n\t\t);\n\t\tthis.clientIdFromLastReplay = this.stateHandler.clientId();\n\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x174 /* \"initial states should be empty before replaying pending\" */,\n\t\t);\n\n\t\tconst initialPendingMessagesCount = this.pendingMessages.length;\n\t\tlet remainingPendingMessagesCount = this.pendingMessages.length;\n\n\t\t// Process exactly `pendingMessagesCount` items in the queue as it represents the number of messages that were\n\t\t// pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n\t\t// which must not be replayed.\n\t\twhile (remainingPendingMessagesCount > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tlet pendingMessage = this.pendingMessages.shift()!;\n\t\t\tremainingPendingMessagesCount--;\n\n\t\t\tconst batchMetadataFlag = asBatchMetadata(pendingMessage.opMetadata)?.batch;\n\t\t\tassert(batchMetadataFlag !== false, 0x41b /* We cannot process batches in chunks */);\n\n\t\t\t// The next message starts a batch (possibly single-message), and we'll need its batchId.\n\t\t\t// We'll find batchId on this message if it was previously generated.\n\t\t\t// Otherwise, generate it now - this is the first time resubmitting this batch.\n\t\t\tconst batchId =\n\t\t\t\tasBatchMetadata(pendingMessage.opMetadata)?.batchId ??\n\t\t\t\tgenerateBatchId(\n\t\t\t\t\tpendingMessage.batchIdContext.clientId,\n\t\t\t\t\tpendingMessage.batchIdContext.batchStartCsn,\n\t\t\t\t);\n\n\t\t\t/**\n\t\t\t * We must preserve the distinct batches on resubmit.\n\t\t\t * Note: It is not possible for the PendingStateManager to receive a partially acked batch. It will\n\t\t\t * either receive the whole batch ack or nothing at all. @see ScheduleManager for how this works.\n\t\t\t */\n\t\t\tif (batchMetadataFlag === undefined) {\n\t\t\t\t// Single-message batch\n\n\t\t\t\tthis.stateHandler.reSubmitBatch(\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: pendingMessage.content,\n\t\t\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tbatchId,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// else: batchMetadataFlag === true (It's a typical multi-message batch)\n\n\t\t\tassert(\n\t\t\t\tremainingPendingMessagesCount > 0,\n\t\t\t\t0x554 /* Last pending message cannot be a batch begin */,\n\t\t\t);\n\n\t\t\tconst batch: PendingMessageResubmitData[] = [];\n\n\t\t\t// check is >= because batch end may be last pending message\n\t\t\twhile (remainingPendingMessagesCount >= 0) {\n\t\t\t\tbatch.push({\n\t\t\t\t\tcontent: pendingMessage.content,\n\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t});\n\n\t\t\t\tif (pendingMessage.opMetadata?.batch === false) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tassert(remainingPendingMessagesCount > 0, 0x555 /* No batch end found */);\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tpendingMessage = this.pendingMessages.shift()!;\n\t\t\t\tremainingPendingMessagesCount--;\n\t\t\t\tassert(\n\t\t\t\t\tpendingMessage.opMetadata?.batch !== true,\n\t\t\t\t\t0x556 /* Batch start needs a corresponding batch end */,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.stateHandler.reSubmitBatch(batch, batchId);\n\t\t}\n\n\t\t// pending ops should no longer depend on previous sequenced local ops after resubmit\n\t\tthis.savedOps = [];\n\n\t\t// We replayPendingStates on read connections too - we expect these to get nack'd though, and to then reconnect\n\t\t// on a write connection and replay again. This filters out the replay that happens on the read connection so\n\t\t// we only see the replays on write connections (that have a chance to go through).\n\t\tif (this.stateHandler.isActiveConnection()) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"PendingStatesReplayed\",\n\t\t\t\tcount: initialPendingMessagesCount,\n\t\t\t\tclientId: this.stateHandler.clientId(),\n\t\t\t});\n\t\t}\n\t}\n}\n\n/** For back-compat if trying to apply stashed ops that pre-date batchIdContext */\nfunction patchBatchIdContext(\n\tmessage: IPendingMessageFromStash,\n): asserts message is IPendingMessage {\n\tconst batchIdContext: IPendingMessageFromStash[\"batchIdContext\"] = message.batchIdContext;\n\tif (batchIdContext === undefined) {\n\t\t// Using uuid guarantees uniqueness, retaining existing behavior\n\t\tmessage.batchIdContext = { clientId: uuid(), batchStartCsn: -1 };\n\t}\n}\n"]}
1
+ {"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings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nF,IAAI,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC;gBAC/B,SAAS,EAAE,uBAAuB;gBAClC,KAAK,EAAE,2BAA2B;gBAClC,QAAQ,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;aACtC,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD;AApcD,kDAocC;AAED,6EAA6E;AAC7E,SAAS,cAAc,CACtB,OAAiC;IAEjC,MAAM,SAAS,GAA0C,OAAO,CAAC,SAAS,CAAC;IAC3E,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,gEAAgE;QAChE,OAAO,CAAC,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAA,SAAI,GAAE,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;IACzE,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable } from \"@fluidframework/core-interfaces\";\nimport { assert, Lazy } from \"@fluidframework/core-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tDataProcessingError,\n\tLoggingError,\n\textractSafePropertiesFromMessage,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport Deque from \"double-ended-queue\";\nimport { v4 as uuid } from \"uuid\";\n\nimport {\n\ttype InboundContainerRuntimeMessage,\n\ttype InboundSequencedContainerRuntimeMessage,\n\ttype LocalContainerRuntimeMessage,\n} from \"./messageTypes.js\";\nimport { asBatchMetadata, asEmptyBatchLocalOpMetadata } from \"./metadata.js\";\nimport { BatchId, BatchMessage, generateBatchId, InboundBatch } from \"./opLifecycle/index.js\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n *\n * @remarks This is the current serialization format for pending local state when a Container is serialized.\n */\nexport interface IPendingMessage {\n\ttype: \"message\";\n\treferenceSequenceNumber: number;\n\tcontent: string;\n\tlocalOpMetadata: unknown;\n\topMetadata: Record<string, unknown> | undefined;\n\tsequenceNumber?: number;\n\t/** Info about the batch this pending message belongs to, for validation and for computing the batchId on reconnect */\n\tbatchInfo: {\n\t\t/** The Batch's original clientId, from when it was first flushed to be submitted */\n\t\tclientId: string;\n\t\t/**\n\t\t * The Batch's original clientSequenceNumber, from when it was first flushed to be submitted\n\t\t *\t@remarks A negative value means it was not yet submitted when queued here (e.g. disconnected right before flush fired)\n\t\t */\n\t\tbatchStartCsn: number;\n\t\t/** length of the batch (how many runtime messages here) */\n\t\tlength: number;\n\t};\n}\n\ntype Patch<T, U> = U & Omit<T, keyof U>;\n\n/** First version of the type (pre-dates batchInfo) */\ntype IPendingMessageV0 = Patch<IPendingMessage, { batchInfo?: undefined }>;\n\n/**\n * Union of all supported schemas for when applying stashed ops\n *\n * @remarks When the format changes, this type should update to reflect all possible schemas.\n */\ntype IPendingMessageFromStash = IPendingMessageV0 | IPendingMessage;\n\nexport interface IPendingLocalState {\n\t/**\n\t * list of pending states, including ops and batch information\n\t */\n\tpendingStates: IPendingMessage[];\n}\n\n/** Info needed to replay/resubmit a pending message */\nexport type PendingMessageResubmitData = Pick<\n\tIPendingMessage,\n\t\"content\" | \"localOpMetadata\" | \"opMetadata\"\n>;\n\nexport interface IRuntimeStateHandler {\n\tconnected(): boolean;\n\tclientId(): string | undefined;\n\tapplyStashedOp(content: string): Promise<unknown>;\n\treSubmitBatch(batch: PendingMessageResubmitData[], batchId: BatchId): void;\n\tisActiveConnection: () => boolean;\n\tisAttached: () => boolean;\n}\n\nfunction isEmptyBatchPendingMessage(message: IPendingMessageFromStash): boolean {\n\tconst content = JSON.parse(message.content);\n\treturn content.type === \"groupedBatch\" && content.contents?.length === 0;\n}\n\nfunction buildPendingMessageContent(message: InboundSequencedContainerRuntimeMessage): string {\n\t// IMPORTANT: Order matters here, this must match the order of the properties used\n\t// when submitting the message.\n\tconst { type, contents, compatDetails }: InboundContainerRuntimeMessage = message;\n\t// Any properties that are not defined, won't be emitted by stringify.\n\treturn JSON.stringify({ type, contents, compatDetails });\n}\n\nfunction typesOfKeys<T extends object>(obj: T): Record<keyof T, string> {\n\treturn Object.keys(obj).reduce((acc, key) => {\n\t\tacc[key] = typeof obj[key];\n\t\treturn acc;\n\t}, {}) as Record<keyof T, string>;\n}\n\nfunction scrubAndStringify(\n\tmessage: InboundContainerRuntimeMessage | LocalContainerRuntimeMessage,\n): string {\n\t// Scrub the whole object in case there are unexpected keys\n\tconst scrubbed: Record<string, unknown> = typesOfKeys(message);\n\n\t// For these known/expected keys, we can either drill in (for contents)\n\t// or just use the value as-is (since it's not personal info)\n\tscrubbed.contents = message.contents && typesOfKeys(message.contents);\n\tscrubbed.compatDetails = message.compatDetails;\n\tscrubbed.type = message.type;\n\n\treturn JSON.stringify(scrubbed);\n}\n\nfunction withoutLocalOpMetadata(message: IPendingMessage): IPendingMessage {\n\treturn {\n\t\t...message,\n\t\tlocalOpMetadata: undefined,\n\t};\n}\n\n/**\n * Get the effective batch ID for a pending message.\n * If the batch ID is already present in the message's op metadata, return it.\n * Otherwise, generate a new batch ID using the client ID and batch start CSN.\n * @param pendingMessage - The pending message\n * @returns The effective batch ID\n */\nfunction getEffectiveBatchId(pendingMessage: IPendingMessage): string {\n\treturn (\n\t\tasBatchMetadata(pendingMessage.opMetadata)?.batchId ??\n\t\tgenerateBatchId(pendingMessage.batchInfo.clientId, pendingMessage.batchInfo.batchStartCsn)\n\t);\n}\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n\t/** Messages that will need to be resubmitted if not ack'd before the next reconnection */\n\tprivate readonly pendingMessages = new Deque<IPendingMessage>();\n\t/** Messages stashed from a previous container, now being rehydrated. Need to be resubmitted. */\n\tprivate readonly initialMessages = new Deque<IPendingMessageFromStash>();\n\n\t/**\n\t * Sequenced local ops that are saved when stashing since pending ops may depend on them\n\t */\n\tprivate savedOps: IPendingMessage[] = [];\n\n\t/** Used to stand in for batchStartCsn for messages that weren't submitted (so no CSN) */\n\tprivate negativeCounter: number = -1;\n\n\tprivate readonly disposeOnce = new Lazy<void>(() => {\n\t\tthis.initialMessages.clear();\n\t\tthis.pendingMessages.clear();\n\t});\n\n\t/** Used to ensure we don't replay ops on the same connection twice */\n\tprivate clientIdFromLastReplay: string | undefined;\n\n\t/**\n\t * The pending messages count. Includes `pendingMessages` and `initialMessages` to keep in sync with\n\t * 'hasPendingMessages'.\n\t */\n\tpublic get pendingMessagesCount(): number {\n\t\treturn this.pendingMessages.length + this.initialMessages.length;\n\t}\n\n\t/**\n\t * The minimumPendingMessageSequenceNumber is the minimum of the first pending message and the first initial message.\n\t *\n\t * We need this so that we can properly keep local data and maintain the correct sequence window.\n\t */\n\tpublic get minimumPendingMessageSequenceNumber(): number | undefined {\n\t\treturn this.pendingMessages.peekFront()?.referenceSequenceNumber;\n\t}\n\n\t/**\n\t * Called to check if there are any pending messages in the pending message queue.\n\t * @returns A boolean indicating whether there are messages or not.\n\t */\n\tpublic hasPendingMessages(): boolean {\n\t\treturn this.pendingMessagesCount !== 0;\n\t}\n\n\tpublic getLocalState(snapshotSequenceNumber?: number): IPendingLocalState {\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x2e9 /* \"Must call getLocalState() after applying initial states\" */,\n\t\t);\n\t\t// Using snapshot sequence number to filter ops older than our latest snapshot.\n\t\t// Such ops should not be declared in pending/stashed state. Snapshot seq num will not\n\t\t// be available when the container is not attached. Therefore, no filtering is needed.\n\t\tconst newSavedOps = [...this.savedOps].filter((message) => {\n\t\t\tassert(\n\t\t\t\tmessage.sequenceNumber !== undefined,\n\t\t\t\t0x97c /* saved op should already have a sequence number */,\n\t\t\t);\n\t\t\treturn message.sequenceNumber > (snapshotSequenceNumber ?? 0);\n\t\t});\n\t\tthis.pendingMessages.toArray().forEach((message) => {\n\t\t\tif (\n\t\t\t\tsnapshotSequenceNumber !== undefined &&\n\t\t\t\tmessage.referenceSequenceNumber < snapshotSequenceNumber\n\t\t\t) {\n\t\t\t\tthrow new LoggingError(\"trying to stash ops older than our latest snapshot\");\n\t\t\t}\n\t\t});\n\t\treturn {\n\t\t\tpendingStates: [\n\t\t\t\t...newSavedOps,\n\t\t\t\t...this.pendingMessages.toArray().map(withoutLocalOpMetadata),\n\t\t\t],\n\t\t};\n\t}\n\n\tconstructor(\n\t\tprivate readonly stateHandler: IRuntimeStateHandler,\n\t\tstashedLocalState: IPendingLocalState | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tif (stashedLocalState?.pendingStates) {\n\t\t\tthis.initialMessages.push(...stashedLocalState.pendingStates);\n\t\t}\n\t}\n\n\tpublic get disposed() {\n\t\treturn this.disposeOnce.evaluated;\n\t}\n\tpublic readonly dispose = () => this.disposeOnce.value;\n\n\t/**\n\t * The given batch has been flushed, and needs to be tracked locally until the corresponding\n\t * acks are processed, to ensure it is successfully sent.\n\t * @param batch - The batch that was flushed\n\t * @param clientSequenceNumber - The CSN of the first message in the batch,\n\t * or undefined if the batch was not yet sent (e.g. by the time we flushed we lost the connection)\n\t */\n\tpublic onFlushBatch(batch: BatchMessage[], clientSequenceNumber: number | undefined) {\n\t\t// If we're connected this is the client of the current connection,\n\t\t// otherwise it's the clientId that just disconnected\n\t\t// It's only undefined if we've NEVER connected. This is a tight corner case and we can\n\t\t// simply make up a unique ID in this case.\n\t\tconst clientId = this.stateHandler.clientId() ?? uuid();\n\n\t\t// If the batch was not yet sent, we need to assign a unique batchStartCsn\n\t\t// Use a negative number to distinguish these from real CSNs\n\t\tconst batchStartCsn = clientSequenceNumber ?? this.negativeCounter--;\n\n\t\tfor (const message of batch) {\n\t\t\tconst {\n\t\t\t\tcontents: content = \"\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\tmetadata: opMetadata,\n\t\t\t} = message;\n\t\t\tconst pendingMessage: IPendingMessage = {\n\t\t\t\ttype: \"message\",\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tcontent,\n\t\t\t\tlocalOpMetadata,\n\t\t\t\topMetadata,\n\t\t\t\t// Note: We only will read this off the first message, but put it on all for simplicity\n\t\t\t\tbatchInfo: { clientId, batchStartCsn, length: batch.length },\n\t\t\t};\n\t\t\tthis.pendingMessages.push(pendingMessage);\n\t\t}\n\t}\n\n\t/**\n\t * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n\t * @param seqNum - Sequence number at which to apply ops. Will apply all ops if seqNum is undefined.\n\t */\n\tpublic async applyStashedOpsAt(seqNum?: number) {\n\t\t// apply stashed ops at sequence number\n\t\twhile (!this.initialMessages.isEmpty()) {\n\t\t\tif (seqNum !== undefined) {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst peekMessage = this.initialMessages.peekFront()!;\n\t\t\t\tif (peekMessage.referenceSequenceNumber > seqNum) {\n\t\t\t\t\tbreak; // nothing left to do at this sequence number\n\t\t\t\t}\n\t\t\t\tif (peekMessage.referenceSequenceNumber < seqNum) {\n\t\t\t\t\tthrow new Error(\"loaded from snapshot too recent to apply stashed ops\");\n\t\t\t\t}\n\t\t\t}\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst nextMessage = this.initialMessages.shift()!;\n\t\t\t// Nothing to apply if the message is an empty batch.\n\t\t\t// We still need to track it for resubmission.\n\t\t\ttry {\n\t\t\t\tif (isEmptyBatchPendingMessage(nextMessage)) {\n\t\t\t\t\tnextMessage.localOpMetadata = { emptyBatch: true }; // equivalent to applyStashedOp for empty batch\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n\t\t\t\tconst localOpMetadata = await this.stateHandler.applyStashedOp(nextMessage.content);\n\t\t\t\tif (!this.stateHandler.isAttached()) {\n\t\t\t\t\tif (localOpMetadata !== undefined) {\n\t\t\t\t\t\tthrow new Error(\"Local Op Metadata must be undefined when not attached\");\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tnextMessage.localOpMetadata = localOpMetadata;\n\t\t\t\t\t// then we push onto pendingMessages which will cause PendingStateManager to resubmit when we connect\n\t\t\t\t\tpatchbatchInfo(nextMessage); // Back compat\n\t\t\t\t\tthis.pendingMessages.push(nextMessage);\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tthrow DataProcessingError.wrapIfUnrecognized(error, \"applyStashedOp\", nextMessage);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Processes an inbound batch of messages - May be local or remote.\n\t *\n\t * @param batch - The inbound batch of messages to process. Could be local or remote.\n\t * @param local - true if we submitted this batch and expect corresponding pending messages\n\t * @returns The inbound batch's messages with localOpMetadata \"zipped\" in.\n\t *\n\t * @remarks Closes the container if:\n\t * - The batchStartCsn doesn't match for local batches\n\t */\n\tpublic processInboundBatch(\n\t\tbatch: InboundBatch,\n\t\tlocal: boolean,\n\t): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata?: unknown;\n\t}[] {\n\t\tif (local) {\n\t\t\treturn this.processPendingLocalBatch(batch);\n\t\t}\n\n\t\t// No localOpMetadata for remote messages\n\t\treturn batch.messages.map((message) => ({ message }));\n\t}\n\n\t/**\n\t * Processes the incoming batch from the server that was submitted by this client.\n\t * It verifies that messages are received in the right order and that the batch information is correct.\n\t * @param batch - The inbound batch (originating from this client) to correlate with the pending local state\n\t * @returns The inbound batch's messages with localOpMetadata \"zipped\" in.\n\t */\n\tprivate processPendingLocalBatch(batch: InboundBatch): {\n\t\tmessage: InboundSequencedContainerRuntimeMessage;\n\t\tlocalOpMetadata: unknown;\n\t}[] {\n\t\tthis.onLocalBatchBegin(batch);\n\n\t\t// Empty batch\n\t\tif (batch.messages.length === 0) {\n\t\t\tassert(\n\t\t\t\tbatch.emptyBatchSequenceNumber !== undefined,\n\t\t\t\t0x9fb /* Expected sequence number for empty batch */,\n\t\t\t);\n\t\t\tconst localOpMetadata = this.processNextPendingMessage(batch.emptyBatchSequenceNumber);\n\t\t\tassert(\n\t\t\t\tasEmptyBatchLocalOpMetadata(localOpMetadata)?.emptyBatch === true,\n\t\t\t\t0xa20 /* Expected empty batch marker */,\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\n\t\treturn batch.messages.map((message) => ({\n\t\t\tmessage,\n\t\t\tlocalOpMetadata: this.processNextPendingMessage(message.sequenceNumber, message),\n\t\t}));\n\t}\n\n\t/**\n\t * Processes the pending local copy of message that's been ack'd by the server.\n\t * @param sequenceNumber - The sequenceNumber from the server corresponding to the next pending message.\n\t * @param message - [optional] The entire incoming message, for comparing contents with the pending message for extra validation.\n\t * @throws DataProcessingError if the pending message content doesn't match the incoming message content.\n\t * @returns - The localOpMetadata of the next pending message, to be sent to whoever submitted the original message.\n\t */\n\tprivate processNextPendingMessage(\n\t\tsequenceNumber: number,\n\t\tmessage?: InboundSequencedContainerRuntimeMessage,\n\t): unknown {\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0x169 /* \"No pending message found for this remote message\" */,\n\t\t);\n\n\t\tpendingMessage.sequenceNumber = sequenceNumber;\n\t\tthis.savedOps.push(withoutLocalOpMetadata(pendingMessage));\n\n\t\tthis.pendingMessages.shift();\n\n\t\t// message is undefined in the Empty Batch case,\n\t\t// because we don't have an incoming message to compare and pendingMessage is just a placeholder anyway.\n\t\tif (message !== undefined) {\n\t\t\tconst messageContent = buildPendingMessageContent(message);\n\n\t\t\t// Stringified content should match\n\t\t\tif (pendingMessage.content !== messageContent) {\n\t\t\t\tconst pendingContentObj = JSON.parse(\n\t\t\t\t\tpendingMessage.content,\n\t\t\t\t) as LocalContainerRuntimeMessage;\n\t\t\t\tconst incomingContentObj = JSON.parse(\n\t\t\t\t\tmessageContent,\n\t\t\t\t) as InboundContainerRuntimeMessage;\n\n\t\t\t\tconst contentsMatch =\n\t\t\t\t\tpendingContentObj.contents === incomingContentObj.contents ||\n\t\t\t\t\t(pendingContentObj.contents !== undefined &&\n\t\t\t\t\t\tincomingContentObj.contents !== undefined &&\n\t\t\t\t\t\tJSON.stringify(pendingContentObj.contents) ===\n\t\t\t\t\t\t\tJSON.stringify(incomingContentObj.contents));\n\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"unexpectedAckReceived\",\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tpendingContentScrubbed: scrubAndStringify(pendingContentObj),\n\t\t\t\t\t\tincomingContentScrubbed: scrubAndStringify(incomingContentObj),\n\t\t\t\t\t\tcontentsMatch,\n\t\t\t\t\t},\n\t\t\t\t});\n\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t\"pending local message content mismatch\",\n\t\t\t\t\t\"unexpectedAckReceived\",\n\t\t\t\t\tmessage,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn pendingMessage.localOpMetadata;\n\t}\n\n\t/**\n\t * Check if the incoming batch matches the batch info for the next pending message.\n\t */\n\tprivate onLocalBatchBegin(batch: InboundBatch) {\n\t\t// Get the next message from the pending queue. Verify a message exists.\n\t\tconst pendingMessage = this.pendingMessages.peekFront();\n\t\tassert(\n\t\t\tpendingMessage !== undefined,\n\t\t\t0xa21 /* No pending message found as we start processing this remote batch */,\n\t\t);\n\n\t\t// Note: This could be undefined if this batch became empty on resubmit.\n\t\t// In this case the next pending message is an empty batch marker.\n\t\t// Empty batches became empty on Resubmit, and submit them and track them in case\n\t\t// a different fork of this container also submitted the same batch (and it may not be empty for that fork).\n\t\tconst firstMessage = batch.messages.length > 0 ? batch.messages[0] : undefined;\n\t\tconst expectedPendingBatchLength = batch.messages.length === 0 ? 1 : batch.messages.length;\n\n\t\t// We expect the incoming batch to be of the same length, starting at the same clientSequenceNumber,\n\t\t// as the batch we originally submitted.\n\t\t// We have another later check to compare the message contents, which we'd expect to fail if this check does,\n\t\t// so we don't throw here, merely log. In a later release this check may replace that one.\n\t\tif (\n\t\t\tpendingMessage.batchInfo.batchStartCsn !== batch.batchStartCsn ||\n\t\t\t(pendingMessage.batchInfo.length >= 0 && // -1 length is back compat and isn't suitable for this check\n\t\t\t\tpendingMessage.batchInfo.length !== expectedPendingBatchLength)\n\t\t) {\n\t\t\tthis.logger?.sendErrorEvent({\n\t\t\t\teventName: \"BatchInfoMismatch\",\n\t\t\t\tdetails: {\n\t\t\t\t\tpendingBatchCsn: pendingMessage.batchInfo.batchStartCsn,\n\t\t\t\t\tbatchStartCsn: batch.batchStartCsn,\n\t\t\t\t\tpendingBatchLength: pendingMessage.batchInfo.length,\n\t\t\t\t\tbatchLength: batch.messages.length,\n\t\t\t\t\tpendingMessageBatchMetadata: asBatchMetadata(pendingMessage.opMetadata)?.batch,\n\t\t\t\t\tmessageBatchMetadata: asBatchMetadata(firstMessage?.metadata)?.batch,\n\t\t\t\t},\n\t\t\t\tmessageDetails: firstMessage && extractSafePropertiesFromMessage(firstMessage),\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n\t * states in its queue. This includes triggering resubmission of unacked ops.\n\t * ! Note: successfully resubmitting an op that has been successfully sequenced is not possible due to checks in the ConnectionStateHandler (Loader layer)\n\t */\n\tpublic replayPendingStates() {\n\t\tassert(\n\t\t\tthis.stateHandler.connected(),\n\t\t\t0x172 /* \"The connection state is not consistent with the runtime\" */,\n\t\t);\n\n\t\t// This assert suggests we are about to send same ops twice, which will result in data loss.\n\t\tassert(\n\t\t\tthis.clientIdFromLastReplay !== this.stateHandler.clientId(),\n\t\t\t0x173 /* \"replayPendingStates called twice for same clientId!\" */,\n\t\t);\n\t\tthis.clientIdFromLastReplay = this.stateHandler.clientId();\n\n\t\tassert(\n\t\t\tthis.initialMessages.isEmpty(),\n\t\t\t0x174 /* \"initial states should be empty before replaying pending\" */,\n\t\t);\n\n\t\tconst initialPendingMessagesCount = this.pendingMessages.length;\n\t\tlet remainingPendingMessagesCount = this.pendingMessages.length;\n\n\t\t// Process exactly `pendingMessagesCount` items in the queue as it represents the number of messages that were\n\t\t// pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n\t\t// which must not be replayed.\n\t\twhile (remainingPendingMessagesCount > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tlet pendingMessage = this.pendingMessages.shift()!;\n\t\t\tremainingPendingMessagesCount--;\n\n\t\t\tconst batchMetadataFlag = asBatchMetadata(pendingMessage.opMetadata)?.batch;\n\t\t\tassert(batchMetadataFlag !== false, 0x41b /* We cannot process batches in chunks */);\n\n\t\t\t// The next message starts a batch (possibly single-message), and we'll need its batchId.\n\t\t\tconst batchId = getEffectiveBatchId(pendingMessage);\n\t\t\t// Resubmit no messages, with the batchId. Will result in another empty batch marker.\n\t\t\tif (asEmptyBatchLocalOpMetadata(pendingMessage.localOpMetadata)?.emptyBatch === true) {\n\t\t\t\tthis.stateHandler.reSubmitBatch([], batchId);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * We must preserve the distinct batches on resubmit.\n\t\t\t * Note: It is not possible for the PendingStateManager to receive a partially acked batch. It will\n\t\t\t * either receive the whole batch ack or nothing at all. @see ScheduleManager for how this works.\n\t\t\t */\n\t\t\tif (batchMetadataFlag === undefined) {\n\t\t\t\t// Single-message batch\n\n\t\t\t\tthis.stateHandler.reSubmitBatch(\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcontent: pendingMessage.content,\n\t\t\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tbatchId,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// else: batchMetadataFlag === true (It's a typical multi-message batch)\n\n\t\t\tassert(\n\t\t\t\tremainingPendingMessagesCount > 0,\n\t\t\t\t0x554 /* Last pending message cannot be a batch begin */,\n\t\t\t);\n\n\t\t\tconst batch: PendingMessageResubmitData[] = [];\n\n\t\t\t// check is >= because batch end may be last pending message\n\t\t\twhile (remainingPendingMessagesCount >= 0) {\n\t\t\t\tbatch.push({\n\t\t\t\t\tcontent: pendingMessage.content,\n\t\t\t\t\tlocalOpMetadata: pendingMessage.localOpMetadata,\n\t\t\t\t\topMetadata: pendingMessage.opMetadata,\n\t\t\t\t});\n\n\t\t\t\tif (pendingMessage.opMetadata?.batch === false) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tassert(remainingPendingMessagesCount > 0, 0x555 /* No batch end found */);\n\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tpendingMessage = this.pendingMessages.shift()!;\n\t\t\t\tremainingPendingMessagesCount--;\n\t\t\t\tassert(\n\t\t\t\t\tpendingMessage.opMetadata?.batch !== true,\n\t\t\t\t\t0x556 /* Batch start needs a corresponding batch end */,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.stateHandler.reSubmitBatch(batch, batchId);\n\t\t}\n\n\t\t// pending ops should no longer depend on previous sequenced local ops after resubmit\n\t\tthis.savedOps = [];\n\n\t\t// We replayPendingStates on read connections too - we expect these to get nack'd though, and to then reconnect\n\t\t// on a write connection and replay again. This filters out the replay that happens on the read connection so\n\t\t// we only see the replays on write connections (that have a chance to go through).\n\t\tif (this.stateHandler.isActiveConnection()) {\n\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\teventName: \"PendingStatesReplayed\",\n\t\t\t\tcount: initialPendingMessagesCount,\n\t\t\t\tclientId: this.stateHandler.clientId(),\n\t\t\t});\n\t\t}\n\t}\n}\n\n/** For back-compat if trying to apply stashed ops that pre-date batchInfo */\nfunction patchbatchInfo(\n\tmessage: IPendingMessageFromStash,\n): asserts message is IPendingMessage {\n\tconst batchInfo: IPendingMessageFromStash[\"batchInfo\"] = message.batchInfo;\n\tif (batchInfo === undefined) {\n\t\t// Using uuid guarantees uniqueness, retaining existing behavior\n\t\tmessage.batchInfo = { clientId: uuid(), batchStartCsn: -1, length: -1 };\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerNode.d.ts","sourceRoot":"","sources":["../../../src/summary/summarizerNode/summarizerNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEN,iBAAiB,EACjB,8BAA8B,EAE9B,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,EACN,mBAAmB,EAMnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,2BAA2B,EAC3B,WAAW,EACX,qBAAqB,EAErB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,mBAAoB,SAAQ,eAAe,EAAE,2BAA2B;CAAG;AAE5F;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,mBAAmB;IAuBxD,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAEpC,OAAO,CAAC,qBAAqB;IAC7B,8CAA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UAAU,EAAE,uBAAuB,GAAG,KAAK;CAW1E;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,WAC5B,mBAAmB,uBACN,mBAAmB,wBAClB,MAAM,2BACH,MAAM,GAAG,SAAS,WACnC,qBAAqB,KAC3B,mBAWD,CAAC"}
1
+ {"version":3,"file":"summarizerNode.d.ts","sourceRoot":"","sources":["../../../src/summary/summarizerNode/summarizerNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACN,aAAa,EACb,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAEN,iBAAiB,EACjB,8BAA8B,EAE9B,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,mBAAmB,EACnB,MAAM,8CAA8C,CAAC;AAEtD,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,EACN,mBAAmB,EAMnB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,2BAA2B,EAC3B,WAAW,EACX,qBAAqB,EAErB,MAAM,0BAA0B,CAAC;AAElC,MAAM,WAAW,mBAAoB,SAAQ,eAAe,EAAE,2BAA2B;CAAG;AAE5F;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,mBAAmB;IAuBxD,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IAEpC,OAAO,CAAC,qBAAqB;IAC7B,8CAA8C;IAC9C,OAAO,CAAC,cAAc,CAAC;IACvB,SAAS,CAAC,gBAAgB,CAAC;IAC3B,oEAAoE;IACpE,SAAS,CAAC,eAAe,CAAC;IA7B3B;;;OAGG;IACH,IAAW,uBAAuB,WAEjC;IAED,SAAS,CAAC,QAAQ,CAAC,QAAQ,8BAAqC;IAChE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,2BAAkC;I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Tree, trackState = true, telemetryContext) {
101
+ // If trackState is false, call summarize internal directly and don't track any state.
102
+ if (!trackState) {
103
+ return this.summarizeInternalFn(fullTree, trackState, telemetryContext);
104
+ }
101
105
  // Try to reuse the tree if unchanged
102
106
  if (this.canReuseHandle && !fullTree && !this.hasChanged()) {
103
107
  const latestSummary = this._latestSummary;
@@ -132,7 +136,7 @@ class SummarizerNode {
132
136
  }
133
137
  : undefined;
134
138
  }
135
- const result = await this.summarizeInternalFn(fullTree, true, telemetryContext, incrementalSummaryContext);
139
+ const result = await this.summarizeInternalFn(fullTree, trackState, telemetryContext, incrementalSummaryContext);
136
140
  this.wipLocalPaths = { localPath: summarizerNodeUtils_js_1.EscapedPath.create(result.id) };
137
141
  if (result.pathPartsForChildren !== undefined) {
138
142
  this.wipLocalPaths.additionalPath = summarizerNodeUtils_js_1.EscapedPath.createAndConcat(result.pathPartsForChildren);
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerNode.js","sourceRoot":"","sources":["../../../src/summary/summarizerNode/summarizerNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA8E;AAC9E,2EAAiE;AAKjE,2EASsD;AACtD,qEAAoE;AAEpE,uEAOkD;AAElD,qEASkC;AAIlC;;;;;;;;;;;;GAYG;AACH,MAAa,cAAc;IAC1B;;;OAGG;IACH,IAAW,uBAAuB;QACjC,OAAO,IAAI,CAAC,cAAc,EAAE,uBAAuB,IAAI,CAAC,CAAC;IAC1D,CAAC;IAUD;;;OAGG;IACH,YACC,UAAgC,EACf,mBAAwC,EACzD,MAA6B,EACrB,qBAA6B;IACrC,8CAA8C;IACtC,cAA4B,EAC1B,gBAAuC;IACjD,oEAAoE;IAC1D,eAAwB;QAPjB,wBAAmB,GAAnB,mBAAmB,CAAqB;QAEjD,0BAAqB,GAArB,qBAAqB,CAAQ;QAE7B,mBAAc,GAAd,cAAc,CAAc;QAC1B,qBAAgB,GAAhB,gBAAgB,CAAuB;QAEvC,oBAAe,GAAf,eAAe,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AW,EAAE,OAAoB;QAC5D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;OAEG;IACI,mBAAmB;QACzB,OAAO,IAAI,CAAC,0BAA0B,KAAK,SAAS,CAAC;IACtD,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,UAAmC;QACjE,MAAM,KAAK,GAAG,IAAI,uBAAY,CAAC,UAAU,CAAC,SAAS,EAAE;YACpD,GAAG,UAAU;YACb,uBAAuB,EAAE,IAAI,CAAC,0BAA0B;YACxD,GAAG,IAAA,2BAAgB,EAAC;gBACnB,EAAE,EAAE,IAAI,CAAC,eAAe;aACxB,CAAC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC9C,MAAM,KAAK,CAAC;IACb,CAAC;CACD;AAhmBD,wCAgmBC;AAED;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,CACvC,MAA2B,EAC3B,mBAAwC,EACxC,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAgC,EAAE,EACZ,EAAE,CACxB,IAAI,cAAc,CACjB,MAAM,EACN,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,uBAAuB,KAAK,SAAS;IACpC,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,oCAAW,CAAC,aAAa,CAAC,uBAAuB,CAAC,EACrD,SAAS,CAAC,sBAAsB,EAChC,EAAE,CAAC,qBAAqB,CACxB,CAAC;AAjBU,QAAA,wBAAwB,4BAiBlC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { SummaryType } from \"@fluidframework/driver-definitions\";\nimport {\n\tISnapshotTree,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIExperimentalIncrementalSummaryContext,\n\tITelemetryContext,\n\tCreateChildSummarizerNodeParam,\n\tCreateSummarizerNodeSource,\n\tISummarizeResult,\n\tISummarizerNode,\n\tISummarizerNodeConfig,\n\tSummarizeInternalFn,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { mergeStats } from \"@fluidframework/runtime-utils/internal\";\nimport { type ITelemetryErrorEventExt } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tLoggingError,\n\tPerformanceEvent,\n\tTelemetryDataTag,\n\tcreateChildLogger,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEscapedPath,\n\tICreateChildDetails,\n\tIRefreshSummaryResult,\n\tIStartSummaryResult,\n\tISummarizerNodeRootContract,\n\tSummaryNode,\n\tValidateSummaryResult,\n\tparseSummaryForSubtrees,\n} from \"./summarizerNodeUtils.js\";\n\nexport interface IRootSummarizerNode extends ISummarizerNode, ISummarizerNodeRootContract {}\n\n/**\n * Encapsulates the summarizing work and state of an individual tree node in the\n * summary tree. It tracks changes and allows for optimizations when unchanged, or\n * can allow for fallback summaries to be generated when an error is encountered.\n * Usage is for the root node to call startSummary first to begin tracking a WIP\n * (work in progress) summary. Then all nodes will call summarize to summaries their\n * individual parts. Once completed and uploaded to storage, the root node will call\n * completeSummary or clearSummary to clear the WIP summary tracking state if something\n * went wrong. The SummarizerNodes will track all pending summaries that have been\n * recorded by the completeSummary call. When one of them is acked, the root node should\n * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline\n * latest successful summary.\n */\nexport class SummarizerNode implements IRootSummarizerNode {\n\t/**\n\t * The reference sequence number of the most recent acked summary.\n\t * Returns 0 if there is not yet an acked summary.\n\t */\n\tpublic get referenceSequenceNumber() {\n\t\treturn this._latestSummary?.referenceSequenceNumber ?? 0;\n\t}\n\n\tprotected readonly children = new Map<string, SummarizerNode>();\n\tprotected readonly pendingSummaries = new Map<string, SummaryNode>();\n\tprotected wipReferenceSequenceNumber: number | undefined;\n\tprivate wipLocalPaths: { localPath: EscapedPath; additionalPath?: EscapedPath } | undefined;\n\tprivate wipSkipRecursion = false;\n\n\tprotected readonly logger: ITelemetryLoggerExt;\n\n\t/**\n\t * Do not call constructor directly.\n\t * Use createRootSummarizerNode to create root node, or createChild to create child nodes.\n\t */\n\tpublic constructor(\n\t\tbaseLogger: ITelemetryBaseLogger,\n\t\tprivate readonly summarizeInternalFn: SummarizeInternalFn,\n\t\tconfig: ISummarizerNodeConfig,\n\t\tprivate _changeSequenceNumber: number,\n\t\t/** Undefined means created without summary */\n\t\tprivate _latestSummary?: SummaryNode,\n\t\tprotected wipSummaryLogger?: ITelemetryBaseLogger,\n\t\t/** A unique id of this node to be logged when sending telemetry. */\n\t\tprotected telemetryNodeId?: string,\n\t) {\n\t\tthis.canReuseHandle = config.canReuseHandle ?? true;\n\t\t// All logs posted by the summarizer node should include the telemetryNodeId.\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: baseLogger,\n\t\t\tproperties: {\n\t\t\t\tall: tagCodeArtifacts({ id: this.telemetryNodeId }),\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * In order to produce a summary with a summarizer node, the summarizer node system must be notified a summary has\n\t * started. This is done by calling startSummary. This will track the reference sequence number of the summary and\n\t * run some validation checks to ensure the summary is correct.\n\t * @param referenceSequenceNumber - the number of ops processed up to this point\n\t * @param summaryLogger - the logger to use for the summary\n\t * @param latestSummaryRefSeqNum - the reference sequence number of the latest summary. Another way to think about\n\t * it is the reference sequence number of the previous summary.\n\t * @returns the number of nodes in the tree, the number of nodes that are invalid, and the different types of\n\t * sequence number mismatches\n\t */\n\tpublic startSummary(\n\t\treferenceSequenceNumber: number,\n\t\tsummaryLogger: ITelemetryBaseLogger,\n\t\tlatestSummaryRefSeqNum: number,\n\t): IStartSummaryResult {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger === undefined,\n\t\t\t0x19f /* \"wipSummaryLogger should not be set yet in startSummary\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.wipReferenceSequenceNumber === undefined,\n\t\t\t0x1a0 /* \"Already tracking a summary\" */,\n\t\t);\n\n\t\tlet nodes = 1;\n\t\tlet invalidNodes = 0;\n\t\tconst sequenceNumberMismatchKeySet = new Set<string>();\n\t\tconst nodeLatestSummaryRefSeqNum = this._latestSummary?.referenceSequenceNumber;\n\t\tif (\n\t\t\tnodeLatestSummaryRefSeqNum !== undefined &&\n\t\t\tlatestSummaryRefSeqNum !== nodeLatestSummaryRefSeqNum\n\t\t) {\n\t\t\tinvalidNodes++;\n\t\t\tsequenceNumberMismatchKeySet.add(\n\t\t\t\t`${latestSummaryRefSeqNum}-${nodeLatestSummaryRefSeqNum}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.wipSummaryLogger = summaryLogger;\n\n\t\tfor (const child of this.children.values()) {\n\t\t\tconst childStartSummaryResult = child.startSummary(\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tthis.wipSummaryLogger,\n\t\t\t\tlatestSummaryRefSeqNum,\n\t\t\t);\n\t\t\tnodes += childStartSummaryResult.nodes;\n\t\t\tinvalidNodes += childStartSummaryResult.invalidNodes;\n\t\t\tfor (const invalidSequenceNumber of childStartSummaryResult.mismatchNumbers) {\n\t\t\t\tsequenceNumberMismatchKeySet.add(invalidSequenceNumber);\n\t\t\t}\n\t\t}\n\t\tthis.wipReferenceSequenceNumber = referenceSequenceNumber;\n\t\treturn {\n\t\t\tnodes,\n\t\t\tinvalidNodes,\n\t\t\tmismatchNumbers: sequenceNumberMismatchKeySet,\n\t\t};\n\t}\n\n\tpublic async summarize(\n\t\tfullTree: boolean,\n\t\ttrackState: boolean = true,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummarizeResult> {\n\t\t// Try to reuse the tree if unchanged\n\t\tif (this.canReuseHandle && !fullTree && !this.hasChanged()) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\tthis.wipLocalPaths = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t\tthis.wipSkipRecursion = true;\n\t\t\t\tconst stats = mergeStats();\n\t\t\t\tstats.handleNodeCount++;\n\t\t\t\treturn {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\ttype: SummaryType.Handle,\n\t\t\t\t\t\thandle: latestSummary.fullPath.path,\n\t\t\t\t\t\thandleType: SummaryType.Tree,\n\t\t\t\t\t},\n\t\t\t\t\tstats,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tlet incrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;\n\t\tif (!fullTree) {\n\t\t\tassert(\n\t\t\t\tthis.wipReferenceSequenceNumber !== undefined,\n\t\t\t\t0x5df /* Summarize should not be called when not tracking the summary */,\n\t\t\t);\n\t\t\tincrementalSummaryContext =\n\t\t\t\tthis._latestSummary !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsummarySequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\t\t\t\t\tlatestSummarySequenceNumber: this._latestSummary.referenceSequenceNumber,\n\t\t\t\t\t\t\t// TODO: remove summaryPath\n\t\t\t\t\t\t\tsummaryPath: this._latestSummary.fullPath.path,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tconst result = await this.summarizeInternalFn(\n\t\t\tfullTree,\n\t\t\ttrue,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.wipLocalPaths = { localPath: EscapedPath.create(result.id) };\n\t\tif (result.pathPartsForChildren !== undefined) {\n\t\t\tthis.wipLocalPaths.additionalPath = EscapedPath.createAndConcat(\n\t\t\t\tresult.pathPartsForChildren,\n\t\t\t);\n\t\t}\n\t\treturn { summary: result.summary, stats: result.stats };\n\t}\n\n\t/**\n\t * Validates that the in-progress summary is correct, i.e., summarize should have run for all non-skipped\n\t * nodes. This will only be called for the root summarizer node and is called by it recursively on all child nodes.\n\t *\n\t * @returns ValidateSummaryResult which contains a boolean success indicating whether the validation was successful.\n\t * In case of failure, additional information is returned indicating type of failure and where it was.\n\t */\n\tpublic validateSummary(): ValidateSummaryResult {\n\t\treturn this.validateSummaryCore(false /* parentSkipRecursion */);\n\t}\n\n\t/**\n\t * Validates that the in-progress summary is correct for all nodes, i.e., summarize should have run for all\n\t * non-skipped nodes.\n\t * @param parentSkipRecursion - true if the parent of this node skipped recursing the child nodes when summarizing.\n\t * In that case, the children will not have work-in-progress state.\n\t *\n\t * @returns ValidateSummaryResult which contains a boolean success indicating whether the validation was successful.\n\t * In case of failure, additional information is returned indicating type of failure and where it was.\n\t */\n\tprotected validateSummaryCore(parentSkipRecursion: boolean): ValidateSummaryResult {\n\t\tif (this.wasSummarizeMissed(parentSkipRecursion)) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\treason: \"NodeDidNotSummarize\",\n\t\t\t\tid: {\n\t\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\t\tvalue: this.telemetryNodeId,\n\t\t\t\t},\n\t\t\t\t// These errors are usually transient and should go away when summarize is retried.\n\t\t\t\tretryAfterSeconds: 1,\n\t\t\t};\n\t\t}\n\t\tif (parentSkipRecursion) {\n\t\t\treturn { success: true };\n\t\t}\n\n\t\tfor (const child of this.children.values()) {\n\t\t\tconst result = child.validateSummaryCore(this.wipSkipRecursion || parentSkipRecursion);\n\t\t\t// If any child fails, return the failure.\n\t\t\tif (!result.success) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t\treturn { success: true };\n\t}\n\n\tprivate wasSummarizeMissed(parentSkipRecursion: boolean): boolean {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger !== undefined,\n\t\t\t0x6fc /* wipSummaryLogger should have been set in startSummary or ctor */,\n\t\t);\n\t\tassert(this.wipReferenceSequenceNumber !== undefined, 0x6fd /* Not tracking a summary */);\n\n\t\t// If the parent node skipped recursion, it did not call summarize on this node. So, summarize was not missed\n\t\t// but was intentionally not called.\n\t\t// Otherwise, summarize should have been called on this node and wipLocalPaths must be set.\n\t\tif (parentSkipRecursion || this.wipLocalPaths !== undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\t/**\n\t\t * The absence of wip local path indicates that summarize was not called for this node. Return failure.\n\t\t * This can happen if:\n\t\t * 1. A child node was created after summarize was already called on the parent. For example, a data store\n\t\t * is realized (loaded) after summarize was called on it creating summarizer nodes for its DDSes. In this case,\n\t\t * parentSkipRecursion will be true and the if block above would handle it.\n\t\t * 2. A new node was created but summarize was never called on it. This can mean that the summary that is\n\t\t * generated may not have the data from this node. We should not continue, log and throw an error. This\n\t\t * will help us identify these cases and take appropriate action.\n\t\t *\n\t\t * This happens due to scenarios such as data store created during summarize. Such errors should go away when\n\t\t * summarize is attempted again.\n\t\t */\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending summary\n\t * queue. We track this until we get an ack from the server for this summary.\n\t * @param proposalHandle - The handle of the summary that was uploaded to the server.\n\t */\n\tpublic completeSummary(proposalHandle: string) {\n\t\tthis.completeSummaryCore(\n\t\t\tproposalHandle,\n\t\t\tundefined /* parentPath */,\n\t\t\tfalse /* parentSkipRecursion */,\n\t\t);\n\t}\n\n\t/**\n\t * Recursive implementation for completeSummary, with additional internal-only parameters.\n\t * @param proposalHandle - The handle of the summary that was uploaded to the server.\n\t * @param parentPath - The path of the parent node which is used to build the path of this node.\n\t * @param parentSkipRecursion - true if the parent of this node skipped recursing the child nodes when summarizing.\n\t * In that case, the children will not have work-in-progress state.\n\t * @param validate - true to validate that the in-progress summary is correct for all nodes.\n\t */\n\tprotected completeSummaryCore(\n\t\tproposalHandle: string,\n\t\tparentPath: EscapedPath | undefined,\n\t\tparentSkipRecursion: boolean,\n\t) {\n\t\tassert(\n\t\t\tthis.wipReferenceSequenceNumber !== undefined,\n\t\t\t0x1a4 /* \"Not tracking a summary\" */,\n\t\t);\n\t\tlet localPathsToUse = this.wipLocalPaths;\n\n\t\tif (parentSkipRecursion) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\t// This case the parent node created a failure summary or was reused.\n\t\t\t\t// This node and all children should only try to reference their path\n\t\t\t\t// by its last known good state in the actual summary tree.\n\t\t\t\t// If parent fails or is reused, the child summarize is not called so\n\t\t\t\t// it did not get a chance to change its paths.\n\t\t\t\t// In this case, essentially only propagate the new summary ref seq num.\n\t\t\t\tlocalPathsToUse = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// This case the child is added after the latest non-failure summary.\n\t\t\t\t// This node and all children should consider themselves as still not\n\t\t\t\t// having a successful summary yet.\n\t\t\t\t// We cannot \"reuse\" this node if unchanged since that summary, because\n\t\t\t\t// handles will be unable to point to that node. It never made it to the\n\t\t\t\t// tree itself, and only exists as an attach op in the _outstandingOps.\n\t\t\t\tthis.clearSummary();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If localPathsToUse is undefined, it means summarize didn't run for this node and in that case the validate\n\t\t// step should have failed.\n\t\tassert(localPathsToUse !== undefined, 0x6fe /* summarize didn't run for node */);\n\t\tconst summary = new SummaryNode({\n\t\t\t...localPathsToUse,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\tbasePath: parentPath,\n\t\t});\n\t\tconst fullPathForChildren = summary.fullPathForChildren;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.completeSummaryCore(\n\t\t\t\tproposalHandle,\n\t\t\t\tfullPathForChildren,\n\t\t\t\tthis.wipSkipRecursion || parentSkipRecursion,\n\t\t\t);\n\t\t}\n\t\t// Note that this overwrites existing pending summary with\n\t\t// the same proposalHandle. If proposalHandle is something like\n\t\t// a hash or unique identifier, this should be fine. If storage\n\t\t// can return the same proposalHandle for a different summary,\n\t\t// this should still be okay, because we should be proposing the\n\t\t// newer one later which would have to overwrite the previous one.\n\t\tthis.pendingSummaries.set(proposalHandle, summary);\n\t\tthis.clearSummary();\n\t}\n\n\tpublic clearSummary() {\n\t\tthis.wipReferenceSequenceNumber = undefined;\n\t\tthis.wipLocalPaths = undefined;\n\t\tthis.wipSkipRecursion = false;\n\t\tthis.wipSummaryLogger = undefined;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.clearSummary();\n\t\t}\n\t}\n\n\t/**\n\t * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,\n\t * it becomes the latest summary. If the current summary is already ahead, we skip the update.\n\t * If the current summary is behind, then we do not refresh.\n\t *\n\t * @returns true if the summary is tracked by this node, false otherwise.\n\t */\n\tpublic async refreshLatestSummary(\n\t\tproposalHandle: string,\n\t\tsummaryRefSeq: number,\n\t): Promise<IRefreshSummaryResult> {\n\t\tconst eventProps: {\n\t\t\tproposalHandle: string | undefined;\n\t\t\tsummaryRefSeq: number;\n\t\t\treferenceSequenceNumber: number;\n\t\t\tisSummaryTracked?: boolean;\n\t\t\tpendingSummaryFound?: boolean;\n\t\t} = {\n\t\t\tproposalHandle,\n\t\t\tsummaryRefSeq,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t};\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"refreshLatestSummary\",\n\t\t\t\t...eventProps,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\t// Refresh latest summary should not happen while a summary is in progress. If it does, it can result\n\t\t\t\t// in inconsistent state, so, we should not continue;\n\t\t\t\tif (this.isSummaryInProgress()) {\n\t\t\t\t\tthrow new LoggingError(\"UnexpectedRefreshDuringSummarize\", {\n\t\t\t\t\t\tinProgressSummaryRefSeq: this.wipReferenceSequenceNumber,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tlet isSummaryTracked = false;\n\t\t\t\tlet isSummaryNewer = false;\n\n\t\t\t\tif (summaryRefSeq > this.referenceSequenceNumber) {\n\t\t\t\t\tisSummaryNewer = true;\n\t\t\t\t}\n\t\t\t\tconst maybeSummaryNode = this.pendingSummaries.get(proposalHandle);\n\t\t\t\tif (maybeSummaryNode !== undefined) {\n\t\t\t\t\tthis.refreshLatestSummaryFromPending(\n\t\t\t\t\t\tproposalHandle,\n\t\t\t\t\t\tmaybeSummaryNode.referenceSequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tisSummaryTracked = true;\n\t\t\t\t}\n\t\t\t\tevent.end({ ...eventProps, isSummaryNewer, pendingSummaryFound: isSummaryTracked });\n\t\t\t\treturn { isSummaryTracked, isSummaryNewer };\n\t\t\t},\n\t\t\t{ start: true, end: true, cancel: \"error\" },\n\t\t);\n\t}\n\t/**\n\t * Called when we get an ack from the server for a summary we've just sent. Updates the reference state of this node\n\t * from the state in the pending summary queue.\n\t * @param proposalHandle - Handle for the current proposal.\n\t * @param referenceSequenceNumber - Reference sequence number of sent summary.\n\t */\n\tprotected refreshLatestSummaryFromPending(\n\t\tproposalHandle: string,\n\t\treferenceSequenceNumber: number,\n\t): void {\n\t\tconst summaryNode = this.pendingSummaries.get(proposalHandle);\n\t\tif (summaryNode === undefined) {\n\t\t\t// This should only happen if parent skipped recursion AND no prior summary existed.\n\t\t\tassert(\n\t\t\t\tthis._latestSummary === undefined,\n\t\t\t\t0x1a6 /* \"Not found pending summary, but this node has previously completed a summary\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\treferenceSequenceNumber === summaryNode.referenceSequenceNumber,\n\t\t\t\t0x1a7 /* Pending summary reference sequence number should be consistent */,\n\t\t\t);\n\n\t\t\t// Clear earlier pending summaries\n\t\t\tthis.pendingSummaries.delete(proposalHandle);\n\t\t}\n\n\t\tthis.refreshLatestSummaryCore(referenceSequenceNumber);\n\n\t\tthis._latestSummary = summaryNode;\n\t\t// Propagate update to all child nodes\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);\n\t\t}\n\t}\n\n\tprivate refreshLatestSummaryCore(referenceSequenceNumber: number): void {\n\t\tfor (const [key, value] of this.pendingSummaries) {\n\t\t\tif (value.referenceSequenceNumber < referenceSequenceNumber) {\n\t\t\t\tthis.pendingSummaries.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic updateBaseSummaryState(snapshot: ISnapshotTree) {\n\t\t// Check base summary to see if it has any additional path parts\n\t\t// separating child SummarizerNodes. Checks for .channels subtrees.\n\t\tconst { childrenPathPart } = parseSummaryForSubtrees(snapshot);\n\t\tif (childrenPathPart !== undefined && this._latestSummary !== undefined) {\n\t\t\tthis._latestSummary.additionalPath = EscapedPath.create(childrenPathPart);\n\t\t}\n\t}\n\n\tpublic recordChange(op: ISequencedDocumentMessage): void {\n\t\tthis.invalidate(op.sequenceNumber);\n\t}\n\n\tpublic invalidate(sequenceNumber: number): void {\n\t\tif (sequenceNumber > this._changeSequenceNumber) {\n\t\t\tthis._changeSequenceNumber = sequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * True if a change has been recorded with sequence number exceeding\n\t * the latest successfully acked summary reference sequence number.\n\t * False implies that the previous summary can be reused.\n\t */\n\tprotected hasChanged(): boolean {\n\t\treturn this._changeSequenceNumber > this.referenceSequenceNumber;\n\t}\n\n\tpublic get latestSummary(): Readonly<SummaryNode> | undefined {\n\t\treturn this._latestSummary;\n\t}\n\n\tprotected readonly canReuseHandle: boolean;\n\n\tpublic createChild(\n\t\t/** Summarize function */\n\t\tsummarizeInternalFn: SummarizeInternalFn,\n\t\t/** Initial id or path part of this node */\n\t\tid: string,\n\t\t/**\n\t\t * Information needed to create the node.\n\t\t * If it is from a base summary, it will assert that a summary has been seen.\n\t\t * Attach information if it is created from an attach op.\n\t\t */\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t\tconfig: ISummarizerNodeConfig = {},\n\t): ISummarizerNode {\n\t\tassert(!this.children.has(id), 0x1ab /* \"Create SummarizerNode child already exists\" */);\n\n\t\tconst createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);\n\t\tconst child = new SummarizerNode(\n\t\t\tthis.logger,\n\t\t\tsummarizeInternalFn,\n\t\t\tconfig,\n\t\t\tcreateDetails.changeSequenceNumber,\n\t\t\tcreateDetails.latestSummary,\n\t\t\tthis.wipSummaryLogger,\n\t\t\tcreateDetails.telemetryNodeId,\n\t\t);\n\n\t\t// There may be additional state that has to be updated in this child. For example, if a summary is being\n\t\t// tracked, the child's summary tracking state needs to be updated too. Same goes for pendingSummaries we might\n\t\t// have outstanding on the parent in case we realize nodes in between Summary Op and Summary Ack.\n\t\tthis.maybeUpdateChildState(child, id);\n\n\t\tthis.children.set(id, child);\n\t\treturn child;\n\t}\n\n\tpublic getChild(id: string): ISummarizerNode | undefined {\n\t\treturn this.children.get(id);\n\t}\n\n\t/**\n\t * Returns the details needed to create a child node.\n\t * @param id - Initial id or path part of the child node.\n\t * @param createParam - Information needed to create the node.\n\t * @returns the details needed to create the child node.\n\t */\n\tprotected getCreateDetailsForChild(\n\t\tid: string,\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t): ICreateChildDetails {\n\t\tlet latestSummary: SummaryNode | undefined;\n\t\tlet changeSequenceNumber: number;\n\n\t\tconst parentLatestSummary = this._latestSummary;\n\t\tswitch (createParam.type) {\n\t\t\tcase CreateSummarizerNodeSource.FromAttach: {\n\t\t\t\tif (\n\t\t\t\t\tparentLatestSummary !== undefined &&\n\t\t\t\t\tcreateParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\t// Prioritize latest summary if it was after this node was attached.\n\t\t\t\t\tlatestSummary = parentLatestSummary.createForChild(id);\n\t\t\t\t}\n\t\t\t\tchangeSequenceNumber = createParam.sequenceNumber;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase CreateSummarizerNodeSource.FromSummary:\n\t\t\tcase CreateSummarizerNodeSource.Local: {\n\t\t\t\tlatestSummary = parentLatestSummary?.createForChild(id);\n\t\t\t\tchangeSequenceNumber = parentLatestSummary?.referenceSequenceNumber ?? -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst type = (createParam as unknown as CreateChildSummarizerNodeParam).type;\n\t\t\t\tunreachableCase(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);\n\t\t\t}\n\t\t}\n\n\t\tconst childTelemetryNodeId = `${this.telemetryNodeId ?? \"\"}/${id}`;\n\n\t\treturn {\n\t\t\tlatestSummary,\n\t\t\tchangeSequenceNumber,\n\t\t\ttelemetryNodeId: childTelemetryNodeId,\n\t\t};\n\t}\n\n\t/**\n\t * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's\n\t * summary tracking state needs to be updated too.\n\t * Also, in case a child node gets realized in between Summary Op and Summary Ack, let's initialize the child's\n\t * pending summary as well.\n\t * @param child - The child node whose state is to be updated.\n\t * @param id - Initial id or path part of this node\n\t *\n\t */\n\tprotected maybeUpdateChildState(child: SummarizerNode, id: string) {\n\t\t// If a summary is in progress, this child was created after the summary started. So, we need to update the\n\t\t// child's summary state as well.\n\t\tif (this.isSummaryInProgress()) {\n\t\t\tchild.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;\n\t\t}\n\t\t// In case we have pending summaries on the parent, let's initialize it on the child.\n\t\tif (child._latestSummary !== undefined) {\n\t\t\tfor (const [key, value] of this.pendingSummaries.entries()) {\n\t\t\t\tconst newLatestSummaryNode = new SummaryNode({\n\t\t\t\t\treferenceSequenceNumber: value.referenceSequenceNumber,\n\t\t\t\t\tbasePath: child._latestSummary.basePath,\n\t\t\t\t\tlocalPath: child._latestSummary.localPath,\n\t\t\t\t});\n\n\t\t\t\tchild.addPendingSummary(key, newLatestSummaryNode);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected addPendingSummary(key: string, summary: SummaryNode) {\n\t\tthis.pendingSummaries.set(key, summary);\n\t}\n\n\t/**\n\t * Tells whether summary tracking is in progress. True if \"startSummary\" API is called before summarize.\n\t */\n\tpublic isSummaryInProgress(): boolean {\n\t\treturn this.wipReferenceSequenceNumber !== undefined;\n\t}\n\n\t/**\n\t * Creates and throws an error due to unexpected conditions.\n\t */\n\tprotected throwUnexpectedError(eventProps: ITelemetryErrorEventExt): never {\n\t\tconst error = new LoggingError(eventProps.eventName, {\n\t\t\t...eventProps,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\t...tagCodeArtifacts({\n\t\t\t\tid: this.telemetryNodeId,\n\t\t\t}),\n\t\t});\n\t\tthis.logger.sendErrorEvent(eventProps, error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Creates a root summarizer node.\n * @param logger - Logger to use within SummarizerNode\n * @param summarizeInternalFn - Function to generate summary\n * @param changeSequenceNumber - Sequence number of latest change to new node/subtree\n * @param referenceSequenceNumber - Reference sequence number of last acked summary,\n * or undefined if not loaded from summary\n * @param config - Configure behavior of summarizer node\n */\nexport const createRootSummarizerNode = (\n\tlogger: ITelemetryLoggerExt,\n\tsummarizeInternalFn: SummarizeInternalFn,\n\tchangeSequenceNumber: number,\n\treferenceSequenceNumber: number | undefined,\n\tconfig: ISummarizerNodeConfig = {},\n): IRootSummarizerNode =>\n\tnew SummarizerNode(\n\t\tlogger,\n\t\tsummarizeInternalFn,\n\t\tconfig,\n\t\tchangeSequenceNumber,\n\t\treferenceSequenceNumber === undefined\n\t\t\t? undefined\n\t\t\t: SummaryNode.createForRoot(referenceSequenceNumber),\n\t\tundefined /* wipSummaryLogger */,\n\t\t\"\" /* telemetryNodeId */,\n\t);\n"]}
1
+ {"version":3,"file":"summarizerNode.js","sourceRoot":"","sources":["../../../src/summary/summarizerNode/summarizerNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA8E;AAC9E,2EAAiE;AAKjE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D;AArmBD,wCAqmBC;AAED;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,CACvC,MAA2B,EAC3B,mBAAwC,EACxC,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAgC,EAAE,EACZ,EAAE,CACxB,IAAI,cAAc,CACjB,MAAM,EACN,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,uBAAuB,KAAK,SAAS;IACpC,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,oCAAW,CAAC,aAAa,CAAC,uBAAuB,CAAC,EACrD,SAAS,CAAC,sBAAsB,EAChC,EAAE,CAAC,qBAAqB,CACxB,CAAC;AAjBU,QAAA,wBAAwB,4BAiBlC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { SummaryType } from \"@fluidframework/driver-definitions\";\nimport {\n\tISnapshotTree,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tIExperimentalIncrementalSummaryContext,\n\tITelemetryContext,\n\tCreateChildSummarizerNodeParam,\n\tCreateSummarizerNodeSource,\n\tISummarizeResult,\n\tISummarizerNode,\n\tISummarizerNodeConfig,\n\tSummarizeInternalFn,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { mergeStats } from \"@fluidframework/runtime-utils/internal\";\nimport { type ITelemetryErrorEventExt } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tLoggingError,\n\tPerformanceEvent,\n\tTelemetryDataTag,\n\tcreateChildLogger,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEscapedPath,\n\tICreateChildDetails,\n\tIRefreshSummaryResult,\n\tIStartSummaryResult,\n\tISummarizerNodeRootContract,\n\tSummaryNode,\n\tValidateSummaryResult,\n\tparseSummaryForSubtrees,\n} from \"./summarizerNodeUtils.js\";\n\nexport interface IRootSummarizerNode extends ISummarizerNode, ISummarizerNodeRootContract {}\n\n/**\n * Encapsulates the summarizing work and state of an individual tree node in the\n * summary tree. It tracks changes and allows for optimizations when unchanged, or\n * can allow for fallback summaries to be generated when an error is encountered.\n * Usage is for the root node to call startSummary first to begin tracking a WIP\n * (work in progress) summary. Then all nodes will call summarize to summaries their\n * individual parts. Once completed and uploaded to storage, the root node will call\n * completeSummary or clearSummary to clear the WIP summary tracking state if something\n * went wrong. The SummarizerNodes will track all pending summaries that have been\n * recorded by the completeSummary call. When one of them is acked, the root node should\n * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline\n * latest successful summary.\n */\nexport class SummarizerNode implements IRootSummarizerNode {\n\t/**\n\t * The reference sequence number of the most recent acked summary.\n\t * Returns 0 if there is not yet an acked summary.\n\t */\n\tpublic get referenceSequenceNumber() {\n\t\treturn this._latestSummary?.referenceSequenceNumber ?? 0;\n\t}\n\n\tprotected readonly children = new Map<string, SummarizerNode>();\n\tprotected readonly pendingSummaries = new Map<string, SummaryNode>();\n\tprotected wipReferenceSequenceNumber: number | undefined;\n\tprivate wipLocalPaths: { localPath: EscapedPath; additionalPath?: EscapedPath } | undefined;\n\tprivate wipSkipRecursion = false;\n\n\tprotected readonly logger: ITelemetryLoggerExt;\n\n\t/**\n\t * Do not call constructor directly.\n\t * Use createRootSummarizerNode to create root node, or createChild to create child nodes.\n\t */\n\tpublic constructor(\n\t\tbaseLogger: ITelemetryBaseLogger,\n\t\tprivate readonly summarizeInternalFn: SummarizeInternalFn,\n\t\tconfig: ISummarizerNodeConfig,\n\t\tprivate _changeSequenceNumber: number,\n\t\t/** Undefined means created without summary */\n\t\tprivate _latestSummary?: SummaryNode,\n\t\tprotected wipSummaryLogger?: ITelemetryBaseLogger,\n\t\t/** A unique id of this node to be logged when sending telemetry. */\n\t\tprotected telemetryNodeId?: string,\n\t) {\n\t\tthis.canReuseHandle = config.canReuseHandle ?? true;\n\t\t// All logs posted by the summarizer node should include the telemetryNodeId.\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: baseLogger,\n\t\t\tproperties: {\n\t\t\t\tall: tagCodeArtifacts({ id: this.telemetryNodeId }),\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * In order to produce a summary with a summarizer node, the summarizer node system must be notified a summary has\n\t * started. This is done by calling startSummary. This will track the reference sequence number of the summary and\n\t * run some validation checks to ensure the summary is correct.\n\t * @param referenceSequenceNumber - the number of ops processed up to this point\n\t * @param summaryLogger - the logger to use for the summary\n\t * @param latestSummaryRefSeqNum - the reference sequence number of the latest summary. Another way to think about\n\t * it is the reference sequence number of the previous summary.\n\t * @returns the number of nodes in the tree, the number of nodes that are invalid, and the different types of\n\t * sequence number mismatches\n\t */\n\tpublic startSummary(\n\t\treferenceSequenceNumber: number,\n\t\tsummaryLogger: ITelemetryBaseLogger,\n\t\tlatestSummaryRefSeqNum: number,\n\t): IStartSummaryResult {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger === undefined,\n\t\t\t0x19f /* \"wipSummaryLogger should not be set yet in startSummary\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.wipReferenceSequenceNumber === undefined,\n\t\t\t0x1a0 /* \"Already tracking a summary\" */,\n\t\t);\n\n\t\tlet nodes = 1;\n\t\tlet invalidNodes = 0;\n\t\tconst sequenceNumberMismatchKeySet = new Set<string>();\n\t\tconst nodeLatestSummaryRefSeqNum = this._latestSummary?.referenceSequenceNumber;\n\t\tif (\n\t\t\tnodeLatestSummaryRefSeqNum !== undefined &&\n\t\t\tlatestSummaryRefSeqNum !== nodeLatestSummaryRefSeqNum\n\t\t) {\n\t\t\tinvalidNodes++;\n\t\t\tsequenceNumberMismatchKeySet.add(\n\t\t\t\t`${latestSummaryRefSeqNum}-${nodeLatestSummaryRefSeqNum}`,\n\t\t\t);\n\t\t}\n\n\t\tthis.wipSummaryLogger = summaryLogger;\n\n\t\tfor (const child of this.children.values()) {\n\t\t\tconst childStartSummaryResult = child.startSummary(\n\t\t\t\treferenceSequenceNumber,\n\t\t\t\tthis.wipSummaryLogger,\n\t\t\t\tlatestSummaryRefSeqNum,\n\t\t\t);\n\t\t\tnodes += childStartSummaryResult.nodes;\n\t\t\tinvalidNodes += childStartSummaryResult.invalidNodes;\n\t\t\tfor (const invalidSequenceNumber of childStartSummaryResult.mismatchNumbers) {\n\t\t\t\tsequenceNumberMismatchKeySet.add(invalidSequenceNumber);\n\t\t\t}\n\t\t}\n\t\tthis.wipReferenceSequenceNumber = referenceSequenceNumber;\n\t\treturn {\n\t\t\tnodes,\n\t\t\tinvalidNodes,\n\t\t\tmismatchNumbers: sequenceNumberMismatchKeySet,\n\t\t};\n\t}\n\n\tpublic async summarize(\n\t\tfullTree: boolean,\n\t\ttrackState: boolean = true,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummarizeResult> {\n\t\t// If trackState is false, call summarize internal directly and don't track any state.\n\t\tif (!trackState) {\n\t\t\treturn this.summarizeInternalFn(fullTree, trackState, telemetryContext);\n\t\t}\n\n\t\t// Try to reuse the tree if unchanged\n\t\tif (this.canReuseHandle && !fullTree && !this.hasChanged()) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\tthis.wipLocalPaths = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t\tthis.wipSkipRecursion = true;\n\t\t\t\tconst stats = mergeStats();\n\t\t\t\tstats.handleNodeCount++;\n\t\t\t\treturn {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\ttype: SummaryType.Handle,\n\t\t\t\t\t\thandle: latestSummary.fullPath.path,\n\t\t\t\t\t\thandleType: SummaryType.Tree,\n\t\t\t\t\t},\n\t\t\t\t\tstats,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tlet incrementalSummaryContext: IExperimentalIncrementalSummaryContext | undefined;\n\t\tif (!fullTree) {\n\t\t\tassert(\n\t\t\t\tthis.wipReferenceSequenceNumber !== undefined,\n\t\t\t\t0x5df /* Summarize should not be called when not tracking the summary */,\n\t\t\t);\n\t\t\tincrementalSummaryContext =\n\t\t\t\tthis._latestSummary !== undefined\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tsummarySequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\t\t\t\t\tlatestSummarySequenceNumber: this._latestSummary.referenceSequenceNumber,\n\t\t\t\t\t\t\t// TODO: remove summaryPath\n\t\t\t\t\t\t\tsummaryPath: this._latestSummary.fullPath.path,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tconst result = await this.summarizeInternalFn(\n\t\t\tfullTree,\n\t\t\ttrackState,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.wipLocalPaths = { localPath: EscapedPath.create(result.id) };\n\t\tif (result.pathPartsForChildren !== undefined) {\n\t\t\tthis.wipLocalPaths.additionalPath = EscapedPath.createAndConcat(\n\t\t\t\tresult.pathPartsForChildren,\n\t\t\t);\n\t\t}\n\t\treturn { summary: result.summary, stats: result.stats };\n\t}\n\n\t/**\n\t * Validates that the in-progress summary is correct, i.e., summarize should have run for all non-skipped\n\t * nodes. This will only be called for the root summarizer node and is called by it recursively on all child nodes.\n\t *\n\t * @returns ValidateSummaryResult which contains a boolean success indicating whether the validation was successful.\n\t * In case of failure, additional information is returned indicating type of failure and where it was.\n\t */\n\tpublic validateSummary(): ValidateSummaryResult {\n\t\treturn this.validateSummaryCore(false /* parentSkipRecursion */);\n\t}\n\n\t/**\n\t * Validates that the in-progress summary is correct for all nodes, i.e., summarize should have run for all\n\t * non-skipped nodes.\n\t * @param parentSkipRecursion - true if the parent of this node skipped recursing the child nodes when summarizing.\n\t * In that case, the children will not have work-in-progress state.\n\t *\n\t * @returns ValidateSummaryResult which contains a boolean success indicating whether the validation was successful.\n\t * In case of failure, additional information is returned indicating type of failure and where it was.\n\t */\n\tprotected validateSummaryCore(parentSkipRecursion: boolean): ValidateSummaryResult {\n\t\tif (this.wasSummarizeMissed(parentSkipRecursion)) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\treason: \"NodeDidNotSummarize\",\n\t\t\t\tid: {\n\t\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\t\tvalue: this.telemetryNodeId,\n\t\t\t\t},\n\t\t\t\t// These errors are usually transient and should go away when summarize is retried.\n\t\t\t\tretryAfterSeconds: 1,\n\t\t\t};\n\t\t}\n\t\tif (parentSkipRecursion) {\n\t\t\treturn { success: true };\n\t\t}\n\n\t\tfor (const child of this.children.values()) {\n\t\t\tconst result = child.validateSummaryCore(this.wipSkipRecursion || parentSkipRecursion);\n\t\t\t// If any child fails, return the failure.\n\t\t\tif (!result.success) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t\treturn { success: true };\n\t}\n\n\tprivate wasSummarizeMissed(parentSkipRecursion: boolean): boolean {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger !== undefined,\n\t\t\t0x6fc /* wipSummaryLogger should have been set in startSummary or ctor */,\n\t\t);\n\t\tassert(this.wipReferenceSequenceNumber !== undefined, 0x6fd /* Not tracking a summary */);\n\n\t\t// If the parent node skipped recursion, it did not call summarize on this node. So, summarize was not missed\n\t\t// but was intentionally not called.\n\t\t// Otherwise, summarize should have been called on this node and wipLocalPaths must be set.\n\t\tif (parentSkipRecursion || this.wipLocalPaths !== undefined) {\n\t\t\treturn false;\n\t\t}\n\n\t\t/**\n\t\t * The absence of wip local path indicates that summarize was not called for this node. Return failure.\n\t\t * This can happen if:\n\t\t * 1. A child node was created after summarize was already called on the parent. For example, a data store\n\t\t * is realized (loaded) after summarize was called on it creating summarizer nodes for its DDSes. In this case,\n\t\t * parentSkipRecursion will be true and the if block above would handle it.\n\t\t * 2. A new node was created but summarize was never called on it. This can mean that the summary that is\n\t\t * generated may not have the data from this node. We should not continue, log and throw an error. This\n\t\t * will help us identify these cases and take appropriate action.\n\t\t *\n\t\t * This happens due to scenarios such as data store created during summarize. Such errors should go away when\n\t\t * summarize is attempted again.\n\t\t */\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending summary\n\t * queue. We track this until we get an ack from the server for this summary.\n\t * @param proposalHandle - The handle of the summary that was uploaded to the server.\n\t */\n\tpublic completeSummary(proposalHandle: string) {\n\t\tthis.completeSummaryCore(\n\t\t\tproposalHandle,\n\t\t\tundefined /* parentPath */,\n\t\t\tfalse /* parentSkipRecursion */,\n\t\t);\n\t}\n\n\t/**\n\t * Recursive implementation for completeSummary, with additional internal-only parameters.\n\t * @param proposalHandle - The handle of the summary that was uploaded to the server.\n\t * @param parentPath - The path of the parent node which is used to build the path of this node.\n\t * @param parentSkipRecursion - true if the parent of this node skipped recursing the child nodes when summarizing.\n\t * In that case, the children will not have work-in-progress state.\n\t * @param validate - true to validate that the in-progress summary is correct for all nodes.\n\t */\n\tprotected completeSummaryCore(\n\t\tproposalHandle: string,\n\t\tparentPath: EscapedPath | undefined,\n\t\tparentSkipRecursion: boolean,\n\t) {\n\t\tassert(\n\t\t\tthis.wipReferenceSequenceNumber !== undefined,\n\t\t\t0x1a4 /* \"Not tracking a summary\" */,\n\t\t);\n\t\tlet localPathsToUse = this.wipLocalPaths;\n\n\t\tif (parentSkipRecursion) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\t// This case the parent node created a failure summary or was reused.\n\t\t\t\t// This node and all children should only try to reference their path\n\t\t\t\t// by its last known good state in the actual summary tree.\n\t\t\t\t// If parent fails or is reused, the child summarize is not called so\n\t\t\t\t// it did not get a chance to change its paths.\n\t\t\t\t// In this case, essentially only propagate the new summary ref seq num.\n\t\t\t\tlocalPathsToUse = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// This case the child is added after the latest non-failure summary.\n\t\t\t\t// This node and all children should consider themselves as still not\n\t\t\t\t// having a successful summary yet.\n\t\t\t\t// We cannot \"reuse\" this node if unchanged since that summary, because\n\t\t\t\t// handles will be unable to point to that node. It never made it to the\n\t\t\t\t// tree itself, and only exists as an attach op in the _outstandingOps.\n\t\t\t\tthis.clearSummary();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t// If localPathsToUse is undefined, it means summarize didn't run for this node and in that case the validate\n\t\t// step should have failed.\n\t\tassert(localPathsToUse !== undefined, 0x6fe /* summarize didn't run for node */);\n\t\tconst summary = new SummaryNode({\n\t\t\t...localPathsToUse,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\tbasePath: parentPath,\n\t\t});\n\t\tconst fullPathForChildren = summary.fullPathForChildren;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.completeSummaryCore(\n\t\t\t\tproposalHandle,\n\t\t\t\tfullPathForChildren,\n\t\t\t\tthis.wipSkipRecursion || parentSkipRecursion,\n\t\t\t);\n\t\t}\n\t\t// Note that this overwrites existing pending summary with\n\t\t// the same proposalHandle. If proposalHandle is something like\n\t\t// a hash or unique identifier, this should be fine. If storage\n\t\t// can return the same proposalHandle for a different summary,\n\t\t// this should still be okay, because we should be proposing the\n\t\t// newer one later which would have to overwrite the previous one.\n\t\tthis.pendingSummaries.set(proposalHandle, summary);\n\t\tthis.clearSummary();\n\t}\n\n\tpublic clearSummary() {\n\t\tthis.wipReferenceSequenceNumber = undefined;\n\t\tthis.wipLocalPaths = undefined;\n\t\tthis.wipSkipRecursion = false;\n\t\tthis.wipSummaryLogger = undefined;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.clearSummary();\n\t\t}\n\t}\n\n\t/**\n\t * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,\n\t * it becomes the latest summary. If the current summary is already ahead, we skip the update.\n\t * If the current summary is behind, then we do not refresh.\n\t *\n\t * @returns true if the summary is tracked by this node, false otherwise.\n\t */\n\tpublic async refreshLatestSummary(\n\t\tproposalHandle: string,\n\t\tsummaryRefSeq: number,\n\t): Promise<IRefreshSummaryResult> {\n\t\tconst eventProps: {\n\t\t\tproposalHandle: string | undefined;\n\t\t\tsummaryRefSeq: number;\n\t\t\treferenceSequenceNumber: number;\n\t\t\tisSummaryTracked?: boolean;\n\t\t\tpendingSummaryFound?: boolean;\n\t\t} = {\n\t\t\tproposalHandle,\n\t\t\tsummaryRefSeq,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t};\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"refreshLatestSummary\",\n\t\t\t\t...eventProps,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\t// Refresh latest summary should not happen while a summary is in progress. If it does, it can result\n\t\t\t\t// in inconsistent state, so, we should not continue;\n\t\t\t\tif (this.isSummaryInProgress()) {\n\t\t\t\t\tthrow new LoggingError(\"UnexpectedRefreshDuringSummarize\", {\n\t\t\t\t\t\tinProgressSummaryRefSeq: this.wipReferenceSequenceNumber,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tlet isSummaryTracked = false;\n\t\t\t\tlet isSummaryNewer = false;\n\n\t\t\t\tif (summaryRefSeq > this.referenceSequenceNumber) {\n\t\t\t\t\tisSummaryNewer = true;\n\t\t\t\t}\n\t\t\t\tconst maybeSummaryNode = this.pendingSummaries.get(proposalHandle);\n\t\t\t\tif (maybeSummaryNode !== undefined) {\n\t\t\t\t\tthis.refreshLatestSummaryFromPending(\n\t\t\t\t\t\tproposalHandle,\n\t\t\t\t\t\tmaybeSummaryNode.referenceSequenceNumber,\n\t\t\t\t\t);\n\t\t\t\t\tisSummaryTracked = true;\n\t\t\t\t}\n\t\t\t\tevent.end({ ...eventProps, isSummaryNewer, pendingSummaryFound: isSummaryTracked });\n\t\t\t\treturn { isSummaryTracked, isSummaryNewer };\n\t\t\t},\n\t\t\t{ start: true, end: true, cancel: \"error\" },\n\t\t);\n\t}\n\t/**\n\t * Called when we get an ack from the server for a summary we've just sent. Updates the reference state of this node\n\t * from the state in the pending summary queue.\n\t * @param proposalHandle - Handle for the current proposal.\n\t * @param referenceSequenceNumber - Reference sequence number of sent summary.\n\t */\n\tprotected refreshLatestSummaryFromPending(\n\t\tproposalHandle: string,\n\t\treferenceSequenceNumber: number,\n\t): void {\n\t\tconst summaryNode = this.pendingSummaries.get(proposalHandle);\n\t\tif (summaryNode === undefined) {\n\t\t\t// This should only happen if parent skipped recursion AND no prior summary existed.\n\t\t\tassert(\n\t\t\t\tthis._latestSummary === undefined,\n\t\t\t\t0x1a6 /* \"Not found pending summary, but this node has previously completed a summary\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\treferenceSequenceNumber === summaryNode.referenceSequenceNumber,\n\t\t\t\t0x1a7 /* Pending summary reference sequence number should be consistent */,\n\t\t\t);\n\n\t\t\t// Clear earlier pending summaries\n\t\t\tthis.pendingSummaries.delete(proposalHandle);\n\t\t}\n\n\t\tthis.refreshLatestSummaryCore(referenceSequenceNumber);\n\n\t\tthis._latestSummary = summaryNode;\n\t\t// Propagate update to all child nodes\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);\n\t\t}\n\t}\n\n\tprivate refreshLatestSummaryCore(referenceSequenceNumber: number): void {\n\t\tfor (const [key, value] of this.pendingSummaries) {\n\t\t\tif (value.referenceSequenceNumber < referenceSequenceNumber) {\n\t\t\t\tthis.pendingSummaries.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic updateBaseSummaryState(snapshot: ISnapshotTree) {\n\t\t// Check base summary to see if it has any additional path parts\n\t\t// separating child SummarizerNodes. Checks for .channels subtrees.\n\t\tconst { childrenPathPart } = parseSummaryForSubtrees(snapshot);\n\t\tif (childrenPathPart !== undefined && this._latestSummary !== undefined) {\n\t\t\tthis._latestSummary.additionalPath = EscapedPath.create(childrenPathPart);\n\t\t}\n\t}\n\n\tpublic recordChange(op: ISequencedDocumentMessage): void {\n\t\tthis.invalidate(op.sequenceNumber);\n\t}\n\n\tpublic invalidate(sequenceNumber: number): void {\n\t\tif (sequenceNumber > this._changeSequenceNumber) {\n\t\t\tthis._changeSequenceNumber = sequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * True if a change has been recorded with sequence number exceeding\n\t * the latest successfully acked summary reference sequence number.\n\t * False implies that the previous summary can be reused.\n\t */\n\tprotected hasChanged(): boolean {\n\t\treturn this._changeSequenceNumber > this.referenceSequenceNumber;\n\t}\n\n\tpublic get latestSummary(): Readonly<SummaryNode> | undefined {\n\t\treturn this._latestSummary;\n\t}\n\n\tprotected readonly canReuseHandle: boolean;\n\n\tpublic createChild(\n\t\t/** Summarize function */\n\t\tsummarizeInternalFn: SummarizeInternalFn,\n\t\t/** Initial id or path part of this node */\n\t\tid: string,\n\t\t/**\n\t\t * Information needed to create the node.\n\t\t * If it is from a base summary, it will assert that a summary has been seen.\n\t\t * Attach information if it is created from an attach op.\n\t\t */\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t\tconfig: ISummarizerNodeConfig = {},\n\t): ISummarizerNode {\n\t\tassert(!this.children.has(id), 0x1ab /* \"Create SummarizerNode child already exists\" */);\n\n\t\tconst createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);\n\t\tconst child = new SummarizerNode(\n\t\t\tthis.logger,\n\t\t\tsummarizeInternalFn,\n\t\t\tconfig,\n\t\t\tcreateDetails.changeSequenceNumber,\n\t\t\tcreateDetails.latestSummary,\n\t\t\tthis.wipSummaryLogger,\n\t\t\tcreateDetails.telemetryNodeId,\n\t\t);\n\n\t\t// There may be additional state that has to be updated in this child. For example, if a summary is being\n\t\t// tracked, the child's summary tracking state needs to be updated too. Same goes for pendingSummaries we might\n\t\t// have outstanding on the parent in case we realize nodes in between Summary Op and Summary Ack.\n\t\tthis.maybeUpdateChildState(child, id);\n\n\t\tthis.children.set(id, child);\n\t\treturn child;\n\t}\n\n\tpublic getChild(id: string): ISummarizerNode | undefined {\n\t\treturn this.children.get(id);\n\t}\n\n\t/**\n\t * Returns the details needed to create a child node.\n\t * @param id - Initial id or path part of the child node.\n\t * @param createParam - Information needed to create the node.\n\t * @returns the details needed to create the child node.\n\t */\n\tprotected getCreateDetailsForChild(\n\t\tid: string,\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t): ICreateChildDetails {\n\t\tlet latestSummary: SummaryNode | undefined;\n\t\tlet changeSequenceNumber: number;\n\n\t\tconst parentLatestSummary = this._latestSummary;\n\t\tswitch (createParam.type) {\n\t\t\tcase CreateSummarizerNodeSource.FromAttach: {\n\t\t\t\tif (\n\t\t\t\t\tparentLatestSummary !== undefined &&\n\t\t\t\t\tcreateParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\t// Prioritize latest summary if it was after this node was attached.\n\t\t\t\t\tlatestSummary = parentLatestSummary.createForChild(id);\n\t\t\t\t}\n\t\t\t\tchangeSequenceNumber = createParam.sequenceNumber;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase CreateSummarizerNodeSource.FromSummary:\n\t\t\tcase CreateSummarizerNodeSource.Local: {\n\t\t\t\tlatestSummary = parentLatestSummary?.createForChild(id);\n\t\t\t\tchangeSequenceNumber = parentLatestSummary?.referenceSequenceNumber ?? -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst type = (createParam as unknown as CreateChildSummarizerNodeParam).type;\n\t\t\t\tunreachableCase(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);\n\t\t\t}\n\t\t}\n\n\t\tconst childTelemetryNodeId = `${this.telemetryNodeId ?? \"\"}/${id}`;\n\n\t\treturn {\n\t\t\tlatestSummary,\n\t\t\tchangeSequenceNumber,\n\t\t\ttelemetryNodeId: childTelemetryNodeId,\n\t\t};\n\t}\n\n\t/**\n\t * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's\n\t * summary tracking state needs to be updated too.\n\t * Also, in case a child node gets realized in between Summary Op and Summary Ack, let's initialize the child's\n\t * pending summary as well.\n\t * @param child - The child node whose state is to be updated.\n\t * @param id - Initial id or path part of this node\n\t *\n\t */\n\tprotected maybeUpdateChildState(child: SummarizerNode, id: string) {\n\t\t// If a summary is in progress, this child was created after the summary started. So, we need to update the\n\t\t// child's summary state as well.\n\t\tif (this.isSummaryInProgress()) {\n\t\t\tchild.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;\n\t\t}\n\t\t// In case we have pending summaries on the parent, let's initialize it on the child.\n\t\tif (child._latestSummary !== undefined) {\n\t\t\tfor (const [key, value] of this.pendingSummaries.entries()) {\n\t\t\t\tconst newLatestSummaryNode = new SummaryNode({\n\t\t\t\t\treferenceSequenceNumber: value.referenceSequenceNumber,\n\t\t\t\t\tbasePath: child._latestSummary.basePath,\n\t\t\t\t\tlocalPath: child._latestSummary.localPath,\n\t\t\t\t});\n\n\t\t\t\tchild.addPendingSummary(key, newLatestSummaryNode);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected addPendingSummary(key: string, summary: SummaryNode) {\n\t\tthis.pendingSummaries.set(key, summary);\n\t}\n\n\t/**\n\t * Tells whether summary tracking is in progress. True if \"startSummary\" API is called before summarize.\n\t */\n\tpublic isSummaryInProgress(): boolean {\n\t\treturn this.wipReferenceSequenceNumber !== undefined;\n\t}\n\n\t/**\n\t * Creates and throws an error due to unexpected conditions.\n\t */\n\tprotected throwUnexpectedError(eventProps: ITelemetryErrorEventExt): never {\n\t\tconst error = new LoggingError(eventProps.eventName, {\n\t\t\t...eventProps,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\t...tagCodeArtifacts({\n\t\t\t\tid: this.telemetryNodeId,\n\t\t\t}),\n\t\t});\n\t\tthis.logger.sendErrorEvent(eventProps, error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Creates a root summarizer node.\n * @param logger - Logger to use within SummarizerNode\n * @param summarizeInternalFn - Function to generate summary\n * @param changeSequenceNumber - Sequence number of latest change to new node/subtree\n * @param referenceSequenceNumber - Reference sequence number of last acked summary,\n * or undefined if not loaded from summary\n * @param config - Configure behavior of summarizer node\n */\nexport const createRootSummarizerNode = (\n\tlogger: ITelemetryLoggerExt,\n\tsummarizeInternalFn: SummarizeInternalFn,\n\tchangeSequenceNumber: number,\n\treferenceSequenceNumber: number | undefined,\n\tconfig: ISummarizerNodeConfig = {},\n): IRootSummarizerNode =>\n\tnew SummarizerNode(\n\t\tlogger,\n\t\tsummarizeInternalFn,\n\t\tconfig,\n\t\tchangeSequenceNumber,\n\t\treferenceSequenceNumber === undefined\n\t\t\t? undefined\n\t\t\t: SummaryNode.createForRoot(referenceSequenceNumber),\n\t\tundefined /* wipSummaryLogger */,\n\t\t\"\" /* telemetryNodeId */,\n\t);\n"]}
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
- import { IExperimentalIncrementalSummaryContext, ITelemetryContext, IGarbageCollectionData, CreateChildSummarizerNodeParam, IGarbageCollectionDetailsBase, ISummarizeInternalResult, ISummarizeResult, ISummarizerNodeConfigWithGC, ISummarizerNodeWithGC, SummarizeInternalFn } from "@fluidframework/runtime-definitions/internal";
6
+ import { IGarbageCollectionData, CreateChildSummarizerNodeParam, IGarbageCollectionDetailsBase, ISummarizerNodeConfigWithGC, ISummarizerNodeWithGC, SummarizeInternalFn } from "@fluidframework/runtime-definitions/internal";
7
7
  import { SummarizerNode } from "./summarizerNode.js";
8
8
  import { EscapedPath, IStartSummaryResult, ISummarizerNodeRootContract, SummaryNode, ValidateSummaryResult } from "./summarizerNodeUtils.js";
9
9
  export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {
@@ -22,9 +22,9 @@ export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISumma
22
22
  * directly into summarizeInternal method.
23
23
  */
24
24
  export declare class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {
25
- private readonly summarizeFn;
26
25
  private readonly getGCDataFn?;
27
26
  private wipSerializedUsedRoutes;
27
+ private wipChildNodesUsedRoutes;
28
28
  private referenceUsedRoutes;
29
29
  private readonly baseGCDetailsP;
30
30
  private baseGCDetailsLoaded;
@@ -36,7 +36,7 @@ export declare class SummarizerNodeWithGC extends SummarizerNode implements IRoo
36
36
  * Do not call constructor directly.
37
37
  * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
38
38
  */
39
- constructor(logger: ITelemetryBaseLogger, summarizeFn: (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext, incrementalSummaryContext?: IExperimentalIncrementalSummaryContext) => Promise<ISummarizeInternalResult>, config: ISummarizerNodeConfigWithGC, changeSequenceNumber: number,
39
+ constructor(logger: ITelemetryBaseLogger, summarizeInternalFn: SummarizeInternalFn, config: ISummarizerNodeConfigWithGC, changeSequenceNumber: number,
40
40
  /** Undefined means created without summary */
41
41
  latestSummary?: SummaryNode, wipSummaryLogger?: ITelemetryBaseLogger, getGCDataFn?: ((fullGC?: boolean) => Promise<IGarbageCollectionData>) | undefined, getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
42
42
  /** A unique id of this node to be logged when sending telemetry. */
@@ -48,7 +48,6 @@ export declare class SummarizerNodeWithGC extends SummarizerNode implements IRoo
48
48
  * - gcData: The garbage collection data of this node that is required for running GC.
49
49
  */
50
50
  private loadBaseGCDetails;
51
- summarize(fullTree: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummarizeResult>;
52
51
  /**
53
52
  * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
54
53
  * the previous summary. Else, it gets new GC data from the underlying Fluid object.
@@ -1 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AQ,sBAAsB,CAAC,uBAC9C,MAAM,QAAQ,6BAA6B,CAAC,KAC/D,yBAaD,CAAC"}
@@ -36,13 +36,12 @@ class SummarizerNodeWithGC extends summarizerNode_js_1.SummarizerNode {
36
36
  * Do not call constructor directly.
37
37
  * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
38
38
  */
39
- constructor(logger, summarizeFn, config, changeSequenceNumber,
39
+ constructor(logger, summarizeInternalFn, config, changeSequenceNumber,
40
40
  /** Undefined means created without summary */
41
41
  latestSummary, wipSummaryLogger, getGCDataFn, getBaseGCDetailsFn,
42
42
  /** A unique id of this node to be logged when sending telemetry. */
43
43
  telemetryId) {
44
- super(logger, async (fullTree, _trackState, telemetryContext, incrementalSummaryContext) => summarizeFn(fullTree, true /* trackState */, telemetryContext, incrementalSummaryContext), config, changeSequenceNumber, latestSummary, wipSummaryLogger, telemetryId);
45
- this.summarizeFn = summarizeFn;
44
+ super(logger, summarizeInternalFn, config, changeSequenceNumber, latestSummary, wipSummaryLogger, telemetryId);
46
45
  this.getGCDataFn = getGCDataFn;
47
46
  // Keeps track of whether we have loaded the base details to ensure that we only do it once.
48
47
  this.baseGCDetailsLoaded = false;
@@ -87,18 +86,6 @@ class SummarizerNodeWithGC extends summarizerNode_js_1.SummarizerNode {
87
86
  this.referenceUsedRoutes = Array.from(baseGCDetails.usedRoutes).sort();
88
87
  }
89
88
  }
90
- async summarize(fullTree, trackState = true, telemetryContext) {
91
- // If GC is not disabled and a summary is in progress, GC should have run and updated the used routes for this
92
- // summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.
93
- if (!this.gcDisabled && this.isSummaryInProgress()) {
94
- (0, internal_1.assert)(this.wipSerializedUsedRoutes !== undefined, 0x1b1 /* "wip used routes should be set if tracking a summary" */);
95
- }
96
- // If trackState is true, get summary from base summarizer node which tracks summary state.
97
- // If trackState is false, get summary from summarizeInternal.
98
- return trackState
99
- ? super.summarize(fullTree, true /* trackState */, telemetryContext)
100
- : this.summarizeFn(fullTree, trackState, telemetryContext);
101
- }
102
89
  /**
103
90
  * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
104
91
  * the previous summary. Else, it gets new GC data from the underlying Fluid object.
@@ -205,6 +192,7 @@ class SummarizerNodeWithGC extends summarizerNode_js_1.SummarizerNode {
205
192
  */
206
193
  clearSummary() {
207
194
  this.wipSerializedUsedRoutes = undefined;
195
+ this.wipChildNodesUsedRoutes = undefined;
208
196
  super.clearSummary();
209
197
  }
210
198
  /**
@@ -284,6 +272,19 @@ class SummarizerNodeWithGC extends summarizerNode_js_1.SummarizerNode {
284
272
  */
285
273
  maybeUpdateChildState(child, id) {
286
274
  super.maybeUpdateChildState(child, id);
275
+ // If GC has run on this node and summarization isn't complete, this.wipSerializedUsedRoutes will be defined.
276
+ // In that case, update the used routes of the child node. This can happen in scenarios where a data store
277
+ // doesn't have any ops but its reference state changed. So, it gets realized during summarize after GC ran
278
+ // so GC would not have run on this node which is fine.
279
+ if (this.wipSerializedUsedRoutes !== undefined) {
280
+ // If the child route used routes are not defined, initialize it now and it can be used for all child nodes
281
+ // created until this summarization process is completed. This is an optimization to unpack the used routes
282
+ // only when needed.
283
+ if (this.wipChildNodesUsedRoutes === undefined) {
284
+ this.wipChildNodesUsedRoutes = (0, internal_2.unpackChildNodesUsedRoutes)(this.usedRoutes);
285
+ }
286
+ child.updateUsedRoutes(this.wipChildNodesUsedRoutes.get(id) ?? [""]);
287
+ }
287
288
  // In case we have pending summaries on the parent, let's initialize it on the child.
288
289
  if (child.latestSummary !== undefined) {
289
290
  for (const [key, value] of this.pendingSummaries.entries()) {