@fluidframework/container-runtime 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/.eslintrc.js +19 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts.map +1 -1
  5. package/dist/batchTracker.js +2 -1
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager.d.ts +15 -2
  8. package/dist/blobManager.d.ts.map +1 -1
  9. package/dist/blobManager.js +109 -37
  10. package/dist/blobManager.js.map +1 -1
  11. package/dist/connectionTelemetry.d.ts.map +1 -1
  12. package/dist/connectionTelemetry.js +11 -9
  13. package/dist/connectionTelemetry.js.map +1 -1
  14. package/dist/containerHandleContext.d.ts.map +1 -1
  15. package/dist/containerHandleContext.js +3 -1
  16. package/dist/containerHandleContext.js.map +1 -1
  17. package/dist/containerRuntime.d.ts +23 -11
  18. package/dist/containerRuntime.d.ts.map +1 -1
  19. package/dist/containerRuntime.js +225 -132
  20. package/dist/containerRuntime.js.map +1 -1
  21. package/dist/dataStore.d.ts.map +1 -1
  22. package/dist/dataStore.js +11 -9
  23. package/dist/dataStore.js.map +1 -1
  24. package/dist/dataStoreContext.d.ts +27 -13
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +95 -56
  27. package/dist/dataStoreContext.js.map +1 -1
  28. package/dist/dataStoreContexts.d.ts.map +1 -1
  29. package/dist/dataStoreContexts.js +7 -3
  30. package/dist/dataStoreContexts.js.map +1 -1
  31. package/dist/dataStoreRegistry.d.ts.map +1 -1
  32. package/dist/dataStoreRegistry.js +3 -1
  33. package/dist/dataStoreRegistry.js.map +1 -1
  34. package/dist/dataStores.d.ts +28 -4
  35. package/dist/dataStores.d.ts.map +1 -1
  36. package/dist/dataStores.js +122 -44
  37. package/dist/dataStores.js.map +1 -1
  38. package/dist/deltaScheduler.d.ts.map +1 -1
  39. package/dist/deltaScheduler.js +8 -3
  40. package/dist/deltaScheduler.js.map +1 -1
  41. package/dist/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +27 -203
  42. package/dist/gc/garbageCollection.d.ts.map +1 -0
  43. package/dist/{garbageCollection.js → gc/garbageCollection.js} +210 -400
  44. package/dist/gc/garbageCollection.js.map +1 -0
  45. package/dist/gc/gcDefinitions.d.ts +189 -0
  46. package/dist/gc/gcDefinitions.d.ts.map +1 -0
  47. package/dist/{garbageCollectionConstants.js → gc/gcDefinitions.js} +27 -2
  48. package/dist/gc/gcDefinitions.js.map +1 -0
  49. package/dist/gc/gcHelpers.d.ts +30 -0
  50. package/dist/gc/gcHelpers.d.ts.map +1 -0
  51. package/dist/gc/gcHelpers.js +65 -0
  52. package/dist/gc/gcHelpers.js.map +1 -0
  53. package/dist/gc/gcSummaryStateTracker.d.ts +86 -0
  54. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -0
  55. package/dist/gc/gcSummaryStateTracker.js +246 -0
  56. package/dist/gc/gcSummaryStateTracker.js.map +1 -0
  57. package/{lib → dist/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  58. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  59. package/dist/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  60. package/dist/gc/gcSweepReadyUsageDetection.js.map +1 -0
  61. package/dist/gc/gcUnreferencedStateTracker.d.ts +34 -0
  62. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  63. package/dist/gc/gcUnreferencedStateTracker.js +94 -0
  64. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -0
  65. package/dist/gc/index.d.ts +11 -0
  66. package/dist/gc/index.d.ts.map +1 -0
  67. package/dist/gc/index.js +40 -0
  68. package/dist/gc/index.js.map +1 -0
  69. package/dist/index.d.ts +2 -5
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +6 -9
  72. package/dist/index.js.map +1 -1
  73. package/dist/opLifecycle/batchManager.d.ts +2 -13
  74. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  75. package/dist/opLifecycle/batchManager.js +19 -41
  76. package/dist/opLifecycle/batchManager.js.map +1 -1
  77. package/dist/opLifecycle/definitions.d.ts +4 -0
  78. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  79. package/dist/opLifecycle/definitions.js.map +1 -1
  80. package/dist/opLifecycle/index.d.ts.map +1 -1
  81. package/dist/opLifecycle/index.js.map +1 -1
  82. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  83. package/dist/opLifecycle/opCompressor.js +1 -0
  84. package/dist/opLifecycle/opCompressor.js.map +1 -1
  85. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  86. package/dist/opLifecycle/opDecompressor.js +5 -2
  87. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  88. package/dist/opLifecycle/opSplitter.d.ts +1 -1
  89. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  90. package/dist/opLifecycle/opSplitter.js +24 -13
  91. package/dist/opLifecycle/opSplitter.js.map +1 -1
  92. package/dist/opLifecycle/outbox.d.ts +19 -3
  93. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  94. package/dist/opLifecycle/outbox.js +78 -45
  95. package/dist/opLifecycle/outbox.js.map +1 -1
  96. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  97. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  98. package/dist/opProperties.d.ts.map +1 -1
  99. package/dist/opProperties.js +1 -3
  100. package/dist/opProperties.js.map +1 -1
  101. package/dist/packageVersion.d.ts +1 -1
  102. package/dist/packageVersion.js +1 -1
  103. package/dist/packageVersion.js.map +1 -1
  104. package/dist/pendingStateManager.d.ts +8 -2
  105. package/dist/pendingStateManager.d.ts.map +1 -1
  106. package/dist/pendingStateManager.js +21 -13
  107. package/dist/pendingStateManager.js.map +1 -1
  108. package/dist/scheduleManager.d.ts.map +1 -1
  109. package/dist/scheduleManager.js +3 -2
  110. package/dist/scheduleManager.js.map +1 -1
  111. package/dist/serializedSnapshotStorage.d.ts +2 -2
  112. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  113. package/dist/serializedSnapshotStorage.js +5 -3
  114. package/dist/serializedSnapshotStorage.js.map +1 -1
  115. package/dist/summary/index.d.ts +17 -0
  116. package/dist/summary/index.d.ts.map +1 -0
  117. package/dist/summary/index.js +47 -0
  118. package/dist/summary/index.js.map +1 -0
  119. package/dist/summary/orderedClientElection.d.ts.map +1 -0
  120. package/dist/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  121. package/dist/summary/orderedClientElection.js.map +1 -0
  122. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  123. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -0
  124. package/{lib → dist/summary}/runningSummarizer.d.ts +19 -18
  125. package/dist/summary/runningSummarizer.d.ts.map +1 -0
  126. package/dist/{runningSummarizer.js → summary/runningSummarizer.js} +191 -76
  127. package/dist/summary/runningSummarizer.js.map +1 -0
  128. package/dist/{summarizer.d.ts → summary/summarizer.d.ts} +4 -6
  129. package/dist/summary/summarizer.d.ts.map +1 -0
  130. package/dist/{summarizer.js → summary/summarizer.js} +31 -71
  131. package/dist/summary/summarizer.js.map +1 -0
  132. package/dist/summary/summarizerClientElection.d.ts.map +1 -0
  133. package/dist/summary/summarizerClientElection.js.map +1 -0
  134. package/dist/summary/summarizerHandle.d.ts.map +1 -0
  135. package/dist/summary/summarizerHandle.js.map +1 -0
  136. package/{lib → dist/summary}/summarizerHeuristics.d.ts +1 -1
  137. package/dist/summary/summarizerHeuristics.d.ts.map +1 -0
  138. package/dist/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +6 -9
  139. package/dist/summary/summarizerHeuristics.js.map +1 -0
  140. package/{lib → dist/summary}/summarizerTypes.d.ts +22 -22
  141. package/dist/summary/summarizerTypes.d.ts.map +1 -0
  142. package/dist/summary/summarizerTypes.js.map +1 -0
  143. package/dist/summary/summaryCollection.d.ts.map +1 -0
  144. package/dist/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  145. package/dist/summary/summaryCollection.js.map +1 -0
  146. package/{lib → dist/summary}/summaryFormat.d.ts +1 -40
  147. package/dist/summary/summaryFormat.d.ts.map +1 -0
  148. package/dist/{summaryFormat.js → summary/summaryFormat.js} +19 -20
  149. package/dist/summary/summaryFormat.js.map +1 -0
  150. package/dist/summary/summaryGenerator.d.ts.map +1 -0
  151. package/dist/{summaryGenerator.js → summary/summaryGenerator.js} +33 -15
  152. package/dist/summary/summaryGenerator.js.map +1 -0
  153. package/dist/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  154. package/dist/summary/summaryManager.d.ts.map +1 -0
  155. package/dist/{summaryManager.js → summary/summaryManager.js} +21 -9
  156. package/dist/summary/summaryManager.js.map +1 -0
  157. package/dist/throttler.d.ts +2 -2
  158. package/dist/throttler.d.ts.map +1 -1
  159. package/dist/throttler.js +4 -4
  160. package/dist/throttler.js.map +1 -1
  161. package/lib/batchTracker.d.ts.map +1 -1
  162. package/lib/batchTracker.js +2 -1
  163. package/lib/batchTracker.js.map +1 -1
  164. package/lib/blobManager.d.ts +15 -2
  165. package/lib/blobManager.d.ts.map +1 -1
  166. package/lib/blobManager.js +109 -37
  167. package/lib/blobManager.js.map +1 -1
  168. package/lib/connectionTelemetry.d.ts.map +1 -1
  169. package/lib/connectionTelemetry.js +11 -9
  170. package/lib/connectionTelemetry.js.map +1 -1
  171. package/lib/containerHandleContext.d.ts.map +1 -1
  172. package/lib/containerHandleContext.js +3 -1
  173. package/lib/containerHandleContext.js.map +1 -1
  174. package/lib/containerRuntime.d.ts +23 -11
  175. package/lib/containerRuntime.d.ts.map +1 -1
  176. package/lib/containerRuntime.js +201 -108
  177. package/lib/containerRuntime.js.map +1 -1
  178. package/lib/dataStore.d.ts.map +1 -1
  179. package/lib/dataStore.js +11 -9
  180. package/lib/dataStore.js.map +1 -1
  181. package/lib/dataStoreContext.d.ts +27 -13
  182. package/lib/dataStoreContext.d.ts.map +1 -1
  183. package/lib/dataStoreContext.js +84 -45
  184. package/lib/dataStoreContext.js.map +1 -1
  185. package/lib/dataStoreContexts.d.ts.map +1 -1
  186. package/lib/dataStoreContexts.js +7 -3
  187. package/lib/dataStoreContexts.js.map +1 -1
  188. package/lib/dataStoreRegistry.d.ts.map +1 -1
  189. package/lib/dataStoreRegistry.js +3 -1
  190. package/lib/dataStoreRegistry.js.map +1 -1
  191. package/lib/dataStores.d.ts +28 -4
  192. package/lib/dataStores.d.ts.map +1 -1
  193. package/lib/dataStores.js +120 -42
  194. package/lib/dataStores.js.map +1 -1
  195. package/lib/deltaScheduler.d.ts.map +1 -1
  196. package/lib/deltaScheduler.js +9 -4
  197. package/lib/deltaScheduler.js.map +1 -1
  198. package/lib/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +27 -203
  199. package/lib/gc/garbageCollection.d.ts.map +1 -0
  200. package/lib/{garbageCollection.js → gc/garbageCollection.js} +190 -379
  201. package/lib/gc/garbageCollection.js.map +1 -0
  202. package/lib/gc/gcDefinitions.d.ts +189 -0
  203. package/lib/gc/gcDefinitions.d.ts.map +1 -0
  204. package/lib/{garbageCollectionConstants.js → gc/gcDefinitions.js} +26 -1
  205. package/lib/gc/gcDefinitions.js.map +1 -0
  206. package/lib/gc/gcHelpers.d.ts +30 -0
  207. package/lib/gc/gcHelpers.d.ts.map +1 -0
  208. package/lib/gc/gcHelpers.js +58 -0
  209. package/lib/gc/gcHelpers.js.map +1 -0
  210. package/lib/gc/gcSummaryStateTracker.d.ts +86 -0
  211. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -0
  212. package/lib/gc/gcSummaryStateTracker.js +242 -0
  213. package/lib/gc/gcSummaryStateTracker.js.map +1 -0
  214. package/{dist → lib/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  215. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  216. package/lib/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  217. package/lib/gc/gcSweepReadyUsageDetection.js.map +1 -0
  218. package/lib/gc/gcUnreferencedStateTracker.d.ts +34 -0
  219. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  220. package/lib/gc/gcUnreferencedStateTracker.js +90 -0
  221. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -0
  222. package/lib/gc/index.d.ts +11 -0
  223. package/lib/gc/index.d.ts.map +1 -0
  224. package/lib/gc/index.js +11 -0
  225. package/lib/gc/index.js.map +1 -0
  226. package/lib/index.d.ts +2 -5
  227. package/lib/index.d.ts.map +1 -1
  228. package/lib/index.js +1 -4
  229. package/lib/index.js.map +1 -1
  230. package/lib/opLifecycle/batchManager.d.ts +2 -13
  231. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  232. package/lib/opLifecycle/batchManager.js +19 -41
  233. package/lib/opLifecycle/batchManager.js.map +1 -1
  234. package/lib/opLifecycle/definitions.d.ts +4 -0
  235. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  236. package/lib/opLifecycle/definitions.js.map +1 -1
  237. package/lib/opLifecycle/index.d.ts.map +1 -1
  238. package/lib/opLifecycle/index.js.map +1 -1
  239. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  240. package/lib/opLifecycle/opCompressor.js +1 -0
  241. package/lib/opLifecycle/opCompressor.js.map +1 -1
  242. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  243. package/lib/opLifecycle/opDecompressor.js +5 -2
  244. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  245. package/lib/opLifecycle/opSplitter.d.ts +1 -1
  246. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  247. package/lib/opLifecycle/opSplitter.js +25 -14
  248. package/lib/opLifecycle/opSplitter.js.map +1 -1
  249. package/lib/opLifecycle/outbox.d.ts +19 -3
  250. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  251. package/lib/opLifecycle/outbox.js +79 -46
  252. package/lib/opLifecycle/outbox.js.map +1 -1
  253. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  254. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  255. package/lib/opProperties.d.ts.map +1 -1
  256. package/lib/opProperties.js +1 -3
  257. package/lib/opProperties.js.map +1 -1
  258. package/lib/packageVersion.d.ts +1 -1
  259. package/lib/packageVersion.js +1 -1
  260. package/lib/packageVersion.js.map +1 -1
  261. package/lib/pendingStateManager.d.ts +8 -2
  262. package/lib/pendingStateManager.d.ts.map +1 -1
  263. package/lib/pendingStateManager.js +21 -13
  264. package/lib/pendingStateManager.js.map +1 -1
  265. package/lib/scheduleManager.d.ts.map +1 -1
  266. package/lib/scheduleManager.js +3 -2
  267. package/lib/scheduleManager.js.map +1 -1
  268. package/lib/serializedSnapshotStorage.d.ts +2 -2
  269. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  270. package/lib/serializedSnapshotStorage.js +5 -3
  271. package/lib/serializedSnapshotStorage.js.map +1 -1
  272. package/lib/summary/index.d.ts +17 -0
  273. package/lib/summary/index.d.ts.map +1 -0
  274. package/lib/summary/index.js +16 -0
  275. package/lib/summary/index.js.map +1 -0
  276. package/lib/summary/orderedClientElection.d.ts.map +1 -0
  277. package/lib/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  278. package/lib/summary/orderedClientElection.js.map +1 -0
  279. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  280. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -0
  281. package/{dist → lib/summary}/runningSummarizer.d.ts +19 -18
  282. package/lib/summary/runningSummarizer.d.ts.map +1 -0
  283. package/lib/{runningSummarizer.js → summary/runningSummarizer.js} +193 -78
  284. package/lib/summary/runningSummarizer.js.map +1 -0
  285. package/lib/{summarizer.d.ts → summary/summarizer.d.ts} +4 -6
  286. package/lib/summary/summarizer.d.ts.map +1 -0
  287. package/lib/{summarizer.js → summary/summarizer.js} +33 -73
  288. package/lib/summary/summarizer.js.map +1 -0
  289. package/lib/summary/summarizerClientElection.d.ts.map +1 -0
  290. package/lib/summary/summarizerClientElection.js.map +1 -0
  291. package/lib/summary/summarizerHandle.d.ts.map +1 -0
  292. package/lib/summary/summarizerHandle.js.map +1 -0
  293. package/{dist → lib/summary}/summarizerHeuristics.d.ts +1 -1
  294. package/lib/summary/summarizerHeuristics.d.ts.map +1 -0
  295. package/lib/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +6 -9
  296. package/lib/summary/summarizerHeuristics.js.map +1 -0
  297. package/{dist → lib/summary}/summarizerTypes.d.ts +22 -22
  298. package/lib/summary/summarizerTypes.d.ts.map +1 -0
  299. package/lib/summary/summarizerTypes.js.map +1 -0
  300. package/lib/summary/summaryCollection.d.ts.map +1 -0
  301. package/lib/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  302. package/lib/summary/summaryCollection.js.map +1 -0
  303. package/{dist → lib/summary}/summaryFormat.d.ts +1 -40
  304. package/lib/summary/summaryFormat.d.ts.map +1 -0
  305. package/lib/{summaryFormat.js → summary/summaryFormat.js} +20 -20
  306. package/lib/summary/summaryFormat.js.map +1 -0
  307. package/lib/summary/summaryGenerator.d.ts.map +1 -0
  308. package/lib/{summaryGenerator.js → summary/summaryGenerator.js} +33 -15
  309. package/lib/summary/summaryGenerator.js.map +1 -0
  310. package/lib/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  311. package/lib/summary/summaryManager.d.ts.map +1 -0
  312. package/lib/{summaryManager.js → summary/summaryManager.js} +21 -9
  313. package/lib/summary/summaryManager.js.map +1 -0
  314. package/lib/throttler.d.ts +2 -2
  315. package/lib/throttler.d.ts.map +1 -1
  316. package/lib/throttler.js +4 -4
  317. package/lib/throttler.js.map +1 -1
  318. package/package.json +60 -51
  319. package/prettier.config.cjs +1 -1
  320. package/src/batchTracker.ts +54 -49
  321. package/src/blobManager.ts +825 -674
  322. package/src/connectionTelemetry.ts +280 -249
  323. package/src/containerHandleContext.ts +27 -29
  324. package/src/containerRuntime.ts +3249 -2978
  325. package/src/dataStore.ts +172 -159
  326. package/src/dataStoreContext.ts +1141 -1057
  327. package/src/dataStoreContexts.ts +178 -161
  328. package/src/dataStoreRegistry.ts +25 -20
  329. package/src/dataStores.ts +880 -731
  330. package/src/deltaScheduler.ts +158 -150
  331. package/{garbageCollection.md → src/gc/garbageCollection.md} +16 -3
  332. package/src/gc/garbageCollection.ts +1506 -0
  333. package/src/gc/gcDefinitions.ts +244 -0
  334. package/src/gc/gcHelpers.ts +86 -0
  335. package/src/gc/gcSummaryStateTracker.ts +339 -0
  336. package/src/gc/gcSweepReadyUsageDetection.ts +145 -0
  337. package/src/gc/gcUnreferencedStateTracker.ts +114 -0
  338. package/src/gc/index.ts +40 -0
  339. package/src/index.ts +67 -70
  340. package/src/opLifecycle/README.md +152 -0
  341. package/src/opLifecycle/batchManager.ts +101 -144
  342. package/src/opLifecycle/definitions.ts +33 -29
  343. package/src/opLifecycle/index.ts +5 -5
  344. package/src/opLifecycle/opCompressor.ts +55 -53
  345. package/src/opLifecycle/opDecompressor.ts +100 -81
  346. package/src/opLifecycle/opSplitter.ts +233 -188
  347. package/src/opLifecycle/outbox.ts +251 -195
  348. package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
  349. package/src/opProperties.ts +11 -9
  350. package/src/packageVersion.ts +1 -1
  351. package/src/pendingStateManager.ts +396 -338
  352. package/src/scheduleManager.ts +299 -269
  353. package/src/serializedSnapshotStorage.ts +126 -112
  354. package/src/summary/index.ts +99 -0
  355. package/src/summary/orderedClientElection.ts +564 -0
  356. package/src/summary/runWhileConnectedCoordinator.ts +113 -0
  357. package/src/summary/runningSummarizer.ts +788 -0
  358. package/src/summary/summarizer.ts +386 -0
  359. package/src/summary/summarizerClientElection.ts +139 -0
  360. package/src/{summarizerHandle.ts → summary/summarizerHandle.ts} +11 -9
  361. package/src/summary/summarizerHeuristics.ts +219 -0
  362. package/src/summary/summarizerTypes.ts +521 -0
  363. package/src/summary/summaryCollection.ts +450 -0
  364. package/src/summary/summaryFormat.ts +226 -0
  365. package/src/summary/summaryGenerator.ts +505 -0
  366. package/src/summary/summaryManager.ts +423 -0
  367. package/src/throttler.ts +131 -122
  368. package/tsconfig.esnext.json +6 -6
  369. package/tsconfig.json +9 -13
  370. package/dist/garbageCollection.d.ts.map +0 -1
  371. package/dist/garbageCollection.js.map +0 -1
  372. package/dist/garbageCollectionConstants.d.ts +0 -25
  373. package/dist/garbageCollectionConstants.d.ts.map +0 -1
  374. package/dist/garbageCollectionConstants.js.map +0 -1
  375. package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
  376. package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  377. package/dist/garbageCollectionTombstoneUtils.js +0 -23
  378. package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
  379. package/dist/gcSweepReadyUsageDetection.d.ts.map +0 -1
  380. package/dist/gcSweepReadyUsageDetection.js.map +0 -1
  381. package/dist/orderedClientElection.d.ts.map +0 -1
  382. package/dist/orderedClientElection.js.map +0 -1
  383. package/dist/runWhileConnectedCoordinator.d.ts.map +0 -1
  384. package/dist/runWhileConnectedCoordinator.js.map +0 -1
  385. package/dist/runningSummarizer.d.ts.map +0 -1
  386. package/dist/runningSummarizer.js.map +0 -1
  387. package/dist/summarizer.d.ts.map +0 -1
  388. package/dist/summarizer.js.map +0 -1
  389. package/dist/summarizerClientElection.d.ts.map +0 -1
  390. package/dist/summarizerClientElection.js.map +0 -1
  391. package/dist/summarizerHandle.d.ts.map +0 -1
  392. package/dist/summarizerHandle.js.map +0 -1
  393. package/dist/summarizerHeuristics.d.ts.map +0 -1
  394. package/dist/summarizerHeuristics.js.map +0 -1
  395. package/dist/summarizerTypes.d.ts.map +0 -1
  396. package/dist/summarizerTypes.js.map +0 -1
  397. package/dist/summaryCollection.d.ts.map +0 -1
  398. package/dist/summaryCollection.js.map +0 -1
  399. package/dist/summaryFormat.d.ts.map +0 -1
  400. package/dist/summaryFormat.js.map +0 -1
  401. package/dist/summaryGenerator.d.ts.map +0 -1
  402. package/dist/summaryGenerator.js.map +0 -1
  403. package/dist/summaryManager.d.ts.map +0 -1
  404. package/dist/summaryManager.js.map +0 -1
  405. package/lib/garbageCollection.d.ts.map +0 -1
  406. package/lib/garbageCollection.js.map +0 -1
  407. package/lib/garbageCollectionConstants.d.ts +0 -25
  408. package/lib/garbageCollectionConstants.d.ts.map +0 -1
  409. package/lib/garbageCollectionConstants.js.map +0 -1
  410. package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
  411. package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  412. package/lib/garbageCollectionTombstoneUtils.js +0 -19
  413. package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
  414. package/lib/gcSweepReadyUsageDetection.d.ts.map +0 -1
  415. package/lib/gcSweepReadyUsageDetection.js.map +0 -1
  416. package/lib/orderedClientElection.d.ts.map +0 -1
  417. package/lib/orderedClientElection.js.map +0 -1
  418. package/lib/runWhileConnectedCoordinator.d.ts.map +0 -1
  419. package/lib/runWhileConnectedCoordinator.js.map +0 -1
  420. package/lib/runningSummarizer.d.ts.map +0 -1
  421. package/lib/runningSummarizer.js.map +0 -1
  422. package/lib/summarizer.d.ts.map +0 -1
  423. package/lib/summarizer.js.map +0 -1
  424. package/lib/summarizerClientElection.d.ts.map +0 -1
  425. package/lib/summarizerClientElection.js.map +0 -1
  426. package/lib/summarizerHandle.d.ts.map +0 -1
  427. package/lib/summarizerHandle.js.map +0 -1
  428. package/lib/summarizerHeuristics.d.ts.map +0 -1
  429. package/lib/summarizerHeuristics.js.map +0 -1
  430. package/lib/summarizerTypes.d.ts.map +0 -1
  431. package/lib/summarizerTypes.js.map +0 -1
  432. package/lib/summaryCollection.d.ts.map +0 -1
  433. package/lib/summaryCollection.js.map +0 -1
  434. package/lib/summaryFormat.d.ts.map +0 -1
  435. package/lib/summaryFormat.js.map +0 -1
  436. package/lib/summaryGenerator.d.ts.map +0 -1
  437. package/lib/summaryGenerator.js.map +0 -1
  438. package/lib/summaryManager.d.ts.map +0 -1
  439. package/lib/summaryManager.js.map +0 -1
  440. package/src/garbageCollection.ts +0 -1800
  441. package/src/garbageCollectionConstants.ts +0 -41
  442. package/src/garbageCollectionTombstoneUtils.ts +0 -28
  443. package/src/gcSweepReadyUsageDetection.ts +0 -139
  444. package/src/orderedClientElection.ts +0 -532
  445. package/src/runWhileConnectedCoordinator.ts +0 -106
  446. package/src/runningSummarizer.ts +0 -610
  447. package/src/summarizer.ts +0 -421
  448. package/src/summarizerClientElection.ts +0 -132
  449. package/src/summarizerHeuristics.ts +0 -222
  450. package/src/summarizerTypes.ts +0 -507
  451. package/src/summaryCollection.ts +0 -421
  452. package/src/summaryFormat.ts +0 -256
  453. package/src/summaryGenerator.ts +0 -450
  454. package/src/summaryManager.ts +0 -394
  455. /package/dist/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  456. /package/dist/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  457. /package/dist/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  458. /package/dist/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  459. /package/dist/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  460. /package/dist/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  461. /package/dist/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  462. /package/dist/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  463. /package/dist/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  464. /package/dist/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  465. /package/lib/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  466. /package/lib/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  467. /package/lib/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  468. /package/lib/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  469. /package/lib/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  470. /package/lib/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  471. /package/lib/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  472. /package/lib/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  473. /package/lib/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  474. /package/lib/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
@@ -18,88 +18,107 @@ import { IMessageProcessingResult } from "./definitions";
18
18
  * 4. An individually compressed op will have undefined batch metadata and compression set to true
19
19
  */
20
20
  export class OpDecompressor {
21
- private activeBatch = false;
22
- private rootMessageContents: any | undefined;
23
- private processedCount = 0;
24
-
25
- public processMessage(message: ISequencedDocumentMessage): IMessageProcessingResult {
26
- assert(
27
- message.compression === undefined || message.compression === CompressionAlgorithms.lz4,
28
- 0x511 /* Only lz4 compression is supported */);
29
-
30
- if (message.metadata?.batch === true && message.compression === CompressionAlgorithms.lz4) {
31
- // Beginning of a compressed batch
32
- assert(this.activeBatch === false, 0x4b8 /* shouldn't have multiple active batches */);
33
- if (message.compression) {
34
- // lz4 is the only supported compression algorithm for now
35
- assert(message.compression === CompressionAlgorithms.lz4,
36
- 0x4b9 /* lz4 is currently the only supported compression algorithm */);
37
- }
38
-
39
- this.activeBatch = true;
40
-
41
- const contents = IsoBuffer.from(message.contents.packedContents, "base64");
42
- const decompressedMessage = decompress(contents);
43
- const intoString = Uint8ArrayToString(decompressedMessage);
44
- const asObj = JSON.parse(intoString);
45
- this.rootMessageContents = asObj;
46
-
47
- return {
48
- message: newMessage(message, this.rootMessageContents[this.processedCount++]),
49
- state: "Accepted",
50
- };
51
- }
52
-
53
- if (this.rootMessageContents !== undefined && message.metadata?.batch === undefined && this.activeBatch) {
54
- assert(message.contents === undefined, 0x512 /* Expecting empty message */);
55
-
56
- // Continuation of compressed batch
57
- return {
58
- message: newMessage(message, this.rootMessageContents[this.processedCount++]),
59
- state: "Accepted",
60
- };
61
- }
62
-
63
- if (this.rootMessageContents !== undefined && message.metadata?.batch === false) {
64
- // End of compressed batch
65
- const returnMessage = newMessage(message, this.rootMessageContents[this.processedCount++]);
66
-
67
- this.activeBatch = false;
68
- this.rootMessageContents = undefined;
69
- this.processedCount = 0;
70
-
71
- return {
72
- message: returnMessage,
73
- state: "Processed",
74
- };
75
- }
76
-
77
- if (message.metadata?.batch === undefined && message.compression === CompressionAlgorithms.lz4) {
78
- // Single compressed message
79
- assert(this.activeBatch === false, 0x4ba /* shouldn't receive compressed message in middle of a batch */);
80
-
81
- const contents = IsoBuffer.from(message.contents.packedContents, "base64");
82
- const decompressedMessage = decompress(contents);
83
- const intoString = new TextDecoder().decode(decompressedMessage);
84
- const asObj = JSON.parse(intoString);
85
-
86
- return {
87
- message: newMessage(message, asObj[0]),
88
- state: "Processed",
89
- };
90
- }
91
-
92
- return {
93
- message,
94
- state: "Skipped",
95
- };
96
- }
21
+ private activeBatch = false;
22
+ private rootMessageContents: any | undefined;
23
+ private processedCount = 0;
24
+
25
+ public processMessage(message: ISequencedDocumentMessage): IMessageProcessingResult {
26
+ assert(
27
+ message.compression === undefined || message.compression === CompressionAlgorithms.lz4,
28
+ 0x511 /* Only lz4 compression is supported */,
29
+ );
30
+
31
+ if (message.metadata?.batch === true && message.compression === CompressionAlgorithms.lz4) {
32
+ // Beginning of a compressed batch
33
+ assert(this.activeBatch === false, 0x4b8 /* shouldn't have multiple active batches */);
34
+ if (message.compression) {
35
+ // lz4 is the only supported compression algorithm for now
36
+ assert(
37
+ message.compression === CompressionAlgorithms.lz4,
38
+ 0x4b9 /* lz4 is currently the only supported compression algorithm */,
39
+ );
40
+ }
41
+
42
+ this.activeBatch = true;
43
+
44
+ const contents = IsoBuffer.from(message.contents.packedContents, "base64");
45
+ const decompressedMessage = decompress(contents);
46
+ const intoString = Uint8ArrayToString(decompressedMessage);
47
+ const asObj = JSON.parse(intoString);
48
+ this.rootMessageContents = asObj;
49
+
50
+ return {
51
+ message: newMessage(message, this.rootMessageContents[this.processedCount++]),
52
+ state: "Accepted",
53
+ };
54
+ }
55
+
56
+ if (
57
+ this.rootMessageContents !== undefined &&
58
+ message.metadata?.batch === undefined &&
59
+ this.activeBatch
60
+ ) {
61
+ assert(message.contents === undefined, 0x512 /* Expecting empty message */);
62
+
63
+ // Continuation of compressed batch
64
+ return {
65
+ message: newMessage(message, this.rootMessageContents[this.processedCount++]),
66
+ state: "Accepted",
67
+ };
68
+ }
69
+
70
+ if (this.rootMessageContents !== undefined && message.metadata?.batch === false) {
71
+ // End of compressed batch
72
+ const returnMessage = newMessage(
73
+ message,
74
+ this.rootMessageContents[this.processedCount++],
75
+ );
76
+
77
+ this.activeBatch = false;
78
+ this.rootMessageContents = undefined;
79
+ this.processedCount = 0;
80
+
81
+ return {
82
+ message: returnMessage,
83
+ state: "Processed",
84
+ };
85
+ }
86
+
87
+ if (
88
+ message.metadata?.batch === undefined &&
89
+ message.compression === CompressionAlgorithms.lz4
90
+ ) {
91
+ // Single compressed message
92
+ assert(
93
+ this.activeBatch === false,
94
+ 0x4ba /* shouldn't receive compressed message in middle of a batch */,
95
+ );
96
+
97
+ const contents = IsoBuffer.from(message.contents.packedContents, "base64");
98
+ const decompressedMessage = decompress(contents);
99
+ const intoString = new TextDecoder().decode(decompressedMessage);
100
+ const asObj = JSON.parse(intoString);
101
+
102
+ return {
103
+ message: newMessage(message, asObj[0]),
104
+ state: "Processed",
105
+ };
106
+ }
107
+
108
+ return {
109
+ message,
110
+ state: "Skipped",
111
+ };
112
+ }
97
113
  }
98
114
 
99
115
  // We should not be mutating the input message nor its metadata
100
- const newMessage = (originalMessage: ISequencedDocumentMessage, contents: any): ISequencedDocumentMessage => ({
101
- ...originalMessage,
102
- contents,
103
- compression: undefined,
104
- metadata: { ...originalMessage.metadata },
116
+ const newMessage = (
117
+ originalMessage: ISequencedDocumentMessage,
118
+ contents: any,
119
+ ): ISequencedDocumentMessage => ({
120
+ ...originalMessage,
121
+ contents,
122
+ compression: undefined,
123
+ metadata: { ...originalMessage.metadata },
105
124
  });
@@ -6,7 +6,10 @@
6
6
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
7
  import { assert } from "@fluidframework/common-utils";
8
8
  import { IBatchMessage } from "@fluidframework/container-definitions";
9
- import { DataCorruptionError, extractSafePropertiesFromMessage } from "@fluidframework/container-utils";
9
+ import {
10
+ DataCorruptionError,
11
+ extractSafePropertiesFromMessage,
12
+ } from "@fluidframework/container-utils";
10
13
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
11
14
  import { ChildLogger } from "@fluidframework/telemetry-utils";
12
15
  import { ContainerMessageType, ContainerRuntimeMessage } from "../containerRuntime";
@@ -16,197 +19,239 @@ import { BatchMessage, IBatch, IChunkedOp, IMessageProcessingResult } from "./de
16
19
  * Responsible for creating and reconstructing chunked messages.
17
20
  */
18
21
  export class OpSplitter {
19
- // Local copy of incomplete received chunks.
20
- private readonly chunkMap: Map<string, string[]>;
21
- private readonly logger;
22
-
23
- constructor(
24
- chunks: [string, string[]][],
25
- private readonly submitBatchFn: ((batch: IBatchMessage[]) => number) | undefined,
26
- private readonly chunkSizeInBytes: number,
27
- private readonly maxBatchSizeInBytes: number,
28
- logger: ITelemetryLogger,
29
- ) {
30
- this.chunkMap = new Map<string, string[]>(chunks);
31
- this.logger = ChildLogger.create(logger, "OpSplitter");
32
- }
33
-
34
- public get isBatchChunkingEnabled(): boolean {
35
- return this.chunkSizeInBytes < Number.POSITIVE_INFINITY && this.submitBatchFn !== undefined;
36
- }
37
-
38
- public get chunks(): ReadonlyMap<string, string[]> {
39
- return this.chunkMap;
40
- }
41
-
42
- public processRemoteMessage(message: ISequencedDocumentMessage): IMessageProcessingResult {
43
- if (message.type !== ContainerMessageType.ChunkedOp) {
44
- return {
45
- message,
46
- state: "Skipped",
47
- };
48
- }
49
-
50
- const clientId = message.clientId;
51
- const chunkedContent = message.contents as IChunkedOp;
52
- this.addChunk(clientId, chunkedContent, message);
53
-
54
- if (chunkedContent.chunkId < chunkedContent.totalChunks) {
55
- // We are processing the op in chunks but haven't reached
56
- // the last chunk yet in order to reconstruct the original op
57
- return {
58
- message,
59
- state: "Accepted",
60
- };
61
- }
62
-
63
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
64
- const serializedContent = this.chunkMap.get(clientId)!.join("");
65
- this.clearPartialChunks(clientId);
66
-
67
- const newMessage = { ...message };
68
- newMessage.contents = serializedContent === "" ? undefined : JSON.parse(serializedContent);
69
- newMessage.type = chunkedContent.originalType;
70
- newMessage.metadata = chunkedContent.originalMetadata;
71
- newMessage.compression = chunkedContent.originalCompression;
72
- return {
73
- message: newMessage,
74
- state: "Processed",
75
- };
76
- }
77
-
78
- public clearPartialChunks(clientId: string) {
79
- if (this.chunkMap.has(clientId)) {
80
- this.chunkMap.delete(clientId);
81
- }
82
- }
83
-
84
- private addChunk(clientId: string, chunkedContent: IChunkedOp, originalMessage: ISequencedDocumentMessage) {
85
- let map = this.chunkMap.get(clientId);
86
- if (map === undefined) {
87
- map = [];
88
- this.chunkMap.set(clientId, map);
89
- }
90
-
91
- if (chunkedContent.chunkId !== map.length + 1) {
92
- // We are expecting the chunks to be processed sequentially, in the same order as they are sent.
93
- // Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)
94
- // holding the existing chunks for that particular clientId.
95
- throw new DataCorruptionError("Chunk Id mismatch", {
96
- ...extractSafePropertiesFromMessage(originalMessage),
97
- chunkMapLength: map.length,
98
- chunkId: chunkedContent.chunkId,
99
- totalChunks: chunkedContent.totalChunks,
100
- });
101
- }
102
-
103
- map.push(chunkedContent.contents);
104
- }
105
-
106
- /**
107
- * Splits the first op of a compressed batch in chunks, sends the chunks separately and
108
- * returns a new batch composed of the last chunk and the rest of the ops in the original batch.
109
- *
110
- * A compressed batch is formed by one large op at the first position, followed by a series of placeholder ops
111
- * which are used in order to reserve the sequence numbers for when the first op gets unrolled into the original
112
- * uncompressed ops at ingestion in the runtime.
113
- *
114
- * If the first op is too large, it can be chunked (split into smaller op) which can be sent individually over the wire
115
- * and accumulate at ingestion, until the last op in the chunk is processed, when the original op is unrolled.
116
- *
117
- * This method will send the first N - 1 chunks separately and use the last chunk as the first message in the result batch
118
- * and then appends the original placeholder ops. This will ensure that the batch semantics of the original (non-compressed) batch
119
- * are preserved, as the original chunked op will be unrolled by the runtime when the first message in the batch is processed
120
- * (as it is the last chunk).
121
- *
122
- * To illustrate, if the input is `[largeOp, emptyOp, emptyOp]`, `largeOp` will be split into `[chunk1, chunk2, chunk3, chunk4]`.
123
- * `chunk1`, `chunk2` and `chunk3` will be sent individually and `[chunk4, emptyOp, emptyOp]` will be returned.
124
- *
125
- * @param batch - the compressed batch which needs to be processed
126
- * @returns A new adjusted batch which can be sent over the wire
127
- */
128
- public splitCompressedBatch(batch: IBatch): IBatch {
129
- assert(this.isBatchChunkingEnabled, 0x513 /* Chunking needs to be enabled */);
130
- assert(batch.contentSizeInBytes > 0 && batch.content.length > 0, 0x514 /* Batch needs to be non-empty */);
131
- assert(this.chunkSizeInBytes !== 0, 0x515 /* Chunk size needs to be non-zero */);
132
- assert(this.chunkSizeInBytes < this.maxBatchSizeInBytes, 0x516 /* Chunk size needs to be smaller than the max batch size */);
133
-
134
- const firstMessage = batch.content[0]; // we expect this to be the large compressed op, which needs to be split
135
- assert(firstMessage.metadata?.compressed === true || firstMessage.compression !== undefined, 0x517 /* Batch needs to be compressed */);
136
- assert((firstMessage.contents?.length ?? 0) >= this.chunkSizeInBytes, 0x518 /* First message in the batch needs to be chunkable */);
137
-
138
- const restOfMessages = batch.content.slice(1); // we expect these to be empty ops, created to reserve sequence numbers
139
- const chunks = splitOp(firstMessage, this.chunkSizeInBytes);
140
-
141
- assert(this.submitBatchFn !== undefined, 0x519 /* We don't support old loaders */);
142
- // Send the first N-1 chunks immediately
143
- for (const chunk of chunks.slice(0, -1)) {
144
- this.submitBatchFn([chunkToBatchMessage(chunk, firstMessage.referenceSequenceNumber)]);
145
- }
146
-
147
- // The last chunk will be part of the new batch and needs to
148
- // preserve the batch metadata of the original batch
149
- const lastChunk = chunkToBatchMessage(
150
- chunks[chunks.length - 1],
151
- firstMessage.referenceSequenceNumber,
152
- { batch: firstMessage.metadata?.batch });
153
-
154
- this.logger.sendPerformanceEvent({
155
- eventName: "Chunked compressed batch",
156
- length: batch.content.length,
157
- sizeInBytes: batch.contentSizeInBytes,
158
- chunks: chunks.length,
159
- chunkSizeInBytes: this.chunkSizeInBytes,
160
- });
161
-
162
- return {
163
- content: [lastChunk, ...restOfMessages],
164
- contentSizeInBytes: lastChunk.contents?.length ?? 0,
165
- };
166
- }
22
+ // Local copy of incomplete received chunks.
23
+ private readonly chunkMap: Map<string, string[]>;
24
+ private readonly logger;
25
+
26
+ constructor(
27
+ chunks: [string, string[]][],
28
+ private readonly submitBatchFn:
29
+ | ((batch: IBatchMessage[], referenceSequenceNumber?: number) => number)
30
+ | undefined,
31
+ private readonly chunkSizeInBytes: number,
32
+ private readonly maxBatchSizeInBytes: number,
33
+ logger: ITelemetryLogger,
34
+ ) {
35
+ this.chunkMap = new Map<string, string[]>(chunks);
36
+ this.logger = ChildLogger.create(logger, "OpSplitter");
37
+ }
38
+
39
+ public get isBatchChunkingEnabled(): boolean {
40
+ return this.chunkSizeInBytes < Number.POSITIVE_INFINITY && this.submitBatchFn !== undefined;
41
+ }
42
+
43
+ public get chunks(): ReadonlyMap<string, string[]> {
44
+ return this.chunkMap;
45
+ }
46
+
47
+ public processRemoteMessage(message: ISequencedDocumentMessage): IMessageProcessingResult {
48
+ if (message.type !== ContainerMessageType.ChunkedOp) {
49
+ return {
50
+ message,
51
+ state: "Skipped",
52
+ };
53
+ }
54
+
55
+ const clientId = message.clientId;
56
+ const chunkedContent = message.contents as IChunkedOp;
57
+ this.addChunk(clientId, chunkedContent, message);
58
+
59
+ if (chunkedContent.chunkId < chunkedContent.totalChunks) {
60
+ // We are processing the op in chunks but haven't reached
61
+ // the last chunk yet in order to reconstruct the original op
62
+ return {
63
+ message,
64
+ state: "Accepted",
65
+ };
66
+ }
67
+
68
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
69
+ const serializedContent = this.chunkMap.get(clientId)!.join("");
70
+ this.clearPartialChunks(clientId);
71
+
72
+ const newMessage = { ...message };
73
+ newMessage.contents = serializedContent === "" ? undefined : JSON.parse(serializedContent);
74
+ newMessage.type = chunkedContent.originalType;
75
+ newMessage.metadata = chunkedContent.originalMetadata;
76
+ newMessage.compression = chunkedContent.originalCompression;
77
+ return {
78
+ message: newMessage,
79
+ state: "Processed",
80
+ };
81
+ }
82
+
83
+ public clearPartialChunks(clientId: string) {
84
+ if (this.chunkMap.has(clientId)) {
85
+ this.chunkMap.delete(clientId);
86
+ }
87
+ }
88
+
89
+ private addChunk(
90
+ clientId: string,
91
+ chunkedContent: IChunkedOp,
92
+ originalMessage: ISequencedDocumentMessage,
93
+ ) {
94
+ let map = this.chunkMap.get(clientId);
95
+ if (map === undefined) {
96
+ map = [];
97
+ this.chunkMap.set(clientId, map);
98
+ }
99
+
100
+ if (chunkedContent.chunkId !== map.length + 1) {
101
+ // We are expecting the chunks to be processed sequentially, in the same order as they are sent.
102
+ // Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)
103
+ // holding the existing chunks for that particular clientId.
104
+ throw new DataCorruptionError("Chunk Id mismatch", {
105
+ ...extractSafePropertiesFromMessage(originalMessage),
106
+ chunkMapLength: map.length,
107
+ chunkId: chunkedContent.chunkId,
108
+ totalChunks: chunkedContent.totalChunks,
109
+ });
110
+ }
111
+
112
+ map.push(chunkedContent.contents);
113
+ }
114
+
115
+ /**
116
+ * Splits the first op of a compressed batch in chunks, sends the chunks separately and
117
+ * returns a new batch composed of the last chunk and the rest of the ops in the original batch.
118
+ *
119
+ * A compressed batch is formed by one large op at the first position, followed by a series of placeholder ops
120
+ * which are used in order to reserve the sequence numbers for when the first op gets unrolled into the original
121
+ * uncompressed ops at ingestion in the runtime.
122
+ *
123
+ * If the first op is too large, it can be chunked (split into smaller op) which can be sent individually over the wire
124
+ * and accumulate at ingestion, until the last op in the chunk is processed, when the original op is unrolled.
125
+ *
126
+ * This method will send the first N - 1 chunks separately and use the last chunk as the first message in the result batch
127
+ * and then appends the original placeholder ops. This will ensure that the batch semantics of the original (non-compressed) batch
128
+ * are preserved, as the original chunked op will be unrolled by the runtime when the first message in the batch is processed
129
+ * (as it is the last chunk).
130
+ *
131
+ * To illustrate, if the input is `[largeOp, emptyOp, emptyOp]`, `largeOp` will be split into `[chunk1, chunk2, chunk3, chunk4]`.
132
+ * `chunk1`, `chunk2` and `chunk3` will be sent individually and `[chunk4, emptyOp, emptyOp]` will be returned.
133
+ *
134
+ * @param batch - the compressed batch which needs to be processed
135
+ * @returns A new adjusted batch which can be sent over the wire
136
+ */
137
+ public splitCompressedBatch(batch: IBatch): IBatch {
138
+ assert(this.isBatchChunkingEnabled, 0x513 /* Chunking needs to be enabled */);
139
+ assert(
140
+ batch.contentSizeInBytes > 0 && batch.content.length > 0,
141
+ 0x514 /* Batch needs to be non-empty */,
142
+ );
143
+ assert(
144
+ batch.referenceSequenceNumber !== undefined,
145
+ 0x58a /* Batch must have a reference sequence number if non-empty */,
146
+ );
147
+ assert(this.chunkSizeInBytes !== 0, 0x515 /* Chunk size needs to be non-zero */);
148
+ assert(
149
+ this.chunkSizeInBytes < this.maxBatchSizeInBytes,
150
+ 0x516 /* Chunk size needs to be smaller than the max batch size */,
151
+ );
152
+
153
+ const firstMessage = batch.content[0]; // we expect this to be the large compressed op, which needs to be split
154
+ assert(
155
+ firstMessage.metadata?.compressed === true || firstMessage.compression !== undefined,
156
+ 0x517 /* Batch needs to be compressed */,
157
+ );
158
+ assert(
159
+ (firstMessage.contents?.length ?? 0) >= this.chunkSizeInBytes,
160
+ 0x518 /* First message in the batch needs to be chunkable */,
161
+ );
162
+
163
+ const restOfMessages = batch.content.slice(1); // we expect these to be empty ops, created to reserve sequence numbers
164
+ const chunks = splitOp(firstMessage, this.chunkSizeInBytes);
165
+
166
+ assert(this.submitBatchFn !== undefined, 0x519 /* We don't support old loaders */);
167
+ // Send the first N-1 chunks immediately
168
+ for (const chunk of chunks.slice(0, -1)) {
169
+ this.submitBatchFn(
170
+ [chunkToBatchMessage(chunk, batch.referenceSequenceNumber)],
171
+ batch.referenceSequenceNumber,
172
+ );
173
+ }
174
+
175
+ // The last chunk will be part of the new batch and needs to
176
+ // preserve the batch metadata of the original batch
177
+ const lastChunk = chunkToBatchMessage(
178
+ chunks[chunks.length - 1],
179
+ batch.referenceSequenceNumber,
180
+ { batch: firstMessage.metadata?.batch },
181
+ );
182
+
183
+ this.logger.sendPerformanceEvent({
184
+ eventName: "Chunked compressed batch",
185
+ length: batch.content.length,
186
+ sizeInBytes: batch.contentSizeInBytes,
187
+ chunks: chunks.length,
188
+ chunkSizeInBytes: this.chunkSizeInBytes,
189
+ });
190
+
191
+ return {
192
+ content: [lastChunk, ...restOfMessages],
193
+ contentSizeInBytes: lastChunk.contents?.length ?? 0,
194
+ referenceSequenceNumber: batch.referenceSequenceNumber,
195
+ };
196
+ }
167
197
  }
168
198
 
169
199
  const chunkToBatchMessage = (
170
- chunk: IChunkedOp,
171
- referenceSequenceNumber: number,
172
- metadata: Record<string, unknown> | undefined = undefined,
200
+ chunk: IChunkedOp,
201
+ referenceSequenceNumber: number,
202
+ metadata: Record<string, unknown> | undefined = undefined,
173
203
  ): BatchMessage => {
174
- const payload: ContainerRuntimeMessage = { type: ContainerMessageType.ChunkedOp, contents: chunk };
175
- return {
176
- contents: JSON.stringify(payload),
177
- deserializedContent: payload,
178
- metadata,
179
- localOpMetadata: undefined,
180
- referenceSequenceNumber,
181
- };
182
- }
204
+ const payload: ContainerRuntimeMessage = {
205
+ type: ContainerMessageType.ChunkedOp,
206
+ contents: chunk,
207
+ };
208
+ return {
209
+ contents: JSON.stringify(payload),
210
+ deserializedContent: payload,
211
+ metadata,
212
+ localOpMetadata: undefined,
213
+ referenceSequenceNumber,
214
+ };
215
+ };
183
216
 
184
217
  export const splitOp = (op: BatchMessage, chunkSizeInBytes: number): IChunkedOp[] => {
185
- const chunks: IChunkedOp[] = [];
186
- assert(op.contents !== undefined && op.contents !== null, 0x51a /* We should have something to chunk */);
187
-
188
- const contentLength = op.contents.length;
189
- const chunkN = Math.floor((contentLength - 1) / chunkSizeInBytes) + 1;
190
- let offset = 0;
191
- for (let i = 1; i <= chunkN; i++) {
192
- const chunk: IChunkedOp = {
193
- chunkId: i,
194
- contents: op.contents.substr(offset, chunkSizeInBytes),
195
- originalType: op.deserializedContent.type,
196
- totalChunks: chunkN,
197
- }
198
-
199
- if (i === chunkN) {
200
- // We don't need to port these to all the chunks,
201
- // as we rebuild the original op when we process the
202
- // last chunk, therefore it is the only one that needs it.
203
- chunk.originalMetadata = op.metadata;
204
- chunk.originalCompression = op.compression;
205
- }
206
-
207
- chunks.push(chunk);
208
- offset += chunkSizeInBytes;
209
- }
210
-
211
- return chunks;
218
+ const chunks: IChunkedOp[] = [];
219
+ assert(
220
+ op.contents !== undefined && op.contents !== null,
221
+ 0x51a /* We should have something to chunk */,
222
+ );
223
+
224
+ const contentLength = op.contents.length;
225
+ const chunkCount = Math.floor((contentLength - 1) / chunkSizeInBytes) + 2;
226
+ let offset = 0;
227
+ for (let i = 1; i < chunkCount; i++) {
228
+ const chunk: IChunkedOp = {
229
+ chunkId: i,
230
+ contents: op.contents.substr(offset, chunkSizeInBytes),
231
+ originalType: op.deserializedContent.type,
232
+ totalChunks: chunkCount,
233
+ };
234
+
235
+ chunks.push(chunk);
236
+ offset += chunkSizeInBytes;
237
+ assert(
238
+ i === chunkCount - 1 || offset <= contentLength,
239
+ 0x58b /* Content offset within bounds */,
240
+ );
241
+ }
242
+
243
+ assert(offset >= contentLength, 0x58c /* Content offset equal or larger than content length */);
244
+ // The last chunk has empty contents, to minimize the risk of the
245
+ // resulting payload exceeding 1MB due to the overhead from the empty ops
246
+ // which will be bundled with this op.
247
+ chunks.push({
248
+ chunkId: chunkCount,
249
+ contents: "",
250
+ originalType: op.deserializedContent.type,
251
+ totalChunks: chunkCount,
252
+ originalMetadata: op.metadata,
253
+ originalCompression: op.compression,
254
+ });
255
+
256
+ return chunks;
212
257
  };