@fluidframework/container-runtime 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229

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 (563) hide show
  1. package/.eslintrc.js +21 -10
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts +1 -2
  5. package/dist/batchTracker.d.ts.map +1 -1
  6. package/dist/batchTracker.js +2 -1
  7. package/dist/batchTracker.js.map +1 -1
  8. package/dist/blobManager.d.ts +74 -42
  9. package/dist/blobManager.d.ts.map +1 -1
  10. package/dist/blobManager.js +321 -152
  11. package/dist/blobManager.js.map +1 -1
  12. package/dist/connectionTelemetry.d.ts.map +1 -1
  13. package/dist/connectionTelemetry.js +11 -9
  14. package/dist/connectionTelemetry.js.map +1 -1
  15. package/dist/containerHandleContext.d.ts.map +1 -1
  16. package/dist/containerHandleContext.js +3 -1
  17. package/dist/containerHandleContext.js.map +1 -1
  18. package/dist/containerRuntime.d.ts +148 -114
  19. package/dist/containerRuntime.d.ts.map +1 -1
  20. package/dist/containerRuntime.js +534 -342
  21. package/dist/containerRuntime.js.map +1 -1
  22. package/dist/dataStore.d.ts.map +1 -1
  23. package/dist/dataStore.js +11 -9
  24. package/dist/dataStore.js.map +1 -1
  25. package/dist/dataStoreContext.d.ts +40 -13
  26. package/dist/dataStoreContext.d.ts.map +1 -1
  27. package/dist/dataStoreContext.js +146 -66
  28. package/dist/dataStoreContext.js.map +1 -1
  29. package/dist/dataStoreContexts.d.ts.map +1 -1
  30. package/dist/dataStoreContexts.js +7 -3
  31. package/dist/dataStoreContexts.js.map +1 -1
  32. package/dist/dataStoreRegistry.d.ts.map +1 -1
  33. package/dist/dataStoreRegistry.js +3 -1
  34. package/dist/dataStoreRegistry.js.map +1 -1
  35. package/dist/dataStores.d.ts +39 -12
  36. package/dist/dataStores.d.ts.map +1 -1
  37. package/dist/dataStores.js +164 -76
  38. package/dist/dataStores.js.map +1 -1
  39. package/dist/deltaManagerSummarizerProxy.d.ts +19 -0
  40. package/dist/deltaManagerSummarizerProxy.d.ts.map +1 -0
  41. package/dist/deltaManagerSummarizerProxy.js +40 -0
  42. package/dist/deltaManagerSummarizerProxy.js.map +1 -0
  43. package/dist/deltaScheduler.d.ts.map +1 -1
  44. package/dist/deltaScheduler.js +8 -3
  45. package/dist/deltaScheduler.js.map +1 -1
  46. package/dist/gc/garbageCollection.d.ts +204 -0
  47. package/dist/gc/garbageCollection.d.ts.map +1 -0
  48. package/dist/gc/garbageCollection.js +926 -0
  49. package/dist/gc/garbageCollection.js.map +1 -0
  50. package/dist/gc/gcConfigs.d.ts +22 -0
  51. package/dist/gc/gcConfigs.d.ts.map +1 -0
  52. package/dist/gc/gcConfigs.js +143 -0
  53. package/dist/gc/gcConfigs.js.map +1 -0
  54. package/dist/gc/gcDefinitions.d.ts +320 -0
  55. package/dist/gc/gcDefinitions.d.ts.map +1 -0
  56. package/dist/gc/gcDefinitions.js +81 -0
  57. package/dist/gc/gcDefinitions.js.map +1 -0
  58. package/dist/gc/gcHelpers.d.ts +86 -0
  59. package/dist/gc/gcHelpers.d.ts.map +1 -0
  60. package/dist/gc/gcHelpers.js +268 -0
  61. package/dist/gc/gcHelpers.js.map +1 -0
  62. package/dist/gc/gcReferenceGraphAlgorithm.d.ts +16 -0
  63. package/dist/gc/gcReferenceGraphAlgorithm.d.ts.map +1 -0
  64. package/dist/gc/gcReferenceGraphAlgorithm.js +49 -0
  65. package/dist/gc/gcReferenceGraphAlgorithm.js.map +1 -0
  66. package/dist/gc/gcSummaryDefinitions.d.ts +52 -0
  67. package/dist/gc/gcSummaryDefinitions.d.ts.map +1 -0
  68. package/dist/gc/gcSummaryDefinitions.js +7 -0
  69. package/dist/gc/gcSummaryDefinitions.js.map +1 -0
  70. package/dist/gc/gcSummaryStateTracker.d.ts +93 -0
  71. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -0
  72. package/dist/gc/gcSummaryStateTracker.js +239 -0
  73. package/dist/gc/gcSummaryStateTracker.js.map +1 -0
  74. package/{lib → dist/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  75. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  76. package/dist/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  77. package/dist/gc/gcSweepReadyUsageDetection.js.map +1 -0
  78. package/dist/gc/gcUnreferencedStateTracker.d.ts +34 -0
  79. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  80. package/dist/gc/gcUnreferencedStateTracker.js +94 -0
  81. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -0
  82. package/dist/gc/index.d.ts +13 -0
  83. package/dist/gc/index.d.ts.map +1 -0
  84. package/dist/gc/index.js +50 -0
  85. package/dist/gc/index.js.map +1 -0
  86. package/dist/index.d.ts +3 -8
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +7 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/opLifecycle/batchManager.d.ts +10 -0
  91. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  92. package/dist/opLifecycle/batchManager.js +37 -8
  93. package/dist/opLifecycle/batchManager.js.map +1 -1
  94. package/dist/opLifecycle/definitions.d.ts +29 -1
  95. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  96. package/dist/opLifecycle/definitions.js.map +1 -1
  97. package/dist/opLifecycle/index.d.ts +3 -3
  98. package/dist/opLifecycle/index.d.ts.map +1 -1
  99. package/dist/opLifecycle/index.js +3 -1
  100. package/dist/opLifecycle/index.js.map +1 -1
  101. package/dist/opLifecycle/opCompressor.d.ts +1 -1
  102. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  103. package/dist/opLifecycle/opCompressor.js +46 -17
  104. package/dist/opLifecycle/opCompressor.js.map +1 -1
  105. package/dist/opLifecycle/opDecompressor.d.ts +6 -1
  106. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  107. package/dist/opLifecycle/opDecompressor.js +72 -18
  108. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  109. package/dist/opLifecycle/opSplitter.d.ts +46 -2
  110. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  111. package/dist/opLifecycle/opSplitter.js +142 -5
  112. package/dist/opLifecycle/opSplitter.js.map +1 -1
  113. package/dist/opLifecycle/outbox.d.ts +23 -2
  114. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  115. package/dist/opLifecycle/outbox.js +101 -51
  116. package/dist/opLifecycle/outbox.js.map +1 -1
  117. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  118. package/dist/opLifecycle/remoteMessageProcessor.js +17 -2
  119. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  120. package/dist/opProperties.d.ts.map +1 -1
  121. package/dist/opProperties.js +1 -3
  122. package/dist/opProperties.js.map +1 -1
  123. package/dist/packageVersion.d.ts +1 -1
  124. package/dist/packageVersion.js +1 -1
  125. package/dist/packageVersion.js.map +1 -1
  126. package/dist/pendingStateManager.d.ts +6 -15
  127. package/dist/pendingStateManager.d.ts.map +1 -1
  128. package/dist/pendingStateManager.js +137 -165
  129. package/dist/pendingStateManager.js.map +1 -1
  130. package/dist/scheduleManager.d.ts +0 -1
  131. package/dist/scheduleManager.d.ts.map +1 -1
  132. package/dist/scheduleManager.js +11 -21
  133. package/dist/scheduleManager.js.map +1 -1
  134. package/dist/storageServiceWithAttachBlobs.d.ts +17 -0
  135. package/dist/storageServiceWithAttachBlobs.d.ts.map +1 -0
  136. package/dist/storageServiceWithAttachBlobs.js +32 -0
  137. package/dist/storageServiceWithAttachBlobs.js.map +1 -0
  138. package/dist/summary/index.d.ts +17 -0
  139. package/dist/summary/index.d.ts.map +1 -0
  140. package/dist/summary/index.js +46 -0
  141. package/dist/summary/index.js.map +1 -0
  142. package/dist/summary/orderedClientElection.d.ts.map +1 -0
  143. package/dist/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  144. package/dist/summary/orderedClientElection.js.map +1 -0
  145. package/{lib → dist/summary}/runWhileConnectedCoordinator.d.ts +3 -2
  146. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  147. package/dist/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +5 -4
  148. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -0
  149. package/{lib → dist/summary}/runningSummarizer.d.ts +19 -18
  150. package/dist/summary/runningSummarizer.d.ts.map +1 -0
  151. package/dist/{runningSummarizer.js → summary/runningSummarizer.js} +191 -77
  152. package/dist/summary/runningSummarizer.js.map +1 -0
  153. package/dist/{summarizer.d.ts → summary/summarizer.d.ts} +6 -12
  154. package/dist/summary/summarizer.d.ts.map +1 -0
  155. package/dist/{summarizer.js → summary/summarizer.js} +32 -76
  156. package/dist/summary/summarizer.js.map +1 -0
  157. package/dist/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +1 -2
  158. package/dist/summary/summarizerClientElection.d.ts.map +1 -0
  159. package/dist/{summarizerClientElection.js → summary/summarizerClientElection.js} +3 -30
  160. package/dist/summary/summarizerClientElection.js.map +1 -0
  161. package/dist/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  162. package/dist/summary/summarizerHeuristics.d.ts.map +1 -0
  163. package/dist/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +9 -12
  164. package/dist/summary/summarizerHeuristics.js.map +1 -0
  165. package/dist/summary/summarizerNode/index.d.ts +8 -0
  166. package/dist/summary/summarizerNode/index.d.ts.map +1 -0
  167. package/dist/summary/summarizerNode/index.js +12 -0
  168. package/dist/summary/summarizerNode/index.js.map +1 -0
  169. package/dist/summary/summarizerNode/summarizerNode.d.ts +149 -0
  170. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
  171. package/dist/summary/summarizerNode/summarizerNode.js +531 -0
  172. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -0
  173. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
  174. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
  175. package/dist/summary/summarizerNode/summarizerNodeUtils.js +132 -0
  176. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
  177. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
  178. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
  179. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +423 -0
  180. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
  181. package/{lib → dist/summary}/summarizerTypes.d.ts +29 -42
  182. package/dist/summary/summarizerTypes.d.ts.map +1 -0
  183. package/dist/{summarizerTypes.js → summary/summarizerTypes.js} +0 -5
  184. package/dist/summary/summarizerTypes.js.map +1 -0
  185. package/dist/summary/summaryCollection.d.ts.map +1 -0
  186. package/dist/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  187. package/dist/summary/summaryCollection.js.map +1 -0
  188. package/{lib → dist/summary}/summaryFormat.d.ts +3 -21
  189. package/dist/summary/summaryFormat.d.ts.map +1 -0
  190. package/dist/{summaryFormat.js → summary/summaryFormat.js} +19 -21
  191. package/dist/summary/summaryFormat.js.map +1 -0
  192. package/dist/summary/summaryGenerator.d.ts.map +1 -0
  193. package/dist/{summaryGenerator.js → summary/summaryGenerator.js} +34 -16
  194. package/dist/summary/summaryGenerator.js.map +1 -0
  195. package/dist/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  196. package/dist/summary/summaryManager.d.ts.map +1 -0
  197. package/dist/{summaryManager.js → summary/summaryManager.js} +21 -9
  198. package/dist/summary/summaryManager.js.map +1 -0
  199. package/dist/throttler.d.ts +2 -2
  200. package/dist/throttler.d.ts.map +1 -1
  201. package/dist/throttler.js +4 -4
  202. package/dist/throttler.js.map +1 -1
  203. package/lib/batchTracker.d.ts +1 -2
  204. package/lib/batchTracker.d.ts.map +1 -1
  205. package/lib/batchTracker.js +2 -1
  206. package/lib/batchTracker.js.map +1 -1
  207. package/lib/blobManager.d.ts +74 -42
  208. package/lib/blobManager.d.ts.map +1 -1
  209. package/lib/blobManager.js +322 -153
  210. package/lib/blobManager.js.map +1 -1
  211. package/lib/connectionTelemetry.d.ts.map +1 -1
  212. package/lib/connectionTelemetry.js +11 -9
  213. package/lib/connectionTelemetry.js.map +1 -1
  214. package/lib/containerHandleContext.d.ts.map +1 -1
  215. package/lib/containerHandleContext.js +3 -1
  216. package/lib/containerHandleContext.js.map +1 -1
  217. package/lib/containerRuntime.d.ts +148 -114
  218. package/lib/containerRuntime.d.ts.map +1 -1
  219. package/lib/containerRuntime.js +506 -314
  220. package/lib/containerRuntime.js.map +1 -1
  221. package/lib/dataStore.d.ts.map +1 -1
  222. package/lib/dataStore.js +11 -9
  223. package/lib/dataStore.js.map +1 -1
  224. package/lib/dataStoreContext.d.ts +40 -13
  225. package/lib/dataStoreContext.d.ts.map +1 -1
  226. package/lib/dataStoreContext.js +136 -56
  227. package/lib/dataStoreContext.js.map +1 -1
  228. package/lib/dataStoreContexts.d.ts.map +1 -1
  229. package/lib/dataStoreContexts.js +7 -3
  230. package/lib/dataStoreContexts.js.map +1 -1
  231. package/lib/dataStoreRegistry.d.ts.map +1 -1
  232. package/lib/dataStoreRegistry.js +3 -1
  233. package/lib/dataStoreRegistry.js.map +1 -1
  234. package/lib/dataStores.d.ts +39 -12
  235. package/lib/dataStores.d.ts.map +1 -1
  236. package/lib/dataStores.js +162 -74
  237. package/lib/dataStores.js.map +1 -1
  238. package/lib/deltaManagerSummarizerProxy.d.ts +19 -0
  239. package/lib/deltaManagerSummarizerProxy.d.ts.map +1 -0
  240. package/lib/deltaManagerSummarizerProxy.js +36 -0
  241. package/lib/deltaManagerSummarizerProxy.js.map +1 -0
  242. package/lib/deltaScheduler.d.ts.map +1 -1
  243. package/lib/deltaScheduler.js +9 -4
  244. package/lib/deltaScheduler.js.map +1 -1
  245. package/lib/gc/garbageCollection.d.ts +204 -0
  246. package/lib/gc/garbageCollection.d.ts.map +1 -0
  247. package/lib/gc/garbageCollection.js +922 -0
  248. package/lib/gc/garbageCollection.js.map +1 -0
  249. package/lib/gc/gcConfigs.d.ts +22 -0
  250. package/lib/gc/gcConfigs.d.ts.map +1 -0
  251. package/lib/gc/gcConfigs.js +139 -0
  252. package/lib/gc/gcConfigs.js.map +1 -0
  253. package/lib/gc/gcDefinitions.d.ts +320 -0
  254. package/lib/gc/gcDefinitions.d.ts.map +1 -0
  255. package/lib/gc/gcDefinitions.js +78 -0
  256. package/lib/gc/gcDefinitions.js.map +1 -0
  257. package/lib/gc/gcHelpers.d.ts +86 -0
  258. package/lib/gc/gcHelpers.d.ts.map +1 -0
  259. package/lib/gc/gcHelpers.js +254 -0
  260. package/lib/gc/gcHelpers.js.map +1 -0
  261. package/lib/gc/gcReferenceGraphAlgorithm.d.ts +16 -0
  262. package/lib/gc/gcReferenceGraphAlgorithm.d.ts.map +1 -0
  263. package/lib/gc/gcReferenceGraphAlgorithm.js +45 -0
  264. package/lib/gc/gcReferenceGraphAlgorithm.js.map +1 -0
  265. package/lib/gc/gcSummaryDefinitions.d.ts +52 -0
  266. package/lib/gc/gcSummaryDefinitions.d.ts.map +1 -0
  267. package/lib/gc/gcSummaryDefinitions.js +6 -0
  268. package/lib/gc/gcSummaryDefinitions.js.map +1 -0
  269. package/lib/gc/gcSummaryStateTracker.d.ts +93 -0
  270. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -0
  271. package/lib/gc/gcSummaryStateTracker.js +235 -0
  272. package/lib/gc/gcSummaryStateTracker.js.map +1 -0
  273. package/{dist → lib/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  274. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  275. package/lib/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  276. package/lib/gc/gcSweepReadyUsageDetection.js.map +1 -0
  277. package/lib/gc/gcUnreferencedStateTracker.d.ts +34 -0
  278. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  279. package/lib/gc/gcUnreferencedStateTracker.js +90 -0
  280. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -0
  281. package/lib/gc/index.d.ts +13 -0
  282. package/lib/gc/index.d.ts.map +1 -0
  283. package/lib/gc/index.js +12 -0
  284. package/lib/gc/index.js.map +1 -0
  285. package/lib/index.d.ts +3 -8
  286. package/lib/index.d.ts.map +1 -1
  287. package/lib/index.js +2 -6
  288. package/lib/index.js.map +1 -1
  289. package/lib/opLifecycle/batchManager.d.ts +10 -0
  290. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  291. package/lib/opLifecycle/batchManager.js +35 -7
  292. package/lib/opLifecycle/batchManager.js.map +1 -1
  293. package/lib/opLifecycle/definitions.d.ts +29 -1
  294. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  295. package/lib/opLifecycle/definitions.js.map +1 -1
  296. package/lib/opLifecycle/index.d.ts +3 -3
  297. package/lib/opLifecycle/index.d.ts.map +1 -1
  298. package/lib/opLifecycle/index.js +2 -2
  299. package/lib/opLifecycle/index.js.map +1 -1
  300. package/lib/opLifecycle/opCompressor.d.ts +1 -1
  301. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  302. package/lib/opLifecycle/opCompressor.js +47 -18
  303. package/lib/opLifecycle/opCompressor.js.map +1 -1
  304. package/lib/opLifecycle/opDecompressor.d.ts +6 -1
  305. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  306. package/lib/opLifecycle/opDecompressor.js +72 -18
  307. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  308. package/lib/opLifecycle/opSplitter.d.ts +46 -2
  309. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  310. package/lib/opLifecycle/opSplitter.js +141 -5
  311. package/lib/opLifecycle/opSplitter.js.map +1 -1
  312. package/lib/opLifecycle/outbox.d.ts +23 -2
  313. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  314. package/lib/opLifecycle/outbox.js +103 -53
  315. package/lib/opLifecycle/outbox.js.map +1 -1
  316. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  317. package/lib/opLifecycle/remoteMessageProcessor.js +17 -2
  318. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  319. package/lib/opProperties.d.ts.map +1 -1
  320. package/lib/opProperties.js +1 -3
  321. package/lib/opProperties.js.map +1 -1
  322. package/lib/packageVersion.d.ts +1 -1
  323. package/lib/packageVersion.js +1 -1
  324. package/lib/packageVersion.js.map +1 -1
  325. package/lib/pendingStateManager.d.ts +6 -15
  326. package/lib/pendingStateManager.d.ts.map +1 -1
  327. package/lib/pendingStateManager.js +137 -165
  328. package/lib/pendingStateManager.js.map +1 -1
  329. package/lib/scheduleManager.d.ts +0 -1
  330. package/lib/scheduleManager.d.ts.map +1 -1
  331. package/lib/scheduleManager.js +11 -21
  332. package/lib/scheduleManager.js.map +1 -1
  333. package/lib/storageServiceWithAttachBlobs.d.ts +17 -0
  334. package/lib/storageServiceWithAttachBlobs.d.ts.map +1 -0
  335. package/lib/storageServiceWithAttachBlobs.js +28 -0
  336. package/lib/storageServiceWithAttachBlobs.js.map +1 -0
  337. package/lib/summary/index.d.ts +17 -0
  338. package/lib/summary/index.d.ts.map +1 -0
  339. package/lib/summary/index.js +15 -0
  340. package/lib/summary/index.js.map +1 -0
  341. package/lib/summary/orderedClientElection.d.ts.map +1 -0
  342. package/lib/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  343. package/lib/summary/orderedClientElection.js.map +1 -0
  344. package/{dist → lib/summary}/runWhileConnectedCoordinator.d.ts +3 -2
  345. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  346. package/lib/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +5 -4
  347. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -0
  348. package/{dist → lib/summary}/runningSummarizer.d.ts +19 -18
  349. package/lib/summary/runningSummarizer.d.ts.map +1 -0
  350. package/lib/{runningSummarizer.js → summary/runningSummarizer.js} +193 -79
  351. package/lib/summary/runningSummarizer.js.map +1 -0
  352. package/lib/{summarizer.d.ts → summary/summarizer.d.ts} +6 -12
  353. package/lib/summary/summarizer.d.ts.map +1 -0
  354. package/lib/{summarizer.js → summary/summarizer.js} +34 -78
  355. package/lib/summary/summarizer.js.map +1 -0
  356. package/lib/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +1 -2
  357. package/lib/summary/summarizerClientElection.d.ts.map +1 -0
  358. package/lib/{summarizerClientElection.js → summary/summarizerClientElection.js} +3 -30
  359. package/lib/summary/summarizerClientElection.js.map +1 -0
  360. package/lib/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  361. package/lib/summary/summarizerHeuristics.d.ts.map +1 -0
  362. package/lib/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +9 -12
  363. package/lib/summary/summarizerHeuristics.js.map +1 -0
  364. package/lib/summary/summarizerNode/index.d.ts +8 -0
  365. package/lib/summary/summarizerNode/index.d.ts.map +1 -0
  366. package/lib/summary/summarizerNode/index.js +7 -0
  367. package/lib/summary/summarizerNode/index.js.map +1 -0
  368. package/lib/summary/summarizerNode/summarizerNode.d.ts +149 -0
  369. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
  370. package/lib/summary/summarizerNode/summarizerNode.js +526 -0
  371. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -0
  372. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
  373. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
  374. package/lib/summary/summarizerNode/summarizerNodeUtils.js +125 -0
  375. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
  376. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
  377. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
  378. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +419 -0
  379. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
  380. package/{dist → lib/summary}/summarizerTypes.d.ts +29 -42
  381. package/lib/summary/summarizerTypes.d.ts.map +1 -0
  382. package/lib/summary/summarizerTypes.js +6 -0
  383. package/lib/summary/summarizerTypes.js.map +1 -0
  384. package/lib/summary/summaryCollection.d.ts.map +1 -0
  385. package/lib/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  386. package/lib/summary/summaryCollection.js.map +1 -0
  387. package/{dist → lib/summary}/summaryFormat.d.ts +3 -21
  388. package/lib/summary/summaryFormat.d.ts.map +1 -0
  389. package/lib/{summaryFormat.js → summary/summaryFormat.js} +20 -21
  390. package/lib/summary/summaryFormat.js.map +1 -0
  391. package/lib/summary/summaryGenerator.d.ts.map +1 -0
  392. package/lib/{summaryGenerator.js → summary/summaryGenerator.js} +34 -16
  393. package/lib/summary/summaryGenerator.js.map +1 -0
  394. package/lib/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  395. package/lib/summary/summaryManager.d.ts.map +1 -0
  396. package/lib/{summaryManager.js → summary/summaryManager.js} +21 -9
  397. package/lib/summary/summaryManager.js.map +1 -0
  398. package/lib/throttler.d.ts +2 -2
  399. package/lib/throttler.d.ts.map +1 -1
  400. package/lib/throttler.js +4 -4
  401. package/lib/throttler.js.map +1 -1
  402. package/package.json +67 -61
  403. package/prettier.config.cjs +1 -1
  404. package/src/batchTracker.ts +55 -50
  405. package/src/blobManager.ts +863 -594
  406. package/src/connectionTelemetry.ts +280 -249
  407. package/src/containerHandleContext.ts +27 -29
  408. package/src/containerRuntime.ts +3174 -2805
  409. package/src/dataStore.ts +172 -159
  410. package/src/dataStoreContext.ts +1141 -993
  411. package/src/dataStoreContexts.ts +178 -161
  412. package/src/dataStoreRegistry.ts +25 -20
  413. package/src/dataStores.ts +887 -716
  414. package/src/deltaManagerSummarizerProxy.ts +46 -0
  415. package/src/deltaScheduler.ts +158 -150
  416. package/{garbageCollection.md → src/gc/garbageCollection.md} +16 -3
  417. package/src/gc/garbageCollection.ts +1250 -0
  418. package/src/gc/gcConfigs.ts +193 -0
  419. package/src/gc/gcDefinitions.ts +387 -0
  420. package/src/gc/gcHelpers.ts +332 -0
  421. package/src/gc/gcReferenceGraphAlgorithm.ts +52 -0
  422. package/src/gc/gcSummaryDefinitions.ts +54 -0
  423. package/src/gc/gcSummaryStateTracker.ts +329 -0
  424. package/src/gc/gcSweepReadyUsageDetection.ts +145 -0
  425. package/src/gc/gcUnreferencedStateTracker.ts +114 -0
  426. package/src/gc/index.ts +65 -0
  427. package/src/index.ts +61 -75
  428. package/src/opLifecycle/README.md +157 -0
  429. package/src/opLifecycle/batchManager.ts +119 -86
  430. package/src/opLifecycle/definitions.ts +49 -19
  431. package/src/opLifecycle/index.ts +7 -6
  432. package/src/opLifecycle/opCompressor.ts +78 -40
  433. package/src/opLifecycle/opDecompressor.ts +148 -64
  434. package/src/opLifecycle/opSplitter.ts +269 -66
  435. package/src/opLifecycle/outbox.ts +268 -184
  436. package/src/opLifecycle/remoteMessageProcessor.ts +63 -47
  437. package/src/opProperties.ts +11 -9
  438. package/src/packageVersion.ts +1 -1
  439. package/src/pendingStateManager.ts +386 -381
  440. package/src/scheduleManager.ts +299 -280
  441. package/src/storageServiceWithAttachBlobs.ts +38 -0
  442. package/src/summary/index.ts +105 -0
  443. package/src/summary/orderedClientElection.ts +564 -0
  444. package/src/summary/runWhileConnectedCoordinator.ts +113 -0
  445. package/src/summary/runningSummarizer.ts +788 -0
  446. package/src/summary/summarizer.ts +372 -0
  447. package/src/summary/summarizerClientElection.ts +139 -0
  448. package/src/summary/summarizerHeuristics.ts +224 -0
  449. package/src/summary/summarizerNode/index.ts +12 -0
  450. package/src/summary/summarizerNode/summarizerNode.ts +766 -0
  451. package/src/summary/summarizerNode/summarizerNodeUtils.ts +214 -0
  452. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +644 -0
  453. package/src/summary/summarizerTypes.ts +507 -0
  454. package/src/summary/summaryCollection.ts +450 -0
  455. package/src/summary/summaryFormat.ts +228 -0
  456. package/src/summary/summaryGenerator.ts +505 -0
  457. package/src/summary/summaryManager.ts +423 -0
  458. package/src/throttler.ts +131 -122
  459. package/tsconfig.esnext.json +6 -6
  460. package/tsconfig.json +9 -13
  461. package/dist/garbageCollection.d.ts +0 -387
  462. package/dist/garbageCollection.d.ts.map +0 -1
  463. package/dist/garbageCollection.js +0 -1138
  464. package/dist/garbageCollection.js.map +0 -1
  465. package/dist/garbageCollectionConstants.d.ts +0 -19
  466. package/dist/garbageCollectionConstants.d.ts.map +0 -1
  467. package/dist/garbageCollectionConstants.js +0 -34
  468. package/dist/garbageCollectionConstants.js.map +0 -1
  469. package/dist/gcSweepReadyUsageDetection.d.ts.map +0 -1
  470. package/dist/gcSweepReadyUsageDetection.js.map +0 -1
  471. package/dist/orderedClientElection.d.ts.map +0 -1
  472. package/dist/orderedClientElection.js.map +0 -1
  473. package/dist/runWhileConnectedCoordinator.d.ts.map +0 -1
  474. package/dist/runWhileConnectedCoordinator.js.map +0 -1
  475. package/dist/runningSummarizer.d.ts.map +0 -1
  476. package/dist/runningSummarizer.js.map +0 -1
  477. package/dist/serializedSnapshotStorage.d.ts +0 -58
  478. package/dist/serializedSnapshotStorage.d.ts.map +0 -1
  479. package/dist/serializedSnapshotStorage.js +0 -108
  480. package/dist/serializedSnapshotStorage.js.map +0 -1
  481. package/dist/summarizer.d.ts.map +0 -1
  482. package/dist/summarizer.js.map +0 -1
  483. package/dist/summarizerClientElection.d.ts.map +0 -1
  484. package/dist/summarizerClientElection.js.map +0 -1
  485. package/dist/summarizerHandle.d.ts +0 -12
  486. package/dist/summarizerHandle.d.ts.map +0 -1
  487. package/dist/summarizerHandle.js +0 -22
  488. package/dist/summarizerHandle.js.map +0 -1
  489. package/dist/summarizerHeuristics.d.ts.map +0 -1
  490. package/dist/summarizerHeuristics.js.map +0 -1
  491. package/dist/summarizerTypes.d.ts.map +0 -1
  492. package/dist/summarizerTypes.js.map +0 -1
  493. package/dist/summaryCollection.d.ts.map +0 -1
  494. package/dist/summaryCollection.js.map +0 -1
  495. package/dist/summaryFormat.d.ts.map +0 -1
  496. package/dist/summaryFormat.js.map +0 -1
  497. package/dist/summaryGenerator.d.ts.map +0 -1
  498. package/dist/summaryGenerator.js.map +0 -1
  499. package/dist/summaryManager.d.ts.map +0 -1
  500. package/dist/summaryManager.js.map +0 -1
  501. package/lib/garbageCollection.d.ts +0 -387
  502. package/lib/garbageCollection.d.ts.map +0 -1
  503. package/lib/garbageCollection.js +0 -1133
  504. package/lib/garbageCollection.js.map +0 -1
  505. package/lib/garbageCollectionConstants.d.ts +0 -19
  506. package/lib/garbageCollectionConstants.d.ts.map +0 -1
  507. package/lib/garbageCollectionConstants.js +0 -31
  508. package/lib/garbageCollectionConstants.js.map +0 -1
  509. package/lib/gcSweepReadyUsageDetection.d.ts.map +0 -1
  510. package/lib/gcSweepReadyUsageDetection.js.map +0 -1
  511. package/lib/orderedClientElection.d.ts.map +0 -1
  512. package/lib/orderedClientElection.js.map +0 -1
  513. package/lib/runWhileConnectedCoordinator.d.ts.map +0 -1
  514. package/lib/runWhileConnectedCoordinator.js.map +0 -1
  515. package/lib/runningSummarizer.d.ts.map +0 -1
  516. package/lib/runningSummarizer.js.map +0 -1
  517. package/lib/serializedSnapshotStorage.d.ts +0 -58
  518. package/lib/serializedSnapshotStorage.d.ts.map +0 -1
  519. package/lib/serializedSnapshotStorage.js +0 -104
  520. package/lib/serializedSnapshotStorage.js.map +0 -1
  521. package/lib/summarizer.d.ts.map +0 -1
  522. package/lib/summarizer.js.map +0 -1
  523. package/lib/summarizerClientElection.d.ts.map +0 -1
  524. package/lib/summarizerClientElection.js.map +0 -1
  525. package/lib/summarizerHandle.d.ts +0 -12
  526. package/lib/summarizerHandle.d.ts.map +0 -1
  527. package/lib/summarizerHandle.js +0 -18
  528. package/lib/summarizerHandle.js.map +0 -1
  529. package/lib/summarizerHeuristics.d.ts.map +0 -1
  530. package/lib/summarizerHeuristics.js.map +0 -1
  531. package/lib/summarizerTypes.d.ts.map +0 -1
  532. package/lib/summarizerTypes.js +0 -9
  533. package/lib/summarizerTypes.js.map +0 -1
  534. package/lib/summaryCollection.d.ts.map +0 -1
  535. package/lib/summaryCollection.js.map +0 -1
  536. package/lib/summaryFormat.d.ts.map +0 -1
  537. package/lib/summaryFormat.js.map +0 -1
  538. package/lib/summaryGenerator.d.ts.map +0 -1
  539. package/lib/summaryGenerator.js.map +0 -1
  540. package/lib/summaryManager.d.ts.map +0 -1
  541. package/lib/summaryManager.js.map +0 -1
  542. package/src/garbageCollection.ts +0 -1646
  543. package/src/garbageCollectionConstants.ts +0 -35
  544. package/src/gcSweepReadyUsageDetection.ts +0 -139
  545. package/src/orderedClientElection.ts +0 -532
  546. package/src/runWhileConnectedCoordinator.ts +0 -106
  547. package/src/runningSummarizer.ts +0 -611
  548. package/src/serializedSnapshotStorage.ts +0 -146
  549. package/src/summarizer.ts +0 -421
  550. package/src/summarizerClientElection.ts +0 -161
  551. package/src/summarizerHandle.ts +0 -21
  552. package/src/summarizerHeuristics.ts +0 -222
  553. package/src/summarizerTypes.ts +0 -510
  554. package/src/summaryCollection.ts +0 -421
  555. package/src/summaryFormat.ts +0 -235
  556. package/src/summaryGenerator.ts +0 -446
  557. package/src/summaryManager.ts +0 -394
  558. /package/dist/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  559. /package/dist/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  560. /package/dist/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  561. /package/lib/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  562. /package/lib/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  563. /package/lib/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
@@ -0,0 +1,1250 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
+ import { assert, LazyPromise, Timer } from "@fluidframework/common-utils";
8
+ import { ClientSessionExpiredError, DataProcessingError } from "@fluidframework/container-utils";
9
+ import { IRequestHeader } from "@fluidframework/core-interfaces";
10
+ import {
11
+ gcTreeKey,
12
+ IGarbageCollectionData,
13
+ IGarbageCollectionDetailsBase,
14
+ ISummarizeResult,
15
+ ITelemetryContext,
16
+ } from "@fluidframework/runtime-definitions";
17
+ import { packagePathToTelemetryProperty, ReadAndParseBlob } from "@fluidframework/runtime-utils";
18
+ import {
19
+ ChildLogger,
20
+ generateStack,
21
+ loggerToMonitoringContext,
22
+ MonitoringContext,
23
+ PerformanceEvent,
24
+ TelemetryDataTag,
25
+ } from "@fluidframework/telemetry-utils";
26
+
27
+ import { RuntimeHeaders } from "../containerRuntime";
28
+ import { ICreateContainerMetadata, RefreshSummaryResult } from "../summary";
29
+ import { generateGCConfigs } from "./gcConfigs";
30
+ import {
31
+ disableSweepLogKey,
32
+ GCNodeType,
33
+ IGarbageCollector,
34
+ IGarbageCollectorCreateParams,
35
+ IGarbageCollectionRuntime,
36
+ IGCResult,
37
+ IGCStats,
38
+ UnreferencedState,
39
+ IGCMetadata,
40
+ IGarbageCollectorConfigs,
41
+ } from "./gcDefinitions";
42
+ import {
43
+ cloneGCData,
44
+ concatGarbageCollectionData,
45
+ getGCDataFromSnapshot,
46
+ sendGCUnexpectedUsageEvent,
47
+ } from "./gcHelpers";
48
+ import { runGarbageCollection } from "./gcReferenceGraphAlgorithm";
49
+ import { IGarbageCollectionSnapshotData, IGarbageCollectionState } from "./gcSummaryDefinitions";
50
+ import { GCSummaryStateTracker } from "./gcSummaryStateTracker";
51
+ import { UnreferencedStateTracker } from "./gcUnreferencedStateTracker";
52
+
53
+ /** The event that is logged when unreferenced node is used after a certain time. */
54
+ interface IUnreferencedEventProps {
55
+ usageType: "Changed" | "Loaded" | "Revived";
56
+ state: UnreferencedState;
57
+ id: string;
58
+ type: GCNodeType;
59
+ unrefTime: number;
60
+ age: number;
61
+ completedGCRuns: number;
62
+ fromId?: string;
63
+ timeout?: number;
64
+ lastSummaryTime?: number;
65
+ viaHandle?: boolean;
66
+ }
67
+
68
+ /**
69
+ * The garbage collector for the container runtime. It consolidates the garbage collection functionality and maintains
70
+ * its state across summaries.
71
+ *
72
+ * Node - represented as nodeId, it's a node on the GC graph
73
+ *
74
+ * Outbound Route - a path from one node to another node, think `nodeA` -\> `nodeB`
75
+ *
76
+ * Graph - all nodes with their respective routes
77
+ *
78
+ * ```
79
+ * GC Graph
80
+ *
81
+ * Node
82
+ * NodeId = "datastore1"
83
+ * / \\
84
+ * OutboundRoute OutboundRoute
85
+ * / \\
86
+ * Node Node
87
+ * NodeId = "dds1" NodeId = "dds2"
88
+ * ```
89
+ */
90
+ export class GarbageCollector implements IGarbageCollector {
91
+ public static create(createParams: IGarbageCollectorCreateParams): IGarbageCollector {
92
+ return new GarbageCollector(createParams);
93
+ }
94
+
95
+ private readonly mc: MonitoringContext;
96
+
97
+ private readonly configs: IGarbageCollectorConfigs;
98
+
99
+ public get shouldRunGC(): boolean {
100
+ return this.configs.shouldRunGC;
101
+ }
102
+
103
+ // Keeps track of the GC state from the last run.
104
+ private gcDataFromLastRun: IGarbageCollectionData | undefined;
105
+ // Keeps a list of references (edges in the GC graph) between GC runs. Each entry has a node id and a list of
106
+ // outbound routes from that node.
107
+ private readonly newReferencesSinceLastRun: Map<string, string[]> = new Map();
108
+ // A list of nodes that have been tombstoned.
109
+ private tombstones: string[] = [];
110
+ // A list of nodes that have been deleted during sweep phase.
111
+ private deletedNodes: Set<string> = new Set();
112
+
113
+ // Promise when resolved returns the GC data data in the base snapshot.
114
+ private readonly baseSnapshotDataP: Promise<IGarbageCollectionSnapshotData | undefined>;
115
+ // Promise when resolved initializes the GC state from the data in the base snapshot.
116
+ private readonly initializeGCStateFromBaseSnapshotP: Promise<void>;
117
+ // The GC details generated from the base snapshot.
118
+ private readonly baseGCDetailsP: Promise<IGarbageCollectionDetailsBase>;
119
+ // Map of node ids to their unreferenced state tracker.
120
+ private readonly unreferencedNodesState: Map<string, UnreferencedStateTracker> = new Map();
121
+ // The Timer responsible for closing the container when the session has expired
122
+ private sessionExpiryTimer: Timer | undefined;
123
+
124
+ // Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one
125
+ // per event per node.
126
+ private readonly loggedUnreferencedEvents: Set<string> = new Set();
127
+ // Queue for unreferenced events that should be logged the next time GC runs.
128
+ private pendingEventsQueue: IUnreferencedEventProps[] = [];
129
+
130
+ // The number of times GC has successfully completed on this instance of GarbageCollector.
131
+ private completedRuns = 0;
132
+
133
+ private readonly runtime: IGarbageCollectionRuntime;
134
+ private readonly createContainerMetadata: ICreateContainerMetadata;
135
+ private readonly isSummarizerClient: boolean;
136
+
137
+ private readonly summaryStateTracker: GCSummaryStateTracker;
138
+
139
+ /** For a given node path, returns the node's package path. */
140
+ private readonly getNodePackagePath: (
141
+ nodePath: string,
142
+ ) => Promise<readonly string[] | undefined>;
143
+ /** Returns the timestamp of the last summary generated for this container. */
144
+ private readonly getLastSummaryTimestampMs: () => number | undefined;
145
+ /** Returns true if connection is active, i.e. it's "write" connection and the runtime is connected. */
146
+ private readonly activeConnection: () => boolean;
147
+
148
+ public get summaryStateNeedsReset(): boolean {
149
+ return this.summaryStateTracker.doesSummaryStateNeedReset;
150
+ }
151
+
152
+ protected constructor(createParams: IGarbageCollectorCreateParams) {
153
+ this.runtime = createParams.runtime;
154
+ this.isSummarizerClient = createParams.isSummarizerClient;
155
+ this.createContainerMetadata = createParams.createContainerMetadata;
156
+ this.getNodePackagePath = createParams.getNodePackagePath;
157
+ this.getLastSummaryTimestampMs = createParams.getLastSummaryTimestampMs;
158
+ this.activeConnection = createParams.activeConnection;
159
+
160
+ const baseSnapshot = createParams.baseSnapshot;
161
+ const readAndParseBlob = createParams.readAndParseBlob;
162
+
163
+ this.mc = loggerToMonitoringContext(
164
+ ChildLogger.create(createParams.baseLogger, "GarbageCollector", {
165
+ all: { completedGCRuns: () => this.completedRuns },
166
+ }),
167
+ );
168
+
169
+ this.configs = generateGCConfigs(this.mc, createParams);
170
+
171
+ // If session expiry is enabled, we need to close the container when the session expiry timeout expires.
172
+ if (this.configs.sessionExpiryTimeoutMs !== undefined) {
173
+ // If Test Override config is set, override Session Expiry timeout.
174
+ const overrideSessionExpiryTimeoutMs = this.mc.config.getNumber(
175
+ "Fluid.GarbageCollection.TestOverride.SessionExpiryMs",
176
+ );
177
+ const timeoutMs = overrideSessionExpiryTimeoutMs ?? this.configs.sessionExpiryTimeoutMs;
178
+
179
+ this.sessionExpiryTimer = new Timer(timeoutMs, () => {
180
+ this.runtime.closeFn(
181
+ new ClientSessionExpiredError(`Client session expired.`, timeoutMs),
182
+ );
183
+ });
184
+ this.sessionExpiryTimer.start();
185
+ }
186
+
187
+ this.summaryStateTracker = new GCSummaryStateTracker(
188
+ this.configs,
189
+ baseSnapshot?.trees[gcTreeKey] !== undefined /* wasGCRunInBaseSnapshot */,
190
+ );
191
+
192
+ // Get the GC data from the base snapshot. Use LazyPromise because we only want to do this once since it
193
+ // it involves fetching blobs from storage which is expensive.
194
+ this.baseSnapshotDataP = new LazyPromise<IGarbageCollectionSnapshotData | undefined>(
195
+ async () => {
196
+ if (baseSnapshot === undefined) {
197
+ return undefined;
198
+ }
199
+
200
+ try {
201
+ // For newer documents, GC data should be present in the GC tree in the root of the snapshot.
202
+ const gcSnapshotTree = baseSnapshot.trees[gcTreeKey];
203
+ if (gcSnapshotTree === undefined) {
204
+ // back-compat - Older documents get their gc data reset for simplicity as there are few of them
205
+ // incremental gc summary will not work with older gc data as well
206
+ return undefined;
207
+ }
208
+
209
+ const snapshotData = await getGCDataFromSnapshot(
210
+ gcSnapshotTree,
211
+ readAndParseBlob,
212
+ );
213
+
214
+ // If the GC version in base snapshot does not match the GC version currently in effect, the GC data
215
+ // in the snapshot cannot be interpreted correctly. Set everything to undefined except for
216
+ // deletedNodes because irrespective of GC versions, these nodes have been deleted and cannot be
217
+ // brought back. The deletedNodes info is needed to identify when these nodes are used.
218
+ if (
219
+ this.configs.gcVersionInBaseSnapshot !==
220
+ this.summaryStateTracker.currentGCVersion
221
+ ) {
222
+ return {
223
+ gcState: undefined,
224
+ tombstones: undefined,
225
+ deletedNodes: snapshotData.deletedNodes,
226
+ };
227
+ }
228
+ return snapshotData;
229
+ } catch (error) {
230
+ const dpe = DataProcessingError.wrapIfUnrecognized(
231
+ error,
232
+ "FailedToInitializeGC",
233
+ );
234
+ dpe.addTelemetryProperties({
235
+ gcConfigs: JSON.stringify(this.configs),
236
+ });
237
+ throw dpe;
238
+ }
239
+ },
240
+ );
241
+
242
+ /**
243
+ * Set up the initializer which initializes the GC state from the data in base snapshot. This is done when
244
+ * connected in write mode or when GC runs the first time. It sets up all unreferenced nodes from the base
245
+ * GC state and updates their inactive or sweep ready state.
246
+ */
247
+ this.initializeGCStateFromBaseSnapshotP = new LazyPromise<void>(async () => {
248
+ /**
249
+ * If there is no current reference timestamp, skip initialization. We need the current timestamp to track
250
+ * how long objects have been unreferenced and if they can be deleted.
251
+ *
252
+ * Note that the only scenario where there is no reference timestamp is when no ops have ever been processed
253
+ * for this container and it is in read mode. In this scenario, there is no point in running GC anyway
254
+ * because references in the container do not change without any ops, i.e., there is nothing to collect.
255
+ */
256
+ const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
257
+ if (currentReferenceTimestampMs === undefined) {
258
+ // Log an event so we can evaluate how often we run into this scenario.
259
+ this.mc.logger.sendErrorEvent({
260
+ eventName: "GarbageCollectorInitializedWithoutTimestamp",
261
+ gcConfigs: JSON.stringify(this.configs),
262
+ });
263
+ return;
264
+ }
265
+ /**
266
+ * The base snapshot data will not be present if the container is loaded from:
267
+ * 1. The first summary created by the detached container.
268
+ * 2. A summary that was generated with GC disabled.
269
+ * 3. A summary that was generated before GC even existed.
270
+ */
271
+ const baseSnapshotData = await this.baseSnapshotDataP;
272
+ if (baseSnapshotData === undefined) {
273
+ return;
274
+ }
275
+ this.updateStateFromSnapshotData(baseSnapshotData, currentReferenceTimestampMs);
276
+ this.summaryStateTracker.initializeBaseState(baseSnapshotData);
277
+ });
278
+
279
+ // Get the GC details from the GC state in the base summary. This is returned in getBaseGCDetails which is
280
+ // used to initialize the GC state of all the nodes in the container.
281
+ this.baseGCDetailsP = new LazyPromise<IGarbageCollectionDetailsBase>(async () => {
282
+ const baseSnapshotData = await this.baseSnapshotDataP;
283
+ if (baseSnapshotData?.gcState === undefined) {
284
+ return {};
285
+ }
286
+
287
+ const gcNodes: { [id: string]: string[] } = {};
288
+ for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
289
+ gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
290
+ }
291
+ // Run GC on the nodes in the base summary to get the routes used in each node in the container.
292
+ // This is an optimization for space (vs performance) wherein we don't need to store the used routes of
293
+ // each node in the summary.
294
+ const usedRoutes = runGarbageCollection(gcNodes, ["/"]).referencedNodeIds;
295
+
296
+ return { gcData: { gcNodes }, usedRoutes };
297
+ });
298
+
299
+ // Log all the GC options and the state determined by the garbage collector. This is interesting only for the
300
+ // summarizer client since it is the only one that runs GC. It also helps keep the telemetry less noisy.
301
+ if (this.isSummarizerClient) {
302
+ this.mc.logger.sendTelemetryEvent({
303
+ eventName: "GarbageCollectorLoaded",
304
+ gcConfigs: JSON.stringify(this.configs),
305
+ gcOptions: JSON.stringify(createParams.gcOptions),
306
+ });
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Called during container initialization. Initialize from the tombstone state in the base snapshot. This is done
312
+ * during initialization so that deleted or tombstoned objects are marked as such before they are loaded or used.
313
+ */
314
+ public async initializeBaseState(): Promise<void> {
315
+ const baseSnapshotData = await this.baseSnapshotDataP;
316
+ /**
317
+ * The base snapshot data will not be present if the container is loaded from:
318
+ * 1. The first summary created by the detached container.
319
+ * 2. A summary that was generated with GC disabled.
320
+ * 3. A summary that was generated before GC even existed.
321
+ */
322
+ if (baseSnapshotData === undefined) {
323
+ return;
324
+ }
325
+
326
+ // Initialize the deleted nodes from the snapshot. This is done irrespective of whether sweep is enabled or not
327
+ // to identify deleted nodes' usage.
328
+ if (baseSnapshotData.deletedNodes !== undefined) {
329
+ this.deletedNodes = new Set(baseSnapshotData.deletedNodes);
330
+ }
331
+
332
+ // If running in tombstone mode, initialize the tombstone state from the snapshot. Also, notify the runtime of
333
+ // tombstone routes.
334
+ if (this.configs.tombstoneMode && baseSnapshotData.tombstones !== undefined) {
335
+ // Create a copy since we are writing from a source we don't control
336
+ this.tombstones = Array.from(baseSnapshotData.tombstones);
337
+ this.runtime.updateTombstonedRoutes(this.tombstones);
338
+ }
339
+ }
340
+
341
+ /**
342
+ * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.
343
+ * All current tracking is reset and updated from the data in the snapshot.
344
+ * @param snapshotData - The snapshot data to update state from. If this is undefined, all GC state and tracking
345
+ * is reset.
346
+ * @param currentReferenceTimestampMs - The current reference timestamp for marking unreferenced nodes' unreferenced
347
+ * timestamp.
348
+ */
349
+ private updateStateFromSnapshotData(
350
+ snapshotData: IGarbageCollectionSnapshotData | undefined,
351
+ currentReferenceTimestampMs: number,
352
+ ) {
353
+ /**
354
+ * Note: "newReferencesSinceLastRun" is not reset here. This is done because there may be references since the
355
+ * snapshot that we are updating state from. For example, this client may have processed ops till seq#1000 and
356
+ * its refreshing state from a summary that happened at seq#900. In this case, there may be references between
357
+ * seq#901 and seq#1000 that we don't want to reset.
358
+ * Unfortunately, there is no way to track the seq# of ops that add references, so we choose to not reset any
359
+ * references here. This should be fine because, in the worst case, we may end up updating the unreferenced
360
+ * timestamp of a node which will delay its deletion. Although not ideal, this will only happen in rare
361
+ * scenarios, so it should be okay.
362
+ */
363
+
364
+ // Clear all existing unreferenced state tracking.
365
+ for (const [, nodeStateTracker] of this.unreferencedNodesState) {
366
+ nodeStateTracker.stopTracking();
367
+ }
368
+ this.unreferencedNodesState.clear();
369
+
370
+ // If running sweep, the tombstone state represents the list of nodes that have been deleted during sweep.
371
+ // If running in tombstone mode, the tombstone state represents the list of nodes that have been marked as
372
+ // tombstones.
373
+ // If this call is because we are refreshing from a snapshot due to an ack, it is likely that the GC state
374
+ // in the snapshot is newer than this client's. And so, the deleted / tombstone nodes need to be updated.
375
+ if (this.configs.shouldRunSweep) {
376
+ const snapshotDeletedNodes = snapshotData?.deletedNodes
377
+ ? new Set(snapshotData.deletedNodes)
378
+ : undefined;
379
+ // If the snapshot contains deleted nodes that are not yet deleted by this client, ask the runtime to
380
+ // delete them.
381
+ if (snapshotDeletedNodes !== undefined) {
382
+ const newDeletedNodes: string[] = [];
383
+ for (const nodeId of snapshotDeletedNodes) {
384
+ if (!this.deletedNodes.has(nodeId)) {
385
+ newDeletedNodes.push(nodeId);
386
+ }
387
+ }
388
+ if (newDeletedNodes.length > 0) {
389
+ // Call container runtime to delete these nodes and add deleted nodes to this.deletedNodes.
390
+ }
391
+ }
392
+ } else if (this.configs.tombstoneMode) {
393
+ // The snapshot may contain more or fewer tombstone nodes than this client. Update tombstone state and
394
+ // notify the runtime to update its state as well.
395
+ this.tombstones = snapshotData?.tombstones ? Array.from(snapshotData.tombstones) : [];
396
+ this.runtime.updateTombstonedRoutes(this.tombstones);
397
+ }
398
+
399
+ // If there is no snapshot data, it means this snapshot was generated with GC disabled. Unset all GC state.
400
+ if (snapshotData?.gcState === undefined) {
401
+ this.gcDataFromLastRun = undefined;
402
+ return;
403
+ }
404
+
405
+ // Update unreferenced state tracking as per the GC state in the snapshot data and update gcDataFromLastRun
406
+ // to the GC data from the snapshot data.
407
+ const gcNodes: { [id: string]: string[] } = {};
408
+ for (const [nodeId, nodeData] of Object.entries(snapshotData.gcState.gcNodes)) {
409
+ if (nodeData.unreferencedTimestampMs !== undefined) {
410
+ this.unreferencedNodesState.set(
411
+ nodeId,
412
+ new UnreferencedStateTracker(
413
+ nodeData.unreferencedTimestampMs,
414
+ this.configs.inactiveTimeoutMs,
415
+ currentReferenceTimestampMs,
416
+ this.configs.sweepTimeoutMs,
417
+ ),
418
+ );
419
+ }
420
+ gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
421
+ }
422
+ this.gcDataFromLastRun = { gcNodes };
423
+ }
424
+
425
+ /**
426
+ * Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this
427
+ * to initialize the base state for non-summarizer clients so that they can track inactive / sweep ready nodes.
428
+ * @param connected - Whether the runtime connected / disconnected.
429
+ * @param clientId - The clientId of this runtime.
430
+ */
431
+ public setConnectionState(connected: boolean, clientId?: string | undefined): void {
432
+ /**
433
+ * For all clients, initialize the base state when the container becomes active, i.e., it transitions
434
+ * to "write" mode. This will ensure that the container's own join op is processed and there is a recent
435
+ * reference timestamp that will be used to update the state of unreferenced nodes. Also, all trailing ops which
436
+ * could affect the GC state will have been processed.
437
+ *
438
+ * If GC is up-to-date for the client and the summarizing client, there will be an doubling of both
439
+ * InactiveObject_Loaded and SweepReady_Loaded errors, as there will be one from the sending client and one from
440
+ * the receiving summarizer client.
441
+ *
442
+ * Ideally, this initialization should only be done for summarizer client. However, we are currently rolling out
443
+ * sweep in phases and we want to track when inactive and sweep ready objects are used in any client.
444
+ */
445
+ if (this.activeConnection() && this.configs.shouldRunGC) {
446
+ this.initializeGCStateFromBaseSnapshotP.catch((error) => {});
447
+ }
448
+ }
449
+
450
+ /**
451
+ * Runs garbage collection and updates the reference / used state of the nodes in the container.
452
+ * @returns stats of the GC run or undefined if GC did not run.
453
+ */
454
+ public async collectGarbage(
455
+ options: {
456
+ /** Logger to use for logging GC events */
457
+ logger?: ITelemetryLogger;
458
+ /** True to run GC sweep phase after the mark phase */
459
+ runSweep?: boolean;
460
+ /** True to generate full GC data */
461
+ fullGC?: boolean;
462
+ },
463
+ telemetryContext?: ITelemetryContext,
464
+ ): Promise<IGCStats | undefined> {
465
+ const fullGC =
466
+ options.fullGC ??
467
+ (this.configs.runFullGC === true || this.summaryStateTracker.doesSummaryStateNeedReset);
468
+ const logger = options.logger
469
+ ? ChildLogger.create(options.logger, undefined, {
470
+ all: { completedGCRuns: () => this.completedRuns },
471
+ })
472
+ : this.mc.logger;
473
+
474
+ /**
475
+ * If there is no current reference timestamp, skip running GC. We need the current timestamp to track
476
+ * how long objects have been unreferenced and if they should be deleted.
477
+ *
478
+ * Note that the only scenario where GC is called and there is no reference timestamp is when no ops have ever
479
+ * been processed for this container and it is in read mode. In this scenario, there is no point in running GC
480
+ * anyway because references in the container do not change without any ops, i.e., there is nothing to collect.
481
+ */
482
+ const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
483
+ if (currentReferenceTimestampMs === undefined) {
484
+ // Log an event so we can evaluate how often we run into this scenario.
485
+ logger.sendErrorEvent({
486
+ eventName: "CollectGarbageCalledWithoutTimestamp",
487
+ gcConfigs: JSON.stringify(this.configs),
488
+ });
489
+ return undefined;
490
+ }
491
+
492
+ // Add the options that are used to run GC to the telemetry context.
493
+ telemetryContext?.setMultiple("fluid_GC", "Options", {
494
+ fullGC,
495
+ runSweep: options.runSweep,
496
+ });
497
+
498
+ return PerformanceEvent.timedExecAsync(
499
+ logger,
500
+ { eventName: "GarbageCollection" },
501
+ async (event) => {
502
+ await this.runPreGCSteps();
503
+
504
+ // Get the runtime's GC data and run GC on the reference graph in it.
505
+ const gcData = await this.runtime.getGCData(fullGC);
506
+ const gcResult = runGarbageCollection(gcData.gcNodes, ["/"]);
507
+
508
+ const gcStats = await this.runPostGCSteps(
509
+ gcData,
510
+ gcResult,
511
+ logger,
512
+ currentReferenceTimestampMs,
513
+ );
514
+ event.end({ ...gcStats, timestamp: currentReferenceTimestampMs });
515
+ this.completedRuns++;
516
+ return gcStats;
517
+ },
518
+ { end: true, cancel: "error" },
519
+ );
520
+ }
521
+
522
+ private async runPreGCSteps() {
523
+ // Ensure that state has been initialized from the base snapshot data.
524
+ await this.initializeGCStateFromBaseSnapshotP;
525
+ // Let the runtime update its pending state before GC runs.
526
+ await this.runtime.updateStateBeforeGC();
527
+ }
528
+
529
+ private async runPostGCSteps(
530
+ gcData: IGarbageCollectionData,
531
+ gcResult: IGCResult,
532
+ logger: ITelemetryLogger,
533
+ currentReferenceTimestampMs: number,
534
+ ): Promise<IGCStats> {
535
+ // Generate statistics from the current run. This is done before updating the current state because it
536
+ // generates some of its data based on previous state of the system.
537
+ const gcStats = this.generateStats(gcResult);
538
+
539
+ // Update the current mark state and update the runtime of all used routes or ids that used as per the GC run.
540
+ const sweepReadyNodes = this.updateMarkPhase(
541
+ gcData,
542
+ gcResult,
543
+ currentReferenceTimestampMs,
544
+ logger,
545
+ );
546
+ this.runtime.updateUsedRoutes(gcResult.referencedNodeIds);
547
+
548
+ // Log events for objects that are ready to be deleted by sweep. When we have sweep enabled, we will
549
+ // delete these objects here instead.
550
+ this.logSweepEvents(logger, currentReferenceTimestampMs);
551
+
552
+ let updatedGCData: IGarbageCollectionData = gcData;
553
+
554
+ if (this.configs.shouldRunSweep) {
555
+ updatedGCData = this.runSweepPhase(sweepReadyNodes, gcData);
556
+ } else if (this.configs.testMode) {
557
+ // If we are running in GC test mode, delete objects for unused routes. This enables testing scenarios
558
+ // involving access to deleted data.
559
+ this.runtime.updateUnusedRoutes(gcResult.deletedNodeIds);
560
+ } else if (this.configs.tombstoneMode) {
561
+ this.tombstones = sweepReadyNodes;
562
+ // If we are running in GC tombstone mode, update tombstoned routes. This enables testing scenarios
563
+ // involving access to "deleted" data without actually deleting the data from summaries.
564
+ // Note: we will not tombstone in test mode.
565
+ this.runtime.updateTombstonedRoutes(this.tombstones);
566
+ }
567
+
568
+ this.gcDataFromLastRun = cloneGCData(updatedGCData);
569
+
570
+ // Log pending unreferenced events such as a node being used after inactive. This is done after GC runs and
571
+ // updates its state so that we don't send false positives based on intermediate state. For example, we may get
572
+ // reference to an unreferenced node from another unreferenced node which means the node wasn't revived.
573
+ await this.logUnreferencedEvents(logger);
574
+
575
+ return gcStats;
576
+ }
577
+
578
+ /**
579
+ * Summarizes the GC data and returns it as a summary tree.
580
+ * We current write the entire GC state in a single blob. This can be modified later to write multiple
581
+ * blobs. All the blob keys should start with `gcBlobPrefix`.
582
+ */
583
+ public summarize(
584
+ fullTree: boolean,
585
+ trackState: boolean,
586
+ telemetryContext?: ITelemetryContext,
587
+ ): ISummarizeResult | undefined {
588
+ if (!this.configs.shouldRunGC || this.gcDataFromLastRun === undefined) {
589
+ return;
590
+ }
591
+
592
+ const gcState: IGarbageCollectionState = { gcNodes: {} };
593
+ for (const [nodeId, outboundRoutes] of Object.entries(this.gcDataFromLastRun.gcNodes)) {
594
+ gcState.gcNodes[nodeId] = {
595
+ outboundRoutes,
596
+ unreferencedTimestampMs:
597
+ this.unreferencedNodesState.get(nodeId)?.unreferencedTimestampMs,
598
+ };
599
+ }
600
+
601
+ return this.summaryStateTracker.summarize(
602
+ fullTree,
603
+ trackState,
604
+ gcState,
605
+ this.deletedNodes,
606
+ this.tombstones,
607
+ );
608
+ }
609
+
610
+ public getMetadata(): IGCMetadata {
611
+ return {
612
+ /**
613
+ * If GC is enabled, the GC data is written using the current GC version and that is the gcFeature that goes
614
+ * into the metadata blob. If GC is disabled, the gcFeature is 0.
615
+ */
616
+ gcFeature: this.configs.gcEnabled ? this.summaryStateTracker.currentGCVersion : 0,
617
+ gcFeatureMatrix: this.configs.persistedGcFeatureMatrix,
618
+ sessionExpiryTimeoutMs: this.configs.sessionExpiryTimeoutMs,
619
+ sweepEnabled: false, // DEPRECATED - to be removed
620
+ sweepTimeoutMs: this.configs.sweepTimeoutMs,
621
+ };
622
+ }
623
+
624
+ /**
625
+ * Returns a the GC details generated from the base summary. This is used to initialize the GC state of the nodes
626
+ * in the container.
627
+ */
628
+ public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
629
+ return this.baseGCDetailsP;
630
+ }
631
+
632
+ /**
633
+ * Called to refresh the latest summary state. This happens when either a pending summary is acked or a snapshot
634
+ * is downloaded and should be used to update the state.
635
+ */
636
+ public async refreshLatestSummary(
637
+ proposalHandle: string | undefined,
638
+ result: RefreshSummaryResult,
639
+ readAndParseBlob: ReadAndParseBlob,
640
+ ): Promise<void> {
641
+ const latestSnapshotData = await this.summaryStateTracker.refreshLatestSummary(
642
+ proposalHandle,
643
+ result,
644
+ readAndParseBlob,
645
+ );
646
+
647
+ // If the latest summary was updated but it was not tracked by this client, our state needs to be updated from
648
+ // this snapshot data.
649
+ if (this.shouldRunGC && result.latestSummaryUpdated && !result.wasSummaryTracked) {
650
+ // The current reference timestamp should be available if we are refreshing state from a snapshot. There has
651
+ // to be at least one op (summary op / ack, if nothing else) if a snapshot was taken.
652
+ const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
653
+ if (currentReferenceTimestampMs === undefined) {
654
+ throw DataProcessingError.create(
655
+ "No reference timestamp when updating GC state from snapshot",
656
+ "refreshLatestSummary",
657
+ undefined,
658
+ {
659
+ proposalHandle,
660
+ summaryRefSeq: result.summaryRefSeq,
661
+ gcConfigs: JSON.stringify(this.configs),
662
+ },
663
+ );
664
+ }
665
+ this.updateStateFromSnapshotData(latestSnapshotData, currentReferenceTimestampMs);
666
+ }
667
+ }
668
+
669
+ /**
670
+ * Called when a node with the given id is updated. If the node is inactive, log an error.
671
+ * @param nodePath - The id of the node that changed.
672
+ * @param reason - Whether the node was loaded or changed.
673
+ * @param timestampMs - The timestamp when the node changed.
674
+ * @param packagePath - The package path of the node. This may not be available if the node hasn't been loaded yet.
675
+ * @param requestHeaders - If the node was loaded via request path, the headers in the request.
676
+ */
677
+ public nodeUpdated(
678
+ nodePath: string,
679
+ reason: "Loaded" | "Changed",
680
+ timestampMs?: number,
681
+ packagePath?: readonly string[],
682
+ requestHeaders?: IRequestHeader,
683
+ ) {
684
+ if (!this.configs.shouldRunGC) {
685
+ return;
686
+ }
687
+
688
+ const nodeStateTracker = this.unreferencedNodesState.get(nodePath);
689
+ if (nodeStateTracker && nodeStateTracker.state !== UnreferencedState.Active) {
690
+ this.inactiveNodeUsed(
691
+ reason,
692
+ nodePath,
693
+ nodeStateTracker,
694
+ undefined /* fromNodeId */,
695
+ packagePath,
696
+ timestampMs,
697
+ requestHeaders,
698
+ );
699
+ }
700
+ }
701
+
702
+ /**
703
+ * Called when an outbound reference is added to a node. This is used to identify all nodes that have been
704
+ * referenced between summaries so that their unreferenced timestamp can be reset.
705
+ *
706
+ * @param fromNodePath - The node from which the reference is added.
707
+ * @param toNodePath - The node to which the reference is added.
708
+ */
709
+ public addedOutboundReference(fromNodePath: string, toNodePath: string) {
710
+ if (!this.configs.shouldRunGC) {
711
+ return;
712
+ }
713
+
714
+ const outboundRoutes = this.newReferencesSinceLastRun.get(fromNodePath) ?? [];
715
+ outboundRoutes.push(toNodePath);
716
+ this.newReferencesSinceLastRun.set(fromNodePath, outboundRoutes);
717
+
718
+ const nodeStateTracker = this.unreferencedNodesState.get(toNodePath);
719
+ if (nodeStateTracker && nodeStateTracker.state !== UnreferencedState.Active) {
720
+ this.inactiveNodeUsed("Revived", toNodePath, nodeStateTracker, fromNodePath);
721
+ }
722
+
723
+ if (this.tombstones.includes(toNodePath)) {
724
+ const nodeType = this.runtime.getNodeType(toNodePath);
725
+
726
+ let eventName = "GC_Tombstone_SubDatastore_Revived";
727
+ if (nodeType === GCNodeType.DataStore) {
728
+ eventName = "GC_Tombstone_Datastore_Revived";
729
+ } else if (nodeType === GCNodeType.Blob) {
730
+ eventName = "GC_Tombstone_Blob_Revived";
731
+ }
732
+
733
+ sendGCUnexpectedUsageEvent(
734
+ this.mc,
735
+ {
736
+ eventName,
737
+ category: "generic",
738
+ url: toNodePath,
739
+ nodeType,
740
+ gcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,
741
+ },
742
+ undefined /* packagePath */,
743
+ );
744
+ }
745
+ }
746
+
747
+ /**
748
+ * Returns whether a node with the given path has been deleted or not. This can be used by the runtime to identify
749
+ * cases where objects are used after they are deleted and throw / log errors accordingly.
750
+ */
751
+ public isNodeDeleted(nodePath: string): boolean {
752
+ return this.deletedNodes.has(nodePath);
753
+ }
754
+
755
+ public dispose(): void {
756
+ this.sessionExpiryTimer?.clear();
757
+ this.sessionExpiryTimer = undefined;
758
+ }
759
+
760
+ /**
761
+ * Updates the state of the system as per the current GC run. It does the following:
762
+ * 1. Sets up the current GC state as per the gcData.
763
+ * 2. Starts tracking for nodes that have become unreferenced in this run.
764
+ * 3. Clears tracking for nodes that were unreferenced but became referenced in this run.
765
+ * @param gcData - The data representing the reference graph on which GC is run.
766
+ * @param gcResult - The result of the GC run on the gcData.
767
+ * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp.
768
+ * @returns - A list of sweep ready nodes. (Nodes ready to be deleted)
769
+ */
770
+ private updateMarkPhase(
771
+ gcData: IGarbageCollectionData,
772
+ gcResult: IGCResult,
773
+ currentReferenceTimestampMs: number,
774
+ logger: ITelemetryLogger,
775
+ ) {
776
+ // Get references from the current GC run + references between previous and current run and then update each
777
+ // node's state
778
+ const allNodesReferencedBetweenGCs =
779
+ this.findAllNodesReferencedBetweenGCs(gcData, this.gcDataFromLastRun, logger) ??
780
+ gcResult.referencedNodeIds;
781
+ this.newReferencesSinceLastRun.clear();
782
+
783
+ // Iterate through the referenced nodes and stop tracking if they were unreferenced before.
784
+ for (const nodeId of allNodesReferencedBetweenGCs) {
785
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
786
+ if (nodeStateTracker !== undefined) {
787
+ // Stop tracking so as to clear out any running timers.
788
+ nodeStateTracker.stopTracking();
789
+ // Delete the node as we don't need to track it any more.
790
+ this.unreferencedNodesState.delete(nodeId);
791
+ }
792
+ }
793
+
794
+ /**
795
+ * If a node became unreferenced in this run, start tracking it.
796
+ * If a node was already unreferenced, update its tracking information. Since the current reference time is
797
+ * from the ops seen, this will ensure that we keep updating the unreferenced state as time moves forward.
798
+ *
799
+ * If a node is sweep ready, store and then return it.
800
+ */
801
+ const sweepReadyNodes: string[] = [];
802
+ for (const nodeId of gcResult.deletedNodeIds) {
803
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
804
+ if (nodeStateTracker === undefined) {
805
+ this.unreferencedNodesState.set(
806
+ nodeId,
807
+ new UnreferencedStateTracker(
808
+ currentReferenceTimestampMs,
809
+ this.configs.inactiveTimeoutMs,
810
+ currentReferenceTimestampMs,
811
+ this.configs.sweepTimeoutMs,
812
+ ),
813
+ );
814
+ } else {
815
+ nodeStateTracker.updateTracking(currentReferenceTimestampMs);
816
+ if (nodeStateTracker.state === UnreferencedState.SweepReady) {
817
+ sweepReadyNodes.push(nodeId);
818
+ }
819
+ }
820
+ }
821
+
822
+ return sweepReadyNodes;
823
+ }
824
+
825
+ /**
826
+ * Deletes nodes from both the runtime and garbage collection
827
+ * @param sweepReadyNodes - nodes that are ready to be deleted
828
+ */
829
+ private runSweepPhase(sweepReadyNodes: string[], gcData: IGarbageCollectionData) {
830
+ // TODO: GC:Validation - validate that removed routes are not double deleted
831
+ // TODO: GC:Validation - validate that the child routes of removed routes are deleted as well
832
+ const sweptRoutes = this.runtime.deleteSweepReadyNodes(sweepReadyNodes);
833
+ const updatedGCData = this.deleteSweptRoutes(sweptRoutes, gcData);
834
+
835
+ for (const nodeId of sweptRoutes) {
836
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
837
+ // TODO: GC:Validation - assert that the nodeStateTracker is defined
838
+ if (nodeStateTracker !== undefined) {
839
+ // Stop tracking so as to clear out any running timers.
840
+ nodeStateTracker.stopTracking();
841
+ // Delete the node as we don't need to track it any more.
842
+ this.unreferencedNodesState.delete(nodeId);
843
+ }
844
+ // TODO: GC:Validation - assert that the deleted node is not a duplicate
845
+ this.deletedNodes.add(nodeId);
846
+ }
847
+
848
+ return updatedGCData;
849
+ }
850
+
851
+ /**
852
+ * @returns IGarbageCollectionData after deleting the sweptRoutes from the gcData
853
+ */
854
+ private deleteSweptRoutes(
855
+ sweptRoutes: string[],
856
+ gcData: IGarbageCollectionData,
857
+ ): IGarbageCollectionData {
858
+ const sweptRoutesSet = new Set<string>(sweptRoutes);
859
+ const gcNodes: { [id: string]: string[] } = {};
860
+ for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {
861
+ if (!sweptRoutesSet.has(id)) {
862
+ gcNodes[id] = Array.from(outboundRoutes);
863
+ }
864
+ }
865
+
866
+ // TODO: GC:Validation - assert that the nodeId is in gcData
867
+
868
+ return {
869
+ gcNodes,
870
+ };
871
+ }
872
+
873
+ /**
874
+ * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in
875
+ * time. There can be nodes that were referenced in between two runs and their unreferenced state needs to be
876
+ * updated. For example, in the following scenarios not updating the unreferenced timestamp can lead to deletion of
877
+ * these objects while there can be in-memory referenced to it:
878
+ * 1. A node transitions from `unreferenced -> referenced -> unreferenced` between two runs. When the reference is
879
+ * added, the object may have been accessed and in-memory reference to it added.
880
+ * 2. A reference is added from one unreferenced node to one or more unreferenced nodes. Even though the node[s] were
881
+ * unreferenced, they could have been accessed and in-memory reference to them added.
882
+ *
883
+ * This function identifies nodes that were referenced since the last run.
884
+ * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.
885
+ *
886
+ * @returns - a list of all nodes referenced from the last local summary until now.
887
+ */
888
+ private findAllNodesReferencedBetweenGCs(
889
+ currentGCData: IGarbageCollectionData,
890
+ previousGCData: IGarbageCollectionData | undefined,
891
+ logger: ITelemetryLogger,
892
+ ): string[] | undefined {
893
+ // If we haven't run GC before there is nothing to do.
894
+ // No previousGCData, means nothing is unreferenced, and there are no reference state trackers to clear
895
+ if (previousGCData === undefined) {
896
+ return undefined;
897
+ }
898
+
899
+ // Find any references that haven't been identified correctly.
900
+ const missingExplicitReferences = this.findMissingExplicitReferences(
901
+ currentGCData,
902
+ previousGCData,
903
+ this.newReferencesSinceLastRun,
904
+ );
905
+
906
+ if (missingExplicitReferences.length > 0) {
907
+ missingExplicitReferences.forEach((missingExplicitReference) => {
908
+ logger.sendErrorEvent({
909
+ eventName: "gcUnknownOutboundReferences",
910
+ gcNodeId: missingExplicitReference[0],
911
+ gcRoutes: JSON.stringify(missingExplicitReference[1]),
912
+ });
913
+ });
914
+ }
915
+
916
+ // No references were added since the last run so we don't have to update reference states of any unreferenced
917
+ // nodes. There is no in between state at this point.
918
+ if (this.newReferencesSinceLastRun.size === 0) {
919
+ return undefined;
920
+ }
921
+
922
+ /**
923
+ * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and
924
+ * edges that have been added since then. To do this, combine the GC data from the last run and the current
925
+ * run, and then add the references since last run.
926
+ *
927
+ * Note on why we need to combine the data from previous run, current run and all references in between -
928
+ * 1. We need data from last run because some of its references may have been deleted since then. If those
929
+ * references added new outbound references before they were deleted, we need to detect them.
930
+ *
931
+ * 2. We need new outbound references since last run because some of them may have been deleted later. If those
932
+ * references added new outbound references before they were deleted, we need to detect them.
933
+ *
934
+ * 3. We need data from the current run because currently we may not detect when DDSes are referenced:
935
+ * - We don't require DDSes handles to be stored in a referenced DDS.
936
+ * - A new data store may have "root" DDSes already created and we don't detect them today.
937
+ */
938
+ const gcDataSuperSet = concatGarbageCollectionData(previousGCData, currentGCData);
939
+ const newOutboundRoutesSinceLastRun: string[] = [];
940
+ this.newReferencesSinceLastRun.forEach((outboundRoutes: string[], sourceNodeId: string) => {
941
+ if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {
942
+ gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;
943
+ } else {
944
+ gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);
945
+ }
946
+ newOutboundRoutesSinceLastRun.push(...outboundRoutes);
947
+ });
948
+
949
+ /**
950
+ * Run GC on the above reference graph starting with root and all new outbound routes. This will generate a
951
+ * list of all nodes that could have been referenced since the last run. If any of these nodes are unreferenced,
952
+ * unreferenced, stop tracking them and remove from unreferenced list.
953
+ * Note that some of these nodes may be unreferenced now and if so, the current run will mark them as
954
+ * unreferenced and add unreferenced state.
955
+ */
956
+ const gcResult = runGarbageCollection(gcDataSuperSet.gcNodes, [
957
+ "/",
958
+ ...newOutboundRoutesSinceLastRun,
959
+ ]);
960
+ return gcResult.referencedNodeIds;
961
+ }
962
+
963
+ /**
964
+ * Finds all new references or outbound routes in the current graph that haven't been explicitly notified to GC.
965
+ * The principle is that every new reference or outbound route must be notified to GC via the
966
+ * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.
967
+ *
968
+ * In more simple terms:
969
+ * Missing Explicit References = Current References - Previous References - Explicitly Added References;
970
+ *
971
+ * @param currentGCData - The GC data (reference graph) from the current GC run.
972
+ * @param previousGCData - The GC data (reference graph) from the previous GC run.
973
+ * @param explicitReferences - New references added explicity between the previous and the current run.
974
+ * @returns - a list of missing explicit references
975
+ */
976
+ private findMissingExplicitReferences(
977
+ currentGCData: IGarbageCollectionData,
978
+ previousGCData: IGarbageCollectionData,
979
+ explicitReferences: Map<string, string[]>,
980
+ ): [string, string[]][] {
981
+ assert(
982
+ previousGCData !== undefined,
983
+ 0x2b7 /* "Can't validate correctness without GC data from last run" */,
984
+ );
985
+
986
+ const currentGraph = Object.entries(currentGCData.gcNodes);
987
+ const missingExplicitReferences: [string, string[]][] = [];
988
+ currentGraph.forEach(([nodeId, currentOutboundRoutes]) => {
989
+ const previousRoutes = previousGCData.gcNodes[nodeId] ?? [];
990
+ const explicitRoutes = explicitReferences.get(nodeId) ?? [];
991
+ const missingExplicitRoutes: string[] = [];
992
+
993
+ /**
994
+ * 1. For routes in the current GC data, routes that were not present in previous GC data and did not have
995
+ * explicit references should be added to missing explicit routes list.
996
+ * 2. Only include data store and blob routes since GC only works for these two.
997
+ * Note: Due to a bug with de-duped blobs, only adding data store routes for now.
998
+ * 3. Ignore DDS routes to their parent datastores since those were added implicitly. So, there won't be
999
+ * explicit routes to them.
1000
+ */
1001
+ currentOutboundRoutes.forEach((route) => {
1002
+ const nodeType = this.runtime.getNodeType(route);
1003
+ if (
1004
+ (nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) &&
1005
+ !nodeId.startsWith(route) &&
1006
+ !previousRoutes.includes(route) &&
1007
+ !explicitRoutes.includes(route)
1008
+ ) {
1009
+ missingExplicitRoutes.push(route);
1010
+ }
1011
+ });
1012
+ if (missingExplicitRoutes.length > 0) {
1013
+ missingExplicitReferences.push([nodeId, missingExplicitRoutes]);
1014
+ }
1015
+ });
1016
+
1017
+ // Ideally missingExplicitReferences should always have a size 0
1018
+ return missingExplicitReferences;
1019
+ }
1020
+
1021
+ /**
1022
+ * Generates the stats of a garbage collection run from the given results of the run.
1023
+ * @param gcResult - The result of a GC run.
1024
+ * @returns the GC stats of the GC run.
1025
+ */
1026
+ private generateStats(gcResult: IGCResult): IGCStats {
1027
+ const gcStats: IGCStats = {
1028
+ nodeCount: 0,
1029
+ dataStoreCount: 0,
1030
+ attachmentBlobCount: 0,
1031
+ unrefNodeCount: 0,
1032
+ unrefDataStoreCount: 0,
1033
+ unrefAttachmentBlobCount: 0,
1034
+ updatedNodeCount: 0,
1035
+ updatedDataStoreCount: 0,
1036
+ updatedAttachmentBlobCount: 0,
1037
+ };
1038
+
1039
+ const updateNodeStats = (nodeId: string, referenced: boolean) => {
1040
+ gcStats.nodeCount++;
1041
+ // If there is no previous GC data, every node's state is generated and is considered as updated.
1042
+ // Otherwise, find out if any node went from referenced to unreferenced or vice-versa.
1043
+ const stateUpdated =
1044
+ this.gcDataFromLastRun === undefined ||
1045
+ this.unreferencedNodesState.has(nodeId) === referenced;
1046
+ if (stateUpdated) {
1047
+ gcStats.updatedNodeCount++;
1048
+ }
1049
+ if (!referenced) {
1050
+ gcStats.unrefNodeCount++;
1051
+ }
1052
+
1053
+ if (this.runtime.getNodeType(nodeId) === GCNodeType.DataStore) {
1054
+ gcStats.dataStoreCount++;
1055
+ if (stateUpdated) {
1056
+ gcStats.updatedDataStoreCount++;
1057
+ }
1058
+ if (!referenced) {
1059
+ gcStats.unrefDataStoreCount++;
1060
+ }
1061
+ }
1062
+ if (this.runtime.getNodeType(nodeId) === GCNodeType.Blob) {
1063
+ gcStats.attachmentBlobCount++;
1064
+ if (stateUpdated) {
1065
+ gcStats.updatedAttachmentBlobCount++;
1066
+ }
1067
+ if (!referenced) {
1068
+ gcStats.unrefAttachmentBlobCount++;
1069
+ }
1070
+ }
1071
+ };
1072
+
1073
+ for (const nodeId of gcResult.referencedNodeIds) {
1074
+ updateNodeStats(nodeId, true /* referenced */);
1075
+ }
1076
+
1077
+ for (const nodeId of gcResult.deletedNodeIds) {
1078
+ updateNodeStats(nodeId, false /* referenced */);
1079
+ }
1080
+
1081
+ return gcStats;
1082
+ }
1083
+
1084
+ /**
1085
+ * For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,
1086
+ * this will give us a view into how much deleted content a container has.
1087
+ */
1088
+ private logSweepEvents(logger: ITelemetryLogger, currentReferenceTimestampMs: number) {
1089
+ if (
1090
+ this.mc.config.getBoolean(disableSweepLogKey) === true ||
1091
+ this.configs.sweepTimeoutMs === undefined
1092
+ ) {
1093
+ return;
1094
+ }
1095
+
1096
+ this.unreferencedNodesState.forEach((nodeStateTracker, nodeId) => {
1097
+ if (nodeStateTracker.state !== UnreferencedState.SweepReady) {
1098
+ return;
1099
+ }
1100
+
1101
+ const nodeType = this.runtime.getNodeType(nodeId);
1102
+ if (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {
1103
+ return;
1104
+ }
1105
+
1106
+ // Log deleted event for each node only once to reduce noise in telemetry.
1107
+ const uniqueEventId = `Deleted-${nodeId}`;
1108
+ if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
1109
+ return;
1110
+ }
1111
+ this.loggedUnreferencedEvents.add(uniqueEventId);
1112
+ logger.sendTelemetryEvent({
1113
+ eventName: "GCObjectDeleted",
1114
+ id: nodeId,
1115
+ type: nodeType,
1116
+ age: currentReferenceTimestampMs - nodeStateTracker.unreferencedTimestampMs,
1117
+ timeout: this.configs.sweepTimeoutMs,
1118
+ completedGCRuns: this.completedRuns,
1119
+ lastSummaryTime: this.getLastSummaryTimestampMs(),
1120
+ });
1121
+ });
1122
+ }
1123
+
1124
+ /**
1125
+ * Called when an inactive node is used after. Queue up an event that will be logged next time GC runs.
1126
+ */
1127
+ private inactiveNodeUsed(
1128
+ usageType: "Changed" | "Loaded" | "Revived",
1129
+ nodeId: string,
1130
+ nodeStateTracker: UnreferencedStateTracker,
1131
+ fromNodeId?: string,
1132
+ packagePath?: readonly string[],
1133
+ currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs(),
1134
+ requestHeaders?: IRequestHeader,
1135
+ ) {
1136
+ // If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip
1137
+ // logging as nothing interesting would have happened worth logging.
1138
+ // If the node is active, skip logging.
1139
+ if (
1140
+ currentReferenceTimestampMs === undefined ||
1141
+ nodeStateTracker.state === UnreferencedState.Active
1142
+ ) {
1143
+ return;
1144
+ }
1145
+
1146
+ // We only care about data stores and attachment blobs for this telemetry since GC only marks these objects
1147
+ // as unreferenced. Also, if an inactive DDS is used, the corresponding data store store will also be used.
1148
+ const nodeType = this.runtime.getNodeType(nodeId);
1149
+ if (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {
1150
+ return;
1151
+ }
1152
+
1153
+ const state = nodeStateTracker.state;
1154
+ const uniqueEventId = `${state}-${nodeId}-${usageType}`;
1155
+ if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
1156
+ return;
1157
+ }
1158
+ this.loggedUnreferencedEvents.add(uniqueEventId);
1159
+
1160
+ const propsToLog = {
1161
+ id: nodeId,
1162
+ type: nodeType,
1163
+ unrefTime: nodeStateTracker.unreferencedTimestampMs,
1164
+ age: currentReferenceTimestampMs - nodeStateTracker.unreferencedTimestampMs,
1165
+ timeout:
1166
+ nodeStateTracker.state === UnreferencedState.Inactive
1167
+ ? this.configs.inactiveTimeoutMs
1168
+ : this.configs.sweepTimeoutMs,
1169
+ completedGCRuns: this.completedRuns,
1170
+ lastSummaryTime: this.getLastSummaryTimestampMs(),
1171
+ ...this.createContainerMetadata,
1172
+ viaHandle: requestHeaders?.[RuntimeHeaders.viaHandle],
1173
+ fromId: fromNodeId,
1174
+ };
1175
+
1176
+ // For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.
1177
+ // For non-summarizer client, log the event now since GC won't run on it. This may result in false positives
1178
+ // but it's a good signal nonetheless and we can consume it with a grain of salt.
1179
+ // Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.
1180
+ // SweepReady errors are usages of Objects that will be deleted by GC Sweep!
1181
+ if (this.isSummarizerClient) {
1182
+ this.pendingEventsQueue.push({ ...propsToLog, usageType, state });
1183
+ } else {
1184
+ // For non-summarizer clients, only log "Loaded" type events since these objects may not be loaded in the
1185
+ // summarizer clients if they are based off of user actions (such as scrolling to content for these objects)
1186
+ // Events generated:
1187
+ // InactiveObject_Loaded, SweepReadyObject_Loaded
1188
+ if (usageType === "Loaded") {
1189
+ const event = {
1190
+ ...propsToLog,
1191
+ eventName: `${state}Object_${usageType}`,
1192
+ pkg: packagePathToTelemetryProperty(packagePath),
1193
+ stack: generateStack(),
1194
+ };
1195
+
1196
+ // Do not log the inactive object x events as error events as they are not the best signal for
1197
+ // detecting something wrong with GC either from the partner or from the runtime itself.
1198
+ if (state === UnreferencedState.Inactive) {
1199
+ this.mc.logger.sendTelemetryEvent(event);
1200
+ } else {
1201
+ this.mc.logger.sendErrorEvent(event);
1202
+ }
1203
+ }
1204
+ }
1205
+ }
1206
+
1207
+ private async logUnreferencedEvents(logger: ITelemetryLogger) {
1208
+ // Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at
1209
+ // summary time they are then logged.
1210
+ // Events generated:
1211
+ // InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived
1212
+ // SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived
1213
+ for (const eventProps of this.pendingEventsQueue) {
1214
+ const { usageType, state, ...propsToLog } = eventProps;
1215
+ /**
1216
+ * Revived event is logged only if the node is active. If the node is not active, the reference to it was
1217
+ * from another unreferenced node and this scenario is not interesting to log.
1218
+ * Loaded and Changed events are logged only if the node is not active. If the node is active, it was
1219
+ * revived and a Revived event will be logged for it.
1220
+ */
1221
+ const nodeStateTracker = this.unreferencedNodesState.get(eventProps.id);
1222
+ const active =
1223
+ nodeStateTracker === undefined ||
1224
+ nodeStateTracker.state === UnreferencedState.Active;
1225
+ if ((usageType === "Revived") === active) {
1226
+ const pkg = await this.getNodePackagePath(eventProps.id);
1227
+ const fromPkg = eventProps.fromId
1228
+ ? await this.getNodePackagePath(eventProps.fromId)
1229
+ : undefined;
1230
+ const event = {
1231
+ ...propsToLog,
1232
+ eventName: `${state}Object_${usageType}`,
1233
+ pkg: pkg
1234
+ ? { value: pkg.join("/"), tag: TelemetryDataTag.CodeArtifact }
1235
+ : undefined,
1236
+ fromPkg: fromPkg
1237
+ ? { value: fromPkg.join("/"), tag: TelemetryDataTag.CodeArtifact }
1238
+ : undefined,
1239
+ };
1240
+
1241
+ if (state === UnreferencedState.Inactive) {
1242
+ logger.sendTelemetryEvent(event);
1243
+ } else {
1244
+ logger.sendErrorEvent(event);
1245
+ }
1246
+ }
1247
+ }
1248
+ this.pendingEventsQueue = [];
1249
+ }
1250
+ }