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