@fluidframework/container-runtime 2.0.0-internal.3.0.2 → 2.0.0-internal.3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (474) hide show
  1. package/.eslintrc.js +19 -19
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts.map +1 -1
  5. package/dist/batchTracker.js +2 -1
  6. package/dist/batchTracker.js.map +1 -1
  7. package/dist/blobManager.d.ts +15 -2
  8. package/dist/blobManager.d.ts.map +1 -1
  9. package/dist/blobManager.js +109 -37
  10. package/dist/blobManager.js.map +1 -1
  11. package/dist/connectionTelemetry.d.ts.map +1 -1
  12. package/dist/connectionTelemetry.js +11 -9
  13. package/dist/connectionTelemetry.js.map +1 -1
  14. package/dist/containerHandleContext.d.ts.map +1 -1
  15. package/dist/containerHandleContext.js +3 -1
  16. package/dist/containerHandleContext.js.map +1 -1
  17. package/dist/containerRuntime.d.ts +23 -11
  18. package/dist/containerRuntime.d.ts.map +1 -1
  19. package/dist/containerRuntime.js +225 -132
  20. package/dist/containerRuntime.js.map +1 -1
  21. package/dist/dataStore.d.ts.map +1 -1
  22. package/dist/dataStore.js +11 -9
  23. package/dist/dataStore.js.map +1 -1
  24. package/dist/dataStoreContext.d.ts +27 -13
  25. package/dist/dataStoreContext.d.ts.map +1 -1
  26. package/dist/dataStoreContext.js +95 -56
  27. package/dist/dataStoreContext.js.map +1 -1
  28. package/dist/dataStoreContexts.d.ts.map +1 -1
  29. package/dist/dataStoreContexts.js +7 -3
  30. package/dist/dataStoreContexts.js.map +1 -1
  31. package/dist/dataStoreRegistry.d.ts.map +1 -1
  32. package/dist/dataStoreRegistry.js +3 -1
  33. package/dist/dataStoreRegistry.js.map +1 -1
  34. package/dist/dataStores.d.ts +28 -4
  35. package/dist/dataStores.d.ts.map +1 -1
  36. package/dist/dataStores.js +122 -44
  37. package/dist/dataStores.js.map +1 -1
  38. package/dist/deltaScheduler.d.ts.map +1 -1
  39. package/dist/deltaScheduler.js +8 -3
  40. package/dist/deltaScheduler.js.map +1 -1
  41. package/dist/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +27 -203
  42. package/dist/gc/garbageCollection.d.ts.map +1 -0
  43. package/dist/{garbageCollection.js → gc/garbageCollection.js} +210 -400
  44. package/dist/gc/garbageCollection.js.map +1 -0
  45. package/dist/gc/gcDefinitions.d.ts +189 -0
  46. package/dist/gc/gcDefinitions.d.ts.map +1 -0
  47. package/dist/{garbageCollectionConstants.js → gc/gcDefinitions.js} +27 -2
  48. package/dist/gc/gcDefinitions.js.map +1 -0
  49. package/dist/gc/gcHelpers.d.ts +30 -0
  50. package/dist/gc/gcHelpers.d.ts.map +1 -0
  51. package/dist/gc/gcHelpers.js +65 -0
  52. package/dist/gc/gcHelpers.js.map +1 -0
  53. package/dist/gc/gcSummaryStateTracker.d.ts +86 -0
  54. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -0
  55. package/dist/gc/gcSummaryStateTracker.js +246 -0
  56. package/dist/gc/gcSummaryStateTracker.js.map +1 -0
  57. package/{lib → dist/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  58. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  59. package/dist/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  60. package/dist/gc/gcSweepReadyUsageDetection.js.map +1 -0
  61. package/dist/gc/gcUnreferencedStateTracker.d.ts +34 -0
  62. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  63. package/dist/gc/gcUnreferencedStateTracker.js +94 -0
  64. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -0
  65. package/dist/gc/index.d.ts +11 -0
  66. package/dist/gc/index.d.ts.map +1 -0
  67. package/dist/gc/index.js +40 -0
  68. package/dist/gc/index.js.map +1 -0
  69. package/dist/index.d.ts +2 -5
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +6 -9
  72. package/dist/index.js.map +1 -1
  73. package/dist/opLifecycle/batchManager.d.ts +2 -13
  74. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  75. package/dist/opLifecycle/batchManager.js +19 -41
  76. package/dist/opLifecycle/batchManager.js.map +1 -1
  77. package/dist/opLifecycle/definitions.d.ts +4 -0
  78. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  79. package/dist/opLifecycle/definitions.js.map +1 -1
  80. package/dist/opLifecycle/index.d.ts.map +1 -1
  81. package/dist/opLifecycle/index.js.map +1 -1
  82. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  83. package/dist/opLifecycle/opCompressor.js +1 -0
  84. package/dist/opLifecycle/opCompressor.js.map +1 -1
  85. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  86. package/dist/opLifecycle/opDecompressor.js +5 -2
  87. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  88. package/dist/opLifecycle/opSplitter.d.ts +1 -1
  89. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  90. package/dist/opLifecycle/opSplitter.js +24 -13
  91. package/dist/opLifecycle/opSplitter.js.map +1 -1
  92. package/dist/opLifecycle/outbox.d.ts +19 -3
  93. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  94. package/dist/opLifecycle/outbox.js +78 -45
  95. package/dist/opLifecycle/outbox.js.map +1 -1
  96. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  97. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  98. package/dist/opProperties.d.ts.map +1 -1
  99. package/dist/opProperties.js +1 -3
  100. package/dist/opProperties.js.map +1 -1
  101. package/dist/packageVersion.d.ts +1 -1
  102. package/dist/packageVersion.js +1 -1
  103. package/dist/packageVersion.js.map +1 -1
  104. package/dist/pendingStateManager.d.ts +8 -2
  105. package/dist/pendingStateManager.d.ts.map +1 -1
  106. package/dist/pendingStateManager.js +21 -13
  107. package/dist/pendingStateManager.js.map +1 -1
  108. package/dist/scheduleManager.d.ts.map +1 -1
  109. package/dist/scheduleManager.js +3 -2
  110. package/dist/scheduleManager.js.map +1 -1
  111. package/dist/serializedSnapshotStorage.d.ts +2 -2
  112. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  113. package/dist/serializedSnapshotStorage.js +5 -3
  114. package/dist/serializedSnapshotStorage.js.map +1 -1
  115. package/dist/summary/index.d.ts +17 -0
  116. package/dist/summary/index.d.ts.map +1 -0
  117. package/dist/summary/index.js +47 -0
  118. package/dist/summary/index.js.map +1 -0
  119. package/dist/summary/orderedClientElection.d.ts.map +1 -0
  120. package/dist/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  121. package/dist/summary/orderedClientElection.js.map +1 -0
  122. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  123. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -0
  124. package/{lib → dist/summary}/runningSummarizer.d.ts +19 -18
  125. package/dist/summary/runningSummarizer.d.ts.map +1 -0
  126. package/dist/{runningSummarizer.js → summary/runningSummarizer.js} +191 -76
  127. package/dist/summary/runningSummarizer.js.map +1 -0
  128. package/dist/{summarizer.d.ts → summary/summarizer.d.ts} +4 -6
  129. package/dist/summary/summarizer.d.ts.map +1 -0
  130. package/dist/{summarizer.js → summary/summarizer.js} +31 -71
  131. package/dist/summary/summarizer.js.map +1 -0
  132. package/dist/summary/summarizerClientElection.d.ts.map +1 -0
  133. package/dist/summary/summarizerClientElection.js.map +1 -0
  134. package/dist/summary/summarizerHandle.d.ts.map +1 -0
  135. package/dist/summary/summarizerHandle.js.map +1 -0
  136. package/{lib → dist/summary}/summarizerHeuristics.d.ts +1 -1
  137. package/dist/summary/summarizerHeuristics.d.ts.map +1 -0
  138. package/dist/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +6 -9
  139. package/dist/summary/summarizerHeuristics.js.map +1 -0
  140. package/{lib → dist/summary}/summarizerTypes.d.ts +22 -22
  141. package/dist/summary/summarizerTypes.d.ts.map +1 -0
  142. package/dist/summary/summarizerTypes.js.map +1 -0
  143. package/dist/summary/summaryCollection.d.ts.map +1 -0
  144. package/dist/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  145. package/dist/summary/summaryCollection.js.map +1 -0
  146. package/{lib → dist/summary}/summaryFormat.d.ts +1 -40
  147. package/dist/summary/summaryFormat.d.ts.map +1 -0
  148. package/dist/{summaryFormat.js → summary/summaryFormat.js} +19 -20
  149. package/dist/summary/summaryFormat.js.map +1 -0
  150. package/dist/summary/summaryGenerator.d.ts.map +1 -0
  151. package/dist/{summaryGenerator.js → summary/summaryGenerator.js} +33 -15
  152. package/dist/summary/summaryGenerator.js.map +1 -0
  153. package/dist/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  154. package/dist/summary/summaryManager.d.ts.map +1 -0
  155. package/dist/{summaryManager.js → summary/summaryManager.js} +21 -9
  156. package/dist/summary/summaryManager.js.map +1 -0
  157. package/dist/throttler.d.ts +2 -2
  158. package/dist/throttler.d.ts.map +1 -1
  159. package/dist/throttler.js +4 -4
  160. package/dist/throttler.js.map +1 -1
  161. package/lib/batchTracker.d.ts.map +1 -1
  162. package/lib/batchTracker.js +2 -1
  163. package/lib/batchTracker.js.map +1 -1
  164. package/lib/blobManager.d.ts +15 -2
  165. package/lib/blobManager.d.ts.map +1 -1
  166. package/lib/blobManager.js +109 -37
  167. package/lib/blobManager.js.map +1 -1
  168. package/lib/connectionTelemetry.d.ts.map +1 -1
  169. package/lib/connectionTelemetry.js +11 -9
  170. package/lib/connectionTelemetry.js.map +1 -1
  171. package/lib/containerHandleContext.d.ts.map +1 -1
  172. package/lib/containerHandleContext.js +3 -1
  173. package/lib/containerHandleContext.js.map +1 -1
  174. package/lib/containerRuntime.d.ts +23 -11
  175. package/lib/containerRuntime.d.ts.map +1 -1
  176. package/lib/containerRuntime.js +201 -108
  177. package/lib/containerRuntime.js.map +1 -1
  178. package/lib/dataStore.d.ts.map +1 -1
  179. package/lib/dataStore.js +11 -9
  180. package/lib/dataStore.js.map +1 -1
  181. package/lib/dataStoreContext.d.ts +27 -13
  182. package/lib/dataStoreContext.d.ts.map +1 -1
  183. package/lib/dataStoreContext.js +84 -45
  184. package/lib/dataStoreContext.js.map +1 -1
  185. package/lib/dataStoreContexts.d.ts.map +1 -1
  186. package/lib/dataStoreContexts.js +7 -3
  187. package/lib/dataStoreContexts.js.map +1 -1
  188. package/lib/dataStoreRegistry.d.ts.map +1 -1
  189. package/lib/dataStoreRegistry.js +3 -1
  190. package/lib/dataStoreRegistry.js.map +1 -1
  191. package/lib/dataStores.d.ts +28 -4
  192. package/lib/dataStores.d.ts.map +1 -1
  193. package/lib/dataStores.js +120 -42
  194. package/lib/dataStores.js.map +1 -1
  195. package/lib/deltaScheduler.d.ts.map +1 -1
  196. package/lib/deltaScheduler.js +9 -4
  197. package/lib/deltaScheduler.js.map +1 -1
  198. package/lib/{garbageCollection.d.ts → gc/garbageCollection.d.ts} +27 -203
  199. package/lib/gc/garbageCollection.d.ts.map +1 -0
  200. package/lib/{garbageCollection.js → gc/garbageCollection.js} +190 -379
  201. package/lib/gc/garbageCollection.js.map +1 -0
  202. package/lib/gc/gcDefinitions.d.ts +189 -0
  203. package/lib/gc/gcDefinitions.d.ts.map +1 -0
  204. package/lib/{garbageCollectionConstants.js → gc/gcDefinitions.js} +26 -1
  205. package/lib/gc/gcDefinitions.js.map +1 -0
  206. package/lib/gc/gcHelpers.d.ts +30 -0
  207. package/lib/gc/gcHelpers.d.ts.map +1 -0
  208. package/lib/gc/gcHelpers.js +58 -0
  209. package/lib/gc/gcHelpers.js.map +1 -0
  210. package/lib/gc/gcSummaryStateTracker.d.ts +86 -0
  211. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -0
  212. package/lib/gc/gcSummaryStateTracker.js +242 -0
  213. package/lib/gc/gcSummaryStateTracker.js.map +1 -0
  214. package/{dist → lib/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  215. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  216. package/lib/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  217. package/lib/gc/gcSweepReadyUsageDetection.js.map +1 -0
  218. package/lib/gc/gcUnreferencedStateTracker.d.ts +34 -0
  219. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  220. package/lib/gc/gcUnreferencedStateTracker.js +90 -0
  221. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -0
  222. package/lib/gc/index.d.ts +11 -0
  223. package/lib/gc/index.d.ts.map +1 -0
  224. package/lib/gc/index.js +11 -0
  225. package/lib/gc/index.js.map +1 -0
  226. package/lib/index.d.ts +2 -5
  227. package/lib/index.d.ts.map +1 -1
  228. package/lib/index.js +1 -4
  229. package/lib/index.js.map +1 -1
  230. package/lib/opLifecycle/batchManager.d.ts +2 -13
  231. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  232. package/lib/opLifecycle/batchManager.js +19 -41
  233. package/lib/opLifecycle/batchManager.js.map +1 -1
  234. package/lib/opLifecycle/definitions.d.ts +4 -0
  235. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  236. package/lib/opLifecycle/definitions.js.map +1 -1
  237. package/lib/opLifecycle/index.d.ts.map +1 -1
  238. package/lib/opLifecycle/index.js.map +1 -1
  239. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  240. package/lib/opLifecycle/opCompressor.js +1 -0
  241. package/lib/opLifecycle/opCompressor.js.map +1 -1
  242. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  243. package/lib/opLifecycle/opDecompressor.js +5 -2
  244. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  245. package/lib/opLifecycle/opSplitter.d.ts +1 -1
  246. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  247. package/lib/opLifecycle/opSplitter.js +25 -14
  248. package/lib/opLifecycle/opSplitter.js.map +1 -1
  249. package/lib/opLifecycle/outbox.d.ts +19 -3
  250. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  251. package/lib/opLifecycle/outbox.js +79 -46
  252. package/lib/opLifecycle/outbox.js.map +1 -1
  253. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  254. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  255. package/lib/opProperties.d.ts.map +1 -1
  256. package/lib/opProperties.js +1 -3
  257. package/lib/opProperties.js.map +1 -1
  258. package/lib/packageVersion.d.ts +1 -1
  259. package/lib/packageVersion.js +1 -1
  260. package/lib/packageVersion.js.map +1 -1
  261. package/lib/pendingStateManager.d.ts +8 -2
  262. package/lib/pendingStateManager.d.ts.map +1 -1
  263. package/lib/pendingStateManager.js +21 -13
  264. package/lib/pendingStateManager.js.map +1 -1
  265. package/lib/scheduleManager.d.ts.map +1 -1
  266. package/lib/scheduleManager.js +3 -2
  267. package/lib/scheduleManager.js.map +1 -1
  268. package/lib/serializedSnapshotStorage.d.ts +2 -2
  269. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  270. package/lib/serializedSnapshotStorage.js +5 -3
  271. package/lib/serializedSnapshotStorage.js.map +1 -1
  272. package/lib/summary/index.d.ts +17 -0
  273. package/lib/summary/index.d.ts.map +1 -0
  274. package/lib/summary/index.js +16 -0
  275. package/lib/summary/index.js.map +1 -0
  276. package/lib/summary/orderedClientElection.d.ts.map +1 -0
  277. package/lib/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  278. package/lib/summary/orderedClientElection.js.map +1 -0
  279. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  280. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -0
  281. package/{dist → lib/summary}/runningSummarizer.d.ts +19 -18
  282. package/lib/summary/runningSummarizer.d.ts.map +1 -0
  283. package/lib/{runningSummarizer.js → summary/runningSummarizer.js} +193 -78
  284. package/lib/summary/runningSummarizer.js.map +1 -0
  285. package/lib/{summarizer.d.ts → summary/summarizer.d.ts} +4 -6
  286. package/lib/summary/summarizer.d.ts.map +1 -0
  287. package/lib/{summarizer.js → summary/summarizer.js} +33 -73
  288. package/lib/summary/summarizer.js.map +1 -0
  289. package/lib/summary/summarizerClientElection.d.ts.map +1 -0
  290. package/lib/summary/summarizerClientElection.js.map +1 -0
  291. package/lib/summary/summarizerHandle.d.ts.map +1 -0
  292. package/lib/summary/summarizerHandle.js.map +1 -0
  293. package/{dist → lib/summary}/summarizerHeuristics.d.ts +1 -1
  294. package/lib/summary/summarizerHeuristics.d.ts.map +1 -0
  295. package/lib/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +6 -9
  296. package/lib/summary/summarizerHeuristics.js.map +1 -0
  297. package/{dist → lib/summary}/summarizerTypes.d.ts +22 -22
  298. package/lib/summary/summarizerTypes.d.ts.map +1 -0
  299. package/lib/summary/summarizerTypes.js.map +1 -0
  300. package/lib/summary/summaryCollection.d.ts.map +1 -0
  301. package/lib/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  302. package/lib/summary/summaryCollection.js.map +1 -0
  303. package/{dist → lib/summary}/summaryFormat.d.ts +1 -40
  304. package/lib/summary/summaryFormat.d.ts.map +1 -0
  305. package/lib/{summaryFormat.js → summary/summaryFormat.js} +20 -20
  306. package/lib/summary/summaryFormat.js.map +1 -0
  307. package/lib/summary/summaryGenerator.d.ts.map +1 -0
  308. package/lib/{summaryGenerator.js → summary/summaryGenerator.js} +33 -15
  309. package/lib/summary/summaryGenerator.js.map +1 -0
  310. package/lib/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  311. package/lib/summary/summaryManager.d.ts.map +1 -0
  312. package/lib/{summaryManager.js → summary/summaryManager.js} +21 -9
  313. package/lib/summary/summaryManager.js.map +1 -0
  314. package/lib/throttler.d.ts +2 -2
  315. package/lib/throttler.d.ts.map +1 -1
  316. package/lib/throttler.js +4 -4
  317. package/lib/throttler.js.map +1 -1
  318. package/package.json +60 -51
  319. package/prettier.config.cjs +1 -1
  320. package/src/batchTracker.ts +54 -49
  321. package/src/blobManager.ts +825 -674
  322. package/src/connectionTelemetry.ts +280 -249
  323. package/src/containerHandleContext.ts +27 -29
  324. package/src/containerRuntime.ts +3249 -2978
  325. package/src/dataStore.ts +172 -159
  326. package/src/dataStoreContext.ts +1141 -1057
  327. package/src/dataStoreContexts.ts +178 -161
  328. package/src/dataStoreRegistry.ts +25 -20
  329. package/src/dataStores.ts +880 -731
  330. package/src/deltaScheduler.ts +158 -150
  331. package/{garbageCollection.md → src/gc/garbageCollection.md} +16 -3
  332. package/src/gc/garbageCollection.ts +1506 -0
  333. package/src/gc/gcDefinitions.ts +244 -0
  334. package/src/gc/gcHelpers.ts +86 -0
  335. package/src/gc/gcSummaryStateTracker.ts +339 -0
  336. package/src/gc/gcSweepReadyUsageDetection.ts +145 -0
  337. package/src/gc/gcUnreferencedStateTracker.ts +114 -0
  338. package/src/gc/index.ts +40 -0
  339. package/src/index.ts +67 -70
  340. package/src/opLifecycle/README.md +152 -0
  341. package/src/opLifecycle/batchManager.ts +101 -144
  342. package/src/opLifecycle/definitions.ts +33 -29
  343. package/src/opLifecycle/index.ts +5 -5
  344. package/src/opLifecycle/opCompressor.ts +55 -53
  345. package/src/opLifecycle/opDecompressor.ts +100 -81
  346. package/src/opLifecycle/opSplitter.ts +233 -188
  347. package/src/opLifecycle/outbox.ts +251 -195
  348. package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
  349. package/src/opProperties.ts +11 -9
  350. package/src/packageVersion.ts +1 -1
  351. package/src/pendingStateManager.ts +396 -338
  352. package/src/scheduleManager.ts +299 -269
  353. package/src/serializedSnapshotStorage.ts +126 -112
  354. package/src/summary/index.ts +99 -0
  355. package/src/summary/orderedClientElection.ts +564 -0
  356. package/src/summary/runWhileConnectedCoordinator.ts +113 -0
  357. package/src/summary/runningSummarizer.ts +788 -0
  358. package/src/summary/summarizer.ts +386 -0
  359. package/src/summary/summarizerClientElection.ts +139 -0
  360. package/src/{summarizerHandle.ts → summary/summarizerHandle.ts} +11 -9
  361. package/src/summary/summarizerHeuristics.ts +219 -0
  362. package/src/summary/summarizerTypes.ts +521 -0
  363. package/src/summary/summaryCollection.ts +450 -0
  364. package/src/summary/summaryFormat.ts +226 -0
  365. package/src/summary/summaryGenerator.ts +505 -0
  366. package/src/summary/summaryManager.ts +423 -0
  367. package/src/throttler.ts +131 -122
  368. package/tsconfig.esnext.json +6 -6
  369. package/tsconfig.json +9 -13
  370. package/dist/garbageCollection.d.ts.map +0 -1
  371. package/dist/garbageCollection.js.map +0 -1
  372. package/dist/garbageCollectionConstants.d.ts +0 -25
  373. package/dist/garbageCollectionConstants.d.ts.map +0 -1
  374. package/dist/garbageCollectionConstants.js.map +0 -1
  375. package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
  376. package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  377. package/dist/garbageCollectionTombstoneUtils.js +0 -23
  378. package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
  379. package/dist/gcSweepReadyUsageDetection.d.ts.map +0 -1
  380. package/dist/gcSweepReadyUsageDetection.js.map +0 -1
  381. package/dist/orderedClientElection.d.ts.map +0 -1
  382. package/dist/orderedClientElection.js.map +0 -1
  383. package/dist/runWhileConnectedCoordinator.d.ts.map +0 -1
  384. package/dist/runWhileConnectedCoordinator.js.map +0 -1
  385. package/dist/runningSummarizer.d.ts.map +0 -1
  386. package/dist/runningSummarizer.js.map +0 -1
  387. package/dist/summarizer.d.ts.map +0 -1
  388. package/dist/summarizer.js.map +0 -1
  389. package/dist/summarizerClientElection.d.ts.map +0 -1
  390. package/dist/summarizerClientElection.js.map +0 -1
  391. package/dist/summarizerHandle.d.ts.map +0 -1
  392. package/dist/summarizerHandle.js.map +0 -1
  393. package/dist/summarizerHeuristics.d.ts.map +0 -1
  394. package/dist/summarizerHeuristics.js.map +0 -1
  395. package/dist/summarizerTypes.d.ts.map +0 -1
  396. package/dist/summarizerTypes.js.map +0 -1
  397. package/dist/summaryCollection.d.ts.map +0 -1
  398. package/dist/summaryCollection.js.map +0 -1
  399. package/dist/summaryFormat.d.ts.map +0 -1
  400. package/dist/summaryFormat.js.map +0 -1
  401. package/dist/summaryGenerator.d.ts.map +0 -1
  402. package/dist/summaryGenerator.js.map +0 -1
  403. package/dist/summaryManager.d.ts.map +0 -1
  404. package/dist/summaryManager.js.map +0 -1
  405. package/lib/garbageCollection.d.ts.map +0 -1
  406. package/lib/garbageCollection.js.map +0 -1
  407. package/lib/garbageCollectionConstants.d.ts +0 -25
  408. package/lib/garbageCollectionConstants.d.ts.map +0 -1
  409. package/lib/garbageCollectionConstants.js.map +0 -1
  410. package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
  411. package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
  412. package/lib/garbageCollectionTombstoneUtils.js +0 -19
  413. package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
  414. package/lib/gcSweepReadyUsageDetection.d.ts.map +0 -1
  415. package/lib/gcSweepReadyUsageDetection.js.map +0 -1
  416. package/lib/orderedClientElection.d.ts.map +0 -1
  417. package/lib/orderedClientElection.js.map +0 -1
  418. package/lib/runWhileConnectedCoordinator.d.ts.map +0 -1
  419. package/lib/runWhileConnectedCoordinator.js.map +0 -1
  420. package/lib/runningSummarizer.d.ts.map +0 -1
  421. package/lib/runningSummarizer.js.map +0 -1
  422. package/lib/summarizer.d.ts.map +0 -1
  423. package/lib/summarizer.js.map +0 -1
  424. package/lib/summarizerClientElection.d.ts.map +0 -1
  425. package/lib/summarizerClientElection.js.map +0 -1
  426. package/lib/summarizerHandle.d.ts.map +0 -1
  427. package/lib/summarizerHandle.js.map +0 -1
  428. package/lib/summarizerHeuristics.d.ts.map +0 -1
  429. package/lib/summarizerHeuristics.js.map +0 -1
  430. package/lib/summarizerTypes.d.ts.map +0 -1
  431. package/lib/summarizerTypes.js.map +0 -1
  432. package/lib/summaryCollection.d.ts.map +0 -1
  433. package/lib/summaryCollection.js.map +0 -1
  434. package/lib/summaryFormat.d.ts.map +0 -1
  435. package/lib/summaryFormat.js.map +0 -1
  436. package/lib/summaryGenerator.d.ts.map +0 -1
  437. package/lib/summaryGenerator.js.map +0 -1
  438. package/lib/summaryManager.d.ts.map +0 -1
  439. package/lib/summaryManager.js.map +0 -1
  440. package/src/garbageCollection.ts +0 -1800
  441. package/src/garbageCollectionConstants.ts +0 -41
  442. package/src/garbageCollectionTombstoneUtils.ts +0 -28
  443. package/src/gcSweepReadyUsageDetection.ts +0 -139
  444. package/src/orderedClientElection.ts +0 -532
  445. package/src/runWhileConnectedCoordinator.ts +0 -106
  446. package/src/runningSummarizer.ts +0 -610
  447. package/src/summarizer.ts +0 -421
  448. package/src/summarizerClientElection.ts +0 -132
  449. package/src/summarizerHeuristics.ts +0 -222
  450. package/src/summarizerTypes.ts +0 -507
  451. package/src/summaryCollection.ts +0 -421
  452. package/src/summaryFormat.ts +0 -256
  453. package/src/summaryGenerator.ts +0 -450
  454. package/src/summaryManager.ts +0 -394
  455. /package/dist/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  456. /package/dist/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  457. /package/dist/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  458. /package/dist/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  459. /package/dist/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  460. /package/dist/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  461. /package/dist/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  462. /package/dist/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  463. /package/dist/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  464. /package/dist/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  465. /package/lib/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  466. /package/lib/{runWhileConnectedCoordinator.d.ts → summary/runWhileConnectedCoordinator.d.ts} +0 -0
  467. /package/lib/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +0 -0
  468. /package/lib/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +0 -0
  469. /package/lib/{summarizerClientElection.js → summary/summarizerClientElection.js} +0 -0
  470. /package/lib/{summarizerHandle.d.ts → summary/summarizerHandle.d.ts} +0 -0
  471. /package/lib/{summarizerHandle.js → summary/summarizerHandle.js} +0 -0
  472. /package/lib/{summarizerTypes.js → summary/summarizerTypes.js} +0 -0
  473. /package/lib/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  474. /package/lib/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
package/src/dataStores.ts CHANGED
@@ -4,59 +4,76 @@
4
4
  */
5
5
 
6
6
  import { ITelemetryBaseLogger, IDisposable } from "@fluidframework/common-definitions";
7
- import { DataCorruptionError, extractSafePropertiesFromMessage } from "@fluidframework/container-utils";
8
- import { IFluidHandle } from "@fluidframework/core-interfaces";
9
- import { FluidObjectHandle } from "@fluidframework/datastore";
10
7
  import {
11
- ISequencedDocumentMessage,
12
- ISnapshotTree,
13
- } from "@fluidframework/protocol-definitions";
8
+ DataCorruptionError,
9
+ extractSafePropertiesFromMessage,
10
+ } from "@fluidframework/container-utils";
11
+ import { IFluidHandle, IRequest } from "@fluidframework/core-interfaces";
12
+ import { FluidObjectHandle } from "@fluidframework/datastore";
13
+ import { ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
14
14
  import {
15
- AliasResult,
16
- channelsTreeName,
17
- CreateChildSummarizerNodeFn,
18
- CreateChildSummarizerNodeParam,
19
- CreateSummarizerNodeSource,
20
- IAttachMessage,
21
- IEnvelope,
22
- IFluidDataStoreContextDetached,
23
- IGarbageCollectionData,
24
- IGarbageCollectionDetailsBase,
25
- IInboundSignalMessage,
26
- InboundAttachMessage,
27
- ISummarizeResult,
28
- ISummaryTreeWithStats,
29
- ITelemetryContext,
15
+ AliasResult,
16
+ channelsTreeName,
17
+ CreateChildSummarizerNodeFn,
18
+ CreateChildSummarizerNodeParam,
19
+ CreateSummarizerNodeSource,
20
+ IAttachMessage,
21
+ IEnvelope,
22
+ IFluidDataStoreContextDetached,
23
+ IGarbageCollectionData,
24
+ IInboundSignalMessage,
25
+ InboundAttachMessage,
26
+ ISummarizeResult,
27
+ ISummaryTreeWithStats,
28
+ ITelemetryContext,
30
29
  } from "@fluidframework/runtime-definitions";
31
30
  import {
32
- convertSnapshotTreeToSummaryTree,
33
- convertToSummaryTree,
34
- create404Response,
35
- createResponseError,
36
- responseToException,
37
- SummaryTreeBuilder,
31
+ convertSnapshotTreeToSummaryTree,
32
+ convertToSummaryTree,
33
+ create404Response,
34
+ createResponseError,
35
+ responseToException,
36
+ SummaryTreeBuilder,
38
37
  } from "@fluidframework/runtime-utils";
39
- import { ChildLogger, loggerToMonitoringContext, LoggingError, MonitoringContext, TelemetryDataTag } from "@fluidframework/telemetry-utils";
38
+ import {
39
+ ChildLogger,
40
+ loggerToMonitoringContext,
41
+ LoggingError,
42
+ MonitoringContext,
43
+ TelemetryDataTag,
44
+ } from "@fluidframework/telemetry-utils";
40
45
  import { AttachState } from "@fluidframework/container-definitions";
41
46
  import { BlobCacheStorageService, buildSnapshotTree } from "@fluidframework/driver-utils";
42
- import { assert, Lazy, LazyPromise } from "@fluidframework/common-utils";
47
+ import { assert, Lazy } from "@fluidframework/common-utils";
43
48
  import { v4 as uuid } from "uuid";
44
- import { GCDataBuilder, unpackChildNodesGCDetails, unpackChildNodesUsedRoutes } from "@fluidframework/garbage-collector";
49
+ import { GCDataBuilder, unpackChildNodesUsedRoutes } from "@fluidframework/garbage-collector";
45
50
  import { DataStoreContexts } from "./dataStoreContexts";
46
- import { ContainerRuntime, defaultRuntimeHeaderData, RuntimeHeaderData, TombstoneResponseHeaderKey } from "./containerRuntime";
47
51
  import {
48
- FluidDataStoreContext,
49
- RemoteFluidDataStoreContext,
50
- LocalFluidDataStoreContext,
51
- createAttributesBlob,
52
- LocalDetachedFluidDataStoreContext,
52
+ ContainerRuntime,
53
+ defaultRuntimeHeaderData,
54
+ RuntimeHeaderData,
55
+ TombstoneResponseHeaderKey,
56
+ } from "./containerRuntime";
57
+ import {
58
+ FluidDataStoreContext,
59
+ RemoteFluidDataStoreContext,
60
+ LocalFluidDataStoreContext,
61
+ createAttributesBlob,
62
+ LocalDetachedFluidDataStoreContext,
53
63
  } from "./dataStoreContext";
54
- import { IContainerRuntimeMetadata, nonDataStorePaths, rootHasIsolatedChannels } from "./summaryFormat";
55
64
  import { IDataStoreAliasMessage, isDataStoreAliasMessage } from "./dataStore";
56
- import { GCNodeType } from "./garbageCollection";
57
- import { throwOnTombstoneLoadKey } from "./garbageCollectionConstants";
58
- import { summarizerClientType } from "./summarizerClientElection";
59
- import { sendGCTombstoneEvent } from "./garbageCollectionTombstoneUtils";
65
+ import {
66
+ GCNodeType,
67
+ sweepDatastoresKey,
68
+ throwOnTombstoneLoadKey,
69
+ sendGCUnexpectedUsageEvent,
70
+ } from "./gc";
71
+ import {
72
+ summarizerClientType,
73
+ IContainerRuntimeMetadata,
74
+ nonDataStorePaths,
75
+ rootHasIsolatedChannels,
76
+ } from "./summary";
60
77
 
61
78
  type PendingAliasResolve = (success: boolean) => void;
62
79
 
@@ -65,698 +82,830 @@ type PendingAliasResolve = (success: boolean) => void;
65
82
  * but eventually could be hosted on any channel once we formalize the channel api boundary.
66
83
  */
67
84
  export class DataStores implements IDisposable {
68
- // Stores tracked by the Domain
69
- private readonly pendingAttach = new Map<string, IAttachMessage>();
70
- // 0.24 back-compat attachingBeforeSummary
71
- public readonly attachOpFiredForDataStore = new Set<string>();
72
-
73
- private readonly mc: MonitoringContext;
74
-
75
- private readonly disposeOnce = new Lazy<void>(() => this.contexts.dispose());
76
-
77
- public readonly containerLoadStats: {
78
- // number of dataStores during loadContainer
79
- readonly containerLoadDataStoreCount: number;
80
- // number of unreferenced dataStores during loadContainer
81
- readonly referencedDataStoreCount: number;
82
- };
83
-
84
- // Stores the ids of new data stores between two GC runs. This is used to notify the garbage collector of new
85
- // root data stores that are added.
86
- private dataStoresSinceLastGC: string[] = [];
87
- /** If true, throw an error when a tombstone data store is retrieved. */
88
- private readonly throwOnTombstoneLoad: boolean;
89
- // The handle to the container runtime. This is used mainly for GC purposes to represent outbound reference from
90
- // the container runtime to other nodes.
91
- private readonly containerRuntimeHandle: IFluidHandle;
92
- private readonly pendingAliasMap: Map<string, Promise<AliasResult>> = new Map<string, Promise<AliasResult>>();
93
-
94
- constructor(
95
- private readonly baseSnapshot: ISnapshotTree | undefined,
96
- private readonly runtime: ContainerRuntime,
97
- private readonly submitAttachFn: (attachContent: any) => void,
98
- private readonly getCreateChildSummarizerNodeFn:
99
- (id: string, createParam: CreateChildSummarizerNodeParam) => CreateChildSummarizerNodeFn,
100
- private readonly deleteChildSummarizerNodeFn: (id: string) => void,
101
- baseLogger: ITelemetryBaseLogger,
102
- getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase>,
103
- private readonly gcNodeUpdated: (
104
- nodePath: string, timestampMs: number, packagePath?: readonly string[]) => void,
105
- private readonly aliasMap: Map<string, string>,
106
- private readonly contexts: DataStoreContexts = new DataStoreContexts(baseLogger),
107
- ) {
108
- this.mc = loggerToMonitoringContext(ChildLogger.create(baseLogger));
109
- this.containerRuntimeHandle = new FluidObjectHandle(this.runtime, "/", this.runtime.IFluidHandleContext);
110
-
111
- const baseGCDetailsP = new LazyPromise(async () => {
112
- const baseGCDetails = await getBaseGCDetails();
113
- return unpackChildNodesGCDetails(baseGCDetails);
114
- });
115
- // Returns the base GC details for the data store with the given id.
116
- const dataStoreBaseGCDetails = async (dataStoreId: string) => {
117
- const baseGCDetails = await baseGCDetailsP;
118
- return baseGCDetails.get(dataStoreId);
119
- };
120
- // Tombstone should only throw when the feature flag is enabled and the client isn't a summarizer
121
- this.throwOnTombstoneLoad =
122
- this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
123
- this.runtime.clientDetails.type !== summarizerClientType;
124
-
125
- // Extract stores stored inside the snapshot
126
- const fluidDataStores = new Map<string, ISnapshotTree>();
127
- if (baseSnapshot) {
128
- for (const [key, value] of Object.entries(baseSnapshot.trees)) {
129
- fluidDataStores.set(key, value);
130
- }
131
- }
132
-
133
- let unreferencedDataStoreCount = 0;
134
- // Create a context for each of them
135
- for (const [key, value] of fluidDataStores) {
136
- let dataStoreContext: FluidDataStoreContext;
137
-
138
- // counting number of unreferenced data stores
139
- if (value.unreferenced) {
140
- unreferencedDataStoreCount++;
141
- }
142
- // If we have a detached container, then create local data store contexts.
143
- if (this.runtime.attachState !== AttachState.Detached) {
144
- dataStoreContext = new RemoteFluidDataStoreContext({
145
- id: key,
146
- snapshotTree: value,
147
- getBaseGCDetails: async () => dataStoreBaseGCDetails(key),
148
- runtime: this.runtime,
149
- storage: this.runtime.storage,
150
- scope: this.runtime.scope,
151
- createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(
152
- key,
153
- { type: CreateSummarizerNodeSource.FromSummary },
154
- ),
155
- });
156
- } else {
157
- if (typeof value !== "object") {
158
- throw new LoggingError("Snapshot should be there to load from!!");
159
- }
160
- const snapshotTree = value;
161
- dataStoreContext = new LocalFluidDataStoreContext({
162
- id: key,
163
- pkg: undefined,
164
- runtime: this.runtime,
165
- storage: this.runtime.storage,
166
- scope: this.runtime.scope,
167
- createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(
168
- key,
169
- { type: CreateSummarizerNodeSource.FromSummary },
170
- ),
171
- makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(key),
172
- snapshotTree,
173
- isRootDataStore: undefined,
174
- });
175
- }
176
- this.contexts.addBoundOrRemoted(dataStoreContext);
177
- }
178
- this.containerLoadStats = {
179
- containerLoadDataStoreCount: fluidDataStores.size,
180
- referencedDataStoreCount: fluidDataStores.size - unreferencedDataStoreCount,
181
- };
182
- }
183
-
184
- public get aliases(): ReadonlyMap<string, string> {
185
- return this.aliasMap;
186
- }
187
-
188
- public get pendingAliases(): Map<string, Promise<AliasResult>> {
189
- return this.pendingAliasMap;
190
- }
191
-
192
- public async waitIfPendingAlias(maybeAlias: string): Promise<AliasResult> {
193
- const pendingAliasPromise = this.pendingAliases.get(maybeAlias);
194
- return pendingAliasPromise === undefined ? "Success" : pendingAliasPromise;
195
- }
196
-
197
- public processAttachMessage(message: ISequencedDocumentMessage, local: boolean) {
198
- const attachMessage = message.contents as InboundAttachMessage;
199
-
200
- this.dataStoresSinceLastGC.push(attachMessage.id);
201
-
202
- // The local object has already been attached
203
- if (local) {
204
- assert(this.pendingAttach.has(attachMessage.id),
205
- 0x15e /* "Local object does not have matching attach message id" */);
206
- this.contexts.get(attachMessage.id)?.emit("attached");
207
- this.pendingAttach.delete(attachMessage.id);
208
- return;
209
- }
210
-
211
- // If a non-local operation then go and create the object, otherwise mark it as officially attached.
212
- if (this.alreadyProcessed(attachMessage.id)) {
213
- // TODO: dataStoreId may require a different tag from PackageData #7488
214
- const error = new DataCorruptionError(
215
- // pre-0.58 error message: duplicateDataStoreCreatedWithExistingId
216
- "Duplicate DataStore created with existing id",
217
- {
218
- ...extractSafePropertiesFromMessage(message),
219
- dataStoreId: {
220
- value: attachMessage.id,
221
- tag: TelemetryDataTag.CodeArtifact,
222
- },
223
- },
224
- );
225
- throw error;
226
- }
227
-
228
- const flatBlobs = new Map<string, ArrayBufferLike>();
229
- let snapshotTree: ISnapshotTree | undefined;
230
- if (attachMessage.snapshot) {
231
- snapshotTree = buildSnapshotTree(attachMessage.snapshot.entries, flatBlobs);
232
- }
233
-
234
- // Include the type of attach message which is the pkg of the store to be
235
- // used by RemoteFluidDataStoreContext in case it is not in the snapshot.
236
- const pkg = [attachMessage.type];
237
- const remoteFluidDataStoreContext = new RemoteFluidDataStoreContext({
238
- id: attachMessage.id,
239
- snapshotTree,
240
- // New data stores begin with empty GC details since GC hasn't run on them yet.
241
- getBaseGCDetails: async () => { return {}; },
242
- runtime: this.runtime,
243
- storage: new BlobCacheStorageService(this.runtime.storage, flatBlobs),
244
- scope: this.runtime.scope,
245
- createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(
246
- attachMessage.id,
247
- {
248
- type: CreateSummarizerNodeSource.FromAttach,
249
- sequenceNumber: message.sequenceNumber,
250
- snapshot: attachMessage.snapshot ?? {
251
- entries: [createAttributesBlob(
252
- pkg,
253
- true /* isRootDataStore */,
254
- )],
255
- },
256
- },
257
- ),
258
- pkg,
259
- });
260
-
261
- this.contexts.addBoundOrRemoted(remoteFluidDataStoreContext);
262
- }
263
-
264
- public processAliasMessage(
265
- message: ISequencedDocumentMessage,
266
- localOpMetadata: unknown,
267
- local: boolean,
268
- ): void {
269
- const aliasMessage = message.contents as IDataStoreAliasMessage;
270
- if (!isDataStoreAliasMessage(aliasMessage)) {
271
- throw new DataCorruptionError(
272
- "malformedDataStoreAliasMessage",
273
- {
274
- ...extractSafePropertiesFromMessage(message),
275
- },
276
- );
277
- }
278
-
279
- const resolve = localOpMetadata as PendingAliasResolve;
280
- const aliasResult = this.processAliasMessageCore(aliasMessage);
281
- if (local) {
282
- resolve(aliasResult);
283
- }
284
- }
285
-
286
- public processAliasMessageCore(aliasMessage: IDataStoreAliasMessage): boolean {
287
- if (this.alreadyProcessed(aliasMessage.alias)) {
288
- return false;
289
- }
290
-
291
- const context = this.contexts.get(aliasMessage.internalId);
292
- if (context === undefined) {
293
- this.mc.logger.sendErrorEvent({
294
- eventName: "AliasFluidDataStoreNotFound",
295
- fluidDataStoreId: aliasMessage.internalId,
296
- });
297
- return false;
298
- }
299
-
300
- const handle = new FluidObjectHandle(
301
- context,
302
- aliasMessage.internalId,
303
- this.runtime.IFluidHandleContext,
304
- );
305
- this.runtime.addedGCOutboundReference(this.containerRuntimeHandle, handle);
306
-
307
- this.aliasMap.set(aliasMessage.alias, context.id);
308
- context.setInMemoryRoot();
309
- return true;
310
- }
311
-
312
- private alreadyProcessed(id: string): boolean {
313
- return this.aliasMap.get(id) !== undefined || this.contexts.get(id) !== undefined;
314
- }
315
-
316
- /**
317
- * Make the data stores locally visible in the container graph by moving the data store context from unbound to
318
- * bound list. This data store can now be reached from the root.
319
- * @param id - The id of the data store context to make visible.
320
- */
321
- private makeDataStoreLocallyVisible(id: string): void {
322
- const localContext = this.contexts.getUnbound(id);
323
- assert(!!localContext, 0x15f /* "Could not find unbound context to bind" */);
324
-
325
- /**
326
- * If the container is not detached, it is globally visible to all clients. This data store should also be
327
- * globally visible. Move it to attaching state and send an "attach" op for it.
328
- * If the container is detached, this data store will be part of the summary that makes the container attached.
329
- */
330
- if (this.runtime.attachState !== AttachState.Detached) {
331
- localContext.emit("attaching");
332
- const message = localContext.generateAttachMessage();
333
-
334
- this.pendingAttach.set(id, message);
335
- this.submitAttachFn(message);
336
- this.attachOpFiredForDataStore.add(id);
337
- }
338
-
339
- this.contexts.bind(id);
340
- }
341
-
342
- public createDetachedDataStoreCore(
343
- pkg: Readonly<string[]>,
344
- isRoot: boolean,
345
- id = uuid()): IFluidDataStoreContextDetached {
346
- assert(!id.includes("/"), 0x30c /* Id cannot contain slashes */);
347
-
348
- const context = new LocalDetachedFluidDataStoreContext({
349
- id,
350
- pkg,
351
- runtime: this.runtime,
352
- storage: this.runtime.storage,
353
- scope: this.runtime.scope,
354
- createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(
355
- id,
356
- { type: CreateSummarizerNodeSource.Local },
357
- ),
358
- makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(id),
359
- snapshotTree: undefined,
360
- isRootDataStore: isRoot,
361
- });
362
- this.contexts.addUnbound(context);
363
- return context;
364
- }
365
-
366
- public _createFluidDataStoreContext(pkg: string[], id: string, props?: any) {
367
- assert(!id.includes("/"), 0x30d /* Id cannot contain slashes */);
368
- const context = new LocalFluidDataStoreContext({
369
- id,
370
- pkg,
371
- runtime: this.runtime,
372
- storage: this.runtime.storage,
373
- scope: this.runtime.scope,
374
- createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(
375
- id,
376
- { type: CreateSummarizerNodeSource.Local },
377
- ),
378
- makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(id),
379
- snapshotTree: undefined,
380
- isRootDataStore: false,
381
- createProps: props,
382
- });
383
- this.contexts.addUnbound(context);
384
- return context;
385
- }
386
-
387
- public get disposed() { return this.disposeOnce.evaluated; }
388
- public readonly dispose = () => this.disposeOnce.value;
389
-
390
- public resubmitDataStoreOp(content: any, localOpMetadata: unknown) {
391
- const envelope = content as IEnvelope;
392
- const context = this.contexts.get(envelope.address);
393
- assert(!!context, 0x160 /* "There should be a store context for the op" */);
394
- context.reSubmit(envelope.contents, localOpMetadata);
395
- }
396
-
397
- public rollbackDataStoreOp(content: any, localOpMetadata: unknown) {
398
- const envelope = content as IEnvelope;
399
- const context = this.contexts.get(envelope.address);
400
- assert(!!context, 0x2e8 /* "There should be a store context for the op" */);
401
- context.rollback(envelope.contents, localOpMetadata);
402
- }
403
-
404
- public async applyStashedOp(content: any): Promise<unknown> {
405
- const envelope = content as IEnvelope;
406
- const context = this.contexts.get(envelope.address);
407
- assert(!!context, 0x161 /* "There should be a store context for the op" */);
408
- return context.applyStashedOp(envelope.contents);
409
- }
410
-
411
- public async applyStashedAttachOp(message: IAttachMessage) {
412
- this.pendingAttach.set(message.id, message);
413
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
414
- this.processAttachMessage({ contents: message } as ISequencedDocumentMessage, false);
415
- }
416
-
417
- public processFluidDataStoreOp(message: ISequencedDocumentMessage, local: boolean, localMessageMetadata: unknown) {
418
- const envelope = message.contents as IEnvelope;
419
- const transformed = { ...message, contents: envelope.contents };
420
- const context = this.contexts.get(envelope.address);
421
- assert(!!context, 0x162 /* "There should be a store context for the op" */);
422
- context.process(transformed, local, localMessageMetadata);
423
-
424
- // Notify that a GC node for the data store changed. This is used to detect if a deleted data store is
425
- // being used.
426
- this.gcNodeUpdated(
427
- `/${envelope.address}`,
428
- message.timestamp,
429
- context.isLoaded ? context.packagePath : undefined,
430
- );
431
- }
432
-
433
- public async getDataStore(id: string, requestHeaderData: RuntimeHeaderData): Promise<FluidDataStoreContext> {
434
- const headerData = { ...defaultRuntimeHeaderData, ...requestHeaderData };
435
-
436
- const context = await this.contexts.getBoundOrRemoted(id, headerData.wait);
437
- const request = { url: id };
438
- if (context === undefined) {
439
- // The requested data store does not exits. Throw a 404 response exception.
440
- throw responseToException(create404Response(request), request);
441
- }
442
-
443
- if (context.tombstoned) {
444
- const shouldFail = this.throwOnTombstoneLoad && !headerData.allowTombstone;
445
-
446
- // The requested data store is removed by gc. Create a 404 gc response exception.
447
- const error = responseToException(createResponseError(
448
- 404,
449
- "DataStore was deleted",
450
- request,
451
- { [TombstoneResponseHeaderKey]: true },
452
- ), request);
453
- sendGCTombstoneEvent(
454
- this.mc,
455
- {
456
- eventName: "GC_Tombstone_DataStore_Requested",
457
- category: shouldFail ? "error" : "generic",
458
- isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
459
- headers: JSON.stringify(requestHeaderData),
460
- },
461
- context.isLoaded ? context.packagePath : undefined,
462
- error,
463
- );
464
-
465
- if (shouldFail) {
466
- throw error;
467
- }
468
- }
469
-
470
- return context;
471
- }
472
-
473
- public processSignal(address: string, message: IInboundSignalMessage, local: boolean) {
474
- const context = this.contexts.get(address);
475
- if (!context) {
476
- // Attach message may not have been processed yet
477
- assert(!local, 0x163 /* "Missing datastore for local signal" */);
478
- this.mc.logger.sendTelemetryEvent({
479
- eventName: "SignalFluidDataStoreNotFound",
480
- fluidDataStoreId: {
481
- value: address,
482
- tag: TelemetryDataTag.CodeArtifact,
483
- },
484
- });
485
- return;
486
- }
487
-
488
- context.processSignal(message, local);
489
- }
490
-
491
- public setConnectionState(connected: boolean, clientId?: string) {
492
- for (const [fluidDataStore, context] of this.contexts) {
493
- try {
494
- context.setConnectionState(connected, clientId);
495
- } catch (error) {
496
- this.mc.logger.sendErrorEvent({
497
- eventName: "SetConnectionStateError",
498
- clientId,
499
- fluidDataStore,
500
- }, error);
501
- }
502
- }
503
- }
504
-
505
- public setAttachState(attachState: AttachState.Attaching | AttachState.Attached): void {
506
- const eventName = attachState === AttachState.Attaching ? "attaching" : "attached";
507
- for (const [, context] of this.contexts) {
508
- // Fire only for bounded stores.
509
- if (!this.contexts.isNotBound(context.id)) {
510
- context.emit(eventName);
511
- }
512
- }
513
- }
514
-
515
- public get size(): number {
516
- return this.contexts.size;
517
- }
518
-
519
- public async summarize(
520
- fullTree: boolean,
521
- trackState: boolean,
522
- telemetryContext?: ITelemetryContext,
523
- ): Promise<ISummaryTreeWithStats> {
524
- const summaryBuilder = new SummaryTreeBuilder();
525
-
526
- // Iterate over each store and ask it to snapshot
527
- await Promise.all(Array.from(this.contexts)
528
- .filter(([_, context]) => {
529
- // Summarizer works only with clients with no local changes!
530
- assert(context.attachState !== AttachState.Attaching,
531
- 0x165 /* "Summarizer cannot work if client has local changes" */);
532
- return context.attachState === AttachState.Attached;
533
- }).map(async ([contextId, context]) => {
534
- const contextSummary = await context.summarize(fullTree, trackState, telemetryContext);
535
- summaryBuilder.addWithStats(contextId, contextSummary);
536
- }));
537
-
538
- return summaryBuilder.getSummaryTree();
539
- }
540
-
541
- public createSummary(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {
542
- const builder = new SummaryTreeBuilder();
543
- // Attaching graph of some stores can cause other stores to get bound too.
544
- // So keep taking summary until no new stores get bound.
545
- let notBoundContextsLength: number;
546
- do {
547
- const builderTree = builder.summary.tree;
548
- notBoundContextsLength = this.contexts.notBoundLength();
549
- // Iterate over each data store and ask it to snapshot
550
- Array.from(this.contexts)
551
- .filter(([key, _]) =>
552
- // Take summary of bounded data stores only, make sure we haven't summarized them already
553
- // and no attach op has been fired for that data store because for loader versions <= 0.24
554
- // we set attach state as "attaching" before taking createNew summary.
555
- !(this.contexts.isNotBound(key)
556
- || builderTree[key]
557
- || this.attachOpFiredForDataStore.has(key)),
558
- )
559
- .map(([key, value]) => {
560
- let dataStoreSummary: ISummarizeResult;
561
- if (value.isLoaded) {
562
- const snapshot = value.generateAttachMessage().snapshot;
563
- dataStoreSummary = convertToSummaryTree(snapshot, true);
564
- } else {
565
- // If this data store is not yet loaded, then there should be no changes in the snapshot from
566
- // which it was created as it is detached container. So just use the previous snapshot.
567
- assert(!!this.baseSnapshot,
568
- 0x166 /* "BaseSnapshot should be there as detached container loaded from snapshot" */);
569
- dataStoreSummary = convertSnapshotTreeToSummaryTree(this.baseSnapshot.trees[key]);
570
- }
571
- builder.addWithStats(key, dataStoreSummary);
572
- });
573
- } while (notBoundContextsLength !== this.contexts.notBoundLength());
574
-
575
- return builder.getSummaryTree();
576
- }
577
-
578
- /**
579
- * Before GC runs, called by the garbage collector to update any pending GC state.
580
- * The garbage collector needs to know all outbound references that are added. Since root data stores are not
581
- * explicitly marked as referenced, notify GC of new root data stores that were added since the last GC run.
582
- */
583
- public async updateStateBeforeGC(): Promise<void> {
584
- for (const id of this.dataStoresSinceLastGC) {
585
- const context = this.contexts.get(id);
586
- assert(context !== undefined, 0x2b6 /* Missing data store context */);
587
- if (await context.isRoot()) {
588
- // A root data store is basically a reference from the container runtime to the data store.
589
- const handle = new FluidObjectHandle(context, id, this.runtime.IFluidHandleContext);
590
- this.runtime.addedGCOutboundReference(this.containerRuntimeHandle, handle);
591
- }
592
- }
593
- this.dataStoresSinceLastGC = [];
594
- }
595
-
596
- /**
597
- * Generates data used for garbage collection. It does the following:
598
- *
599
- * 1. Calls into each child data store context to get its GC data.
600
- *
601
- * 2. Prefixes the child context's id to the GC nodes in the child's GC data. This makes sure that the node can be
602
- * identified as belonging to the child.
603
- *
604
- * 3. Adds a GC node for this channel to the nodes received from the children. All these nodes together represent
605
- * the GC data of this channel.
606
- *
607
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
608
- */
609
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
610
- const builder = new GCDataBuilder();
611
- // Iterate over each store and get their GC data.
612
- await Promise.all(Array.from(this.contexts)
613
- .filter(([_, context]) => {
614
- // Get GC data only for attached contexts. Detached contexts are not connected in the GC reference
615
- // graph so any references they might have won't be connected as well.
616
- return context.attachState === AttachState.Attached;
617
- }).map(async ([contextId, context]) => {
618
- const contextGCData = await context.getGCData(fullGC);
619
- // Prefix the child's id to the ids of its GC nodes so they can be identified as belonging to the child.
620
- // This also gradually builds the id of each node to be a path from the root.
621
- builder.prefixAndAddNodes(contextId, contextGCData.gcNodes);
622
- }));
623
-
624
- // Get the outbound routes and add a GC node for this channel.
625
- builder.addNode("/", await this.getOutboundRoutes());
626
- return builder.getGCData();
627
- }
628
-
629
- /**
630
- * After GC has run, called to notify this Container's data stores of routes that are used in it.
631
- * @param usedRoutes - The routes that are used in all data stores in this Container.
632
- */
633
- public updateUsedRoutes(usedRoutes: string[]) {
634
- // Get a map of data store ids to routes used in it.
635
- const usedDataStoreRoutes = unpackChildNodesUsedRoutes(usedRoutes);
636
-
637
- // Verify that the used routes are correct.
638
- for (const [id] of usedDataStoreRoutes) {
639
- assert(this.contexts.has(id), 0x167 /* "Used route does not belong to any known data store" */);
640
- }
641
-
642
- // Update the used routes in each data store. Used routes is empty for unused data stores.
643
- for (const [contextId, context] of this.contexts) {
644
- context.updateUsedRoutes(usedDataStoreRoutes.get(contextId) ?? []);
645
- }
646
- }
647
-
648
- /**
649
- * This is called to update objects whose routes are unused. The unused objects are deleted.
650
- * @param unusedRoutes - The routes that are unused in all data stores in this Container.
651
- */
652
- public updateUnusedRoutes(unusedRoutes: string[]) {
653
- for (const route of unusedRoutes) {
654
- const pathParts = route.split("/");
655
- // Delete data store only if its route (/datastoreId) is in unusedRoutes. We don't want to delete a data
656
- // store based on its DDS being unused.
657
- if (pathParts.length > 2) {
658
- continue;
659
- }
660
- const dataStoreId = pathParts[1];
661
- assert(this.contexts.has(dataStoreId), 0x2d7 /* No data store with specified id */);
662
- // Delete the contexts of unused data stores.
663
- this.contexts.delete(dataStoreId);
664
- // Delete the summarizer node of the unused data stores.
665
- this.deleteChildSummarizerNodeFn(dataStoreId);
666
- }
667
- }
668
-
669
- /**
670
- * This is called to update objects whose routes are tombstones. Tombstoned datastore contexts enable testing
671
- * scenarios with accessing deleted content without actually deleting content from summaries.
672
- * @param tombstonedRoutes - The routes that are tombstones in all data stores in this Container.
673
- */
674
- public updateTombstonedRoutes(tombstonedRoutes: string[]) {
675
- const tombstonedDataStoresSet: Set<string> = new Set();
676
- for (const route of tombstonedRoutes) {
677
- const pathParts = route.split("/");
678
- // Tombstone data store only if its route (/datastoreId) is directly in tombstoneRoutes.
679
- if (pathParts.length > 2) {
680
- continue;
681
- }
682
- const dataStoreId = pathParts[1];
683
- assert(this.contexts.has(dataStoreId), 0x510 /* No data store with specified id */);
684
- tombstonedDataStoresSet.add(dataStoreId);
685
- }
686
-
687
- // Update the used routes in each data store. Used routes is empty for unused data stores.
688
- for (const [contextId, context] of this.contexts) {
689
- context.setTombstone(tombstonedDataStoresSet.has(contextId));
690
- }
691
- }
692
-
693
- /**
694
- * Returns the outbound routes of this channel. Only root data stores are considered referenced and their paths are
695
- * part of outbound routes.
696
- */
697
- private async getOutboundRoutes(): Promise<string[]> {
698
- const outboundRoutes: string[] = [];
699
- for (const [contextId, context] of this.contexts) {
700
- const isRootDataStore = await context.isRoot();
701
- if (isRootDataStore) {
702
- outboundRoutes.push(`/${contextId}`);
703
- }
704
- }
705
- return outboundRoutes;
706
- }
707
-
708
- /**
709
- * Called by GC to retrieve the package path of a data store node with the given path.
710
- */
711
- public async getDataStorePackagePath(nodePath: string): Promise<readonly string[] | undefined> {
712
- // If the node belongs to a data store, return its package path. For DDSes, we return the package path of the
713
- // data store that contains it.
714
- const context = this.contexts.get(nodePath.split("/")[1]);
715
- return (await context?.getInitialSnapshotDetails())?.pkg;
716
- }
717
-
718
- /**
719
- * Called by GC to determine if a node is for a data store or for an object within a data store (for e.g. DDS).
720
- * @returns the GC node type if the node belongs to a data store or object within data store, undefined otherwise.
721
- */
722
- public getGCNodeType(nodePath: string): GCNodeType | undefined {
723
- const pathParts = nodePath.split("/");
724
- if (!this.contexts.has(pathParts[1])) {
725
- return undefined;
726
- }
727
-
728
- // Data stores paths are of the format "/dataStoreId".
729
- // Sub data store paths are of the format "/dataStoreId/subPath/...".
730
- if (pathParts.length === 2) {
731
- return GCNodeType.DataStore;
732
- }
733
- return GCNodeType.SubDataStore;
734
- }
85
+ // Stores tracked by the Domain
86
+ private readonly pendingAttach = new Map<string, IAttachMessage>();
87
+ // 0.24 back-compat attachingBeforeSummary
88
+ public readonly attachOpFiredForDataStore = new Set<string>();
89
+
90
+ private readonly mc: MonitoringContext;
91
+
92
+ private readonly disposeOnce = new Lazy<void>(() => this.contexts.dispose());
93
+
94
+ public readonly containerLoadStats: {
95
+ // number of dataStores during loadContainer
96
+ readonly containerLoadDataStoreCount: number;
97
+ // number of unreferenced dataStores during loadContainer
98
+ readonly referencedDataStoreCount: number;
99
+ };
100
+
101
+ // Stores the ids of new data stores between two GC runs. This is used to notify the garbage collector of new
102
+ // root data stores that are added.
103
+ private dataStoresSinceLastGC: string[] = [];
104
+ /** If true, throw an error when a tombstone data store is retrieved. */
105
+ private readonly throwOnTombstoneLoad: boolean;
106
+ // The handle to the container runtime. This is used mainly for GC purposes to represent outbound reference from
107
+ // the container runtime to other nodes.
108
+ private readonly containerRuntimeHandle: IFluidHandle;
109
+ private readonly pendingAliasMap: Map<string, Promise<AliasResult>> = new Map<
110
+ string,
111
+ Promise<AliasResult>
112
+ >();
113
+
114
+ constructor(
115
+ private readonly baseSnapshot: ISnapshotTree | undefined,
116
+ private readonly runtime: ContainerRuntime,
117
+ private readonly submitAttachFn: (attachContent: any) => void,
118
+ private readonly getCreateChildSummarizerNodeFn: (
119
+ id: string,
120
+ createParam: CreateChildSummarizerNodeParam,
121
+ ) => CreateChildSummarizerNodeFn,
122
+ private readonly deleteChildSummarizerNodeFn: (id: string) => void,
123
+ baseLogger: ITelemetryBaseLogger,
124
+ private readonly gcNodeUpdated: (
125
+ nodePath: string,
126
+ timestampMs: number,
127
+ packagePath?: readonly string[],
128
+ ) => void,
129
+ private readonly isDataStoreDeleted: (nodePath: string) => boolean,
130
+ private readonly aliasMap: Map<string, string>,
131
+ private readonly contexts: DataStoreContexts = new DataStoreContexts(baseLogger),
132
+ ) {
133
+ this.mc = loggerToMonitoringContext(ChildLogger.create(baseLogger));
134
+ this.containerRuntimeHandle = new FluidObjectHandle(
135
+ this.runtime,
136
+ "/",
137
+ this.runtime.IFluidHandleContext,
138
+ );
139
+
140
+ // Tombstone should only throw when the feature flag is enabled and the client isn't a summarizer
141
+ this.throwOnTombstoneLoad =
142
+ this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
143
+ this.runtime.gcTombstoneEnforcementAllowed &&
144
+ this.runtime.clientDetails.type !== summarizerClientType;
145
+
146
+ // Extract stores stored inside the snapshot
147
+ const fluidDataStores = new Map<string, ISnapshotTree>();
148
+ if (baseSnapshot) {
149
+ for (const [key, value] of Object.entries(baseSnapshot.trees)) {
150
+ fluidDataStores.set(key, value);
151
+ }
152
+ }
153
+
154
+ let unreferencedDataStoreCount = 0;
155
+ // Create a context for each of them
156
+ for (const [key, value] of fluidDataStores) {
157
+ let dataStoreContext: FluidDataStoreContext;
158
+
159
+ // counting number of unreferenced data stores
160
+ if (value.unreferenced) {
161
+ unreferencedDataStoreCount++;
162
+ }
163
+ // If we have a detached container, then create local data store contexts.
164
+ if (this.runtime.attachState !== AttachState.Detached) {
165
+ dataStoreContext = new RemoteFluidDataStoreContext({
166
+ id: key,
167
+ snapshotTree: value,
168
+ runtime: this.runtime,
169
+ storage: this.runtime.storage,
170
+ scope: this.runtime.scope,
171
+ createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(key, {
172
+ type: CreateSummarizerNodeSource.FromSummary,
173
+ }),
174
+ });
175
+ } else {
176
+ if (typeof value !== "object") {
177
+ throw new LoggingError("Snapshot should be there to load from!!");
178
+ }
179
+ const snapshotTree = value;
180
+ dataStoreContext = new LocalFluidDataStoreContext({
181
+ id: key,
182
+ pkg: undefined,
183
+ runtime: this.runtime,
184
+ storage: this.runtime.storage,
185
+ scope: this.runtime.scope,
186
+ createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(key, {
187
+ type: CreateSummarizerNodeSource.FromSummary,
188
+ }),
189
+ makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(key),
190
+ snapshotTree,
191
+ isRootDataStore: undefined,
192
+ });
193
+ }
194
+ this.contexts.addBoundOrRemoted(dataStoreContext);
195
+ }
196
+ this.containerLoadStats = {
197
+ containerLoadDataStoreCount: fluidDataStores.size,
198
+ referencedDataStoreCount: fluidDataStores.size - unreferencedDataStoreCount,
199
+ };
200
+ }
201
+
202
+ public get aliases(): ReadonlyMap<string, string> {
203
+ return this.aliasMap;
204
+ }
205
+
206
+ public get pendingAliases(): Map<string, Promise<AliasResult>> {
207
+ return this.pendingAliasMap;
208
+ }
209
+
210
+ public async waitIfPendingAlias(maybeAlias: string): Promise<AliasResult> {
211
+ const pendingAliasPromise = this.pendingAliases.get(maybeAlias);
212
+ return pendingAliasPromise === undefined ? "Success" : pendingAliasPromise;
213
+ }
214
+
215
+ public processAttachMessage(message: ISequencedDocumentMessage, local: boolean) {
216
+ const attachMessage = message.contents as InboundAttachMessage;
217
+
218
+ this.dataStoresSinceLastGC.push(attachMessage.id);
219
+
220
+ // The local object has already been attached
221
+ if (local) {
222
+ assert(
223
+ this.pendingAttach.has(attachMessage.id),
224
+ 0x15e /* "Local object does not have matching attach message id" */,
225
+ );
226
+ this.contexts.get(attachMessage.id)?.emit("attached");
227
+ this.pendingAttach.delete(attachMessage.id);
228
+ return;
229
+ }
230
+
231
+ // If a non-local operation then go and create the object, otherwise mark it as officially attached.
232
+ if (this.alreadyProcessed(attachMessage.id)) {
233
+ // TODO: dataStoreId may require a different tag from PackageData #7488
234
+ const error = new DataCorruptionError(
235
+ // pre-0.58 error message: duplicateDataStoreCreatedWithExistingId
236
+ "Duplicate DataStore created with existing id",
237
+ {
238
+ ...extractSafePropertiesFromMessage(message),
239
+ dataStoreId: {
240
+ value: attachMessage.id,
241
+ tag: TelemetryDataTag.CodeArtifact,
242
+ },
243
+ },
244
+ );
245
+ throw error;
246
+ }
247
+
248
+ const flatBlobs = new Map<string, ArrayBufferLike>();
249
+ let snapshotTree: ISnapshotTree | undefined;
250
+ if (attachMessage.snapshot) {
251
+ snapshotTree = buildSnapshotTree(attachMessage.snapshot.entries, flatBlobs);
252
+ }
253
+
254
+ // Include the type of attach message which is the pkg of the store to be
255
+ // used by RemoteFluidDataStoreContext in case it is not in the snapshot.
256
+ const pkg = [attachMessage.type];
257
+ const remoteFluidDataStoreContext = new RemoteFluidDataStoreContext({
258
+ id: attachMessage.id,
259
+ snapshotTree,
260
+ runtime: this.runtime,
261
+ storage: new BlobCacheStorageService(this.runtime.storage, flatBlobs),
262
+ scope: this.runtime.scope,
263
+ createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(attachMessage.id, {
264
+ type: CreateSummarizerNodeSource.FromAttach,
265
+ sequenceNumber: message.sequenceNumber,
266
+ snapshot: attachMessage.snapshot ?? {
267
+ entries: [createAttributesBlob(pkg, true /* isRootDataStore */)],
268
+ },
269
+ }),
270
+ pkg,
271
+ });
272
+
273
+ this.contexts.addBoundOrRemoted(remoteFluidDataStoreContext);
274
+ }
275
+
276
+ public processAliasMessage(
277
+ message: ISequencedDocumentMessage,
278
+ localOpMetadata: unknown,
279
+ local: boolean,
280
+ ): void {
281
+ const aliasMessage = message.contents as IDataStoreAliasMessage;
282
+ if (!isDataStoreAliasMessage(aliasMessage)) {
283
+ throw new DataCorruptionError("malformedDataStoreAliasMessage", {
284
+ ...extractSafePropertiesFromMessage(message),
285
+ });
286
+ }
287
+
288
+ const resolve = localOpMetadata as PendingAliasResolve;
289
+ const aliasResult = this.processAliasMessageCore(aliasMessage);
290
+ if (local) {
291
+ resolve(aliasResult);
292
+ }
293
+ }
294
+
295
+ public processAliasMessageCore(aliasMessage: IDataStoreAliasMessage): boolean {
296
+ if (this.alreadyProcessed(aliasMessage.alias)) {
297
+ return false;
298
+ }
299
+
300
+ const context = this.contexts.get(aliasMessage.internalId);
301
+ if (context === undefined) {
302
+ this.mc.logger.sendErrorEvent({
303
+ eventName: "AliasFluidDataStoreNotFound",
304
+ fluidDataStoreId: aliasMessage.internalId,
305
+ });
306
+ return false;
307
+ }
308
+
309
+ const handle = new FluidObjectHandle(
310
+ context,
311
+ aliasMessage.internalId,
312
+ this.runtime.IFluidHandleContext,
313
+ );
314
+ this.runtime.addedGCOutboundReference(this.containerRuntimeHandle, handle);
315
+
316
+ this.aliasMap.set(aliasMessage.alias, context.id);
317
+ context.setInMemoryRoot();
318
+ return true;
319
+ }
320
+
321
+ private alreadyProcessed(id: string): boolean {
322
+ return this.aliasMap.get(id) !== undefined || this.contexts.get(id) !== undefined;
323
+ }
324
+
325
+ /**
326
+ * Make the data stores locally visible in the container graph by moving the data store context from unbound to
327
+ * bound list. This data store can now be reached from the root.
328
+ * @param id - The id of the data store context to make visible.
329
+ */
330
+ private makeDataStoreLocallyVisible(id: string): void {
331
+ const localContext = this.contexts.getUnbound(id);
332
+ assert(!!localContext, 0x15f /* "Could not find unbound context to bind" */);
333
+
334
+ /**
335
+ * If the container is not detached, it is globally visible to all clients. This data store should also be
336
+ * globally visible. Move it to attaching state and send an "attach" op for it.
337
+ * If the container is detached, this data store will be part of the summary that makes the container attached.
338
+ */
339
+ if (this.runtime.attachState !== AttachState.Detached) {
340
+ localContext.emit("attaching");
341
+ const message = localContext.generateAttachMessage();
342
+
343
+ this.pendingAttach.set(id, message);
344
+ this.submitAttachFn(message);
345
+ this.attachOpFiredForDataStore.add(id);
346
+ }
347
+
348
+ this.contexts.bind(id);
349
+ }
350
+
351
+ public createDetachedDataStoreCore(
352
+ pkg: Readonly<string[]>,
353
+ isRoot: boolean,
354
+ id = uuid(),
355
+ ): IFluidDataStoreContextDetached {
356
+ assert(!id.includes("/"), 0x30c /* Id cannot contain slashes */);
357
+
358
+ const context = new LocalDetachedFluidDataStoreContext({
359
+ id,
360
+ pkg,
361
+ runtime: this.runtime,
362
+ storage: this.runtime.storage,
363
+ scope: this.runtime.scope,
364
+ createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(id, {
365
+ type: CreateSummarizerNodeSource.Local,
366
+ }),
367
+ makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(id),
368
+ snapshotTree: undefined,
369
+ isRootDataStore: isRoot,
370
+ });
371
+ this.contexts.addUnbound(context);
372
+ return context;
373
+ }
374
+
375
+ public _createFluidDataStoreContext(pkg: string[], id: string, props?: any) {
376
+ assert(!id.includes("/"), 0x30d /* Id cannot contain slashes */);
377
+ const context = new LocalFluidDataStoreContext({
378
+ id,
379
+ pkg,
380
+ runtime: this.runtime,
381
+ storage: this.runtime.storage,
382
+ scope: this.runtime.scope,
383
+ createSummarizerNodeFn: this.getCreateChildSummarizerNodeFn(id, {
384
+ type: CreateSummarizerNodeSource.Local,
385
+ }),
386
+ makeLocallyVisibleFn: () => this.makeDataStoreLocallyVisible(id),
387
+ snapshotTree: undefined,
388
+ isRootDataStore: false,
389
+ createProps: props,
390
+ });
391
+ this.contexts.addUnbound(context);
392
+ return context;
393
+ }
394
+
395
+ public get disposed() {
396
+ return this.disposeOnce.evaluated;
397
+ }
398
+ public readonly dispose = () => this.disposeOnce.value;
399
+
400
+ public resubmitDataStoreOp(content: any, localOpMetadata: unknown) {
401
+ const envelope = content as IEnvelope;
402
+ const context = this.contexts.get(envelope.address);
403
+ assert(!!context, 0x160 /* "There should be a store context for the op" */);
404
+ context.reSubmit(envelope.contents, localOpMetadata);
405
+ }
406
+
407
+ public rollbackDataStoreOp(content: any, localOpMetadata: unknown) {
408
+ const envelope = content as IEnvelope;
409
+ const context = this.contexts.get(envelope.address);
410
+ assert(!!context, 0x2e8 /* "There should be a store context for the op" */);
411
+ context.rollback(envelope.contents, localOpMetadata);
412
+ }
413
+
414
+ public async applyStashedOp(content: any): Promise<unknown> {
415
+ const envelope = content as IEnvelope;
416
+ const context = this.contexts.get(envelope.address);
417
+ assert(!!context, 0x161 /* "There should be a store context for the op" */);
418
+ return context.applyStashedOp(envelope.contents);
419
+ }
420
+
421
+ public async applyStashedAttachOp(message: IAttachMessage) {
422
+ this.pendingAttach.set(message.id, message);
423
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
424
+ this.processAttachMessage({ contents: message } as ISequencedDocumentMessage, false);
425
+ }
426
+
427
+ public processFluidDataStoreOp(
428
+ message: ISequencedDocumentMessage,
429
+ local: boolean,
430
+ localMessageMetadata: unknown,
431
+ ) {
432
+ const envelope = message.contents as IEnvelope;
433
+ const transformed = { ...message, contents: envelope.contents };
434
+ const request = { url: envelope.address };
435
+ this.validateNotDeleted(envelope.address, request);
436
+ const context = this.contexts.get(envelope.address);
437
+ assert(!!context, 0x162 /* "There should be a store context for the op" */);
438
+ context.process(transformed, local, localMessageMetadata);
439
+
440
+ // Notify that a GC node for the data store changed. This is used to detect if a deleted data store is
441
+ // being used.
442
+ this.gcNodeUpdated(
443
+ `/${envelope.address}`,
444
+ message.timestamp,
445
+ context.isLoaded ? context.packagePath : undefined,
446
+ );
447
+ }
448
+
449
+ public async getDataStore(
450
+ id: string,
451
+ requestHeaderData: RuntimeHeaderData,
452
+ ): Promise<FluidDataStoreContext> {
453
+ const headerData = { ...defaultRuntimeHeaderData, ...requestHeaderData };
454
+ const request = { url: id };
455
+
456
+ this.validateNotDeleted(id, request, headerData);
457
+
458
+ const context = await this.contexts.getBoundOrRemoted(id, headerData.wait);
459
+ if (context === undefined) {
460
+ // The requested data store does not exits. Throw a 404 response exception.
461
+ throw responseToException(create404Response(request), request);
462
+ }
463
+
464
+ this.validateNotTombstoned(context, request, requestHeaderData);
465
+
466
+ return context;
467
+ }
468
+
469
+ /**
470
+ * Validate that the data store had not been deleted by GC.
471
+ *
472
+ * @param id - data store id
473
+ * @param request - the request information to log if the validation detects the data store has been deleted
474
+ * @param requestHeaderData - the request header information to log if the validation detects the data store has been deleted
475
+ */
476
+ private validateNotDeleted(
477
+ id: string,
478
+ request: IRequest,
479
+ requestHeaderData?: RuntimeHeaderData,
480
+ ) {
481
+ const dataStoreNodePath = `/${id}`;
482
+ if (this.isDataStoreDeleted(dataStoreNodePath)) {
483
+ assert(
484
+ !this.contexts.has(id),
485
+ 0x570 /* Inconsistent state! GC says the data store is deleted, but the data store is not deleted from the runtime. */,
486
+ );
487
+ // The requested data store is removed by gc. Create a 404 gc response exception.
488
+ const error = responseToException(
489
+ createResponseError(404, "DataStore was deleted", request),
490
+ request,
491
+ );
492
+ sendGCUnexpectedUsageEvent(
493
+ this.mc,
494
+ {
495
+ eventName: "GC_Deleted_DataStore_Requested",
496
+ category: "error",
497
+ isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
498
+ headers: JSON.stringify(requestHeaderData),
499
+ gcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,
500
+ },
501
+ undefined /** packagePath */,
502
+ error,
503
+ );
504
+ throw error;
505
+ }
506
+ }
507
+
508
+ /**
509
+ * Validates that the data store context requested has not been marked as tombstone by GC.
510
+ *
511
+ * @param context - the data store context in question
512
+ * @param request - the request information to log if the validation detects the data store has been tombstoned
513
+ * @param headerData - the request header information to log if the validation detects the data store has been tombstoned
514
+ */
515
+ private validateNotTombstoned(
516
+ context: FluidDataStoreContext,
517
+ request: IRequest,
518
+ headerData: RuntimeHeaderData,
519
+ ) {
520
+ if (context.tombstoned) {
521
+ const shouldFail = this.throwOnTombstoneLoad && !headerData.allowTombstone;
522
+
523
+ // The requested data store is removed by gc. Create a 404 gc response exception.
524
+ const error = responseToException(
525
+ createResponseError(404, "DataStore was deleted", request, {
526
+ [TombstoneResponseHeaderKey]: true,
527
+ }),
528
+ request,
529
+ );
530
+ sendGCUnexpectedUsageEvent(
531
+ this.mc,
532
+ {
533
+ eventName: "GC_Tombstone_DataStore_Requested",
534
+ category: shouldFail ? "error" : "generic",
535
+ isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
536
+ headers: JSON.stringify(headerData),
537
+ gcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,
538
+ },
539
+ context.isLoaded ? context.packagePath : undefined,
540
+ error,
541
+ );
542
+
543
+ if (shouldFail) {
544
+ throw error;
545
+ }
546
+ }
547
+ }
548
+
549
+ public processSignal(address: string, message: IInboundSignalMessage, local: boolean) {
550
+ const request = { url: address };
551
+ this.validateNotDeleted(address, request);
552
+ const context = this.contexts.get(address);
553
+ if (!context) {
554
+ // Attach message may not have been processed yet
555
+ assert(!local, 0x163 /* "Missing datastore for local signal" */);
556
+ this.mc.logger.sendTelemetryEvent({
557
+ eventName: "SignalFluidDataStoreNotFound",
558
+ fluidDataStoreId: {
559
+ value: address,
560
+ tag: TelemetryDataTag.CodeArtifact,
561
+ },
562
+ });
563
+ return;
564
+ }
565
+
566
+ context.processSignal(message, local);
567
+ }
568
+
569
+ public setConnectionState(connected: boolean, clientId?: string) {
570
+ for (const [fluidDataStore, context] of this.contexts) {
571
+ try {
572
+ context.setConnectionState(connected, clientId);
573
+ } catch (error) {
574
+ this.mc.logger.sendErrorEvent(
575
+ {
576
+ eventName: "SetConnectionStateError",
577
+ clientId,
578
+ fluidDataStore,
579
+ },
580
+ error,
581
+ );
582
+ }
583
+ }
584
+ }
585
+
586
+ public setAttachState(attachState: AttachState.Attaching | AttachState.Attached): void {
587
+ const eventName = attachState === AttachState.Attaching ? "attaching" : "attached";
588
+ for (const [, context] of this.contexts) {
589
+ // Fire only for bounded stores.
590
+ if (!this.contexts.isNotBound(context.id)) {
591
+ context.emit(eventName);
592
+ }
593
+ }
594
+ }
595
+
596
+ public get size(): number {
597
+ return this.contexts.size;
598
+ }
599
+
600
+ public async summarize(
601
+ fullTree: boolean,
602
+ trackState: boolean,
603
+ telemetryContext?: ITelemetryContext,
604
+ ): Promise<ISummaryTreeWithStats> {
605
+ const summaryBuilder = new SummaryTreeBuilder();
606
+
607
+ // Iterate over each store and ask it to snapshot
608
+ await Promise.all(
609
+ Array.from(this.contexts)
610
+ .filter(([_, context]) => {
611
+ // Summarizer works only with clients with no local changes. A data store in attaching
612
+ // state indicates an op was sent to attach a local data store.
613
+ assert(
614
+ context.attachState !== AttachState.Attaching,
615
+ 0x588 /* Local data store detected in attaching state during summarize */,
616
+ );
617
+ return context.attachState === AttachState.Attached;
618
+ })
619
+ .map(async ([contextId, context]) => {
620
+ const contextSummary = await context.summarize(
621
+ fullTree,
622
+ trackState,
623
+ telemetryContext,
624
+ );
625
+ summaryBuilder.addWithStats(contextId, contextSummary);
626
+ }),
627
+ );
628
+
629
+ return summaryBuilder.getSummaryTree();
630
+ }
631
+
632
+ public createSummary(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {
633
+ const builder = new SummaryTreeBuilder();
634
+ // Attaching graph of some stores can cause other stores to get bound too.
635
+ // So keep taking summary until no new stores get bound.
636
+ let notBoundContextsLength: number;
637
+ do {
638
+ const builderTree = builder.summary.tree;
639
+ notBoundContextsLength = this.contexts.notBoundLength();
640
+ // Iterate over each data store and ask it to snapshot
641
+ Array.from(this.contexts)
642
+ .filter(
643
+ ([key, _]) =>
644
+ // Take summary of bounded data stores only, make sure we haven't summarized them already
645
+ // and no attach op has been fired for that data store because for loader versions <= 0.24
646
+ // we set attach state as "attaching" before taking createNew summary.
647
+ !(
648
+ this.contexts.isNotBound(key) ||
649
+ builderTree[key] ||
650
+ this.attachOpFiredForDataStore.has(key)
651
+ ),
652
+ )
653
+ .map(([key, value]) => {
654
+ let dataStoreSummary: ISummarizeResult;
655
+ if (value.isLoaded) {
656
+ const snapshot = value.generateAttachMessage().snapshot;
657
+ dataStoreSummary = convertToSummaryTree(snapshot, true);
658
+ } else {
659
+ // If this data store is not yet loaded, then there should be no changes in the snapshot from
660
+ // which it was created as it is detached container. So just use the previous snapshot.
661
+ assert(
662
+ !!this.baseSnapshot,
663
+ 0x166 /* "BaseSnapshot should be there as detached container loaded from snapshot" */,
664
+ );
665
+ dataStoreSummary = convertSnapshotTreeToSummaryTree(
666
+ this.baseSnapshot.trees[key],
667
+ );
668
+ }
669
+ builder.addWithStats(key, dataStoreSummary);
670
+ });
671
+ } while (notBoundContextsLength !== this.contexts.notBoundLength());
672
+
673
+ return builder.getSummaryTree();
674
+ }
675
+
676
+ /**
677
+ * Before GC runs, called by the garbage collector to update any pending GC state.
678
+ * The garbage collector needs to know all outbound references that are added. Since root data stores are not
679
+ * explicitly marked as referenced, notify GC of new root data stores that were added since the last GC run.
680
+ */
681
+ public async updateStateBeforeGC(): Promise<void> {
682
+ for (const id of this.dataStoresSinceLastGC) {
683
+ const context = this.contexts.get(id);
684
+ assert(context !== undefined, 0x2b6 /* Missing data store context */);
685
+ if (await context.isRoot()) {
686
+ // A root data store is basically a reference from the container runtime to the data store.
687
+ const handle = new FluidObjectHandle(context, id, this.runtime.IFluidHandleContext);
688
+ this.runtime.addedGCOutboundReference(this.containerRuntimeHandle, handle);
689
+ }
690
+ }
691
+ this.dataStoresSinceLastGC = [];
692
+ }
693
+
694
+ /**
695
+ * Generates data used for garbage collection. It does the following:
696
+ *
697
+ * 1. Calls into each child data store context to get its GC data.
698
+ *
699
+ * 2. Prefixes the child context's id to the GC nodes in the child's GC data. This makes sure that the node can be
700
+ * identified as belonging to the child.
701
+ *
702
+ * 3. Adds a GC node for this channel to the nodes received from the children. All these nodes together represent
703
+ * the GC data of this channel.
704
+ *
705
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
706
+ */
707
+ public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
708
+ const builder = new GCDataBuilder();
709
+ // Iterate over each store and get their GC data.
710
+ await Promise.all(
711
+ Array.from(this.contexts)
712
+ .filter(([_, context]) => {
713
+ // Summarizer client and hence GC works only with clients with no local changes. A data store in
714
+ // attaching state indicates an op was sent to attach a local data store.
715
+ assert(
716
+ context.attachState !== AttachState.Attaching,
717
+ 0x589 /* Local data store detected in attaching state while running GC */,
718
+ );
719
+ return context.attachState === AttachState.Attached;
720
+ })
721
+ .map(async ([contextId, context]) => {
722
+ const contextGCData = await context.getGCData(fullGC);
723
+ // Prefix the child's id to the ids of its GC nodes so they can be identified as belonging to the child.
724
+ // This also gradually builds the id of each node to be a path from the root.
725
+ builder.prefixAndAddNodes(contextId, contextGCData.gcNodes);
726
+ }),
727
+ );
728
+
729
+ // Get the outbound routes and add a GC node for this channel.
730
+ builder.addNode("/", await this.getOutboundRoutes());
731
+ return builder.getGCData();
732
+ }
733
+
734
+ /**
735
+ * After GC has run, called to notify this Container's data stores of routes that are used in it.
736
+ * @param usedRoutes - The routes that are used in all data stores in this Container.
737
+ */
738
+ public updateUsedRoutes(usedRoutes: string[]) {
739
+ // Get a map of data store ids to routes used in it.
740
+ const usedDataStoreRoutes = unpackChildNodesUsedRoutes(usedRoutes);
741
+
742
+ // Verify that the used routes are correct.
743
+ for (const [id] of usedDataStoreRoutes) {
744
+ assert(
745
+ this.contexts.has(id),
746
+ 0x167 /* "Used route does not belong to any known data store" */,
747
+ );
748
+ }
749
+
750
+ // Update the used routes in each data store. Used routes is empty for unused data stores.
751
+ for (const [contextId, context] of this.contexts) {
752
+ context.updateUsedRoutes(usedDataStoreRoutes.get(contextId) ?? []);
753
+ }
754
+ }
755
+
756
+ /**
757
+ * This is called to update objects whose routes are unused. The unused objects are deleted.
758
+ * @param unusedRoutes - The routes that are unused in all data stores in this Container.
759
+ */
760
+ public updateUnusedRoutes(unusedRoutes: string[]) {
761
+ for (const route of unusedRoutes) {
762
+ const pathParts = route.split("/");
763
+ // Delete data store only if its route (/datastoreId) is in unusedRoutes. We don't want to delete a data
764
+ // store based on its DDS being unused.
765
+ if (pathParts.length > 2) {
766
+ continue;
767
+ }
768
+ const dataStoreId = pathParts[1];
769
+ assert(this.contexts.has(dataStoreId), 0x2d7 /* No data store with specified id */);
770
+ // Delete the contexts of unused data stores.
771
+ this.contexts.delete(dataStoreId);
772
+ // Delete the summarizer node of the unused data stores.
773
+ this.deleteChildSummarizerNodeFn(dataStoreId);
774
+ }
775
+ }
776
+
777
+ /**
778
+ * Delete data stores and its objects that are sweep ready.
779
+ * @param sweepReadyDataStoreRoutes - The routes of data stores and its objects that are sweep ready and should
780
+ * be deleted.
781
+ * @returns - The routes of data stores and its objects that were deleted.
782
+ */
783
+ public deleteSweepReadyNodes(sweepReadyDataStoreRoutes: string[]): string[] {
784
+ // If sweep for data stores is not enabled, return empty list indicating nothing is deleted.
785
+ if (this.mc.config.getBoolean(sweepDatastoresKey) !== true) {
786
+ return [];
787
+ }
788
+ for (const route of sweepReadyDataStoreRoutes) {
789
+ const pathParts = route.split("/");
790
+ const dataStoreId = pathParts[1];
791
+
792
+ // TODO: GC:Validation - Skip any routes already deleted
793
+ // Ignore sub-data store routes because a data store and its sub-routes are deleted together, so, we only
794
+ // need to delete the data store.
795
+ if (pathParts.length > 2) {
796
+ continue;
797
+ }
798
+
799
+ if (!this.contexts.has(dataStoreId)) {
800
+ this.mc.logger.sendErrorEvent({
801
+ eventName: "DeletedDataStoreNotFound",
802
+ dataStoreId,
803
+ });
804
+ }
805
+
806
+ const dataStore = this.contexts.get(dataStoreId);
807
+ assert(dataStore !== undefined, 0x571 /* Attempting to delete unknown dataStore */);
808
+ dataStore.delete();
809
+
810
+ // Delete the contexts of sweep ready data stores.
811
+ this.contexts.delete(dataStoreId);
812
+ // Delete the summarizer node of the sweep ready data stores.
813
+ this.deleteChildSummarizerNodeFn(dataStoreId);
814
+ }
815
+ return Array.from(sweepReadyDataStoreRoutes);
816
+ }
817
+
818
+ /**
819
+ * This is called to update objects whose routes are tombstones. Tombstoned datastore contexts enable testing
820
+ * scenarios with accessing deleted content without actually deleting content from summaries.
821
+ * @param tombstonedRoutes - The routes that are tombstones in all data stores in this Container.
822
+ */
823
+ public updateTombstonedRoutes(tombstonedRoutes: string[]) {
824
+ const tombstonedDataStoresSet: Set<string> = new Set();
825
+ for (const route of tombstonedRoutes) {
826
+ const pathParts = route.split("/");
827
+ // Tombstone data store only if its route (/datastoreId) is directly in tombstoneRoutes.
828
+ if (pathParts.length > 2) {
829
+ continue;
830
+ }
831
+ const dataStoreId = pathParts[1];
832
+ assert(this.contexts.has(dataStoreId), 0x510 /* No data store with specified id */);
833
+ tombstonedDataStoresSet.add(dataStoreId);
834
+ }
835
+
836
+ // Update the used routes in each data store. Used routes is empty for unused data stores.
837
+ for (const [contextId, context] of this.contexts) {
838
+ context.setTombstone(tombstonedDataStoresSet.has(contextId));
839
+ }
840
+ }
841
+
842
+ /**
843
+ * Returns the outbound routes of this channel. Only root data stores are considered referenced and their paths are
844
+ * part of outbound routes.
845
+ */
846
+ private async getOutboundRoutes(): Promise<string[]> {
847
+ const outboundRoutes: string[] = [];
848
+ for (const [contextId, context] of this.contexts) {
849
+ const isRootDataStore = await context.isRoot();
850
+ if (isRootDataStore) {
851
+ outboundRoutes.push(`/${contextId}`);
852
+ }
853
+ }
854
+ return outboundRoutes;
855
+ }
856
+
857
+ /**
858
+ * Called by GC to retrieve the package path of a data store node with the given path.
859
+ */
860
+ public async getDataStorePackagePath(nodePath: string): Promise<readonly string[] | undefined> {
861
+ // If the node belongs to a data store, return its package path. For DDSes, we return the package path of the
862
+ // data store that contains it.
863
+ const context = this.contexts.get(nodePath.split("/")[1]);
864
+ return (await context?.getInitialSnapshotDetails())?.pkg;
865
+ }
866
+
867
+ /**
868
+ * Called by GC to determine if a node is for a data store or for an object within a data store (for e.g. DDS).
869
+ * @returns the GC node type if the node belongs to a data store or object within data store, undefined otherwise.
870
+ */
871
+ public getGCNodeType(nodePath: string): GCNodeType | undefined {
872
+ const pathParts = nodePath.split("/");
873
+ if (!this.contexts.has(pathParts[1])) {
874
+ return undefined;
875
+ }
876
+
877
+ // Data stores paths are of the format "/dataStoreId".
878
+ // Sub data store paths are of the format "/dataStoreId/subPath/...".
879
+ if (pathParts.length === 2) {
880
+ return GCNodeType.DataStore;
881
+ }
882
+ return GCNodeType.SubDataStore;
883
+ }
735
884
  }
736
885
 
737
886
  export function getSummaryForDatastores(
738
- snapshot: ISnapshotTree | undefined,
739
- metadata?: IContainerRuntimeMetadata,
887
+ snapshot: ISnapshotTree | undefined,
888
+ metadata?: IContainerRuntimeMetadata,
740
889
  ): ISnapshotTree | undefined {
741
- if (!snapshot) {
742
- return undefined;
743
- }
744
-
745
- if (rootHasIsolatedChannels(metadata)) {
746
- const datastoresSnapshot = snapshot.trees[channelsTreeName];
747
- assert(!!datastoresSnapshot, 0x168 /* Expected tree in snapshot not found */);
748
- return datastoresSnapshot;
749
- } else {
750
- // back-compat: strip out all non-datastore paths before giving to DataStores object.
751
- const datastoresTrees: ISnapshotTree["trees"] = {};
752
- for (const [key, value] of Object.entries(snapshot.trees)) {
753
- if (!nonDataStorePaths.includes(key)) {
754
- datastoresTrees[key] = value;
755
- }
756
- }
757
- return {
758
- ...snapshot,
759
- trees: datastoresTrees,
760
- };
761
- }
890
+ if (!snapshot) {
891
+ return undefined;
892
+ }
893
+
894
+ if (rootHasIsolatedChannels(metadata)) {
895
+ const datastoresSnapshot = snapshot.trees[channelsTreeName];
896
+ assert(!!datastoresSnapshot, 0x168 /* Expected tree in snapshot not found */);
897
+ return datastoresSnapshot;
898
+ } else {
899
+ // back-compat: strip out all non-datastore paths before giving to DataStores object.
900
+ const datastoresTrees: ISnapshotTree["trees"] = {};
901
+ for (const [key, value] of Object.entries(snapshot.trees)) {
902
+ if (!nonDataStorePaths.includes(key)) {
903
+ datastoresTrees[key] = value;
904
+ }
905
+ }
906
+ return {
907
+ ...snapshot,
908
+ trees: datastoresTrees,
909
+ };
910
+ }
762
911
  }