@fluidframework/container-runtime 2.32.0 → 2.33.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 (189) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/container-runtime.legacy.alpha.api.md +71 -67
  3. package/container-runtime.test-files.tar +0 -0
  4. package/dist/blobManager/blobManager.d.ts +7 -4
  5. package/dist/blobManager/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager/blobManager.js +38 -12
  7. package/dist/blobManager/blobManager.js.map +1 -1
  8. package/dist/channelCollection.d.ts +4 -0
  9. package/dist/channelCollection.d.ts.map +1 -1
  10. package/dist/channelCollection.js +24 -0
  11. package/dist/channelCollection.js.map +1 -1
  12. package/dist/compatUtils.d.ts +74 -0
  13. package/dist/compatUtils.d.ts.map +1 -0
  14. package/dist/compatUtils.js +151 -0
  15. package/dist/compatUtils.js.map +1 -0
  16. package/dist/compressionDefinitions.d.ts +39 -0
  17. package/dist/compressionDefinitions.d.ts.map +1 -0
  18. package/dist/compressionDefinitions.js +30 -0
  19. package/dist/compressionDefinitions.js.map +1 -0
  20. package/dist/containerRuntime.d.ts +78 -52
  21. package/dist/containerRuntime.d.ts.map +1 -1
  22. package/dist/containerRuntime.js +141 -54
  23. package/dist/containerRuntime.js.map +1 -1
  24. package/dist/dataStoreContext.d.ts +3 -0
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +122 -66
  27. package/dist/dataStoreContext.js.map +1 -1
  28. package/dist/deltaManagerProxies.d.ts +55 -12
  29. package/dist/deltaManagerProxies.d.ts.map +1 -1
  30. package/dist/deltaManagerProxies.js +63 -55
  31. package/dist/deltaManagerProxies.js.map +1 -1
  32. package/dist/gc/gcDefinitions.d.ts +2 -0
  33. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  34. package/dist/gc/gcDefinitions.js.map +1 -1
  35. package/dist/index.d.ts +4 -2
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +3 -2
  38. package/dist/index.js.map +1 -1
  39. package/dist/legacy.d.ts +1 -0
  40. package/dist/opLifecycle/batchManager.d.ts +3 -15
  41. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  42. package/dist/opLifecycle/batchManager.js +5 -39
  43. package/dist/opLifecycle/batchManager.js.map +1 -1
  44. package/dist/opLifecycle/definitions.d.ts +44 -11
  45. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  46. package/dist/opLifecycle/definitions.js.map +1 -1
  47. package/dist/opLifecycle/index.d.ts +3 -3
  48. package/dist/opLifecycle/index.d.ts.map +1 -1
  49. package/dist/opLifecycle/index.js +3 -2
  50. package/dist/opLifecycle/index.js.map +1 -1
  51. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  52. package/dist/opLifecycle/opCompressor.js +4 -4
  53. package/dist/opLifecycle/opCompressor.js.map +1 -1
  54. package/dist/opLifecycle/opDecompressor.js +3 -3
  55. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  56. package/dist/opLifecycle/opGroupingManager.d.ts +2 -2
  57. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  58. package/dist/opLifecycle/opGroupingManager.js +1 -2
  59. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  60. package/dist/opLifecycle/opSerialization.d.ts +3 -1
  61. package/dist/opLifecycle/opSerialization.d.ts.map +1 -1
  62. package/dist/opLifecycle/opSerialization.js +4 -2
  63. package/dist/opLifecycle/opSerialization.js.map +1 -1
  64. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  65. package/dist/opLifecycle/opSplitter.js +2 -2
  66. package/dist/opLifecycle/opSplitter.js.map +1 -1
  67. package/dist/opLifecycle/outbox.d.ts +25 -3
  68. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  69. package/dist/opLifecycle/outbox.js +112 -61
  70. package/dist/opLifecycle/outbox.js.map +1 -1
  71. package/dist/packageVersion.d.ts +1 -1
  72. package/dist/packageVersion.js +1 -1
  73. package/dist/packageVersion.js.map +1 -1
  74. package/dist/pendingStateManager.d.ts +36 -7
  75. package/dist/pendingStateManager.d.ts.map +1 -1
  76. package/dist/pendingStateManager.js +83 -16
  77. package/dist/pendingStateManager.js.map +1 -1
  78. package/dist/runtimeLayerCompatState.d.ts.map +1 -1
  79. package/dist/runtimeLayerCompatState.js +1 -1
  80. package/dist/runtimeLayerCompatState.js.map +1 -1
  81. package/dist/summary/documentSchema.d.ts +1 -0
  82. package/dist/summary/documentSchema.d.ts.map +1 -1
  83. package/dist/summary/documentSchema.js +2 -0
  84. package/dist/summary/documentSchema.js.map +1 -1
  85. package/lib/blobManager/blobManager.d.ts +7 -4
  86. package/lib/blobManager/blobManager.d.ts.map +1 -1
  87. package/lib/blobManager/blobManager.js +38 -12
  88. package/lib/blobManager/blobManager.js.map +1 -1
  89. package/lib/channelCollection.d.ts +4 -0
  90. package/lib/channelCollection.d.ts.map +1 -1
  91. package/lib/channelCollection.js +24 -0
  92. package/lib/channelCollection.js.map +1 -1
  93. package/lib/compatUtils.d.ts +74 -0
  94. package/lib/compatUtils.d.ts.map +1 -0
  95. package/lib/compatUtils.js +142 -0
  96. package/lib/compatUtils.js.map +1 -0
  97. package/lib/compressionDefinitions.d.ts +39 -0
  98. package/lib/compressionDefinitions.d.ts.map +1 -0
  99. package/lib/compressionDefinitions.js +27 -0
  100. package/lib/compressionDefinitions.js.map +1 -0
  101. package/lib/containerRuntime.d.ts +78 -52
  102. package/lib/containerRuntime.d.ts.map +1 -1
  103. package/lib/containerRuntime.js +143 -56
  104. package/lib/containerRuntime.js.map +1 -1
  105. package/lib/dataStoreContext.d.ts +3 -0
  106. package/lib/dataStoreContext.d.ts.map +1 -1
  107. package/lib/dataStoreContext.js +57 -1
  108. package/lib/dataStoreContext.js.map +1 -1
  109. package/lib/deltaManagerProxies.d.ts +55 -12
  110. package/lib/deltaManagerProxies.d.ts.map +1 -1
  111. package/lib/deltaManagerProxies.js +63 -55
  112. package/lib/deltaManagerProxies.js.map +1 -1
  113. package/lib/gc/gcDefinitions.d.ts +2 -0
  114. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  115. package/lib/gc/gcDefinitions.js.map +1 -1
  116. package/lib/index.d.ts +4 -2
  117. package/lib/index.d.ts.map +1 -1
  118. package/lib/index.js +2 -1
  119. package/lib/index.js.map +1 -1
  120. package/lib/legacy.d.ts +1 -0
  121. package/lib/opLifecycle/batchManager.d.ts +3 -15
  122. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  123. package/lib/opLifecycle/batchManager.js +4 -37
  124. package/lib/opLifecycle/batchManager.js.map +1 -1
  125. package/lib/opLifecycle/definitions.d.ts +44 -11
  126. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  127. package/lib/opLifecycle/definitions.js.map +1 -1
  128. package/lib/opLifecycle/index.d.ts +3 -3
  129. package/lib/opLifecycle/index.d.ts.map +1 -1
  130. package/lib/opLifecycle/index.js +2 -2
  131. package/lib/opLifecycle/index.js.map +1 -1
  132. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  133. package/lib/opLifecycle/opCompressor.js +2 -2
  134. package/lib/opLifecycle/opCompressor.js.map +1 -1
  135. package/lib/opLifecycle/opDecompressor.js +1 -1
  136. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  137. package/lib/opLifecycle/opGroupingManager.d.ts +2 -2
  138. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  139. package/lib/opLifecycle/opGroupingManager.js +1 -2
  140. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  141. package/lib/opLifecycle/opSerialization.d.ts +3 -1
  142. package/lib/opLifecycle/opSerialization.d.ts.map +1 -1
  143. package/lib/opLifecycle/opSerialization.js +4 -2
  144. package/lib/opLifecycle/opSerialization.js.map +1 -1
  145. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  146. package/lib/opLifecycle/opSplitter.js +1 -1
  147. package/lib/opLifecycle/opSplitter.js.map +1 -1
  148. package/lib/opLifecycle/outbox.d.ts +25 -3
  149. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  150. package/lib/opLifecycle/outbox.js +110 -61
  151. package/lib/opLifecycle/outbox.js.map +1 -1
  152. package/lib/packageVersion.d.ts +1 -1
  153. package/lib/packageVersion.js +1 -1
  154. package/lib/packageVersion.js.map +1 -1
  155. package/lib/pendingStateManager.d.ts +36 -7
  156. package/lib/pendingStateManager.d.ts.map +1 -1
  157. package/lib/pendingStateManager.js +84 -17
  158. package/lib/pendingStateManager.js.map +1 -1
  159. package/lib/runtimeLayerCompatState.d.ts.map +1 -1
  160. package/lib/runtimeLayerCompatState.js +2 -2
  161. package/lib/runtimeLayerCompatState.js.map +1 -1
  162. package/lib/summary/documentSchema.d.ts +1 -0
  163. package/lib/summary/documentSchema.d.ts.map +1 -1
  164. package/lib/summary/documentSchema.js +2 -0
  165. package/lib/summary/documentSchema.js.map +1 -1
  166. package/lib/tsdoc-metadata.json +1 -1
  167. package/package.json +21 -20
  168. package/src/blobManager/blobManager.ts +48 -15
  169. package/src/channelCollection.ts +27 -0
  170. package/src/compatUtils.ts +211 -0
  171. package/src/compressionDefinitions.ts +47 -0
  172. package/src/containerRuntime.ts +259 -108
  173. package/src/dataStoreContext.ts +82 -2
  174. package/src/deltaManagerProxies.ts +132 -70
  175. package/src/gc/gcDefinitions.ts +2 -0
  176. package/src/index.ts +5 -3
  177. package/src/opLifecycle/batchManager.ts +7 -52
  178. package/src/opLifecycle/definitions.ts +45 -11
  179. package/src/opLifecycle/index.ts +7 -2
  180. package/src/opLifecycle/opCompressor.ts +2 -2
  181. package/src/opLifecycle/opDecompressor.ts +1 -1
  182. package/src/opLifecycle/opGroupingManager.ts +7 -5
  183. package/src/opLifecycle/opSerialization.ts +6 -2
  184. package/src/opLifecycle/opSplitter.ts +1 -1
  185. package/src/opLifecycle/outbox.ts +154 -85
  186. package/src/packageVersion.ts +1 -1
  187. package/src/pendingStateManager.ts +135 -21
  188. package/src/runtimeLayerCompatState.ts +5 -2
  189. package/src/summary/documentSchema.ts +3 -0
@@ -1 +1 @@
1
- {"version":3,"file":"opGroupingManager.js","sourceRoot":"","sources":["../../src/opLifecycle/opGroupingManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAE7D,uEAGkD;AAsBlD,SAAS,eAAe,CAAC,UAAmB;IAC3C,OAAO,CACL,UAAoD,EAAE,IAAI;QAC3D,iBAAiB,CAAC,cAAc,CAChC,CAAC;AACH,CAAC;AAED,SAAgB,cAAc,CAAC,EAA6B;IAC3D,OAAO,eAAe,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAFD,wCAEC;AAMD,MAAa,iBAAiB;IAI7B,YACkB,MAA+B,EAChD,MAA4B;QADX,WAAM,GAAN,MAAM,CAAyB;QAGhD,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED;;;;;;OAMG;IACI,uBAAuB,CAC7B,mBAA2B,EAC3B,uBAA+B;QAE/B,IAAA,iBAAM,EACL,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAClC,KAAK,CAAC,yEAAyE,CAC/E,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;YACnC,IAAI,EAAE,iBAAiB,CAAC,cAAc;YACtC,QAAQ,EAAE,EAAE;SACZ,CAAC,CAAC;QAEH,MAAM,kBAAkB,GAAyB;YAChD,QAAQ,EAAE,EAAE,OAAO,EAAE,mBAAmB,EAAE;YAC1C,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;YACrC,uBAAuB;YACvB,QAAQ,EAAE,YAAY;SACtB,CAAC;QACF,MAAM,aAAa,GAA2B;YAC7C,kBAAkB,EAAE,CAAC;YACrB,QAAQ,EAAE,CAAC,kBAAkB,CAAC;YAC9B,uBAAuB;SACvB,CAAC;QACF,OAAO,EAAE,aAAa,EAAE,kBAAkB,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;IAC3C,CAAC;;AAxHF,8CAyHC;AAxHgB,gCAAc,GAAG,cAAc,CAAC","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 } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tcreateChildLogger,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype OutboundBatch,\n\ttype OutboundBatchMessage,\n\ttype OutboundSingletonBatch,\n} from \"./definitions.js\";\n\n/**\n * Grouping makes assumptions about the shape of message contents. This interface codifies those assumptions, but does not validate them.\n */\ninterface IGroupedBatchMessageContents {\n\ttype: typeof OpGroupingManager.groupedBatchOp;\n\tcontents: IGroupedMessage[];\n}\n\ninterface IGroupedMessage {\n\tcontents?: unknown;\n\tmetadata?: Record<string, unknown>;\n\tcompression?: string;\n}\n\nfunction isGroupContents(opContents: unknown): opContents is IGroupedBatchMessageContents {\n\treturn (\n\t\t(opContents as Partial<IGroupedBatchMessageContents>)?.type ===\n\t\tOpGroupingManager.groupedBatchOp\n\t);\n}\n\nexport function isGroupedBatch(op: ISequencedDocumentMessage): boolean {\n\treturn isGroupContents(op.contents);\n}\n\nexport interface OpGroupingManagerConfig {\n\treadonly groupedBatchingEnabled: boolean;\n}\n\nexport class OpGroupingManager {\n\tstatic readonly groupedBatchOp = \"groupedBatch\";\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly config: OpGroupingManagerConfig,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpGroupingManager\" });\n\t}\n\n\t/**\n\t * Creates a new batch with a single message of type \"groupedBatch\" and empty contents.\n\t * This is needed as a placeholder if a batch becomes empty on resubmit, but we are tracking batch IDs.\n\t * @param resubmittingBatchId - batch ID of the resubmitting batch\n\t * @param referenceSequenceNumber - reference sequence number\n\t * @returns - The outbound batch as well as the interior placeholder message\n\t */\n\tpublic createEmptyGroupedBatch(\n\t\tresubmittingBatchId: string,\n\t\treferenceSequenceNumber: number,\n\t): { outboundBatch: OutboundSingletonBatch; placeholderMessage: OutboundBatchMessage } {\n\t\tassert(\n\t\t\tthis.config.groupedBatchingEnabled,\n\t\t\t0xa00 /* cannot create empty grouped batch when grouped batching is disabled */,\n\t\t);\n\t\tconst serializedOp = JSON.stringify({\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: [],\n\t\t});\n\n\t\tconst placeholderMessage: OutboundBatchMessage = {\n\t\t\tmetadata: { batchId: resubmittingBatchId },\n\t\t\tlocalOpMetadata: { emptyBatch: true },\n\t\t\treferenceSequenceNumber,\n\t\t\tcontents: serializedOp,\n\t\t};\n\t\tconst outboundBatch: OutboundSingletonBatch = {\n\t\t\tcontentSizeInBytes: 0,\n\t\t\tmessages: [placeholderMessage],\n\t\t\treferenceSequenceNumber,\n\t\t};\n\t\treturn { outboundBatch, placeholderMessage };\n\t}\n\n\t/**\n\t * Converts the given batch into a \"grouped batch\" - a batch with a single message of type \"groupedBatch\",\n\t * with contents being an array of the original batch's messages.\n\t *\n\t * If the batch already has only 1 message, it is returned as-is.\n\t *\n\t * @remarks - Remember that a BatchMessage has its content JSON serialized, so the incoming batch message contents\n\t * must be parsed first, and then the type and contents mentioned above are hidden in that JSON serialization.\n\t */\n\tpublic groupBatch(batch: OutboundBatch): OutboundSingletonBatch {\n\t\tassert(this.groupedBatchingEnabled(), 0xb79 /* grouping disabled! */);\n\t\tassert(batch.messages.length > 0, 0xb7a /* Unexpected attempt to group an empty batch */);\n\n\t\tif (batch.messages.length === 1) {\n\t\t\treturn batch as OutboundSingletonBatch;\n\t\t}\n\n\t\tif (batch.messages.length >= 1000) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"GroupLargeBatch\",\n\t\t\t\tlength: batch.messages.length,\n\t\t\t\treentrant: batch.hasReentrantOps,\n\t\t\t\treferenceSequenceNumber: batch.messages[0].referenceSequenceNumber,\n\t\t\t});\n\t\t}\n\t\t// We expect this will be on the first message, if present at all.\n\t\tlet groupedBatchId;\n\t\tfor (const message of batch.messages) {\n\t\t\tif (message.metadata) {\n\t\t\t\tconst { batch: _batch, batchId, ...rest } = message.metadata;\n\t\t\t\tif (batchId) {\n\t\t\t\t\tgroupedBatchId = batchId;\n\t\t\t\t}\n\t\t\t\tassert(Object.keys(rest).length === 0, 0x5dd /* cannot group ops with metadata */);\n\t\t\t}\n\t\t}\n\n\t\tconst serializedContent = JSON.stringify({\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: batch.messages.map<IGroupedMessage>((message) => ({\n\t\t\t\tcontents: message.contents === undefined ? undefined : JSON.parse(message.contents),\n\t\t\t\tmetadata: message.metadata,\n\t\t\t\tcompression: message.compression,\n\t\t\t})),\n\t\t});\n\n\t\tconst groupedBatch: OutboundSingletonBatch = {\n\t\t\t...batch,\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\tmetadata: { batchId: groupedBatchId },\n\t\t\t\t\treferenceSequenceNumber: batch.messages[0].referenceSequenceNumber,\n\t\t\t\t\tcontents: serializedContent,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t\treturn groupedBatch;\n\t}\n\n\tpublic ungroupOp(op: ISequencedDocumentMessage): ISequencedDocumentMessage[] {\n\t\tassert(isGroupContents(op.contents), 0x947 /* can only ungroup a grouped batch */);\n\t\tconst contents: IGroupedBatchMessageContents = op.contents;\n\n\t\tlet fakeCsn = 1;\n\t\treturn contents.contents.map((subMessage) => ({\n\t\t\t...op,\n\t\t\tclientSequenceNumber: fakeCsn++,\n\t\t\tcontents: subMessage.contents,\n\t\t\tmetadata: subMessage.metadata,\n\t\t\tcompression: subMessage.compression,\n\t\t}));\n\t}\n\n\tpublic groupedBatchingEnabled(): boolean {\n\t\treturn this.config.groupedBatchingEnabled;\n\t}\n}\n"]}
1
+ {"version":3,"file":"opGroupingManager.js","sourceRoot":"","sources":["../../src/opLifecycle/opGroupingManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAA6D;AAE7D,uEAGkD;AAsBlD,SAAS,eAAe,CAAC,UAAmB;IAC3C,OAAO,CACL,UAAoD,EAAE,IAAI;QAC3D,iBAAiB,CAAC,cAAc,CAChC,CAAC;AACH,CAAC;AAED,SAAgB,cAAc,CAAC,EAA6B;IAC3D,OAAO,eAAe,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAFD,wCAEC;AAMD,MAAa,iBAAiB;IAI7B,YACkB,MAA+B,EAChD,MAA4B;QADX,WAAM,GAAN,MAAM,CAAyB;QAGhD,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED;;;;;;OAMG;IACI,uBAAuB,CAC7B,mBAA2B,EAC3B,uBAA+B;QAK/B,IAAA,iBAAM,EACL,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAClC,KAAK,CAAC,yEAAyE,CAC/E,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;YACnC,IAAI,EAAE,iBAAiB,CAAC,cAAc;YACtC,QAAQ,EAAE,EAAE;SACZ,CAAC,CAAC;QAEH,MAAM,kBAAkB,GAA+B;YACtD,QAAQ,EAAE,EAAE,OAAO,EAAE,mBAAmB,EAAE;YAC1C,eAAe,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE;YACrC,uBAAuB;SACvB,CAAC;QACF,MAAM,aAAa,GAA2B;YAC7C,kBAAkB,EAAE,CAAC;YACrB,QAAQ,EAAE,CAAC,EAAE,GAAG,kBAAkB,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;YAC7D,uBAAuB;SACvB,CAAC;QACF,OAAO,E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MAAM,CAAC,sBAAsB,CAAC;IAC3C,CAAC;;AA1HF,8CA2HC;AA1HgB,gCAAc,GAAG,cAAc,CAAC","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 } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tcreateChildLogger,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype LocalEmptyBatchPlaceholder,\n\ttype OutboundBatch,\n\ttype OutboundSingletonBatch,\n} from \"./definitions.js\";\n\n/**\n * Grouping makes assumptions about the shape of message contents. This interface codifies those assumptions, but does not validate them.\n */\ninterface IGroupedBatchMessageContents {\n\ttype: typeof OpGroupingManager.groupedBatchOp;\n\tcontents: IGroupedMessage[];\n}\n\ninterface IGroupedMessage {\n\tcontents?: unknown;\n\tmetadata?: Record<string, unknown>;\n\tcompression?: string;\n}\n\nfunction isGroupContents(opContents: unknown): opContents is IGroupedBatchMessageContents {\n\treturn (\n\t\t(opContents as Partial<IGroupedBatchMessageContents>)?.type ===\n\t\tOpGroupingManager.groupedBatchOp\n\t);\n}\n\nexport function isGroupedBatch(op: ISequencedDocumentMessage): boolean {\n\treturn isGroupContents(op.contents);\n}\n\nexport interface OpGroupingManagerConfig {\n\treadonly groupedBatchingEnabled: boolean;\n}\n\nexport class OpGroupingManager {\n\tstatic readonly groupedBatchOp = \"groupedBatch\";\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tprivate readonly config: OpGroupingManagerConfig,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpGroupingManager\" });\n\t}\n\n\t/**\n\t * Creates a new batch with a single message of type \"groupedBatch\" and empty contents.\n\t * This is needed as a placeholder if a batch becomes empty on resubmit, but we are tracking batch IDs.\n\t * @param resubmittingBatchId - batch ID of the resubmitting batch\n\t * @param referenceSequenceNumber - reference sequence number\n\t * @returns - The outbound batch as well as the interior placeholder message\n\t */\n\tpublic createEmptyGroupedBatch(\n\t\tresubmittingBatchId: string,\n\t\treferenceSequenceNumber: number,\n\t): {\n\t\toutboundBatch: OutboundSingletonBatch;\n\t\tplaceholderMessage: LocalEmptyBatchPlaceholder;\n\t} {\n\t\tassert(\n\t\t\tthis.config.groupedBatchingEnabled,\n\t\t\t0xa00 /* cannot create empty grouped batch when grouped batching is disabled */,\n\t\t);\n\t\tconst serializedOp = JSON.stringify({\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: [],\n\t\t});\n\n\t\tconst placeholderMessage: LocalEmptyBatchPlaceholder = {\n\t\t\tmetadata: { batchId: resubmittingBatchId },\n\t\t\tlocalOpMetadata: { emptyBatch: true },\n\t\t\treferenceSequenceNumber,\n\t\t};\n\t\tconst outboundBatch: OutboundSingletonBatch = {\n\t\t\tcontentSizeInBytes: 0,\n\t\t\tmessages: [{ ...placeholderMessage, contents: serializedOp }],\n\t\t\treferenceSequenceNumber,\n\t\t};\n\t\treturn { outboundBatch, placeholderMessage };\n\t}\n\n\t/**\n\t * Converts the given batch into a \"grouped batch\" - a batch with a single message of type \"groupedBatch\",\n\t * with contents being an array of the original batch's messages.\n\t *\n\t * If the batch already has only 1 message, it is returned as-is.\n\t *\n\t * @remarks - Remember that a BatchMessage has its content JSON serialized, so the incoming batch message contents\n\t * must be parsed first, and then the type and contents mentioned above are hidden in that JSON serialization.\n\t */\n\tpublic groupBatch(batch: OutboundBatch): OutboundSingletonBatch {\n\t\tassert(this.groupedBatchingEnabled(), 0xb79 /* grouping disabled! */);\n\t\tassert(batch.messages.length > 0, 0xb7a /* Unexpected attempt to group an empty batch */);\n\n\t\tif (batch.messages.length === 1) {\n\t\t\treturn batch as OutboundSingletonBatch;\n\t\t}\n\n\t\tif (batch.messages.length >= 1000) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"GroupLargeBatch\",\n\t\t\t\tlength: batch.messages.length,\n\t\t\t\treentrant: batch.hasReentrantOps,\n\t\t\t\treferenceSequenceNumber: batch.messages[0].referenceSequenceNumber,\n\t\t\t});\n\t\t}\n\t\t// We expect this will be on the first message, if present at all.\n\t\tlet groupedBatchId;\n\t\tfor (const message of batch.messages) {\n\t\t\tif (message.metadata) {\n\t\t\t\tconst { batch: _batch, batchId, ...rest } = message.metadata;\n\t\t\t\tif (batchId) {\n\t\t\t\t\tgroupedBatchId = batchId;\n\t\t\t\t}\n\t\t\t\tassert(Object.keys(rest).length === 0, 0x5dd /* cannot group ops with metadata */);\n\t\t\t}\n\t\t}\n\n\t\tconst serializedContent = JSON.stringify({\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: batch.messages.map<IGroupedMessage>((message) => ({\n\t\t\t\tcontents: message.contents === undefined ? undefined : JSON.parse(message.contents),\n\t\t\t\tmetadata: message.metadata,\n\t\t\t\tcompression: message.compression,\n\t\t\t})),\n\t\t});\n\n\t\tconst groupedBatch: OutboundSingletonBatch = {\n\t\t\t...batch,\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\tmetadata: { batchId: groupedBatchId },\n\t\t\t\t\treferenceSequenceNumber: batch.messages[0].referenceSequenceNumber,\n\t\t\t\t\tcontents: serializedContent,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t\treturn groupedBatch;\n\t}\n\n\tpublic ungroupOp(op: ISequencedDocumentMessage): ISequencedDocumentMessage[] {\n\t\tassert(isGroupContents(op.contents), 0x947 /* can only ungroup a grouped batch */);\n\t\tconst contents: IGroupedBatchMessageContents = op.contents;\n\n\t\tlet fakeCsn = 1;\n\t\treturn contents.contents.map((subMessage) => ({\n\t\t\t...op,\n\t\t\tclientSequenceNumber: fakeCsn++,\n\t\t\tcontents: subMessage.contents,\n\t\t\tmetadata: subMessage.metadata,\n\t\t\tcompression: subMessage.compression,\n\t\t}));\n\t}\n\n\tpublic groupedBatchingEnabled(): boolean {\n\t\treturn this.config.groupedBatchingEnabled;\n\t}\n}\n"]}
@@ -15,6 +15,8 @@ export declare function ensureContentsDeserialized(mutableMessage: ISequencedDoc
15
15
  /**
16
16
  * Before submitting an op to the Outbox, its contents must be serialized using this function.
17
17
  * @remarks - The deserialization on process happens via the function {@link ensureContentsDeserialized}.
18
+ *
19
+ * @param toSerialize - op message to serialize. Also supports an array of ops.
18
20
  */
19
- export declare function serializeOp(op: LocalContainerRuntimeMessage): string;
21
+ export declare function serializeOp(toSerialize: LocalContainerRuntimeMessage | LocalContainerRuntimeMessage[]): string;
20
22
  //# sourceMappingURL=opSerialization.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opSerialization.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/opSerialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAO7F,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,yBAAyB,GAAG,IAAI,CAM1F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,4BAA4B,GAAG,MAAM,CAYpE"}
1
+ {"version":3,"file":"opSerialization.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/opSerialization.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAO7F,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAEvE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,yBAAyB,GAAG,IAAI,CAM1F;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAC1B,WAAW,EAAE,4BAA4B,GAAG,4BAA4B,EAAE,GACxE,MAAM,CAYR"}
@@ -24,9 +24,11 @@ exports.ensureContentsDeserialized = ensureContentsDeserialized;
24
24
  /**
25
25
  * Before submitting an op to the Outbox, its contents must be serialized using this function.
26
26
  * @remarks - The deserialization on process happens via the function {@link ensureContentsDeserialized}.
27
+ *
28
+ * @param toSerialize - op message to serialize. Also supports an array of ops.
27
29
  */
28
- function serializeOp(op) {
29
- return JSON.stringify(op,
30
+ function serializeOp(toSerialize) {
31
+ return JSON.stringify(toSerialize,
30
32
  // replacer:
31
33
  (key, value) => {
32
34
  // If 'value' is an IFluidHandle return its encoded form.
@@ -1 +1 @@
1
- {"version":3,"file":"opSerialization.js","sourceRoot":"","sources":["../../src/opLifecycle/opSerialization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,qEAIgD;AAIhD;;;;;;GAMG;AACH,SAAgB,0BAA0B,CAAC,cAAyC;IACnF,yEAAyE;IACzE,qFAAqF;IACrF,IAAI,OAAO,cAAc,CAAC,QAAQ,KAAK,QAAQ,IAAI,cAAc,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;QACnF,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;AACF,CAAC;AAND,gEAMC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,EAAgC;IAC3D,OAAO,IAAI,CAAC,SAAS,CACpB,EAAE;IACF,YAAY;IACZ,CAAC,GAAG,EAAE,KAAc,EAAE,EAAE;QACvB,yDAAyD;QACzD,IAAI,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAA,uCAA4B,EAAC,IAAA,gCAAqB,EAAC,KAAK,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CACD,CAAC;AACH,CAAC;AAZD,kCAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tencodeHandleForSerialization,\n\tisFluidHandle,\n\ttoFluidHandleInternal,\n} from \"@fluidframework/runtime-utils/internal\";\n\nimport type { LocalContainerRuntimeMessage } from \"../messageTypes.js\";\n\n/**\n * Takes an incoming runtime message (outer type \"op\"), JSON.parses the message's contents in place,\n * if needed (old Loader does this for us).\n * Only to be used for runtime messages. The contents here would be the virtualized payload for a batch of ops.\n * @remarks - Serialization during submit happens via {@link serializeOp}\n * @param mutableMessage - op message received\n */\nexport function ensureContentsDeserialized(mutableMessage: ISequencedDocumentMessage): void {\n\t// This should become unconditional once Loader LTS reaches 2.4 or later.\n\t// There will be a long time of needing both cases, until LTS advances to that point.\n\tif (typeof mutableMessage.contents === \"string\" && mutableMessage.contents !== \"\") {\n\t\tmutableMessage.contents = JSON.parse(mutableMessage.contents);\n\t}\n}\n\n/**\n * Before submitting an op to the Outbox, its contents must be serialized using this function.\n * @remarks - The deserialization on process happens via the function {@link ensureContentsDeserialized}.\n */\nexport function serializeOp(op: LocalContainerRuntimeMessage): string {\n\treturn JSON.stringify(\n\t\top,\n\t\t// replacer:\n\t\t(key, value: unknown) => {\n\t\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\t\tif (isFluidHandle(value)) {\n\t\t\t\treturn encodeHandleForSerialization(toFluidHandleInternal(value));\n\t\t\t}\n\t\t\treturn value;\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"opSerialization.js","sourceRoot":"","sources":["../../src/opLifecycle/opSerialization.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,qEAIgD;AAIhD;;;;;;GAMG;AACH,SAAgB,0BAA0B,CAAC,cAAyC;IACnF,yEAAyE;IACzE,qFAAqF;IACrF,IAAI,OAAO,cAAc,CAAC,QAAQ,KAAK,QAAQ,IAAI,cAAc,CAAC,QAAQ,KAAK,EAAE,EAAE,CAAC;QACnF,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;AACF,CAAC;AAND,gEAMC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CAC1B,WAA0E;IAE1E,OAAO,IAAI,CAAC,SAAS,CACpB,WAAW;IACX,YAAY;IACZ,CAAC,GAAG,EAAE,KAAc,EAAE,EAAE;QACvB,yDAAyD;QACzD,IAAI,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAA,uCAA4B,EAAC,IAAA,gCAAqB,EAAC,KAAK,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CACD,CAAC;AACH,CAAC;AAdD,kCAcC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tencodeHandleForSerialization,\n\tisFluidHandle,\n\ttoFluidHandleInternal,\n} from \"@fluidframework/runtime-utils/internal\";\n\nimport type { LocalContainerRuntimeMessage } from \"../messageTypes.js\";\n\n/**\n * Takes an incoming runtime message (outer type \"op\"), JSON.parses the message's contents in place,\n * if needed (old Loader does this for us).\n * Only to be used for runtime messages. The contents here would be the virtualized payload for a batch of ops.\n * @remarks - Serialization during submit happens via {@link serializeOp}\n * @param mutableMessage - op message received\n */\nexport function ensureContentsDeserialized(mutableMessage: ISequencedDocumentMessage): void {\n\t// This should become unconditional once Loader LTS reaches 2.4 or later.\n\t// There will be a long time of needing both cases, until LTS advances to that point.\n\tif (typeof mutableMessage.contents === \"string\" && mutableMessage.contents !== \"\") {\n\t\tmutableMessage.contents = JSON.parse(mutableMessage.contents);\n\t}\n}\n\n/**\n * Before submitting an op to the Outbox, its contents must be serialized using this function.\n * @remarks - The deserialization on process happens via the function {@link ensureContentsDeserialized}.\n *\n * @param toSerialize - op message to serialize. Also supports an array of ops.\n */\nexport function serializeOp(\n\ttoSerialize: LocalContainerRuntimeMessage | LocalContainerRuntimeMessage[],\n): string {\n\treturn JSON.stringify(\n\t\ttoSerialize,\n\t\t// replacer:\n\t\t(key, value: unknown) => {\n\t\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\t\tif (isFluidHandle(value)) {\n\t\t\t\treturn encodeHandleForSerialization(toFluidHandleInternal(value));\n\t\t\t}\n\t\t\treturn value;\n\t\t},\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"opSplitter.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/opSplitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6CAA6C,CAAC;AAWxF,OAAO,EACN,UAAU,EACV,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,MAAM,kBAAkB,CAAC;AAE1B,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAE5E;AAWD;;GAEG;AACH,qBAAa,UAAU;IAOrB,OAAO,CAAC,QAAQ,CAAC,aAAa;aAGd,gBAAgB,EAAE,MAAM;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB;IATrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;gBAG5C,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,EACX,aAAa,EAC3B,CAAC,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,uBAAuB,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GACtE,SAAS,EACI,gBAAgB,EAAE,MAAM,EACvB,mBAAmB,EAAE,MAAM,EAC5C,MAAM,EAAE,oBAAoB;IAM7B,IA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AAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsB;gBAG5C,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,EACX,aAAa,EAC3B,CAAC,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,uBAAuB,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,GACtE,SAAS,EACI,gBAAgB,EAAE,MAAM,EACvB,mBAAmB,EAAE,MAAM,EAC5C,MAAM,EAAE,oBAAoB;IAM7B,IAAW,sBAAsB,IAAI,OAAO,CAI3C;IAED,IAAW,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAEjD;IAEM,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAMjD,OAAO,CAAC,QAAQ;IA0BhB;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACI,0BAA0B,CAAC,KAAK,EAAE,sBAAsB,GAAG,sBAAsB;IAoEjF,YAAY,CAAC,OAAO,EAAE,yBAAyB,GAAG,kBAAkB;CAuC3E;AAED,KAAK,kBAAkB,GACpB;IACA,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC;CAC5B,GACD;IACA,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,yBAAyB,CAAC;CAC3C,CAAC;AAkBL;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,OACf,oBAAoB,oBACN,MAAM,YACf,OAAO,KACd,UAAU,EAkDZ,CAAC"}
@@ -8,7 +8,7 @@ exports.splitOp = exports.OpSplitter = exports.isChunkedMessage = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
10
10
  const messageTypes_js_1 = require("../messageTypes.js");
11
- const batchManager_js_1 = require("./batchManager.js");
11
+ const outbox_js_1 = require("./outbox.js");
12
12
  function isChunkedMessage(message) {
13
13
  return isChunkedContents(message.contents);
14
14
  }
@@ -93,7 +93,7 @@ class OpSplitter {
93
93
  // (but we keep it here to support a legacy test case, wherein it contains empty placeholder messages)
94
94
  const [firstMessage, ...restOfMessages] = batch.messages;
95
95
  (0, internal_1.assert)((firstMessage.contents?.length ?? 0) >= this.chunkSizeInBytes, 0x518 /* First message in the batch needs to be chunkable */);
96
- const socketSize = (0, batchManager_js_1.estimateSocketSize)(batch);
96
+ const socketSize = (0, outbox_js_1.estimateSocketSize)(batch);
97
97
  const chunks = (0, exports.splitOp)(firstMessage, this.chunkSizeInBytes,
98
98
  // If we estimate that the socket batch size will exceed the batch limit
99
99
  // we will inject an empty op to minimize the risk of the payload failing due to
@@ -1 +1 @@
1
- {"version":3,"file":"opSplitter.js","sourceRoot":"","sources":["../../src/opLifecycle/opSplitter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAE7D,uEAKkD;AAElD,wDAA4F;AAE5F,uDAAuD;AAOvD,SAAgB,gBAAgB,CAAC,OAAkC;IAClE,OAAO,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC;AAOD,SAAS,iBAAiB,CAAC,QAAiB;IAC3C,OAAQ,QAAsC,EAAE,IAAI,KAAK,sCAAoB,CAAC,SAAS,CAAC;AACzF,CAAC;AAED;;GAEG;AACH,MAAa,UAAU;IAKtB,YACC,MAA4B,EACX,aAEL,EACI,gBAAwB,EACvB,mBAA2B,EAC5C,MAA4B;QALX,kBAAa,GAAb,aAAa,CAElB;QACI,qBAAgB,GAAhB,gBAAgB,CAAQ;QACvB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAG5C,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAmB,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,IAAW,sBAAsB;QACh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AAK,CAAC,kCAAkC,CACxC,CAAC;IACH,CAAC;IAED,IAAA,iBAAM,EACL,MAAM,IAAI,aAAa,EACvB,KAAK,CAAC,wDAAwD,CAC9D,CAAC;IACF,IAAA,iBAAM,EAAC,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAtDW,QAAA,OAAO,WAsDlB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IBatchMessage } from \"@fluidframework/container-definitions/internal\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tDataCorruptionError,\n\tcreateChildLogger,\n\textractSafePropertiesFromMessage,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { ContainerMessageType, ContainerRuntimeChunkedOpMessage } from \"../messageTypes.js\";\n\nimport { estimateSocketSize } from \"./batchManager.js\";\nimport {\n\tIChunkedOp,\n\ttype OutboundBatchMessage,\n\ttype OutboundSingletonBatch,\n} from \"./definitions.js\";\n\nexport function isChunkedMessage(message: ISequencedDocumentMessage): boolean {\n\treturn isChunkedContents(message.contents);\n}\n\ninterface IChunkedContents {\n\treadonly type: typeof ContainerMessageType.ChunkedOp;\n\treadonly contents: IChunkedOp;\n}\n\nfunction isChunkedContents(contents: unknown): contents is IChunkedContents {\n\treturn (contents as Partial<IChunkedContents>)?.type === ContainerMessageType.ChunkedOp;\n}\n\n/**\n * Responsible for creating and reconstructing chunked messages.\n */\nexport class OpSplitter {\n\t// Local copy of incomplete received chunks.\n\tprivate readonly chunkMap: Map<string, string[]>;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tchunks: [string, string[]][],\n\t\tprivate readonly submitBatchFn:\n\t\t\t| ((batch: IBatchMessage[], referenceSequenceNumber?: number) => number)\n\t\t\t| undefined,\n\t\tpublic readonly chunkSizeInBytes: number,\n\t\tprivate readonly maxBatchSizeInBytes: number,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.chunkMap = new Map<string, string[]>(chunks);\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpSplitter\" });\n\t}\n\n\tpublic get isBatchChunkingEnabled(): boolean {\n\t\treturn (\n\t\t\tthis.chunkSizeInBytes < Number.POSITIVE_INFINITY && this.submitBatchFn !== undefined\n\t\t);\n\t}\n\n\tpublic get chunks(): ReadonlyMap<string, string[]> {\n\t\treturn this.chunkMap;\n\t}\n\n\tpublic clearPartialChunks(clientId: string): void {\n\t\tif (this.chunkMap.has(clientId)) {\n\t\t\tthis.chunkMap.delete(clientId);\n\t\t}\n\t}\n\n\tprivate addChunk(\n\t\tclientId: string,\n\t\tchunkedContent: IChunkedOp,\n\t\toriginalMessage: ISequencedDocumentMessage,\n\t): void {\n\t\tlet map = this.chunkMap.get(clientId);\n\t\tif (map === undefined) {\n\t\t\tmap = [];\n\t\t\tthis.chunkMap.set(clientId, map);\n\t\t}\n\n\t\tif (chunkedContent.chunkId !== map.length + 1) {\n\t\t\t// We are expecting the chunks to be processed sequentially, in the same order as they are sent.\n\t\t\t// Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)\n\t\t\t// holding the existing chunks for that particular clientId.\n\t\t\tthrow new DataCorruptionError(\"Chunk Id mismatch\", {\n\t\t\t\t...extractSafePropertiesFromMessage(originalMessage),\n\t\t\t\tchunkMapLength: map.length,\n\t\t\t\tchunkId: chunkedContent.chunkId,\n\t\t\t\ttotalChunks: chunkedContent.totalChunks,\n\t\t\t});\n\t\t}\n\n\t\tmap.push(chunkedContent.contents);\n\t}\n\n\t/**\n\t * Takes a singleton batch, and splits the interior message into chunks, sending the chunks separately and\n\t * returning a new singleton batch containing the last chunk.\n\t *\n\t * A compressed batch is formed by one large op at the first position.\n\t *\n\t * If the op is too large, it can be chunked (split into smaller op) which can be sent individually over the wire\n\t * and accumulate at ingestion, until the last op in the chunk is processed, when the original op is unrolled.\n\t *\n\t * This method will send the first N - 1 chunks separately and use the last chunk as the first message in the result batch.\n\t * This will ensure that the batch semantics of the original (non-compressed) batch are preserved, as the original chunked op\n\t * will be unrolled by the runtime when the first message in the batch is processed (as it is the last chunk).\n\t *\n\t * To illustrate the current functionality, if the input is `[largeOp]`, `largeOp` will be split into `[chunk1, chunk2, chunk3, chunk4]`.\n\t * `chunk1`, `chunk2` and `chunk3` will be sent individually and `[chunk4]` will be returned.\n\t *\n\t * @remarks - A side effect here is that 1 or more chunks are queued immediately for sending in next JS turn.\n\t *\n\t * @privateRemarks\n\t * This maintains support for splitting a compressed batch with multiple messages (empty placeholders after the first),\n\t * but this is only used for Unit Tests so the typing has been updated to preclude that.\n\t * That code should be moved out of this function into a test helper.\n\t *\n\t * @param batch - the compressed batch which needs to be split into chunks before being sent over the wire\n\t * @returns A batch with the last chunk in place of the original complete compressed content\n\t */\n\tpublic splitSingletonBatchMessage(batch: OutboundSingletonBatch): OutboundSingletonBatch {\n\t\tassert(this.isBatchChunkingEnabled, 0x513 /* Chunking needs to be enabled */);\n\t\tassert(\n\t\t\tbatch.contentSizeInBytes > 0 && batch.messages.length > 0,\n\t\t\t0x514 /* Batch needs to be non-empty */,\n\t\t);\n\t\tassert(\n\t\t\tbatch.referenceSequenceNumber !== undefined,\n\t\t\t0x58a /* Batch must have a reference sequence number if non-empty */,\n\t\t);\n\t\tassert(this.chunkSizeInBytes !== 0, 0x515 /* Chunk size needs to be non-zero */);\n\t\tassert(\n\t\t\tthis.chunkSizeInBytes < this.maxBatchSizeInBytes,\n\t\t\t0x516 /* Chunk size needs to be smaller than the max batch size */,\n\t\t);\n\n\t\t// first message is the large compressed op to split, and we expect restOfMessages to be empty\n\t\t// (but we keep it here to support a legacy test case, wherein it contains empty placeholder messages)\n\t\tconst [firstMessage, ...restOfMessages] = batch.messages;\n\t\tassert(\n\t\t\t(firstMessage.contents?.length ?? 0) >= this.chunkSizeInBytes,\n\t\t\t0x518 /* First message in the batch needs to be chunkable */,\n\t\t);\n\n\t\tconst socketSize = estimateSocketSize(batch);\n\t\tconst chunks = splitOp(\n\t\t\tfirstMessage,\n\t\t\tthis.chunkSizeInBytes,\n\t\t\t// If we estimate that the socket batch size will exceed the batch limit\n\t\t\t// we will inject an empty op to minimize the risk of the payload failing due to\n\t\t\t// the overhead from the trailing empty ops in the batch.\n\t\t\tsocketSize >= this.maxBatchSizeInBytes,\n\t\t);\n\n\t\tassert(this.submitBatchFn !== undefined, 0x519 /* We don't support old loaders */);\n\t\t// Send the first N-1 chunks immediately\n\t\tfor (const chunk of chunks.slice(0, -1)) {\n\t\t\tthis.submitBatchFn(\n\t\t\t\t[chunkToBatchMessage(chunk, batch.referenceSequenceNumber)],\n\t\t\t\tbatch.referenceSequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\t// The last chunk will be part of the new batch and needs to\n\t\t// preserve the batch metadata of the original batch\n\t\tconst lastChunk = chunkToBatchMessage(\n\t\t\tchunks[chunks.length - 1],\n\t\t\tbatch.referenceSequenceNumber,\n\t\t\t{ batch: firstMessage.metadata?.batch },\n\t\t);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\t// Used to be \"Chunked compressed batch\"\n\t\t\teventName: \"CompressedChunkedBatch\",\n\t\t\tlength: batch.messages.length,\n\t\t\tsizeInBytes: batch.contentSizeInBytes,\n\t\t\tchunks: chunks.length,\n\t\t\tchunkSizeInBytes: this.chunkSizeInBytes,\n\t\t\tsocketSize,\n\t\t});\n\n\t\treturn {\n\t\t\tmessages: [lastChunk, ...restOfMessages],\n\t\t\tcontentSizeInBytes: lastChunk.contents?.length ?? 0,\n\t\t\treferenceSequenceNumber: batch.referenceSequenceNumber,\n\t\t};\n\t}\n\n\tpublic processChunk(message: ISequencedDocumentMessage): ProcessChunkResult {\n\t\tassert(isChunkedContents(message.contents), 0x948 /* message not of type ChunkedOp */);\n\t\tconst contents: IChunkedContents = message.contents;\n\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\n\t\tconst clientId = message.clientId as string;\n\t\tconst chunkedContent = contents.contents;\n\t\tthis.addChunk(clientId, chunkedContent, message);\n\n\t\tif (chunkedContent.chunkId < chunkedContent.totalChunks) {\n\t\t\t// We are processing the op in chunks but haven't reached\n\t\t\t// the last chunk yet in order to reconstruct the original op\n\t\t\treturn {\n\t\t\t\tisFinalChunk: false,\n\t\t\t};\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst serializedContent = this.chunkMap.get(clientId)!.join(\"\");\n\t\tthis.clearPartialChunks(clientId);\n\n\t\t// The final/complete message will contain the data from all the chunks.\n\t\t// It will have the sequenceNumber of the last chunk\n\t\tconst completeMessage = { ...message };\n\t\tcompleteMessage.contents =\n\t\t\tserializedContent === \"\" ? undefined : JSON.parse(serializedContent);\n\t\t// back-compat with 1.x builds\n\t\t// This is only required / present for non-compressed, chunked ops\n\t\t// For compressed ops, we have op grouping enabled, and type of each op is preserved within compressed content.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment\n\t\tcompleteMessage.type = (chunkedContent as any).originalType;\n\t\tcompleteMessage.metadata = chunkedContent.originalMetadata;\n\t\tcompleteMessage.compression = chunkedContent.originalCompression;\n\t\treturn {\n\t\t\tmessage: completeMessage,\n\t\t\tisFinalChunk: true,\n\t\t};\n\t}\n}\n\ntype ProcessChunkResult =\n\t| {\n\t\t\treadonly isFinalChunk: false;\n\t }\n\t| {\n\t\t\treadonly isFinalChunk: true;\n\t\t\treadonly message: ISequencedDocumentMessage;\n\t };\n\nconst chunkToBatchMessage = (\n\tchunk: IChunkedOp,\n\treferenceSequenceNumber: number,\n\tmetadata: Record<string, unknown> | undefined = undefined,\n): OutboundBatchMessage => {\n\tconst payload: ContainerRuntimeChunkedOpMessage = {\n\t\ttype: ContainerMessageType.ChunkedOp,\n\t\tcontents: chunk,\n\t};\n\treturn {\n\t\tcontents: JSON.stringify(payload),\n\t\tmetadata,\n\t\treferenceSequenceNumber,\n\t};\n};\n\n/**\n * Splits an op into smaller ops (chunks), based on the size of the op and the `chunkSizeInBytes` parameter.\n *\n * The last op of the result will be bundled with empty ops in the same batch. There is a risk of the batch payload\n * exceeding the 1MB limit due to the overhead from the empty ops. If the last op is large, the risk is even higher.\n * To minimize the odds, an extra empty op can be added to the result using the `extraOp` parameter.\n *\n * @param op - the op to be split\n * @param chunkSizeInBytes - how large should the chunks be\n * @param extraOp - should an extra empty op be added to the result\n * @returns an array of chunked ops\n */\nexport const splitOp = (\n\top: OutboundBatchMessage,\n\tchunkSizeInBytes: number,\n\textraOp: boolean = false,\n): IChunkedOp[] => {\n\tconst chunks: IChunkedOp[] = [];\n\tassert(\n\t\top.contents !== undefined && op.contents !== null,\n\t\t0x51a /* We should have something to chunk */,\n\t);\n\n\tconst contentLength = op.contents.length;\n\tconst chunkCount =\n\t\tMath.floor((contentLength - 1) / chunkSizeInBytes) + 1 + (extraOp ? 1 : 0);\n\tlet offset = 0;\n\tfor (let chunkId = 1; chunkId <= chunkCount; chunkId++) {\n\t\tconst chunk: IChunkedOp = {\n\t\t\tchunkId,\n\t\t\tcontents: op.contents.slice(offset, offset + chunkSizeInBytes),\n\t\t\ttotalChunks: chunkCount,\n\t\t};\n\n\t\tif (chunkId === chunkCount) {\n\t\t\t// We don't need to port these to all the chunks,\n\t\t\t// as we rebuild the original op when we process the\n\t\t\t// last chunk, therefore it is the only one that needs it.\n\t\t\tchunk.originalMetadata = op.metadata;\n\t\t\tchunk.originalCompression = op.compression;\n\n\t\t\t// back-compat with 1.x builds\n\t\t\t// 2.x builds only do chunking for compressed ops.\n\t\t\t// originalType is no longer used in such cases, as each op preserves its type within compressed payload.\n\t\t\t// But, if 1.x builds see this op, and there is no type on the message, then it will ignore this message silently.\n\t\t\t// This is really bad, as we will crash on later ops and it's very hard to debug these cases.\n\t\t\t// If we put some known type here, then we will crash on it (as 1.x does not understand compression, and thus will not\n\t\t\t// find info on the op like address of the channel to deliver the op)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t(chunk as any).originalType = \"component\";\n\t\t}\n\n\t\tchunks.push(chunk);\n\t\toffset += chunkSizeInBytes;\n\t\tassert(\n\t\t\tchunkId >= chunkCount - 1 || offset <= contentLength,\n\t\t\t0x58b /* Content offset within bounds */,\n\t\t);\n\t}\n\n\tassert(\n\t\toffset >= contentLength,\n\t\t0x58c /* Content offset equal or larger than content length */,\n\t);\n\tassert(chunks.length === chunkCount, 0x5a5 /* Expected number of chunks */);\n\treturn chunks;\n};\n"]}
1
+ {"version":3,"file":"opSplitter.js","sourceRoot":"","sources":["../../src/opLifecycle/opSplitter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,kEAA6D;AAE7D,uEAKkD;AAElD,wDAA4F;AAO5F,2CAAiD;AAEjD,SAAgB,gBAAgB,CAAC,OAAkC;IAClE,OAAO,iBAAiB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAFD,4CAEC;AAOD,SAAS,iBAAiB,CAAC,QAAiB;IAC3C,OAAQ,QAAsC,EAAE,IAAI,KAAK,sCAAoB,CAAC,SAAS,CAAC;AACzF,CAAC;AAED;;GAEG;AACH,MAAa,UAAU;IAKtB,YACC,MAA4B,EACX,aAEL,EACI,gBAAwB,EACvB,mBAA2B,EAC5C,MAA4B;QALX,kBAAa,GAAb,aAAa,CAElB;QACI,qBAAgB,GAAhB,gBAAgB,CAAQ;QACvB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAG5C,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAmB,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,GAAG,IAAA,4BAAiB,EAAC,EAAE,MA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,IAAA,iBAAM,EACL,OAAO,IAAI,UAAU,GAAG,CAAC,IAAI,MAAM,IAAI,aAAa,EACpD,KAAK,CAAC,kCAAkC,CACxC,CAAC;IACH,CAAC;IAED,IAAA,iBAAM,EACL,MAAM,IAAI,aAAa,EACvB,KAAK,CAAC,wDAAwD,CAC9D,CAAC;IACF,IAAA,iBAAM,EAAC,MAAM,CAAC,MAAM,KAAK,UAAU,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;IAC5E,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAtDW,QAAA,OAAO,WAsDlB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IBatchMessage } from \"@fluidframework/container-definitions/internal\";\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport {\n\tDataCorruptionError,\n\tcreateChildLogger,\n\textractSafePropertiesFromMessage,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { ContainerMessageType, ContainerRuntimeChunkedOpMessage } from \"../messageTypes.js\";\n\nimport {\n\tIChunkedOp,\n\ttype OutboundBatchMessage,\n\ttype OutboundSingletonBatch,\n} from \"./definitions.js\";\nimport { estimateSocketSize } from \"./outbox.js\";\n\nexport function isChunkedMessage(message: ISequencedDocumentMessage): boolean {\n\treturn isChunkedContents(message.contents);\n}\n\ninterface IChunkedContents {\n\treadonly type: typeof ContainerMessageType.ChunkedOp;\n\treadonly contents: IChunkedOp;\n}\n\nfunction isChunkedContents(contents: unknown): contents is IChunkedContents {\n\treturn (contents as Partial<IChunkedContents>)?.type === ContainerMessageType.ChunkedOp;\n}\n\n/**\n * Responsible for creating and reconstructing chunked messages.\n */\nexport class OpSplitter {\n\t// Local copy of incomplete received chunks.\n\tprivate readonly chunkMap: Map<string, string[]>;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tconstructor(\n\t\tchunks: [string, string[]][],\n\t\tprivate readonly submitBatchFn:\n\t\t\t| ((batch: IBatchMessage[], referenceSequenceNumber?: number) => number)\n\t\t\t| undefined,\n\t\tpublic readonly chunkSizeInBytes: number,\n\t\tprivate readonly maxBatchSizeInBytes: number,\n\t\tlogger: ITelemetryBaseLogger,\n\t) {\n\t\tthis.chunkMap = new Map<string, string[]>(chunks);\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpSplitter\" });\n\t}\n\n\tpublic get isBatchChunkingEnabled(): boolean {\n\t\treturn (\n\t\t\tthis.chunkSizeInBytes < Number.POSITIVE_INFINITY && this.submitBatchFn !== undefined\n\t\t);\n\t}\n\n\tpublic get chunks(): ReadonlyMap<string, string[]> {\n\t\treturn this.chunkMap;\n\t}\n\n\tpublic clearPartialChunks(clientId: string): void {\n\t\tif (this.chunkMap.has(clientId)) {\n\t\t\tthis.chunkMap.delete(clientId);\n\t\t}\n\t}\n\n\tprivate addChunk(\n\t\tclientId: string,\n\t\tchunkedContent: IChunkedOp,\n\t\toriginalMessage: ISequencedDocumentMessage,\n\t): void {\n\t\tlet map = this.chunkMap.get(clientId);\n\t\tif (map === undefined) {\n\t\t\tmap = [];\n\t\t\tthis.chunkMap.set(clientId, map);\n\t\t}\n\n\t\tif (chunkedContent.chunkId !== map.length + 1) {\n\t\t\t// We are expecting the chunks to be processed sequentially, in the same order as they are sent.\n\t\t\t// Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)\n\t\t\t// holding the existing chunks for that particular clientId.\n\t\t\tthrow new DataCorruptionError(\"Chunk Id mismatch\", {\n\t\t\t\t...extractSafePropertiesFromMessage(originalMessage),\n\t\t\t\tchunkMapLength: map.length,\n\t\t\t\tchunkId: chunkedContent.chunkId,\n\t\t\t\ttotalChunks: chunkedContent.totalChunks,\n\t\t\t});\n\t\t}\n\n\t\tmap.push(chunkedContent.contents);\n\t}\n\n\t/**\n\t * Takes a singleton batch, and splits the interior message into chunks, sending the chunks separately and\n\t * returning a new singleton batch containing the last chunk.\n\t *\n\t * A compressed batch is formed by one large op at the first position.\n\t *\n\t * If the op is too large, it can be chunked (split into smaller op) which can be sent individually over the wire\n\t * and accumulate at ingestion, until the last op in the chunk is processed, when the original op is unrolled.\n\t *\n\t * This method will send the first N - 1 chunks separately and use the last chunk as the first message in the result batch.\n\t * This will ensure that the batch semantics of the original (non-compressed) batch are preserved, as the original chunked op\n\t * will be unrolled by the runtime when the first message in the batch is processed (as it is the last chunk).\n\t *\n\t * To illustrate the current functionality, if the input is `[largeOp]`, `largeOp` will be split into `[chunk1, chunk2, chunk3, chunk4]`.\n\t * `chunk1`, `chunk2` and `chunk3` will be sent individually and `[chunk4]` will be returned.\n\t *\n\t * @remarks - A side effect here is that 1 or more chunks are queued immediately for sending in next JS turn.\n\t *\n\t * @privateRemarks\n\t * This maintains support for splitting a compressed batch with multiple messages (empty placeholders after the first),\n\t * but this is only used for Unit Tests so the typing has been updated to preclude that.\n\t * That code should be moved out of this function into a test helper.\n\t *\n\t * @param batch - the compressed batch which needs to be split into chunks before being sent over the wire\n\t * @returns A batch with the last chunk in place of the original complete compressed content\n\t */\n\tpublic splitSingletonBatchMessage(batch: OutboundSingletonBatch): OutboundSingletonBatch {\n\t\tassert(this.isBatchChunkingEnabled, 0x513 /* Chunking needs to be enabled */);\n\t\tassert(\n\t\t\tbatch.contentSizeInBytes > 0 && batch.messages.length > 0,\n\t\t\t0x514 /* Batch needs to be non-empty */,\n\t\t);\n\t\tassert(\n\t\t\tbatch.referenceSequenceNumber !== undefined,\n\t\t\t0x58a /* Batch must have a reference sequence number if non-empty */,\n\t\t);\n\t\tassert(this.chunkSizeInBytes !== 0, 0x515 /* Chunk size needs to be non-zero */);\n\t\tassert(\n\t\t\tthis.chunkSizeInBytes < this.maxBatchSizeInBytes,\n\t\t\t0x516 /* Chunk size needs to be smaller than the max batch size */,\n\t\t);\n\n\t\t// first message is the large compressed op to split, and we expect restOfMessages to be empty\n\t\t// (but we keep it here to support a legacy test case, wherein it contains empty placeholder messages)\n\t\tconst [firstMessage, ...restOfMessages] = batch.messages;\n\t\tassert(\n\t\t\t(firstMessage.contents?.length ?? 0) >= this.chunkSizeInBytes,\n\t\t\t0x518 /* First message in the batch needs to be chunkable */,\n\t\t);\n\n\t\tconst socketSize = estimateSocketSize(batch);\n\t\tconst chunks = splitOp(\n\t\t\tfirstMessage,\n\t\t\tthis.chunkSizeInBytes,\n\t\t\t// If we estimate that the socket batch size will exceed the batch limit\n\t\t\t// we will inject an empty op to minimize the risk of the payload failing due to\n\t\t\t// the overhead from the trailing empty ops in the batch.\n\t\t\tsocketSize >= this.maxBatchSizeInBytes,\n\t\t);\n\n\t\tassert(this.submitBatchFn !== undefined, 0x519 /* We don't support old loaders */);\n\t\t// Send the first N-1 chunks immediately\n\t\tfor (const chunk of chunks.slice(0, -1)) {\n\t\t\tthis.submitBatchFn(\n\t\t\t\t[chunkToBatchMessage(chunk, batch.referenceSequenceNumber)],\n\t\t\t\tbatch.referenceSequenceNumber,\n\t\t\t);\n\t\t}\n\n\t\t// The last chunk will be part of the new batch and needs to\n\t\t// preserve the batch metadata of the original batch\n\t\tconst lastChunk = chunkToBatchMessage(\n\t\t\tchunks[chunks.length - 1],\n\t\t\tbatch.referenceSequenceNumber,\n\t\t\t{ batch: firstMessage.metadata?.batch },\n\t\t);\n\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\t// Used to be \"Chunked compressed batch\"\n\t\t\teventName: \"CompressedChunkedBatch\",\n\t\t\tlength: batch.messages.length,\n\t\t\tsizeInBytes: batch.contentSizeInBytes,\n\t\t\tchunks: chunks.length,\n\t\t\tchunkSizeInBytes: this.chunkSizeInBytes,\n\t\t\tsocketSize,\n\t\t});\n\n\t\treturn {\n\t\t\tmessages: [lastChunk, ...restOfMessages],\n\t\t\tcontentSizeInBytes: lastChunk.contents?.length ?? 0,\n\t\t\treferenceSequenceNumber: batch.referenceSequenceNumber,\n\t\t};\n\t}\n\n\tpublic processChunk(message: ISequencedDocumentMessage): ProcessChunkResult {\n\t\tassert(isChunkedContents(message.contents), 0x948 /* message not of type ChunkedOp */);\n\t\tconst contents: IChunkedContents = message.contents;\n\n\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\n\t\tconst clientId = message.clientId as string;\n\t\tconst chunkedContent = contents.contents;\n\t\tthis.addChunk(clientId, chunkedContent, message);\n\n\t\tif (chunkedContent.chunkId < chunkedContent.totalChunks) {\n\t\t\t// We are processing the op in chunks but haven't reached\n\t\t\t// the last chunk yet in order to reconstruct the original op\n\t\t\treturn {\n\t\t\t\tisFinalChunk: false,\n\t\t\t};\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst serializedContent = this.chunkMap.get(clientId)!.join(\"\");\n\t\tthis.clearPartialChunks(clientId);\n\n\t\t// The final/complete message will contain the data from all the chunks.\n\t\t// It will have the sequenceNumber of the last chunk\n\t\tconst completeMessage = { ...message };\n\t\tcompleteMessage.contents =\n\t\t\tserializedContent === \"\" ? undefined : JSON.parse(serializedContent);\n\t\t// back-compat with 1.x builds\n\t\t// This is only required / present for non-compressed, chunked ops\n\t\t// For compressed ops, we have op grouping enabled, and type of each op is preserved within compressed content.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment\n\t\tcompleteMessage.type = (chunkedContent as any).originalType;\n\t\tcompleteMessage.metadata = chunkedContent.originalMetadata;\n\t\tcompleteMessage.compression = chunkedContent.originalCompression;\n\t\treturn {\n\t\t\tmessage: completeMessage,\n\t\t\tisFinalChunk: true,\n\t\t};\n\t}\n}\n\ntype ProcessChunkResult =\n\t| {\n\t\t\treadonly isFinalChunk: false;\n\t }\n\t| {\n\t\t\treadonly isFinalChunk: true;\n\t\t\treadonly message: ISequencedDocumentMessage;\n\t };\n\nconst chunkToBatchMessage = (\n\tchunk: IChunkedOp,\n\treferenceSequenceNumber: number,\n\tmetadata: Record<string, unknown> | undefined = undefined,\n): OutboundBatchMessage => {\n\tconst payload: ContainerRuntimeChunkedOpMessage = {\n\t\ttype: ContainerMessageType.ChunkedOp,\n\t\tcontents: chunk,\n\t};\n\treturn {\n\t\tcontents: JSON.stringify(payload),\n\t\tmetadata,\n\t\treferenceSequenceNumber,\n\t};\n};\n\n/**\n * Splits an op into smaller ops (chunks), based on the size of the op and the `chunkSizeInBytes` parameter.\n *\n * The last op of the result will be bundled with empty ops in the same batch. There is a risk of the batch payload\n * exceeding the 1MB limit due to the overhead from the empty ops. If the last op is large, the risk is even higher.\n * To minimize the odds, an extra empty op can be added to the result using the `extraOp` parameter.\n *\n * @param op - the op to be split\n * @param chunkSizeInBytes - how large should the chunks be\n * @param extraOp - should an extra empty op be added to the result\n * @returns an array of chunked ops\n */\nexport const splitOp = (\n\top: OutboundBatchMessage,\n\tchunkSizeInBytes: number,\n\textraOp: boolean = false,\n): IChunkedOp[] => {\n\tconst chunks: IChunkedOp[] = [];\n\tassert(\n\t\top.contents !== undefined && op.contents !== null,\n\t\t0x51a /* We should have something to chunk */,\n\t);\n\n\tconst contentLength = op.contents.length;\n\tconst chunkCount =\n\t\tMath.floor((contentLength - 1) / chunkSizeInBytes) + 1 + (extraOp ? 1 : 0);\n\tlet offset = 0;\n\tfor (let chunkId = 1; chunkId <= chunkCount; chunkId++) {\n\t\tconst chunk: IChunkedOp = {\n\t\t\tchunkId,\n\t\t\tcontents: op.contents.slice(offset, offset + chunkSizeInBytes),\n\t\t\ttotalChunks: chunkCount,\n\t\t};\n\n\t\tif (chunkId === chunkCount) {\n\t\t\t// We don't need to port these to all the chunks,\n\t\t\t// as we rebuild the original op when we process the\n\t\t\t// last chunk, therefore it is the only one that needs it.\n\t\t\tchunk.originalMetadata = op.metadata;\n\t\t\tchunk.originalCompression = op.compression;\n\n\t\t\t// back-compat with 1.x builds\n\t\t\t// 2.x builds only do chunking for compressed ops.\n\t\t\t// originalType is no longer used in such cases, as each op preserves its type within compressed payload.\n\t\t\t// But, if 1.x builds see this op, and there is no type on the message, then it will ignore this message silently.\n\t\t\t// This is really bad, as we will crash on later ops and it's very hard to debug these cases.\n\t\t\t// If we put some known type here, then we will crash on it (as 1.x does not understand compression, and thus will not\n\t\t\t// find info on the op like address of the channel to deliver the op)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t(chunk as any).originalType = \"component\";\n\t\t}\n\n\t\tchunks.push(chunk);\n\t\toffset += chunkSizeInBytes;\n\t\tassert(\n\t\t\tchunkId >= chunkCount - 1 || offset <= contentLength,\n\t\t\t0x58b /* Content offset within bounds */,\n\t\t);\n\t}\n\n\tassert(\n\t\toffset >= contentLength,\n\t\t0x58c /* Content offset equal or larger than content length */,\n\t);\n\tassert(chunks.length === chunkCount, 0x5a5 /* Expected number of chunks */);\n\treturn chunks;\n};\n"]}
@@ -4,10 +4,10 @@
4
4
  */
5
5
  import { IBatchMessage } from "@fluidframework/container-definitions/internal";
6
6
  import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7
- import { ICompressionRuntimeOptions } from "../containerRuntime.js";
7
+ import { ICompressionRuntimeOptions } from "../compressionDefinitions.js";
8
8
  import { PendingMessageResubmitData, PendingStateManager } from "../pendingStateManager.js";
9
9
  import { BatchSequenceNumbers, type BatchId } from "./batchManager.js";
10
- import { LocalBatchMessage, IBatchCheckpoint, type OutboundBatch } from "./definitions.js";
10
+ import { LocalBatchMessage, IBatchCheckpoint, type LocalBatch, type OutboundBatch } from "./definitions.js";
11
11
  import { OpCompressor } from "./opCompressor.js";
12
12
  import { OpGroupingManager } from "./opGroupingManager.js";
13
13
  import { OpSplitter } from "./opSplitter.js";
@@ -50,6 +50,25 @@ export interface IOutboxParameters {
50
50
  * @returns the result of the action provided
51
51
  */
52
52
  export declare function getLongStack<T>(action: () => T, length?: number): T;
53
+ /**
54
+ * Convert from local batch to outbound batch, including computing contentSizeInBytes.
55
+ */
56
+ export declare function localBatchToOutboundBatch({ staged: _staged, // Peel this off the incoming batch, it's irrelevant (see Note below)
57
+ ...localBatch }: LocalBatch): OutboundBatch;
58
+ /**
59
+ * Estimates the real size in bytes on the socket for a given batch. It assumes that
60
+ * the envelope size (and the size of an empty op) is 200 bytes, taking into account
61
+ * extra overhead from stringification.
62
+ *
63
+ * @remarks
64
+ * Also content will be stringified, and that adds a lot of overhead due to a lot of escape characters.
65
+ * Not taking it into account, as compression work should help there - compressed payload will be
66
+ * initially stored as base64, and that requires only 2 extra escape characters.
67
+ *
68
+ * @param batch - the batch to inspect
69
+ * @returns An estimate of the payload size in bytes which will be produced when the batch is sent over the wire
70
+ */
71
+ export declare const estimateSocketSize: (batch: OutboundBatch) => number;
53
72
  /**
54
73
  * The Outbox collects messages submitted by the ContainerRuntime into a batch,
55
74
  * and then flushes the batch when requested.
@@ -102,8 +121,10 @@ export declare class Outbox {
102
121
  * @throws If called from a reentrant context, or if the batch being flushed is too large.
103
122
  * @param resubmittingBatchId - If defined, indicates this is a resubmission of a batch
104
123
  * with the given Batch ID, which must be preserved
124
+ * @param resubmittingStagedBatch - If defined, indicates this is a resubmission of a batch that is staged,
125
+ * meaning it should not be sent to the ordering service yet.
105
126
  */
106
- flush(resubmittingBatchId?: BatchId): void;
127
+ flush(resubmittingBatchId?: BatchId, resubmittingStagedBatch?: boolean): void;
107
128
  private flushAll;
108
129
  private flushEmptyBatch;
109
130
  private flushInternal;
@@ -136,6 +157,7 @@ export declare class Outbox {
136
157
  * @returns the clientSequenceNumber of the start of the batch, or undefined if nothing was sent
137
158
  */
138
159
  private sendBatch;
160
+ private makeBatchTooLargeError;
139
161
  /**
140
162
  * Gets a checkpoint object per batch that facilitates iterating over the batch messages when rolling back.
141
163
  */
@@ -1 +1 @@
1
- {"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,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AI;QAC7B,SAAS,EAAE,gBAAgB,CAAC;QAC5B,iBAAiB,EAAE,gBAAgB,CAAC;QACpC,eAAe,EAAE,gBAAgB,CAAC;KAClC;CAUD"}
@@ -4,10 +4,11 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Outbox = exports.getLongStack = void 0;
7
+ exports.Outbox = exports.estimateSocketSize = exports.localBatchToOutboundBatch = exports.getLongStack = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
10
10
  const batchManager_js_1 = require("./batchManager.js");
11
+ const opSerialization_js_1 = require("./opSerialization.js");
11
12
  /**
12
13
  * Temporarily increase the stack limit while executing the provided action.
13
14
  * If a negative value is provided for `length`, no stack frames will be collected.
@@ -45,6 +46,50 @@ function getLongStack(action, length = 50) {
45
46
  }
46
47
  }
47
48
  exports.getLongStack = getLongStack;
49
+ /**
50
+ * Convert from local batch to outbound batch, including computing contentSizeInBytes.
51
+ */
52
+ function localBatchToOutboundBatch({ staged: _staged, // Peel this off the incoming batch, it's irrelevant (see Note below)
53
+ ...localBatch }) {
54
+ // Note: the staged property might be misleading here, in case a pre-staging batch is resubmitted during staging mode.
55
+ // It will be set to true, but the batch was not actually staged.
56
+ // Shallow copy each message as we switch types
57
+ const outboundMessages = localBatch.messages.map(({ runtimeOp, ...message }) => ({
58
+ contents: (0, opSerialization_js_1.serializeOp)(runtimeOp),
59
+ ...message,
60
+ }));
61
+ const contentSizeInBytes = outboundMessages.reduce((acc, message) => acc + (message.contents?.length ?? 0), 0);
62
+ // Shallow copy the local batch, updating the messages to be outbound messages and adding contentSizeInBytes
63
+ const outboundBatch = {
64
+ ...localBatch,
65
+ messages: outboundMessages,
66
+ contentSizeInBytes,
67
+ };
68
+ return outboundBatch;
69
+ }
70
+ exports.localBatchToOutboundBatch = localBatchToOutboundBatch;
71
+ /**
72
+ * Estimated size of the stringification overhead for an op accumulated
73
+ * from runtime to loader to the service.
74
+ */
75
+ const opOverhead = 200;
76
+ /**
77
+ * Estimates the real size in bytes on the socket for a given batch. It assumes that
78
+ * the envelope size (and the size of an empty op) is 200 bytes, taking into account
79
+ * extra overhead from stringification.
80
+ *
81
+ * @remarks
82
+ * Also content will be stringified, and that adds a lot of overhead due to a lot of escape characters.
83
+ * Not taking it into account, as compression work should help there - compressed payload will be
84
+ * initially stored as base64, and that requires only 2 extra escape characters.
85
+ *
86
+ * @param batch - the batch to inspect
87
+ * @returns An estimate of the payload size in bytes which will be produced when the batch is sent over the wire
88
+ */
89
+ const estimateSocketSize = (batch) => {
90
+ return batch.contentSizeInBytes + opOverhead * batch.messages.length;
91
+ };
92
+ exports.estimateSocketSize = estimateSocketSize;
48
93
  /**
49
94
  * The Outbox collects messages submitted by the ContainerRuntime into a batch,
50
95
  * and then flushes the batch when requested.
@@ -66,16 +111,9 @@ class Outbox {
66
111
  this.maxMismatchedOpsToReport = 3;
67
112
  this.mismatchedOpsReported = 0;
68
113
  this.logger = (0, internal_2.createChildLogger)({ logger: params.logger, namespace: "Outbox" });
69
- const isCompressionEnabled = this.params.config.compressionOptions.minimumBatchSizeInBytes !==
70
- Number.POSITIVE_INFINITY;
71
- // We need to allow infinite size batches if we enable compression
72
- const hardLimit = isCompressionEnabled
73
- ? Number.POSITIVE_INFINITY
74
- : this.params.config.maxBatchSizeInBytes;
75
- this.mainBatch = new batchManager_js_1.BatchManager({ hardLimit, canRebase: true });
76
- this.blobAttachBatch = new batchManager_js_1.BatchManager({ hardLimit, canRebase: true });
114
+ this.mainBatch = new batchManager_js_1.BatchManager({ canRebase: true });
115
+ this.blobAttachBatch = new batchManager_js_1.BatchManager({ canRebase: true });
77
116
  this.idAllocationBatch = new batchManager_js_1.BatchManager({
78
- hardLimit,
79
117
  canRebase: false,
80
118
  ignoreBatchId: true,
81
119
  });
@@ -131,7 +169,7 @@ class Outbox {
131
169
  ? "generic"
132
170
  : "error",
133
171
  eventName: "ReferenceSequenceNumberMismatch",
134
- Data_details: {
172
+ details: {
135
173
  expectedDueToReentrancy,
136
174
  mainReferenceSequenceNumber: mainBatchSeqNums.referenceSequenceNumber,
137
175
  mainClientSequenceNumber: mainBatchSeqNums.clientSequenceNumber,
@@ -166,14 +204,7 @@ class Outbox {
166
204
  this.addMessageToBatchManager(this.idAllocationBatch, message);
167
205
  }
168
206
  addMessageToBatchManager(batchManager, message) {
169
- if (!batchManager.push(message, this.isContextReentrant(), this.params.getCurrentSequenceNumbers().clientSequenceNumber)) {
170
- throw new internal_2.GenericError("BatchTooLarge", /* error */ undefined, {
171
- opSize: message.serializedOp?.length ?? 0,
172
- batchSize: batchManager.contentSizeInBytes,
173
- count: batchManager.length,
174
- limit: batchManager.options.hardLimit,
175
- });
176
- }
207
+ batchManager.push(message, this.isContextReentrant(), this.params.getCurrentSequenceNumbers().clientSequenceNumber);
177
208
  }
178
209
  /**
179
210
  * Flush all the batches to the ordering service.
@@ -182,12 +213,14 @@ class Outbox {
182
213
  * @throws If called from a reentrant context, or if the batch being flushed is too large.
183
214
  * @param resubmittingBatchId - If defined, indicates this is a resubmission of a batch
184
215
  * with the given Batch ID, which must be preserved
216
+ * @param resubmittingStagedBatch - If defined, indicates this is a resubmission of a batch that is staged,
217
+ * meaning it should not be sent to the ordering service yet.
185
218
  */
186
- flush(resubmittingBatchId) {
219
+ flush(resubmittingBatchId, resubmittingStagedBatch) {
187
220
  (0, internal_1.assert)(!this.isContextReentrant(), 0xb7b /* Flushing must not happen while incoming changes are being processed */);
188
- this.flushAll(resubmittingBatchId);
221
+ this.flushAll(resubmittingBatchId, resubmittingStagedBatch);
189
222
  }
190
- flushAll(resubmittingBatchId) {
223
+ flushAll(resubmittingBatchId, resubmittingStagedBatch) {
191
224
  const allBatchesEmpty = this.idAllocationBatch.empty && this.blobAttachBatch.empty && this.mainBatch.empty;
192
225
  if (allBatchesEmpty) {
193
226
  // If we're resubmitting and all batches are empty, we need to flush an empty batch.
@@ -196,34 +229,51 @@ class Outbox {
196
229
  // by the rest of the system, including remote clients.
197
230
  // In some cases we *must* resubmit the empty batch (to match up with a non-empty version tracked locally by a container fork), so we do it always.
198
231
  if (resubmittingBatchId) {
199
- this.flushEmptyBatch(resubmittingBatchId);
232
+ this.flushEmptyBatch(resubmittingBatchId, resubmittingStagedBatch === true);
200
233
  }
201
234
  return;
202
235
  }
203
236
  // Don't use resubmittingBatchId for idAllocationBatch.
204
237
  // ID Allocation messages are not directly resubmitted so we don't want to reuse the batch ID.
205
- this.flushInternal(this.idAllocationBatch);
206
- this.flushInternal(this.blobAttachBatch, true /* disableGroupedBatching */, resubmittingBatchId);
207
- this.flushInternal(this.mainBatch, false /* disableGroupedBatching */, resubmittingBatchId);
238
+ this.flushInternal({
239
+ batchManager: this.idAllocationBatch,
240
+ // Note: For now, we will never stage ID Allocation messages.
241
+ // They won't contain personal info and no harm in extra allocations in case of discarding the staged changes
242
+ });
243
+ this.flushInternal({
244
+ batchManager: this.blobAttachBatch,
245
+ disableGroupedBatching: true,
246
+ resubmittingBatchId,
247
+ resubmittingStagedBatch,
248
+ });
249
+ this.flushInternal({
250
+ batchManager: this.mainBatch,
251
+ resubmittingBatchId,
252
+ resubmittingStagedBatch,
253
+ });
208
254
  }
209
- flushEmptyBatch(resubmittingBatchId) {
255
+ flushEmptyBatch(resubmittingBatchId, resubmittingStagedBatch) {
210
256
  const referenceSequenceNumber = this.params.getCurrentSequenceNumbers().referenceSequenceNumber;
211
257
  (0, internal_1.assert)(referenceSequenceNumber !== undefined, 0xa01 /* reference sequence number should be defined */);
212
258
  const { outboundBatch, placeholderMessage } = this.params.groupingManager.createEmptyGroupedBatch(resubmittingBatchId, referenceSequenceNumber);
213
259
  let clientSequenceNumber;
214
- if (this.params.shouldSend()) {
260
+ if (this.params.shouldSend() && !resubmittingStagedBatch) {
215
261
  clientSequenceNumber = this.sendBatch(outboundBatch);
216
262
  }
217
263
  // Push the empty batch placeholder to the PendingStateManager
218
- this.params.pendingStateManager.onFlushBatch([{ ...placeholderMessage, serializedOp: "", contents: undefined }], // placeholder message - serializedOp will never be used
219
- clientSequenceNumber);
264
+ this.params.pendingStateManager.onFlushEmptyBatch(placeholderMessage, clientSequenceNumber, resubmittingStagedBatch);
220
265
  return;
221
266
  }
222
- flushInternal(batchManager, disableGroupedBatching = false, resubmittingBatchId) {
267
+ flushInternal(params) {
268
+ const { batchManager, disableGroupedBatching = false, resubmittingBatchId, resubmittingStagedBatch, } = params;
223
269
  if (batchManager.empty) {
224
270
  return;
225
271
  }
226
272
  const rawBatch = batchManager.popBatch(resubmittingBatchId);
273
+ // When resubmitting, we respect the staged state of the original batch.
274
+ // In this case rawBatch.staged will match the state of inStagingMode when
275
+ // the resubmit occurred, which is not relevant.
276
+ const staged = resubmittingStagedBatch ?? rawBatch.staged === true;
227
277
  const groupingEnabled = !disableGroupedBatching && this.params.groupingManager.groupedBatchingEnabled();
228
278
  if (batchManager.options.canRebase &&
229
279
  rawBatch.hasReentrantOps === true &&
@@ -235,6 +285,9 @@ class Outbox {
235
285
  // If a batch contains reentrant ops (ops created as a result from processing another op)
236
286
  // it needs to be rebased so that we can ensure consistent reference sequence numbers
237
287
  // and eventual consistency at the DDS level.
288
+ // Note: Since this is happening in the same turn the ops were originally created with,
289
+ // and they haven't gone to PendingStateManager yet, we can just let them respect
290
+ // ContainerRuntime.inStagingMode
238
291
  this.rebase(rawBatch, batchManager);
239
292
  return;
240
293
  }
@@ -242,12 +295,12 @@ class Outbox {
242
295
  // Did we disconnect? (i.e. is shouldSend false?)
243
296
  // If so, do nothing, as pending state manager will resubmit it correctly on reconnect.
244
297
  // Because flush() is a task that executes async (on clean stack), we can get here in disconnected state.
245
- if (this.params.shouldSend()) {
298
+ if (this.params.shouldSend() && !staged) {
246
299
  const virtualizedBatch = this.virtualizeBatch(rawBatch, groupingEnabled);
247
300
  clientSequenceNumber = this.sendBatch(virtualizedBatch);
248
301
  (0, internal_1.assert)(clientSequenceNumber === undefined || clientSequenceNumber >= 0, 0x9d2 /* unexpected negative clientSequenceNumber (empty batch should yield undefined) */);
249
302
  }
250
- this.params.pendingStateManager.onFlushBatch(rawBatch.messages, clientSequenceNumber, batchManager.options.ignoreBatchId);
303
+ this.params.pendingStateManager.onFlushBatch(rawBatch.messages, clientSequenceNumber, staged, batchManager.options.ignoreBatchId);
251
304
  }
252
305
  /**
253
306
  * Rebases a batch. All the ops in the batch are resubmitted to the runtime and
@@ -261,7 +314,7 @@ class Outbox {
261
314
  this.rebasing = true;
262
315
  for (const message of rawBatch.messages) {
263
316
  this.params.reSubmit({
264
- content: message.serializedOp,
317
+ runtimeOp: message.runtimeOp,
265
318
  localOpMetadata: message.localOpMetadata,
266
319
  opMetadata: message.metadata,
267
320
  });
@@ -274,7 +327,7 @@ class Outbox {
274
327
  }, new internal_2.UsageError("BatchRebase"));
275
328
  this.batchRebasesToReport--;
276
329
  }
277
- this.flushInternal(batchManager);
330
+ this.flushInternal({ batchManager });
278
331
  this.rebasing = false;
279
332
  }
280
333
  isContextReentrant() {
@@ -295,13 +348,7 @@ class Outbox {
295
348
  */
296
349
  virtualizeBatch(localBatch, groupingEnabled) {
297
350
  // Shallow copy the local batch, updating the messages to be outbound messages
298
- const originalBatch = {
299
- ...localBatch,
300
- messages: localBatch.messages.map(({ serializedOp, ...message }) => ({
301
- contents: serializedOp,
302
- ...message,
303
- })),
304
- };
351
+ const originalBatch = localBatchToOutboundBatch(localBatch);
305
352
  const originalOrGroupedBatch = groupingEnabled
306
353
  ? this.params.groupingManager.groupBatch(originalBatch)
307
354
  : originalBatch;
@@ -312,9 +359,8 @@ class Outbox {
312
359
  // Regardless of whether we grouped or not, we now have a batch with a single message.
313
360
  // Now proceed to compress/chunk it if necessary.
314
361
  const singletonBatch = originalOrGroupedBatch;
315
- if (this.params.config.compressionOptions === undefined ||
316
- this.params.config.compressionOptions.minimumBatchSizeInBytes >
317
- singletonBatch.contentSizeInBytes ||
362
+ if (this.params.config.compressionOptions.minimumBatchSizeInBytes >
363
+ singletonBatch.contentSizeInBytes ||
318
364
  this.params.submitBatchFn === undefined) {
319
365
  // Nothing to do if compression is disabled, unnecessary or unsupported.
320
366
  return singletonBatch;
@@ -325,16 +371,10 @@ class Outbox {
325
371
  ? compressedBatch
326
372
  : this.params.splitter.splitSingletonBatchMessage(compressedBatch);
327
373
  }
374
+ // We want to distinguish this "BatchTooLarge" case from the generic "BatchTooLarge" case in sendBatch
328
375
  if (compressedBatch.contentSizeInBytes >= this.params.config.maxBatchSizeInBytes) {
329
- throw internal_2.DataProcessingError.create("BatchTooLarge", "compressionInsufficient",
330
- /* sequencedMessage */ undefined, {
331
- batchSize: singletonBatch.contentSizeInBytes,
332
- compressedBatchSize: compressedBatch.contentSizeInBytes,
333
- count: compressedBatch.messages.length,
334
- limit: this.params.config.maxBatchSizeInBytes,
335
- chunkingEnabled: this.params.splitter.isBatchChunkingEnabled,
336
- compressionOptions: JSON.stringify(this.params.config.compressionOptions),
337
- socketSize: (0, batchManager_js_1.estimateSocketSize)(singletonBatch),
376
+ throw this.makeBatchTooLargeError(compressedBatch, "CompressionInsufficient", {
377
+ uncompressedSizeInBytes: singletonBatch.contentSizeInBytes,
338
378
  });
339
379
  }
340
380
  return compressedBatch;
@@ -350,14 +390,9 @@ class Outbox {
350
390
  if (length === 0) {
351
391
  return undefined; // Nothing submitted
352
392
  }
353
- const socketSize = (0, batchManager_js_1.estimateSocketSize)(batch);
393
+ const socketSize = (0, exports.estimateSocketSize)(batch);
354
394
  if (socketSize >= this.params.config.maxBatchSizeInBytes) {
355
- this.logger.sendPerformanceEvent({
356
- eventName: "LargeBatch",
357
- length: batch.messages.length,
358
- sizeInBytes: batch.contentSizeInBytes,
359
- socketSize,
360
- });
395
+ throw this.makeBatchTooLargeError(batch, "CannotSend");
361
396
  }
362
397
  let clientSequenceNumber;
363
398
  if (this.params.submitBatchFn === undefined) {
@@ -380,6 +415,22 @@ class Outbox {
380
415
  (0, internal_1.assert)(clientSequenceNumber >= 0, 0x3d0 /* clientSequenceNumber can't be negative */);
381
416
  return clientSequenceNumber;
382
417
  }
418
+ makeBatchTooLargeError(batch, codepath, moreDetails) {
419
+ return internal_2.DataProcessingError.create("BatchTooLarge", codepath,
420
+ /* sequencedMessage */ undefined, {
421
+ errorDetails: {
422
+ opCount: batch.messages.length,
423
+ contentSizeInBytes: batch.contentSizeInBytes,
424
+ socketSize: (0, exports.estimateSocketSize)(batch),
425
+ maxBatchSizeInBytes: this.params.config.maxBatchSizeInBytes,
426
+ groupedBatchingEnabled: this.params.groupingManager.groupedBatchingEnabled(),
427
+ compressionOptions: JSON.stringify(this.params.config.compressionOptions),
428
+ chunkingEnabled: this.params.splitter.isBatchChunkingEnabled,
429
+ chunkSizeInBytes: this.params.splitter.chunkSizeInBytes,
430
+ ...moreDetails,
431
+ },
432
+ });
433
+ }
383
434
  /**
384
435
  * Gets a checkpoint object per batch that facilitates iterating over the batch messages when rolling back.
385
436
  */