@fluidframework/container-runtime 2.3.0-288113 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/api-report/container-runtime.legacy.alpha.api.md +15 -0
  3. package/container-runtime.test-files.tar +0 -0
  4. package/dist/channelCollection.d.ts +1 -1
  5. package/dist/channelCollection.d.ts.map +1 -1
  6. package/dist/channelCollection.js +1 -16
  7. package/dist/channelCollection.js.map +1 -1
  8. package/dist/connectionTelemetry.d.ts +27 -3
  9. package/dist/connectionTelemetry.d.ts.map +1 -1
  10. package/dist/connectionTelemetry.js.map +1 -1
  11. package/dist/containerRuntime.d.ts +68 -13
  12. package/dist/containerRuntime.d.ts.map +1 -1
  13. package/dist/containerRuntime.js +262 -180
  14. package/dist/containerRuntime.js.map +1 -1
  15. package/dist/deltaManagerProxies.d.ts.map +1 -1
  16. package/dist/deltaManagerProxies.js +11 -4
  17. package/dist/deltaManagerProxies.js.map +1 -1
  18. package/dist/gc/garbageCollection.d.ts.map +1 -1
  19. package/dist/gc/garbageCollection.js +0 -2
  20. package/dist/gc/garbageCollection.js.map +1 -1
  21. package/dist/gc/gcHelpers.d.ts.map +1 -1
  22. package/dist/gc/gcHelpers.js +0 -8
  23. package/dist/gc/gcHelpers.js.map +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +2 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/legacy.d.ts +3 -1
  29. package/dist/messageTypes.d.ts +0 -9
  30. package/dist/messageTypes.d.ts.map +1 -1
  31. package/dist/messageTypes.js.map +1 -1
  32. package/dist/opLifecycle/batchManager.d.ts +9 -0
  33. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  34. package/dist/opLifecycle/batchManager.js +19 -6
  35. package/dist/opLifecycle/batchManager.js.map +1 -1
  36. package/dist/opLifecycle/duplicateBatchDetector.d.ts +32 -0
  37. package/dist/opLifecycle/duplicateBatchDetector.d.ts.map +1 -0
  38. package/dist/opLifecycle/duplicateBatchDetector.js +68 -0
  39. package/dist/opLifecycle/duplicateBatchDetector.js.map +1 -0
  40. package/dist/opLifecycle/index.d.ts +3 -2
  41. package/dist/opLifecycle/index.d.ts.map +1 -1
  42. package/dist/opLifecycle/index.js +4 -1
  43. package/dist/opLifecycle/index.js.map +1 -1
  44. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  45. package/dist/opLifecycle/opCompressor.js +0 -4
  46. package/dist/opLifecycle/opCompressor.js.map +1 -1
  47. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  48. package/dist/opLifecycle/opGroupingManager.js +0 -4
  49. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  50. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  51. package/dist/opLifecycle/opSplitter.js +1 -6
  52. package/dist/opLifecycle/opSplitter.js.map +1 -1
  53. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  54. package/dist/opLifecycle/outbox.js +1 -4
  55. package/dist/opLifecycle/outbox.js.map +1 -1
  56. package/dist/opLifecycle/remoteMessageProcessor.d.ts +37 -17
  57. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  58. package/dist/opLifecycle/remoteMessageProcessor.js +47 -37
  59. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  60. package/dist/packageVersion.d.ts +1 -1
  61. package/dist/packageVersion.d.ts.map +1 -1
  62. package/dist/packageVersion.js +1 -1
  63. package/dist/packageVersion.js.map +1 -1
  64. package/dist/pendingStateManager.d.ts +27 -17
  65. package/dist/pendingStateManager.d.ts.map +1 -1
  66. package/dist/pendingStateManager.js +85 -56
  67. package/dist/pendingStateManager.js.map +1 -1
  68. package/dist/scheduleManager.d.ts +2 -4
  69. package/dist/scheduleManager.d.ts.map +1 -1
  70. package/dist/scheduleManager.js +6 -37
  71. package/dist/scheduleManager.js.map +1 -1
  72. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  73. package/dist/summary/summarizerNode/summarizerNodeUtils.js +0 -2
  74. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  75. package/dist/summary/summaryCollection.d.ts.map +1 -1
  76. package/dist/summary/summaryCollection.js +5 -7
  77. package/dist/summary/summaryCollection.js.map +1 -1
  78. package/dist/summary/summaryFormat.d.ts.map +1 -1
  79. package/dist/summary/summaryFormat.js +1 -4
  80. package/dist/summary/summaryFormat.js.map +1 -1
  81. package/lib/channelCollection.d.ts +1 -1
  82. package/lib/channelCollection.d.ts.map +1 -1
  83. package/lib/channelCollection.js +1 -16
  84. package/lib/channelCollection.js.map +1 -1
  85. package/lib/connectionTelemetry.d.ts +27 -3
  86. package/lib/connectionTelemetry.d.ts.map +1 -1
  87. package/lib/connectionTelemetry.js.map +1 -1
  88. package/lib/containerRuntime.d.ts +68 -13
  89. package/lib/containerRuntime.d.ts.map +1 -1
  90. package/lib/containerRuntime.js +262 -181
  91. package/lib/containerRuntime.js.map +1 -1
  92. package/lib/deltaManagerProxies.d.ts.map +1 -1
  93. package/lib/deltaManagerProxies.js +11 -4
  94. package/lib/deltaManagerProxies.js.map +1 -1
  95. package/lib/gc/garbageCollection.d.ts.map +1 -1
  96. package/lib/gc/garbageCollection.js +0 -2
  97. package/lib/gc/garbageCollection.js.map +1 -1
  98. package/lib/gc/gcHelpers.d.ts.map +1 -1
  99. package/lib/gc/gcHelpers.js +0 -8
  100. package/lib/gc/gcHelpers.js.map +1 -1
  101. package/lib/index.d.ts +1 -1
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +1 -1
  104. package/lib/index.js.map +1 -1
  105. package/lib/legacy.d.ts +3 -1
  106. package/lib/messageTypes.d.ts +0 -9
  107. package/lib/messageTypes.d.ts.map +1 -1
  108. package/lib/messageTypes.js.map +1 -1
  109. package/lib/opLifecycle/batchManager.d.ts +9 -0
  110. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  111. package/lib/opLifecycle/batchManager.js +17 -5
  112. package/lib/opLifecycle/batchManager.js.map +1 -1
  113. package/lib/opLifecycle/duplicateBatchDetector.d.ts +32 -0
  114. package/lib/opLifecycle/duplicateBatchDetector.d.ts.map +1 -0
  115. package/lib/opLifecycle/duplicateBatchDetector.js +64 -0
  116. package/lib/opLifecycle/duplicateBatchDetector.js.map +1 -0
  117. package/lib/opLifecycle/index.d.ts +3 -2
  118. package/lib/opLifecycle/index.d.ts.map +1 -1
  119. package/lib/opLifecycle/index.js +2 -1
  120. package/lib/opLifecycle/index.js.map +1 -1
  121. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  122. package/lib/opLifecycle/opCompressor.js +0 -4
  123. package/lib/opLifecycle/opCompressor.js.map +1 -1
  124. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  125. package/lib/opLifecycle/opGroupingManager.js +0 -4
  126. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  127. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  128. package/lib/opLifecycle/opSplitter.js +1 -6
  129. package/lib/opLifecycle/opSplitter.js.map +1 -1
  130. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  131. package/lib/opLifecycle/outbox.js +1 -4
  132. package/lib/opLifecycle/outbox.js.map +1 -1
  133. package/lib/opLifecycle/remoteMessageProcessor.d.ts +37 -17
  134. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  135. package/lib/opLifecycle/remoteMessageProcessor.js +47 -37
  136. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  137. package/lib/packageVersion.d.ts +1 -1
  138. package/lib/packageVersion.d.ts.map +1 -1
  139. package/lib/packageVersion.js +1 -1
  140. package/lib/packageVersion.js.map +1 -1
  141. package/lib/pendingStateManager.d.ts +27 -17
  142. package/lib/pendingStateManager.d.ts.map +1 -1
  143. package/lib/pendingStateManager.js +85 -56
  144. package/lib/pendingStateManager.js.map +1 -1
  145. package/lib/scheduleManager.d.ts +2 -4
  146. package/lib/scheduleManager.d.ts.map +1 -1
  147. package/lib/scheduleManager.js +6 -37
  148. package/lib/scheduleManager.js.map +1 -1
  149. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  150. package/lib/summary/summarizerNode/summarizerNodeUtils.js +0 -2
  151. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  152. package/lib/summary/summaryCollection.d.ts.map +1 -1
  153. package/lib/summary/summaryCollection.js +5 -7
  154. package/lib/summary/summaryCollection.js.map +1 -1
  155. package/lib/summary/summaryFormat.d.ts.map +1 -1
  156. package/lib/summary/summaryFormat.js +1 -4
  157. package/lib/summary/summaryFormat.js.map +1 -1
  158. package/lib/tsdoc-metadata.json +1 -1
  159. package/package.json +50 -24
  160. package/src/channelCollection.ts +7 -21
  161. package/src/connectionTelemetry.ts +33 -3
  162. package/src/containerRuntime.ts +382 -233
  163. package/src/deltaManagerProxies.ts +11 -4
  164. package/src/gc/garbageCollection.ts +1 -3
  165. package/src/gc/gcHelpers.ts +4 -12
  166. package/src/index.ts +2 -0
  167. package/src/messageTypes.ts +0 -10
  168. package/src/opLifecycle/batchManager.ts +29 -7
  169. package/src/opLifecycle/duplicateBatchDetector.ts +78 -0
  170. package/src/opLifecycle/index.ts +4 -1
  171. package/src/opLifecycle/opCompressor.ts +2 -6
  172. package/src/opLifecycle/opGroupingManager.ts +2 -6
  173. package/src/opLifecycle/opSplitter.ts +2 -6
  174. package/src/opLifecycle/outbox.ts +1 -3
  175. package/src/opLifecycle/remoteMessageProcessor.ts +87 -59
  176. package/src/packageVersion.ts +1 -1
  177. package/src/pendingStateManager.ts +114 -66
  178. package/src/scheduleManager.ts +8 -47
  179. package/src/summary/summarizerNode/summarizerNodeUtils.ts +1 -3
  180. package/src/summary/summaryCollection.ts +7 -9
  181. package/src/summary/summaryFormat.ts +1 -3
  182. package/src/summary/summaryFormats.md +11 -9
  183. package/tsconfig.json +1 -0
@@ -25,6 +25,7 @@ class RemoteMessageProcessor {
25
25
  this.opSplitter = opSplitter;
26
26
  this.opDecompressor = opDecompressor;
27
27
  this.opGroupingManager = opGroupingManager;
28
+ this.batchInProgress = false;
28
29
  }
29
30
  get partialMessages() {
30
31
  return this.opSplitter.chunks;
@@ -75,62 +76,72 @@ class RemoteMessageProcessor {
75
76
  }
76
77
  }
77
78
  if ((0, opGroupingManager_js_1.isGroupedBatch)(message)) {
78
- // We should be awaiting a new batch (batchInProgress undefined)
79
- (0, internal_1.assert)(this.batchInProgress === undefined, 0x9d3 /* Grouped batch interrupting another batch */);
79
+ // We should be awaiting a new batch (batchInProgress false)
80
+ (0, internal_1.assert)(!this.batchInProgress, 0x9d3 /* Grouped batch interrupting another batch */);
80
81
  const batchId = (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batchId;
81
82
  const groupedMessages = this.opGroupingManager.ungroupOp(message).map(unpack);
82
83
  return {
84
+ type: "fullBatch",
83
85
  messages: groupedMessages, // Will be [] for an empty batch
84
- batchStartCsn: message.clientSequenceNumber,
85
- clientId,
86
- batchId,
87
- // If the batch is empty, we need to return the sequence number aside
88
- emptyBatchSequenceNumber: groupedMessages.length === 0 ? message.sequenceNumber : undefined,
86
+ batchStart: {
87
+ batchStartCsn: message.clientSequenceNumber,
88
+ clientId,
89
+ batchId,
90
+ keyMessage: groupedMessages[0] ?? message, // For an empty batch, this is the empty grouped batch message. Needed for sequence numbers for this batch
91
+ },
92
+ length: groupedMessages.length, // Will be 0 for an empty batch
89
93
  };
90
94
  }
91
95
  // Do a final unpack of runtime messages in case the message was not grouped, compressed, or chunked
92
96
  unpackRuntimeMessage(message, logLegacyCase);
93
- const { batchEnded } = this.addMessageToBatch(message);
94
- if (!batchEnded) {
95
- // batch not yet complete
96
- return undefined;
97
- }
98
- const completedBatch = this.batchInProgress;
99
- this.batchInProgress = undefined;
100
- return completedBatch;
97
+ return this.getResultBasedOnBatchMetadata(message);
101
98
  }
102
99
  /**
103
- * Add the given message to the current batch, and indicate whether the batch is now complete.
104
- *
105
- * @returns batchEnded: true if the batch is now complete, batchEnded: false if more messages are expected
100
+ * Now that the message has been "unwrapped" as to any virtualization (grouping, compression, chunking),
101
+ * inspect the batch metadata flag and determine what kind of result to return.
106
102
  */
107
- addMessageToBatch(message) {
103
+ getResultBasedOnBatchMetadata(message) {
108
104
  const batchMetadataFlag = (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batch;
109
- if (this.batchInProgress === undefined) {
105
+ if (!this.batchInProgress) {
110
106
  // We are waiting for a new batch
111
107
  (0, internal_1.assert)(batchMetadataFlag !== false, 0x9d5 /* Unexpected batch end marker */);
112
108
  // Start of a new multi-message batch
113
109
  if (batchMetadataFlag === true) {
114
- this.batchInProgress = {
115
- messages: [message],
116
- batchId: (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batchId,
117
- clientId: message.clientId,
118
- batchStartCsn: message.clientSequenceNumber,
110
+ this.batchInProgress = true;
111
+ return {
112
+ type: "batchStartingMessage",
113
+ batchStart: {
114
+ batchId: (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batchId,
115
+ clientId: message.clientId,
116
+ batchStartCsn: message.clientSequenceNumber,
117
+ keyMessage: message,
118
+ },
119
+ nextMessage: message,
119
120
  };
120
- return { batchEnded: false };
121
121
  }
122
122
  // Single-message batch (Since metadata flag is undefined)
123
- this.batchInProgress = {
123
+ return {
124
+ type: "fullBatch",
124
125
  messages: [message],
125
- batchStartCsn: message.clientSequenceNumber,
126
- clientId: message.clientId,
127
- batchId: (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batchId,
126
+ batchStart: {
127
+ batchStartCsn: message.clientSequenceNumber,
128
+ clientId: message.clientId,
129
+ batchId: (0, metadata_js_1.asBatchMetadata)(message.metadata)?.batchId,
130
+ keyMessage: message,
131
+ },
132
+ length: 1,
128
133
  };
129
- return { batchEnded: true };
130
134
  }
131
135
  (0, internal_1.assert)(batchMetadataFlag !== true, 0x9d6 /* Unexpected batch start marker */);
132
- this.batchInProgress.messages.push(message);
133
- return { batchEnded: batchMetadataFlag === false };
136
+ // Clear batchInProgress state if the batch is ending
137
+ if (batchMetadataFlag === false) {
138
+ this.batchInProgress = false;
139
+ }
140
+ return {
141
+ type: "nextBatchMessage",
142
+ nextMessage: message,
143
+ batchEnd: batchMetadataFlag === false,
144
+ };
134
145
  }
135
146
  }
136
147
  exports.RemoteMessageProcessor = RemoteMessageProcessor;
@@ -141,10 +152,9 @@ exports.RemoteMessageProcessor = RemoteMessageProcessor;
141
152
  * @param logLegacyCase - callback to log when legacy op is encountered
142
153
  */
143
154
  function ensureContentsDeserialized(mutableMessage, hasModernRuntimeMessageEnvelope, logLegacyCase) {
144
- // Currently the loader layer is parsing the contents of the message as JSON if it is a string,
145
- // so we never expect to see this case.
146
- // We intend to remove that logic from the Loader, at which point we will have it here.
147
- // Only hasModernRuntimeMessageEnvelope true will be expected to have JSON contents.
155
+ // This should become unconditional once (Loader LTS) DeltaManager.processInboundMessage() stops parsing content (ADO #12052)
156
+ // Note: Until that change is made in the loader, this case will never be hit.
157
+ // Then there will be a long time of needing both cases, until LTS catches up to the change.
148
158
  let didParseJsonContents;
149
159
  if (typeof mutableMessage.contents === "string" && mutableMessage.contents !== "") {
150
160
  mutableMessage.contents = JSON.parse(mutableMessage.contents);
@@ -1 +1 @@
1
- {"version":3,"file":"remoteMessageProcessor.js","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,0EAGqD;AAErD,wDAK4B;AAC5B,gDAAiD;AAGjD,iEAA2E;AAC3E,mDAA+D;AAsB/D,SAAS,iBAAiB,CACzB,OAAkC;IAElC,IAAA,iBAAM,EACL,OAAO,CAAC,QAAQ,KAAK,IAAI,EACzB,KAAK,CAAC,sEAAsE,CAC5E,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAa,sBAAsB;IAQlC,YACkB,UAAsB,EACtB,cAA8B,EAC9B,iBAAoC;QAFpC,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D,aAAa,CAAC,0CAA0C,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACP,aAAa;QACb,MAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AA1BD,oDA0BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport {\n\tContainerMessageType,\n\ttype InboundContainerRuntimeMessage,\n\ttype InboundSequencedContainerRuntimeMessage,\n\ttype InboundSequencedRecentlyAddedContainerRuntimeMessage,\n} from \"../messageTypes.js\";\nimport { asBatchMetadata } from \"../metadata.js\";\n\nimport { OpDecompressor } from \"./opDecompressor.js\";\nimport { OpGroupingManager, isGroupedBatch } from \"./opGroupingManager.js\";\nimport { OpSplitter, isChunkedMessage } from \"./opSplitter.js\";\n\n/** Messages being received as a batch, with details needed to process the batch */\nexport interface InboundBatch {\n\t/** Messages in this batch */\n\treadonly messages: InboundSequencedContainerRuntimeMessage[];\n\t/** Batch ID, if present */\n\treadonly batchId: string | undefined;\n\t/** clientId that sent this batch. Used to compute Batch ID if needed */\n\treadonly clientId: string;\n\t/**\n\t * Client Sequence Number of the first message in the batch.\n\t * Used to compute Batch ID if needed\n\t *\n\t * @remarks For chunked batches, this is the CSN of the \"representative\" chunk (the final chunk).\n\t * For grouped batches, clientSequenceNumber on messages is overwritten, so we track this original value here.\n\t */\n\treadonly batchStartCsn: number;\n\t/** For an empty batch (with no messages), we need to remember the empty grouped batch's sequence number */\n\treadonly emptyBatchSequenceNumber?: number;\n}\n\nfunction assertHasClientId(\n\tmessage: ISequencedDocumentMessage,\n): asserts message is ISequencedDocumentMessage & { clientId: string } {\n\tassert(\n\t\tmessage.clientId !== null,\n\t\t0xa02 /* Server-generated message should not reach RemoteMessageProcessor */,\n\t);\n}\n\n/**\n * Stateful class for processing incoming remote messages as the virtualization measures are unwrapped,\n * potentially across numerous inbound ops.\n *\n * @internal\n */\nexport class RemoteMessageProcessor {\n\t/**\n\t * The current batch being received, with details needed to process it.\n\t *\n\t * @remarks If undefined, we are expecting the next message to start a new batch.\n\t */\n\tprivate batchInProgress: InboundBatch | undefined;\n\n\tconstructor(\n\t\tprivate readonly opSplitter: OpSplitter,\n\t\tprivate readonly opDecompressor: OpDecompressor,\n\t\tprivate readonly opGroupingManager: OpGroupingManager,\n\t) {}\n\n\tpublic get partialMessages(): ReadonlyMap<string, string[]> {\n\t\treturn this.opSplitter.chunks;\n\t}\n\n\tpublic clearPartialMessagesFor(clientId: string) {\n\t\tthis.opSplitter.clearPartialChunks(clientId);\n\t}\n\n\t/**\n\t * Ungroups and Unchunks the runtime ops of a batch received over the wire\n\t * @param remoteMessageCopy - A shallow copy of a message from another client, possibly virtualized\n\t * (grouped, compressed, and/or chunked).\n\t * Being a shallow copy, it's considered mutable, meaning no other Container or other parallel procedure\n\t * depends on this object instance.\n\t * Note remoteMessageCopy.contents (and other object props) MUST not be modified,\n\t * but may be overwritten (as is the case with contents).\n\t *\n\t * Incoming messages will always have compression, chunking, and grouped batching happen in a defined order and that order cannot be changed.\n\t * When processing these messages, the order is:\n\t * 1. If chunked, process the chunk and only continue if this is a final chunk\n\t * 2. If compressed, decompress the message and store for further unrolling of the decompressed content\n\t * 3. If grouped, ungroup the message\n\t * For more details, see https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/src/opLifecycle/README.md#inbound\n\t *\n\t * @returns all the unchunked, decompressed, ungrouped, unpacked InboundSequencedContainerRuntimeMessage from a single batch\n\t * or undefined if the batch is not yet complete.\n\t */\n\tpublic process(\n\t\tremoteMessageCopy: ISequencedDocumentMessage,\n\t\tlogLegacyCase: (codePath: string) => void,\n\t): InboundBatch | undefined {\n\t\tlet message = remoteMessageCopy;\n\n\t\tassertHasClientId(message);\n\t\tconst clientId = message.clientId;\n\n\t\tif (isChunkedMessage(message)) {\n\t\t\tconst chunkProcessingResult = this.opSplitter.processChunk(message);\n\t\t\t// Only continue further if current chunk is the final chunk\n\t\t\tif (!chunkProcessingResult.isFinalChunk) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// This message will always be compressed\n\t\t\tmessage = chunkProcessingResult.message;\n\t\t}\n\n\t\tif (this.opDecompressor.isCompressedMessage(message)) {\n\t\t\tthis.opDecompressor.decompressAndStore(message);\n\t\t}\n\n\t\tif (this.opDecompressor.currentlyUnrolling) {\n\t\t\tmessage = this.opDecompressor.unroll(message);\n\t\t\t// Need to unpack after unrolling if not a groupedBatch\n\t\t\tif (!isGroupedBatch(message)) {\n\t\t\t\tunpack(message);\n\t\t\t}\n\t\t}\n\n\t\tif (isGroupedBatch(message)) {\n\t\t\t// We should be awaiting a new batch (batchInProgress undefined)\n\t\t\tassert(\n\t\t\t\tthis.batchInProgress === undefined,\n\t\t\t\t0x9d3 /* Grouped batch interrupting another batch */,\n\t\t\t);\n\t\t\tconst batchId = asBatchMetadata(message.metadata)?.batchId;\n\t\t\tconst groupedMessages = this.opGroupingManager.ungroupOp(message).map(unpack);\n\t\t\treturn {\n\t\t\t\tmessages: groupedMessages, // Will be [] for an empty batch\n\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\tclientId,\n\t\t\t\tbatchId,\n\t\t\t\t// If the batch is empty, we need to return the sequence number aside\n\t\t\t\temptyBatchSequenceNumber:\n\t\t\t\t\tgroupedMessages.length === 0 ? message.sequenceNumber : undefined,\n\t\t\t};\n\t\t}\n\n\t\t// Do a final unpack of runtime messages in case the message was not grouped, compressed, or chunked\n\t\tunpackRuntimeMessage(message, logLegacyCase);\n\n\t\tconst { batchEnded } = this.addMessageToBatch(\n\t\t\tmessage as InboundSequencedContainerRuntimeMessage & { clientId: string },\n\t\t);\n\n\t\tif (!batchEnded) {\n\t\t\t// batch not yet complete\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst completedBatch = this.batchInProgress;\n\t\tthis.batchInProgress = undefined;\n\t\treturn completedBatch;\n\t}\n\n\t/**\n\t * Add the given message to the current batch, and indicate whether the batch is now complete.\n\t *\n\t * @returns batchEnded: true if the batch is now complete, batchEnded: false if more messages are expected\n\t */\n\tprivate addMessageToBatch(\n\t\tmessage: InboundSequencedContainerRuntimeMessage & { clientId: string },\n\t): { batchEnded: boolean } {\n\t\tconst batchMetadataFlag = asBatchMetadata(message.metadata)?.batch;\n\t\tif (this.batchInProgress === undefined) {\n\t\t\t// We are waiting for a new batch\n\t\t\tassert(batchMetadataFlag !== false, 0x9d5 /* Unexpected batch end marker */);\n\n\t\t\t// Start of a new multi-message batch\n\t\t\tif (batchMetadataFlag === true) {\n\t\t\t\tthis.batchInProgress = {\n\t\t\t\t\tmessages: [message],\n\t\t\t\t\tbatchId: asBatchMetadata(message.metadata)?.batchId,\n\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\t};\n\n\t\t\t\treturn { batchEnded: false };\n\t\t\t}\n\n\t\t\t// Single-message batch (Since metadata flag is undefined)\n\t\t\tthis.batchInProgress = {\n\t\t\t\tmessages: [message],\n\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\tclientId: message.clientId,\n\t\t\t\tbatchId: asBatchMetadata(message.metadata)?.batchId,\n\t\t\t};\n\t\t\treturn { batchEnded: true };\n\t\t}\n\t\tassert(batchMetadataFlag !== true, 0x9d6 /* Unexpected batch start marker */);\n\n\t\tthis.batchInProgress.messages.push(message);\n\n\t\treturn { batchEnded: batchMetadataFlag === false };\n\t}\n}\n\n/**\n * Takes an incoming message and if the contents is a string, JSON.parse's it in place\n * @param mutableMessage - op message received\n * @param hasModernRuntimeMessageEnvelope - false if the message does not contain the modern op envelop where message.type is MessageType.Operation\n * @param logLegacyCase - callback to log when legacy op is encountered\n */\nexport function ensureContentsDeserialized(\n\tmutableMessage: ISequencedDocumentMessage,\n\thasModernRuntimeMessageEnvelope: boolean,\n\tlogLegacyCase: (codePath: string) => void,\n): void {\n\t// Currently the loader layer is parsing the contents of the message as JSON if it is a string,\n\t// so we never expect to see this case.\n\t// We intend to remove that logic from the Loader, at which point we will have it here.\n\t// Only hasModernRuntimeMessageEnvelope true will be expected to have JSON contents.\n\tlet didParseJsonContents: boolean;\n\tif (typeof mutableMessage.contents === \"string\" && mutableMessage.contents !== \"\") {\n\t\tmutableMessage.contents = JSON.parse(mutableMessage.contents);\n\t\tdidParseJsonContents = true;\n\t} else {\n\t\tdidParseJsonContents = false;\n\t}\n\n\t// The DeltaManager parses the contents of the message as JSON if it is a string,\n\t// so we should never end up parsing it here.\n\t// Let's observe if we are wrong about this to learn about these cases.\n\tif (didParseJsonContents) {\n\t\tlogLegacyCase(\"ensureContentsDeserialized_foundJsonContents\");\n\t}\n}\n\n/**\n * For a given message, it moves the nested InboundContainerRuntimeMessage props one level up.\n *\n * The return type illustrates the assumption that the message param\n * becomes a InboundSequencedContainerRuntimeMessage by the time the function returns\n * (but there is no runtime validation of the 'type' or 'compatDetails' values).\n */\nfunction unpack(message: ISequencedDocumentMessage): InboundSequencedContainerRuntimeMessage {\n\t// We assume the contents is an InboundContainerRuntimeMessage (the message is \"packed\")\n\tconst contents = message.contents as InboundContainerRuntimeMessage;\n\n\t// We're going to unpack message in-place (promoting those properties of contents up to message itself)\n\tconst messageUnpacked = message as InboundSequencedContainerRuntimeMessage;\n\n\tmessageUnpacked.type = contents.type;\n\tmessageUnpacked.contents = contents.contents;\n\tif (\"compatDetails\" in contents) {\n\t\t(messageUnpacked as InboundSequencedRecentlyAddedContainerRuntimeMessage).compatDetails =\n\t\t\tcontents.compatDetails;\n\t}\n\treturn messageUnpacked;\n}\n\n/**\n * Unpacks runtime messages.\n *\n * @remarks This API makes no promises regarding backward-compatibility. This is internal API.\n * @param message - message (as it observed in storage / service)\n * @returns whether the given message was unpacked\n *\n * @internal\n */\nexport function unpackRuntimeMessage(\n\tmessage: ISequencedDocumentMessage,\n\tlogLegacyCase: (codePath: string) => void = () => {},\n): boolean {\n\tif (message.type !== MessageType.Operation) {\n\t\t// Legacy format, but it's already \"unpacked\",\n\t\t// i.e. message.type is actually ContainerMessageType.\n\t\t// Or it's non-runtime message.\n\t\t// Nothing to do in such case.\n\t\treturn false;\n\t}\n\n\t// legacy op format?\n\t// TODO: Unsure if this is a real format we should be concerned with. There doesn't appear to be anything prepared to handle the address member.\n\tif (\n\t\t(message.contents as { address?: unknown }).address !== undefined &&\n\t\t(message.contents as { type?: unknown }).type === undefined\n\t) {\n\t\tmessage.type = ContainerMessageType.FluidDataStoreOp;\n\t\tlogLegacyCase(\"unpackRuntimeMessage_contentsWithAddress\");\n\t} else {\n\t\t// new format\n\t\tunpack(message);\n\t}\n\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"remoteMessageProcessor.js","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,0EAGqD;AAErD,wDAK4B;AAC5B,gDAAiD;AAGjD,iEAA2E;AAC3E,mDAA+D;AAoD/D,SAAS,iBAAiB,CACzB,OAAkC;IAElC,IAAA,iBAAM,EACL,OAAO,CAAC,QAAQ,KAAK,IAAI,EACzB,KAAK,CAAC,sEAAsE,CAC5E,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAa,sBAAsB;IAGlC,YACkB,UAAsB,EACtB,cAA8B,EAC9B,iBAAoC;QAFpC,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,sBAAiB,GAAjB,iBAAiB,CAAmB;QAL9C,oBAAe,GAAY,KAAK,CAAC;IAMtC,CAAC;IAEJ,IAAW,eAAe;QACzB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAC/B,CAAC;IAEM,uBAAuB,CAAC,QAAgB;QAC9C,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC,QA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AAC;AACF,CAAC;AAtBD,gEAsBC;AAED;;;;;;GAMG;AACH,SAAS,MAAM,CAAC,OAAkC;IACjD,wFAAwF;IACxF,MAAM,QAAQ,GAAG,OAAO,CAAC,QAA0C,CAAC;IAEpE,uGAAuG;IACvG,MAAM,eAAe,GAAG,OAAkD,CAAC;IAE3E,eAAe,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IACrC,eAAe,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;IAC7C,IAAI,eAAe,IAAI,QAAQ,EAAE,CAAC;QAChC,eAAwE,CAAC,aAAa;YACtF,QAAQ,CAAC,aAAa,CAAC;IACzB,CAAC;IACD,OAAO,eAAe,CAAC;AACxB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,oBAAoB,CACnC,OAAkC,EAClC,gBAA4C,GAAG,EAAE,GAAE,CAAC;IAEpD,IAAI,OAAO,CAAC,IAAI,KAAK,sBAAW,CAAC,SAAS,EAAE,CAAC;QAC5C,8CAA8C;QAC9C,sDAAsD;QACtD,+BAA+B;QAC/B,8BAA8B;QAC9B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,oBAAoB;IACpB,gJAAgJ;IAChJ,IACE,OAAO,CAAC,QAAkC,CAAC,OAAO,KAAK,SAAS;QAChE,OAAO,CAAC,QAA+B,CAAC,IAAI,KAAK,SAAS,EAC1D,CAAC;QACF,OAAO,CAAC,IAAI,GAAG,sCAAoB,CAAC,gBAAgB,CAAC;QACrD,aAAa,CAAC,0CAA0C,CAAC,CAAC;IAC3D,CAAC;SAAM,CAAC;QACP,aAAa;QACb,MAAM,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AA1BD,oDA0BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\n\nimport {\n\tContainerMessageType,\n\ttype InboundContainerRuntimeMessage,\n\ttype InboundSequencedContainerRuntimeMessage,\n\ttype InboundSequencedRecentlyAddedContainerRuntimeMessage,\n} from \"../messageTypes.js\";\nimport { asBatchMetadata } from \"../metadata.js\";\n\nimport { OpDecompressor } from \"./opDecompressor.js\";\nimport { OpGroupingManager, isGroupedBatch } from \"./opGroupingManager.js\";\nimport { OpSplitter, isChunkedMessage } from \"./opSplitter.js\";\n\n/** Info about the batch we learn when we process the first message */\nexport interface BatchStartInfo {\n\t/** Batch ID, if present */\n\treadonly batchId: string | undefined;\n\t/** clientId that sent this batch. Used to compute Batch ID if needed */\n\treadonly clientId: string;\n\t/**\n\t * Client Sequence Number of the Grouped Batch message, or the first message in the ungrouped batch.\n\t * Used to compute Batch ID if needed\n\t *\n\t * @remarks For chunked batches, this is the CSN of the \"representative\" chunk (the final chunk).\n\t * For grouped batches, clientSequenceNumber on messages is overwritten, so we track this original value here.\n\t */\n\treadonly batchStartCsn: number;\n\t/**\n\t * The first message in the batch, or if the batch is empty, the empty grouped batch message.\n\t * Used for accessing the sequence numbers for the (start of the) batch.\n\t *\n\t * @remarks Do not use clientSequenceNumber here, use batchStartCsn instead.\n\t */\n\treadonly keyMessage: ISequencedDocumentMessage;\n}\n\n/**\n * Result of processing the next inbound message.\n * Depending on the message and configuration of RemoteMessageProcessor, the result may be:\n * - A full batch of messages (including a single-message batch)\n * - The first message of a multi-message batch\n * - The next message in a multi-message batch\n */\nexport type InboundMessageResult =\n\t| {\n\t\t\ttype: \"fullBatch\";\n\t\t\tmessages: InboundSequencedContainerRuntimeMessage[];\n\t\t\tbatchStart: BatchStartInfo;\n\t\t\tlength: number;\n\t }\n\t| {\n\t\t\ttype: \"batchStartingMessage\";\n\t\t\tbatchStart: BatchStartInfo;\n\t\t\tnextMessage: InboundSequencedContainerRuntimeMessage;\n\t\t\tlength?: never;\n\t }\n\t| {\n\t\t\ttype: \"nextBatchMessage\";\n\t\t\tbatchEnd?: boolean;\n\t\t\tnextMessage: InboundSequencedContainerRuntimeMessage;\n\t\t\tlength?: never;\n\t };\n\nfunction assertHasClientId(\n\tmessage: ISequencedDocumentMessage,\n): asserts message is ISequencedDocumentMessage & { clientId: string } {\n\tassert(\n\t\tmessage.clientId !== null,\n\t\t0xa02 /* Server-generated message should not reach RemoteMessageProcessor */,\n\t);\n}\n\n/**\n * Stateful class for processing incoming remote messages as the virtualization measures are unwrapped,\n * potentially across numerous inbound ops.\n *\n * @internal\n */\nexport class RemoteMessageProcessor {\n\tprivate batchInProgress: boolean = false;\n\n\tconstructor(\n\t\tprivate readonly opSplitter: OpSplitter,\n\t\tprivate readonly opDecompressor: OpDecompressor,\n\t\tprivate readonly opGroupingManager: OpGroupingManager,\n\t) {}\n\n\tpublic get partialMessages(): ReadonlyMap<string, string[]> {\n\t\treturn this.opSplitter.chunks;\n\t}\n\n\tpublic clearPartialMessagesFor(clientId: string) {\n\t\tthis.opSplitter.clearPartialChunks(clientId);\n\t}\n\n\t/**\n\t * Ungroups and Unchunks the runtime ops of a batch received over the wire\n\t * @param remoteMessageCopy - A shallow copy of a message from another client, possibly virtualized\n\t * (grouped, compressed, and/or chunked).\n\t * Being a shallow copy, it's considered mutable, meaning no other Container or other parallel procedure\n\t * depends on this object instance.\n\t * Note remoteMessageCopy.contents (and other object props) MUST not be modified,\n\t * but may be overwritten (as is the case with contents).\n\t *\n\t * Incoming messages will always have compression, chunking, and grouped batching happen in a defined order and that order cannot be changed.\n\t * When processing these messages, the order is:\n\t * 1. If chunked, process the chunk and only continue if this is a final chunk\n\t * 2. If compressed, decompress the message and store for further unrolling of the decompressed content\n\t * 3. If grouped, ungroup the message\n\t * For more details, see https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/src/opLifecycle/README.md#inbound\n\t *\n\t * @returns all the unchunked, decompressed, ungrouped, unpacked InboundSequencedContainerRuntimeMessage from a single batch\n\t * or undefined if the batch is not yet complete.\n\t */\n\tpublic process(\n\t\tremoteMessageCopy: ISequencedDocumentMessage,\n\t\tlogLegacyCase: (codePath: string) => void,\n\t): InboundMessageResult | undefined {\n\t\tlet message = remoteMessageCopy;\n\n\t\tassertHasClientId(message);\n\t\tconst clientId = message.clientId;\n\n\t\tif (isChunkedMessage(message)) {\n\t\t\tconst chunkProcessingResult = this.opSplitter.processChunk(message);\n\t\t\t// Only continue further if current chunk is the final chunk\n\t\t\tif (!chunkProcessingResult.isFinalChunk) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\t// This message will always be compressed\n\t\t\tmessage = chunkProcessingResult.message;\n\t\t}\n\n\t\tif (this.opDecompressor.isCompressedMessage(message)) {\n\t\t\tthis.opDecompressor.decompressAndStore(message);\n\t\t}\n\n\t\tif (this.opDecompressor.currentlyUnrolling) {\n\t\t\tmessage = this.opDecompressor.unroll(message);\n\t\t\t// Need to unpack after unrolling if not a groupedBatch\n\t\t\tif (!isGroupedBatch(message)) {\n\t\t\t\tunpack(message);\n\t\t\t}\n\t\t}\n\n\t\tif (isGroupedBatch(message)) {\n\t\t\t// We should be awaiting a new batch (batchInProgress false)\n\t\t\tassert(!this.batchInProgress, 0x9d3 /* Grouped batch interrupting another batch */);\n\t\t\tconst batchId = asBatchMetadata(message.metadata)?.batchId;\n\t\t\tconst groupedMessages = this.opGroupingManager.ungroupOp(message).map(unpack);\n\n\t\t\treturn {\n\t\t\t\ttype: \"fullBatch\",\n\t\t\t\tmessages: groupedMessages, // Will be [] for an empty batch\n\t\t\t\tbatchStart: {\n\t\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\t\tclientId,\n\t\t\t\t\tbatchId,\n\t\t\t\t\tkeyMessage: groupedMessages[0] ?? message, // For an empty batch, this is the empty grouped batch message. Needed for sequence numbers for this batch\n\t\t\t\t},\n\t\t\t\tlength: groupedMessages.length, // Will be 0 for an empty batch\n\t\t\t};\n\t\t}\n\n\t\t// Do a final unpack of runtime messages in case the message was not grouped, compressed, or chunked\n\t\tunpackRuntimeMessage(message, logLegacyCase);\n\n\t\treturn this.getResultBasedOnBatchMetadata(\n\t\t\tmessage as InboundSequencedContainerRuntimeMessage & { clientId: string },\n\t\t);\n\t}\n\n\t/**\n\t * Now that the message has been \"unwrapped\" as to any virtualization (grouping, compression, chunking),\n\t * inspect the batch metadata flag and determine what kind of result to return.\n\t */\n\tprivate getResultBasedOnBatchMetadata(\n\t\tmessage: InboundSequencedContainerRuntimeMessage & { clientId: string },\n\t): InboundMessageResult {\n\t\tconst batchMetadataFlag = asBatchMetadata(message.metadata)?.batch;\n\t\tif (!this.batchInProgress) {\n\t\t\t// We are waiting for a new batch\n\t\t\tassert(batchMetadataFlag !== false, 0x9d5 /* Unexpected batch end marker */);\n\n\t\t\t// Start of a new multi-message batch\n\t\t\tif (batchMetadataFlag === true) {\n\t\t\t\tthis.batchInProgress = true;\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"batchStartingMessage\",\n\t\t\t\t\tbatchStart: {\n\t\t\t\t\t\tbatchId: asBatchMetadata(message.metadata)?.batchId,\n\t\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\t\t\tkeyMessage: message,\n\t\t\t\t\t},\n\t\t\t\t\tnextMessage: message,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Single-message batch (Since metadata flag is undefined)\n\t\t\treturn {\n\t\t\t\ttype: \"fullBatch\",\n\t\t\t\tmessages: [message],\n\t\t\t\tbatchStart: {\n\t\t\t\t\tbatchStartCsn: message.clientSequenceNumber,\n\t\t\t\t\tclientId: message.clientId,\n\t\t\t\t\tbatchId: asBatchMetadata(message.metadata)?.batchId,\n\t\t\t\t\tkeyMessage: message,\n\t\t\t\t},\n\t\t\t\tlength: 1,\n\t\t\t};\n\t\t}\n\t\tassert(batchMetadataFlag !== true, 0x9d6 /* Unexpected batch start marker */);\n\n\t\t// Clear batchInProgress state if the batch is ending\n\t\tif (batchMetadataFlag === false) {\n\t\t\tthis.batchInProgress = false;\n\t\t}\n\n\t\treturn {\n\t\t\ttype: \"nextBatchMessage\",\n\t\t\tnextMessage: message,\n\t\t\tbatchEnd: batchMetadataFlag === false,\n\t\t};\n\t}\n}\n\n/**\n * Takes an incoming message and if the contents is a string, JSON.parse's it in place\n * @param mutableMessage - op message received\n * @param hasModernRuntimeMessageEnvelope - false if the message does not contain the modern op envelop where message.type is MessageType.Operation\n * @param logLegacyCase - callback to log when legacy op is encountered\n */\nexport function ensureContentsDeserialized(\n\tmutableMessage: ISequencedDocumentMessage,\n\thasModernRuntimeMessageEnvelope: boolean,\n\tlogLegacyCase: (codePath: string) => void,\n): void {\n\t// This should become unconditional once (Loader LTS) DeltaManager.processInboundMessage() stops parsing content (ADO #12052)\n\t// Note: Until that change is made in the loader, this case will never be hit.\n\t// Then there will be a long time of needing both cases, until LTS catches up to the change.\n\tlet didParseJsonContents: boolean;\n\tif (typeof mutableMessage.contents === \"string\" && mutableMessage.contents !== \"\") {\n\t\tmutableMessage.contents = JSON.parse(mutableMessage.contents);\n\t\tdidParseJsonContents = true;\n\t} else {\n\t\tdidParseJsonContents = false;\n\t}\n\n\t// The DeltaManager parses the contents of the message as JSON if it is a string,\n\t// so we should never end up parsing it here.\n\t// Let's observe if we are wrong about this to learn about these cases.\n\tif (didParseJsonContents) {\n\t\tlogLegacyCase(\"ensureContentsDeserialized_foundJsonContents\");\n\t}\n}\n\n/**\n * For a given message, it moves the nested InboundContainerRuntimeMessage props one level up.\n *\n * The return type illustrates the assumption that the message param\n * becomes a InboundSequencedContainerRuntimeMessage by the time the function returns\n * (but there is no runtime validation of the 'type' or 'compatDetails' values).\n */\nfunction unpack(message: ISequencedDocumentMessage): InboundSequencedContainerRuntimeMessage {\n\t// We assume the contents is an InboundContainerRuntimeMessage (the message is \"packed\")\n\tconst contents = message.contents as InboundContainerRuntimeMessage;\n\n\t// We're going to unpack message in-place (promoting those properties of contents up to message itself)\n\tconst messageUnpacked = message as InboundSequencedContainerRuntimeMessage;\n\n\tmessageUnpacked.type = contents.type;\n\tmessageUnpacked.contents = contents.contents;\n\tif (\"compatDetails\" in contents) {\n\t\t(messageUnpacked as InboundSequencedRecentlyAddedContainerRuntimeMessage).compatDetails =\n\t\t\tcontents.compatDetails;\n\t}\n\treturn messageUnpacked;\n}\n\n/**\n * Unpacks runtime messages.\n *\n * @remarks This API makes no promises regarding backward-compatibility. This is internal API.\n * @param message - message (as it observed in storage / service)\n * @returns whether the given message was unpacked\n *\n * @internal\n */\nexport function unpackRuntimeMessage(\n\tmessage: ISequencedDocumentMessage,\n\tlogLegacyCase: (codePath: string) => void = () => {},\n): boolean {\n\tif (message.type !== MessageType.Operation) {\n\t\t// Legacy format, but it's already \"unpacked\",\n\t\t// i.e. message.type is actually ContainerMessageType.\n\t\t// Or it's non-runtime message.\n\t\t// Nothing to do in such case.\n\t\treturn false;\n\t}\n\n\t// legacy op format?\n\t// TODO: Unsure if this is a real format we should be concerned with. There doesn't appear to be anything prepared to handle the address member.\n\tif (\n\t\t(message.contents as { address?: unknown }).address !== undefined &&\n\t\t(message.contents as { type?: unknown }).type === undefined\n\t) {\n\t\tmessage.type = ContainerMessageType.FluidDataStoreOp;\n\t\tlogLegacyCase(\"unpackRuntimeMessage_contentsWithAddress\");\n\t} else {\n\t\t// new format\n\t\tunpack(message);\n\t}\n\n\treturn true;\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/container-runtime";
8
- export declare const pkgVersion = "2.3.0-288113";
8
+ export declare const pkgVersion = "2.3.1";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,sCAAsC,CAAC;AAC3D,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,sCAAsC,CAAC;AAC3D,eAAO,MAAM,UAAU,UAAU,CAAC"}
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/container-runtime";
11
- exports.pkgVersion = "2.3.0-288113";
11
+ exports.pkgVersion = "2.3.1";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"2.3.0-288113\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,OAAO,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"2.3.1\";\n"]}
@@ -5,7 +5,7 @@
5
5
  import { IDisposable } from "@fluidframework/core-interfaces";
6
6
  import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
7
7
  import { type InboundSequencedContainerRuntimeMessage } from "./messageTypes.js";
8
- import { BatchId, BatchMessage, InboundBatch } from "./opLifecycle/index.js";
8
+ import { BatchId, BatchMessage, InboundMessageResult } from "./opLifecycle/index.js";
9
9
  /**
10
10
  * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the
11
11
  * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.
@@ -21,11 +21,14 @@ export interface IPendingMessage {
21
21
  sequenceNumber?: number;
22
22
  /** Info about the batch this pending message belongs to, for validation and for computing the batchId on reconnect */
23
23
  batchInfo: {
24
- /** The Batch's original clientId, from when it was first flushed to be submitted */
24
+ /**
25
+ * The Batch's original clientId, from when it was first flushed to be submitted.
26
+ * Or, a random uuid if it was never submitted (and batchStartCsn will be -1)
27
+ */
25
28
  clientId: string;
26
29
  /**
27
30
  * The Batch's original clientSequenceNumber, from when it was first flushed to be submitted
28
- * @remarks A negative value means it was not yet submitted when queued here (e.g. disconnected right before flush fired)
31
+ * Or, -1 if it was never submitted (and clientId will be a random uuid)
29
32
  */
30
33
  batchStartCsn: number;
31
34
  /** length of the batch (how many runtime messages here) */
@@ -68,8 +71,6 @@ export declare class PendingStateManager implements IDisposable {
68
71
  * Sequenced local ops that are saved when stashing since pending ops may depend on them
69
72
  */
70
73
  private savedOps;
71
- /** Used to stand in for batchStartCsn for messages that weren't submitted (so no CSN) */
72
- private negativeCounter;
73
74
  private readonly disposeOnce;
74
75
  /** Used to ensure we don't replay ops on the same connection twice */
75
76
  private clientIdFromLastReplay;
@@ -107,26 +108,35 @@ export declare class PendingStateManager implements IDisposable {
107
108
  */
108
109
  applyStashedOpsAt(seqNum?: number): Promise<void>;
109
110
  /**
110
- * Processes an inbound batch of messages - May be local or remote.
111
+ * Compares the batch ID of the incoming batch with the pending batch ID for this client.
112
+ * They should not match, as that would indicate a forked container.
113
+ * @param remoteBatchStart - BatchStartInfo for an incoming batch *NOT* submitted by this client
114
+ * @returns whether the batch IDs match
115
+ */
116
+ private remoteBatchMatchesPendingBatch;
117
+ /**
118
+ * Processes an inbound message or batch of messages - May be local or remote.
111
119
  *
112
- * @param batch - The inbound batch of messages to process. Could be local or remote.
113
- * @param local - true if we submitted this batch and expect corresponding pending messages
114
- * @returns The inbound batch's messages with localOpMetadata "zipped" in.
120
+ * @param inbound - The inbound message(s) to process, with extra info (e.g. about the start of a batch). Could be local or remote.
121
+ * @param local - true if we submitted these messages and expect corresponding pending messages
122
+ * @returns The inbound messages with localOpMetadata "zipped" in.
115
123
  *
116
- * @remarks Closes the container if:
117
- * - The batchStartCsn doesn't match for local batches
124
+ * @throws a DataProcessingError in either of these cases:
125
+ * - The pending message content doesn't match the incoming message content for any message here
126
+ * - The batch IDs *do match* but it's not local (indicates Container forking).
118
127
  */
119
- processInboundBatch(batch: InboundBatch, local: boolean): {
128
+ processInboundMessages(inbound: InboundMessageResult, local: boolean): {
120
129
  message: InboundSequencedContainerRuntimeMessage;
121
130
  localOpMetadata?: unknown;
122
131
  }[];
123
132
  /**
124
- * Processes the incoming batch from the server that was submitted by this client.
125
- * It verifies that messages are received in the right order and that the batch information is correct.
126
- * @param batch - The inbound batch (originating from this client) to correlate with the pending local state
127
- * @returns The inbound batch's messages with localOpMetadata "zipped" in.
133
+ * Processes the incoming message(s) from the server that were submitted by this client.
134
+ * It verifies that messages are received in the right order and that any batch information is correct.
135
+ * @param inbound - The inbound message(s) (originating from this client) to correlate with the pending local state
136
+ * @throws DataProcessingError if the pending message content doesn't match the incoming message content for any message here
137
+ * @returns The inbound messages with localOpMetadata "zipped" in.
128
138
  */
129
- private processPendingLocalBatch;
139
+ private processPendingLocalMessages;
130
140
  /**
131
141
  * Processes the pending local copy of message that's been ack'd by the server.
132
142
  * @param sequenceNumber - The sequenceNumber from the server corresponding to the next pending message.
@@ -1 +1 @@
1
- {"version":3,"file":"pendingStateManager.d.ts","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;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,OAAO,EAAE,uCAAuC,CAAC;QACjD,eAAe,CAAC,EAAE,OAAO,CAAC;KAC1B,EAAE;IAoBH;;;;;;OAMG;IACH,OAAO,CAAC,2BAA2B;IA4BnC;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAwDjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAsDzB;;;;OAIG;IACI,mBAAmB;CA6G1B"}
@@ -47,17 +47,6 @@ function withoutLocalOpMetadata(message) {
47
47
  localOpMetadata: undefined,
48
48
  };
49
49
  }
50
- /**
51
- * Get the effective batch ID for a pending message.
52
- * If the batch ID is already present in the message's op metadata, return it.
53
- * Otherwise, generate a new batch ID using the client ID and batch start CSN.
54
- * @param pendingMessage - The pending message
55
- * @returns The effective batch ID
56
- */
57
- function getEffectiveBatchId(pendingMessage) {
58
- return ((0, metadata_js_1.asBatchMetadata)(pendingMessage.opMetadata)?.batchId ??
59
- (0, index_js_1.generateBatchId)(pendingMessage.batchInfo.clientId, pendingMessage.batchInfo.batchStartCsn));
60
- }
61
50
  /**
62
51
  * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been
63
52
  * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed
@@ -123,8 +112,6 @@ class PendingStateManager {
123
112
  * Sequenced local ops that are saved when stashing since pending ops may depend on them
124
113
  */
125
114
  this.savedOps = [];
126
- /** Used to stand in for batchStartCsn for messages that weren't submitted (so no CSN) */
127
- this.negativeCounter = -1;
128
115
  this.disposeOnce = new internal_1.Lazy(() => {
129
116
  this.initialMessages.clear();
130
117
  this.pendingMessages.clear();
@@ -145,14 +132,16 @@ class PendingStateManager {
145
132
  * or undefined if the batch was not yet sent (e.g. by the time we flushed we lost the connection)
146
133
  */
147
134
  onFlushBatch(batch, clientSequenceNumber) {
148
- // If we're connected this is the client of the current connection,
149
- // otherwise it's the clientId that just disconnected
150
- // It's only undefined if we've NEVER connected. This is a tight corner case and we can
151
- // simply make up a unique ID in this case.
152
- const clientId = this.stateHandler.clientId() ?? (0, uuid_1.v4)();
153
- // If the batch was not yet sent, we need to assign a unique batchStartCsn
154
- // Use a negative number to distinguish these from real CSNs
155
- const batchStartCsn = clientSequenceNumber ?? this.negativeCounter--;
135
+ // clientId and batchStartCsn are used for generating the batchId so we can detect container forks
136
+ // where this batch was submitted by two different clients rehydrating from the same local state.
137
+ // In the typical case where the batch was actually sent, use the clientId and clientSequenceNumber.
138
+ // In the case where the batch was not sent, use a random uuid for clientId, and -1 for clientSequenceNumber to indicate this case.
139
+ // This will guarantee uniqueness of the batchId, and is a suitable fallback since clientId/CSN is only needed if the batch was actually sent/sequenced.
140
+ const batchWasSent = clientSequenceNumber !== undefined;
141
+ const [clientId, batchStartCsn] = batchWasSent
142
+ ? [this.stateHandler.clientId(), clientSequenceNumber]
143
+ : [(0, uuid_1.v4)(), -1]; // -1 will indicate not a real clientId/CSN pair
144
+ (0, internal_1.assert)(clientId !== undefined, 0xa33 /* clientId (from stateHandler) could only be undefined if we've never connected, but we have a CSN so we know that's not the case */);
156
145
  for (const message of batch) {
157
146
  const { contents: content = "", referenceSequenceNumber, localOpMetadata, metadata: opMetadata, } = message;
158
147
  const pendingMessage = {
@@ -215,38 +204,66 @@ class PendingStateManager {
215
204
  }
216
205
  }
217
206
  /**
218
- * Processes an inbound batch of messages - May be local or remote.
207
+ * Compares the batch ID of the incoming batch with the pending batch ID for this client.
208
+ * They should not match, as that would indicate a forked container.
209
+ * @param remoteBatchStart - BatchStartInfo for an incoming batch *NOT* submitted by this client
210
+ * @returns whether the batch IDs match
211
+ */
212
+ remoteBatchMatchesPendingBatch(remoteBatchStart) {
213
+ // We may have no pending changes - if so, no match, no problem.
214
+ const pendingMessage = this.pendingMessages.peekFront();
215
+ if (pendingMessage === undefined) {
216
+ return false;
217
+ }
218
+ // We must compare the effective batch IDs, since one of these ops
219
+ // may have been the original, not resubmitted, so wouldn't have its batch ID stamped yet.
220
+ const pendingBatchId = (0, index_js_1.getEffectiveBatchId)(pendingMessage);
221
+ const inboundBatchId = (0, index_js_1.getEffectiveBatchId)(remoteBatchStart);
222
+ return pendingBatchId === inboundBatchId;
223
+ }
224
+ /**
225
+ * Processes an inbound message or batch of messages - May be local or remote.
219
226
  *
220
- * @param batch - The inbound batch of messages to process. Could be local or remote.
221
- * @param local - true if we submitted this batch and expect corresponding pending messages
222
- * @returns The inbound batch's messages with localOpMetadata "zipped" in.
227
+ * @param inbound - The inbound message(s) to process, with extra info (e.g. about the start of a batch). Could be local or remote.
228
+ * @param local - true if we submitted these messages and expect corresponding pending messages
229
+ * @returns The inbound messages with localOpMetadata "zipped" in.
223
230
  *
224
- * @remarks Closes the container if:
225
- * - The batchStartCsn doesn't match for local batches
231
+ * @throws a DataProcessingError in either of these cases:
232
+ * - The pending message content doesn't match the incoming message content for any message here
233
+ * - The batch IDs *do match* but it's not local (indicates Container forking).
226
234
  */
227
- processInboundBatch(batch, local) {
235
+ processInboundMessages(inbound, local) {
228
236
  if (local) {
229
- return this.processPendingLocalBatch(batch);
237
+ return this.processPendingLocalMessages(inbound);
238
+ }
239
+ // An inbound remote batch should not match the pending batch ID for this client.
240
+ // That would indicate the container forked (two instances trying to submit the same local state)
241
+ if ("batchStart" in inbound && this.remoteBatchMatchesPendingBatch(inbound.batchStart)) {
242
+ throw internal_2.DataProcessingError.create("Forked Container Error! Matching batchIds but mismatched clientId", "PendingStateManager.processInboundMessages", inbound.batchStart.keyMessage);
230
243
  }
231
244
  // No localOpMetadata for remote messages
232
- return batch.messages.map((message) => ({ message }));
245
+ const messages = inbound.type === "fullBatch" ? inbound.messages : [inbound.nextMessage];
246
+ return messages.map((message) => ({ message }));
233
247
  }
234
248
  /**
235
- * Processes the incoming batch from the server that was submitted by this client.
236
- * It verifies that messages are received in the right order and that the batch information is correct.
237
- * @param batch - The inbound batch (originating from this client) to correlate with the pending local state
238
- * @returns The inbound batch's messages with localOpMetadata "zipped" in.
249
+ * Processes the incoming message(s) from the server that were submitted by this client.
250
+ * It verifies that messages are received in the right order and that any batch information is correct.
251
+ * @param inbound - The inbound message(s) (originating from this client) to correlate with the pending local state
252
+ * @throws DataProcessingError if the pending message content doesn't match the incoming message content for any message here
253
+ * @returns The inbound messages with localOpMetadata "zipped" in.
239
254
  */
240
- processPendingLocalBatch(batch) {
241
- this.onLocalBatchBegin(batch);
255
+ processPendingLocalMessages(inbound) {
256
+ if ("batchStart" in inbound) {
257
+ this.onLocalBatchBegin(inbound.batchStart, inbound.length);
258
+ }
242
259
  // Empty batch
243
- if (batch.messages.length === 0) {
244
- (0, internal_1.assert)(batch.emptyBatchSequenceNumber !== undefined, 0x9fb /* Expected sequence number for empty batch */);
245
- const localOpMetadata = this.processNextPendingMessage(batch.emptyBatchSequenceNumber);
260
+ if (inbound.length === 0) {
261
+ const localOpMetadata = this.processNextPendingMessage(inbound.batchStart.keyMessage.sequenceNumber);
246
262
  (0, internal_1.assert)((0, metadata_js_1.asEmptyBatchLocalOpMetadata)(localOpMetadata)?.emptyBatch === true, 0xa20 /* Expected empty batch marker */);
247
263
  return [];
248
264
  }
249
- return batch.messages.map((message) => ({
265
+ const messages = inbound.type === "fullBatch" ? inbound.messages : [inbound.nextMessage];
266
+ return messages.map((message) => ({
250
267
  message,
251
268
  localOpMetadata: this.processNextPendingMessage(message.sequenceNumber, message),
252
269
  }));
@@ -293,30 +310,42 @@ class PendingStateManager {
293
310
  /**
294
311
  * Check if the incoming batch matches the batch info for the next pending message.
295
312
  */
296
- onLocalBatchBegin(batch) {
313
+ onLocalBatchBegin(batchStart, batchLength) {
297
314
  // Get the next message from the pending queue. Verify a message exists.
298
315
  const pendingMessage = this.pendingMessages.peekFront();
299
316
  (0, internal_1.assert)(pendingMessage !== undefined, 0xa21 /* No pending message found as we start processing this remote batch */);
300
- // Note: This could be undefined if this batch became empty on resubmit.
301
- // In this case the next pending message is an empty batch marker.
302
- // Empty batches became empty on Resubmit, and submit them and track them in case
303
- // a different fork of this container also submitted the same batch (and it may not be empty for that fork).
304
- const firstMessage = batch.messages.length > 0 ? batch.messages[0] : undefined;
305
- const expectedPendingBatchLength = batch.messages.length === 0 ? 1 : batch.messages.length;
317
+ // If this batch became empty on resubmit, batch.messages will be empty (so firstMessage undefined)
318
+ // and the next pending message should be an empty batch marker.
319
+ // More Info: We must submit empty batches and track them in case a different fork
320
+ // of this container also submitted the same batch (and it may not be empty for that fork).
321
+ const firstMessage = batchStart.keyMessage;
322
+ // -1 length is for back compat, undefined length means we actually don't know it
323
+ const skipLengthCheck = pendingMessage.batchInfo.length === -1 || batchLength === undefined;
324
+ const expectedPendingBatchLength = batchLength === 0
325
+ ? 1 // For an empty batch, expect a singleton array with the empty batch marker
326
+ : batchLength; // Otherwise, the lengths should actually match
327
+ // Note: We don't need to use getEffectiveBatchId here, just check the explicit stamped batchID
328
+ // That logic is needed only when comparing across potential container forks.
329
+ // Furthermore, we also are comparing the batch IDs constituent data - clientId (it's local) and batchStartCsn.
330
+ const pendingBatchId = (0, metadata_js_1.asBatchMetadata)(pendingMessage.opMetadata)?.batchId;
331
+ const inboundBatchId = batchStart.batchId;
306
332
  // We expect the incoming batch to be of the same length, starting at the same clientSequenceNumber,
307
- // as the batch we originally submitted.
333
+ // as the batch we originally submitted. The batchIds should match as well, if set (or neither should be set)
308
334
  // We have another later check to compare the message contents, which we'd expect to fail if this check does,
309
- // so we don't throw here, merely log. In a later release this check may replace that one.
310
- if (pendingMessage.batchInfo.batchStartCsn !== batch.batchStartCsn ||
311
- (pendingMessage.batchInfo.length >= 0 && // -1 length is back compat and isn't suitable for this check
312
- pendingMessage.batchInfo.length !== expectedPendingBatchLength)) {
335
+ // so we don't throw here, merely log. In a later release this check may replace that one since it's cheaper.
336
+ if (pendingMessage.batchInfo.batchStartCsn !== batchStart.batchStartCsn ||
337
+ (!skipLengthCheck && pendingMessage.batchInfo.length !== expectedPendingBatchLength) ||
338
+ pendingBatchId !== inboundBatchId) {
313
339
  this.logger?.sendErrorEvent({
314
340
  eventName: "BatchInfoMismatch",
315
341
  details: {
316
342
  pendingBatchCsn: pendingMessage.batchInfo.batchStartCsn,
317
- batchStartCsn: batch.batchStartCsn,
343
+ batchStartCsn: batchStart.batchStartCsn,
318
344
  pendingBatchLength: pendingMessage.batchInfo.length,
319
- batchLength: batch.messages.length,
345
+ expectedPendingBatchLength,
346
+ batchLength,
347
+ pendingBatchId,
348
+ inboundBatchId,
320
349
  pendingMessageBatchMetadata: (0, metadata_js_1.asBatchMetadata)(pendingMessage.opMetadata)?.batch,
321
350
  messageBatchMetadata: (0, metadata_js_1.asBatchMetadata)(firstMessage?.metadata)?.batch,
322
351
  },
@@ -347,9 +376,9 @@ class PendingStateManager {
347
376
  const batchMetadataFlag = (0, metadata_js_1.asBatchMetadata)(pendingMessage.opMetadata)?.batch;
348
377
  (0, internal_1.assert)(batchMetadataFlag !== false, 0x41b /* We cannot process batches in chunks */);
349
378
  // The next message starts a batch (possibly single-message), and we'll need its batchId.
350
- const batchId = getEffectiveBatchId(pendingMessage);
351
- // Resubmit no messages, with the batchId. Will result in another empty batch marker.
379
+ const batchId = (0, index_js_1.getEffectiveBatchId)(pendingMessage);
352
380
  if ((0, metadata_js_1.asEmptyBatchLocalOpMetadata)(pendingMessage.localOpMetadata)?.emptyBatch === true) {
381
+ // Resubmit no messages, with the batchId. Will result in another empty batch marker.
353
382
  this.stateHandler.reSubmitBatch([], batchId);
354
383
  continue;
355
384
  }