@fluidframework/container-runtime 2.13.0 → 2.21.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 (489) hide show
  1. package/.eslintrc.cjs +71 -5
  2. package/CHANGELOG.md +84 -0
  3. package/api-report/container-runtime.legacy.alpha.api.md +38 -232
  4. package/dist/batchTracker.d.ts +1 -2
  5. package/dist/batchTracker.d.ts.map +1 -1
  6. package/dist/batchTracker.js +1 -1
  7. package/dist/batchTracker.js.map +1 -1
  8. package/dist/blobManager/blobManager.d.ts +5 -1
  9. package/dist/blobManager/blobManager.d.ts.map +1 -1
  10. package/dist/blobManager/blobManager.js +30 -13
  11. package/dist/blobManager/blobManager.js.map +1 -1
  12. package/dist/blobManager/blobManagerSnapSum.d.ts +1 -0
  13. package/dist/blobManager/blobManagerSnapSum.d.ts.map +1 -1
  14. package/dist/blobManager/blobManagerSnapSum.js +7 -5
  15. package/dist/blobManager/blobManagerSnapSum.js.map +1 -1
  16. package/dist/channelCollection.d.ts +23 -12
  17. package/dist/channelCollection.d.ts.map +1 -1
  18. package/dist/channelCollection.js +85 -53
  19. package/dist/channelCollection.js.map +1 -1
  20. package/dist/connectionTelemetry.d.ts +2 -2
  21. package/dist/connectionTelemetry.d.ts.map +1 -1
  22. package/dist/connectionTelemetry.js +10 -6
  23. package/dist/connectionTelemetry.js.map +1 -1
  24. package/dist/containerHandleContext.d.ts +1 -1
  25. package/dist/containerHandleContext.d.ts.map +1 -1
  26. package/dist/containerHandleContext.js.map +1 -1
  27. package/dist/containerRuntime.d.ts +87 -94
  28. package/dist/containerRuntime.d.ts.map +1 -1
  29. package/dist/containerRuntime.js +312 -226
  30. package/dist/containerRuntime.js.map +1 -1
  31. package/dist/dataStore.d.ts +7 -3
  32. package/dist/dataStore.d.ts.map +1 -1
  33. package/dist/dataStore.js +8 -4
  34. package/dist/dataStore.js.map +1 -1
  35. package/dist/dataStoreContext.d.ts +41 -25
  36. package/dist/dataStoreContext.d.ts.map +1 -1
  37. package/dist/dataStoreContext.js +47 -29
  38. package/dist/dataStoreContext.js.map +1 -1
  39. package/dist/dataStoreContexts.d.ts +6 -2
  40. package/dist/dataStoreContexts.d.ts.map +1 -1
  41. package/dist/dataStoreContexts.js +7 -2
  42. package/dist/dataStoreContexts.js.map +1 -1
  43. package/dist/dataStoreRegistry.d.ts +1 -1
  44. package/dist/dataStoreRegistry.d.ts.map +1 -1
  45. package/dist/dataStoreRegistry.js.map +1 -1
  46. package/dist/deltaManagerProxies.d.ts +1 -17
  47. package/dist/deltaManagerProxies.d.ts.map +1 -1
  48. package/dist/deltaManagerProxies.js.map +1 -1
  49. package/dist/deltaScheduler.d.ts +9 -6
  50. package/dist/deltaScheduler.d.ts.map +1 -1
  51. package/dist/deltaScheduler.js +95 -89
  52. package/dist/deltaScheduler.js.map +1 -1
  53. package/dist/gc/garbageCollection.d.ts +21 -7
  54. package/dist/gc/garbageCollection.d.ts.map +1 -1
  55. package/dist/gc/garbageCollection.js +48 -19
  56. package/dist/gc/garbageCollection.js.map +1 -1
  57. package/dist/gc/gcConfigs.d.ts +11 -0
  58. package/dist/gc/gcConfigs.d.ts.map +1 -1
  59. package/dist/gc/gcConfigs.js +5 -2
  60. package/dist/gc/gcConfigs.js.map +1 -1
  61. package/dist/gc/gcDefinitions.d.ts +218 -70
  62. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  63. package/dist/gc/gcDefinitions.js +40 -13
  64. package/dist/gc/gcDefinitions.js.map +1 -1
  65. package/dist/gc/gcHelpers.d.ts +6 -2
  66. package/dist/gc/gcHelpers.d.ts.map +1 -1
  67. package/dist/gc/gcHelpers.js +14 -7
  68. package/dist/gc/gcHelpers.js.map +1 -1
  69. package/dist/gc/gcReferenceGraphAlgorithm.js.map +1 -1
  70. package/dist/gc/gcSummaryDefinitions.d.ts +18 -6
  71. package/dist/gc/gcSummaryDefinitions.d.ts.map +1 -1
  72. package/dist/gc/gcSummaryDefinitions.js.map +1 -1
  73. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  74. package/dist/gc/gcSummaryStateTracker.js +2 -1
  75. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  76. package/dist/gc/gcTelemetry.d.ts +33 -11
  77. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  78. package/dist/gc/gcTelemetry.js +35 -17
  79. package/dist/gc/gcTelemetry.js.map +1 -1
  80. package/dist/gc/gcUnreferencedStateTracker.d.ts +42 -13
  81. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
  82. package/dist/gc/gcUnreferencedStateTracker.js +27 -9
  83. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -1
  84. package/dist/gc/index.d.ts +1 -0
  85. package/dist/gc/index.d.ts.map +1 -1
  86. package/dist/gc/index.js +3 -1
  87. package/dist/gc/index.js.map +1 -1
  88. package/dist/inboundBatchAggregator.d.ts +34 -0
  89. package/dist/inboundBatchAggregator.d.ts.map +1 -0
  90. package/dist/inboundBatchAggregator.js +185 -0
  91. package/dist/inboundBatchAggregator.js.map +1 -0
  92. package/dist/index.d.ts +1 -1
  93. package/dist/index.d.ts.map +1 -1
  94. package/dist/index.js.map +1 -1
  95. package/dist/layerCompatState.d.ts +19 -0
  96. package/dist/layerCompatState.d.ts.map +1 -0
  97. package/dist/layerCompatState.js +64 -0
  98. package/dist/layerCompatState.js.map +1 -0
  99. package/dist/legacy.d.ts +0 -4
  100. package/dist/messageTypes.d.ts +14 -5
  101. package/dist/messageTypes.d.ts.map +1 -1
  102. package/dist/messageTypes.js.map +1 -1
  103. package/dist/metadata.d.ts +12 -4
  104. package/dist/metadata.d.ts.map +1 -1
  105. package/dist/metadata.js +6 -2
  106. package/dist/metadata.js.map +1 -1
  107. package/dist/opLifecycle/batchManager.d.ts +9 -3
  108. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  109. package/dist/opLifecycle/batchManager.js +3 -1
  110. package/dist/opLifecycle/batchManager.js.map +1 -1
  111. package/dist/opLifecycle/duplicateBatchDetector.d.ts +9 -3
  112. package/dist/opLifecycle/duplicateBatchDetector.d.ts.map +1 -1
  113. package/dist/opLifecycle/duplicateBatchDetector.js +11 -5
  114. package/dist/opLifecycle/duplicateBatchDetector.js.map +1 -1
  115. package/dist/opLifecycle/opCompressor.d.ts +3 -2
  116. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  117. package/dist/opLifecycle/opCompressor.js +13 -19
  118. package/dist/opLifecycle/opCompressor.js.map +1 -1
  119. package/dist/opLifecycle/opDecompressor.d.ts +6 -1
  120. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  121. package/dist/opLifecycle/opDecompressor.js +16 -8
  122. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  123. package/dist/opLifecycle/opGroupingManager.d.ts +1 -2
  124. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  125. package/dist/opLifecycle/opGroupingManager.js +9 -6
  126. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  127. package/dist/opLifecycle/opSplitter.d.ts +13 -10
  128. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  129. package/dist/opLifecycle/opSplitter.js +16 -11
  130. package/dist/opLifecycle/opSplitter.js.map +1 -1
  131. package/dist/opLifecycle/outbox.d.ts +4 -4
  132. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  133. package/dist/opLifecycle/outbox.js +17 -16
  134. package/dist/opLifecycle/outbox.js.map +1 -1
  135. package/dist/opLifecycle/remoteMessageProcessor.d.ts +9 -3
  136. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  137. package/dist/opLifecycle/remoteMessageProcessor.js +3 -1
  138. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  139. package/dist/package.json +2 -1
  140. package/dist/packageVersion.d.ts +1 -1
  141. package/dist/packageVersion.js +1 -1
  142. package/dist/packageVersion.js.map +1 -1
  143. package/dist/pendingStateManager.d.ts +22 -11
  144. package/dist/pendingStateManager.d.ts.map +1 -1
  145. package/dist/pendingStateManager.js +24 -15
  146. package/dist/pendingStateManager.js.map +1 -1
  147. package/dist/summary/documentSchema.d.ts +7 -0
  148. package/dist/summary/documentSchema.d.ts.map +1 -1
  149. package/dist/summary/documentSchema.js +8 -4
  150. package/dist/summary/documentSchema.js.map +1 -1
  151. package/dist/summary/index.d.ts +1 -1
  152. package/dist/summary/index.d.ts.map +1 -1
  153. package/dist/summary/index.js.map +1 -1
  154. package/dist/summary/orderedClientElection.d.ts +94 -31
  155. package/dist/summary/orderedClientElection.d.ts.map +1 -1
  156. package/dist/summary/orderedClientElection.js +28 -16
  157. package/dist/summary/orderedClientElection.js.map +1 -1
  158. package/dist/summary/runWhileConnectedCoordinator.d.ts +1 -0
  159. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -1
  160. package/dist/summary/runWhileConnectedCoordinator.js +7 -2
  161. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -1
  162. package/dist/summary/runningSummarizer.d.ts +17 -6
  163. package/dist/summary/runningSummarizer.d.ts.map +1 -1
  164. package/dist/summary/runningSummarizer.js +48 -19
  165. package/dist/summary/runningSummarizer.js.map +1 -1
  166. package/dist/summary/summarizer.d.ts +10 -5
  167. package/dist/summary/summarizer.d.ts.map +1 -1
  168. package/dist/summary/summarizer.js +26 -11
  169. package/dist/summary/summarizer.js.map +1 -1
  170. package/dist/summary/summarizerClientElection.d.ts.map +1 -1
  171. package/dist/summary/summarizerClientElection.js +1 -0
  172. package/dist/summary/summarizerClientElection.js.map +1 -1
  173. package/dist/summary/summarizerHeuristics.d.ts +6 -2
  174. package/dist/summary/summarizerHeuristics.d.ts.map +1 -1
  175. package/dist/summary/summarizerHeuristics.js +13 -5
  176. package/dist/summary/summarizerHeuristics.js.map +1 -1
  177. package/dist/summary/summarizerNode/index.d.ts.map +1 -1
  178. package/dist/summary/summarizerNode/index.js.map +1 -1
  179. package/dist/summary/summarizerNode/summarizerNode.d.ts +24 -8
  180. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  181. package/dist/summary/summarizerNode/summarizerNode.js +45 -36
  182. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  183. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +48 -16
  184. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  185. package/dist/summary/summarizerNode/summarizerNodeUtils.js +3 -1
  186. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  187. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +13 -5
  188. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  189. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +15 -7
  190. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  191. package/dist/summary/summarizerTypes.d.ts +253 -135
  192. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  193. package/dist/summary/summarizerTypes.js.map +1 -1
  194. package/dist/summary/summaryCollection.d.ts +3 -4
  195. package/dist/summary/summaryCollection.d.ts.map +1 -1
  196. package/dist/summary/summaryCollection.js +10 -8
  197. package/dist/summary/summaryCollection.js.map +1 -1
  198. package/dist/summary/summaryFormat.d.ts +28 -9
  199. package/dist/summary/summaryFormat.d.ts.map +1 -1
  200. package/dist/summary/summaryFormat.js +3 -2
  201. package/dist/summary/summaryFormat.js.map +1 -1
  202. package/dist/summary/summaryGenerator.d.ts +9 -3
  203. package/dist/summary/summaryGenerator.d.ts.map +1 -1
  204. package/dist/summary/summaryGenerator.js +22 -9
  205. package/dist/summary/summaryGenerator.js.map +1 -1
  206. package/dist/summary/summaryManager.d.ts +8 -4
  207. package/dist/summary/summaryManager.d.ts.map +1 -1
  208. package/dist/summary/summaryManager.js +20 -9
  209. package/dist/summary/summaryManager.js.map +1 -1
  210. package/dist/throttler.d.ts +26 -10
  211. package/dist/throttler.d.ts.map +1 -1
  212. package/dist/throttler.js +12 -4
  213. package/dist/throttler.js.map +1 -1
  214. package/lib/batchTracker.d.ts +1 -2
  215. package/lib/batchTracker.d.ts.map +1 -1
  216. package/lib/batchTracker.js +2 -2
  217. package/lib/batchTracker.js.map +1 -1
  218. package/lib/blobManager/blobManager.d.ts +5 -1
  219. package/lib/blobManager/blobManager.d.ts.map +1 -1
  220. package/lib/blobManager/blobManager.js +30 -13
  221. package/lib/blobManager/blobManager.js.map +1 -1
  222. package/lib/blobManager/blobManagerSnapSum.d.ts +1 -0
  223. package/lib/blobManager/blobManagerSnapSum.d.ts.map +1 -1
  224. package/lib/blobManager/blobManagerSnapSum.js +7 -5
  225. package/lib/blobManager/blobManagerSnapSum.js.map +1 -1
  226. package/lib/channelCollection.d.ts +23 -12
  227. package/lib/channelCollection.d.ts.map +1 -1
  228. package/lib/channelCollection.js +88 -54
  229. package/lib/channelCollection.js.map +1 -1
  230. package/lib/connectionTelemetry.d.ts +2 -2
  231. package/lib/connectionTelemetry.d.ts.map +1 -1
  232. package/lib/connectionTelemetry.js +11 -7
  233. package/lib/connectionTelemetry.js.map +1 -1
  234. package/lib/containerHandleContext.d.ts +1 -1
  235. package/lib/containerHandleContext.d.ts.map +1 -1
  236. package/lib/containerHandleContext.js.map +1 -1
  237. package/lib/containerRuntime.d.ts +87 -94
  238. package/lib/containerRuntime.d.ts.map +1 -1
  239. package/lib/containerRuntime.js +319 -228
  240. package/lib/containerRuntime.js.map +1 -1
  241. package/lib/dataStore.d.ts +7 -3
  242. package/lib/dataStore.d.ts.map +1 -1
  243. package/lib/dataStore.js +8 -4
  244. package/lib/dataStore.js.map +1 -1
  245. package/lib/dataStoreContext.d.ts +41 -25
  246. package/lib/dataStoreContext.d.ts.map +1 -1
  247. package/lib/dataStoreContext.js +47 -29
  248. package/lib/dataStoreContext.js.map +1 -1
  249. package/lib/dataStoreContexts.d.ts +6 -2
  250. package/lib/dataStoreContexts.d.ts.map +1 -1
  251. package/lib/dataStoreContexts.js +7 -2
  252. package/lib/dataStoreContexts.js.map +1 -1
  253. package/lib/dataStoreRegistry.d.ts +1 -1
  254. package/lib/dataStoreRegistry.d.ts.map +1 -1
  255. package/lib/dataStoreRegistry.js.map +1 -1
  256. package/lib/deltaManagerProxies.d.ts +1 -17
  257. package/lib/deltaManagerProxies.d.ts.map +1 -1
  258. package/lib/deltaManagerProxies.js.map +1 -1
  259. package/lib/deltaScheduler.d.ts +9 -6
  260. package/lib/deltaScheduler.d.ts.map +1 -1
  261. package/lib/deltaScheduler.js +96 -90
  262. package/lib/deltaScheduler.js.map +1 -1
  263. package/lib/gc/garbageCollection.d.ts +21 -7
  264. package/lib/gc/garbageCollection.d.ts.map +1 -1
  265. package/lib/gc/garbageCollection.js +51 -20
  266. package/lib/gc/garbageCollection.js.map +1 -1
  267. package/lib/gc/gcConfigs.d.ts +11 -0
  268. package/lib/gc/gcConfigs.d.ts.map +1 -1
  269. package/lib/gc/gcConfigs.js +4 -2
  270. package/lib/gc/gcConfigs.js.map +1 -1
  271. package/lib/gc/gcDefinitions.d.ts +218 -70
  272. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  273. package/lib/gc/gcDefinitions.js +40 -13
  274. package/lib/gc/gcDefinitions.js.map +1 -1
  275. package/lib/gc/gcHelpers.d.ts +6 -2
  276. package/lib/gc/gcHelpers.d.ts.map +1 -1
  277. package/lib/gc/gcHelpers.js +14 -7
  278. package/lib/gc/gcHelpers.js.map +1 -1
  279. package/lib/gc/gcReferenceGraphAlgorithm.js.map +1 -1
  280. package/lib/gc/gcSummaryDefinitions.d.ts +18 -6
  281. package/lib/gc/gcSummaryDefinitions.d.ts.map +1 -1
  282. package/lib/gc/gcSummaryDefinitions.js.map +1 -1
  283. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  284. package/lib/gc/gcSummaryStateTracker.js +2 -1
  285. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  286. package/lib/gc/gcTelemetry.d.ts +33 -11
  287. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  288. package/lib/gc/gcTelemetry.js +38 -18
  289. package/lib/gc/gcTelemetry.js.map +1 -1
  290. package/lib/gc/gcUnreferencedStateTracker.d.ts +42 -13
  291. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -1
  292. package/lib/gc/gcUnreferencedStateTracker.js +27 -9
  293. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -1
  294. package/lib/gc/index.d.ts +1 -0
  295. package/lib/gc/index.d.ts.map +1 -1
  296. package/lib/gc/index.js +1 -0
  297. package/lib/gc/index.js.map +1 -1
  298. package/lib/inboundBatchAggregator.d.ts +34 -0
  299. package/lib/inboundBatchAggregator.d.ts.map +1 -0
  300. package/lib/inboundBatchAggregator.js +181 -0
  301. package/lib/inboundBatchAggregator.js.map +1 -0
  302. package/lib/index.d.ts +1 -1
  303. package/lib/index.d.ts.map +1 -1
  304. package/lib/index.js.map +1 -1
  305. package/lib/layerCompatState.d.ts +19 -0
  306. package/lib/layerCompatState.d.ts.map +1 -0
  307. package/lib/layerCompatState.js +60 -0
  308. package/lib/layerCompatState.js.map +1 -0
  309. package/lib/legacy.d.ts +0 -4
  310. package/lib/messageTypes.d.ts +14 -5
  311. package/lib/messageTypes.d.ts.map +1 -1
  312. package/lib/messageTypes.js.map +1 -1
  313. package/lib/metadata.d.ts +12 -4
  314. package/lib/metadata.d.ts.map +1 -1
  315. package/lib/metadata.js +6 -2
  316. package/lib/metadata.js.map +1 -1
  317. package/lib/opLifecycle/batchManager.d.ts +9 -3
  318. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  319. package/lib/opLifecycle/batchManager.js +3 -1
  320. package/lib/opLifecycle/batchManager.js.map +1 -1
  321. package/lib/opLifecycle/duplicateBatchDetector.d.ts +9 -3
  322. package/lib/opLifecycle/duplicateBatchDetector.d.ts.map +1 -1
  323. package/lib/opLifecycle/duplicateBatchDetector.js +11 -5
  324. package/lib/opLifecycle/duplicateBatchDetector.js.map +1 -1
  325. package/lib/opLifecycle/opCompressor.d.ts +3 -2
  326. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  327. package/lib/opLifecycle/opCompressor.js +14 -20
  328. package/lib/opLifecycle/opCompressor.js.map +1 -1
  329. package/lib/opLifecycle/opDecompressor.d.ts +6 -1
  330. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  331. package/lib/opLifecycle/opDecompressor.js +17 -9
  332. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  333. package/lib/opLifecycle/opGroupingManager.d.ts +1 -2
  334. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  335. package/lib/opLifecycle/opGroupingManager.js +10 -7
  336. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  337. package/lib/opLifecycle/opSplitter.d.ts +13 -10
  338. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  339. package/lib/opLifecycle/opSplitter.js +16 -11
  340. package/lib/opLifecycle/opSplitter.js.map +1 -1
  341. package/lib/opLifecycle/outbox.d.ts +4 -4
  342. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  343. package/lib/opLifecycle/outbox.js +17 -16
  344. package/lib/opLifecycle/outbox.js.map +1 -1
  345. package/lib/opLifecycle/remoteMessageProcessor.d.ts +9 -3
  346. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  347. package/lib/opLifecycle/remoteMessageProcessor.js +3 -1
  348. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  349. package/lib/packageVersion.d.ts +1 -1
  350. package/lib/packageVersion.js +1 -1
  351. package/lib/packageVersion.js.map +1 -1
  352. package/lib/pendingStateManager.d.ts +22 -11
  353. package/lib/pendingStateManager.d.ts.map +1 -1
  354. package/lib/pendingStateManager.js +25 -16
  355. package/lib/pendingStateManager.js.map +1 -1
  356. package/lib/summary/documentSchema.d.ts +7 -0
  357. package/lib/summary/documentSchema.d.ts.map +1 -1
  358. package/lib/summary/documentSchema.js +8 -4
  359. package/lib/summary/documentSchema.js.map +1 -1
  360. package/lib/summary/index.d.ts +1 -1
  361. package/lib/summary/index.d.ts.map +1 -1
  362. package/lib/summary/index.js.map +1 -1
  363. package/lib/summary/orderedClientElection.d.ts +94 -31
  364. package/lib/summary/orderedClientElection.d.ts.map +1 -1
  365. package/lib/summary/orderedClientElection.js +28 -16
  366. package/lib/summary/orderedClientElection.js.map +1 -1
  367. package/lib/summary/runWhileConnectedCoordinator.d.ts +1 -0
  368. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -1
  369. package/lib/summary/runWhileConnectedCoordinator.js +7 -2
  370. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -1
  371. package/lib/summary/runningSummarizer.d.ts +17 -6
  372. package/lib/summary/runningSummarizer.d.ts.map +1 -1
  373. package/lib/summary/runningSummarizer.js +48 -19
  374. package/lib/summary/runningSummarizer.js.map +1 -1
  375. package/lib/summary/summarizer.d.ts +10 -5
  376. package/lib/summary/summarizer.d.ts.map +1 -1
  377. package/lib/summary/summarizer.js +26 -11
  378. package/lib/summary/summarizer.js.map +1 -1
  379. package/lib/summary/summarizerClientElection.d.ts.map +1 -1
  380. package/lib/summary/summarizerClientElection.js +1 -0
  381. package/lib/summary/summarizerClientElection.js.map +1 -1
  382. package/lib/summary/summarizerHeuristics.d.ts +6 -2
  383. package/lib/summary/summarizerHeuristics.d.ts.map +1 -1
  384. package/lib/summary/summarizerHeuristics.js +13 -5
  385. package/lib/summary/summarizerHeuristics.js.map +1 -1
  386. package/lib/summary/summarizerNode/index.d.ts.map +1 -1
  387. package/lib/summary/summarizerNode/index.js.map +1 -1
  388. package/lib/summary/summarizerNode/summarizerNode.d.ts +24 -8
  389. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  390. package/lib/summary/summarizerNode/summarizerNode.js +45 -36
  391. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  392. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +48 -16
  393. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
  394. package/lib/summary/summarizerNode/summarizerNodeUtils.js +3 -1
  395. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
  396. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +13 -5
  397. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  398. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +15 -7
  399. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  400. package/lib/summary/summarizerTypes.d.ts +253 -135
  401. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  402. package/lib/summary/summarizerTypes.js.map +1 -1
  403. package/lib/summary/summaryCollection.d.ts +3 -4
  404. package/lib/summary/summaryCollection.d.ts.map +1 -1
  405. package/lib/summary/summaryCollection.js +10 -8
  406. package/lib/summary/summaryCollection.js.map +1 -1
  407. package/lib/summary/summaryFormat.d.ts +28 -9
  408. package/lib/summary/summaryFormat.d.ts.map +1 -1
  409. package/lib/summary/summaryFormat.js +2 -2
  410. package/lib/summary/summaryFormat.js.map +1 -1
  411. package/lib/summary/summaryGenerator.d.ts +9 -3
  412. package/lib/summary/summaryGenerator.d.ts.map +1 -1
  413. package/lib/summary/summaryGenerator.js +22 -9
  414. package/lib/summary/summaryGenerator.js.map +1 -1
  415. package/lib/summary/summaryManager.d.ts +8 -4
  416. package/lib/summary/summaryManager.d.ts.map +1 -1
  417. package/lib/summary/summaryManager.js +20 -9
  418. package/lib/summary/summaryManager.js.map +1 -1
  419. package/lib/throttler.d.ts +26 -10
  420. package/lib/throttler.d.ts.map +1 -1
  421. package/lib/throttler.js +12 -4
  422. package/lib/throttler.js.map +1 -1
  423. package/package.json +22 -31
  424. package/src/batchTracker.ts +34 -36
  425. package/src/blobManager/blobManager.ts +54 -33
  426. package/src/blobManager/blobManagerSnapSum.ts +10 -10
  427. package/src/channelCollection.ts +108 -82
  428. package/src/connectionTelemetry.ts +43 -19
  429. package/src/containerHandleContext.ts +2 -2
  430. package/src/containerRuntime.ts +492 -364
  431. package/src/dataStore.ts +17 -9
  432. package/src/dataStoreContext.ts +94 -73
  433. package/src/dataStoreContexts.ts +17 -12
  434. package/src/dataStoreRegistry.ts +1 -1
  435. package/src/deltaManagerProxies.ts +5 -5
  436. package/src/deltaScheduler.ts +24 -18
  437. package/src/gc/garbageCollection.ts +89 -40
  438. package/src/gc/gcConfigs.ts +13 -5
  439. package/src/gc/gcDefinitions.ts +224 -70
  440. package/src/gc/gcHelpers.ts +22 -11
  441. package/src/gc/gcReferenceGraphAlgorithm.ts +1 -1
  442. package/src/gc/gcSummaryDefinitions.ts +18 -6
  443. package/src/gc/gcSummaryStateTracker.ts +7 -3
  444. package/src/gc/gcTelemetry.ts +73 -30
  445. package/src/gc/gcUnreferencedStateTracker.ts +40 -16
  446. package/src/gc/index.ts +1 -0
  447. package/src/{scheduleManager.ts → inboundBatchAggregator.ts} +55 -122
  448. package/src/index.ts +0 -3
  449. package/src/layerCompatState.ts +75 -0
  450. package/src/messageTypes.ts +16 -5
  451. package/src/metadata.ts +12 -4
  452. package/src/opLifecycle/README.md +43 -34
  453. package/src/opLifecycle/batchManager.ts +12 -6
  454. package/src/opLifecycle/duplicateBatchDetector.ts +12 -6
  455. package/src/opLifecycle/opCompressor.ts +22 -25
  456. package/src/opLifecycle/opDecompressor.ts +23 -11
  457. package/src/opLifecycle/opGroupingManager.ts +16 -11
  458. package/src/opLifecycle/opSplitter.ts +24 -18
  459. package/src/opLifecycle/outbox.ts +35 -33
  460. package/src/opLifecycle/remoteMessageProcessor.ts +13 -5
  461. package/src/packageVersion.ts +1 -1
  462. package/src/pendingStateManager.ts +49 -26
  463. package/src/summary/documentSchema.ts +41 -22
  464. package/src/summary/index.ts +0 -3
  465. package/src/summary/orderedClientElection.ts +114 -49
  466. package/src/summary/runWhileConnectedCoordinator.ts +12 -3
  467. package/src/summary/runningSummarizer.ts +79 -36
  468. package/src/summary/summarizer.ts +51 -25
  469. package/src/summary/summarizerClientElection.ts +4 -2
  470. package/src/summary/summarizerHeuristics.ts +23 -12
  471. package/src/summary/summarizerNode/index.ts +1 -0
  472. package/src/summary/summarizerNode/summarizerNode.ts +54 -43
  473. package/src/summary/summarizerNode/summarizerNodeUtils.ts +48 -16
  474. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +25 -15
  475. package/src/summary/summarizerTypes.ts +253 -139
  476. package/src/summary/summaryCollection.ts +41 -31
  477. package/src/summary/summaryFormat.ts +34 -13
  478. package/src/summary/summaryGenerator.ts +39 -18
  479. package/src/summary/summaryManager.ts +36 -24
  480. package/src/throttler.ts +23 -11
  481. package/container-runtime.test-files.tar +0 -0
  482. package/dist/scheduleManager.d.ts +0 -28
  483. package/dist/scheduleManager.d.ts.map +0 -1
  484. package/dist/scheduleManager.js +0 -233
  485. package/dist/scheduleManager.js.map +0 -1
  486. package/lib/scheduleManager.d.ts +0 -28
  487. package/lib/scheduleManager.d.ts.map +0 -1
  488. package/lib/scheduleManager.js +0 -229
  489. package/lib/scheduleManager.js.map +0 -1
@@ -26,15 +26,21 @@ class OrderedClientCollection extends client_utils_1.TypedEventEmitter {
26
26
  }
27
27
  constructor(logger, deltaManager, quorum) {
28
28
  super();
29
- /** Collection of ALL clients currently in the quorum, with client ids as keys. */
29
+ /**
30
+ * Collection of ALL clients currently in the quorum, with client ids as keys.
31
+ */
30
32
  this.clientMap = new Map();
31
- /** Placeholder head node of linked list, for simplified null checking. */
33
+ /**
34
+ * Placeholder head node of linked list, for simplified null checking.
35
+ */
32
36
  this.rootNode = {
33
37
  sequenceNumber: -1,
34
38
  olderClient: undefined,
35
39
  youngerClient: undefined,
36
40
  };
37
- /** Pointer to end of linked list, for optimized client adds. */
41
+ /**
42
+ * Pointer to end of linked list, for optimized client adds.
43
+ */
38
44
  this._youngestClient = this.rootNode;
39
45
  this.logger = (0, internal_2.createChildLogger)({ logger, namespace: "OrderedClientCollection" });
40
46
  const members = quorum.getMembers();
@@ -109,7 +115,9 @@ class OrderedClientCollection extends client_utils_1.TypedEventEmitter {
109
115
  this.clientMap.delete(clientId);
110
116
  return removeClient;
111
117
  }
112
- /** Returns an array of all clients being tracked in order from oldest to newest. */
118
+ /**
119
+ * Returns an array of all clients being tracked in order from oldest to newest.
120
+ */
113
121
  getAllClients() {
114
122
  const result = [];
115
123
  let currClient = this.rootNode;
@@ -177,7 +185,9 @@ class OrderedClientElection extends client_utils_1.TypedEventEmitter {
177
185
  return this._electedParent;
178
186
  }
179
187
  constructor(logger, orderedClientCollection,
180
- /** Serialized state from summary or current sequence number at time of load if new. */
188
+ /**
189
+ * Serialized state from summary or current sequence number at time of load if new.
190
+ */
181
191
  initialState, isEligibleFn, recordPerformanceEvents = false) {
182
192
  super();
183
193
  this.logger = logger;
@@ -320,21 +330,21 @@ class OrderedClientElection extends client_utils_1.TypedEventEmitter {
320
330
  this._eligibleCount--;
321
331
  if (this._electedClient === client) {
322
332
  // Removing the _electedClient. There are 2 possible cases:
323
- if (this._electedParent !== client) {
324
- // 1. The _electedClient is a summarizer that we've been allowing to finish its work.
333
+ if (this._electedParent === client) {
334
+ // 1. The _electedClient is an interactive client that has left the quorum.
335
+ // Automatically shift to next oldest client.
336
+ const nextClient = this.findFirstEligibleParent(this._electedParent?.youngerClient) ??
337
+ this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
338
+ this.tryElectingClient(nextClient, sequenceNumber, "RemoveClient");
339
+ }
340
+ else {
341
+ // 2. The _electedClient is a summarizer that we've been allowing to finish its work.
325
342
  // Let the _electedParent become the _electedClient so that it can start its own summarizer.
326
343
  if (this._electedClient.client.details.type !== summarizerClientElection_js_1.summarizerClientType) {
327
344
  throw new internal_2.UsageError("Elected client should be a summarizer client 1");
328
345
  }
329
346
  this.tryElectingClient(this._electedParent, sequenceNumber, "RemoveSummarizerClient");
330
347
  }
331
- else {
332
- // 2. The _electedClient is an interactive client that has left the quorum.
333
- // Automatically shift to next oldest client.
334
- const nextClient = this.findFirstEligibleParent(this._electedParent?.youngerClient) ??
335
- this.findFirstEligibleParent(this.orderedClientCollection.oldestClient);
336
- this.tryElectingClient(nextClient, sequenceNumber, "RemoveClient");
337
- }
338
348
  }
339
349
  else if (this._electedParent === client) {
340
350
  // Removing the _electedParent (but not _electedClient).
@@ -350,7 +360,9 @@ class OrderedClientElection extends client_utils_1.TypedEventEmitter {
350
360
  }
351
361
  }
352
362
  getAllEligibleClients() {
353
- return this.orderedClientCollection.getAllClients().filter(this.isEligibleFn);
363
+ return this.orderedClientCollection
364
+ .getAllClients()
365
+ .filter((client) => this.isEligibleFn(client));
354
366
  }
355
367
  /**
356
368
  * (Re-)start election with the oldest client in the quorum. This is called if we need to summarize
@@ -386,7 +398,7 @@ class OrderedClientElection extends client_utils_1.TypedEventEmitter {
386
398
  sequenceNumber,
387
399
  electedClientId: this.electedClient?.clientId,
388
400
  electedParentId: this.electedParent?.clientId,
389
- isEligible: client !== undefined ? this.isEligibleFn(client) : false,
401
+ isEligible: client === undefined ? false : this.isEligibleFn(client),
390
402
  isSummarizerClient: client?.client.details.type === summarizerClientElection_js_1.summarizerClientType,
391
403
  reason,
392
404
  });
@@ -1 +1 @@
1
- {"version":3,"file":"orderedClientElection.js","sourceRoot":"","sources":["../../src/summary/orderedClientElection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAA2C;AAE3C,+DAAiE;AAGjE,kEAA6D;AAE7D,uEAIkD;AAElD,+EAAqE;AA8DrE;;;;;;GAMG;AACH,MAAa,uBACZ,SAAQ,gCAAiD;IAezD,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC5B,CAAC;IACD,IAAW,YAAY;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;IACpC,CAAC;IAED,YACC,MAA4B,EAC5B,YAAyE,EACzE,MAAiD;QAEjD,KAAK,EAAE,CAAC;QAxBT,kFAAkF;QACjE,cAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;QAC9D,0EAA0E;QACzD,aAAQ,GAAkB;YAC1C,cAAc,EAAE,CAAC,CAAC;YAClB,WAAW,EAAE,SAAS;YACtB,aAAa,EAAE,SAAS;SACxB,CAAC;QAC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I,CAAC,uBAAuB,IAAI,SAAS,EAAE,CAAC;YAC/C,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;gBAChC,SAAS;gBACT,QAAQ,EAAE,MAAM,EAAE,QAAQ;gBAC1B,cAAc;gBACd,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,eAAe,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ;gBAC7C,UAAU,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK;gBACpE,kBAAkB,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,KAAK,kDAAoB;gBACxE,MAAM;aACN,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD;AAzVD,sDAyVC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @rushstack/no-new-null */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { IEvent, IEventProvider, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient, IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { summarizerClientType } from \"./summarizerClientElection.js\";\n\n// helper types for recursive readonly.\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type ImmutablePrimitives = undefined | null | boolean | string | number | Function;\nexport type Immutable<T> = T extends ImmutablePrimitives\n\t? T\n\t: T extends (infer A)[]\n\t\t? readonly Immutable<A>[]\n\t\t: T extends Map<infer K, infer V>\n\t\t\t? ReadonlyMap<Immutable<K>, Immutable<V>>\n\t\t\t: T extends Set<infer V>\n\t\t\t\t? ReadonlySet<Immutable<V>>\n\t\t\t\t: { readonly [K in keyof T]: Immutable<T[K]> };\n\n/** Minimum information for a client tracked for election consideration. */\nexport interface ITrackedClient {\n\treadonly clientId: string;\n\treadonly sequenceNumber: number;\n\treadonly client: Immutable<IClient>;\n}\n\n/** Common contract for link nodes within an OrderedClientCollection. */\nexport interface ILinkNode {\n\treadonly sequenceNumber: number;\n\tyoungerClient: ILinkedClient | undefined;\n}\n\n/** Placeholder root node within an OrderedClientCollection; does not represent a client. */\nexport interface IRootLinkNode extends ILinkNode {\n\treadonly sequenceNumber: -1;\n\treadonly olderClient: undefined;\n}\n\n/** Additional information required to keep track of the client within the doubly-linked list. */\nexport interface ILinkedClient extends ILinkNode, ITrackedClient {\n\tolderClient: LinkNode;\n}\n\n/** Any link node within OrderedClientCollection including the placeholder root node. */\nexport type LinkNode = IRootLinkNode | ILinkedClient;\n\n/** Events raised by an OrderedClientCollection. */\nexport interface IOrderedClientCollectionEvents extends IEvent {\n\t/** Event fires when client is being added. */\n\t(\n\t\tevent: \"addClient\" | \"removeClient\",\n\t\tlistener: (client: ILinkedClient, sequenceNumber: number) => void,\n\t);\n}\n\n/** Contract for a sorted collection of all clients in the quorum. */\nexport interface IOrderedClientCollection\n\textends IEventProvider<IOrderedClientCollectionEvents> {\n\t/** Count of clients in the collection. */\n\treadonly count: number;\n\t/** Pointer to the oldest client in the collection. */\n\treadonly oldestClient: ILinkedClient | undefined;\n\t/** Returns a sorted array of all the clients in the collection. */\n\tgetAllClients(): ILinkedClient[];\n}\n\n/**\n * Tracks clients in the Quorum. It maintains their order using their join op\n * sequence numbers.\n * Internally, the collection of clients is maintained in a doubly-linked list,\n * with pointers to both the first and last nodes.\n * The first (root) node is a placeholder to simplify logic and reduce null checking.\n */\nexport class OrderedClientCollection\n\textends TypedEventEmitter<IOrderedClientCollectionEvents>\n\timplements IOrderedClientCollection\n{\n\t/** Collection of ALL clients currently in the quorum, with client ids as keys. */\n\tprivate readonly clientMap = new Map<string, ILinkedClient>();\n\t/** Placeholder head node of linked list, for simplified null checking. */\n\tprivate readonly rootNode: IRootLinkNode = {\n\t\tsequenceNumber: -1,\n\t\tolderClient: undefined,\n\t\tyoungerClient: undefined,\n\t};\n\t/** Pointer to end of linked list, for optimized client adds. */\n\tprivate _youngestClient: LinkNode = this.rootNode;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic get count() {\n\t\treturn this.clientMap.size;\n\t}\n\tpublic get oldestClient() {\n\t\treturn this.rootNode.youngerClient;\n\t}\n\n\tconstructor(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tdeltaManager: Pick<IDeltaManager<unknown, unknown>, \"lastSequenceNumber\">,\n\t\tquorum: Pick<IQuorumClients, \"getMembers\" | \"on\">,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OrderedClientCollection\" });\n\t\tconst members = quorum.getMembers();\n\t\tfor (const [clientId, client] of members) {\n\t\t\tthis.addClient(clientId, client);\n\t\t}\n\n\t\tquorum.on(\"addMember\", (clientId, client) => {\n\t\t\tconst newClient = this.addClient(clientId, client);\n\t\t\tthis.emit(\"addClient\", newClient, deltaManager.lastSequenceNumber);\n\t\t});\n\t\tquorum.on(\"removeMember\", (clientId) => {\n\t\t\tconst sequenceNumber = deltaManager.lastSequenceNumber;\n\t\t\tconst removeClient = this.removeClient(clientId);\n\t\t\tif (removeClient === undefined) {\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"ClientNotFound\",\n\t\t\t\t\tclientId,\n\t\t\t\t\tsequenceNumber,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.emit(\"removeClient\", removeClient, sequenceNumber);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addClient(clientId: string, client: ISequencedClient): ITrackedClient {\n\t\t// Normal case is adding the latest client, which will bypass loop.\n\t\t// Find where it belongs otherwise (maybe possible during initial load?).\n\t\tassert(\n\t\t\tclient.sequenceNumber > -1,\n\t\t\t0x1f6 /* \"Negative client sequence number not allowed\" */,\n\t\t);\n\t\tlet currClient = this._youngestClient;\n\t\twhile (currClient.sequenceNumber > client.sequenceNumber) {\n\t\t\tassert(\n\t\t\t\tcurrClient.olderClient !== undefined,\n\t\t\t\t0x1f7 /* \"Previous client should always be defined\" */,\n\t\t\t);\n\t\t\t// Note: If adding a client older than the elected client, it will not be automatically elected.\n\t\t\tcurrClient = currClient.olderClient;\n\t\t}\n\n\t\t// Now currClient is the node right before where the new client node should be.\n\t\tconst newClient: ILinkedClient = {\n\t\t\tclientId,\n\t\t\tsequenceNumber: client.sequenceNumber,\n\t\t\tclient: { ...client.client }, // shallow clone\n\t\t\tolderClient: currClient,\n\t\t\tyoungerClient: currClient.youngerClient,\n\t\t};\n\n\t\t// Update prev node to point to this new node.\n\t\tnewClient.olderClient.youngerClient = newClient;\n\n\t\tif (newClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = newClient;\n\t\t} else {\n\t\t\t// Update next node to point back to this new node.\n\t\t\tnewClient.youngerClient.olderClient = newClient;\n\t\t}\n\n\t\tthis.clientMap.set(clientId, newClient);\n\t\treturn newClient;\n\t}\n\n\tprivate removeClient(clientId: string): ITrackedClient | undefined {\n\t\tconst removeClient = this.clientMap.get(clientId);\n\t\tif (removeClient === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update prev node to point to next node.\n\t\tremoveClient.olderClient.youngerClient = removeClient.youngerClient;\n\n\t\tif (removeClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = removeClient.olderClient;\n\t\t} else {\n\t\t\t// Update next node to point back to previous node.\n\t\t\tremoveClient.youngerClient.olderClient = removeClient.olderClient;\n\t\t}\n\n\t\tthis.clientMap.delete(clientId);\n\t\treturn removeClient;\n\t}\n\n\t/** Returns an array of all clients being tracked in order from oldest to newest. */\n\tpublic getAllClients(): ILinkedClient[] {\n\t\tconst result: ILinkedClient[] = [];\n\t\tlet currClient: LinkNode = this.rootNode;\n\t\twhile (currClient.youngerClient !== undefined) {\n\t\t\tresult.push(currClient.youngerClient);\n\t\t\tcurrClient = currClient.youngerClient;\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/** Events raised by an OrderedClientElection. */\nexport interface IOrderedClientElectionEvents extends IEvent {\n\t/** Event fires when the currently elected client changes. */\n\t(\n\t\tevent: \"election\",\n\t\tlistener: (\n\t\t\t/** Newly elected client. */\n\t\t\tclient: ITrackedClient | undefined,\n\t\t\t/** Sequence number where election took place. */\n\t\t\tsequenceNumber: number,\n\t\t\t/** Previously elected client. */\n\t\t\tprevClient: ITrackedClient | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Serialized state of IOrderedClientElection.\n * @legacy\n * @alpha\n */\nexport interface ISerializedElection {\n\t/** Sequence number at the time of the latest election. */\n\treadonly electionSequenceNumber: number;\n\n\t/**\n\t * Most recently elected client id. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClientId: string | undefined;\n\n\t/** Most recently elected parent client id. This is always an interactive client. */\n\treadonly electedParentId: string | undefined;\n}\n\n/** Contract for maintaining a deterministic client election based on eligibility. */\nexport interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {\n\t/** Count of eligible clients in the collection. */\n\treadonly eligibleCount: number;\n\n\t/**\n\t * Currently elected client. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClient: ITrackedClient | undefined;\n\t/** Currently elected parent client. This is always an interactive client. */\n\treadonly electedParent: ITrackedClient | undefined;\n\t/** Sequence number of most recent election. */\n\treadonly electionSequenceNumber: number;\n\t/** Resets the currently elected client back to the oldest eligible client. */\n\tresetElectedClient(sequenceNumber: number): void;\n\t/** Peeks at what the next elected client would be if incrementElectedClient were called. */\n\tpeekNextElectedClient(): ITrackedClient | undefined;\n\t/** Returns a sorted array of all the eligible clients in the collection. */\n\tgetAllEligibleClients(): ITrackedClient[];\n\t/** Serialize election data */\n\tserialize(): ISerializedElection;\n}\n\n/**\n * Adapter for OrderedClientCollection, with the purpose of deterministically maintaining\n * a currently elected client, excluding ineligible clients, in a distributed fashion.\n * This can be true as long as incrementElectedClient and resetElectedClient calls\n * are called under the same conditions for all clients.\n */\nexport class OrderedClientElection\n\textends TypedEventEmitter<IOrderedClientElectionEvents>\n\timplements IOrderedClientElection\n{\n\tprivate _eligibleCount: number = 0;\n\tprivate _electedClient: ILinkedClient | undefined;\n\tprivate _electedParent: ILinkedClient | undefined;\n\tprivate _electionSequenceNumber: number;\n\n\tpublic get eligibleCount() {\n\t\treturn this._eligibleCount;\n\t}\n\tpublic get electionSequenceNumber() {\n\t\treturn this._electionSequenceNumber;\n\t}\n\n\t/**\n\t * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case\n\t * where a new interactive parent client has been elected, but the summarizer is still doing work, so\n\t * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager\n\t * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has\n\t * left the quorum.\n\t *\n\t * Details:\n\t *\n\t * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest\n\t * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.\n\t * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that\n\t * it spawned stops producing summaries, at which point a new electedParent will be chosen.\n\t *\n\t * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to\n\t * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new\n\t * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until\n\t * electedClient leaves the quorum.\n\t *\n\t * A typical sequence looks like this:\n\t *\n\t * i. Begin by electing A. electedParent === A, electedClient === A.\n\t *\n\t * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'\n\t *\n\t * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'\n\t *\n\t * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'\n\t * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.\n\t *\n\t * v. A' completes its summary, and the summarizer and backing client are torn down.\n\t *\n\t * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B\n\t *\n\t * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'\n\t */\n\tpublic get electedClient() {\n\t\treturn this._electedClient;\n\t}\n\tpublic get electedParent() {\n\t\treturn this._electedParent;\n\t}\n\n\tconstructor(\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly orderedClientCollection: IOrderedClientCollection,\n\t\t/** Serialized state from summary or current sequence number at time of load if new. */\n\t\tinitialState: ISerializedElection | number,\n\t\tprivate readonly isEligibleFn: (c: ITrackedClient) => boolean,\n\t\tprivate readonly recordPerformanceEvents: boolean = false,\n\t) {\n\t\tsuper();\n\t\tlet initialClient: ILinkedClient | undefined;\n\t\tlet initialParent: ILinkedClient | undefined;\n\t\tfor (const client of orderedClientCollection.getAllClients()) {\n\t\t\tthis.addClient(client, 0);\n\t\t\tif (typeof initialState !== \"number\") {\n\t\t\t\tif (client.clientId === initialState.electedClientId) {\n\t\t\t\t\tinitialClient = client;\n\t\t\t\t\tif (\n\t\t\t\t\t\tinitialState.electedParentId === undefined &&\n\t\t\t\t\t\tclient.client.details.type !== summarizerClientType\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If there was no elected parent in the serialized data, use this one.\n\t\t\t\t\t\tinitialParent = client;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (client.clientId === initialState.electedParentId) {\n\t\t\t\t\tinitialParent = client;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\torderedClientCollection.on(\"addClient\", (client, seq) => this.addClient(client, seq));\n\t\torderedClientCollection.on(\"removeClient\", (client, seq) =>\n\t\t\tthis.removeClient(client, seq),\n\t\t);\n\n\t\tif (typeof initialState === \"number\") {\n\t\t\tthis._electionSequenceNumber = initialState;\n\t\t} else {\n\t\t\t// Override the initially elected client with the initial state.\n\t\t\tif (initialClient?.clientId !== initialState.electedClientId) {\n\t\t\t\t// Cannot find initially elected client, so elect undefined.\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientNotFound\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t\tclientCount: orderedClientCollection.count,\n\t\t\t\t});\n\t\t\t} else if (initialClient !== undefined && !isEligibleFn(initialClient)) {\n\t\t\t\t// Initially elected client is ineligible, so elect next eligible client.\n\t\t\t\tinitialClient = initialParent = this.findFirstEligibleParent(initialParent);\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientIneligible\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._electedParent = initialParent;\n\t\t\tthis._electedClient = initialClient;\n\t\t\tthis._electionSequenceNumber = initialState.electionSequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * Tries changing the elected client, raising an event if it is different.\n\t * Note that this function does no eligibility or suitability checks. If we get here, then\n\t * we will set _electedClient, and we will set _electedParent if this is an interactive client.\n\t */\n\tprivate tryElectingClient(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingClient\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tlet change = false;\n\t\tconst isSummarizerClient = client?.client.details.type === summarizerClientType;\n\t\tconst prevClient = this._electedClient;\n\t\tif (this._electedClient !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected client. Record the sequence number and note that we have to fire an event.\n\t\t\tthis._electionSequenceNumber = sequenceNumber;\n\t\t\tthis._electedClient = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (this._electedParent !== client && !isSummarizerClient) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"InteractiveClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected parent as well.\n\t\t\tthis._electedParent = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (change) {\n\t\t\tthis.emit(\"election\", client, sequenceNumber, prevClient);\n\t\t}\n\t}\n\n\tprivate tryElectingParent(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingParent\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tif (this._electedParent !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ParentElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\tthis._electedParent = client;\n\t\t\tthis.emit(\"election\", this._electedClient, sequenceNumber, this._electedClient);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to find the first eligible parent client starting with the passed in client,\n\t * or undefined if none are eligible.\n\t * @param client - client to start checking\n\t * @returns oldest eligible client starting with passed in client or undefined if none.\n\t */\n\tprivate findFirstEligibleParent(\n\t\tclient: ILinkedClient | undefined,\n\t): ILinkedClient | undefined {\n\t\tlet candidateClient = client;\n\t\twhile (\n\t\t\tcandidateClient !== undefined &&\n\t\t\t(!this.isEligibleFn(candidateClient) ||\n\t\t\t\tcandidateClient.client.details.type === summarizerClientType)\n\t\t) {\n\t\t\tcandidateClient = candidateClient.youngerClient;\n\t\t}\n\t\treturn candidateClient;\n\t}\n\n\t/**\n\t * Updates tracking for when a new client is added to the collection.\n\t * Will automatically elect that new client if none is elected currently.\n\t * @param client - client added to the collection\n\t * @param sequenceNumber - sequence number when client was added\n\t */\n\tprivate addClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"AddClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount++;\n\t\t\tconst newClientIsSummarizer = client.client.details.type === summarizerClientType;\n\t\t\tconst electedClientIsSummarizer =\n\t\t\t\tthis._electedClient?.client.details.type === summarizerClientType;\n\t\t\t// Note that we allow a summarizer client to supersede an interactive client as elected client.\n\t\t\tif (\n\t\t\t\tthis._electedClient === undefined ||\n\t\t\t\t(!electedClientIsSummarizer && newClientIsSummarizer)\n\t\t\t) {\n\t\t\t\tthis.tryElectingClient(client, sequenceNumber, \"AddClient\");\n\t\t\t} else if (this._electedParent === undefined && !newClientIsSummarizer) {\n\t\t\t\t// This is an odd case. If the _electedClient is set, the _electedParent should be as well.\n\t\t\t\tthis.tryElectingParent(client, sequenceNumber, \"AddClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates tracking for when an existing client is removed from the collection.\n\t * Will automatically elect next oldest client if currently elected is removed.\n\t * @param client - client removed from the collection\n\t * @param sequenceNumber - sequence number when client was removed\n\t */\n\tprivate removeClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"RemoveClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount--;\n\t\t\tif (this._electedClient === client) {\n\t\t\t\t// Removing the _electedClient. There are 2 possible cases:\n\t\t\t\tif (this._electedParent !== client) {\n\t\t\t\t\t// 1. The _electedClient is a summarizer that we've been allowing to finish its work.\n\t\t\t\t\t// Let the _electedParent become the _electedClient so that it can start its own summarizer.\n\t\t\t\t\tif (this._electedClient.client.details.type !== summarizerClientType) {\n\t\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 1\");\n\t\t\t\t\t}\n\t\t\t\t\tthis.tryElectingClient(\n\t\t\t\t\t\tthis._electedParent,\n\t\t\t\t\t\tsequenceNumber,\n\t\t\t\t\t\t\"RemoveSummarizerClient\",\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// 2. The _electedClient is an interactive client that has left the quorum.\n\t\t\t\t\t// Automatically shift to next oldest client.\n\t\t\t\t\tconst nextClient =\n\t\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\t\tthis.tryElectingClient(nextClient, sequenceNumber, \"RemoveClient\");\n\t\t\t\t}\n\t\t\t} else if (this._electedParent === client) {\n\t\t\t\t// Removing the _electedParent (but not _electedClient).\n\t\t\t\t// Shift to the next oldest parent, but do not replace the _electedClient,\n\t\t\t\t// which is a summarizer that is still doing work.\n\t\t\t\tif (this._electedClient?.client.details.type !== summarizerClientType) {\n\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 2\");\n\t\t\t\t}\n\t\t\t\tconst nextParent =\n\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\tthis.tryElectingParent(nextParent, sequenceNumber, \"RemoveClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getAllEligibleClients(): ITrackedClient[] {\n\t\treturn this.orderedClientCollection.getAllClients().filter(this.isEligibleFn);\n\t}\n\n\t/**\n\t * (Re-)start election with the oldest client in the quorum. This is called if we need to summarize\n\t * and no client has been elected.\n\t */\n\tpublic resetElectedClient(sequenceNumber: number): void {\n\t\tconst firstClient = this.findFirstEligibleParent(\n\t\t\tthis.orderedClientCollection.oldestClient,\n\t\t);\n\t\tif (this._electedClient === undefined || this._electedClient === this._electedParent) {\n\t\t\tthis.tryElectingClient(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t} else {\n\t\t\t// The _electedClient is a summarizer and should not be replaced until it leaves the quorum.\n\t\t\t// Changing the _electedParent will stop the summarizer.\n\t\t\tthis.tryElectingParent(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t}\n\t}\n\n\tpublic peekNextElectedClient(): ITrackedClient | undefined {\n\t\treturn (\n\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient)\n\t\t);\n\t}\n\n\tpublic serialize(): ISerializedElection {\n\t\treturn {\n\t\t\telectionSequenceNumber: this.electionSequenceNumber,\n\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t};\n\t}\n\n\tprivate sendPerformanceEvent(\n\t\teventName: string,\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\tforceSend: boolean = false,\n\t\treason?: string,\n\t) {\n\t\tif (this.recordPerformanceEvents || forceSend) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName,\n\t\t\t\tclientId: client?.clientId,\n\t\t\t\tsequenceNumber,\n\t\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t\t\tisEligible: client !== undefined ? this.isEligibleFn(client) : false,\n\t\t\t\tisSummarizerClient: client?.client.details.type === summarizerClientType,\n\t\t\t\treason,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C","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @rushstack/no-new-null */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { IEvent, IEventProvider, ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { IClient, IQuorumClients, ISequencedClient } from \"@fluidframework/driver-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tUsageError,\n\tcreateChildLogger,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { summarizerClientType } from \"./summarizerClientElection.js\";\n\n// helper types for recursive readonly.\n// eslint-disable-next-line @typescript-eslint/ban-types\nexport type ImmutablePrimitives = undefined | null | boolean | string | number | Function;\nexport type Immutable<T> = T extends ImmutablePrimitives\n\t? T\n\t: T extends (infer A)[]\n\t\t? readonly Immutable<A>[]\n\t\t: T extends Map<infer K, infer V>\n\t\t\t? ReadonlyMap<Immutable<K>, Immutable<V>>\n\t\t\t: T extends Set<infer V>\n\t\t\t\t? ReadonlySet<Immutable<V>>\n\t\t\t\t: { readonly [K in keyof T]: Immutable<T[K]> };\n\n/**\n * Minimum information for a client tracked for election consideration.\n */\nexport interface ITrackedClient {\n\treadonly clientId: string;\n\treadonly sequenceNumber: number;\n\treadonly client: Immutable<IClient>;\n}\n\n/**\n * Common contract for link nodes within an OrderedClientCollection.\n */\nexport interface ILinkNode {\n\treadonly sequenceNumber: number;\n\tyoungerClient: ILinkedClient | undefined;\n}\n\n/**\n * Placeholder root node within an OrderedClientCollection; does not represent a client.\n */\nexport interface IRootLinkNode extends ILinkNode {\n\treadonly sequenceNumber: -1;\n\treadonly olderClient: undefined;\n}\n\n/**\n * Additional information required to keep track of the client within the doubly-linked list.\n */\nexport interface ILinkedClient extends ILinkNode, ITrackedClient {\n\tolderClient: LinkNode;\n}\n\n/**\n * Any link node within OrderedClientCollection including the placeholder root node.\n */\nexport type LinkNode = IRootLinkNode | ILinkedClient;\n\n/**\n * Events raised by an OrderedClientCollection.\n */\nexport interface IOrderedClientCollectionEvents extends IEvent {\n\t/**\n\t * Event fires when client is being added.\n\t */\n\t(\n\t\tevent: \"addClient\" | \"removeClient\",\n\t\tlistener: (client: ILinkedClient, sequenceNumber: number) => void,\n\t);\n}\n\n/**\n * Contract for a sorted collection of all clients in the quorum.\n */\nexport interface IOrderedClientCollection\n\textends IEventProvider<IOrderedClientCollectionEvents> {\n\t/**\n\t * Count of clients in the collection.\n\t */\n\treadonly count: number;\n\t/**\n\t * Pointer to the oldest client in the collection.\n\t */\n\treadonly oldestClient: ILinkedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the clients in the collection.\n\t */\n\tgetAllClients(): ILinkedClient[];\n}\n\n/**\n * Tracks clients in the Quorum. It maintains their order using their join op\n * sequence numbers.\n * Internally, the collection of clients is maintained in a doubly-linked list,\n * with pointers to both the first and last nodes.\n * The first (root) node is a placeholder to simplify logic and reduce null checking.\n */\nexport class OrderedClientCollection\n\textends TypedEventEmitter<IOrderedClientCollectionEvents>\n\timplements IOrderedClientCollection\n{\n\t/**\n\t * Collection of ALL clients currently in the quorum, with client ids as keys.\n\t */\n\tprivate readonly clientMap = new Map<string, ILinkedClient>();\n\t/**\n\t * Placeholder head node of linked list, for simplified null checking.\n\t */\n\tprivate readonly rootNode: IRootLinkNode = {\n\t\tsequenceNumber: -1,\n\t\tolderClient: undefined,\n\t\tyoungerClient: undefined,\n\t};\n\t/**\n\t * Pointer to end of linked list, for optimized client adds.\n\t */\n\tprivate _youngestClient: LinkNode = this.rootNode;\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic get count(): number {\n\t\treturn this.clientMap.size;\n\t}\n\tpublic get oldestClient(): ILinkedClient | undefined {\n\t\treturn this.rootNode.youngerClient;\n\t}\n\n\tconstructor(\n\t\tlogger: ITelemetryBaseLogger,\n\t\tdeltaManager: Pick<IDeltaManager<unknown, unknown>, \"lastSequenceNumber\">,\n\t\tquorum: Pick<IQuorumClients, \"getMembers\" | \"on\">,\n\t) {\n\t\tsuper();\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OrderedClientCollection\" });\n\t\tconst members = quorum.getMembers();\n\t\tfor (const [clientId, client] of members) {\n\t\t\tthis.addClient(clientId, client);\n\t\t}\n\n\t\tquorum.on(\"addMember\", (clientId, client) => {\n\t\t\tconst newClient = this.addClient(clientId, client);\n\t\t\tthis.emit(\"addClient\", newClient, deltaManager.lastSequenceNumber);\n\t\t});\n\t\tquorum.on(\"removeMember\", (clientId) => {\n\t\t\tconst sequenceNumber = deltaManager.lastSequenceNumber;\n\t\t\tconst removeClient = this.removeClient(clientId);\n\t\t\tif (removeClient === undefined) {\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"ClientNotFound\",\n\t\t\t\t\tclientId,\n\t\t\t\t\tsequenceNumber,\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.emit(\"removeClient\", removeClient, sequenceNumber);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate addClient(clientId: string, client: ISequencedClient): ITrackedClient {\n\t\t// Normal case is adding the latest client, which will bypass loop.\n\t\t// Find where it belongs otherwise (maybe possible during initial load?).\n\t\tassert(\n\t\t\tclient.sequenceNumber > -1,\n\t\t\t0x1f6 /* \"Negative client sequence number not allowed\" */,\n\t\t);\n\t\tlet currClient = this._youngestClient;\n\t\twhile (currClient.sequenceNumber > client.sequenceNumber) {\n\t\t\tassert(\n\t\t\t\tcurrClient.olderClient !== undefined,\n\t\t\t\t0x1f7 /* \"Previous client should always be defined\" */,\n\t\t\t);\n\t\t\t// Note: If adding a client older than the elected client, it will not be automatically elected.\n\t\t\tcurrClient = currClient.olderClient;\n\t\t}\n\n\t\t// Now currClient is the node right before where the new client node should be.\n\t\tconst newClient: ILinkedClient = {\n\t\t\tclientId,\n\t\t\tsequenceNumber: client.sequenceNumber,\n\t\t\tclient: { ...client.client }, // shallow clone\n\t\t\tolderClient: currClient,\n\t\t\tyoungerClient: currClient.youngerClient,\n\t\t};\n\n\t\t// Update prev node to point to this new node.\n\t\tnewClient.olderClient.youngerClient = newClient;\n\n\t\tif (newClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = newClient;\n\t\t} else {\n\t\t\t// Update next node to point back to this new node.\n\t\t\tnewClient.youngerClient.olderClient = newClient;\n\t\t}\n\n\t\tthis.clientMap.set(clientId, newClient);\n\t\treturn newClient;\n\t}\n\n\tprivate removeClient(clientId: string): ITrackedClient | undefined {\n\t\tconst removeClient = this.clientMap.get(clientId);\n\t\tif (removeClient === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Update prev node to point to next node.\n\t\tremoveClient.olderClient.youngerClient = removeClient.youngerClient;\n\n\t\tif (removeClient.youngerClient === undefined) {\n\t\t\t// Update linked list end pointer to youngest client.\n\t\t\tthis._youngestClient = removeClient.olderClient;\n\t\t} else {\n\t\t\t// Update next node to point back to previous node.\n\t\t\tremoveClient.youngerClient.olderClient = removeClient.olderClient;\n\t\t}\n\n\t\tthis.clientMap.delete(clientId);\n\t\treturn removeClient;\n\t}\n\n\t/**\n\t * Returns an array of all clients being tracked in order from oldest to newest.\n\t */\n\tpublic getAllClients(): ILinkedClient[] {\n\t\tconst result: ILinkedClient[] = [];\n\t\tlet currClient: LinkNode = this.rootNode;\n\t\twhile (currClient.youngerClient !== undefined) {\n\t\t\tresult.push(currClient.youngerClient);\n\t\t\tcurrClient = currClient.youngerClient;\n\t\t}\n\t\treturn result;\n\t}\n}\n\n/**\n * Events raised by an OrderedClientElection.\n */\nexport interface IOrderedClientElectionEvents extends IEvent {\n\t/**\n\t * Event fires when the currently elected client changes.\n\t */\n\t(\n\t\tevent: \"election\",\n\t\tlistener: (\n\t\t\t/**\n\t\t\t * Newly elected client.\n\t\t\t */\n\t\t\tclient: ITrackedClient | undefined,\n\t\t\t/**\n\t\t\t * Sequence number where election took place.\n\t\t\t */\n\t\t\tsequenceNumber: number,\n\t\t\t/**\n\t\t\t * Previously elected client.\n\t\t\t */\n\t\t\tprevClient: ITrackedClient | undefined,\n\t\t) => void,\n\t);\n}\n\n/**\n * Serialized state of IOrderedClientElection.\n * @legacy\n * @alpha\n * @deprecated This type will be moved to internal in 2.30. External usage is not necessary or supported.\n */\nexport interface ISerializedElection {\n\t/**\n\t * Sequence number at the time of the latest election.\n\t */\n\treadonly electionSequenceNumber: number;\n\n\t/**\n\t * Most recently elected client id. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClientId: string | undefined;\n\n\t/**\n\t * Most recently elected parent client id. This is always an interactive client.\n\t */\n\treadonly electedParentId: string | undefined;\n}\n\n/**\n * Contract for maintaining a deterministic client election based on eligibility.\n */\nexport interface IOrderedClientElection extends IEventProvider<IOrderedClientElectionEvents> {\n\t/**\n\t * Count of eligible clients in the collection.\n\t */\n\treadonly eligibleCount: number;\n\n\t/**\n\t * Currently elected client. This is either:\n\t *\n\t * 1. the interactive elected parent client, in which case electedClientId === electedParentId,\n\t * and the SummaryManager on the elected client will spawn a summarizer client, or\n\t *\n\t * 2. the non-interactive summarizer client itself.\n\t */\n\treadonly electedClient: ITrackedClient | undefined;\n\t/**\n\t * Currently elected parent client. This is always an interactive client.\n\t */\n\treadonly electedParent: ITrackedClient | undefined;\n\t/**\n\t * Sequence number of most recent election.\n\t */\n\treadonly electionSequenceNumber: number;\n\t/**\n\t * Resets the currently elected client back to the oldest eligible client.\n\t */\n\tresetElectedClient(sequenceNumber: number): void;\n\t/**\n\t * Peeks at what the next elected client would be if incrementElectedClient were called.\n\t */\n\tpeekNextElectedClient(): ITrackedClient | undefined;\n\t/**\n\t * Returns a sorted array of all the eligible clients in the collection.\n\t */\n\tgetAllEligibleClients(): ITrackedClient[];\n\t/**\n\t * Serialize election data\n\t */\n\tserialize(): ISerializedElection;\n}\n\n/**\n * Adapter for OrderedClientCollection, with the purpose of deterministically maintaining\n * a currently elected client, excluding ineligible clients, in a distributed fashion.\n * This can be true as long as incrementElectedClient and resetElectedClient calls\n * are called under the same conditions for all clients.\n */\nexport class OrderedClientElection\n\textends TypedEventEmitter<IOrderedClientElectionEvents>\n\timplements IOrderedClientElection\n{\n\tprivate _eligibleCount: number = 0;\n\tprivate _electedClient: ILinkedClient | undefined;\n\tprivate _electedParent: ILinkedClient | undefined;\n\tprivate _electionSequenceNumber: number;\n\n\tpublic get eligibleCount(): number {\n\t\treturn this._eligibleCount;\n\t}\n\tpublic get electionSequenceNumber(): number {\n\t\treturn this._electionSequenceNumber;\n\t}\n\n\t/**\n\t * OrderedClientCollection tracks electedClient and electedParent separately. This allows us to handle the case\n\t * where a new interactive parent client has been elected, but the summarizer is still doing work, so\n\t * a new summarizer should not yet be spawned. In this case, changing electedParent will cause SummaryManager\n\t * to stop the current summarizer, but a new summarizer will not be spawned until the old summarizer client has\n\t * left the quorum.\n\t *\n\t * Details:\n\t *\n\t * electedParent is the interactive client that has been elected to spawn a summarizer. It is typically the oldest\n\t * eligible interactive client in the quorum. Only the electedParent is permitted to spawn a summarizer.\n\t * Once elected, this client will remain the electedParent until it leaves the quorum or the summarizer that\n\t * it spawned stops producing summaries, at which point a new electedParent will be chosen.\n\t *\n\t * electedClient is the non-interactive summarizer client if one exists. If not, then electedClient is equal to\n\t * electedParent. If electedParent === electedClient, this is the signal for electedParent to spawn a new\n\t * electedClient. Once a summarizer client becomes electedClient, a new summarizer will not be spawned until\n\t * electedClient leaves the quorum.\n\t *\n\t * A typical sequence looks like this:\n\t *\n\t * i. Begin by electing A. electedParent === A, electedClient === A.\n\t *\n\t * ii. SummaryManager running on A spawns a summarizer client, A'. electedParent === A, electedClient === A'\n\t *\n\t * iii. A' stops producing summaries. A new parent client, B, is elected. electedParent === B, electedClient === A'\n\t *\n\t * iv. SummaryManager running on A detects the change to electedParent and tells the summarizer to stop, but A'\n\t * is in mid-summarization. No new summarizer is spawned, as electedParent !== electedClient.\n\t *\n\t * v. A' completes its summary, and the summarizer and backing client are torn down.\n\t *\n\t * vi. A' leaves the quorum, and B takes its place as electedClient. electedParent === B, electedClient === B\n\t *\n\t * vii. SummaryManager running on B spawns a summarizer client, B'. electedParent === B, electedClient === B'\n\t */\n\tpublic get electedClient(): ILinkedClient | undefined {\n\t\treturn this._electedClient;\n\t}\n\tpublic get electedParent(): ILinkedClient | undefined {\n\t\treturn this._electedParent;\n\t}\n\n\tconstructor(\n\t\tprivate readonly logger: ITelemetryLoggerExt,\n\t\tprivate readonly orderedClientCollection: IOrderedClientCollection,\n\t\t/**\n\t\t * Serialized state from summary or current sequence number at time of load if new.\n\t\t */\n\t\tinitialState: ISerializedElection | number,\n\t\tprivate readonly isEligibleFn: (c: ITrackedClient) => boolean,\n\t\tprivate readonly recordPerformanceEvents: boolean = false,\n\t) {\n\t\tsuper();\n\t\tlet initialClient: ILinkedClient | undefined;\n\t\tlet initialParent: ILinkedClient | undefined;\n\t\tfor (const client of orderedClientCollection.getAllClients()) {\n\t\t\tthis.addClient(client, 0);\n\t\t\tif (typeof initialState !== \"number\") {\n\t\t\t\tif (client.clientId === initialState.electedClientId) {\n\t\t\t\t\tinitialClient = client;\n\t\t\t\t\tif (\n\t\t\t\t\t\tinitialState.electedParentId === undefined &&\n\t\t\t\t\t\tclient.client.details.type !== summarizerClientType\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If there was no elected parent in the serialized data, use this one.\n\t\t\t\t\t\tinitialParent = client;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (client.clientId === initialState.electedParentId) {\n\t\t\t\t\tinitialParent = client;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\torderedClientCollection.on(\"addClient\", (client, seq) => this.addClient(client, seq));\n\t\torderedClientCollection.on(\"removeClient\", (client, seq) =>\n\t\t\tthis.removeClient(client, seq),\n\t\t);\n\n\t\tif (typeof initialState === \"number\") {\n\t\t\tthis._electionSequenceNumber = initialState;\n\t\t} else {\n\t\t\t// Override the initially elected client with the initial state.\n\t\t\tif (initialClient?.clientId !== initialState.electedClientId) {\n\t\t\t\t// Cannot find initially elected client, so elect undefined.\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientNotFound\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t\tclientCount: orderedClientCollection.count,\n\t\t\t\t});\n\t\t\t} else if (initialClient !== undefined && !isEligibleFn(initialClient)) {\n\t\t\t\t// Initially elected client is ineligible, so elect next eligible client.\n\t\t\t\tinitialClient = initialParent = this.findFirstEligibleParent(initialParent);\n\t\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"InitialElectedClientIneligible\",\n\t\t\t\t\telectionSequenceNumber: initialState.electionSequenceNumber,\n\t\t\t\t\texpectedClientId: initialState.electedClientId,\n\t\t\t\t\telectedClientId: initialClient?.clientId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis._electedParent = initialParent;\n\t\t\tthis._electedClient = initialClient;\n\t\t\tthis._electionSequenceNumber = initialState.electionSequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * Tries changing the elected client, raising an event if it is different.\n\t * Note that this function does no eligibility or suitability checks. If we get here, then\n\t * we will set _electedClient, and we will set _electedParent if this is an interactive client.\n\t */\n\tprivate tryElectingClient(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingClient\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tlet change = false;\n\t\tconst isSummarizerClient = client?.client.details.type === summarizerClientType;\n\t\tconst prevClient = this._electedClient;\n\t\tif (this._electedClient !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected client. Record the sequence number and note that we have to fire an event.\n\t\t\tthis._electionSequenceNumber = sequenceNumber;\n\t\t\tthis._electedClient = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (this._electedParent !== client && !isSummarizerClient) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"InteractiveClientElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\t// Changing the elected parent as well.\n\t\t\tthis._electedParent = client;\n\t\t\tchange = true;\n\t\t}\n\t\tif (change) {\n\t\t\tthis.emit(\"election\", client, sequenceNumber, prevClient);\n\t\t}\n\t}\n\n\tprivate tryElectingParent(\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\treason: string,\n\t): void {\n\t\tthis.sendPerformanceEvent(\n\t\t\t\"TryElectingParent\",\n\t\t\tclient,\n\t\t\tsequenceNumber,\n\t\t\tfalse /* forceSend */,\n\t\t\treason,\n\t\t);\n\t\tif (this._electedParent !== client) {\n\t\t\tthis.sendPerformanceEvent(\n\t\t\t\t\"ParentElected\",\n\t\t\t\tclient,\n\t\t\t\tsequenceNumber,\n\t\t\t\ttrue /* forceSend */,\n\t\t\t\treason,\n\t\t\t);\n\t\t\tthis._electedParent = client;\n\t\t\tthis.emit(\"election\", this._electedClient, sequenceNumber, this._electedClient);\n\t\t}\n\t}\n\n\t/**\n\t * Helper function to find the first eligible parent client starting with the passed in client,\n\t * or undefined if none are eligible.\n\t * @param client - client to start checking\n\t * @returns oldest eligible client starting with passed in client or undefined if none.\n\t */\n\tprivate findFirstEligibleParent(\n\t\tclient: ILinkedClient | undefined,\n\t): ILinkedClient | undefined {\n\t\tlet candidateClient = client;\n\t\twhile (\n\t\t\tcandidateClient !== undefined &&\n\t\t\t(!this.isEligibleFn(candidateClient) ||\n\t\t\t\tcandidateClient.client.details.type === summarizerClientType)\n\t\t) {\n\t\t\tcandidateClient = candidateClient.youngerClient;\n\t\t}\n\t\treturn candidateClient;\n\t}\n\n\t/**\n\t * Updates tracking for when a new client is added to the collection.\n\t * Will automatically elect that new client if none is elected currently.\n\t * @param client - client added to the collection\n\t * @param sequenceNumber - sequence number when client was added\n\t */\n\tprivate addClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"AddClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount++;\n\t\t\tconst newClientIsSummarizer = client.client.details.type === summarizerClientType;\n\t\t\tconst electedClientIsSummarizer =\n\t\t\t\tthis._electedClient?.client.details.type === summarizerClientType;\n\t\t\t// Note that we allow a summarizer client to supersede an interactive client as elected client.\n\t\t\tif (\n\t\t\t\tthis._electedClient === undefined ||\n\t\t\t\t(!electedClientIsSummarizer && newClientIsSummarizer)\n\t\t\t) {\n\t\t\t\tthis.tryElectingClient(client, sequenceNumber, \"AddClient\");\n\t\t\t} else if (this._electedParent === undefined && !newClientIsSummarizer) {\n\t\t\t\t// This is an odd case. If the _electedClient is set, the _electedParent should be as well.\n\t\t\t\tthis.tryElectingParent(client, sequenceNumber, \"AddClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Updates tracking for when an existing client is removed from the collection.\n\t * Will automatically elect next oldest client if currently elected is removed.\n\t * @param client - client removed from the collection\n\t * @param sequenceNumber - sequence number when client was removed\n\t */\n\tprivate removeClient(client: ILinkedClient, sequenceNumber: number): void {\n\t\tthis.sendPerformanceEvent(\"RemoveClient\", client, sequenceNumber);\n\t\tif (this.isEligibleFn(client)) {\n\t\t\tthis._eligibleCount--;\n\t\t\tif (this._electedClient === client) {\n\t\t\t\t// Removing the _electedClient. There are 2 possible cases:\n\t\t\t\tif (this._electedParent === client) {\n\t\t\t\t\t// 1. The _electedClient is an interactive client that has left the quorum.\n\t\t\t\t\t// Automatically shift to next oldest client.\n\t\t\t\t\tconst nextClient =\n\t\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\t\tthis.tryElectingClient(nextClient, sequenceNumber, \"RemoveClient\");\n\t\t\t\t} else {\n\t\t\t\t\t// 2. The _electedClient is a summarizer that we've been allowing to finish its work.\n\t\t\t\t\t// Let the _electedParent become the _electedClient so that it can start its own summarizer.\n\t\t\t\t\tif (this._electedClient.client.details.type !== summarizerClientType) {\n\t\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 1\");\n\t\t\t\t\t}\n\t\t\t\t\tthis.tryElectingClient(\n\t\t\t\t\t\tthis._electedParent,\n\t\t\t\t\t\tsequenceNumber,\n\t\t\t\t\t\t\"RemoveSummarizerClient\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else if (this._electedParent === client) {\n\t\t\t\t// Removing the _electedParent (but not _electedClient).\n\t\t\t\t// Shift to the next oldest parent, but do not replace the _electedClient,\n\t\t\t\t// which is a summarizer that is still doing work.\n\t\t\t\tif (this._electedClient?.client.details.type !== summarizerClientType) {\n\t\t\t\t\tthrow new UsageError(\"Elected client should be a summarizer client 2\");\n\t\t\t\t}\n\t\t\t\tconst nextParent =\n\t\t\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient);\n\t\t\t\tthis.tryElectingParent(nextParent, sequenceNumber, \"RemoveClient\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic getAllEligibleClients(): ITrackedClient[] {\n\t\treturn this.orderedClientCollection\n\t\t\t.getAllClients()\n\t\t\t.filter((client) => this.isEligibleFn(client));\n\t}\n\n\t/**\n\t * (Re-)start election with the oldest client in the quorum. This is called if we need to summarize\n\t * and no client has been elected.\n\t */\n\tpublic resetElectedClient(sequenceNumber: number): void {\n\t\tconst firstClient = this.findFirstEligibleParent(\n\t\t\tthis.orderedClientCollection.oldestClient,\n\t\t);\n\t\tif (this._electedClient === undefined || this._electedClient === this._electedParent) {\n\t\t\tthis.tryElectingClient(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t} else {\n\t\t\t// The _electedClient is a summarizer and should not be replaced until it leaves the quorum.\n\t\t\t// Changing the _electedParent will stop the summarizer.\n\t\t\tthis.tryElectingParent(firstClient, sequenceNumber, \"ResetElectedClient\");\n\t\t}\n\t}\n\n\tpublic peekNextElectedClient(): ITrackedClient | undefined {\n\t\treturn (\n\t\t\tthis.findFirstEligibleParent(this._electedParent?.youngerClient) ??\n\t\t\tthis.findFirstEligibleParent(this.orderedClientCollection.oldestClient)\n\t\t);\n\t}\n\n\tpublic serialize(): ISerializedElection {\n\t\treturn {\n\t\t\telectionSequenceNumber: this.electionSequenceNumber,\n\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t};\n\t}\n\n\tprivate sendPerformanceEvent(\n\t\teventName: string,\n\t\tclient: ILinkedClient | undefined,\n\t\tsequenceNumber: number,\n\t\tforceSend: boolean = false,\n\t\treason?: string,\n\t): void {\n\t\tif (this.recordPerformanceEvents || forceSend) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName,\n\t\t\t\tclientId: client?.clientId,\n\t\t\t\tsequenceNumber,\n\t\t\t\telectedClientId: this.electedClient?.clientId,\n\t\t\t\telectedParentId: this.electedParent?.clientId,\n\t\t\t\tisEligible: client === undefined ? false : this.isEligibleFn(client),\n\t\t\t\tisSummarizerClient: client?.client.details.type === summarizerClientType,\n\t\t\t\treason,\n\t\t\t});\n\t\t}\n\t}\n}\n"]}
@@ -8,6 +8,7 @@ import { IConnectableRuntime, ISummaryCancellationToken } from "./summarizerType
8
8
  * Similar to AbortController, but using promise instead of events
9
9
  * @legacy
10
10
  * @alpha
11
+ * @deprecated This type will be moved to internal in 2.30. External usage is not necessary or supported.
11
12
  */
12
13
  export interface ICancellableSummarizerController extends ISummaryCancellationToken {
13
14
  stop(reason: SummarizerStopReason): void;
@@ -1 +1 @@
1
- {"version":3,"file":"runWhileConnectedCoordinator.d.ts","sourceRoot":"","sources":["../../src/summary/runWhileConnectedCoordinator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAGnG,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;;;GAIG;AACH,MAAM,WAAW,gCAAiC,SAAQ,yBAAyB;IAClF,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACzC;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,yBAGxC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,4BAA6B,YAAW,gCAAgC;IAsCnF,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAtCxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwC;IAErE,IAAW,SAAS,YAkBnB;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAExD;WAEmB,MAAM,CAAC,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,OAAO;IAM9E,SAAS,aACS,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,MAAM,OAAO;IAGvC;;;;;;;;;;;;OAYG;cACa,SAAS;IAiBzB;;OAEG;IACI,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;CAM/C"}
1
+ {"version":3,"file":"runWhileConnectedCoordinator.d.ts","sourceRoot":"","sources":["../../src/summary/runWhileConnectedCoordinator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wDAAwD,CAAC;AAInG,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;;;;GAKG;AAEH,MAAM,WAAW,gCAAiC,SAAQ,yBAAyB;IAClF,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACzC;AAED;;;;GAIG;AAEH,eAAO,MAAM,0BAA0B,EAAE,yBAGxC,CAAC;AAEF;;;;GAIG;AACH,qBAAa,4BAA6B,YAAW,gCAAgC;IA2CnF,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IA3CxB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAwC;IAErE,IAAW,SAAS,IAAI,OAAO,CAkB9B;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAExD;WAEmB,MAAM,CAEzB,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,MAAM,OAAO,GACnB,OAAO,CAAC,4BAA4B,CAAC;IAMxC,SAAS,aAES,OAAO,EAAE,mBAAmB,EAC5B,MAAM,EAAE,MAAM,OAAO;IAGvC;;;;;;;;;;;;OAYG;cACa,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB1C;;OAEG;IACI,IAAI,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI;CAM/C"}
@@ -11,6 +11,7 @@ const internal_1 = require("@fluidframework/core-utils/internal");
11
11
  * This object implements ISummaryCancellationToken interface but cancellation is never leveraged.
12
12
  * @internal
13
13
  */
14
+ // eslint-disable-next-line import/no-deprecated
14
15
  exports.neverCancelledSummaryToken = {
15
16
  cancelled: false,
16
17
  waitCancelled: new Promise(() => { }),
@@ -44,12 +45,16 @@ class RunWhileConnectedCoordinator {
44
45
  get waitCancelled() {
45
46
  return this.stopDeferred.promise;
46
47
  }
47
- static async create(runtime, active) {
48
+ static async create(
49
+ // eslint-disable-next-line import/no-deprecated
50
+ runtime, active) {
48
51
  const obj = new RunWhileConnectedCoordinator(runtime, active);
49
52
  await obj.waitStart();
50
53
  return obj;
51
54
  }
52
- constructor(runtime, active) {
55
+ constructor(
56
+ // eslint-disable-next-line import/no-deprecated
57
+ runtime, active) {
53
58
  this.runtime = runtime;
54
59
  this.active = active;
55
60
  this._cancelled = false;
@@ -1 +1 @@
1
- {"version":3,"file":"runWhileConnectedCoordinator.js","sourceRoot":"","sources":["../../src/summary/runWhileConnectedCoordinator.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAAuE;AAavE;;;;GAIG;AACU,QAAA,0BAA0B,GAA8B;IACpE,SAAS,EAAE,KAAK;IAChB,aAAa,EAAE,IAAI,OAAO,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;CACpC,CAAC;AAEF;;;;GAIG;AACH,MAAa,4BAA4B;IAIxC,IAAW,SAAS;QACnB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,IAAA,iBAAM,EAAC,IAAI,CAAC,MAAM,EAAE,EAAE,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAEvE,+EAA+E;YAC/E,iFAAiF;YACjF,4EAA4E;YAC5E,oCAAoC;YACpC,6CAA6C;YAC7C,mGAAmG;YACnG,yBAAyB;YACzB,oFAAoF;YACpF,EAAE;YACF,wEAAwE;YACxE,uFAAuF;QACxF,CAAC;QAED,OAAO,IAAI,CAAC,UAAU,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;IAClC,CAAC;IAEM,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,OAA4B,EAAE,MAAqB;QAC7E,MAAM,GAAG,GAAG,IAAI,4BAA4B,CA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nC,CAAC;IACF,CAAC;CACD;AAjFD,oEAiFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { SummarizerStopReason } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\n\nimport { IConnectableRuntime, ISummaryCancellationToken } from \"./summarizerTypes.js\";\n\n/**\n * Similar to AbortController, but using promise instead of events\n * @legacy\n * @alpha\n */\nexport interface ICancellableSummarizerController extends ISummaryCancellationToken {\n\tstop(reason: SummarizerStopReason): void;\n}\n\n/**\n * Can be useful in testing as well as in places where caller does not use cancellation.\n * This object implements ISummaryCancellationToken interface but cancellation is never leveraged.\n * @internal\n */\nexport const neverCancelledSummaryToken: ISummaryCancellationToken = {\n\tcancelled: false,\n\twaitCancelled: new Promise(() => {}),\n};\n\n/**\n * Helper class to coordinate something that needs to run only while connected.\n * This provides promises that resolve as it starts or stops. Stopping happens\n * when disconnected or if stop() is called.\n */\nexport class RunWhileConnectedCoordinator implements ICancellableSummarizerController {\n\tprivate _cancelled = false;\n\tprivate readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n\tpublic get cancelled() {\n\t\tif (!this._cancelled) {\n\t\t\tassert(this.active(), 0x25d /* \"We should never connect as 'read'\" */);\n\n\t\t\t// This check can't be enabled in current design due to lastSummary flow, where\n\t\t\t// summarizer for closed container stays around and can produce one more summary.\n\t\t\t// Currently we solve the problem of overlapping summarizer by doing wait in\n\t\t\t// SummaryManager.createSummarizer()\n\t\t\t// Better solution would involve these steps:\n\t\t\t// 1. Summarizer selection logic should chose summarizing client (with clientType === \"summarizer\")\n\t\t\t// if such client exists.\n\t\t\t// 2. Summarizer should be updated about such changes (to update onBehalfOfClientId)\n\t\t\t//\n\t\t\t// assert(this.runtime.summarizerClientId === this.onBehalfOfClientId ||\n\t\t\t// this.runtime.summarizerClientId === this.runtime.clientId, \"onBehalfOfClientId\");\n\t\t}\n\n\t\treturn this._cancelled;\n\t}\n\n\t/**\n\t * Returns a promise that resolves once stopped either externally or by disconnect.\n\t */\n\tpublic get waitCancelled(): Promise<SummarizerStopReason> {\n\t\treturn this.stopDeferred.promise;\n\t}\n\n\tpublic static async create(runtime: IConnectableRuntime, active: () => boolean) {\n\t\tconst obj = new RunWhileConnectedCoordinator(runtime, active);\n\t\tawait obj.waitStart();\n\t\treturn obj;\n\t}\n\n\tprotected constructor(\n\t\tprivate readonly runtime: IConnectableRuntime,\n\t\tprivate readonly active: () => boolean,\n\t) {}\n\n\t/**\n\t * Starts and waits for a promise which resolves when connected.\n\t * The promise will also resolve if stopped either externally or by disconnect.\n\t *\n\t * We only listen on disconnected event for clientType === \"summarizer\" container!\n\t * And only do it here - no other place should check it! That way we have only one place\n\t * that controls policy and it's easy to change policy in the future if we want to!\n\t * We do not listen for \"main\" (aka interactive) container disconnect here, as it's\n\t * responsibility of SummaryManager to decide if that's material or not. There are cases\n\t * like \"lastSummary\", or main client experiencing nacks / disconnects due to hitting limit\n\t * of non-summarized ops, where can make determination to continue with summary even if main\n\t * client is disconnected.\n\t */\n\tprotected async waitStart() {\n\t\tif (this.runtime.disposed) {\n\t\t\tthis.stop(\"summarizerClientDisconnected\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.once(\"dispose\", () => this.stop(\"summarizerClientDisconnected\"));\n\n\t\tif (!this.runtime.connected) {\n\t\t\tconst waitConnected = new Promise<void>((resolve) =>\n\t\t\t\tthis.runtime.once(\"connected\", resolve),\n\t\t\t);\n\t\t\tawait Promise.race([waitConnected, this.waitCancelled]);\n\t\t}\n\t\tthis.runtime.once(\"disconnected\", () => this.stop(\"summarizerClientDisconnected\"));\n\t}\n\n\t/**\n\t * Stops running.\n\t */\n\tpublic stop(reason: SummarizerStopReason): void {\n\t\tif (!this._cancelled) {\n\t\t\tthis._cancelled = true;\n\t\t\tthis.stopDeferred.resolve(reason);\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"runWhileConn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,CAAC,SAAS;QACxB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC1C,OAAO;QACR,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;QAE9E,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC7B,MAAM,aAAa,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CACnD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CACvC,CAAC;YACF,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IACpF,CAAC;IAED;;OAEG;IACI,IAAI,CAAC,MAA4B;QACvC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;CACD;AAtFD,oEAsFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { SummarizerStopReason } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\n\n// eslint-disable-next-line import/no-deprecated\nimport { IConnectableRuntime, ISummaryCancellationToken } from \"./summarizerTypes.js\";\n\n/**\n * Similar to AbortController, but using promise instead of events\n * @legacy\n * @alpha\n * @deprecated This type will be moved to internal in 2.30. External usage is not necessary or supported.\n */\n// eslint-disable-next-line import/no-deprecated\nexport interface ICancellableSummarizerController extends ISummaryCancellationToken {\n\tstop(reason: SummarizerStopReason): void;\n}\n\n/**\n * Can be useful in testing as well as in places where caller does not use cancellation.\n * This object implements ISummaryCancellationToken interface but cancellation is never leveraged.\n * @internal\n */\n// eslint-disable-next-line import/no-deprecated\nexport const neverCancelledSummaryToken: ISummaryCancellationToken = {\n\tcancelled: false,\n\twaitCancelled: new Promise(() => {}),\n};\n\n/**\n * Helper class to coordinate something that needs to run only while connected.\n * This provides promises that resolve as it starts or stops. Stopping happens\n * when disconnected or if stop() is called.\n */\nexport class RunWhileConnectedCoordinator implements ICancellableSummarizerController {\n\tprivate _cancelled = false;\n\tprivate readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n\tpublic get cancelled(): boolean {\n\t\tif (!this._cancelled) {\n\t\t\tassert(this.active(), 0x25d /* \"We should never connect as 'read'\" */);\n\n\t\t\t// This check can't be enabled in current design due to lastSummary flow, where\n\t\t\t// summarizer for closed container stays around and can produce one more summary.\n\t\t\t// Currently we solve the problem of overlapping summarizer by doing wait in\n\t\t\t// SummaryManager.createSummarizer()\n\t\t\t// Better solution would involve these steps:\n\t\t\t// 1. Summarizer selection logic should chose summarizing client (with clientType === \"summarizer\")\n\t\t\t// if such client exists.\n\t\t\t// 2. Summarizer should be updated about such changes (to update onBehalfOfClientId)\n\t\t\t//\n\t\t\t// assert(this.runtime.summarizerClientId === this.onBehalfOfClientId ||\n\t\t\t// this.runtime.summarizerClientId === this.runtime.clientId, \"onBehalfOfClientId\");\n\t\t}\n\n\t\treturn this._cancelled;\n\t}\n\n\t/**\n\t * Returns a promise that resolves once stopped either externally or by disconnect.\n\t */\n\tpublic get waitCancelled(): Promise<SummarizerStopReason> {\n\t\treturn this.stopDeferred.promise;\n\t}\n\n\tpublic static async create(\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\truntime: IConnectableRuntime,\n\t\tactive: () => boolean,\n\t): Promise<RunWhileConnectedCoordinator> {\n\t\tconst obj = new RunWhileConnectedCoordinator(runtime, active);\n\t\tawait obj.waitStart();\n\t\treturn obj;\n\t}\n\n\tprotected constructor(\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tprivate readonly runtime: IConnectableRuntime,\n\t\tprivate readonly active: () => boolean,\n\t) {}\n\n\t/**\n\t * Starts and waits for a promise which resolves when connected.\n\t * The promise will also resolve if stopped either externally or by disconnect.\n\t *\n\t * We only listen on disconnected event for clientType === \"summarizer\" container!\n\t * And only do it here - no other place should check it! That way we have only one place\n\t * that controls policy and it's easy to change policy in the future if we want to!\n\t * We do not listen for \"main\" (aka interactive) container disconnect here, as it's\n\t * responsibility of SummaryManager to decide if that's material or not. There are cases\n\t * like \"lastSummary\", or main client experiencing nacks / disconnects due to hitting limit\n\t * of non-summarized ops, where can make determination to continue with summary even if main\n\t * client is disconnected.\n\t */\n\tprotected async waitStart(): Promise<void> {\n\t\tif (this.runtime.disposed) {\n\t\t\tthis.stop(\"summarizerClientDisconnected\");\n\t\t\treturn;\n\t\t}\n\n\t\tthis.runtime.once(\"dispose\", () => this.stop(\"summarizerClientDisconnected\"));\n\n\t\tif (!this.runtime.connected) {\n\t\t\tconst waitConnected = new Promise<void>((resolve) =>\n\t\t\t\tthis.runtime.once(\"connected\", resolve),\n\t\t\t);\n\t\t\tawait Promise.race([waitConnected, this.waitCancelled]);\n\t\t}\n\t\tthis.runtime.once(\"disconnected\", () => this.stop(\"summarizerClientDisconnected\"));\n\t}\n\n\t/**\n\t * Stops running.\n\t */\n\tpublic stop(reason: SummarizerStopReason): void {\n\t\tif (!this._cancelled) {\n\t\t\tthis._cancelled = true;\n\t\t\tthis.stopDeferred.resolve(reason);\n\t\t}\n\t}\n}\n"]}
@@ -6,6 +6,7 @@ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
6
  import type { ISummarizerEvents, SummarizerStopReason } from "@fluidframework/container-runtime-definitions/internal";
7
7
  import { IDisposable, ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
8
8
  import { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
9
+ import { type ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
9
10
  import { ISummaryConfiguration } from "../containerRuntime.js";
10
11
  import { EnqueueSummarizeResult, IEnqueueSummarizeOptions, IOnDemandSummarizeOptions, IRefreshSummaryAckOptions, ISubmitSummaryOptions, ISummarizeHeuristicData, ISummarizeResults, ISummarizerRuntime, ISummaryCancellationToken, SubmitSummaryResult } from "./summarizerTypes.js";
11
12
  import { IClientSummaryWatcher, SummaryCollection } from "./summaryCollection.js";
@@ -52,7 +53,9 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
52
53
  private totalSuccessfulAttempts;
53
54
  private initialized;
54
55
  private readonly runtimeListener;
55
- /** The maximum number of summary attempts to do when submit summary fails. */
56
+ /**
57
+ * The maximum number of summary attempts to do when submit summary fails.
58
+ */
56
59
  private readonly maxAttemptsForSubmitFailures;
57
60
  /**
58
61
  * These are necessary to store outside of methods because of the logic around runnning a lastSummary.
@@ -78,8 +81,10 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
78
81
  * but only if they're logging about that same summary.
79
82
  * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct
80
83
  */
81
- tryGetCorrelatedLogger: (summaryOpRefSeq: any) => import("@fluidframework/telemetry-utils/internal").ITelemetryLoggerExt | undefined;
82
- /** We only want a single heuristic runner micro-task (will provide better optimized grouping of ops) */
84
+ tryGetCorrelatedLogger: (summaryOpRefSeq: number) => ITelemetryLoggerExt | undefined;
85
+ /**
86
+ * We only want a single heuristic runner micro-task (will provide better optimized grouping of ops)
87
+ */
83
88
  private heuristicRunnerMicroTaskExists;
84
89
  handleOp(op: ISequencedDocumentMessage, runtimeMessage: boolean): void;
85
90
  /**
@@ -114,7 +119,9 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
114
119
  * @returns ISummarizeResult - result of running a summary.
115
120
  */
116
121
  private trySummarizeOnce;
117
- /** Heuristics summarize attempt. */
122
+ /**
123
+ * Heuristics summarize attempt.
124
+ */
118
125
  private trySummarize;
119
126
  /**
120
127
  * Tries to summarize with retries where retry is based on the failure params.
@@ -126,9 +133,13 @@ export declare class RunningSummarizer extends TypedEventEmitter<ISummarizerEven
126
133
  * as heuristics based summaries.
127
134
  */
128
135
  private summarizeOnDemandWithRetries;
129
- /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */
136
+ /**
137
+ *{@inheritdoc (ISummarizer:interface).summarizeOnDemand}
138
+ */
130
139
  summarizeOnDemand(options: IOnDemandSummarizeOptions, resultsBuilder?: SummarizeResultBuilder): ISummarizeResults;
131
- /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */
140
+ /**
141
+ *{@inheritdoc (ISummarizer:interface).enqueueSummarize}
142
+ */
132
143
  enqueueSummarize(options: IEnqueueSummarizeOptions): EnqueueSummarizeResult;
133
144
  private tryRunEnqueuedSummary;
134
145
  private disposeEnqueuedSummary;
@@ -1 +1 @@
1
- {"version":3,"file":"runningSummarizer.d.ts","sourceRoot":"","sources":["../../src/summary/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAEX,iBAAiB,EAEjB,oBAAoB,EACpB,MAAM,wDAAwD,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEpF,OAAO,EAGN,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AASrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAI/D,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EAGvB,iBAAiB,EAGjB,kBAAkB,EAClB,yBAAyB,EACzB,mBAAm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,CAAC,QAAQ,CAAC,eAAe,CAGtB;IAEV;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAS;IAEtD;;;OAGG;IACH,OAAO,CAAC,8BAA8B,CAC3B;IAEX,OAAO;YA2HO,gBAAgB;IAkC9B,OAAO,CAAC,QAAQ,CAAC,qCAAqC,CA4BpD;IAEF;;;;;;;OAOG;YACW,0BAA0B;IAYjC,OAAO,IAAI,IAAI;IAYtB;;;;;OAKG;IACI,sBAAsB,oBACX,MAAM,KACrB,mBAAmB,GAAG,SAAS,CAGpB;IAEd;;OAEG;IACH,OAAO,CAAC,8BAA8B,CAAS;IAExC,QAAQ,CAAC,EAAE,EAAE,yBAAyB,EAAE,cAAc,EAAE,OAAO,GAAG,IAAI;IA8B7E;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAgB3B,OAAO,CAAC,6BAA6B;IAWxB,QAAQ,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAyCjD,SAAS;IAuBvB,OAAO,CAAC,mBAAmB;IAI3B,OAAO,CAAC,kBAAkB;IAW1B;;;;;;;;OAQG;YACW,mBAAmB;IAsBjC;;;;;;;;OAQG;IACH,OAAO,CAAC,gBAAgB;IA8ExB;;OAEG;IACH,OAAO,CAAC,YAAY;IAuBpB;;;OAGG;YACW,uBAAuB;IA0KrC;;;OAGG;YACW,4BAA4B;IAqB1C;;OAEG;IACI,iBAAiB,CACvB,OAAO,EAAE,yBAAyB,EAClC,cAAc,GAAE,sBAAqD,GACnE,iBAAiB;IAgCpB;;OAEG;IACI,gBAAgB,CAAC,OAAO,EAAE,wBAAwB,GAAG,sBAAsB;IAmClF,OAAO,CAAC,qBAAqB;IAwB7B,OAAO,CAAC,sBAAsB;CAS9B"}
@@ -31,7 +31,15 @@ exports.defaultMaxAttemptsForSubmitFailures = 5;
31
31
  * This object is created and controlled by Summarizer object.
32
32
  */
33
33
  class RunningSummarizer extends client_utils_1.TypedEventEmitter {
34
- static async start(logger, summaryWatcher, configuration, submitSummaryCallback, refreshLatestSummaryAckCallback, heuristicData, summaryCollection, cancellationToken, stopSummarizerCallback, runtime) {
34
+ static async start(logger, summaryWatcher, configuration,
35
+ // eslint-disable-next-line import/no-deprecated
36
+ submitSummaryCallback,
37
+ // eslint-disable-next-line import/no-deprecated
38
+ refreshLatestSummaryAckCallback, heuristicData, summaryCollection,
39
+ // eslint-disable-next-line import/no-deprecated
40
+ cancellationToken, stopSummarizerCallback,
41
+ // eslint-disable-next-line import/no-deprecated
42
+ runtime) {
35
43
  const summarizer = new RunningSummarizer(logger, summaryWatcher, configuration, submitSummaryCallback, refreshLatestSummaryAckCallback, heuristicData, summaryCollection, cancellationToken, stopSummarizerCallback, runtime);
36
44
  // If there have been any acks newer that the one this client loaded from until now, process them before
37
45
  // starting the running summarizer which will trigger summary heuristics.
@@ -77,7 +85,11 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
77
85
  get disposed() {
78
86
  return this._disposed;
79
87
  }
80
- constructor(baseLogger, summaryWatcher, configuration, submitSummaryCallback, refreshLatestSummaryAckCallback, heuristicData, summaryCollection, cancellationToken, stopSummarizerCallback, runtime) {
88
+ constructor(baseLogger, summaryWatcher, configuration, submitSummaryCallback, refreshLatestSummaryAckCallback, heuristicData, summaryCollection,
89
+ // eslint-disable-next-line import/no-deprecated
90
+ cancellationToken, stopSummarizerCallback,
91
+ // eslint-disable-next-line import/no-deprecated
92
+ runtime) {
81
93
  super();
82
94
  this.summaryWatcher = summaryWatcher;
83
95
  this.configuration = configuration;
@@ -99,7 +111,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
99
111
  * We want the lastSummary to also be captured as "all attempts failed".
100
112
  */
101
113
  this.lastSummarizeFailureEventProps = undefined;
102
- this.refreshLatestSummaryAckAndHandleError = async (options) => {
114
+ this.refreshLatestSummaryAckAndHandleError = async (
115
+ // eslint-disable-next-line import/no-deprecated
116
+ options) => {
103
117
  return this.refreshLatestSummaryAckCallback(options).catch(async (error) => {
104
118
  // If the error is 404, so maybe the fetched version no longer exists on server. We just
105
119
  // ignore this error in that case, as that means we will have another summaryAck for the
@@ -129,7 +143,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
129
143
  this.tryGetCorrelatedLogger = (summaryOpRefSeq) => this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq
130
144
  ? this.mc.logger
131
145
  : undefined;
132
- /** We only want a single heuristic runner micro-task (will provide better optimized grouping of ops) */
146
+ /**
147
+ * We only want a single heuristic runner micro-task (will provide better optimized grouping of ops)
148
+ */
133
149
  this.heuristicRunnerMicroTaskExists = false;
134
150
  const telemetryProps = {
135
151
  summarizeCount: () => this.summarizeCount,
@@ -177,7 +193,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
177
193
  const immediatelyRefreshLatestSummaryAck = this.mc.config.getBoolean("Fluid.Summarizer.immediatelyRefreshLatestSummaryAck") ?? true;
178
194
  this.generator = new summaryGenerator_js_1.SummaryGenerator(this.pendingAckTimer, this.heuristicData, this.submitSummaryCallback, () => {
179
195
  this.totalSuccessfulAttempts++;
180
- }, async (options) => {
196
+ },
197
+ // eslint-disable-next-line import/no-deprecated
198
+ async (options) => {
181
199
  if (immediatelyRefreshLatestSummaryAck) {
182
200
  await this.refreshLatestSummaryAckAndHandleError(options);
183
201
  }
@@ -214,6 +232,7 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
214
232
  // executing the refreshLatestSummaryAck.
215
233
  // https://dev.azure.com/fluidframework/internal/_workitems/edit/779
216
234
  await this.lockedSummaryAction(() => { }, async () => {
235
+ // eslint-disable-next-line import/no-deprecated
217
236
  const options = {
218
237
  proposalHandle: summaryOpHandle,
219
238
  ackHandle: summaryAckHandle,
@@ -286,10 +305,12 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
286
305
  switch (op.type) {
287
306
  case internal_2.MessageType.Summarize:
288
307
  case internal_2.MessageType.SummaryAck:
289
- case internal_2.MessageType.SummaryNack:
308
+ case internal_2.MessageType.SummaryNack: {
290
309
  return false;
291
- default:
310
+ }
311
+ default: {
292
312
  return runtimeMessage || this.nonRuntimeOpCanTriggerSummary();
313
+ }
293
314
  }
294
315
  }
295
316
  nonRuntimeOpCanTriggerSummary() {
@@ -306,12 +327,12 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
306
327
  this.stopping = true;
307
328
  this.disposeEnqueuedSummary();
308
329
  // This will try to run lastSummary if needed.
309
- if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {
310
- if (this.summarizingLock === undefined) {
311
- this.trySummarizeOnce(
312
- // summarizeProps
313
- { summarizeReason: "lastSummary" }, {}, undefined, true /* isLastSummary */);
314
- }
330
+ if (allowLastSummary &&
331
+ this.heuristicRunner?.shouldRunLastSummary() &&
332
+ this.summarizingLock === undefined) {
333
+ this.trySummarizeOnce(
334
+ // summarizeProps
335
+ { summarizeReason: "lastSummary" }, {}, undefined, true /* isLastSummary */);
315
336
  }
316
337
  // Note that trySummarizeOnce() call above returns right away, without waiting.
317
338
  // So we need to wait for its completion, otherwise it would be destroyed right away.
@@ -394,6 +415,7 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
394
415
  logger: this.mc.logger,
395
416
  properties: { all: summarizeProps },
396
417
  });
418
+ // eslint-disable-next-line import/no-deprecated
397
419
  const summaryOptions = {
398
420
  ...options,
399
421
  summaryLogger,
@@ -449,7 +471,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
449
471
  });
450
472
  return resultsBuilder.build();
451
473
  }
452
- /** Heuristics summarize attempt. */
474
+ /**
475
+ * Heuristics summarize attempt.
476
+ */
453
477
  trySummarize(reason) {
454
478
  if (this.summarizingLock !== undefined) {
455
479
  // lockedSummaryAction() will retry heuristic-based summary at the end of current attempt
@@ -487,6 +511,7 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
487
511
  logger: this.mc.logger,
488
512
  properties: { all: summarizeProps },
489
513
  });
514
+ // eslint-disable-next-line import/no-deprecated
490
515
  const summaryOptions = {
491
516
  ...summarizeOptions,
492
517
  summaryLogger,
@@ -534,9 +559,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
534
559
  // If submit summary failed, use maxAttemptsForSubmitFailures. Else use the defaultMaxAttempts.
535
560
  // Note: Check "summarySubmitted" result first because if it fails, ack nack would fail as well.
536
561
  const submitSummaryResult = await results.summarySubmitted;
537
- maxAttempts = !submitSummaryResult.success
538
- ? this.maxAttemptsForSubmitFailures
539
- : exports.defaultMaxAttempts;
562
+ maxAttempts = submitSummaryResult.success
563
+ ? exports.defaultMaxAttempts
564
+ : this.maxAttemptsForSubmitFailures;
540
565
  // Emit "summarize" event for this failed attempt.
541
566
  status = "failure";
542
567
  error = ackNackResult.error;
@@ -636,7 +661,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
636
661
  resultsBuilder.receivedSummaryAckOrNack.resolve(ackNackResult);
637
662
  return resultsBuilder.build();
638
663
  }
639
- /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */
664
+ /**
665
+ *{@inheritdoc (ISummarizer:interface).summarizeOnDemand}
666
+ */
640
667
  summarizeOnDemand(options, resultsBuilder = new summaryGenerator_js_1.SummarizeResultBuilder()) {
641
668
  if (this.stopping) {
642
669
  resultsBuilder.fail("RunningSummarizer stopped or disposed", new summaryGenerator_js_1.RetriableSummaryError("RunningSummarizer stopped or disposed"));
@@ -659,7 +686,9 @@ class RunningSummarizer extends client_utils_1.TypedEventEmitter {
659
686
  }
660
687
  return resultsBuilder.build();
661
688
  }
662
- /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */
689
+ /**
690
+ *{@inheritdoc (ISummarizer:interface).enqueueSummarize}
691
+ */
663
692
  enqueueSummarize(options) {
664
693
  const { reason, afterSequenceNumber = 0, override = false, ...summarizeOptions } = options;
665
694
  let overridden = false;