@fluidframework/container-runtime 2.0.0-dev-rc.2.0.0.246488 → 2.0.0-dev-rc.3.0.0.250606

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 (456) hide show
  1. package/api-report/container-runtime.api.md +78 -25
  2. package/dist/batchTracker.d.ts +1 -1
  3. package/dist/batchTracker.d.ts.map +1 -1
  4. package/dist/batchTracker.js +2 -2
  5. package/dist/batchTracker.js.map +1 -1
  6. package/dist/blobManager.d.ts +3 -3
  7. package/dist/blobManager.d.ts.map +1 -1
  8. package/dist/blobManager.js +3 -3
  9. package/dist/blobManager.js.map +1 -1
  10. package/dist/channelCollection.d.ts +5 -5
  11. package/dist/channelCollection.d.ts.map +1 -1
  12. package/dist/channelCollection.js +44 -11
  13. package/dist/channelCollection.js.map +1 -1
  14. package/dist/connectionTelemetry.d.ts +2 -2
  15. package/dist/connectionTelemetry.d.ts.map +1 -1
  16. package/dist/connectionTelemetry.js +3 -3
  17. package/dist/connectionTelemetry.js.map +1 -1
  18. package/dist/container-runtime-alpha.d.ts +205 -11
  19. package/dist/container-runtime-beta.d.ts +16 -2
  20. package/dist/container-runtime-public.d.ts +16 -2
  21. package/dist/container-runtime-untrimmed.d.ts +205 -24
  22. package/dist/containerHandleContext.d.ts.map +1 -1
  23. package/dist/containerHandleContext.js.map +1 -1
  24. package/dist/containerRuntime.d.ts +32 -26
  25. package/dist/containerRuntime.d.ts.map +1 -1
  26. package/dist/containerRuntime.js +213 -119
  27. package/dist/containerRuntime.js.map +1 -1
  28. package/dist/dataStore.d.ts +1 -1
  29. package/dist/dataStore.d.ts.map +1 -1
  30. package/dist/dataStore.js +2 -2
  31. package/dist/dataStore.js.map +1 -1
  32. package/dist/dataStoreContext.d.ts +4 -4
  33. package/dist/dataStoreContext.d.ts.map +1 -1
  34. package/dist/dataStoreContext.js +18 -18
  35. package/dist/dataStoreContext.js.map +1 -1
  36. package/dist/dataStoreContexts.d.ts.map +1 -1
  37. package/dist/dataStoreContexts.js.map +1 -1
  38. package/dist/dataStoreRegistry.d.ts.map +1 -1
  39. package/dist/dataStoreRegistry.js.map +1 -1
  40. package/dist/deltaScheduler.d.ts +1 -1
  41. package/dist/deltaScheduler.d.ts.map +1 -1
  42. package/dist/deltaScheduler.js +1 -1
  43. package/dist/deltaScheduler.js.map +1 -1
  44. package/dist/gc/garbageCollection.d.ts +1 -1
  45. package/dist/gc/garbageCollection.d.ts.map +1 -1
  46. package/dist/gc/garbageCollection.js +1 -1
  47. package/dist/gc/garbageCollection.js.map +1 -1
  48. package/dist/gc/gcConfigs.d.ts +1 -1
  49. package/dist/gc/gcConfigs.d.ts.map +1 -1
  50. package/dist/gc/gcConfigs.js.map +1 -1
  51. package/dist/gc/gcDefinitions.d.ts +1 -1
  52. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  53. package/dist/gc/gcDefinitions.js.map +1 -1
  54. package/dist/gc/gcHelpers.d.ts.map +1 -1
  55. package/dist/gc/gcHelpers.js.map +1 -1
  56. package/dist/gc/gcSummaryStateTracker.d.ts +1 -1
  57. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  58. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  59. package/dist/gc/gcTelemetry.d.ts +1 -1
  60. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  61. package/dist/gc/gcTelemetry.js.map +1 -1
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js +4 -2
  65. package/dist/index.js.map +1 -1
  66. package/dist/messageTypes.d.ts +11 -5
  67. package/dist/messageTypes.d.ts.map +1 -1
  68. package/dist/messageTypes.js +4 -0
  69. package/dist/messageTypes.js.map +1 -1
  70. package/dist/opLifecycle/definitions.d.ts +1 -19
  71. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  72. package/dist/opLifecycle/definitions.js.map +1 -1
  73. package/dist/opLifecycle/index.d.ts +3 -3
  74. package/dist/opLifecycle/index.d.ts.map +1 -1
  75. package/dist/opLifecycle/index.js +3 -1
  76. package/dist/opLifecycle/index.js.map +1 -1
  77. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  78. package/dist/opLifecycle/opCompressor.js +2 -3
  79. package/dist/opLifecycle/opCompressor.js.map +1 -1
  80. package/dist/opLifecycle/opDecompressor.d.ts +15 -4
  81. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  82. package/dist/opLifecycle/opDecompressor.js +60 -61
  83. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  84. package/dist/opLifecycle/opGroupingManager.d.ts +2 -1
  85. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  86. package/dist/opLifecycle/opGroupingManager.js +9 -11
  87. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  88. package/dist/opLifecycle/opSplitter.d.ts +11 -3
  89. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  90. package/dist/opLifecycle/opSplitter.js +48 -38
  91. package/dist/opLifecycle/opSplitter.js.map +1 -1
  92. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  93. package/dist/opLifecycle/outbox.js +7 -12
  94. package/dist/opLifecycle/outbox.js.map +1 -1
  95. package/dist/opLifecycle/remoteMessageProcessor.d.ts +8 -0
  96. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  97. package/dist/opLifecycle/remoteMessageProcessor.js +36 -35
  98. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  99. package/dist/packageVersion.d.ts +1 -1
  100. package/dist/packageVersion.js +1 -1
  101. package/dist/packageVersion.js.map +1 -1
  102. package/dist/pendingStateManager.d.ts +1 -1
  103. package/dist/pendingStateManager.d.ts.map +1 -1
  104. package/dist/pendingStateManager.js.map +1 -1
  105. package/dist/scheduleManager.d.ts +1 -1
  106. package/dist/scheduleManager.d.ts.map +1 -1
  107. package/dist/scheduleManager.js +2 -2
  108. package/dist/scheduleManager.js.map +1 -1
  109. package/dist/summary/documentSchema.d.ts +178 -0
  110. package/dist/summary/documentSchema.d.ts.map +1 -0
  111. package/dist/summary/documentSchema.js +345 -0
  112. package/dist/summary/documentSchema.js.map +1 -0
  113. package/dist/summary/index.d.ts +2 -1
  114. package/dist/summary/index.d.ts.map +1 -1
  115. package/dist/summary/index.js +4 -1
  116. package/dist/summary/index.js.map +1 -1
  117. package/dist/summary/orderedClientElection.d.ts +2 -2
  118. package/dist/summary/orderedClientElection.d.ts.map +1 -1
  119. package/dist/summary/orderedClientElection.js +3 -2
  120. package/dist/summary/orderedClientElection.js.map +1 -1
  121. package/dist/summary/runWhileConnectedCoordinator.d.ts +1 -1
  122. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -1
  123. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
  124. package/dist/summary/runningSummarizer.d.ts +2 -2
  125. package/dist/summary/runningSummarizer.d.ts.map +1 -1
  126. package/dist/summary/runningSummarizer.js +2 -2
  127. package/dist/summary/runningSummarizer.js.map +1 -1
  128. package/dist/summary/summarizer.d.ts +2 -2
  129. package/dist/summary/summarizer.d.ts.map +1 -1
  130. package/dist/summary/summarizer.js +2 -2
  131. package/dist/summary/summarizer.js.map +1 -1
  132. package/dist/summary/summarizerClientElection.d.ts +2 -2
  133. package/dist/summary/summarizerClientElection.d.ts.map +1 -1
  134. package/dist/summary/summarizerClientElection.js.map +1 -1
  135. package/dist/summary/summarizerHeuristics.d.ts +1 -1
  136. package/dist/summary/summarizerHeuristics.d.ts.map +1 -1
  137. package/dist/summary/summarizerHeuristics.js.map +1 -1
  138. package/dist/summary/summarizerNode/summarizerNode.d.ts +2 -2
  139. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  140. package/dist/summary/summarizerNode/summarizerNode.js +3 -3
  141. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  142. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +1 -1
  143. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  144. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  145. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +1 -1
  146. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  147. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +1 -1
  148. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  149. package/dist/summary/summarizerTypes.d.ts +3 -3
  150. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  151. package/dist/summary/summarizerTypes.js.map +1 -1
  152. package/dist/summary/summaryCollection.d.ts +2 -2
  153. package/dist/summary/summaryCollection.d.ts.map +1 -1
  154. package/dist/summary/summaryCollection.js +1 -1
  155. package/dist/summary/summaryCollection.js.map +1 -1
  156. package/dist/summary/summaryFormat.d.ts +5 -16
  157. package/dist/summary/summaryFormat.d.ts.map +1 -1
  158. package/dist/summary/summaryFormat.js.map +1 -1
  159. package/dist/summary/summaryGenerator.d.ts +2 -2
  160. package/dist/summary/summaryGenerator.d.ts.map +1 -1
  161. package/dist/summary/summaryGenerator.js +2 -2
  162. package/dist/summary/summaryGenerator.js.map +1 -1
  163. package/dist/summary/summaryManager.d.ts +1 -1
  164. package/dist/summary/summaryManager.d.ts.map +1 -1
  165. package/dist/summary/summaryManager.js +2 -2
  166. package/dist/summary/summaryManager.js.map +1 -1
  167. package/lib/batchTracker.d.ts +1 -1
  168. package/lib/batchTracker.d.ts.map +1 -1
  169. package/lib/batchTracker.js +2 -2
  170. package/lib/batchTracker.js.map +1 -1
  171. package/lib/blobManager.d.ts +3 -3
  172. package/lib/blobManager.d.ts.map +1 -1
  173. package/lib/blobManager.js +5 -5
  174. package/lib/blobManager.js.map +1 -1
  175. package/lib/channelCollection.d.ts +5 -5
  176. package/lib/channelCollection.d.ts.map +1 -1
  177. package/lib/channelCollection.js +46 -13
  178. package/lib/channelCollection.js.map +1 -1
  179. package/lib/connectionTelemetry.d.ts +2 -2
  180. package/lib/connectionTelemetry.d.ts.map +1 -1
  181. package/lib/connectionTelemetry.js +3 -3
  182. package/lib/connectionTelemetry.js.map +1 -1
  183. package/lib/container-runtime-alpha.d.ts +205 -11
  184. package/lib/container-runtime-beta.d.ts +16 -2
  185. package/lib/container-runtime-public.d.ts +16 -2
  186. package/lib/container-runtime-untrimmed.d.ts +205 -24
  187. package/lib/containerHandleContext.d.ts.map +1 -1
  188. package/lib/containerHandleContext.js.map +1 -1
  189. package/lib/containerRuntime.d.ts +32 -26
  190. package/lib/containerRuntime.d.ts.map +1 -1
  191. package/lib/containerRuntime.js +175 -81
  192. package/lib/containerRuntime.js.map +1 -1
  193. package/lib/dataStore.d.ts +1 -1
  194. package/lib/dataStore.d.ts.map +1 -1
  195. package/lib/dataStore.js +2 -2
  196. package/lib/dataStore.js.map +1 -1
  197. package/lib/dataStoreContext.d.ts +4 -4
  198. package/lib/dataStoreContext.d.ts.map +1 -1
  199. package/lib/dataStoreContext.js +3 -3
  200. package/lib/dataStoreContext.js.map +1 -1
  201. package/lib/dataStoreContexts.d.ts.map +1 -1
  202. package/lib/dataStoreContexts.js.map +1 -1
  203. package/lib/dataStoreRegistry.d.ts.map +1 -1
  204. package/lib/dataStoreRegistry.js.map +1 -1
  205. package/lib/deltaScheduler.d.ts +1 -1
  206. package/lib/deltaScheduler.d.ts.map +1 -1
  207. package/lib/deltaScheduler.js +1 -1
  208. package/lib/deltaScheduler.js.map +1 -1
  209. package/lib/gc/garbageCollection.d.ts +1 -1
  210. package/lib/gc/garbageCollection.d.ts.map +1 -1
  211. package/lib/gc/garbageCollection.js +3 -3
  212. package/lib/gc/garbageCollection.js.map +1 -1
  213. package/lib/gc/gcConfigs.d.ts +1 -1
  214. package/lib/gc/gcConfigs.d.ts.map +1 -1
  215. package/lib/gc/gcConfigs.js +1 -1
  216. package/lib/gc/gcConfigs.js.map +1 -1
  217. package/lib/gc/gcDefinitions.d.ts +1 -1
  218. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  219. package/lib/gc/gcDefinitions.js.map +1 -1
  220. package/lib/gc/gcHelpers.d.ts.map +1 -1
  221. package/lib/gc/gcHelpers.js.map +1 -1
  222. package/lib/gc/gcSummaryStateTracker.d.ts +1 -1
  223. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  224. package/lib/gc/gcSummaryStateTracker.js +1 -1
  225. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  226. package/lib/gc/gcTelemetry.d.ts +1 -1
  227. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  228. package/lib/gc/gcTelemetry.js +1 -1
  229. package/lib/gc/gcTelemetry.js.map +1 -1
  230. package/lib/index.d.ts +2 -2
  231. package/lib/index.d.ts.map +1 -1
  232. package/lib/index.js +2 -2
  233. package/lib/index.js.map +1 -1
  234. package/lib/messageTypes.d.ts +11 -5
  235. package/lib/messageTypes.d.ts.map +1 -1
  236. package/lib/messageTypes.js +4 -0
  237. package/lib/messageTypes.js.map +1 -1
  238. package/lib/opLifecycle/definitions.d.ts +1 -19
  239. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  240. package/lib/opLifecycle/definitions.js.map +1 -1
  241. package/lib/opLifecycle/index.d.ts +3 -3
  242. package/lib/opLifecycle/index.d.ts.map +1 -1
  243. package/lib/opLifecycle/index.js +2 -2
  244. package/lib/opLifecycle/index.js.map +1 -1
  245. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  246. package/lib/opLifecycle/opCompressor.js +2 -3
  247. package/lib/opLifecycle/opCompressor.js.map +1 -1
  248. package/lib/opLifecycle/opDecompressor.d.ts +15 -4
  249. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  250. package/lib/opLifecycle/opDecompressor.js +60 -61
  251. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  252. package/lib/opLifecycle/opGroupingManager.d.ts +2 -1
  253. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  254. package/lib/opLifecycle/opGroupingManager.js +7 -10
  255. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  256. package/lib/opLifecycle/opSplitter.d.ts +11 -3
  257. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  258. package/lib/opLifecycle/opSplitter.js +46 -37
  259. package/lib/opLifecycle/opSplitter.js.map +1 -1
  260. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  261. package/lib/opLifecycle/outbox.js +7 -12
  262. package/lib/opLifecycle/outbox.js.map +1 -1
  263. package/lib/opLifecycle/remoteMessageProcessor.d.ts +8 -0
  264. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  265. package/lib/opLifecycle/remoteMessageProcessor.js +36 -35
  266. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  267. package/lib/packageVersion.d.ts +1 -1
  268. package/lib/packageVersion.js +1 -1
  269. package/lib/packageVersion.js.map +1 -1
  270. package/lib/pendingStateManager.d.ts +1 -1
  271. package/lib/pendingStateManager.d.ts.map +1 -1
  272. package/lib/pendingStateManager.js.map +1 -1
  273. package/lib/scheduleManager.d.ts +1 -1
  274. package/lib/scheduleManager.d.ts.map +1 -1
  275. package/lib/scheduleManager.js +2 -2
  276. package/lib/scheduleManager.js.map +1 -1
  277. package/lib/summary/documentSchema.d.ts +178 -0
  278. package/lib/summary/documentSchema.d.ts.map +1 -0
  279. package/lib/summary/documentSchema.js +341 -0
  280. package/lib/summary/documentSchema.js.map +1 -0
  281. package/lib/summary/index.d.ts +2 -1
  282. package/lib/summary/index.d.ts.map +1 -1
  283. package/lib/summary/index.js +1 -0
  284. package/lib/summary/index.js.map +1 -1
  285. package/lib/summary/orderedClientElection.d.ts +2 -2
  286. package/lib/summary/orderedClientElection.d.ts.map +1 -1
  287. package/lib/summary/orderedClientElection.js +3 -2
  288. package/lib/summary/orderedClientElection.js.map +1 -1
  289. package/lib/summary/runWhileConnectedCoordinator.d.ts +1 -1
  290. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -1
  291. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
  292. package/lib/summary/runningSummarizer.d.ts +2 -2
  293. package/lib/summary/runningSummarizer.d.ts.map +1 -1
  294. package/lib/summary/runningSummarizer.js +3 -3
  295. package/lib/summary/runningSummarizer.js.map +1 -1
  296. package/lib/summary/summarizer.d.ts +2 -2
  297. package/lib/summary/summarizer.d.ts.map +1 -1
  298. package/lib/summary/summarizer.js +3 -3
  299. package/lib/summary/summarizer.js.map +1 -1
  300. package/lib/summary/summarizerClientElection.d.ts +2 -2
  301. package/lib/summary/summarizerClientElection.d.ts.map +1 -1
  302. package/lib/summary/summarizerClientElection.js.map +1 -1
  303. package/lib/summary/summarizerHeuristics.d.ts +1 -1
  304. package/lib/summary/summarizerHeuristics.d.ts.map +1 -1
  305. package/lib/summary/summarizerHeuristics.js.map +1 -1
  306. package/lib/summary/summarizerNode/summarizerNode.d.ts +2 -2
  307. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  308. package/lib/summary/summarizerNode/summarizerNode.js +4 -4
  309. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  310. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +1 -1
  311. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  312. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  313. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +1 -1
  314. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  315. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +1 -1
  316. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  317. package/lib/summary/summarizerTypes.d.ts +3 -3
  318. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  319. package/lib/summary/summarizerTypes.js.map +1 -1
  320. package/lib/summary/summaryCollection.d.ts +2 -2
  321. package/lib/summary/summaryCollection.d.ts.map +1 -1
  322. package/lib/summary/summaryCollection.js +1 -1
  323. package/lib/summary/summaryCollection.js.map +1 -1
  324. package/lib/summary/summaryFormat.d.ts +5 -16
  325. package/lib/summary/summaryFormat.d.ts.map +1 -1
  326. package/lib/summary/summaryFormat.js +1 -1
  327. package/lib/summary/summaryFormat.js.map +1 -1
  328. package/lib/summary/summaryGenerator.d.ts +2 -2
  329. package/lib/summary/summaryGenerator.d.ts.map +1 -1
  330. package/lib/summary/summaryGenerator.js +3 -3
  331. package/lib/summary/summaryGenerator.js.map +1 -1
  332. package/lib/summary/summaryManager.d.ts +1 -1
  333. package/lib/summary/summaryManager.d.ts.map +1 -1
  334. package/lib/summary/summaryManager.js +2 -2
  335. package/lib/summary/summaryManager.js.map +1 -1
  336. package/lib/test/blobManager.spec.js +3 -3
  337. package/lib/test/blobManager.spec.js.map +1 -1
  338. package/lib/test/containerRuntime.spec.js +6 -4
  339. package/lib/test/containerRuntime.spec.js.map +1 -1
  340. package/lib/test/dataStoreContext.spec.js +4 -4
  341. package/lib/test/dataStoreContext.spec.js.map +1 -1
  342. package/lib/test/dataStoreCreation.spec.js +1 -1
  343. package/lib/test/dataStoreCreation.spec.js.map +1 -1
  344. package/lib/test/dataStoreRegistry.spec.js.map +1 -1
  345. package/lib/test/documentSchema.spec.js +282 -0
  346. package/lib/test/documentSchema.spec.js.map +1 -0
  347. package/lib/test/fuzz/fuzzUtils.js +11 -7
  348. package/lib/test/fuzz/fuzzUtils.js.map +1 -1
  349. package/lib/test/fuzz/summarizer.fuzz.spec.js +9 -7
  350. package/lib/test/fuzz/summarizer.fuzz.spec.js.map +1 -1
  351. package/lib/test/fuzz/summarizerFuzzMocks.js +43 -25
  352. package/lib/test/fuzz/summarizerFuzzMocks.js.map +1 -1
  353. package/lib/test/fuzz/summarizerFuzzSuite.js +7 -4
  354. package/lib/test/fuzz/summarizerFuzzSuite.js.map +1 -1
  355. package/lib/test/gc/garbageCollection.spec.js +5 -5
  356. package/lib/test/gc/garbageCollection.spec.js.map +1 -1
  357. package/lib/test/gc/gcConfigs.spec.js +2 -2
  358. package/lib/test/gc/gcConfigs.spec.js.map +1 -1
  359. package/lib/test/gc/gcHelpers.spec.js.map +1 -1
  360. package/lib/test/gc/gcStats.spec.js +2 -2
  361. package/lib/test/gc/gcStats.spec.js.map +1 -1
  362. package/lib/test/gc/gcSummaryStateTracker.spec.js +1 -1
  363. package/lib/test/gc/gcSummaryStateTracker.spec.js.map +1 -1
  364. package/lib/test/gc/gcTelemetry.spec.js +3 -3
  365. package/lib/test/gc/gcTelemetry.spec.js.map +1 -1
  366. package/lib/test/gc/gcUnreferencedStateTracker.spec.js +1 -1
  367. package/lib/test/gc/gcUnreferencedStateTracker.spec.js.map +1 -1
  368. package/lib/test/getPendingBlobs.spec.js +1 -1
  369. package/lib/test/getPendingBlobs.spec.js.map +1 -1
  370. package/lib/test/hardwareStats.spec.js +1 -1
  371. package/lib/test/hardwareStats.spec.js.map +1 -1
  372. package/lib/test/opLifecycle/OpGroupingManager.spec.js +95 -118
  373. package/lib/test/opLifecycle/OpGroupingManager.spec.js.map +1 -1
  374. package/lib/test/opLifecycle/batchManager.spec.js +1 -1
  375. package/lib/test/opLifecycle/batchManager.spec.js.map +1 -1
  376. package/lib/test/opLifecycle/opCompressor.spec.js +0 -1
  377. package/lib/test/opLifecycle/opCompressor.spec.js.map +1 -1
  378. package/lib/test/opLifecycle/opDecompressor.spec.js +60 -55
  379. package/lib/test/opLifecycle/opDecompressor.spec.js.map +1 -1
  380. package/lib/test/opLifecycle/opSplitter.spec.js +56 -41
  381. package/lib/test/opLifecycle/opSplitter.spec.js.map +1 -1
  382. package/lib/test/opLifecycle/outbox.spec.js +118 -10
  383. package/lib/test/opLifecycle/outbox.spec.js.map +1 -1
  384. package/lib/test/opLifecycle/remoteMessageProcessor.spec.js +115 -91
  385. package/lib/test/opLifecycle/remoteMessageProcessor.spec.js.map +1 -1
  386. package/lib/test/pendingStateManager.spec.js +1 -1
  387. package/lib/test/pendingStateManager.spec.js.map +1 -1
  388. package/lib/test/scheduleManager.spec.js +1 -1
  389. package/lib/test/scheduleManager.spec.js.map +1 -1
  390. package/lib/test/summarizerNode.spec.js +1 -1
  391. package/lib/test/summarizerNode.spec.js.map +1 -1
  392. package/lib/test/summarizerNodeWithGc.spec.js +1 -1
  393. package/lib/test/summarizerNodeWithGc.spec.js.map +1 -1
  394. package/lib/test/summary/runningSummarizer.spec.js +4 -4
  395. package/lib/test/summary/runningSummarizer.spec.js.map +1 -1
  396. package/lib/test/summary/summarizer.spec.js.map +1 -1
  397. package/lib/test/summary/summarizerClientElection.spec.js +2 -2
  398. package/lib/test/summary/summarizerClientElection.spec.js.map +1 -1
  399. package/lib/test/summary/summarizerHeuristics.spec.js +1 -1
  400. package/lib/test/summary/summarizerHeuristics.spec.js.map +1 -1
  401. package/lib/test/summary/summaryCollection.spec.js +1 -1
  402. package/lib/test/summary/summaryCollection.spec.js.map +1 -1
  403. package/lib/test/summary/summaryManager.spec.js +3 -3
  404. package/lib/test/summary/summaryManager.spec.js.map +1 -1
  405. package/lib/test/throttler.spec.js +1 -1
  406. package/lib/test/throttler.spec.js.map +1 -1
  407. package/lib/test/types/validateContainerRuntimePrevious.generated.js +6 -4
  408. package/lib/test/types/validateContainerRuntimePrevious.generated.js.map +1 -1
  409. package/package.json +35 -21
  410. package/src/batchTracker.ts +3 -3
  411. package/src/blobManager.ts +15 -15
  412. package/src/channelCollection.ts +75 -35
  413. package/src/connectionTelemetry.ts +10 -10
  414. package/src/containerHandleContext.ts +1 -1
  415. package/src/containerRuntime.ts +352 -197
  416. package/src/dataStore.ts +2 -2
  417. package/src/dataStoreContext.ts +19 -19
  418. package/src/dataStoreContexts.ts +2 -2
  419. package/src/dataStoreRegistry.ts +1 -1
  420. package/src/deltaScheduler.ts +1 -1
  421. package/src/gc/garbageCollection.ts +12 -12
  422. package/src/gc/gcConfigs.ts +11 -11
  423. package/src/gc/gcDefinitions.ts +2 -2
  424. package/src/gc/gcHelpers.ts +2 -2
  425. package/src/gc/gcSummaryStateTracker.ts +4 -4
  426. package/src/gc/gcTelemetry.ts +6 -6
  427. package/src/index.ts +8 -1
  428. package/src/messageTypes.ts +18 -5
  429. package/src/opLifecycle/README.md +89 -0
  430. package/src/opLifecycle/definitions.ts +1 -20
  431. package/src/opLifecycle/index.ts +3 -9
  432. package/src/opLifecycle/opCompressor.ts +4 -5
  433. package/src/opLifecycle/opDecompressor.ts +83 -100
  434. package/src/opLifecycle/opGroupingManager.ts +9 -12
  435. package/src/opLifecycle/opSplitter.ts +73 -47
  436. package/src/opLifecycle/outbox.ts +13 -31
  437. package/src/opLifecycle/remoteMessageProcessor.ts +41 -59
  438. package/src/packageVersion.ts +1 -1
  439. package/src/pendingStateManager.ts +2 -2
  440. package/src/scheduleManager.ts +7 -7
  441. package/src/summary/documentSchema.ts +553 -0
  442. package/src/summary/index.ts +10 -1
  443. package/src/summary/orderedClientElection.ts +6 -5
  444. package/src/summary/runWhileConnectedCoordinator.ts +1 -1
  445. package/src/summary/runningSummarizer.ts +19 -19
  446. package/src/summary/summarizer.ts +14 -14
  447. package/src/summary/summarizerClientElection.ts +2 -2
  448. package/src/summary/summarizerHeuristics.ts +2 -2
  449. package/src/summary/summarizerNode/summarizerNode.ts +15 -15
  450. package/src/summary/summarizerNode/summarizerNodeUtils.ts +1 -1
  451. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +4 -4
  452. package/src/summary/summarizerTypes.ts +3 -3
  453. package/src/summary/summaryCollection.ts +3 -3
  454. package/src/summary/summaryFormat.ts +8 -19
  455. package/src/summary/summaryGenerator.ts +10 -10
  456. package/src/summary/summaryManager.ts +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"scheduleManager.js","sourceRoot":"","sources":["../src/scheduleManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,gCAAgC,GAEhC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,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F,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tcreateChildLogger,\n\tDataCorruptionError,\n\tDataProcessingError,\n\textractSafePropertiesFromMessage,\n\tITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport type { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport { DeltaScheduler } from \"./deltaScheduler.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\nimport { IBatchMetadata } from \"./metadata.js\";\n\ntype IRuntimeMessageMetadata =\n\t| undefined\n\t| {\n\t\t\tbatch?: boolean;\n\t };\n\n/**\n * This class has the following responsibilities:\n *\n * 1. It tracks batches as we process ops and raises \"batchBegin\" and \"batchEnd\" events.\n * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)\n *\n * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch\n * unless all ops of the batch are in.\n */\nexport class ScheduleManager {\n\tprivate readonly deltaScheduler: DeltaScheduler;\n\tprivate batchClientId: string | undefined;\n\tprivate hitError = false;\n\n\tconstructor(\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tprivate readonly emitter: EventEmitter,\n\t\treadonly getClientId: () => string | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.deltaScheduler = new DeltaScheduler(\n\t\t\tthis.deltaManager,\n\t\t\tcreateChildLogger({ logger: this.logger, namespace: \"DeltaScheduler\" }),\n\t\t);\n\t\tvoid new ScheduleManagerCore(deltaManager, getClientId, logger);\n\t}\n\n\tpublic beforeOpProcessing(message: ISequencedDocumentMessage) {\n\t\tif (this.batchClientId !== message.clientId) {\n\t\t\tassert(\n\t\t\t\tthis.batchClientId === undefined,\n\t\t\t\t0x2a2 /* \"Batch is interrupted by other client op. Should be caught by trackPending()\" */,\n\t\t\t);\n\n\t\t\t// This could be the beginning of a new batch or an individual message.\n\t\t\tthis.emitter.emit(\"batchBegin\", message);\n\t\t\tthis.deltaScheduler.batchBegin(message);\n\n\t\t\tconst batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tthis.batchClientId = batch ? (message.clientId as string) : undefined;\n\t\t}\n\t}\n\n\tpublic afterOpProcessing(error: any | undefined, message: ISequencedDocumentMessage) {\n\t\t// If this is no longer true, we need to revisit what we do where we set this.hitError.\n\t\tassert(!this.hitError, 0x2a3 /* \"container should be closed on any error\" */);\n\n\t\tif (error) {\n\t\t\t// We assume here that loader will close container and stop processing all future ops.\n\t\t\t// This is implicit dependency. If this flow changes, this code might no longer be correct.\n\t\t\tthis.hitError = true;\n\t\t\tthis.batchClientId = undefined;\n\t\t\tthis.emitter.emit(\"batchEnd\", error, message);\n\t\t\tthis.deltaScheduler.batchEnd(message);\n\t\t\treturn;\n\t\t}\n\n\t\tconst batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n\t\t// If no batchClientId has been set then we're in an individual batch. Else, if we get\n\t\t// batch end metadata, this is end of the current batch.\n\t\tif (this.batchClientId === undefined || batch === false) {\n\t\t\tthis.batchClientId = undefined;\n\t\t\tthis.emitter.emit(\"batchEnd\", undefined, message);\n\t\t\tthis.deltaScheduler.batchEnd(message);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n/**\n * This class controls pausing and resuming of inbound queue to ensure that we never\n * start processing ops in a batch IF we do not have all ops in the batch.\n */\nclass ScheduleManagerCore {\n\tprivate pauseSequenceNumber: number | undefined;\n\tprivate currentBatchClientId: string | undefined;\n\tprivate localPaused = false;\n\tprivate timePaused = 0;\n\tprivate batchCount = 0;\n\n\tconstructor(\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tprivate readonly getClientId: () => string | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\t// Listen for delta manager sends and add batch metadata to messages\n\t\tthis.deltaManager.on(\"prepareSend\", (messages: IDocumentMessage[]) => {\n\t\t\tif (messages.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// First message will have the batch flag set to true if doing a batched send\n\t\t\tconst firstMessageMetadata = messages[0].metadata as IRuntimeMessageMetadata;\n\t\t\tif (!firstMessageMetadata?.batch) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the batch contains only a single op, clear the batch flag.\n\t\t\tif (messages.length === 1) {\n\t\t\t\tdelete firstMessageMetadata.batch;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set the batch flag to false on the last message to indicate the end of the send batch\n\t\t\tconst lastMessage = messages[messages.length - 1];\n\t\t\t// TODO: It's not clear if this shallow clone is required, as opposed to just setting \"batch\" to false.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tlastMessage.metadata = { ...(lastMessage.metadata as any), batch: false };\n\t\t});\n\n\t\t// Listen for updates and peek at the inbound\n\t\tthis.deltaManager.inbound.on(\"push\", (message: ISequencedDocumentMessage) => {\n\t\t\tthis.trackPending(message);\n\t\t});\n\n\t\t// Start with baseline - empty inbound queue.\n\t\tassert(!this.localPaused, 0x293 /* \"initial state\" */);\n\n\t\tconst allPending = this.deltaManager.inbound.toArray();\n\t\tfor (const pending of allPending) {\n\t\t\tthis.trackPending(pending);\n\t\t}\n\n\t\t// We are intentionally directly listening to the \"op\" to inspect system ops as well.\n\t\t// If we do not observe system ops, we are likely to hit 0x296 assert when system ops\n\t\t// precedes start of incomplete batch.\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterOpProcessing(message));\n\t}\n\n\t/**\n\t * The only public function in this class - called when we processed an op,\n\t * to make decision if op processing should be paused or not after that.\n\t */\n\tpublic afterOpProcessing(message: ISequencedDocumentMessage) {\n\t\tassert(\n\t\t\t!this.localPaused,\n\t\t\t0x294 /* \"can't have op processing paused if we are processing an op\" */,\n\t\t);\n\n\t\t// If the inbound queue is ever empty, nothing to do!\n\t\tif (this.deltaManager.inbound.length === 0) {\n\t\t\tassert(\n\t\t\t\tthis.pauseSequenceNumber === undefined,\n\t\t\t\t0x295 /* \"there should be no pending batch if we have no ops\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// The queue is\n\t\t// 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n\t\t// - here (processing ops until reaching start of incomplete batch)\n\t\t// - in trackPending(), when queue was empty and start of batch showed up.\n\t\t// 2. resumed when batch end comes in (in trackPending())\n\n\t\t// do we have incomplete batch to worry about?\n\t\tif (this.pauseSequenceNumber !== undefined) {\n\t\t\tif (message.sequenceNumber >= this.pauseSequenceNumber) {\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t// Former assert 0x296\n\t\t\t\t\t\"Incomplete batch\",\n\t\t\t\t\t\"ScheduleManager\",\n\t\t\t\t\tmessage,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: message.type,\n\t\t\t\t\t\tcontentType: typeof message.contents,\n\t\t\t\t\t\tbatch: (message.metadata as IBatchMetadata | undefined)?.batch,\n\t\t\t\t\t\tcompression: message.compression,\n\t\t\t\t\t\tpauseSeqNum: this.pauseSequenceNumber,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!\n\t\t\tif (message.sequenceNumber + 1 === this.pauseSequenceNumber) {\n\t\t\t\tthis.pauseQueue();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pauseQueue() {\n\t\tassert(!this.localPaused, 0x297 /* \"always called from resumed state\" */);\n\t\tthis.localPaused = true;\n\t\tthis.timePaused = performance.now();\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tthis.deltaManager.inbound.pause();\n\t}\n\n\tprivate resumeQueue(startBatch: number, messageEndBatch: ISequencedDocumentMessage) {\n\t\tconst endBatch = messageEndBatch.sequenceNumber;\n\t\tconst duration = this.localPaused ? performance.now() - this.timePaused : undefined;\n\n\t\tthis.batchCount++;\n\t\tif (this.batchCount % 1000 === 1) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"BatchStats\",\n\t\t\t\tsequenceNumber: endBatch,\n\t\t\t\tlength: endBatch - startBatch + 1,\n\t\t\t\tmsnDistance: endBatch - messageEndBatch.minimumSequenceNumber,\n\t\t\t\tduration,\n\t\t\t\tbatchCount: this.batchCount,\n\t\t\t\tinterrupted: this.localPaused,\n\t\t\t});\n\t\t}\n\n\t\t// Return early if no change in value\n\t\tif (!this.localPaused) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.localPaused = false;\n\n\t\tthis.deltaManager.inbound.resume();\n\t}\n\n\t/**\n\t * Called for each incoming op (i.e. inbound \"push\" notification)\n\t */\n\tprivate trackPending(message: ISequencedDocumentMessage) {\n\t\tassert(\n\t\t\tthis.deltaManager.inbound.length !== 0,\n\t\t\t0x298 /* \"we have something in the queue that generates this event\" */,\n\t\t);\n\n\t\tassert(\n\t\t\t(this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined),\n\t\t\t0x299 /* \"non-synchronized state\" */,\n\t\t);\n\n\t\tconst metadata = message.metadata as IRuntimeMessageMetadata;\n\t\t// batchMetadata will be true for the message that starts a batch, false for the one that ends it, and\n\t\t// undefined for all other messages.\n\t\tconst batchMetadata = metadata?.batch;\n\n\t\t// Protocol messages are never part of a runtime batch of messages\n\t\tif (!isRuntimeMessage(message)) {\n\t\t\t// Protocol messages should never show up in the middle of the batch!\n\t\t\tif (this.currentBatchClientId !== undefined) {\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t\"Received a system message during batch processing\", // Formerly known as assert 0x29a\n\t\t\t\t\t\"trackPending\",\n\t\t\t\t\tmessage,\n\t\t\t\t\t{\n\t\t\t\t\t\truntimeVersion: pkgVersion,\n\t\t\t\t\t\tbatchClientId:\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\t\t\t\tthis.currentBatchClientId === null ? \"null\" : this.currentBatchClientId,\n\t\t\t\t\t\tpauseSequenceNumber: this.pauseSequenceNumber,\n\t\t\t\t\t\tlocalBatch: this.currentBatchClientId === this.getClientId(),\n\t\t\t\t\t\tmessageType: message.type,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tassert(batchMetadata === undefined, 0x29b /* \"system op in a batch?\" */);\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29c /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.currentBatchClientId === undefined && batchMetadata === undefined) {\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29d /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// If we got here, the message is part of a batch. Either starting, in progress, or ending.\n\n\t\t// If this is not the start of the batch, error out if the message was sent by a client other than the one that\n\t\t// started the current batch (it should not be possible for ops from other clients to get interleaved with a batch).\n\t\tif (\n\t\t\tthis.currentBatchClientId !== undefined &&\n\t\t\tthis.currentBatchClientId !== message.clientId\n\t\t) {\n\t\t\tthrow new DataCorruptionError(\"OpBatchIncomplete\", {\n\t\t\t\truntimeVersion: pkgVersion,\n\t\t\t\tbatchClientId:\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\t\tthis.currentBatchClientId === null ? \"null\" : this.currentBatchClientId,\n\t\t\t\tpauseSequenceNumber: this.pauseSequenceNumber,\n\t\t\t\tlocalBatch: this.currentBatchClientId === this.getClientId(),\n\t\t\t\tlocalMessage: message.clientId === this.getClientId(),\n\t\t\t\t...extractSafePropertiesFromMessage(message),\n\t\t\t});\n\t\t}\n\n\t\t// The queue is\n\t\t// 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n\t\t// - in afterOpProcessing() - processing ops until reaching start of incomplete batch\n\t\t// - here, when queue was empty and start of batch showed up (batchMetadata === true below).\n\t\t// 2. resumed when batch end comes in (batchMetadata === false below)\n\n\t\tif (batchMetadata) {\n\t\t\tassert(\n\t\t\t\tthis.currentBatchClientId === undefined,\n\t\t\t\t0x29e /* \"there can't be active batch\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29f /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\tthis.pauseSequenceNumber = message.sequenceNumber;\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tthis.currentBatchClientId = message.clientId as string;\n\t\t\t// Start of the batch\n\t\t\t// Only pause processing if queue has no other ops!\n\t\t\t// If there are any other ops in the queue, processing will be stopped when they are processed!\n\t\t\tif (this.deltaManager.inbound.length === 1) {\n\t\t\t\tthis.pauseQueue();\n\t\t\t}\n\t\t} else if (batchMetadata === false) {\n\t\t\tassert(\n\t\t\t\tthis.pauseSequenceNumber !== undefined,\n\t\t\t\t0x2a0 /* \"batch presence was validated above\" */,\n\t\t\t);\n\t\t\t// Batch is complete, we can process it!\n\t\t\tthis.resumeQueue(this.pauseSequenceNumber, message);\n\t\t\tthis.pauseSequenceNumber = undefined;\n\t\t\tthis.currentBatchClientId = undefined;\n\t\t} else {\n\t\t\t// Continuation of current batch. Do nothing\n\t\t\tassert(this.currentBatchClientId !== undefined, 0x2a1 /* \"logic error\" */);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"scheduleManager.js","sourceR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IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;SACtC;aAAM;YACN,4CAA4C;YAC5C,MAAM,CAAC,IAAI,CAAC,oBAAoB,KAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;SAC3E;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { EventEmitter } from \"@fluid-internal/client-utils\";\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tDataCorruptionError,\n\tDataProcessingError,\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n\textractSafePropertiesFromMessage,\n} from \"@fluidframework/telemetry-utils\";\nimport { DeltaScheduler } from \"./deltaScheduler.js\";\nimport { IBatchMetadata } from \"./metadata.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\ntype IRuntimeMessageMetadata =\n\t| undefined\n\t| {\n\t\t\tbatch?: boolean;\n\t };\n\n/**\n * This class has the following responsibilities:\n *\n * 1. It tracks batches as we process ops and raises \"batchBegin\" and \"batchEnd\" events.\n * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)\n *\n * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch\n * unless all ops of the batch are in.\n */\nexport class ScheduleManager {\n\tprivate readonly deltaScheduler: DeltaScheduler;\n\tprivate batchClientId: string | undefined;\n\tprivate hitError = false;\n\n\tconstructor(\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tprivate readonly emitter: EventEmitter,\n\t\treadonly getClientId: () => string | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.deltaScheduler = new DeltaScheduler(\n\t\t\tthis.deltaManager,\n\t\t\tcreateChildLogger({ logger: this.logger, namespace: \"DeltaScheduler\" }),\n\t\t);\n\t\tvoid new ScheduleManagerCore(deltaManager, getClientId, logger);\n\t}\n\n\tpublic beforeOpProcessing(message: ISequencedDocumentMessage) {\n\t\tif (this.batchClientId !== message.clientId) {\n\t\t\tassert(\n\t\t\t\tthis.batchClientId === undefined,\n\t\t\t\t0x2a2 /* \"Batch is interrupted by other client op. Should be caught by trackPending()\" */,\n\t\t\t);\n\n\t\t\t// This could be the beginning of a new batch or an individual message.\n\t\t\tthis.emitter.emit(\"batchBegin\", message);\n\t\t\tthis.deltaScheduler.batchBegin(message);\n\n\t\t\tconst batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tthis.batchClientId = batch ? (message.clientId as string) : undefined;\n\t\t}\n\t}\n\n\tpublic afterOpProcessing(error: any | undefined, message: ISequencedDocumentMessage) {\n\t\t// If this is no longer true, we need to revisit what we do where we set this.hitError.\n\t\tassert(!this.hitError, 0x2a3 /* \"container should be closed on any error\" */);\n\n\t\tif (error) {\n\t\t\t// We assume here that loader will close container and stop processing all future ops.\n\t\t\t// This is implicit dependency. If this flow changes, this code might no longer be correct.\n\t\t\tthis.hitError = true;\n\t\t\tthis.batchClientId = undefined;\n\t\t\tthis.emitter.emit(\"batchEnd\", error, message);\n\t\t\tthis.deltaScheduler.batchEnd(message);\n\t\t\treturn;\n\t\t}\n\n\t\tconst batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n\t\t// If no batchClientId has been set then we're in an individual batch. Else, if we get\n\t\t// batch end metadata, this is end of the current batch.\n\t\tif (this.batchClientId === undefined || batch === false) {\n\t\t\tthis.batchClientId = undefined;\n\t\t\tthis.emitter.emit(\"batchEnd\", undefined, message);\n\t\t\tthis.deltaScheduler.batchEnd(message);\n\t\t\treturn;\n\t\t}\n\t}\n}\n\n/**\n * This class controls pausing and resuming of inbound queue to ensure that we never\n * start processing ops in a batch IF we do not have all ops in the batch.\n */\nclass ScheduleManagerCore {\n\tprivate pauseSequenceNumber: number | undefined;\n\tprivate currentBatchClientId: string | undefined;\n\tprivate localPaused = false;\n\tprivate timePaused = 0;\n\tprivate batchCount = 0;\n\n\tconstructor(\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tprivate readonly getClientId: () => string | undefined,\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t) {\n\t\t// Listen for delta manager sends and add batch metadata to messages\n\t\tthis.deltaManager.on(\"prepareSend\", (messages: IDocumentMessage[]) => {\n\t\t\tif (messages.length === 0) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// First message will have the batch flag set to true if doing a batched send\n\t\t\tconst firstMessageMetadata = messages[0].metadata as IRuntimeMessageMetadata;\n\t\t\tif (!firstMessageMetadata?.batch) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the batch contains only a single op, clear the batch flag.\n\t\t\tif (messages.length === 1) {\n\t\t\t\tdelete firstMessageMetadata.batch;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Set the batch flag to false on the last message to indicate the end of the send batch\n\t\t\tconst lastMessage = messages[messages.length - 1];\n\t\t\t// TODO: It's not clear if this shallow clone is required, as opposed to just setting \"batch\" to false.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tlastMessage.metadata = { ...(lastMessage.metadata as any), batch: false };\n\t\t});\n\n\t\t// Listen for updates and peek at the inbound\n\t\tthis.deltaManager.inbound.on(\"push\", (message: ISequencedDocumentMessage) => {\n\t\t\tthis.trackPending(message);\n\t\t});\n\n\t\t// Start with baseline - empty inbound queue.\n\t\tassert(!this.localPaused, 0x293 /* \"initial state\" */);\n\n\t\tconst allPending = this.deltaManager.inbound.toArray();\n\t\tfor (const pending of allPending) {\n\t\t\tthis.trackPending(pending);\n\t\t}\n\n\t\t// We are intentionally directly listening to the \"op\" to inspect system ops as well.\n\t\t// If we do not observe system ops, we are likely to hit 0x296 assert when system ops\n\t\t// precedes start of incomplete batch.\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterOpProcessing(message));\n\t}\n\n\t/**\n\t * The only public function in this class - called when we processed an op,\n\t * to make decision if op processing should be paused or not after that.\n\t */\n\tpublic afterOpProcessing(message: ISequencedDocumentMessage) {\n\t\tassert(\n\t\t\t!this.localPaused,\n\t\t\t0x294 /* \"can't have op processing paused if we are processing an op\" */,\n\t\t);\n\n\t\t// If the inbound queue is ever empty, nothing to do!\n\t\tif (this.deltaManager.inbound.length === 0) {\n\t\t\tassert(\n\t\t\t\tthis.pauseSequenceNumber === undefined,\n\t\t\t\t0x295 /* \"there should be no pending batch if we have no ops\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// The queue is\n\t\t// 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n\t\t// - here (processing ops until reaching start of incomplete batch)\n\t\t// - in trackPending(), when queue was empty and start of batch showed up.\n\t\t// 2. resumed when batch end comes in (in trackPending())\n\n\t\t// do we have incomplete batch to worry about?\n\t\tif (this.pauseSequenceNumber !== undefined) {\n\t\t\tif (message.sequenceNumber >= this.pauseSequenceNumber) {\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t// Former assert 0x296\n\t\t\t\t\t\"Incomplete batch\",\n\t\t\t\t\t\"ScheduleManager\",\n\t\t\t\t\tmessage,\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: message.type,\n\t\t\t\t\t\tcontentType: typeof message.contents,\n\t\t\t\t\t\tbatch: (message.metadata as IBatchMetadata | undefined)?.batch,\n\t\t\t\t\t\tcompression: message.compression,\n\t\t\t\t\t\tpauseSeqNum: this.pauseSequenceNumber,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!\n\t\t\tif (message.sequenceNumber + 1 === this.pauseSequenceNumber) {\n\t\t\t\tthis.pauseQueue();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pauseQueue() {\n\t\tassert(!this.localPaused, 0x297 /* \"always called from resumed state\" */);\n\t\tthis.localPaused = true;\n\t\tthis.timePaused = performance.now();\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\tthis.deltaManager.inbound.pause();\n\t}\n\n\tprivate resumeQueue(startBatch: number, messageEndBatch: ISequencedDocumentMessage) {\n\t\tconst endBatch = messageEndBatch.sequenceNumber;\n\t\tconst duration = this.localPaused ? performance.now() - this.timePaused : undefined;\n\n\t\tthis.batchCount++;\n\t\tif (this.batchCount % 1000 === 1) {\n\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"BatchStats\",\n\t\t\t\tsequenceNumber: endBatch,\n\t\t\t\tlength: endBatch - startBatch + 1,\n\t\t\t\tmsnDistance: endBatch - messageEndBatch.minimumSequenceNumber,\n\t\t\t\tduration,\n\t\t\t\tbatchCount: this.batchCount,\n\t\t\t\tinterrupted: this.localPaused,\n\t\t\t});\n\t\t}\n\n\t\t// Return early if no change in value\n\t\tif (!this.localPaused) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.localPaused = false;\n\n\t\tthis.deltaManager.inbound.resume();\n\t}\n\n\t/**\n\t * Called for each incoming op (i.e. inbound \"push\" notification)\n\t */\n\tprivate trackPending(message: ISequencedDocumentMessage) {\n\t\tassert(\n\t\t\tthis.deltaManager.inbound.length !== 0,\n\t\t\t0x298 /* \"we have something in the queue that generates this event\" */,\n\t\t);\n\n\t\tassert(\n\t\t\t(this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined),\n\t\t\t0x299 /* \"non-synchronized state\" */,\n\t\t);\n\n\t\tconst metadata = message.metadata as IRuntimeMessageMetadata;\n\t\t// batchMetadata will be true for the message that starts a batch, false for the one that ends it, and\n\t\t// undefined for all other messages.\n\t\tconst batchMetadata = metadata?.batch;\n\n\t\t// Protocol messages are never part of a runtime batch of messages\n\t\tif (!isRuntimeMessage(message)) {\n\t\t\t// Protocol messages should never show up in the middle of the batch!\n\t\t\tif (this.currentBatchClientId !== undefined) {\n\t\t\t\tthrow DataProcessingError.create(\n\t\t\t\t\t\"Received a system message during batch processing\", // Formerly known as assert 0x29a\n\t\t\t\t\t\"trackPending\",\n\t\t\t\t\tmessage,\n\t\t\t\t\t{\n\t\t\t\t\t\truntimeVersion: pkgVersion,\n\t\t\t\t\t\tbatchClientId:\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\t\t\t\tthis.currentBatchClientId === null ? \"null\" : this.currentBatchClientId,\n\t\t\t\t\t\tpauseSequenceNumber: this.pauseSequenceNumber,\n\t\t\t\t\t\tlocalBatch: this.currentBatchClientId === this.getClientId(),\n\t\t\t\t\t\tmessageType: message.type,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tassert(batchMetadata === undefined, 0x29b /* \"system op in a batch?\" */);\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29c /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.currentBatchClientId === undefined && batchMetadata === undefined) {\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29d /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\t// If we got here, the message is part of a batch. Either starting, in progress, or ending.\n\n\t\t// If this is not the start of the batch, error out if the message was sent by a client other than the one that\n\t\t// started the current batch (it should not be possible for ops from other clients to get interleaved with a batch).\n\t\tif (\n\t\t\tthis.currentBatchClientId !== undefined &&\n\t\t\tthis.currentBatchClientId !== message.clientId\n\t\t) {\n\t\t\tthrow new DataCorruptionError(\"OpBatchIncomplete\", {\n\t\t\t\truntimeVersion: pkgVersion,\n\t\t\t\tbatchClientId:\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n\t\t\t\t\tthis.currentBatchClientId === null ? \"null\" : this.currentBatchClientId,\n\t\t\t\tpauseSequenceNumber: this.pauseSequenceNumber,\n\t\t\t\tlocalBatch: this.currentBatchClientId === this.getClientId(),\n\t\t\t\tlocalMessage: message.clientId === this.getClientId(),\n\t\t\t\t...extractSafePropertiesFromMessage(message),\n\t\t\t});\n\t\t}\n\n\t\t// The queue is\n\t\t// 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n\t\t// - in afterOpProcessing() - processing ops until reaching start of incomplete batch\n\t\t// - here, when queue was empty and start of batch showed up (batchMetadata === true below).\n\t\t// 2. resumed when batch end comes in (batchMetadata === false below)\n\n\t\tif (batchMetadata) {\n\t\t\tassert(\n\t\t\t\tthis.currentBatchClientId === undefined,\n\t\t\t\t0x29e /* \"there can't be active batch\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\t!this.localPaused,\n\t\t\t\t0x29f /* \"we should be processing ops when there is no active batch\" */,\n\t\t\t);\n\t\t\tthis.pauseSequenceNumber = message.sequenceNumber;\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tthis.currentBatchClientId = message.clientId as string;\n\t\t\t// Start of the batch\n\t\t\t// Only pause processing if queue has no other ops!\n\t\t\t// If there are any other ops in the queue, processing will be stopped when they are processed!\n\t\t\tif (this.deltaManager.inbound.length === 1) {\n\t\t\t\tthis.pauseQueue();\n\t\t\t}\n\t\t} else if (batchMetadata === false) {\n\t\t\tassert(\n\t\t\t\tthis.pauseSequenceNumber !== undefined,\n\t\t\t\t0x2a0 /* \"batch presence was validated above\" */,\n\t\t\t);\n\t\t\t// Batch is complete, we can process it!\n\t\t\tthis.resumeQueue(this.pauseSequenceNumber, message);\n\t\t\tthis.pauseSequenceNumber = undefined;\n\t\t\tthis.currentBatchClientId = undefined;\n\t\t} else {\n\t\t\t// Continuation of current batch. Do nothing\n\t\t\tassert(this.currentBatchClientId !== undefined, 0x2a1 /* \"logic error\" */);\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Descripe allowed type for properties in document schema.
3
+ * Please note that for all property types we should use undefined to indicate that particular capability is off.
4
+ * Using false, or some string value (like "off") will result in clients who do not understand that property failing, whereas
5
+ * we want them to continue to collaborate alongside clients who support that capability, but such capability is shipping dark for now.
6
+ * @alpha
7
+ */
8
+ export type DocumentSchemaValueType = string | true | number | undefined;
9
+ /**
10
+ * ID Compressor mode.
11
+ * "on" - compressor is On. It's loaded as part of container load. This mode is sticky - once on, compressor is On for all
12
+ * sessions for a given document. This results in IContainerRuntime.idCompressor to be always available.
13
+ * "delayed" - ID compressor bundle is loaded only on establishing of first delta connection, i.e. it does not impact boot of cotnainer.
14
+ * In such mode IContainerRuntime.idCompressor is not made available (unless previous sessions of same document had it "On").
15
+ * The only thing that is available is IContainerRuntime.generateDocumentUniqueId() that provides opportunistically short IDs.
16
+ * undefined - ID compressor is not loaded.
17
+ * While IContainerRuntime.generateDocumentUniqueId() is available, it will produce long IDs that are do not compress well.
18
+ *
19
+ * @alpha
20
+ */
21
+ export type IdCompressorMode = "on" | "delayed" | undefined;
22
+ /**
23
+ * Document schema information.
24
+ * Describes overall shape of document schema, including unknown (to this version) properties.
25
+ *
26
+ * Used by runtime to make a call if it can understand document schema.
27
+ * If it can't, it should not continue with document and immediately fail, preventing random (cryptic) failures
28
+ * down the road and potentially corrupting documents.
29
+ * For now this structure and appropriate interpretation / behavior is focused only on runtime features.
30
+ * In the future that could be interpolated to more areas, including DDSs used, and even possibly - application
31
+ * schema.
32
+ *
33
+ * Runtime will ignore any properties at the root that it does not understand (i.e. IDocumentSchema.app), but will
34
+ * stop (and fail session) on any unknown properties within "runtime" sub-tree.
35
+ *
36
+ * In most cases values preserved in the document will not dictate if such features should be enabled in a given session.
37
+ * I.e. if compression is mentioned in document schema, this means that runtime version that opens such document must know
38
+ * how to interpret such ops, but does not need to actually use compression itself. That said, some options could be
39
+ * sticky, i.e. influence feature selection for all runtimes opening a document. ID compression is one such example.
40
+ * Currently there is no mechanism to remove feature from this property bag, i.e. once compression was used, even if it's
41
+ * disabled (through feature gate or code deployment), all existing documents that used compression will continue to fail
42
+ * if opened by clients who do not support compression.
43
+ *
44
+ * For now we are limiting it to just plain properties, and only really simple types, but that can be changed in the future.
45
+ *
46
+ * @alpha
47
+ */
48
+ export interface IDocumentSchema {
49
+ version: number;
50
+ refSeq: number;
51
+ runtime: Record<string, DocumentSchemaValueType>;
52
+ }
53
+ /**
54
+ * Content of the type=ContainerMessageType.DocumentSchemaChange ops.
55
+ * The meaning of refSeq field is different in such messages (compared to other usages of IDocumentSchemaCurrent)
56
+ * ContainerMessageType.DocumentSchemaChange messages use CAS (Compare-and-swap) semantics, and convey
57
+ * regSeq of last known schema change (known to a client proposing schema change).
58
+ * @see ContainerRuntimeDocumentSchemaMessage
59
+ * @alpha
60
+ */
61
+ export type IDocumentSchemaChangeMessage = IDocumentSchema;
62
+ /**
63
+ * Settings that this session would like to have, based on options and feature gates.
64
+ *
65
+ * WARNING: This type is used to infer IDocumentSchemaCurrent type!
66
+ * Any changes here (including renaming of properties) are potentially changing document format and should be considered carefully!
67
+ *
68
+ * @alpha
69
+ */
70
+ export interface IDocumentSchemaFeatures {
71
+ explicitSchemaControl: boolean;
72
+ compressionLz4: boolean;
73
+ idCompressorMode: IdCompressorMode;
74
+ opGroupingEnabled: boolean;
75
+ }
76
+ /**
77
+ * Current version known properties that define document schema
78
+ * This must be bumped whenever the format of document schema or protocol for changing the current document schema changes.
79
+ * Ex: adding a new configuration property (under IDocumentSchema.runtime) does not require changing this version.
80
+ * Ex: Changing the 'document schema acceptance' mechanism from convert-and-swap to one requiring consensus does require changing this version.
81
+ * @alpha
82
+ */
83
+ export declare const currentDocumentVersionSchema = 1;
84
+ /**
85
+ * Current document schema.
86
+ * @alpha
87
+ */
88
+ export type IDocumentSchemaCurrent = {
89
+ version: 1;
90
+ refSeq: number;
91
+ runtime: {
92
+ [P in keyof IDocumentSchemaFeatures]?: IDocumentSchemaFeatures[P] extends boolean ? true : IDocumentSchemaFeatures[P];
93
+ };
94
+ };
95
+ /**
96
+ * Controller of document schema.
97
+ *
98
+ * Recommended pre-reading: https://github.com/microsoft/FluidFramework/blob/main/packages/dds/SchemaVersioning.md
99
+ *
100
+ * This class manages current document schema and transitions between document schemas.
101
+ * At the moment, it only focuses on subset of document schema, specifically - how FluidFramework runtime serializes data
102
+ * (summary and op format), features & capabilities that a version of runtime has to support and understand in
103
+ * order to collaborate on a document.
104
+ * New features that modify document format have to be included in document schema definition.
105
+ * Usage of such features could only happen after document schema has been updated to reflect such feature.
106
+ *
107
+ * This formality allows clients that do not understand such features to fail right away when they observe
108
+ * document schema listing capabilities that such client does not understand.
109
+ * Old clients will fail in predictable way. This allows us to
110
+ * 1) Immediately see such issues and adjust if features are enabled too early, before changes have been saturated.
111
+ * 2) There is no way to get to 100% saturation with new code. Even if we have 99.99% saturation, there are
112
+ * still 0.01% of clients who will fail. Failing early and predictably ensures they have no chance to limp along
113
+ * and potentially corrupt the document. This is especially true for summarizer client, who could simply "undo"
114
+ * changes it does not understands.
115
+ *
116
+ * It's important to note how it overlaps with feature gates and safe velocity.
117
+ * If new feature was in use, that resulted in a number of documents referencing such feature in document schema.
118
+ * But, developers (through code deployment or feature gates) could disable usage of such features.
119
+ * That will stop a process of further document schema changes (for documents that were not using such feature).
120
+ * And documents that already list such capability in their schema will continue to do so. Later ensures that old
121
+ * clients who do not understand such feature will continue to fail to open such documents, as such documents very
122
+ * likely contain data in a new format.
123
+ *
124
+ * Users of this class need to use DocumentsSchemaController.sessionSchema to determine what features can be used.
125
+ *
126
+ * There are two modes this class can operate:
127
+ * 1) Legacy mode. In such mode it does not issue any ops to change document schema. Any changes happen implicitly,
128
+ * right away, and new features are available right away
129
+ * 2) Non-legacy mode. In such mode any changes to schema require an op roundtrip. This class will manage such transitions.
130
+ * However code should assume that any new features that were not enabled in a given document will not be available
131
+ * for a given session. That's because this session may never send any ops (including read-only documents). Or it may
132
+ * fail to convert schema.
133
+ * This class promises eventual movement forward. I.e. if new feature is allowed (let's say - through feature gates),
134
+ * then eventually all documents that are modified will have that feature reflected in their schema. It could require
135
+ * multiple reloads / new sessions to get there (depends on if code reacts to schema changes right away, or only consults
136
+ * schema on document load).
137
+ *
138
+ * How schemas are changed (in non-legacy mode):
139
+ * If a client needs to change a schema, it will attempt to do so as part of normal ops sending process.
140
+ * Changes happen in CAS (Compare-and-swap) fashion, i.e. client tells current schema and schema it wants to change to.
141
+ * When a number of clients race to change a schema, then only one of them will win, all others will fail because they will
142
+ * reference old schema that is no longer in effect.
143
+ * Clients can retry, but current implementation is simply - they will not (and will rely on next session / reload to do
144
+ * recalc and decide if schema needs to be changed or not).
145
+ *
146
+ * @alpha
147
+ */
148
+ export declare class DocumentsSchemaController {
149
+ private readonly onSchemaChange;
150
+ private explicitSchemaControl;
151
+ private sendOp;
152
+ private documentSchema;
153
+ private readonly desiredSchema;
154
+ private futureSchema;
155
+ sessionSchema: IDocumentSchemaCurrent;
156
+ /**
157
+ * Constructs DocumentsSchemaController that controls current schema and processes around it, including changes in schema.
158
+ * @param explicitSchemaControl - Tells if schema changes are done implicitly (without ops - legacy behavior), or go through formal schema change ops process.
159
+ * @param existing - Is the document existing document, or a new doc.
160
+ * @param documentMetadataSchema - current document's schema, if present.
161
+ * @param compressionAlgorithm - desired compression algorith to use
162
+ * @param idCompressorModeArg - desired ID compressor mode to use
163
+ * @param opGroupingEnabled - true if it's desired to use op grouping.
164
+ */
165
+ constructor(existing: boolean, documentMetadataSchema: IDocumentSchema | undefined, features: IDocumentSchemaFeatures, onSchemaChange: (schema: IDocumentSchemaCurrent) => void);
166
+ summarizeDocumentSchema(refSeq: number): IDocumentSchemaCurrent | undefined;
167
+ onMessageSent(send: (content: IDocumentSchemaChangeMessage) => void): void;
168
+ /**
169
+ * Process document schema change message
170
+ * @param content - content of the message
171
+ * @param local - whether op is local
172
+ * @param sequenceNumber - sequence number of the op
173
+ * @returns - true if schema was accepted, otherwise false (rejected due to failed CAS)
174
+ */
175
+ processDocumentSchemaOp(content: IDocumentSchemaChangeMessage, local: boolean, sequenceNumber: number): boolean;
176
+ onDisconnect(): void;
177
+ }
178
+ //# sourceMappingURL=documentSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"documentSchema.d.ts","sourceRoot":"","sources":["../../src/summary/documentSchema.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAAC;AAEzE;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,WAAW,eAAe;IAI/B,OAAO,EAAE,MAAM,CAAC;IAGhB,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,uBAAuB,CAAC,CAAC;CACjD;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,4BAA4B,GAAG,eAAe,CAAC;AAE3D;;;;;;;GAOG;AACH,MAAM,WAAW,uBAAuB;IAIvC,qBAAqB,EAAE,OAAO,CAAC;IAC/B,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,iBAAiB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C;;;GAGG;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACpC,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE;SACP,CAAC,IAAI,MAAM,uBAAuB,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,SAAS,OAAO,GAC9E,IAAI,GACJ,uBAAuB,CAAC,CAAC,CAAC;KAC7B,CAAC;CACF,CAAC;AAuMF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,qBAAa,yBAAyB;IAkCpC,OAAO,CAAC,QAAQ,CAAC,cAAc;IAjChC,OAAO,CAAC,qBAAqB,CAAU;IACvC,OAAO,CAAC,MAAM,CAAQ;IAGtB,OAAO,CAAC,cAAc,CAAyB;IAI/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAyB;IAGvD,OAAO,CAAC,YAAY,CAAqC;IAOlD,aAAa,EAAE,sBAAsB,CAAC;IAE7C;;;;;;;;OAQG;gBAEF,QAAQ,EAAE,OAAO,EACjB,sBAAsB,EAAE,eAAe,GAAG,SAAS,EACnD,QAAQ,EAAE,uBAAuB,EAChB,cAAc,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,IAAI;IAyDnE,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS;IAmB3E,aAAa,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,4BAA4B,KAAK,IAAI;IAe1E;;;;;;OAMG;IACI,uBAAuB,CAC7B,OAAO,EAAE,4BAA4B,EACrC,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,MAAM;IAyChB,YAAY;CAGnB"}
@@ -0,0 +1,341 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { assert } from "@fluidframework/core-utils";
6
+ import { DataProcessingError } from "@fluidframework/telemetry-utils";
7
+ /**
8
+ * Current version known properties that define document schema
9
+ * This must be bumped whenever the format of document schema or protocol for changing the current document schema changes.
10
+ * Ex: adding a new configuration property (under IDocumentSchema.runtime) does not require changing this version.
11
+ * Ex: Changing the 'document schema acceptance' mechanism from convert-and-swap to one requiring consensus does require changing this version.
12
+ * @alpha
13
+ */
14
+ export const currentDocumentVersionSchema = 1;
15
+ class TrueOrUndefined {
16
+ and(currentDocSchema, desiredDocSchema) {
17
+ return currentDocSchema === true && desiredDocSchema === true ? true : undefined;
18
+ }
19
+ or(currentDocSchema, desiredDocSchema) {
20
+ return currentDocSchema === true || desiredDocSchema === true ? true : undefined;
21
+ }
22
+ validate(t) {
23
+ return t === undefined || t === true;
24
+ }
25
+ }
26
+ class TrueOrUndefinedMax extends TrueOrUndefined {
27
+ and(currentDocSchema, desiredDocSchema) {
28
+ return this.or(currentDocSchema, desiredDocSchema);
29
+ }
30
+ }
31
+ class MultiChoice {
32
+ constructor(choices) {
33
+ this.choices = choices;
34
+ }
35
+ and(currentDocSchema, desiredDocSchema) {
36
+ if (currentDocSchema === undefined || desiredDocSchema === undefined) {
37
+ return undefined;
38
+ }
39
+ return this.choices[Math.min(this.choices.indexOf(currentDocSchema), this.choices.indexOf(desiredDocSchema))];
40
+ }
41
+ or(currentDocSchema, desiredDocSchema) {
42
+ if (currentDocSchema === undefined) {
43
+ return desiredDocSchema;
44
+ }
45
+ if (desiredDocSchema === undefined) {
46
+ return currentDocSchema;
47
+ }
48
+ return this.choices[Math.max(this.choices.indexOf(currentDocSchema), this.choices.indexOf(desiredDocSchema))];
49
+ }
50
+ validate(t) {
51
+ return t === undefined || (typeof t === "string" && this.choices.includes(t));
52
+ }
53
+ }
54
+ class IdCompressorProperty extends MultiChoice {
55
+ // document schema always wins!
56
+ and(currentDocSchema, desiredDocSchema) {
57
+ return currentDocSchema;
58
+ }
59
+ }
60
+ /**
61
+ * Helper structure to valida if a schema is compatible with existing code.
62
+ */
63
+ const documentSchemaSupportedConfigs = {
64
+ explicitSchemaControl: new TrueOrUndefinedMax(),
65
+ idCompressorMode: new IdCompressorProperty(["delayed", "on"]),
66
+ opGroupingEnabled: new TrueOrUndefined(),
67
+ compressionLz4: new TrueOrUndefined(),
68
+ };
69
+ /**
70
+ * Checks if a given schema is compatible with current code, i.e. if current code can understand all the features of that schema.
71
+ * If schema is not compatible with current code, it throws an exception.
72
+ * @param documentSchema - current schema
73
+ */
74
+ function checkRuntimeCompatibility(documentSchema) {
75
+ // Back-compat - we can't do anything about legacy documents.
76
+ // There is no way to validate them, so we are taking a guess that safe deployment processes used by a given app
77
+ // do not run into compat problems.
78
+ if (documentSchema === undefined) {
79
+ return;
80
+ }
81
+ const msg = "Document can't be opened with current version of the code";
82
+ if (documentSchema.version !== currentDocumentVersionSchema) {
83
+ throw DataProcessingError.create(msg, "checkRuntimeCompat", undefined, // message
84
+ {
85
+ runtimeSchemaVersion: documentSchema.version,
86
+ currentRuntimeSchemaVersion: currentDocumentVersionSchema,
87
+ });
88
+ }
89
+ let unknownProperty;
90
+ const regSeq = documentSchema.refSeq;
91
+ // defence in depth - it should not be possible to get here anything other than integer, but worth validating it.
92
+ if (typeof regSeq !== "number" || regSeq < 0 || !Number.isInteger(regSeq)) {
93
+ unknownProperty = "refSeq";
94
+ }
95
+ else if (documentSchema.runtime === null || typeof documentSchema.runtime !== "object") {
96
+ unknownProperty = "runtime";
97
+ }
98
+ else {
99
+ for (const [name, value] of Object.entries(documentSchema.runtime)) {
100
+ const validator = documentSchemaSupportedConfigs[name];
101
+ if (validator === undefined || !validator.validate(value)) {
102
+ unknownProperty = `runtime/${name}`;
103
+ }
104
+ }
105
+ }
106
+ if (unknownProperty !== undefined) {
107
+ const value = documentSchema[unknownProperty];
108
+ throw DataProcessingError.create(msg, "checkRuntimeCompat", undefined, // message
109
+ {
110
+ codeVersion: currentDocumentVersionSchema,
111
+ property: unknownProperty,
112
+ value,
113
+ });
114
+ }
115
+ }
116
+ function and(currentDocSchema, desiredDocSchema) {
117
+ const runtime = {};
118
+ for (const key of new Set([
119
+ ...Object.keys(currentDocSchema.runtime),
120
+ ...Object.keys(desiredDocSchema.runtime),
121
+ ])) {
122
+ runtime[key] = documentSchemaSupportedConfigs[key].and(currentDocSchema.runtime[key], desiredDocSchema.runtime[key]);
123
+ }
124
+ return {
125
+ version: currentDocumentVersionSchema,
126
+ refSeq: currentDocSchema.refSeq,
127
+ runtime,
128
+ };
129
+ }
130
+ function or(currentDocSchema, desiredDocSchema) {
131
+ const runtime = {};
132
+ for (const key of new Set([
133
+ ...Object.keys(currentDocSchema.runtime),
134
+ ...Object.keys(desiredDocSchema.runtime),
135
+ ])) {
136
+ runtime[key] = documentSchemaSupportedConfigs[key].or(currentDocSchema.runtime[key], desiredDocSchema.runtime[key]);
137
+ }
138
+ return {
139
+ version: currentDocumentVersionSchema,
140
+ refSeq: currentDocSchema.refSeq,
141
+ runtime,
142
+ };
143
+ }
144
+ function same(currentDocSchema, desiredDocSchema) {
145
+ for (const key of new Set([
146
+ ...Object.keys(currentDocSchema.runtime),
147
+ ...Object.keys(desiredDocSchema.runtime),
148
+ ])) {
149
+ // If schemas differ only by type of behavior, then we should not send schema change ops!
150
+ if (key !== "explicitSchemaControl" &&
151
+ currentDocSchema.runtime[key] !== desiredDocSchema.runtime[key]) {
152
+ return false;
153
+ }
154
+ }
155
+ return true;
156
+ }
157
+ function boolToProp(b) {
158
+ return b ? true : undefined;
159
+ }
160
+ /* eslint-disable jsdoc/check-indentation */
161
+ /**
162
+ * Controller of document schema.
163
+ *
164
+ * Recommended pre-reading: https://github.com/microsoft/FluidFramework/blob/main/packages/dds/SchemaVersioning.md
165
+ *
166
+ * This class manages current document schema and transitions between document schemas.
167
+ * At the moment, it only focuses on subset of document schema, specifically - how FluidFramework runtime serializes data
168
+ * (summary and op format), features & capabilities that a version of runtime has to support and understand in
169
+ * order to collaborate on a document.
170
+ * New features that modify document format have to be included in document schema definition.
171
+ * Usage of such features could only happen after document schema has been updated to reflect such feature.
172
+ *
173
+ * This formality allows clients that do not understand such features to fail right away when they observe
174
+ * document schema listing capabilities that such client does not understand.
175
+ * Old clients will fail in predictable way. This allows us to
176
+ * 1) Immediately see such issues and adjust if features are enabled too early, before changes have been saturated.
177
+ * 2) There is no way to get to 100% saturation with new code. Even if we have 99.99% saturation, there are
178
+ * still 0.01% of clients who will fail. Failing early and predictably ensures they have no chance to limp along
179
+ * and potentially corrupt the document. This is especially true for summarizer client, who could simply "undo"
180
+ * changes it does not understands.
181
+ *
182
+ * It's important to note how it overlaps with feature gates and safe velocity.
183
+ * If new feature was in use, that resulted in a number of documents referencing such feature in document schema.
184
+ * But, developers (through code deployment or feature gates) could disable usage of such features.
185
+ * That will stop a process of further document schema changes (for documents that were not using such feature).
186
+ * And documents that already list such capability in their schema will continue to do so. Later ensures that old
187
+ * clients who do not understand such feature will continue to fail to open such documents, as such documents very
188
+ * likely contain data in a new format.
189
+ *
190
+ * Users of this class need to use DocumentsSchemaController.sessionSchema to determine what features can be used.
191
+ *
192
+ * There are two modes this class can operate:
193
+ * 1) Legacy mode. In such mode it does not issue any ops to change document schema. Any changes happen implicitly,
194
+ * right away, and new features are available right away
195
+ * 2) Non-legacy mode. In such mode any changes to schema require an op roundtrip. This class will manage such transitions.
196
+ * However code should assume that any new features that were not enabled in a given document will not be available
197
+ * for a given session. That's because this session may never send any ops (including read-only documents). Or it may
198
+ * fail to convert schema.
199
+ * This class promises eventual movement forward. I.e. if new feature is allowed (let's say - through feature gates),
200
+ * then eventually all documents that are modified will have that feature reflected in their schema. It could require
201
+ * multiple reloads / new sessions to get there (depends on if code reacts to schema changes right away, or only consults
202
+ * schema on document load).
203
+ *
204
+ * How schemas are changed (in non-legacy mode):
205
+ * If a client needs to change a schema, it will attempt to do so as part of normal ops sending process.
206
+ * Changes happen in CAS (Compare-and-swap) fashion, i.e. client tells current schema and schema it wants to change to.
207
+ * When a number of clients race to change a schema, then only one of them will win, all others will fail because they will
208
+ * reference old schema that is no longer in effect.
209
+ * Clients can retry, but current implementation is simply - they will not (and will rely on next session / reload to do
210
+ * recalc and decide if schema needs to be changed or not).
211
+ *
212
+ * @alpha
213
+ */
214
+ export class DocumentsSchemaController {
215
+ /**
216
+ * Constructs DocumentsSchemaController that controls current schema and processes around it, including changes in schema.
217
+ * @param explicitSchemaControl - Tells if schema changes are done implicitly (without ops - legacy behavior), or go through formal schema change ops process.
218
+ * @param existing - Is the document existing document, or a new doc.
219
+ * @param documentMetadataSchema - current document's schema, if present.
220
+ * @param compressionAlgorithm - desired compression algorith to use
221
+ * @param idCompressorModeArg - desired ID compressor mode to use
222
+ * @param opGroupingEnabled - true if it's desired to use op grouping.
223
+ */
224
+ constructor(existing, documentMetadataSchema, features, onSchemaChange) {
225
+ this.onSchemaChange = onSchemaChange;
226
+ this.sendOp = true;
227
+ checkRuntimeCompatibility(documentMetadataSchema);
228
+ this.documentSchema =
229
+ documentMetadataSchema ??
230
+ ({
231
+ version: currentDocumentVersionSchema,
232
+ // see comment in summarizeDocumentSchema() on why it has to stay zero
233
+ refSeq: 0,
234
+ // If it's existing document and it has no schema, then it was written by legacy client.
235
+ // If it's a new document, then we define it's legacy-related behaviors.
236
+ runtime: {
237
+ explicitSchemaControl: boolToProp(!existing && features.explicitSchemaControl),
238
+ },
239
+ });
240
+ // Use legacy behavior only if both document and options tell us to use legacy.
241
+ // Otherwise it's no longer legacy time!
242
+ this.explicitSchemaControl =
243
+ this.documentSchema.runtime.explicitSchemaControl === true ||
244
+ features.explicitSchemaControl;
245
+ this.desiredSchema = {
246
+ version: currentDocumentVersionSchema,
247
+ refSeq: this.documentSchema.refSeq,
248
+ runtime: {
249
+ explicitSchemaControl: boolToProp(features.explicitSchemaControl),
250
+ compressionLz4: boolToProp(features.compressionLz4),
251
+ idCompressorMode: features.idCompressorMode,
252
+ opGroupingEnabled: boolToProp(features.opGroupingEnabled),
253
+ },
254
+ };
255
+ if (!this.explicitSchemaControl || !existing) {
256
+ this.sessionSchema = this.desiredSchema;
257
+ assert(boolToProp(this.explicitSchemaControl) ===
258
+ this.sessionSchema.runtime.explicitSchemaControl, "explicitSchemaControl");
259
+ this.futureSchema = undefined;
260
+ }
261
+ else {
262
+ this.sessionSchema = and(this.documentSchema, this.desiredSchema);
263
+ this.futureSchema = or(this.documentSchema, this.desiredSchema);
264
+ assert(this.sessionSchema.runtime.explicitSchemaControl === true, "legacy");
265
+ assert(this.futureSchema.runtime.explicitSchemaControl === true, "legacy");
266
+ if (same(this.documentSchema, this.futureSchema)) {
267
+ this.futureSchema = undefined;
268
+ }
269
+ }
270
+ // Validate that schema we are operating in is actually a schema we consider compatible with current runtime.
271
+ checkRuntimeCompatibility(this.sessionSchema);
272
+ checkRuntimeCompatibility(this.futureSchema);
273
+ }
274
+ summarizeDocumentSchema(refSeq) {
275
+ // For legacy behavior, we could write nothing (return undefined).
276
+ // It does not buy us anything, as whatever written in summary does not actually impact clients operating in legacy mode.
277
+ // But writing current used config (and assuming most of the clients settle on same config over time) will help with transition
278
+ // out of legacy mode, as clients transitioning out of it would be able to use all the
279
+ // features that are mentioned in schema right away, without a need to go through schema transition (and thus for a session or
280
+ // two losing ability to use all the features)
281
+ const schema = this.explicitSchemaControl ? this.documentSchema : this.desiredSchema;
282
+ // It's important to keep refSeq at zero in legacy mode, such that transition out of it is simple and we do not have
283
+ // race conditions. If we put any other number (including latest seq number), then we will have two clients
284
+ // (loading from two different summaries) with different numbers, and eventual consistency will be broken as schema
285
+ // change ops will be interpretted differently by those two clients.
286
+ assert(this.explicitSchemaControl || schema.refSeq === 0, "refSeq should be zero");
287
+ return schema;
288
+ }
289
+ onMessageSent(send) {
290
+ if (this.sendOp && this.futureSchema !== undefined) {
291
+ assert(this.explicitSchemaControl &&
292
+ this.futureSchema.runtime.explicitSchemaControl === true, "not legacy");
293
+ send({
294
+ ...this.futureSchema,
295
+ refSeq: this.documentSchema.refSeq,
296
+ });
297
+ }
298
+ this.sendOp = false;
299
+ }
300
+ /**
301
+ * Process document schema change message
302
+ * @param content - content of the message
303
+ * @param local - whether op is local
304
+ * @param sequenceNumber - sequence number of the op
305
+ * @returns - true if schema was accepted, otherwise false (rejected due to failed CAS)
306
+ */
307
+ processDocumentSchemaOp(content, local, sequenceNumber) {
308
+ assert(content.refSeq <= this.documentSchema.refSeq, "did we lose a message somewhere?");
309
+ assert(this.documentSchema.refSeq < sequenceNumber, "time should move forward only!");
310
+ if (content.refSeq !== this.documentSchema.refSeq) {
311
+ // CAS failed
312
+ return false;
313
+ }
314
+ // This assert should be after checking for successful CAS above.
315
+ // This will ensure we do not trip on our own messages that are no longer wanted as we processed someone else schema change message.
316
+ assert(!local || (this.explicitSchemaControl && this.futureSchema !== undefined), "not sending ops");
317
+ // Changes are in effect. Immediately check that this client understands these changes
318
+ checkRuntimeCompatibility(content);
319
+ const schema = { ...content, refSeq: sequenceNumber };
320
+ this.documentSchema = schema;
321
+ this.sessionSchema = and(this.documentSchema, this.desiredSchema);
322
+ // legacy behavior is automatically off for the document once someone sends a schema op -
323
+ // from now on it's fully controlled by ops.
324
+ // This is very important, as summarizeDocumentSchema() should use this new schema!
325
+ this.explicitSchemaControl = true;
326
+ // Stop attempting changing schema.
327
+ // If it was local op, then we succeeded and do not need to try again.
328
+ // If it was remote op, then some changes happened to schema.
329
+ // We would need to recalculate this.futureSchema by merging changes that we just received.
330
+ // Avoid this complexity for now - a new client session (loading from new summary with these changes)
331
+ // will automatically do this recalculation and will figure out
332
+ this.futureSchema = undefined;
333
+ this.onSchemaChange(this.sessionSchema);
334
+ return true;
335
+ }
336
+ onDisconnect() {
337
+ this.sendOp = true;
338
+ }
339
+ }
340
+ /* eslint-enable jsdoc/check-indentation */
341
+ //# sourceMappingURL=documentSchema.js.map