@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
@@ -1,1133 +0,0 @@
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, UsageError } from "@fluidframework/container-utils";
18
- import { cloneGCData, concatGarbageCollectionStates, concatGarbageCollectionData, runGarbageCollection, unpackChildNodesGCDetails, } from "@fluidframework/garbage-collector";
19
- import { SummaryType } from "@fluidframework/protocol-definitions";
20
- import { gcBlobKey, } from "@fluidframework/runtime-definitions";
21
- import { mergeStats, packagePathToTelemetryProperty, SummaryTreeBuilder, } from "@fluidframework/runtime-utils";
22
- import { ChildLogger, generateStack, loggerToMonitoringContext, PerformanceEvent, TelemetryDataTag, } from "@fluidframework/telemetry-utils";
23
- import { RuntimeHeaders } from "./containerRuntime";
24
- import { getSummaryForDatastores } from "./dataStores";
25
- import { defaultInactiveTimeoutMs, defaultSessionExpiryDurationMs, disableSweepLogKey, disableTombstoneKey, gcBlobPrefix, gcTestModeKey, gcTombstoneBlobKey, gcTreeKey, oneDayMs, runGCKey, runSessionExpiryKey, runSweepKey, trackGCStateKey } from "./garbageCollectionConstants";
26
- import { SweepReadyUsageDetectionHandler } from "./gcSweepReadyUsageDetection";
27
- import { getGCVersion, metadataBlobName, dataStoreAttributesBlobName, } from "./summaryFormat";
28
- /** This is the current version of garbage collection. */
29
- const GCVersion = 1;
30
- /** The types of GC nodes in the GC reference graph. */
31
- export const GCNodeType = {
32
- // Nodes that are for data stores.
33
- DataStore: "DataStore",
34
- // Nodes that are within a data store. For example, DDS nodes.
35
- SubDataStore: "SubDataStore",
36
- // Nodes that are for attachment blobs, i.e., blobs uploaded via BlobManager.
37
- Blob: "Blob",
38
- // Nodes that are neither of the above. For example, root node.
39
- Other: "Other",
40
- };
41
- /** The state of node that is unreferenced. */
42
- export const UnreferencedState = {
43
- /** The node is active, i.e., it can become referenced again. */
44
- Active: "Active",
45
- /** The node is inactive, i.e., it should not become referenced. */
46
- Inactive: "Inactive",
47
- /** The node is ready to be deleted by the sweep phase. */
48
- SweepReady: "SweepReady",
49
- };
50
- /**
51
- * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced and if it can
52
- * be deleted by the sweep phase.
53
- */
54
- export class UnreferencedStateTracker {
55
- constructor(unreferencedTimestampMs,
56
- /** The time after which node transitions to Inactive state. */
57
- inactiveTimeoutMs,
58
- /** The current reference timestamp used to track how long this node has been unreferenced for. */
59
- currentReferenceTimestampMs,
60
- /** The time after which node transitions to SweepReady state; undefined if session expiry is disabled. */
61
- sweepTimeoutMs) {
62
- this.unreferencedTimestampMs = unreferencedTimestampMs;
63
- this.inactiveTimeoutMs = inactiveTimeoutMs;
64
- this.sweepTimeoutMs = sweepTimeoutMs;
65
- this._state = UnreferencedState.Active;
66
- if (this.sweepTimeoutMs !== undefined) {
67
- assert(this.inactiveTimeoutMs <= this.sweepTimeoutMs, 0x3b0 /* inactive timeout must not be greater than the sweep timeout */);
68
- }
69
- this.sweepTimer = new TimerWithNoDefaultTimeout(() => {
70
- this._state = UnreferencedState.SweepReady;
71
- assert(!this.inactiveTimer.hasTimer, 0x3b1 /* inactiveTimer still running after sweepTimer fired! */);
72
- });
73
- this.inactiveTimer = new TimerWithNoDefaultTimeout(() => {
74
- this._state = UnreferencedState.Inactive;
75
- // After the node becomes inactive, start the sweep timer after which the node will be ready for sweep.
76
- if (this.sweepTimeoutMs !== undefined) {
77
- this.sweepTimer.restart(this.sweepTimeoutMs - this.inactiveTimeoutMs);
78
- }
79
- });
80
- this.updateTracking(currentReferenceTimestampMs);
81
- }
82
- get state() {
83
- return this._state;
84
- }
85
- /* Updates the unreferenced state based on the provided timestamp. */
86
- updateTracking(currentReferenceTimestampMs) {
87
- const unreferencedDurationMs = currentReferenceTimestampMs - this.unreferencedTimestampMs;
88
- // If the node has been unreferenced for sweep timeout amount of time, update the state to SweepReady.
89
- if (this.sweepTimeoutMs !== undefined && unreferencedDurationMs >= this.sweepTimeoutMs) {
90
- this._state = UnreferencedState.SweepReady;
91
- this.clearTimers();
92
- return;
93
- }
94
- // If the node has been unreferenced for inactive timeoutMs amount of time, update the state to inactive.
95
- // Also, start a timer for the sweep timeout.
96
- if (unreferencedDurationMs >= this.inactiveTimeoutMs) {
97
- this._state = UnreferencedState.Inactive;
98
- this.inactiveTimer.clear();
99
- if (this.sweepTimeoutMs !== undefined) {
100
- this.sweepTimer.restart(this.sweepTimeoutMs - unreferencedDurationMs);
101
- }
102
- return;
103
- }
104
- // The node is still active. Ensure the inactive timer is running with the proper remaining duration.
105
- this.inactiveTimer.restart(this.inactiveTimeoutMs - unreferencedDurationMs);
106
- }
107
- clearTimers() {
108
- this.inactiveTimer.clear();
109
- this.sweepTimer.clear();
110
- }
111
- /** Stop tracking this node. Reset the unreferenced timers and state, if any. */
112
- stopTracking() {
113
- this.clearTimers();
114
- this._state = UnreferencedState.Active;
115
- }
116
- }
117
- /**
118
- * The garbage collector for the container runtime. It consolidates the garbage collection functionality and maintains
119
- * its state across summaries.
120
- *
121
- * Node - represented as nodeId, it's a node on the GC graph
122
- *
123
- * Outbound Route - a path from one node to another node, think `nodeA` -\> `nodeB`
124
- *
125
- * Graph - all nodes with their respective routes
126
- *
127
- * ```
128
- * GC Graph
129
- *
130
- * Node
131
- * NodeId = "datastore1"
132
- * / \\
133
- * OutboundRoute OutboundRoute
134
- * / \\
135
- * Node Node
136
- * NodeId = "dds1" NodeId = "dds2"
137
- * ```
138
- */
139
- export class GarbageCollector {
140
- constructor(createParams) {
141
- var _a, _b, _c, _d, _e, _f, _g, _h;
142
- /**
143
- * Tells whether the initial GC state needs to be reset. This can happen under 2 conditions:
144
- *
145
- * 1. The base snapshot contains GC state but GC is disabled. This will happen the first time GC is disabled after
146
- * it was enabled before. GC state needs to be removed from summary and all nodes should be marked referenced.
147
- *
148
- * 2. The base snapshot does not have GC state but GC is enabled. This will happen the very first time GC runs on
149
- * a document and the first time GC is enabled after is was disabled before.
150
- *
151
- * Note that the state needs reset only for the very first time summary is generated by this client. After that, the
152
- * state will be up-to-date and this flag will be reset.
153
- */
154
- this.initialStateNeedsReset = false;
155
- // The current GC version that this container is running.
156
- this.currentGCVersion = GCVersion;
157
- // Keeps a list of references (edges in the GC graph) between GC runs. Each entry has a node id and a list of
158
- // outbound routes from that node.
159
- this.newReferencesSinceLastRun = new Map();
160
- this.tombstones = [];
161
- // Map of node ids to their unreferenced state tracker.
162
- this.unreferencedNodesState = new Map();
163
- // Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one
164
- // per event per node.
165
- this.loggedUnreferencedEvents = new Set();
166
- // Queue for unreferenced events that should be logged the next time GC runs.
167
- this.pendingEventsQueue = [];
168
- // The number of times GC has successfully completed on this instance of GarbageCollector.
169
- this.completedRuns = 0;
170
- this.runtime = createParams.runtime;
171
- this.isSummarizerClient = createParams.isSummarizerClient;
172
- this.gcOptions = createParams.gcOptions;
173
- this.createContainerMetadata = createParams.createContainerMetadata;
174
- this.getNodePackagePath = createParams.getNodePackagePath;
175
- this.getLastSummaryTimestampMs = createParams.getLastSummaryTimestampMs;
176
- this.activeConnection = createParams.activeConnection;
177
- const baseSnapshot = createParams.baseSnapshot;
178
- const metadata = createParams.metadata;
179
- const readAndParseBlob = createParams.readAndParseBlob;
180
- this.mc = loggerToMonitoringContext(ChildLogger.create(createParams.baseLogger, "GarbageCollector", { all: { completedGCRuns: () => this.completedRuns } }));
181
- this.sweepReadyUsageHandler = new SweepReadyUsageDetectionHandler(createParams.getContainerDiagnosticId(), this.mc, this.runtime.closeFn);
182
- let prevSummaryGCVersion;
183
- /**
184
- * Sweep timeout is the time after which unreferenced content can be swept.
185
- * Sweep timeout = session expiry timeout + snapshot cache expiry timeout + one day buffer.
186
- *
187
- * The snapshot cache expiry timeout cannot be known precisely but the upper bound is 5 days.
188
- * The buffer is added to account for any clock skew or other edge cases.
189
- * We use server timestamps throughout so the skew should be minimal but make it 1 day to be safe.
190
- */
191
- function computeSweepTimeout(sessionExpiryTimeoutMs) {
192
- const maxSnapshotCacheExpiryMs = 5 * oneDayMs;
193
- const bufferMs = oneDayMs;
194
- return sessionExpiryTimeoutMs &&
195
- (sessionExpiryTimeoutMs + maxSnapshotCacheExpiryMs + bufferMs);
196
- }
197
- /**
198
- * The following GC state is enabled during container creation and cannot be changed throughout its lifetime:
199
- * 1. Whether running GC mark phase is allowed or not.
200
- * 2. Whether running GC sweep phase is allowed or not.
201
- * 3. Whether GC session expiry is enabled or not.
202
- * For existing containers, we get this information from the metadata blob of its summary.
203
- */
204
- if (createParams.existing) {
205
- prevSummaryGCVersion = getGCVersion(metadata);
206
- // Existing documents which did not have metadata blob or had GC disabled have version as 0. For all
207
- // other existing documents, GC is enabled.
208
- this.gcEnabled = prevSummaryGCVersion > 0;
209
- this.sweepEnabled = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.sweepEnabled) !== null && _a !== void 0 ? _a : false;
210
- this.sessionExpiryTimeoutMs = metadata === null || metadata === void 0 ? void 0 : metadata.sessionExpiryTimeoutMs;
211
- this.sweepTimeoutMs =
212
- (_b = metadata === null || metadata === void 0 ? void 0 : metadata.sweepTimeoutMs) !== null && _b !== void 0 ? _b : computeSweepTimeout(this.sessionExpiryTimeoutMs); // Backfill old documents that didn't persist this
213
- }
214
- else {
215
- // Sweep should not be enabled without enabling GC mark phase. We could silently disable sweep in this
216
- // scenario but explicitly failing makes it clearer and promotes correct usage.
217
- if (this.gcOptions.sweepAllowed && this.gcOptions.gcAllowed === false) {
218
- throw new UsageError("GC sweep phase cannot be enabled without enabling GC mark phase");
219
- }
220
- // This Test Override only applies for new containers
221
- const testOverrideSweepTimeoutMs = this.mc.config.getNumber("Fluid.GarbageCollection.TestOverride.SweepTimeoutMs");
222
- // For new documents, GC is enabled by default. It can be explicitly disabled by setting the gcAllowed
223
- // flag in GC options to false.
224
- this.gcEnabled = this.gcOptions.gcAllowed !== false;
225
- // The sweep phase has to be explicitly enabled by setting the sweepAllowed flag in GC options to true.
226
- // ...unless we're using the TestOverride
227
- this.sweepEnabled = this.gcOptions.sweepAllowed === true || testOverrideSweepTimeoutMs !== undefined;
228
- // Set the Session Expiry only if the flag is enabled and GC is enabled.
229
- if (this.mc.config.getBoolean(runSessionExpiryKey) && this.gcEnabled) {
230
- this.sessionExpiryTimeoutMs = (_c = this.gcOptions.sessionExpiryTimeoutMs) !== null && _c !== void 0 ? _c : defaultSessionExpiryDurationMs;
231
- }
232
- this.sweepTimeoutMs =
233
- testOverrideSweepTimeoutMs !== null && testOverrideSweepTimeoutMs !== void 0 ? testOverrideSweepTimeoutMs : computeSweepTimeout(this.sessionExpiryTimeoutMs);
234
- }
235
- // If session expiry is enabled, we need to close the container when the session expiry timeout expires.
236
- if (this.sessionExpiryTimeoutMs !== undefined) {
237
- // If Test Override config is set, override Session Expiry timeout.
238
- const overrideSessionExpiryTimeoutMs = this.mc.config.getNumber("Fluid.GarbageCollection.TestOverride.SessionExpiryMs");
239
- const timeoutMs = overrideSessionExpiryTimeoutMs !== null && overrideSessionExpiryTimeoutMs !== void 0 ? overrideSessionExpiryTimeoutMs : this.sessionExpiryTimeoutMs;
240
- this.sessionExpiryTimer = new Timer(timeoutMs, () => { this.runtime.closeFn(new ClientSessionExpiredError(`Client session expired.`, timeoutMs)); });
241
- this.sessionExpiryTimer.start();
242
- }
243
- // For existing document, the latest summary is the one that we loaded from. So, use its GC version as the
244
- // latest tracked GC version. For new documents, we will be writing the first summary with the current version.
245
- this.latestSummaryGCVersion = prevSummaryGCVersion !== null && prevSummaryGCVersion !== void 0 ? prevSummaryGCVersion : this.currentGCVersion;
246
- /**
247
- * Whether GC should run or not. The following conditions have to be met to run sweep:
248
- *
249
- * 1. GC should be enabled for this container.
250
- *
251
- * 2. GC should not be disabled via disableGC GC option.
252
- *
253
- * These conditions can be overridden via runGCKey feature flag.
254
- */
255
- this.shouldRunGC = (_d = this.mc.config.getBoolean(runGCKey)) !== null && _d !== void 0 ? _d : (
256
- // GC must be enabled for the document.
257
- this.gcEnabled
258
- // GC must not be disabled via GC options.
259
- && !this.gcOptions.disableGC);
260
- /**
261
- * Whether sweep should run or not. The following conditions have to be met to run sweep:
262
- *
263
- * 1. Overall GC or mark phase must be enabled (this.shouldRunGC).
264
- * 2. Sweep timeout should be available. Without this, we wouldn't know when an object should be deleted.
265
- * 3. The driver must implement the policy limiting the age of snapshots used for loading. Otherwise
266
- * the Sweep Timeout calculation is not valid. We use the persisted value to ensure consistency over time.
267
- * 4. Sweep should be enabled for this container (this.sweepEnabled). This can be overridden via runSweep
268
- * feature flag.
269
- */
270
- this.shouldRunSweep =
271
- this.shouldRunGC
272
- && this.sweepTimeoutMs !== undefined
273
- && ((_e = this.mc.config.getBoolean(runSweepKey)) !== null && _e !== void 0 ? _e : this.sweepEnabled);
274
- this.trackGCState = this.mc.config.getBoolean(trackGCStateKey) === true;
275
- // Override inactive timeout if test config or gc options to override it is set.
276
- this.inactiveTimeoutMs = (_g = (_f = this.mc.config.getNumber("Fluid.GarbageCollection.TestOverride.InactiveTimeoutMs")) !== null && _f !== void 0 ? _f : this.gcOptions.inactiveTimeoutMs) !== null && _g !== void 0 ? _g : defaultInactiveTimeoutMs;
277
- // Inactive timeout must be greater than sweep timeout since a node goes from active -> inactive -> sweep ready.
278
- if (this.sweepTimeoutMs !== undefined && this.inactiveTimeoutMs > this.sweepTimeoutMs) {
279
- throw new UsageError("inactive timeout should not be greater than the sweep timeout");
280
- }
281
- // Whether we are running in test mode. In this mode, unreferenced nodes are immediately deleted.
282
- this.testMode = (_h = this.mc.config.getBoolean(gcTestModeKey)) !== null && _h !== void 0 ? _h : this.gcOptions.runGCInTestMode === true;
283
- // Whether we are running in tombstone mode. This is true by default unless disabled via feature flags.
284
- this.tombstoneMode = this.mc.config.getBoolean(disableTombstoneKey) !== true;
285
- // The GC state needs to be reset if the base snapshot contains GC tree and GC is disabled or it doesn't
286
- // contain GC tree and GC is enabled.
287
- const gcTreePresent = (baseSnapshot === null || baseSnapshot === void 0 ? void 0 : baseSnapshot.trees[gcTreeKey]) !== undefined;
288
- this.initialStateNeedsReset = gcTreePresent !== this.shouldRunGC;
289
- // Get the GC data from the base snapshot. Use LazyPromise because we only want to do this once since it
290
- // it involves fetching blobs from storage which is expensive.
291
- this.baseSnapshotDataP = new LazyPromise(async () => {
292
- var _a;
293
- if (baseSnapshot === undefined) {
294
- return undefined;
295
- }
296
- try {
297
- // For newer documents, GC data should be present in the GC tree in the root of the snapshot.
298
- const gcSnapshotTree = baseSnapshot.trees[gcTreeKey];
299
- if (gcSnapshotTree !== undefined) {
300
- return getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);
301
- }
302
- // back-compat - Older documents will have the GC blobs in each data store's summary tree. Get them and
303
- // consolidate into IGarbageCollectionState format.
304
- // Add a node for the root node that is not present in older snapshot format.
305
- const gcState = { gcNodes: { "/": { outboundRoutes: [] } } };
306
- const dataStoreSnapshotTree = getSummaryForDatastores(baseSnapshot, metadata);
307
- assert(dataStoreSnapshotTree !== undefined, 0x2a8 /* "Expected data store snapshot tree in base snapshot" */);
308
- for (const [dsId, dsSnapshotTree] of Object.entries(dataStoreSnapshotTree.trees)) {
309
- const blobId = dsSnapshotTree.blobs[gcBlobKey];
310
- if (blobId === undefined) {
311
- continue;
312
- }
313
- const gcSummaryDetails = await readAndParseBlob(blobId);
314
- // If there are no nodes for this data store, skip it.
315
- if (((_a = gcSummaryDetails.gcData) === null || _a === void 0 ? void 0 : _a.gcNodes) === undefined) {
316
- continue;
317
- }
318
- const dsRootId = `/${dsId}`;
319
- // Since we used to write GC data at data store level, we won't have an entry for the root ("/").
320
- // Construct that entry by adding root data store ids to its outbound routes.
321
- const initialSnapshotDetails = await readAndParseBlob(dsSnapshotTree.blobs[dataStoreAttributesBlobName]);
322
- if (initialSnapshotDetails.isRootDataStore) {
323
- gcState.gcNodes["/"].outboundRoutes.push(dsRootId);
324
- }
325
- for (const [id, outboundRoutes] of Object.entries(gcSummaryDetails.gcData.gcNodes)) {
326
- // Prefix the data store id to the GC node ids to make them relative to the root from being
327
- // relative to the data store. Similar to how its done in DataStore::getGCData.
328
- const rootId = id === "/" ? dsRootId : `${dsRootId}${id}`;
329
- gcState.gcNodes[rootId] = { outboundRoutes: Array.from(outboundRoutes) };
330
- }
331
- assert(gcState.gcNodes[dsRootId] !== undefined, 0x2a9 /* GC nodes for data store not in GC blob */);
332
- gcState.gcNodes[dsRootId].unreferencedTimestampMs = gcSummaryDetails.unrefTimestamp;
333
- }
334
- // If there is only one node (root node just added above), either GC is disabled or we are loading from
335
- // the first summary generated by detached container. In both cases, GC was not run - return undefined.
336
- return Object.keys(gcState.gcNodes).length === 1 ? undefined : { gcState, tombstones: undefined };
337
- }
338
- catch (error) {
339
- const dpe = DataProcessingError.wrapIfUnrecognized(error, "FailedToInitializeGC");
340
- dpe.addTelemetryProperties({ gcConfigs: JSON.stringify(this.configs) });
341
- throw dpe;
342
- }
343
- });
344
- /**
345
- * Set up the initializer which initializes the GC state from the data in base snapshot. This is done when
346
- * connected in write mode or when GC runs the first time. It sets up all unreferenced nodes from the base
347
- * GC state and updates their inactive or sweep ready state.
348
- */
349
- this.initializeGCStateFromBaseSnapshotP = new LazyPromise(async () => {
350
- const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
351
- /**
352
- * If there is no current reference timestamp, skip initialization. We need the current timestamp to track
353
- * how long objects have been unreferenced and if they can be deleted.
354
- *
355
- * Note that the only scenario where there is no reference timestamp is when no ops have ever been processed
356
- * for this container and it is in read mode. In this scenario, there is no point in running GC anyway
357
- * because references in the container do not change without any ops, i.e., there is nothing to collect.
358
- */
359
- if (currentReferenceTimestampMs === undefined) {
360
- // Log an event so we can evaluate how often we run into this scenario.
361
- this.mc.logger.sendErrorEvent({
362
- eventName: "GarbageCollectorInitializedWithoutTimestamp",
363
- gcConfigs: JSON.stringify(this.configs),
364
- });
365
- return;
366
- }
367
- const baseSnapshotData = await this.baseSnapshotDataP;
368
- /**
369
- * The base snapshot data will not be present if the container is loaded from:
370
- * 1. The first summary created by the detached container.
371
- * 2. A summary that was generated with GC disabled.
372
- * 3. A summary that was generated before GC even existed.
373
- */
374
- if (baseSnapshotData === undefined) {
375
- return;
376
- }
377
- const gcNodes = {};
378
- for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
379
- if (nodeData.unreferencedTimestampMs !== undefined) {
380
- this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(nodeData.unreferencedTimestampMs, this.inactiveTimeoutMs, currentReferenceTimestampMs, this.sweepTimeoutMs));
381
- }
382
- gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
383
- }
384
- this.previousGCDataFromLastRun = { gcNodes };
385
- // If tracking state across summaries, update latest summary data from the base snapshot's GC data.
386
- if (this.trackGCState) {
387
- this.latestSummaryData = {
388
- serializedGCState: JSON.stringify(generateSortedGCState(baseSnapshotData.gcState)),
389
- serializedTombstones: JSON.stringify(baseSnapshotData.tombstones),
390
- };
391
- }
392
- });
393
- // Get the GC details for each node from the GC state in the base summary. This is returned in getBaseGCDetails
394
- // which the caller uses to initialize each node's GC state.
395
- this.baseGCDetailsP = new LazyPromise(async () => {
396
- const baseSnapshotData = await this.baseSnapshotDataP;
397
- if (baseSnapshotData === undefined) {
398
- return new Map();
399
- }
400
- const gcNodes = {};
401
- for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
402
- gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
403
- }
404
- // Run GC on the nodes in the base summary to get the routes used in each node in the container.
405
- // This is an optimization for space (vs performance) wherein we don't need to store the used routes of
406
- // each node in the summary.
407
- const usedRoutes = runGarbageCollection(gcNodes, ["/"]).referencedNodeIds;
408
- const baseGCDetailsMap = unpackChildNodesGCDetails({ gcData: { gcNodes }, usedRoutes });
409
- // Currently, the nodes may write the GC data. So, we need to update its base GC details with the
410
- // unreferenced timestamp. Once we start writing the GC data here, we won't need to do this anymore.
411
- for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
412
- if (nodeData.unreferencedTimestampMs !== undefined) {
413
- const dataStoreGCDetails = baseGCDetailsMap.get(nodeId.slice(1));
414
- if (dataStoreGCDetails !== undefined) {
415
- dataStoreGCDetails.unrefTimestamp = nodeData.unreferencedTimestampMs;
416
- }
417
- }
418
- }
419
- return baseGCDetailsMap;
420
- });
421
- // Log all the GC options and the state determined by the garbage collector. This is interesting only for the
422
- // summarizer client since it is the only one that runs GC. It also helps keep the telemetry less noisy.
423
- if (this.isSummarizerClient) {
424
- this.mc.logger.sendTelemetryEvent({
425
- eventName: "GarbageCollectorLoaded",
426
- gcConfigs: JSON.stringify(this.configs),
427
- });
428
- }
429
- }
430
- static create(createParams) {
431
- return new GarbageCollector(createParams);
432
- }
433
- /**
434
- * Tells whether the GC state needs to be reset in the next summary. We need to do this if:
435
- *
436
- * 1. GC was enabled and is now disabled. The GC state needs to be removed and everything becomes referenced.
437
- *
438
- * 2. GC was disabled and is now enabled. The GC state needs to be regenerated and added to summary.
439
- *
440
- * 3. The GC version in the latest summary is different from the current GC version. This can happen if:
441
- *
442
- * 3.1. The summary this client loaded with has data from a different GC version.
443
- *
444
- * 3.2. This client's latest summary was updated from a snapshot that has a different GC version.
445
- */
446
- get summaryStateNeedsReset() {
447
- return this.initialStateNeedsReset ||
448
- (this.shouldRunGC && this.latestSummaryGCVersion !== this.currentGCVersion);
449
- }
450
- /** Returns a list of all the configurations for garbage collection. */
451
- get configs() {
452
- return Object.assign({ gcEnabled: this.gcEnabled, sweepEnabled: this.sweepEnabled, runGC: this.shouldRunGC, runSweep: this.shouldRunSweep, testMode: this.testMode, tombstoneMode: this.tombstoneMode, sessionExpiry: this.sessionExpiryTimeoutMs, sweepTimeout: this.sweepTimeoutMs, inactiveTimeout: this.inactiveTimeoutMs, trackGCState: this.trackGCState }, this.gcOptions);
453
- }
454
- /**
455
- * Called during container initialization. Initialize the tombstone state so that object are marked as tombstones
456
- * before they are loaded or used. This is important to get accurate information of whether tombstoned object are
457
- * in use or not.
458
- */
459
- async initializeBaseState() {
460
- const baseSnapshotData = await this.baseSnapshotDataP;
461
- /**
462
- * The base snapshot data or tombstone state will not be present if the container is loaded from:
463
- * 1. The first summary created by the detached container.
464
- * 2. A summary that was generated with GC disabled.
465
- * 3. A summary that was generated before GC even existed.
466
- * 4. A summary that was generated with tombstone feature disabled.
467
- */
468
- if (!this.tombstoneMode || (baseSnapshotData === null || baseSnapshotData === void 0 ? void 0 : baseSnapshotData.tombstones) === undefined) {
469
- return;
470
- }
471
- this.tombstones = baseSnapshotData.tombstones;
472
- this.runtime.updateUnusedRoutes(this.tombstones, true /* tombstone */);
473
- }
474
- /**
475
- * Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this
476
- * to initialize the base state for non-summarizer clients so that they can track inactive / sweep ready nodes.
477
- * @param connected - Whether the runtime connected / disconnected.
478
- * @param clientId - The clientId of this runtime.
479
- */
480
- setConnectionState(connected, clientId) {
481
- /**
482
- * For all clients, initialize the base state when the container becomes active, i.e., it transitions
483
- * to "write" mode. This will ensure that the container's own join op is processed and there is a recent
484
- * reference timestamp that will be used to update the state of unreferenced nodes. Also, all trailing ops which
485
- * could affect the GC state will have been processed.
486
- *
487
- * If GC is up-to-date for the client and the summarizing client, there will be an doubling of both
488
- * InactiveObject_Loaded and SweepReady_Loaded errors, as there will be one from the sending client and one from
489
- * the receiving summarizer client.
490
- *
491
- * Ideally, this initialization should only be done for summarizer client. However, we are currently rolling out
492
- * sweep in phases and we want to track when inactive and sweep ready objects are used in any client.
493
- */
494
- if (this.activeConnection() && this.shouldRunGC) {
495
- this.initializeGCStateFromBaseSnapshotP.catch((error) => { });
496
- }
497
- }
498
- /**
499
- * Runs garbage collection and updates the reference / used state of the nodes in the container.
500
- * @returns stats of the GC run or undefined if GC did not run.
501
- */
502
- async collectGarbage(options) {
503
- var _a;
504
- const fullGC = (_a = options.fullGC) !== null && _a !== void 0 ? _a : (this.gcOptions.runFullGC === true || this.summaryStateNeedsReset);
505
- const logger = options.logger
506
- ? ChildLogger.create(options.logger, undefined, { all: { completedGCRuns: () => this.completedRuns } })
507
- : this.mc.logger;
508
- /**
509
- * If there is no current reference timestamp, skip running GC. We need the current timestamp to track
510
- * how long objects have been unreferenced and if they should be deleted.
511
- *
512
- * Note that the only scenario where GC is called and there is no reference timestamp is when no ops have ever
513
- * been processed for this container and it is in read mode. In this scenario, there is no point in running GC
514
- * anyway because references in the container do not change without any ops, i.e., there is nothing to collect.
515
- */
516
- const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
517
- if (currentReferenceTimestampMs === undefined) {
518
- // Log an event so we can evaluate how often we run into this scenario.
519
- logger.sendErrorEvent({
520
- eventName: "CollectGarbageCalledWithoutTimestamp",
521
- gcConfigs: JSON.stringify(this.configs),
522
- });
523
- return undefined;
524
- }
525
- return PerformanceEvent.timedExecAsync(logger, { eventName: "GarbageCollection" }, async (event) => {
526
- await this.runPreGCSteps();
527
- // Get the runtime's GC data and run GC on the reference graph in it.
528
- const gcData = await this.runtime.getGCData(fullGC);
529
- const gcResult = runGarbageCollection(gcData.gcNodes, ["/"]);
530
- const gcStats = await this.runPostGCSteps(gcData, gcResult, logger, currentReferenceTimestampMs);
531
- event.end(Object.assign(Object.assign({}, gcStats), { timestamp: currentReferenceTimestampMs }));
532
- this.completedRuns++;
533
- return gcStats;
534
- }, { end: true, cancel: "error" });
535
- }
536
- async runPreGCSteps() {
537
- // Ensure that state has been initialized from the base snapshot data.
538
- await this.initializeGCStateFromBaseSnapshotP;
539
- // Let the runtime update its pending state before GC runs.
540
- await this.runtime.updateStateBeforeGC();
541
- }
542
- async runPostGCSteps(gcData, gcResult, logger, currentReferenceTimestampMs) {
543
- // Generate statistics from the current run. This is done before updating the current state because it
544
- // generates some of its data based on previous state of the system.
545
- const gcStats = this.generateStats(gcResult);
546
- // Update the state since the last GC run. There can be nodes that were referenced between the last and
547
- // the current run. We need to identify than and update their unreferenced state if needed.
548
- this.updateStateSinceLastRun(gcData, logger);
549
- // Update the current state and update the runtime of all routes or ids that used as per the GC run.
550
- this.updateCurrentState(gcData, gcResult, currentReferenceTimestampMs);
551
- this.runtime.updateUsedRoutes(gcResult.referencedNodeIds);
552
- // Log events for objects that are ready to be deleted by sweep. When we have sweep enabled, we will
553
- // delete these objects here instead.
554
- this.logSweepEvents(logger, currentReferenceTimestampMs);
555
- // If we are running in GC test mode, delete objects for unused routes. This enables testing scenarios
556
- // involving access to deleted data.
557
- if (this.testMode) {
558
- this.runtime.updateUnusedRoutes(gcResult.deletedNodeIds, false /* tombstone */);
559
- }
560
- else if (this.tombstoneMode) {
561
- // If we are running in GC tombstone mode, tombstone objects for unused routes. This enables testing
562
- // scenarios involving access to "deleted" data without actually deleting the data from summaries.
563
- // Note: we will not tombstone in test mode
564
- this.runtime.updateUnusedRoutes(this.tombstones, true /* tombstone */);
565
- }
566
- // Log pending unreferenced events such as a node being used after inactive. This is done after GC runs and
567
- // updates its state so that we don't send false positives based on intermediate state. For example, we may get
568
- // reference to an unreferenced node from another unreferenced node which means the node wasn't revived.
569
- await this.logUnreferencedEvents(logger);
570
- return gcStats;
571
- }
572
- /**
573
- * Summarizes the GC data and returns it as a summary tree.
574
- * We current write the entire GC state in a single blob. This can be modified later to write multiple
575
- * blobs. All the blob keys should start with `gcBlobPrefix`.
576
- */
577
- summarize(fullTree, trackState, telemetryContext) {
578
- var _a;
579
- if (!this.shouldRunGC || this.previousGCDataFromLastRun === undefined) {
580
- return;
581
- }
582
- const gcState = { gcNodes: {} };
583
- for (const [nodeId, outboundRoutes] of Object.entries(this.previousGCDataFromLastRun.gcNodes)) {
584
- gcState.gcNodes[nodeId] = {
585
- outboundRoutes,
586
- unreferencedTimestampMs: (_a = this.unreferencedNodesState.get(nodeId)) === null || _a === void 0 ? void 0 : _a.unreferencedTimestampMs,
587
- };
588
- }
589
- const serializedGCState = JSON.stringify(generateSortedGCState(gcState));
590
- const serializedTombstones = this.tombstoneMode
591
- ? (this.tombstones.length > 0 ? JSON.stringify(this.tombstones.sort()) : undefined)
592
- : undefined;
593
- /**
594
- * Incremental summary of GC data - If any of the GC state or tombstone state hasn't changed since the last
595
- * summary, send summary handles for them. Otherwise, send the data in summary blobs.
596
- */
597
- if (this.trackGCState) {
598
- this.pendingSummaryData = { serializedGCState, serializedTombstones };
599
- if (trackState && !fullTree && this.latestSummaryData !== undefined) {
600
- // If neither GC state or tombstone state changed, send a summary handle for the entire GC data.
601
- if (this.latestSummaryData.serializedGCState === serializedGCState
602
- && this.latestSummaryData.serializedTombstones === serializedTombstones) {
603
- const stats = mergeStats();
604
- stats.handleNodeCount++;
605
- return {
606
- summary: {
607
- type: SummaryType.Handle,
608
- handle: `/${gcTreeKey}`,
609
- handleType: SummaryType.Tree,
610
- },
611
- stats,
612
- };
613
- }
614
- // If either or both of GC state or tombstone state changed, build a GC summary tree.
615
- return this.buildGCSummaryTree(serializedGCState, serializedTombstones, true /* trackState */);
616
- }
617
- }
618
- // If not tracking GC state, build a GC summary tree without any summary handles.
619
- return this.buildGCSummaryTree(serializedGCState, serializedTombstones, false /* trackState */);
620
- }
621
- /**
622
- * Builds the GC summary tree which contains GC state and tombstone state.
623
- * If trackState is false, both GC state and tombstone state are written as summary blobs.
624
- * If trackState is true, summary blob is written for GC state or tombstone state if they changed.
625
- * @param serializedGCState - The GC state serialized as string.
626
- * @param serializedTombstones - THe tombstone state serialized as string.
627
- * @param trackState - Whether we are tracking GC state across summaries.
628
- * @returns the GC summary tree.
629
- */
630
- buildGCSummaryTree(serializedGCState, serializedTombstones, trackState) {
631
- var _a, _b;
632
- const gcStateBlobKey = `${gcBlobPrefix}_root`;
633
- const builder = new SummaryTreeBuilder();
634
- // If the GC state hasn't changed, write a summary handle, else write a summary blob for it.
635
- if (((_a = this.latestSummaryData) === null || _a === void 0 ? void 0 : _a.serializedGCState) === serializedGCState && trackState) {
636
- builder.addHandle(gcStateBlobKey, SummaryType.Blob, `/${gcTreeKey}/${gcStateBlobKey}`);
637
- }
638
- else {
639
- builder.addBlob(gcStateBlobKey, serializedGCState);
640
- }
641
- // If there is no tombstone data, return only the GC state.
642
- if (serializedTombstones === undefined) {
643
- return builder.getSummaryTree();
644
- }
645
- // If the tombstone state hasn't changed, write a summary handle, else write a summary blob for it.
646
- if (((_b = this.latestSummaryData) === null || _b === void 0 ? void 0 : _b.serializedTombstones) === serializedTombstones && trackState) {
647
- builder.addHandle(gcTombstoneBlobKey, SummaryType.Blob, `/${gcTreeKey}/${gcTombstoneBlobKey}`);
648
- }
649
- else {
650
- builder.addBlob(gcTombstoneBlobKey, serializedTombstones);
651
- }
652
- return builder.getSummaryTree();
653
- }
654
- getMetadata() {
655
- return {
656
- /**
657
- * If GC is enabled, the GC data is written using the current GC version and that is the gcFeature that goes
658
- * into the metadata blob. If GC is disabled, the gcFeature is 0.
659
- */
660
- gcFeature: this.gcEnabled ? this.currentGCVersion : 0,
661
- sessionExpiryTimeoutMs: this.sessionExpiryTimeoutMs,
662
- sweepEnabled: this.sweepEnabled,
663
- sweepTimeoutMs: this.sweepTimeoutMs,
664
- };
665
- }
666
- /**
667
- * Returns a map of node ids to their base GC details generated from the base summary. This is used by the caller
668
- * to initialize the GC state of the nodes.
669
- */
670
- async getBaseGCDetails() {
671
- return this.baseGCDetailsP;
672
- }
673
- /**
674
- * Called when the latest summary of the system has been refreshed. This will be used to update the state of the
675
- * latest summary tracked.
676
- */
677
- async latestSummaryStateRefreshed(result, readAndParseBlob) {
678
- if (!this.shouldRunGC || !result.latestSummaryUpdated) {
679
- return;
680
- }
681
- // If the summary was tracked by this client, it was the one that generated the summary in the first place.
682
- // Basically, it was written in the current GC version.
683
- if (result.wasSummaryTracked) {
684
- this.latestSummaryGCVersion = this.currentGCVersion;
685
- this.initialStateNeedsReset = false;
686
- if (this.trackGCState) {
687
- this.latestSummaryData = this.pendingSummaryData;
688
- this.pendingSummaryData = undefined;
689
- }
690
- return;
691
- }
692
- // If the summary was not tracked by this client, update latest GC version and blob from the snapshot in the
693
- // result as that is now the latest summary.
694
- const snapshot = result.snapshot;
695
- const metadataBlobId = snapshot.blobs[metadataBlobName];
696
- if (metadataBlobId) {
697
- const metadata = await readAndParseBlob(metadataBlobId);
698
- this.latestSummaryGCVersion = getGCVersion(metadata);
699
- }
700
- const gcSnapshotTree = snapshot.trees[gcTreeKey];
701
- if (gcSnapshotTree !== undefined && this.trackGCState) {
702
- const latestGCData = await getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);
703
- this.latestSummaryData = {
704
- serializedGCState: JSON.stringify(generateSortedGCState(latestGCData.gcState)),
705
- serializedTombstones: JSON.stringify(latestGCData.tombstones),
706
- };
707
- }
708
- else {
709
- this.latestSummaryData = undefined;
710
- }
711
- this.pendingSummaryData = undefined;
712
- }
713
- /**
714
- * Called when a node with the given id is updated. If the node is inactive, log an error.
715
- * @param nodePath - The id of the node that changed.
716
- * @param reason - Whether the node was loaded or changed.
717
- * @param timestampMs - The timestamp when the node changed.
718
- * @param packagePath - The package path of the node. This may not be available if the node hasn't been loaded yet.
719
- * @param requestHeaders - If the node was loaded via request path, the headers in the request.
720
- */
721
- nodeUpdated(nodePath, reason, timestampMs, packagePath, requestHeaders) {
722
- if (!this.shouldRunGC) {
723
- return;
724
- }
725
- const nodeStateTracker = this.unreferencedNodesState.get(nodePath);
726
- if (nodeStateTracker && nodeStateTracker.state !== UnreferencedState.Active) {
727
- this.inactiveNodeUsed(reason, nodePath, nodeStateTracker, undefined /* fromNodeId */, packagePath, timestampMs, requestHeaders);
728
- }
729
- }
730
- /**
731
- * Called when an outbound reference is added to a node. This is used to identify all nodes that have been
732
- * referenced between summaries so that their unreferenced timestamp can be reset.
733
- *
734
- * @param fromNodePath - The node from which the reference is added.
735
- * @param toNodePath - The node to which the reference is added.
736
- */
737
- addedOutboundReference(fromNodePath, toNodePath) {
738
- var _a;
739
- if (!this.shouldRunGC) {
740
- return;
741
- }
742
- const outboundRoutes = (_a = this.newReferencesSinceLastRun.get(fromNodePath)) !== null && _a !== void 0 ? _a : [];
743
- outboundRoutes.push(toNodePath);
744
- this.newReferencesSinceLastRun.set(fromNodePath, outboundRoutes);
745
- const nodeStateTracker = this.unreferencedNodesState.get(toNodePath);
746
- if (nodeStateTracker && nodeStateTracker.state !== UnreferencedState.Active) {
747
- this.inactiveNodeUsed("Revived", toNodePath, nodeStateTracker, fromNodePath);
748
- }
749
- }
750
- dispose() {
751
- var _a;
752
- (_a = this.sessionExpiryTimer) === null || _a === void 0 ? void 0 : _a.clear();
753
- this.sessionExpiryTimer = undefined;
754
- }
755
- /**
756
- * Updates the state of the system as per the current GC run. It does the following:
757
- * 1. Sets up the current GC state as per the gcData.
758
- * 2. Starts tracking for nodes that have become unreferenced in this run.
759
- * 3. Clears tracking for nodes that were unreferenced but became referenced in this run.
760
- * @param gcData - The data representing the reference graph on which GC is run.
761
- * @param gcResult - The result of the GC run on the gcData.
762
- * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp.
763
- */
764
- updateCurrentState(gcData, gcResult, currentReferenceTimestampMs) {
765
- this.previousGCDataFromLastRun = cloneGCData(gcData);
766
- this.tombstones = [];
767
- this.newReferencesSinceLastRun.clear();
768
- // Iterate through the referenced nodes and stop tracking if they were unreferenced before.
769
- for (const nodeId of gcResult.referencedNodeIds) {
770
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
771
- if (nodeStateTracker !== undefined) {
772
- // Stop tracking so as to clear out any running timers.
773
- nodeStateTracker.stopTracking();
774
- // Delete the node as we don't need to track it any more.
775
- this.unreferencedNodesState.delete(nodeId);
776
- }
777
- }
778
- /**
779
- * If a node became unreferenced in this run, start tracking it.
780
- * If a node was already unreferenced, update its tracking information. Since the current reference time is
781
- * from the ops seen, this will ensure that we keep updating the unreferenced state as time moves forward.
782
- */
783
- for (const nodeId of gcResult.deletedNodeIds) {
784
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
785
- if (nodeStateTracker === undefined) {
786
- this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(currentReferenceTimestampMs, this.inactiveTimeoutMs, currentReferenceTimestampMs, this.sweepTimeoutMs));
787
- }
788
- else {
789
- nodeStateTracker.updateTracking(currentReferenceTimestampMs);
790
- if (this.tombstoneMode && nodeStateTracker.state === UnreferencedState.SweepReady) {
791
- const nodeType = this.runtime.getNodeType(nodeId);
792
- if (nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) {
793
- this.tombstones.push(nodeId);
794
- }
795
- }
796
- }
797
- }
798
- }
799
- /**
800
- * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in
801
- * time. There can be nodes that were referenced in between two runs and their unreferenced state needs to be
802
- * updated. For example, in the following scenarios not updating the unreferenced timestamp can lead to deletion of
803
- * these objects while there can be in-memory referenced to it:
804
- * 1. A node transitions from `unreferenced -> referenced -> unreferenced` between two runs. When the reference is
805
- * added, the object may have been accessed and in-memory reference to it added.
806
- * 2. A reference is added from one unreferenced node to one or more unreferenced nodes. Even though the node[s] were
807
- * unreferenced, they could have been accessed and in-memory reference to them added.
808
- *
809
- * This function identifies nodes that were referenced since last run and removes their unreferenced state, if any.
810
- * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.
811
- */
812
- updateStateSinceLastRun(currentGCData, logger) {
813
- // If we haven't run GC before there is nothing to do.
814
- if (this.previousGCDataFromLastRun === undefined) {
815
- return;
816
- }
817
- // Find any references that haven't been identified correctly.
818
- const missingExplicitReferences = this.findMissingExplicitReferences(currentGCData, this.previousGCDataFromLastRun, this.newReferencesSinceLastRun);
819
- if (missingExplicitReferences.length > 0) {
820
- missingExplicitReferences.forEach((missingExplicitReference) => {
821
- const event = {
822
- eventName: "gcUnknownOutboundReferences",
823
- gcNodeId: missingExplicitReference[0],
824
- gcRoutes: JSON.stringify(missingExplicitReference[1]),
825
- };
826
- logger.sendPerformanceEvent(event);
827
- });
828
- }
829
- // No references were added since the last run so we don't have to update reference states of any unreferenced
830
- // nodes
831
- if (this.newReferencesSinceLastRun.size === 0) {
832
- return;
833
- }
834
- /**
835
- * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and
836
- * edges that have been added since then. To do this, combine the GC data from the last run and the current
837
- * run, and then add the references since last run.
838
- *
839
- * Note on why we need to combine the data from previous run, current run and all references in between -
840
- * 1. We need data from last run because some of its references may have been deleted since then. If those
841
- * references added new outbound references before they were deleted, we need to detect them.
842
- *
843
- * 2. We need new outbound references since last run because some of them may have been deleted later. If those
844
- * references added new outbound references before they were deleted, we need to detect them.
845
- *
846
- * 3. We need data from the current run because currently we may not detect when DDSes are referenced:
847
- * - We don't require DDSes handles to be stored in a referenced DDS.
848
- * - A new data store may have "root" DDSes already created and we don't detect them today.
849
- */
850
- const gcDataSuperSet = concatGarbageCollectionData(this.previousGCDataFromLastRun, currentGCData);
851
- const newOutboundRoutesSinceLastRun = [];
852
- this.newReferencesSinceLastRun.forEach((outboundRoutes, sourceNodeId) => {
853
- if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {
854
- gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;
855
- }
856
- else {
857
- gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);
858
- }
859
- newOutboundRoutesSinceLastRun.push(...outboundRoutes);
860
- });
861
- /**
862
- * Run GC on the above reference graph starting with root and all new outbound routes. This will generate a
863
- * list of all nodes that could have been referenced since the last run. If any of these nodes are unreferenced,
864
- * unreferenced, stop tracking them and remove from unreferenced list.
865
- * Note that some of these nodes may be unreferenced now and if so, the current run will mark them as
866
- * unreferenced and add unreferenced state.
867
- */
868
- const gcResult = runGarbageCollection(gcDataSuperSet.gcNodes, ["/", ...newOutboundRoutesSinceLastRun]);
869
- for (const nodeId of gcResult.referencedNodeIds) {
870
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
871
- if (nodeStateTracker !== undefined) {
872
- // Stop tracking so as to clear out any running timers.
873
- nodeStateTracker.stopTracking();
874
- // Delete the unreferenced state as we don't need to track it any more.
875
- this.unreferencedNodesState.delete(nodeId);
876
- }
877
- }
878
- }
879
- /**
880
- * Finds all new references or outbound routes in the current graph that haven't been explicitly notified to GC.
881
- * The principle is that every new reference or outbound route must be notified to GC via the
882
- * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.
883
- *
884
- * In more simple terms:
885
- * Missing Explicit References = Current References - Previous References - Explicitly Added References;
886
- *
887
- * @param currentGCData - The GC data (reference graph) from the current GC run.
888
- * @param previousGCData - The GC data (reference graph) from the previous GC run.
889
- * @param explicitReferences - New references added explicity between the previous and the current run.
890
- * @returns - a list of missing explicit references
891
- */
892
- findMissingExplicitReferences(currentGCData, previousGCData, explicitReferences) {
893
- assert(previousGCData !== undefined, 0x2b7);
894
- const currentGraph = Object.entries(currentGCData.gcNodes);
895
- const missingExplicitReferences = [];
896
- currentGraph.forEach(([nodeId, currentOutboundRoutes]) => {
897
- var _a, _b;
898
- const previousRoutes = (_a = previousGCData.gcNodes[nodeId]) !== null && _a !== void 0 ? _a : [];
899
- const explicitRoutes = (_b = explicitReferences.get(nodeId)) !== null && _b !== void 0 ? _b : [];
900
- const missingExplicitRoutes = [];
901
- currentOutboundRoutes.forEach((route) => {
902
- const isBlobOrDataStoreRoute = this.runtime.getNodeType(route) === GCNodeType.Blob ||
903
- this.runtime.getNodeType(route) === GCNodeType.DataStore;
904
- // Ignore implicitly added DDS routes to their parent datastores
905
- const notRouteFromDDSToParentDataStore = !nodeId.startsWith(route);
906
- if (isBlobOrDataStoreRoute &&
907
- notRouteFromDDSToParentDataStore &&
908
- (!previousRoutes.includes(route) && !explicitRoutes.includes(route))) {
909
- missingExplicitRoutes.push(route);
910
- }
911
- });
912
- if (missingExplicitRoutes.length > 0) {
913
- missingExplicitReferences.push([nodeId, missingExplicitRoutes]);
914
- }
915
- });
916
- // Ideally missingExplicitReferences should always have a size 0
917
- return missingExplicitReferences;
918
- }
919
- /**
920
- * Generates the stats of a garbage collection run from the given results of the run.
921
- * @param gcResult - The result of a GC run.
922
- * @returns the GC stats of the GC run.
923
- */
924
- generateStats(gcResult) {
925
- const gcStats = {
926
- nodeCount: 0,
927
- dataStoreCount: 0,
928
- attachmentBlobCount: 0,
929
- unrefNodeCount: 0,
930
- unrefDataStoreCount: 0,
931
- unrefAttachmentBlobCount: 0,
932
- updatedNodeCount: 0,
933
- updatedDataStoreCount: 0,
934
- updatedAttachmentBlobCount: 0,
935
- };
936
- const updateNodeStats = (nodeId, referenced) => {
937
- gcStats.nodeCount++;
938
- // If there is no previous GC data, every node's state is generated and is considered as updated.
939
- // Otherwise, find out if any node went from referenced to unreferenced or vice-versa.
940
- const stateUpdated = this.previousGCDataFromLastRun === undefined ||
941
- this.unreferencedNodesState.has(nodeId) === referenced;
942
- if (stateUpdated) {
943
- gcStats.updatedNodeCount++;
944
- }
945
- if (!referenced) {
946
- gcStats.unrefNodeCount++;
947
- }
948
- if (this.runtime.getNodeType(nodeId) === GCNodeType.DataStore) {
949
- gcStats.dataStoreCount++;
950
- if (stateUpdated) {
951
- gcStats.updatedDataStoreCount++;
952
- }
953
- if (!referenced) {
954
- gcStats.unrefDataStoreCount++;
955
- }
956
- }
957
- if (this.runtime.getNodeType(nodeId) === GCNodeType.Blob) {
958
- gcStats.attachmentBlobCount++;
959
- if (stateUpdated) {
960
- gcStats.updatedAttachmentBlobCount++;
961
- }
962
- if (!referenced) {
963
- gcStats.unrefAttachmentBlobCount++;
964
- }
965
- }
966
- };
967
- for (const nodeId of gcResult.referencedNodeIds) {
968
- updateNodeStats(nodeId, true /* referenced */);
969
- }
970
- for (const nodeId of gcResult.deletedNodeIds) {
971
- updateNodeStats(nodeId, false /* referenced */);
972
- }
973
- return gcStats;
974
- }
975
- /**
976
- * For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,
977
- * this will give us a view into how much deleted content a container has.
978
- */
979
- logSweepEvents(logger, currentReferenceTimestampMs) {
980
- if (this.mc.config.getBoolean(disableSweepLogKey) === true || this.sweepTimeoutMs === undefined) {
981
- return;
982
- }
983
- this.unreferencedNodesState.forEach((nodeStateTracker, nodeId) => {
984
- if (nodeStateTracker.state !== UnreferencedState.SweepReady) {
985
- return;
986
- }
987
- const nodeType = this.runtime.getNodeType(nodeId);
988
- if (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {
989
- return;
990
- }
991
- // Log deleted event for each node only once to reduce noise in telemetry.
992
- const uniqueEventId = `Deleted-${nodeId}`;
993
- if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
994
- return;
995
- }
996
- this.loggedUnreferencedEvents.add(uniqueEventId);
997
- logger.sendTelemetryEvent({
998
- eventName: "GCObjectDeleted",
999
- id: nodeId,
1000
- type: nodeType,
1001
- age: currentReferenceTimestampMs - nodeStateTracker.unreferencedTimestampMs,
1002
- timeout: this.sweepTimeoutMs,
1003
- completedGCRuns: this.completedRuns,
1004
- lastSummaryTime: this.getLastSummaryTimestampMs(),
1005
- });
1006
- });
1007
- }
1008
- /**
1009
- * Called when an inactive node is used after. Queue up an event that will be logged next time GC runs.
1010
- */
1011
- inactiveNodeUsed(usageType, nodeId, nodeStateTracker, fromNodeId, packagePath, currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs(), requestHeaders) {
1012
- // If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip
1013
- // logging as nothing interesting would have happened worth logging.
1014
- // If the node is active, skip logging.
1015
- if (currentReferenceTimestampMs === undefined || nodeStateTracker.state === UnreferencedState.Active) {
1016
- return;
1017
- }
1018
- // We only care about data stores and attachment blobs for this telemetry since GC only marks these objects
1019
- // as unreferenced. Also, if an inactive DDS is used, the corresponding data store store will also be used.
1020
- const nodeType = this.runtime.getNodeType(nodeId);
1021
- if (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {
1022
- return;
1023
- }
1024
- const state = nodeStateTracker.state;
1025
- const uniqueEventId = `${state}-${nodeId}-${usageType}`;
1026
- if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
1027
- return;
1028
- }
1029
- this.loggedUnreferencedEvents.add(uniqueEventId);
1030
- const propsToLog = Object.assign(Object.assign({ id: nodeId, type: nodeType, unrefTime: nodeStateTracker.unreferencedTimestampMs, age: currentReferenceTimestampMs - nodeStateTracker.unreferencedTimestampMs, timeout: nodeStateTracker.state === UnreferencedState.Inactive
1031
- ? this.inactiveTimeoutMs
1032
- : this.sweepTimeoutMs, completedGCRuns: this.completedRuns, lastSummaryTime: this.getLastSummaryTimestampMs() }, this.createContainerMetadata), { externalRequest: requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders[RuntimeHeaders.externalRequest], viaHandle: requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders[RuntimeHeaders.viaHandle], fromId: fromNodeId });
1033
- // For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.
1034
- // For non-summarizer client, log the event now since GC won't run on it. This may result in false positives
1035
- // but it's a good signal nonetheless and we can consume it with a grain of salt.
1036
- // Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.
1037
- // SweepReady errors are usages of Objects that will be deleted by GC Sweep!
1038
- if (this.isSummarizerClient) {
1039
- this.pendingEventsQueue.push(Object.assign(Object.assign({}, propsToLog), { usageType, state }));
1040
- }
1041
- else {
1042
- // For non-summarizer clients, only log "Loaded" type events since these objects may not be loaded in the
1043
- // summarizer clients if they are based off of user actions (such as scrolling to content for these objects)
1044
- // Events generated:
1045
- // InactiveObject_Loaded, SweepReadyObject_Loaded
1046
- if (usageType === "Loaded") {
1047
- this.mc.logger.sendErrorEvent(Object.assign(Object.assign({}, propsToLog), { eventName: `${state}Object_${usageType}`, pkg: packagePathToTelemetryProperty(packagePath), stack: generateStack() }));
1048
- }
1049
- // If SweepReady Usage Detection is enabed, the handler may close the interactive container.
1050
- // Once Sweep is fully implemented, this will be removed since the objects will be gone
1051
- // and errors will arise elsewhere in the runtime
1052
- if (state === UnreferencedState.SweepReady) {
1053
- this.sweepReadyUsageHandler.usageDetectedInInteractiveClient(Object.assign(Object.assign({}, propsToLog), { usageType }));
1054
- }
1055
- }
1056
- }
1057
- async logUnreferencedEvents(logger) {
1058
- // Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at
1059
- // summary time they are then logged.
1060
- // Events generated:
1061
- // InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived
1062
- // SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived
1063
- for (const eventProps of this.pendingEventsQueue) {
1064
- const { usageType, state } = eventProps, propsToLog = __rest(eventProps, ["usageType", "state"]);
1065
- /**
1066
- * Revived event is logged only if the node is active. If the node is not active, the reference to it was
1067
- * from another unreferenced node and this scenario is not interesting to log.
1068
- * Loaded and Changed events are logged only if the node is not active. If the node is active, it was
1069
- * revived and a Revived event will be logged for it.
1070
- */
1071
- const nodeStateTracker = this.unreferencedNodesState.get(eventProps.id);
1072
- const active = nodeStateTracker === undefined || nodeStateTracker.state === UnreferencedState.Active;
1073
- if ((usageType === "Revived") === active) {
1074
- const pkg = await this.getNodePackagePath(eventProps.id);
1075
- const fromPkg = eventProps.fromId ? await this.getNodePackagePath(eventProps.fromId) : undefined;
1076
- logger.sendErrorEvent(Object.assign(Object.assign({}, propsToLog), { eventName: `${state}Object_${usageType}`, pkg: pkg ? { value: pkg.join("/"), tag: TelemetryDataTag.CodeArtifact } : undefined, fromPkg: fromPkg ? { value: fromPkg.join("/"), tag: TelemetryDataTag.CodeArtifact } : undefined }));
1077
- }
1078
- }
1079
- this.pendingEventsQueue = [];
1080
- }
1081
- }
1082
- /**
1083
- * Gets the base garbage collection state from the given snapshot tree. It contains GC state and tombstone state.
1084
- * The GC state may be written into multiple blobs. Merge the GC state from all such blobs into one.
1085
- */
1086
- async function getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob) {
1087
- let rootGCState = { gcNodes: {} };
1088
- let tombstones;
1089
- for (const key of Object.keys(gcSnapshotTree.blobs)) {
1090
- if (key === gcTombstoneBlobKey) {
1091
- tombstones = await readAndParseBlob(gcSnapshotTree.blobs[key]);
1092
- continue;
1093
- }
1094
- // Skip blobs that do not start with the GC prefix.
1095
- if (!key.startsWith(gcBlobPrefix)) {
1096
- continue;
1097
- }
1098
- const blobId = gcSnapshotTree.blobs[key];
1099
- if (blobId === undefined) {
1100
- continue;
1101
- }
1102
- const gcState = await readAndParseBlob(blobId);
1103
- assert(gcState !== undefined, 0x2ad /* "GC blob missing from snapshot" */);
1104
- // Merge the GC state of this blob into the root GC state.
1105
- rootGCState = concatGarbageCollectionStates(rootGCState, gcState);
1106
- }
1107
- return { gcState: rootGCState, tombstones };
1108
- }
1109
- function generateSortedGCState(gcState) {
1110
- const sortableArray = Object.entries(gcState.gcNodes);
1111
- sortableArray.sort(([a], [b]) => a.localeCompare(b));
1112
- const sortedGCState = { gcNodes: {} };
1113
- for (const [nodeId, nodeData] of sortableArray) {
1114
- nodeData.outboundRoutes.sort();
1115
- sortedGCState.gcNodes[nodeId] = nodeData;
1116
- }
1117
- return sortedGCState;
1118
- }
1119
- /** A wrapper around common-utils Timer that requires the timeout when calling start/restart */
1120
- class TimerWithNoDefaultTimeout extends Timer {
1121
- constructor(callback) {
1122
- // The default timeout/handlers will never be used since start/restart pass overrides below
1123
- super(0, () => { throw new Error("DefaultHandler should not be used"); });
1124
- this.callback = callback;
1125
- }
1126
- start(timeoutMs) {
1127
- super.start(timeoutMs, this.callback);
1128
- }
1129
- restart(timeoutMs) {
1130
- super.restart(timeoutMs, this.callback);
1131
- }
1132
- }
1133
- //# sourceMappingURL=garbageCollection.js.map