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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (563) hide show
  1. package/.eslintrc.js +21 -10
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/batchTracker.d.ts +1 -2
  5. package/dist/batchTracker.d.ts.map +1 -1
  6. package/dist/batchTracker.js +2 -1
  7. package/dist/batchTracker.js.map +1 -1
  8. package/dist/blobManager.d.ts +74 -42
  9. package/dist/blobManager.d.ts.map +1 -1
  10. package/dist/blobManager.js +321 -152
  11. package/dist/blobManager.js.map +1 -1
  12. package/dist/connectionTelemetry.d.ts.map +1 -1
  13. package/dist/connectionTelemetry.js +11 -9
  14. package/dist/connectionTelemetry.js.map +1 -1
  15. package/dist/containerHandleContext.d.ts.map +1 -1
  16. package/dist/containerHandleContext.js +3 -1
  17. package/dist/containerHandleContext.js.map +1 -1
  18. package/dist/containerRuntime.d.ts +148 -114
  19. package/dist/containerRuntime.d.ts.map +1 -1
  20. package/dist/containerRuntime.js +534 -342
  21. package/dist/containerRuntime.js.map +1 -1
  22. package/dist/dataStore.d.ts.map +1 -1
  23. package/dist/dataStore.js +11 -9
  24. package/dist/dataStore.js.map +1 -1
  25. package/dist/dataStoreContext.d.ts +40 -13
  26. package/dist/dataStoreContext.d.ts.map +1 -1
  27. package/dist/dataStoreContext.js +146 -66
  28. package/dist/dataStoreContext.js.map +1 -1
  29. package/dist/dataStoreContexts.d.ts.map +1 -1
  30. package/dist/dataStoreContexts.js +7 -3
  31. package/dist/dataStoreContexts.js.map +1 -1
  32. package/dist/dataStoreRegistry.d.ts.map +1 -1
  33. package/dist/dataStoreRegistry.js +3 -1
  34. package/dist/dataStoreRegistry.js.map +1 -1
  35. package/dist/dataStores.d.ts +39 -12
  36. package/dist/dataStores.d.ts.map +1 -1
  37. package/dist/dataStores.js +164 -76
  38. package/dist/dataStores.js.map +1 -1
  39. package/dist/deltaManagerSummarizerProxy.d.ts +19 -0
  40. package/dist/deltaManagerSummarizerProxy.d.ts.map +1 -0
  41. package/dist/deltaManagerSummarizerProxy.js +40 -0
  42. package/dist/deltaManagerSummarizerProxy.js.map +1 -0
  43. package/dist/deltaScheduler.d.ts.map +1 -1
  44. package/dist/deltaScheduler.js +8 -3
  45. package/dist/deltaScheduler.js.map +1 -1
  46. package/dist/gc/garbageCollection.d.ts +204 -0
  47. package/dist/gc/garbageCollection.d.ts.map +1 -0
  48. package/dist/gc/garbageCollection.js +926 -0
  49. package/dist/gc/garbageCollection.js.map +1 -0
  50. package/dist/gc/gcConfigs.d.ts +22 -0
  51. package/dist/gc/gcConfigs.d.ts.map +1 -0
  52. package/dist/gc/gcConfigs.js +143 -0
  53. package/dist/gc/gcConfigs.js.map +1 -0
  54. package/dist/gc/gcDefinitions.d.ts +320 -0
  55. package/dist/gc/gcDefinitions.d.ts.map +1 -0
  56. package/dist/gc/gcDefinitions.js +81 -0
  57. package/dist/gc/gcDefinitions.js.map +1 -0
  58. package/dist/gc/gcHelpers.d.ts +86 -0
  59. package/dist/gc/gcHelpers.d.ts.map +1 -0
  60. package/dist/gc/gcHelpers.js +268 -0
  61. package/dist/gc/gcHelpers.js.map +1 -0
  62. package/dist/gc/gcReferenceGraphAlgorithm.d.ts +16 -0
  63. package/dist/gc/gcReferenceGraphAlgorithm.d.ts.map +1 -0
  64. package/dist/gc/gcReferenceGraphAlgorithm.js +49 -0
  65. package/dist/gc/gcReferenceGraphAlgorithm.js.map +1 -0
  66. package/dist/gc/gcSummaryDefinitions.d.ts +52 -0
  67. package/dist/gc/gcSummaryDefinitions.d.ts.map +1 -0
  68. package/dist/gc/gcSummaryDefinitions.js +7 -0
  69. package/dist/gc/gcSummaryDefinitions.js.map +1 -0
  70. package/dist/gc/gcSummaryStateTracker.d.ts +93 -0
  71. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -0
  72. package/dist/gc/gcSummaryStateTracker.js +239 -0
  73. package/dist/gc/gcSummaryStateTracker.js.map +1 -0
  74. package/{lib → dist/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  75. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  76. package/dist/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  77. package/dist/gc/gcSweepReadyUsageDetection.js.map +1 -0
  78. package/dist/gc/gcUnreferencedStateTracker.d.ts +34 -0
  79. package/dist/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  80. package/dist/gc/gcUnreferencedStateTracker.js +94 -0
  81. package/dist/gc/gcUnreferencedStateTracker.js.map +1 -0
  82. package/dist/gc/index.d.ts +13 -0
  83. package/dist/gc/index.d.ts.map +1 -0
  84. package/dist/gc/index.js +50 -0
  85. package/dist/gc/index.js.map +1 -0
  86. package/dist/index.d.ts +3 -8
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +7 -13
  89. package/dist/index.js.map +1 -1
  90. package/dist/opLifecycle/batchManager.d.ts +10 -0
  91. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  92. package/dist/opLifecycle/batchManager.js +37 -8
  93. package/dist/opLifecycle/batchManager.js.map +1 -1
  94. package/dist/opLifecycle/definitions.d.ts +29 -1
  95. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  96. package/dist/opLifecycle/definitions.js.map +1 -1
  97. package/dist/opLifecycle/index.d.ts +3 -3
  98. package/dist/opLifecycle/index.d.ts.map +1 -1
  99. package/dist/opLifecycle/index.js +3 -1
  100. package/dist/opLifecycle/index.js.map +1 -1
  101. package/dist/opLifecycle/opCompressor.d.ts +1 -1
  102. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  103. package/dist/opLifecycle/opCompressor.js +46 -17
  104. package/dist/opLifecycle/opCompressor.js.map +1 -1
  105. package/dist/opLifecycle/opDecompressor.d.ts +6 -1
  106. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  107. package/dist/opLifecycle/opDecompressor.js +72 -18
  108. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  109. package/dist/opLifecycle/opSplitter.d.ts +46 -2
  110. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  111. package/dist/opLifecycle/opSplitter.js +142 -5
  112. package/dist/opLifecycle/opSplitter.js.map +1 -1
  113. package/dist/opLifecycle/outbox.d.ts +23 -2
  114. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  115. package/dist/opLifecycle/outbox.js +101 -51
  116. package/dist/opLifecycle/outbox.js.map +1 -1
  117. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  118. package/dist/opLifecycle/remoteMessageProcessor.js +17 -2
  119. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  120. package/dist/opProperties.d.ts.map +1 -1
  121. package/dist/opProperties.js +1 -3
  122. package/dist/opProperties.js.map +1 -1
  123. package/dist/packageVersion.d.ts +1 -1
  124. package/dist/packageVersion.js +1 -1
  125. package/dist/packageVersion.js.map +1 -1
  126. package/dist/pendingStateManager.d.ts +6 -15
  127. package/dist/pendingStateManager.d.ts.map +1 -1
  128. package/dist/pendingStateManager.js +137 -165
  129. package/dist/pendingStateManager.js.map +1 -1
  130. package/dist/scheduleManager.d.ts +0 -1
  131. package/dist/scheduleManager.d.ts.map +1 -1
  132. package/dist/scheduleManager.js +11 -21
  133. package/dist/scheduleManager.js.map +1 -1
  134. package/dist/storageServiceWithAttachBlobs.d.ts +17 -0
  135. package/dist/storageServiceWithAttachBlobs.d.ts.map +1 -0
  136. package/dist/storageServiceWithAttachBlobs.js +32 -0
  137. package/dist/storageServiceWithAttachBlobs.js.map +1 -0
  138. package/dist/summary/index.d.ts +17 -0
  139. package/dist/summary/index.d.ts.map +1 -0
  140. package/dist/summary/index.js +46 -0
  141. package/dist/summary/index.js.map +1 -0
  142. package/dist/summary/orderedClientElection.d.ts.map +1 -0
  143. package/dist/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  144. package/dist/summary/orderedClientElection.js.map +1 -0
  145. package/{lib → dist/summary}/runWhileConnectedCoordinator.d.ts +3 -2
  146. package/dist/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  147. package/dist/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +5 -4
  148. package/dist/summary/runWhileConnectedCoordinator.js.map +1 -0
  149. package/{lib → dist/summary}/runningSummarizer.d.ts +19 -18
  150. package/dist/summary/runningSummarizer.d.ts.map +1 -0
  151. package/dist/{runningSummarizer.js → summary/runningSummarizer.js} +191 -77
  152. package/dist/summary/runningSummarizer.js.map +1 -0
  153. package/dist/{summarizer.d.ts → summary/summarizer.d.ts} +6 -12
  154. package/dist/summary/summarizer.d.ts.map +1 -0
  155. package/dist/{summarizer.js → summary/summarizer.js} +32 -76
  156. package/dist/summary/summarizer.js.map +1 -0
  157. package/dist/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +1 -2
  158. package/dist/summary/summarizerClientElection.d.ts.map +1 -0
  159. package/dist/{summarizerClientElection.js → summary/summarizerClientElection.js} +3 -30
  160. package/dist/summary/summarizerClientElection.js.map +1 -0
  161. package/dist/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  162. package/dist/summary/summarizerHeuristics.d.ts.map +1 -0
  163. package/dist/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +9 -12
  164. package/dist/summary/summarizerHeuristics.js.map +1 -0
  165. package/dist/summary/summarizerNode/index.d.ts +8 -0
  166. package/dist/summary/summarizerNode/index.d.ts.map +1 -0
  167. package/dist/summary/summarizerNode/index.js +12 -0
  168. package/dist/summary/summarizerNode/index.js.map +1 -0
  169. package/dist/summary/summarizerNode/summarizerNode.d.ts +149 -0
  170. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
  171. package/dist/summary/summarizerNode/summarizerNode.js +531 -0
  172. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -0
  173. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
  174. package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
  175. package/dist/summary/summarizerNode/summarizerNodeUtils.js +132 -0
  176. package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
  177. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
  178. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
  179. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +423 -0
  180. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
  181. package/{lib → dist/summary}/summarizerTypes.d.ts +29 -42
  182. package/dist/summary/summarizerTypes.d.ts.map +1 -0
  183. package/dist/{summarizerTypes.js → summary/summarizerTypes.js} +0 -5
  184. package/dist/summary/summarizerTypes.js.map +1 -0
  185. package/dist/summary/summaryCollection.d.ts.map +1 -0
  186. package/dist/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  187. package/dist/summary/summaryCollection.js.map +1 -0
  188. package/{lib → dist/summary}/summaryFormat.d.ts +3 -21
  189. package/dist/summary/summaryFormat.d.ts.map +1 -0
  190. package/dist/{summaryFormat.js → summary/summaryFormat.js} +19 -21
  191. package/dist/summary/summaryFormat.js.map +1 -0
  192. package/dist/summary/summaryGenerator.d.ts.map +1 -0
  193. package/dist/{summaryGenerator.js → summary/summaryGenerator.js} +34 -16
  194. package/dist/summary/summaryGenerator.js.map +1 -0
  195. package/dist/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  196. package/dist/summary/summaryManager.d.ts.map +1 -0
  197. package/dist/{summaryManager.js → summary/summaryManager.js} +21 -9
  198. package/dist/summary/summaryManager.js.map +1 -0
  199. package/dist/throttler.d.ts +2 -2
  200. package/dist/throttler.d.ts.map +1 -1
  201. package/dist/throttler.js +4 -4
  202. package/dist/throttler.js.map +1 -1
  203. package/lib/batchTracker.d.ts +1 -2
  204. package/lib/batchTracker.d.ts.map +1 -1
  205. package/lib/batchTracker.js +2 -1
  206. package/lib/batchTracker.js.map +1 -1
  207. package/lib/blobManager.d.ts +74 -42
  208. package/lib/blobManager.d.ts.map +1 -1
  209. package/lib/blobManager.js +322 -153
  210. package/lib/blobManager.js.map +1 -1
  211. package/lib/connectionTelemetry.d.ts.map +1 -1
  212. package/lib/connectionTelemetry.js +11 -9
  213. package/lib/connectionTelemetry.js.map +1 -1
  214. package/lib/containerHandleContext.d.ts.map +1 -1
  215. package/lib/containerHandleContext.js +3 -1
  216. package/lib/containerHandleContext.js.map +1 -1
  217. package/lib/containerRuntime.d.ts +148 -114
  218. package/lib/containerRuntime.d.ts.map +1 -1
  219. package/lib/containerRuntime.js +506 -314
  220. package/lib/containerRuntime.js.map +1 -1
  221. package/lib/dataStore.d.ts.map +1 -1
  222. package/lib/dataStore.js +11 -9
  223. package/lib/dataStore.js.map +1 -1
  224. package/lib/dataStoreContext.d.ts +40 -13
  225. package/lib/dataStoreContext.d.ts.map +1 -1
  226. package/lib/dataStoreContext.js +136 -56
  227. package/lib/dataStoreContext.js.map +1 -1
  228. package/lib/dataStoreContexts.d.ts.map +1 -1
  229. package/lib/dataStoreContexts.js +7 -3
  230. package/lib/dataStoreContexts.js.map +1 -1
  231. package/lib/dataStoreRegistry.d.ts.map +1 -1
  232. package/lib/dataStoreRegistry.js +3 -1
  233. package/lib/dataStoreRegistry.js.map +1 -1
  234. package/lib/dataStores.d.ts +39 -12
  235. package/lib/dataStores.d.ts.map +1 -1
  236. package/lib/dataStores.js +162 -74
  237. package/lib/dataStores.js.map +1 -1
  238. package/lib/deltaManagerSummarizerProxy.d.ts +19 -0
  239. package/lib/deltaManagerSummarizerProxy.d.ts.map +1 -0
  240. package/lib/deltaManagerSummarizerProxy.js +36 -0
  241. package/lib/deltaManagerSummarizerProxy.js.map +1 -0
  242. package/lib/deltaScheduler.d.ts.map +1 -1
  243. package/lib/deltaScheduler.js +9 -4
  244. package/lib/deltaScheduler.js.map +1 -1
  245. package/lib/gc/garbageCollection.d.ts +204 -0
  246. package/lib/gc/garbageCollection.d.ts.map +1 -0
  247. package/lib/gc/garbageCollection.js +922 -0
  248. package/lib/gc/garbageCollection.js.map +1 -0
  249. package/lib/gc/gcConfigs.d.ts +22 -0
  250. package/lib/gc/gcConfigs.d.ts.map +1 -0
  251. package/lib/gc/gcConfigs.js +139 -0
  252. package/lib/gc/gcConfigs.js.map +1 -0
  253. package/lib/gc/gcDefinitions.d.ts +320 -0
  254. package/lib/gc/gcDefinitions.d.ts.map +1 -0
  255. package/lib/gc/gcDefinitions.js +78 -0
  256. package/lib/gc/gcDefinitions.js.map +1 -0
  257. package/lib/gc/gcHelpers.d.ts +86 -0
  258. package/lib/gc/gcHelpers.d.ts.map +1 -0
  259. package/lib/gc/gcHelpers.js +254 -0
  260. package/lib/gc/gcHelpers.js.map +1 -0
  261. package/lib/gc/gcReferenceGraphAlgorithm.d.ts +16 -0
  262. package/lib/gc/gcReferenceGraphAlgorithm.d.ts.map +1 -0
  263. package/lib/gc/gcReferenceGraphAlgorithm.js +45 -0
  264. package/lib/gc/gcReferenceGraphAlgorithm.js.map +1 -0
  265. package/lib/gc/gcSummaryDefinitions.d.ts +52 -0
  266. package/lib/gc/gcSummaryDefinitions.d.ts.map +1 -0
  267. package/lib/gc/gcSummaryDefinitions.js +6 -0
  268. package/lib/gc/gcSummaryDefinitions.js.map +1 -0
  269. package/lib/gc/gcSummaryStateTracker.d.ts +93 -0
  270. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -0
  271. package/lib/gc/gcSummaryStateTracker.js +235 -0
  272. package/lib/gc/gcSummaryStateTracker.js.map +1 -0
  273. package/{dist → lib/gc}/gcSweepReadyUsageDetection.d.ts +5 -5
  274. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +1 -0
  275. package/lib/{gcSweepReadyUsageDetection.js → gc/gcSweepReadyUsageDetection.js} +15 -11
  276. package/lib/gc/gcSweepReadyUsageDetection.js.map +1 -0
  277. package/lib/gc/gcUnreferencedStateTracker.d.ts +34 -0
  278. package/lib/gc/gcUnreferencedStateTracker.d.ts.map +1 -0
  279. package/lib/gc/gcUnreferencedStateTracker.js +90 -0
  280. package/lib/gc/gcUnreferencedStateTracker.js.map +1 -0
  281. package/lib/gc/index.d.ts +13 -0
  282. package/lib/gc/index.d.ts.map +1 -0
  283. package/lib/gc/index.js +12 -0
  284. package/lib/gc/index.js.map +1 -0
  285. package/lib/index.d.ts +3 -8
  286. package/lib/index.d.ts.map +1 -1
  287. package/lib/index.js +2 -6
  288. package/lib/index.js.map +1 -1
  289. package/lib/opLifecycle/batchManager.d.ts +10 -0
  290. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  291. package/lib/opLifecycle/batchManager.js +35 -7
  292. package/lib/opLifecycle/batchManager.js.map +1 -1
  293. package/lib/opLifecycle/definitions.d.ts +29 -1
  294. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  295. package/lib/opLifecycle/definitions.js.map +1 -1
  296. package/lib/opLifecycle/index.d.ts +3 -3
  297. package/lib/opLifecycle/index.d.ts.map +1 -1
  298. package/lib/opLifecycle/index.js +2 -2
  299. package/lib/opLifecycle/index.js.map +1 -1
  300. package/lib/opLifecycle/opCompressor.d.ts +1 -1
  301. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  302. package/lib/opLifecycle/opCompressor.js +47 -18
  303. package/lib/opLifecycle/opCompressor.js.map +1 -1
  304. package/lib/opLifecycle/opDecompressor.d.ts +6 -1
  305. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  306. package/lib/opLifecycle/opDecompressor.js +72 -18
  307. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  308. package/lib/opLifecycle/opSplitter.d.ts +46 -2
  309. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  310. package/lib/opLifecycle/opSplitter.js +141 -5
  311. package/lib/opLifecycle/opSplitter.js.map +1 -1
  312. package/lib/opLifecycle/outbox.d.ts +23 -2
  313. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  314. package/lib/opLifecycle/outbox.js +103 -53
  315. package/lib/opLifecycle/outbox.js.map +1 -1
  316. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  317. package/lib/opLifecycle/remoteMessageProcessor.js +17 -2
  318. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  319. package/lib/opProperties.d.ts.map +1 -1
  320. package/lib/opProperties.js +1 -3
  321. package/lib/opProperties.js.map +1 -1
  322. package/lib/packageVersion.d.ts +1 -1
  323. package/lib/packageVersion.js +1 -1
  324. package/lib/packageVersion.js.map +1 -1
  325. package/lib/pendingStateManager.d.ts +6 -15
  326. package/lib/pendingStateManager.d.ts.map +1 -1
  327. package/lib/pendingStateManager.js +137 -165
  328. package/lib/pendingStateManager.js.map +1 -1
  329. package/lib/scheduleManager.d.ts +0 -1
  330. package/lib/scheduleManager.d.ts.map +1 -1
  331. package/lib/scheduleManager.js +11 -21
  332. package/lib/scheduleManager.js.map +1 -1
  333. package/lib/storageServiceWithAttachBlobs.d.ts +17 -0
  334. package/lib/storageServiceWithAttachBlobs.d.ts.map +1 -0
  335. package/lib/storageServiceWithAttachBlobs.js +28 -0
  336. package/lib/storageServiceWithAttachBlobs.js.map +1 -0
  337. package/lib/summary/index.d.ts +17 -0
  338. package/lib/summary/index.d.ts.map +1 -0
  339. package/lib/summary/index.js +15 -0
  340. package/lib/summary/index.js.map +1 -0
  341. package/lib/summary/orderedClientElection.d.ts.map +1 -0
  342. package/lib/{orderedClientElection.js → summary/orderedClientElection.js} +10 -4
  343. package/lib/summary/orderedClientElection.js.map +1 -0
  344. package/{dist → lib/summary}/runWhileConnectedCoordinator.d.ts +3 -2
  345. package/lib/summary/runWhileConnectedCoordinator.d.ts.map +1 -0
  346. package/lib/{runWhileConnectedCoordinator.js → summary/runWhileConnectedCoordinator.js} +5 -4
  347. package/lib/summary/runWhileConnectedCoordinator.js.map +1 -0
  348. package/{dist → lib/summary}/runningSummarizer.d.ts +19 -18
  349. package/lib/summary/runningSummarizer.d.ts.map +1 -0
  350. package/lib/{runningSummarizer.js → summary/runningSummarizer.js} +193 -79
  351. package/lib/summary/runningSummarizer.js.map +1 -0
  352. package/lib/{summarizer.d.ts → summary/summarizer.d.ts} +6 -12
  353. package/lib/summary/summarizer.d.ts.map +1 -0
  354. package/lib/{summarizer.js → summary/summarizer.js} +34 -78
  355. package/lib/summary/summarizer.js.map +1 -0
  356. package/lib/{summarizerClientElection.d.ts → summary/summarizerClientElection.d.ts} +1 -2
  357. package/lib/summary/summarizerClientElection.d.ts.map +1 -0
  358. package/lib/{summarizerClientElection.js → summary/summarizerClientElection.js} +3 -30
  359. package/lib/summary/summarizerClientElection.js.map +1 -0
  360. package/lib/{summarizerHeuristics.d.ts → summary/summarizerHeuristics.d.ts} +1 -1
  361. package/lib/summary/summarizerHeuristics.d.ts.map +1 -0
  362. package/lib/{summarizerHeuristics.js → summary/summarizerHeuristics.js} +9 -12
  363. package/lib/summary/summarizerHeuristics.js.map +1 -0
  364. package/lib/summary/summarizerNode/index.d.ts +8 -0
  365. package/lib/summary/summarizerNode/index.d.ts.map +1 -0
  366. package/lib/summary/summarizerNode/index.js +7 -0
  367. package/lib/summary/summarizerNode/index.js.map +1 -0
  368. package/lib/summary/summarizerNode/summarizerNode.d.ts +149 -0
  369. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
  370. package/lib/summary/summarizerNode/summarizerNode.js +526 -0
  371. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -0
  372. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
  373. package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
  374. package/lib/summary/summarizerNode/summarizerNodeUtils.js +125 -0
  375. package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
  376. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
  377. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
  378. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +419 -0
  379. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
  380. package/{dist → lib/summary}/summarizerTypes.d.ts +29 -42
  381. package/lib/summary/summarizerTypes.d.ts.map +1 -0
  382. package/lib/summary/summarizerTypes.js +6 -0
  383. package/lib/summary/summarizerTypes.js.map +1 -0
  384. package/lib/summary/summaryCollection.d.ts.map +1 -0
  385. package/lib/{summaryCollection.js → summary/summaryCollection.js} +18 -8
  386. package/lib/summary/summaryCollection.js.map +1 -0
  387. package/{dist → lib/summary}/summaryFormat.d.ts +3 -21
  388. package/lib/summary/summaryFormat.d.ts.map +1 -0
  389. package/lib/{summaryFormat.js → summary/summaryFormat.js} +20 -21
  390. package/lib/summary/summaryFormat.js.map +1 -0
  391. package/lib/summary/summaryGenerator.d.ts.map +1 -0
  392. package/lib/{summaryGenerator.js → summary/summaryGenerator.js} +34 -16
  393. package/lib/summary/summaryGenerator.js.map +1 -0
  394. package/lib/{summaryManager.d.ts → summary/summaryManager.d.ts} +1 -1
  395. package/lib/summary/summaryManager.d.ts.map +1 -0
  396. package/lib/{summaryManager.js → summary/summaryManager.js} +21 -9
  397. package/lib/summary/summaryManager.js.map +1 -0
  398. package/lib/throttler.d.ts +2 -2
  399. package/lib/throttler.d.ts.map +1 -1
  400. package/lib/throttler.js +4 -4
  401. package/lib/throttler.js.map +1 -1
  402. package/package.json +67 -61
  403. package/prettier.config.cjs +1 -1
  404. package/src/batchTracker.ts +55 -50
  405. package/src/blobManager.ts +863 -594
  406. package/src/connectionTelemetry.ts +280 -249
  407. package/src/containerHandleContext.ts +27 -29
  408. package/src/containerRuntime.ts +3174 -2805
  409. package/src/dataStore.ts +172 -159
  410. package/src/dataStoreContext.ts +1141 -993
  411. package/src/dataStoreContexts.ts +178 -161
  412. package/src/dataStoreRegistry.ts +25 -20
  413. package/src/dataStores.ts +887 -716
  414. package/src/deltaManagerSummarizerProxy.ts +46 -0
  415. package/src/deltaScheduler.ts +158 -150
  416. package/{garbageCollection.md → src/gc/garbageCollection.md} +16 -3
  417. package/src/gc/garbageCollection.ts +1250 -0
  418. package/src/gc/gcConfigs.ts +193 -0
  419. package/src/gc/gcDefinitions.ts +387 -0
  420. package/src/gc/gcHelpers.ts +332 -0
  421. package/src/gc/gcReferenceGraphAlgorithm.ts +52 -0
  422. package/src/gc/gcSummaryDefinitions.ts +54 -0
  423. package/src/gc/gcSummaryStateTracker.ts +329 -0
  424. package/src/gc/gcSweepReadyUsageDetection.ts +145 -0
  425. package/src/gc/gcUnreferencedStateTracker.ts +114 -0
  426. package/src/gc/index.ts +65 -0
  427. package/src/index.ts +61 -75
  428. package/src/opLifecycle/README.md +157 -0
  429. package/src/opLifecycle/batchManager.ts +119 -86
  430. package/src/opLifecycle/definitions.ts +49 -19
  431. package/src/opLifecycle/index.ts +7 -6
  432. package/src/opLifecycle/opCompressor.ts +78 -40
  433. package/src/opLifecycle/opDecompressor.ts +148 -64
  434. package/src/opLifecycle/opSplitter.ts +269 -66
  435. package/src/opLifecycle/outbox.ts +268 -184
  436. package/src/opLifecycle/remoteMessageProcessor.ts +63 -47
  437. package/src/opProperties.ts +11 -9
  438. package/src/packageVersion.ts +1 -1
  439. package/src/pendingStateManager.ts +386 -381
  440. package/src/scheduleManager.ts +299 -280
  441. package/src/storageServiceWithAttachBlobs.ts +38 -0
  442. package/src/summary/index.ts +105 -0
  443. package/src/summary/orderedClientElection.ts +564 -0
  444. package/src/summary/runWhileConnectedCoordinator.ts +113 -0
  445. package/src/summary/runningSummarizer.ts +788 -0
  446. package/src/summary/summarizer.ts +372 -0
  447. package/src/summary/summarizerClientElection.ts +139 -0
  448. package/src/summary/summarizerHeuristics.ts +224 -0
  449. package/src/summary/summarizerNode/index.ts +12 -0
  450. package/src/summary/summarizerNode/summarizerNode.ts +766 -0
  451. package/src/summary/summarizerNode/summarizerNodeUtils.ts +214 -0
  452. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +644 -0
  453. package/src/summary/summarizerTypes.ts +507 -0
  454. package/src/summary/summaryCollection.ts +450 -0
  455. package/src/summary/summaryFormat.ts +228 -0
  456. package/src/summary/summaryGenerator.ts +505 -0
  457. package/src/summary/summaryManager.ts +423 -0
  458. package/src/throttler.ts +131 -122
  459. package/tsconfig.esnext.json +6 -6
  460. package/tsconfig.json +9 -13
  461. package/dist/garbageCollection.d.ts +0 -387
  462. package/dist/garbageCollection.d.ts.map +0 -1
  463. package/dist/garbageCollection.js +0 -1138
  464. package/dist/garbageCollection.js.map +0 -1
  465. package/dist/garbageCollectionConstants.d.ts +0 -19
  466. package/dist/garbageCollectionConstants.d.ts.map +0 -1
  467. package/dist/garbageCollectionConstants.js +0 -34
  468. package/dist/garbageCollectionConstants.js.map +0 -1
  469. package/dist/gcSweepReadyUsageDetection.d.ts.map +0 -1
  470. package/dist/gcSweepReadyUsageDetection.js.map +0 -1
  471. package/dist/orderedClientElection.d.ts.map +0 -1
  472. package/dist/orderedClientElection.js.map +0 -1
  473. package/dist/runWhileConnectedCoordinator.d.ts.map +0 -1
  474. package/dist/runWhileConnectedCoordinator.js.map +0 -1
  475. package/dist/runningSummarizer.d.ts.map +0 -1
  476. package/dist/runningSummarizer.js.map +0 -1
  477. package/dist/serializedSnapshotStorage.d.ts +0 -58
  478. package/dist/serializedSnapshotStorage.d.ts.map +0 -1
  479. package/dist/serializedSnapshotStorage.js +0 -108
  480. package/dist/serializedSnapshotStorage.js.map +0 -1
  481. package/dist/summarizer.d.ts.map +0 -1
  482. package/dist/summarizer.js.map +0 -1
  483. package/dist/summarizerClientElection.d.ts.map +0 -1
  484. package/dist/summarizerClientElection.js.map +0 -1
  485. package/dist/summarizerHandle.d.ts +0 -12
  486. package/dist/summarizerHandle.d.ts.map +0 -1
  487. package/dist/summarizerHandle.js +0 -22
  488. package/dist/summarizerHandle.js.map +0 -1
  489. package/dist/summarizerHeuristics.d.ts.map +0 -1
  490. package/dist/summarizerHeuristics.js.map +0 -1
  491. package/dist/summarizerTypes.d.ts.map +0 -1
  492. package/dist/summarizerTypes.js.map +0 -1
  493. package/dist/summaryCollection.d.ts.map +0 -1
  494. package/dist/summaryCollection.js.map +0 -1
  495. package/dist/summaryFormat.d.ts.map +0 -1
  496. package/dist/summaryFormat.js.map +0 -1
  497. package/dist/summaryGenerator.d.ts.map +0 -1
  498. package/dist/summaryGenerator.js.map +0 -1
  499. package/dist/summaryManager.d.ts.map +0 -1
  500. package/dist/summaryManager.js.map +0 -1
  501. package/lib/garbageCollection.d.ts +0 -387
  502. package/lib/garbageCollection.d.ts.map +0 -1
  503. package/lib/garbageCollection.js +0 -1133
  504. package/lib/garbageCollection.js.map +0 -1
  505. package/lib/garbageCollectionConstants.d.ts +0 -19
  506. package/lib/garbageCollectionConstants.d.ts.map +0 -1
  507. package/lib/garbageCollectionConstants.js +0 -31
  508. package/lib/garbageCollectionConstants.js.map +0 -1
  509. package/lib/gcSweepReadyUsageDetection.d.ts.map +0 -1
  510. package/lib/gcSweepReadyUsageDetection.js.map +0 -1
  511. package/lib/orderedClientElection.d.ts.map +0 -1
  512. package/lib/orderedClientElection.js.map +0 -1
  513. package/lib/runWhileConnectedCoordinator.d.ts.map +0 -1
  514. package/lib/runWhileConnectedCoordinator.js.map +0 -1
  515. package/lib/runningSummarizer.d.ts.map +0 -1
  516. package/lib/runningSummarizer.js.map +0 -1
  517. package/lib/serializedSnapshotStorage.d.ts +0 -58
  518. package/lib/serializedSnapshotStorage.d.ts.map +0 -1
  519. package/lib/serializedSnapshotStorage.js +0 -104
  520. package/lib/serializedSnapshotStorage.js.map +0 -1
  521. package/lib/summarizer.d.ts.map +0 -1
  522. package/lib/summarizer.js.map +0 -1
  523. package/lib/summarizerClientElection.d.ts.map +0 -1
  524. package/lib/summarizerClientElection.js.map +0 -1
  525. package/lib/summarizerHandle.d.ts +0 -12
  526. package/lib/summarizerHandle.d.ts.map +0 -1
  527. package/lib/summarizerHandle.js +0 -18
  528. package/lib/summarizerHandle.js.map +0 -1
  529. package/lib/summarizerHeuristics.d.ts.map +0 -1
  530. package/lib/summarizerHeuristics.js.map +0 -1
  531. package/lib/summarizerTypes.d.ts.map +0 -1
  532. package/lib/summarizerTypes.js +0 -9
  533. package/lib/summarizerTypes.js.map +0 -1
  534. package/lib/summaryCollection.d.ts.map +0 -1
  535. package/lib/summaryCollection.js.map +0 -1
  536. package/lib/summaryFormat.d.ts.map +0 -1
  537. package/lib/summaryFormat.js.map +0 -1
  538. package/lib/summaryGenerator.d.ts.map +0 -1
  539. package/lib/summaryGenerator.js.map +0 -1
  540. package/lib/summaryManager.d.ts.map +0 -1
  541. package/lib/summaryManager.js.map +0 -1
  542. package/src/garbageCollection.ts +0 -1646
  543. package/src/garbageCollectionConstants.ts +0 -35
  544. package/src/gcSweepReadyUsageDetection.ts +0 -139
  545. package/src/orderedClientElection.ts +0 -532
  546. package/src/runWhileConnectedCoordinator.ts +0 -106
  547. package/src/runningSummarizer.ts +0 -611
  548. package/src/serializedSnapshotStorage.ts +0 -146
  549. package/src/summarizer.ts +0 -421
  550. package/src/summarizerClientElection.ts +0 -161
  551. package/src/summarizerHandle.ts +0 -21
  552. package/src/summarizerHeuristics.ts +0 -222
  553. package/src/summarizerTypes.ts +0 -510
  554. package/src/summaryCollection.ts +0 -421
  555. package/src/summaryFormat.ts +0 -235
  556. package/src/summaryGenerator.ts +0 -446
  557. package/src/summaryManager.ts +0 -394
  558. /package/dist/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  559. /package/dist/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  560. /package/dist/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
  561. /package/lib/{orderedClientElection.d.ts → summary/orderedClientElection.d.ts} +0 -0
  562. /package/lib/{summaryCollection.d.ts → summary/summaryCollection.d.ts} +0 -0
  563. /package/lib/{summaryGenerator.d.ts → summary/summaryGenerator.d.ts} +0 -0
@@ -3,1004 +3,1148 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { IDisposable, ITelemetryLogger, ITelemetryProperties } from "@fluidframework/common-definitions";
7
6
  import {
8
- FluidObject,
9
- IRequest,
10
- IResponse,
11
- IFluidHandle,
12
- } from "@fluidframework/core-interfaces";
7
+ IDisposable,
8
+ ITelemetryLogger,
9
+ ITelemetryProperties,
10
+ } from "@fluidframework/common-definitions";
11
+ import { FluidObject, IRequest, IResponse, IFluidHandle } from "@fluidframework/core-interfaces";
13
12
  import {
14
- IAudience,
15
- IDeltaManager,
16
- AttachState,
17
- ILoaderOptions,
13
+ IAudience,
14
+ IDeltaManager,
15
+ AttachState,
16
+ ILoaderOptions,
18
17
  } from "@fluidframework/container-definitions";
19
- import {
20
- assert,
21
- Deferred,
22
- LazyPromise,
23
- TypedEventEmitter,
24
- } from "@fluidframework/common-utils";
18
+ import { assert, Deferred, LazyPromise, TypedEventEmitter } from "@fluidframework/common-utils";
25
19
  import { IDocumentStorageService } from "@fluidframework/driver-definitions";
26
20
  import { readAndParse } from "@fluidframework/driver-utils";
27
21
  import { BlobTreeEntry } from "@fluidframework/protocol-base";
28
22
  import {
29
- IClientDetails,
30
- IDocumentMessage,
31
- IQuorumClients,
32
- ISequencedDocumentMessage,
33
- ISnapshotTree,
34
- ITreeEntry,
23
+ IClientDetails,
24
+ IDocumentMessage,
25
+ IQuorumClients,
26
+ ISequencedDocumentMessage,
27
+ ISnapshotTree,
28
+ ITreeEntry,
35
29
  } from "@fluidframework/protocol-definitions";
30
+ import { IContainerRuntime } from "@fluidframework/container-runtime-definitions";
36
31
  import {
37
- IContainerRuntime,
38
- } from "@fluidframework/container-runtime-definitions";
39
- import {
40
- BindState,
41
- channelsTreeName,
42
- CreateChildSummarizerNodeFn,
43
- CreateChildSummarizerNodeParam,
44
- FluidDataStoreRegistryEntry,
45
- IAttachMessage,
46
- IFluidDataStoreChannel,
47
- IFluidDataStoreContext,
48
- IFluidDataStoreContextDetached,
49
- IFluidDataStoreContextEvents,
50
- IFluidDataStoreRegistry,
51
- IGarbageCollectionData,
52
- IGarbageCollectionDetailsBase,
53
- IInboundSignalMessage,
54
- IProvideFluidDataStoreFactory,
55
- ISummarizeInternalResult,
56
- ISummarizeResult,
57
- ISummarizerNodeWithGC,
58
- SummarizeInternalFn,
59
- ITelemetryContext,
32
+ channelsTreeName,
33
+ CreateChildSummarizerNodeFn,
34
+ CreateChildSummarizerNodeParam,
35
+ FluidDataStoreRegistryEntry,
36
+ IAttachMessage,
37
+ IFluidDataStoreChannel,
38
+ IFluidDataStoreContext,
39
+ IFluidDataStoreContextDetached,
40
+ IFluidDataStoreContextEvents,
41
+ IFluidDataStoreRegistry,
42
+ IGarbageCollectionData,
43
+ IGarbageCollectionDetailsBase,
44
+ IInboundSignalMessage,
45
+ IProvideFluidDataStoreFactory,
46
+ ISummarizeInternalResult,
47
+ ISummarizeResult,
48
+ ISummarizerNodeWithGC,
49
+ SummarizeInternalFn,
50
+ ITelemetryContext,
51
+ VisibilityState,
60
52
  } from "@fluidframework/runtime-definitions";
61
53
  import {
62
- addBlobToSummary,
63
- convertSummaryTreeToITree,
64
- packagePathToTelemetryProperty,
54
+ addBlobToSummary,
55
+ convertSummaryTreeToITree,
56
+ packagePathToTelemetryProperty,
65
57
  } from "@fluidframework/runtime-utils";
66
58
  import {
67
- ChildLogger,
68
- loggerToMonitoringContext,
69
- LoggingError,
70
- MonitoringContext,
71
- TelemetryDataTag,
72
- ThresholdCounter,
59
+ ChildLogger,
60
+ generateStack,
61
+ loggerToMonitoringContext,
62
+ LoggingError,
63
+ MonitoringContext,
64
+ TelemetryDataTag,
65
+ ThresholdCounter,
73
66
  } from "@fluidframework/telemetry-utils";
74
67
  import {
75
- DataCorruptionError,
76
- DataProcessingError,
77
- extractSafePropertiesFromMessage,
68
+ DataCorruptionError,
69
+ DataProcessingError,
70
+ extractSafePropertiesFromMessage,
78
71
  } from "@fluidframework/container-utils";
79
72
 
80
- import { ContainerRuntime } from "./containerRuntime";
81
73
  import {
82
- dataStoreAttributesBlobName,
83
- hasIsolatedChannels,
84
- wrapSummaryInChannelsTree,
85
- ReadFluidDataStoreAttributes,
86
- WriteFluidDataStoreAttributes,
87
- getAttributesFormatVersion,
88
- getFluidDataStoreAttributes,
89
- } from "./summaryFormat";
90
- import { throwOnTombstoneUsageKey } from "./garbageCollectionConstants";
91
- import { summarizerClientType } from "./summarizerClientElection";
74
+ dataStoreAttributesBlobName,
75
+ hasIsolatedChannels,
76
+ wrapSummaryInChannelsTree,
77
+ ReadFluidDataStoreAttributes,
78
+ WriteFluidDataStoreAttributes,
79
+ getAttributesFormatVersion,
80
+ getFluidDataStoreAttributes,
81
+ summarizerClientType,
82
+ } from "./summary";
83
+ import { ContainerRuntime } from "./containerRuntime";
84
+ import { sendGCUnexpectedUsageEvent, throwOnTombstoneUsageKey } from "./gc";
92
85
 
93
86
  function createAttributes(
94
- pkg: readonly string[],
95
- isRootDataStore: boolean,
87
+ pkg: readonly string[],
88
+ isRootDataStore: boolean,
96
89
  ): WriteFluidDataStoreAttributes {
97
- const stringifiedPkg = JSON.stringify(pkg);
98
- return {
99
- pkg: stringifiedPkg,
100
- summaryFormatVersion: 2,
101
- isRootDataStore,
102
- };
90
+ const stringifiedPkg = JSON.stringify(pkg);
91
+ return {
92
+ pkg: stringifiedPkg,
93
+ summaryFormatVersion: 2,
94
+ isRootDataStore,
95
+ };
103
96
  }
104
- export function createAttributesBlob(
105
- pkg: readonly string[],
106
- isRootDataStore: boolean,
107
- ): ITreeEntry {
108
- const attributes = createAttributes(pkg, isRootDataStore);
109
- return new BlobTreeEntry(dataStoreAttributesBlobName, JSON.stringify(attributes));
97
+ export function createAttributesBlob(pkg: readonly string[], isRootDataStore: boolean): ITreeEntry {
98
+ const attributes = createAttributes(pkg, isRootDataStore);
99
+ return new BlobTreeEntry(dataStoreAttributesBlobName, JSON.stringify(attributes));
110
100
  }
111
101
 
112
102
  interface ISnapshotDetails {
113
- pkg: readonly string[];
114
- isRootDataStore: boolean;
115
- snapshot?: ISnapshotTree;
103
+ pkg: readonly string[];
104
+ isRootDataStore: boolean;
105
+ snapshot?: ISnapshotTree;
116
106
  }
117
107
 
118
108
  interface FluidDataStoreMessage {
119
- content: any;
120
- type: string;
109
+ content: any;
110
+ type: string;
121
111
  }
122
112
 
123
113
  /** Properties necessary for creating a FluidDataStoreContext */
124
114
  export interface IFluidDataStoreContextProps {
125
- readonly id: string;
126
- readonly runtime: ContainerRuntime;
127
- readonly storage: IDocumentStorageService;
128
- readonly scope: FluidObject;
129
- readonly createSummarizerNodeFn: CreateChildSummarizerNodeFn;
130
- readonly pkg?: Readonly<string[]>;
115
+ readonly id: string;
116
+ readonly runtime: ContainerRuntime;
117
+ readonly storage: IDocumentStorageService;
118
+ readonly scope: FluidObject;
119
+ readonly createSummarizerNodeFn: CreateChildSummarizerNodeFn;
120
+ readonly pkg?: Readonly<string[]>;
131
121
  }
132
122
 
133
123
  /** Properties necessary for creating a local FluidDataStoreContext */
134
124
  export interface ILocalFluidDataStoreContextProps extends IFluidDataStoreContextProps {
135
- readonly pkg: Readonly<string[]> | undefined;
136
- readonly snapshotTree: ISnapshotTree | undefined;
137
- readonly isRootDataStore: boolean | undefined;
138
- readonly makeLocallyVisibleFn: () => void;
139
- /**
140
- * @deprecated 0.16 Issue #1635, #3631
141
- */
142
- readonly createProps?: any;
125
+ readonly pkg: Readonly<string[]> | undefined;
126
+ readonly snapshotTree: ISnapshotTree | undefined;
127
+ readonly isRootDataStore: boolean | undefined;
128
+ readonly makeLocallyVisibleFn: () => void;
129
+ /**
130
+ * @deprecated 0.16 Issue #1635, #3631
131
+ */
132
+ readonly createProps?: any;
143
133
  }
144
134
 
145
135
  /** Properties necessary for creating a remote FluidDataStoreContext */
146
136
  export interface IRemoteFluidDataStoreContextProps extends IFluidDataStoreContextProps {
147
- readonly snapshotTree: ISnapshotTree | undefined;
148
- readonly getBaseGCDetails: () => Promise<IGarbageCollectionDetailsBase | undefined>;
137
+ readonly snapshotTree: ISnapshotTree | undefined;
149
138
  }
150
139
 
151
140
  /**
152
141
  * Represents the context for the store. This context is passed to the store runtime.
153
142
  */
154
- export abstract class FluidDataStoreContext extends TypedEventEmitter<IFluidDataStoreContextEvents> implements
155
- IFluidDataStoreContext,
156
- IDisposable {
157
- public get packagePath(): readonly string[] {
158
- assert(this.pkg !== undefined, 0x139 /* "Undefined package path" */);
159
- return this.pkg;
160
- }
161
-
162
- public get options(): ILoaderOptions {
163
- return this._containerRuntime.options;
164
- }
165
-
166
- public get clientId(): string | undefined {
167
- return this._containerRuntime.clientId;
168
- }
169
-
170
- public get clientDetails(): IClientDetails {
171
- return this._containerRuntime.clientDetails;
172
- }
173
-
174
- public get logger(): ITelemetryLogger {
175
- return this._containerRuntime.logger;
176
- }
177
-
178
- public get deltaManager(): IDeltaManager<ISequencedDocumentMessage, IDocumentMessage> {
179
- return this._containerRuntime.deltaManager;
180
- }
181
-
182
- public get connected(): boolean {
183
- return this._containerRuntime.connected;
184
- }
185
-
186
- public get IFluidHandleContext() {
187
- return this._containerRuntime.IFluidHandleContext;
188
- }
189
-
190
- public get containerRuntime(): IContainerRuntime {
191
- return this._containerRuntime;
192
- }
193
-
194
- public get isLoaded(): boolean {
195
- return this.loaded;
196
- }
197
-
198
- public get baseSnapshot(): ISnapshotTree | undefined {
199
- return this._baseSnapshot;
200
- }
201
-
202
- private _disposed = false;
203
- public get disposed() { return this._disposed; }
204
-
205
- /**
206
- * Tombstone is a temporary feature that prevents a data store from sending / receiving ops, signals and from
207
- * loading.
208
- */
209
- private _tombstoned = false;
210
- public get tombstoned() { return this._tombstoned; }
211
- /** If true, throw an error when a tombstone data store is used. */
212
- private readonly throwOnTombstoneUsage: boolean;
213
-
214
- public get attachState(): AttachState {
215
- return this._attachState;
216
- }
217
-
218
- public get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {
219
- return this.registry;
220
- }
221
-
222
- /**
223
- * A datastore is considered as root if it
224
- * 1. is root in memory - see isInMemoryRoot
225
- * 2. is root as part of the base snapshot that the datastore loaded from
226
- * @returns whether a datastore is root
227
- */
228
- public async isRoot(): Promise<boolean> {
229
- return this.isInMemoryRoot() || (await this.getInitialSnapshotDetails()).isRootDataStore;
230
- }
231
-
232
- /**
233
- * There are 3 states where isInMemoryRoot needs to be true
234
- * 1. when a datastore becomes aliased. This can happen for both remote and local datastores
235
- * 2. when a datastore is created locally as root
236
- * 3. when a datastore is created locally as root and is rehydrated
237
- * @returns whether a datastore is root in memory
238
- */
239
- protected isInMemoryRoot(): boolean {
240
- return this._isInMemoryRoot;
241
- }
242
-
243
- protected registry: IFluidDataStoreRegistry | undefined;
244
-
245
- protected detachedRuntimeCreation = false;
246
- /** @deprecated - To be replaced by calling makeLocallyVisible directly */
247
- public readonly bindToContext: () => void;
248
- protected channel: IFluidDataStoreChannel | undefined;
249
- private loaded = false;
250
- protected pending: ISequencedDocumentMessage[] | undefined = [];
251
- protected channelDeferred: Deferred<IFluidDataStoreChannel> | undefined;
252
- private _baseSnapshot: ISnapshotTree | undefined;
253
- protected _attachState: AttachState;
254
- private _isInMemoryRoot: boolean = false;
255
- protected readonly summarizerNode: ISummarizerNodeWithGC;
256
- private readonly mc: MonitoringContext;
257
- private readonly thresholdOpsCounter: ThresholdCounter;
258
- private static readonly pendingOpsCountThreshold = 1000;
259
-
260
- // The used routes of this node as per the last GC run. This is used to update the used routes of the channel
261
- // if it realizes after GC is run.
262
- private lastUsedRoutes: string[] | undefined;
263
-
264
- public readonly id: string;
265
- private readonly _containerRuntime: ContainerRuntime;
266
- public readonly storage: IDocumentStorageService;
267
- public readonly scope: FluidObject;
268
- protected pkg?: readonly string[];
269
-
270
- constructor(
271
- props: IFluidDataStoreContextProps,
272
- private readonly existing: boolean,
273
- private bindState: BindState, // Used to assert for state tracking purposes
274
- public readonly isLocalDataStore: boolean,
275
- private readonly makeLocallyVisibleFn: () => void,
276
- ) {
277
- super();
278
-
279
- this._containerRuntime = props.runtime;
280
- this.id = props.id;
281
- this.storage = props.storage;
282
- this.scope = props.scope;
283
- this.pkg = props.pkg;
284
-
285
- // URIs use slashes as delimiters. Handles use URIs.
286
- // Thus having slashes in types almost guarantees trouble down the road!
287
- assert(!this.id.includes("/"), 0x13a /* Data store ID contains slash */);
288
-
289
- this._attachState = this.containerRuntime.attachState !== AttachState.Detached && this.existing ?
290
- this.containerRuntime.attachState : AttachState.Detached;
291
-
292
- this.bindToContext = () => {
293
- assert(this.bindState === BindState.NotBound, 0x13b /* "datastore context is already in bound state" */);
294
- this.bindState = BindState.Binding;
295
- assert(this.channel !== undefined, 0x13c /* "undefined channel on datastore context" */);
296
- this.makeLocallyVisible();
297
- this.bindState = BindState.Bound;
298
- };
299
-
300
- const thisSummarizeInternal =
301
- async (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) =>
302
- this.summarizeInternal(fullTree, trackState, telemetryContext);
303
-
304
- this.summarizerNode = props.createSummarizerNodeFn(
305
- thisSummarizeInternal,
306
- async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
307
- async () => this.getBaseGCDetails(),
308
- );
309
-
310
- this.mc = loggerToMonitoringContext(ChildLogger.create(this.logger, "FluidDataStoreContext"));
311
- this.thresholdOpsCounter = new ThresholdCounter(FluidDataStoreContext.pendingOpsCountThreshold, this.mc.logger);
312
-
313
- // Tombstone should only throw when the feature flag is enabled and the client isn't a summarizer
314
- this.throwOnTombstoneUsage =
315
- this.mc.config.getBoolean(throwOnTombstoneUsageKey) === true &&
316
- this.clientDetails.type !== summarizerClientType;
317
- }
318
-
319
- public dispose(): void {
320
- if (this._disposed) {
321
- return;
322
- }
323
- this._disposed = true;
324
-
325
- // Dispose any pending runtime after it gets fulfilled
326
- // Errors are logged where this.channelDeferred is consumed/generated (realizeCore(), bindRuntime())
327
- if (this.channelDeferred) {
328
- this.channelDeferred.promise.then((runtime) => {
329
- runtime.dispose();
330
- }).catch((error) => {});
331
- }
332
- }
333
-
334
- public setTombstone(tombstone: boolean) {
335
- if (this.tombstoned === tombstone) {
336
- return;
337
- }
338
-
339
- this._tombstoned = tombstone;
340
- }
341
-
342
- private rejectDeferredRealize(reason: string, packageName?: string): never {
343
- throw new LoggingError(reason, { packageName: { value: packageName, tag: TelemetryDataTag.CodeArtifact } });
344
- }
345
-
346
- public async realize(): Promise<IFluidDataStoreChannel> {
347
- assert(!this.detachedRuntimeCreation, 0x13d /* "Detached runtime creation on realize()" */);
348
- if (!this.channelDeferred) {
349
- this.channelDeferred = new Deferred<IFluidDataStoreChannel>();
350
- this.realizeCore(this.existing).catch((error) => {
351
- const errorWrapped = DataProcessingError.wrapIfUnrecognized(error, "realizeFluidDataStoreContext");
352
- errorWrapped.addTelemetryProperties({
353
- fluidDataStoreId: {
354
- value: this.id,
355
- tag: TelemetryDataTag.CodeArtifact,
356
- },
357
- });
358
- this.channelDeferred?.reject(errorWrapped);
359
- this.logger.sendErrorEvent({ eventName: "RealizeError" }, errorWrapped);
360
- });
361
- }
362
- return this.channelDeferred.promise;
363
- }
364
-
365
- protected async factoryFromPackagePath(packages?: readonly string[]) {
366
- assert(this.pkg === packages, 0x13e /* "Unexpected package path" */);
367
- if (packages === undefined) {
368
- this.rejectDeferredRealize("packages is undefined");
369
- }
370
-
371
- let entry: FluidDataStoreRegistryEntry | undefined;
372
- let registry: IFluidDataStoreRegistry | undefined = this._containerRuntime.IFluidDataStoreRegistry;
373
- let lastPkg: string | undefined;
374
- for (const pkg of packages) {
375
- if (!registry) {
376
- this.rejectDeferredRealize("No registry for package", lastPkg);
377
- }
378
- lastPkg = pkg;
379
- entry = await registry.get(pkg);
380
- if (!entry) {
381
- this.rejectDeferredRealize("Registry does not contain entry for the package", pkg);
382
- }
383
- registry = entry.IFluidDataStoreRegistry;
384
- }
385
- const factory = entry?.IFluidDataStoreFactory;
386
- if (factory === undefined) {
387
- this.rejectDeferredRealize("Can't find factory for package", lastPkg);
388
- }
389
-
390
- return { factory, registry };
391
- }
392
-
393
- private async realizeCore(existing: boolean): Promise<void> {
394
- const details = await this.getInitialSnapshotDetails();
395
- // Base snapshot is the baseline where pending ops are applied to.
396
- // It is important that this be in sync with the pending ops, and also
397
- // that it is set here, before bindRuntime is called.
398
- this._baseSnapshot = details.snapshot;
399
- const packages = details.pkg;
400
-
401
- const { factory, registry } = await this.factoryFromPackagePath(packages);
402
-
403
- assert(this.registry === undefined, 0x13f /* "datastore context registry is already set" */);
404
- this.registry = registry;
405
-
406
- const channel = await factory.instantiateDataStore(this, existing);
407
- assert(channel !== undefined, 0x140 /* "undefined channel on datastore context" */);
408
- this.bindRuntime(channel);
409
- }
410
-
411
- /**
412
- * Notifies this object about changes in the connection state.
413
- * @param value - New connection state.
414
- * @param clientId - ID of the client. Its old ID when in disconnected state and
415
- * its new client ID when we are connecting or connected.
416
- */
417
- public setConnectionState(connected: boolean, clientId?: string) {
418
- // ConnectionState should not fail in tombstone mode as this is internally run
419
- this.verifyNotClosed("setConnectionState", false /* checkTombstone */);
420
-
421
- // Connection events are ignored if the store is not yet loaded
422
- if (!this.loaded) {
423
- return;
424
- }
425
-
426
- assert(this.connected === connected, 0x141 /* "Unexpected connected state" */);
427
-
428
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
429
- this.channel!.setConnectionState(connected, clientId);
430
- }
431
-
432
- public process(messageArg: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {
433
- this.verifyNotClosed("process", true, extractSafePropertiesFromMessage(messageArg));
434
-
435
- const innerContents = messageArg.contents as FluidDataStoreMessage;
436
- const message = {
437
- ...messageArg,
438
- type: innerContents.type,
439
- contents: innerContents.content,
440
- };
441
-
442
- this.summarizerNode.recordChange(message);
443
-
444
- if (this.loaded) {
445
- return this.channel?.process(message, local, localOpMetadata);
446
- } else {
447
- assert(!local, 0x142 /* "local store channel is not loaded" */);
448
- assert(this.pending !== undefined, 0x23d /* "pending is undefined" */);
449
- this.pending.push(message);
450
- this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
451
- }
452
- }
453
-
454
- public processSignal(message: IInboundSignalMessage, local: boolean): void {
455
- this.verifyNotClosed("processSignal");
456
-
457
- // Signals are ignored if the store is not yet loaded
458
- if (!this.loaded) {
459
- return;
460
- }
461
-
462
- this.channel?.processSignal(message, local);
463
- }
464
-
465
- public getQuorum(): IQuorumClients {
466
- return this._containerRuntime.getQuorum();
467
- }
468
-
469
- public getAudience(): IAudience {
470
- return this._containerRuntime.getAudience();
471
- }
472
-
473
- /**
474
- * Returns a summary at the current sequence number.
475
- * @param fullTree - true to bypass optimizations and force a full summary tree
476
- * @param trackState - This tells whether we should track state from this summary.
477
- * @param telemetryContext - summary data passed through the layers for telemetry purposes
478
- */
479
- public async summarize(
480
- fullTree: boolean = false,
481
- trackState: boolean = true,
482
- telemetryContext?: ITelemetryContext,
483
- ): Promise<ISummarizeResult> {
484
- return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
485
- }
486
-
487
- private async summarizeInternal(
488
- fullTree: boolean,
489
- trackState: boolean,
490
- telemetryContext?: ITelemetryContext,
491
- ): Promise<ISummarizeInternalResult> {
492
- await this.realize();
493
-
494
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
495
- const summarizeResult = await this.channel!.summarize(fullTree, trackState, telemetryContext);
496
-
497
- // Wrap dds summaries in .channels subtree.
498
- wrapSummaryInChannelsTree(summarizeResult);
499
- const pathPartsForChildren = [channelsTreeName];
500
-
501
- // Add data store's attributes to the summary.
502
- const { pkg } = await this.getInitialSnapshotDetails();
503
- const isRoot = await this.isRoot();
504
- const attributes = createAttributes(pkg, isRoot);
505
- addBlobToSummary(summarizeResult, dataStoreAttributesBlobName, JSON.stringify(attributes));
506
-
507
- // If we are not referenced, mark the summary tree as unreferenced. Also, update unreferenced blob
508
- // size in the summary stats with the blobs size of this data store.
509
- if (!this.summarizerNode.isReferenced()) {
510
- summarizeResult.summary.unreferenced = true;
511
- summarizeResult.stats.unreferencedBlobSize = summarizeResult.stats.totalBlobSize;
512
- }
513
-
514
- return {
515
- ...summarizeResult,
516
- id: this.id,
517
- pathPartsForChildren,
518
- };
519
- }
520
-
521
- /**
522
- * Returns the data used for garbage collection. This includes a list of GC nodes that represent this data store
523
- * including any of its child channel contexts. Each node has a set of outbound routes to other GC nodes in the
524
- * document.
525
- * If there is no new data in this data store since the last summary, previous GC data is used.
526
- * If there is new data, the GC data is generated again (by calling getGCDataInternal).
527
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
528
- */
529
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
530
- return this.summarizerNode.getGCData(fullGC);
531
- }
532
-
533
- /**
534
- * Generates data used for garbage collection. This is called when there is new data since last summary. It
535
- * realizes the data store and calls into each channel context to get its GC data.
536
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
537
- */
538
- private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
539
- await this.realize();
540
- assert(this.channel !== undefined, 0x143 /* "Channel should not be undefined when running GC" */);
541
-
542
- return this.channel.getGCData(fullGC);
543
- }
544
-
545
- /**
546
- * After GC has run, called to notify the data store of routes used in it. These are used for the following:
547
- *
548
- * 1. To identify if this data store is being referenced in the document or not.
549
- *
550
- * 2. To determine if it needs to re-summarize in case used routes changed since last summary.
551
- *
552
- * 3. These are added to the summary generated by the data store.
553
- *
554
- * 4. To notify child contexts of their used routes. This is done immediately if the data store is loaded.
555
- * Else, it is done when realizing the data store.
556
- *
557
- * 5. To update the timestamp when this data store or any children are marked as unreferenced.
558
- *
559
- * @param usedRoutes - The routes that are used in this data store.
560
- */
561
- public updateUsedRoutes(usedRoutes: string[]) {
562
- // Update the used routes in this data store's summarizer node.
563
- this.summarizerNode.updateUsedRoutes(usedRoutes);
564
-
565
- /**
566
- * Store the used routes to update the channel if the data store is not loaded yet. If the used routes changed
567
- * since the previous run, the data store will be loaded during summarize since the used state changed. So, it's
568
- * safe to only store the last used routes.
569
- */
570
- this.lastUsedRoutes = usedRoutes;
571
-
572
- // If we are loaded, call the channel so it can update the used routes of the child contexts.
573
- // If we are not loaded, we will update this when we are realized.
574
- if (this.loaded) {
575
- this.updateChannelUsedRoutes();
576
- }
577
- }
578
-
579
- /**
580
- * Called when a new outbound reference is added to another node. This is used by garbage collection to identify
581
- * all references added in the system.
582
- * @param srcHandle - The handle of the node that added the reference.
583
- * @param outboundHandle - The handle of the outbound node that is referenced.
584
- */
585
- public addedGCOutboundReference(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) {
586
- this._containerRuntime.addedGCOutboundReference(srcHandle, outboundHandle);
587
- }
588
-
589
- /**
590
- * Updates the used routes of the channel and its child contexts. The channel must be loaded before calling this.
591
- * It is called in these two scenarios:
592
- * 1. When the used routes of the data store is updated and the data store is loaded.
593
- * 2. When the data store is realized. This updates the channel's used routes as per last GC run.
594
- */
595
- private updateChannelUsedRoutes() {
596
- assert(this.loaded, 0x144 /* "Channel should be loaded when updating used routes" */);
597
- assert(this.channel !== undefined, 0x145 /* "Channel should be present when data store is loaded" */);
598
-
599
- // If there is no lastUsedRoutes, GC has not run up until this point.
600
- if (this.lastUsedRoutes === undefined) {
601
- return;
602
- }
603
-
604
- // Remove the route to this data store, if it exists.
605
- const usedChannelRoutes = this.lastUsedRoutes.filter(
606
- (id: string) => { return id !== "/" && id !== ""; },
607
- );
608
- this.channel.updateUsedRoutes(usedChannelRoutes);
609
- }
610
-
611
- /**
612
- * @deprecated 0.18.Should call request on the runtime directly
613
- */
614
- public async request(request: IRequest): Promise<IResponse> {
615
- const runtime = await this.realize();
616
- return runtime.request(request);
617
- }
618
-
619
- public submitMessage(type: string, content: any, localOpMetadata: unknown): void {
620
- this.verifyNotClosed("submitMessage");
621
- assert(!!this.channel, 0x146 /* "Channel must exist when submitting message" */);
622
- const fluidDataStoreContent: FluidDataStoreMessage = {
623
- content,
624
- type,
625
- };
626
- this._containerRuntime.submitDataStoreOp(
627
- this.id,
628
- fluidDataStoreContent,
629
- localOpMetadata);
630
- }
631
-
632
- /**
633
- * This is called from a SharedSummaryBlock that does not generate ops but only wants to be part of the summary.
634
- * It indicates that there is data in the object that needs to be summarized.
635
- * We will update the latestSequenceNumber of the summary tracker of this
636
- * store and of the object's channel.
637
- *
638
- * @param address - The address of the channel that is dirty.
639
- *
640
- */
641
- public setChannelDirty(address: string): void {
642
- this.verifyNotClosed("setChannelDirty");
643
-
644
- // Get the latest sequence number.
645
- const latestSequenceNumber = this.deltaManager.lastSequenceNumber;
646
-
647
- this.summarizerNode.invalidate(latestSequenceNumber);
648
-
649
- const channelSummarizerNode = this.summarizerNode.getChild(address);
650
-
651
- if (channelSummarizerNode) {
652
- channelSummarizerNode.invalidate(latestSequenceNumber); // TODO: lazy load problem?
653
- }
654
- }
655
-
656
- public submitSignal(type: string, content: any) {
657
- this.verifyNotClosed("submitSignal");
658
-
659
- assert(!!this.channel, 0x147 /* "Channel must exist on submitting signal" */);
660
- return this._containerRuntime.submitDataStoreSignal(this.id, type, content);
661
- }
662
-
663
- /**
664
- * This is called by the data store channel when it becomes locally visible indicating that it is ready to become
665
- * globally visible now.
666
- */
667
- public makeLocallyVisible() {
668
- assert(this.channel !== undefined, 0x2cf /* "undefined channel on datastore context" */);
669
- this.makeLocallyVisibleFn();
670
- }
671
-
672
- protected bindRuntime(channel: IFluidDataStoreChannel) {
673
- if (this.channel) {
674
- throw new Error("Runtime already bound");
675
- }
676
-
677
- try {
678
- assert(!this.detachedRuntimeCreation, 0x148 /* "Detached runtime creation on runtime bind" */);
679
- assert(this.channelDeferred !== undefined, 0x149 /* "Undefined channel deferral" */);
680
- assert(this.pkg !== undefined, 0x14a /* "Undefined package path" */);
681
-
682
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
683
- const pending = this.pending!;
684
-
685
- // Apply all pending ops
686
- for (const op of pending) {
687
- channel.process(op, false, undefined /* localOpMetadata */);
688
- }
689
-
690
- this.thresholdOpsCounter.send("ProcessPendingOps", pending.length);
691
- this.pending = undefined;
692
-
693
- // And now mark the runtime active
694
- this.loaded = true;
695
- this.channel = channel;
696
-
697
- // Freeze the package path to ensure that someone doesn't modify it when it is
698
- // returned in packagePath().
699
- Object.freeze(this.pkg);
700
-
701
- /**
702
- * Update the used routes of the channel. If GC has run before this data store was realized, we will have
703
- * the used routes saved. So, this will ensure that all the child contexts have up-to-date used routes as
704
- * per the last time GC was run.
705
- * Also, this data store may have been realized during summarize. In that case, the child contexts need to
706
- * have their used routes updated to determine if its needs to summarize again and to add it to the summary.
707
- */
708
- this.updateChannelUsedRoutes();
709
-
710
- // And notify the pending promise it is now available
711
- this.channelDeferred.resolve(this.channel);
712
- } catch (error) {
713
- this.channelDeferred?.reject(error);
714
- this.logger.sendErrorEvent(
715
- { eventName: "BindRuntimeError", fluidDataStoreId: {
716
- value: this.id,
717
- tag: TelemetryDataTag.CodeArtifact,
718
- } },
719
- error);
720
- }
721
- }
722
-
723
- public async getAbsoluteUrl(relativeUrl: string): Promise<string | undefined> {
724
- if (this.attachState !== AttachState.Attached) {
725
- return undefined;
726
- }
727
- return this._containerRuntime.getAbsoluteUrl(relativeUrl);
728
- }
729
-
730
- public abstract generateAttachMessage(): IAttachMessage;
731
-
732
- public abstract getInitialSnapshotDetails(): Promise<ISnapshotDetails>;
733
-
734
- /**
735
- * @deprecated Sets the datastore as root, for aliasing purposes: #7948
736
- * This method should not be used outside of the aliasing context.
737
- * It will be removed, as the source of truth for this flag will be the aliasing blob.
738
- */
739
- public setInMemoryRoot(): void {
740
- this._isInMemoryRoot = true;
741
- }
742
-
743
- public abstract getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase>;
744
-
745
- public reSubmit(contents: any, localOpMetadata: unknown) {
746
- assert(!!this.channel, 0x14b /* "Channel must exist when resubmitting ops" */);
747
- const innerContents = contents as FluidDataStoreMessage;
748
- this.channel.reSubmit(innerContents.type, innerContents.content, localOpMetadata);
749
- }
750
-
751
- public rollback(contents: any, localOpMetadata: unknown) {
752
- if (!this.channel) {
753
- throw new Error("Channel must exist when rolling back ops");
754
- }
755
- if (!this.channel.rollback) {
756
- throw new Error("Channel doesn't support rollback");
757
- }
758
- const innerContents = contents as FluidDataStoreMessage;
759
- this.channel.rollback(innerContents.type, innerContents.content, localOpMetadata);
760
- }
761
-
762
- public async applyStashedOp(contents: any): Promise<unknown> {
763
- if (!this.channel) {
764
- await this.realize();
765
- }
766
- assert(!!this.channel, 0x14c /* "Channel must exist when rebasing ops" */);
767
- const innerContents = contents as FluidDataStoreMessage;
768
- return this.channel.applyStashedOp(innerContents.content);
769
- }
770
-
771
- private verifyNotClosed(callSite: string, checkTombstone = true, safeTelemetryProps: ITelemetryProperties = {}) {
772
- if (this._disposed) {
773
- throw new Error(`Context is closed! Call site [${callSite}]`);
774
- }
775
-
776
- if (checkTombstone && this.tombstoned) {
777
- const messageString = `Context is tombstoned! Call site [${callSite}]`;
778
- const error = new DataCorruptionError(messageString, {
779
- errorMessage: messageString,
780
- ...safeTelemetryProps,
781
- });
782
-
783
- // Always log an error when tombstoned data store is used. However, throw an error only if
784
- // throwOnTombstoneUsage is set.
785
- this.mc.logger.sendErrorEvent({
786
- eventName: "GC_Tombstone_DataStore_Changed",
787
- callSite,
788
- pkg: packagePathToTelemetryProperty(this.pkg),
789
- }, error);
790
- // Always log an error when tombstoned data store is used. However, throw an error only if
791
- // throwOnTombstoneUsage is set and the client is not a summarizer.
792
- if (this.throwOnTombstoneUsage) {
793
- throw error;
794
- }
795
- }
796
- }
797
-
798
- public getCreateChildSummarizerNodeFn(id: string, createParam: CreateChildSummarizerNodeParam) {
799
- return (
800
- summarizeInternal: SummarizeInternalFn,
801
- getGCDataFn: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
802
- getBaseGCDetailsFn: () => Promise<IGarbageCollectionDetailsBase>,
803
- ) => this.summarizerNode.createChild(
804
- summarizeInternal,
805
- id,
806
- createParam,
807
- // DDS will not create failure summaries
808
- { throwOnFailure: true },
809
- getGCDataFn,
810
- getBaseGCDetailsFn,
811
- );
812
- }
813
-
814
- public async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {
815
- return this.containerRuntime.uploadBlob(blob);
816
- }
143
+ export abstract class FluidDataStoreContext
144
+ extends TypedEventEmitter<IFluidDataStoreContextEvents>
145
+ implements IFluidDataStoreContext, IDisposable
146
+ {
147
+ public get packagePath(): readonly string[] {
148
+ assert(this.pkg !== undefined, 0x139 /* "Undefined package path" */);
149
+ return this.pkg;
150
+ }
151
+
152
+ public get options(): ILoaderOptions {
153
+ return this._containerRuntime.options;
154
+ }
155
+
156
+ public get clientId(): string | undefined {
157
+ return this._containerRuntime.clientId;
158
+ }
159
+
160
+ public get clientDetails(): IClientDetails {
161
+ return this._containerRuntime.clientDetails;
162
+ }
163
+
164
+ public get logger(): ITelemetryLogger {
165
+ return this._containerRuntime.logger;
166
+ }
167
+
168
+ public get deltaManager(): IDeltaManager<ISequencedDocumentMessage, IDocumentMessage> {
169
+ return this._containerRuntime.deltaManager;
170
+ }
171
+
172
+ public get connected(): boolean {
173
+ return this._containerRuntime.connected;
174
+ }
175
+
176
+ public get IFluidHandleContext() {
177
+ return this._containerRuntime.IFluidHandleContext;
178
+ }
179
+
180
+ public get containerRuntime(): IContainerRuntime {
181
+ return this._containerRuntime;
182
+ }
183
+
184
+ public ensureNoDataModelChanges<T>(callback: () => T): T {
185
+ return this._containerRuntime.ensureNoDataModelChanges(callback);
186
+ }
187
+
188
+ public get isLoaded(): boolean {
189
+ return this.loaded;
190
+ }
191
+
192
+ public get baseSnapshot(): ISnapshotTree | undefined {
193
+ return this._baseSnapshot;
194
+ }
195
+
196
+ private _disposed = false;
197
+ public get disposed() {
198
+ return this._disposed;
199
+ }
200
+
201
+ /**
202
+ * Tombstone is a temporary feature that prevents a data store from sending / receiving ops, signals and from
203
+ * loading.
204
+ */
205
+ private _tombstoned = false;
206
+ public get tombstoned() {
207
+ return this._tombstoned;
208
+ }
209
+ /** If true, throw an error when a tombstone data store is used. */
210
+ private readonly throwOnTombstoneUsage: boolean;
211
+
212
+ /** If true, this means that this data store context and its children have been removed from the runtime */
213
+ private deleted: boolean = false;
214
+
215
+ public get attachState(): AttachState {
216
+ return this._attachState;
217
+ }
218
+
219
+ public get IFluidDataStoreRegistry(): IFluidDataStoreRegistry | undefined {
220
+ return this.registry;
221
+ }
222
+
223
+ /**
224
+ * A datastore is considered as root if it
225
+ * 1. is root in memory - see isInMemoryRoot
226
+ * 2. is root as part of the base snapshot that the datastore loaded from
227
+ * @returns whether a datastore is root
228
+ */
229
+ public async isRoot(): Promise<boolean> {
230
+ return this.isInMemoryRoot() || (await this.getInitialSnapshotDetails()).isRootDataStore;
231
+ }
232
+
233
+ /**
234
+ * There are 3 states where isInMemoryRoot needs to be true
235
+ * 1. when a datastore becomes aliased. This can happen for both remote and local datastores
236
+ * 2. when a datastore is created locally as root
237
+ * 3. when a datastore is created locally as root and is rehydrated
238
+ * @returns whether a datastore is root in memory
239
+ */
240
+ protected isInMemoryRoot(): boolean {
241
+ return this._isInMemoryRoot;
242
+ }
243
+
244
+ protected registry: IFluidDataStoreRegistry | undefined;
245
+
246
+ protected detachedRuntimeCreation = false;
247
+ protected channel: IFluidDataStoreChannel | undefined;
248
+ private loaded = false;
249
+ protected pending: ISequencedDocumentMessage[] | undefined = [];
250
+ protected channelDeferred: Deferred<IFluidDataStoreChannel> | undefined;
251
+ private _baseSnapshot: ISnapshotTree | undefined;
252
+ protected _attachState: AttachState;
253
+ private _isInMemoryRoot: boolean = false;
254
+ protected readonly summarizerNode: ISummarizerNodeWithGC;
255
+ protected readonly mc: MonitoringContext;
256
+ private readonly thresholdOpsCounter: ThresholdCounter;
257
+ private static readonly pendingOpsCountThreshold = 1000;
258
+
259
+ /**
260
+ * If the summarizer makes local changes, a telemetry event is logged. This has the potential to be very noisy.
261
+ * So, adding a count of how many telemetry events are logged per data store context. This can be
262
+ * controlled via feature flags.
263
+ */
264
+ private localChangesTelemetryCount: number;
265
+
266
+ // The used routes of this node as per the last GC run. This is used to update the used routes of the channel
267
+ // if it realizes after GC is run.
268
+ private lastUsedRoutes: string[] | undefined;
269
+
270
+ public readonly id: string;
271
+ private readonly _containerRuntime: ContainerRuntime;
272
+ public readonly storage: IDocumentStorageService;
273
+ public readonly scope: FluidObject;
274
+ protected pkg?: readonly string[];
275
+
276
+ constructor(
277
+ props: IFluidDataStoreContextProps,
278
+ private readonly existing: boolean,
279
+ public readonly isLocalDataStore: boolean,
280
+ private readonly makeLocallyVisibleFn: () => void,
281
+ ) {
282
+ super();
283
+
284
+ this._containerRuntime = props.runtime;
285
+ this.id = props.id;
286
+ this.storage = props.storage;
287
+ this.scope = props.scope;
288
+ this.pkg = props.pkg;
289
+
290
+ // URIs use slashes as delimiters. Handles use URIs.
291
+ // Thus having slashes in types almost guarantees trouble down the road!
292
+ assert(!this.id.includes("/"), 0x13a /* Data store ID contains slash */);
293
+
294
+ this._attachState =
295
+ this.containerRuntime.attachState !== AttachState.Detached && this.existing
296
+ ? this.containerRuntime.attachState
297
+ : AttachState.Detached;
298
+
299
+ const thisSummarizeInternal = async (
300
+ fullTree: boolean,
301
+ trackState: boolean,
302
+ telemetryContext?: ITelemetryContext,
303
+ ) => this.summarizeInternal(fullTree, trackState, telemetryContext);
304
+
305
+ this.summarizerNode = props.createSummarizerNodeFn(
306
+ thisSummarizeInternal,
307
+ async (fullGC?: boolean) => this.getGCDataInternal(fullGC),
308
+ );
309
+
310
+ this.mc = loggerToMonitoringContext(
311
+ ChildLogger.create(this.logger, "FluidDataStoreContext"),
312
+ );
313
+ this.thresholdOpsCounter = new ThresholdCounter(
314
+ FluidDataStoreContext.pendingOpsCountThreshold,
315
+ this.mc.logger,
316
+ );
317
+
318
+ // Tombstone should only throw when the feature flag is enabled and the client isn't a summarizer
319
+ this.throwOnTombstoneUsage =
320
+ this.mc.config.getBoolean(throwOnTombstoneUsageKey) === true &&
321
+ this._containerRuntime.gcTombstoneEnforcementAllowed &&
322
+ this.clientDetails.type !== summarizerClientType;
323
+
324
+ // By default, a data store can log maximum 10 local changes telemetry in summarizer.
325
+ this.localChangesTelemetryCount =
326
+ this.mc.config.getNumber("Fluid.Telemetry.LocalChangesTelemetryCount") ?? 10;
327
+ }
328
+
329
+ public dispose(): void {
330
+ if (this._disposed) {
331
+ return;
332
+ }
333
+ this._disposed = true;
334
+
335
+ // Dispose any pending runtime after it gets fulfilled
336
+ // Errors are logged where this.channelDeferred is consumed/generated (realizeCore(), bindRuntime())
337
+ if (this.channelDeferred) {
338
+ this.channelDeferred.promise
339
+ .then((runtime) => {
340
+ runtime.dispose();
341
+ })
342
+ .catch((error) => {});
343
+ }
344
+ }
345
+
346
+ /**
347
+ * When delete is called, that means that the data store is permanently removed from the runtime, and will not show up in future summaries
348
+ * This function is called to prevent ops from being generated from this data store once it has been deleted. Furthermore, this data store
349
+ * should not receive any ops/signals.
350
+ */
351
+ public delete() {
352
+ this.deleted = true;
353
+ }
354
+
355
+ public setTombstone(tombstone: boolean) {
356
+ if (this.tombstoned === tombstone) {
357
+ return;
358
+ }
359
+
360
+ this._tombstoned = tombstone;
361
+ }
362
+
363
+ private rejectDeferredRealize(
364
+ reason: string,
365
+ failedPkgPath?: string,
366
+ fullPackageName?: readonly string[],
367
+ ): never {
368
+ throw new LoggingError(reason, {
369
+ failedPkgPath: { value: failedPkgPath, tag: TelemetryDataTag.CodeArtifact },
370
+ fullPackageName: packagePathToTelemetryProperty(fullPackageName),
371
+ });
372
+ }
373
+
374
+ public async realize(): Promise<IFluidDataStoreChannel> {
375
+ assert(!this.detachedRuntimeCreation, 0x13d /* "Detached runtime creation on realize()" */);
376
+ if (!this.channelDeferred) {
377
+ this.channelDeferred = new Deferred<IFluidDataStoreChannel>();
378
+ this.realizeCore(this.existing).catch((error) => {
379
+ const errorWrapped = DataProcessingError.wrapIfUnrecognized(
380
+ error,
381
+ "realizeFluidDataStoreContext",
382
+ );
383
+ errorWrapped.addTelemetryProperties({
384
+ fluidDataStoreId: {
385
+ value: this.id,
386
+ tag: TelemetryDataTag.CodeArtifact,
387
+ },
388
+ packageName: packagePathToTelemetryProperty(this.pkg),
389
+ });
390
+ this.channelDeferred?.reject(errorWrapped);
391
+ this.logger.sendErrorEvent({ eventName: "RealizeError" }, errorWrapped);
392
+ });
393
+ }
394
+ return this.channelDeferred.promise;
395
+ }
396
+
397
+ protected async factoryFromPackagePath(packages?: readonly string[]) {
398
+ assert(this.pkg === packages, 0x13e /* "Unexpected package path" */);
399
+ if (packages === undefined) {
400
+ this.rejectDeferredRealize("packages is undefined");
401
+ }
402
+
403
+ let entry: FluidDataStoreRegistryEntry | undefined;
404
+ let registry: IFluidDataStoreRegistry | undefined =
405
+ this._containerRuntime.IFluidDataStoreRegistry;
406
+ let lastPkg: string | undefined;
407
+ for (const pkg of packages) {
408
+ if (!registry) {
409
+ this.rejectDeferredRealize("No registry for package", lastPkg, packages);
410
+ }
411
+ lastPkg = pkg;
412
+ entry = await registry.get(pkg);
413
+ if (!entry) {
414
+ this.rejectDeferredRealize(
415
+ "Registry does not contain entry for the package",
416
+ pkg,
417
+ packages,
418
+ );
419
+ }
420
+ registry = entry.IFluidDataStoreRegistry;
421
+ }
422
+ const factory = entry?.IFluidDataStoreFactory;
423
+ if (factory === undefined) {
424
+ this.rejectDeferredRealize("Can't find factory for package", lastPkg, packages);
425
+ }
426
+
427
+ return { factory, registry };
428
+ }
429
+
430
+ private async realizeCore(existing: boolean): Promise<void> {
431
+ const details = await this.getInitialSnapshotDetails();
432
+ // Base snapshot is the baseline where pending ops are applied to.
433
+ // It is important that this be in sync with the pending ops, and also
434
+ // that it is set here, before bindRuntime is called.
435
+ this._baseSnapshot = details.snapshot;
436
+ const packages = details.pkg;
437
+
438
+ const { factory, registry } = await this.factoryFromPackagePath(packages);
439
+
440
+ assert(
441
+ this.registry === undefined,
442
+ 0x13f /* "datastore context registry is already set" */,
443
+ );
444
+ this.registry = registry;
445
+
446
+ const channel = await factory.instantiateDataStore(this, existing);
447
+ assert(channel !== undefined, 0x140 /* "undefined channel on datastore context" */);
448
+ this.bindRuntime(channel);
449
+ }
450
+
451
+ /**
452
+ * Notifies this object about changes in the connection state.
453
+ * @param value - New connection state.
454
+ * @param clientId - ID of the client. Its old ID when in disconnected state and
455
+ * its new client ID when we are connecting or connected.
456
+ */
457
+ public setConnectionState(connected: boolean, clientId?: string) {
458
+ // ConnectionState should not fail in tombstone mode as this is internally run
459
+ this.verifyNotClosed("setConnectionState", false /* checkTombstone */);
460
+
461
+ // Connection events are ignored if the store is not yet loaded
462
+ if (!this.loaded) {
463
+ return;
464
+ }
465
+
466
+ assert(this.connected === connected, 0x141 /* "Unexpected connected state" */);
467
+
468
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
469
+ this.channel!.setConnectionState(connected, clientId);
470
+ }
471
+
472
+ public process(
473
+ messageArg: ISequencedDocumentMessage,
474
+ local: boolean,
475
+ localOpMetadata: unknown,
476
+ ): void {
477
+ this.verifyNotClosed("process", true, extractSafePropertiesFromMessage(messageArg));
478
+
479
+ const innerContents = messageArg.contents as FluidDataStoreMessage;
480
+ const message = {
481
+ ...messageArg,
482
+ type: innerContents.type,
483
+ contents: innerContents.content,
484
+ };
485
+
486
+ this.summarizerNode.recordChange(message);
487
+
488
+ if (this.loaded) {
489
+ return this.channel?.process(message, local, localOpMetadata);
490
+ } else {
491
+ assert(!local, 0x142 /* "local store channel is not loaded" */);
492
+ assert(this.pending !== undefined, 0x23d /* "pending is undefined" */);
493
+ this.pending.push(message);
494
+ this.thresholdOpsCounter.sendIfMultiple("StorePendingOps", this.pending.length);
495
+ }
496
+ }
497
+
498
+ public processSignal(message: IInboundSignalMessage, local: boolean): void {
499
+ this.verifyNotClosed("processSignal");
500
+
501
+ // Signals are ignored if the store is not yet loaded
502
+ if (!this.loaded) {
503
+ return;
504
+ }
505
+
506
+ this.channel?.processSignal(message, local);
507
+ }
508
+
509
+ public getQuorum(): IQuorumClients {
510
+ return this._containerRuntime.getQuorum();
511
+ }
512
+
513
+ public getAudience(): IAudience {
514
+ return this._containerRuntime.getAudience();
515
+ }
516
+
517
+ /**
518
+ * Returns a summary at the current sequence number.
519
+ * @param fullTree - true to bypass optimizations and force a full summary tree
520
+ * @param trackState - This tells whether we should track state from this summary.
521
+ * @param telemetryContext - summary data passed through the layers for telemetry purposes
522
+ */
523
+ public async summarize(
524
+ fullTree: boolean = false,
525
+ trackState: boolean = true,
526
+ telemetryContext?: ITelemetryContext,
527
+ ): Promise<ISummarizeResult> {
528
+ return this.summarizerNode.summarize(fullTree, trackState, telemetryContext);
529
+ }
530
+
531
+ private async summarizeInternal(
532
+ fullTree: boolean,
533
+ trackState: boolean,
534
+ telemetryContext?: ITelemetryContext,
535
+ ): Promise<ISummarizeInternalResult> {
536
+ await this.realize();
537
+
538
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
539
+ const summarizeResult = await this.channel!.summarize(
540
+ fullTree,
541
+ trackState,
542
+ telemetryContext,
543
+ );
544
+
545
+ // Wrap dds summaries in .channels subtree.
546
+ wrapSummaryInChannelsTree(summarizeResult);
547
+ const pathPartsForChildren = [channelsTreeName];
548
+
549
+ // Add data store's attributes to the summary.
550
+ const { pkg } = await this.getInitialSnapshotDetails();
551
+ const isRoot = await this.isRoot();
552
+ const attributes = createAttributes(pkg, isRoot);
553
+ addBlobToSummary(summarizeResult, dataStoreAttributesBlobName, JSON.stringify(attributes));
554
+
555
+ // If we are not referenced, mark the summary tree as unreferenced. Also, update unreferenced blob
556
+ // size in the summary stats with the blobs size of this data store.
557
+ if (!this.summarizerNode.isReferenced()) {
558
+ summarizeResult.summary.unreferenced = true;
559
+ summarizeResult.stats.unreferencedBlobSize = summarizeResult.stats.totalBlobSize;
560
+ }
561
+
562
+ return {
563
+ ...summarizeResult,
564
+ id: this.id,
565
+ pathPartsForChildren,
566
+ };
567
+ }
568
+
569
+ /**
570
+ * Returns the data used for garbage collection. This includes a list of GC nodes that represent this data store
571
+ * including any of its child channel contexts. Each node has a set of outbound routes to other GC nodes in the
572
+ * document.
573
+ * If there is no new data in this data store since the last summary, previous GC data is used.
574
+ * If there is new data, the GC data is generated again (by calling getGCDataInternal).
575
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
576
+ */
577
+ public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
578
+ return this.summarizerNode.getGCData(fullGC);
579
+ }
580
+
581
+ /**
582
+ * Generates data used for garbage collection. This is called when there is new data since last summary. It
583
+ * realizes the data store and calls into each channel context to get its GC data.
584
+ * @param fullGC - true to bypass optimizations and force full generation of GC data.
585
+ */
586
+ private async getGCDataInternal(fullGC: boolean = false): Promise<IGarbageCollectionData> {
587
+ await this.realize();
588
+ assert(
589
+ this.channel !== undefined,
590
+ 0x143 /* "Channel should not be undefined when running GC" */,
591
+ );
592
+
593
+ return this.channel.getGCData(fullGC);
594
+ }
595
+
596
+ /**
597
+ * After GC has run, called to notify the data store of routes used in it. These are used for the following:
598
+ *
599
+ * 1. To identify if this data store is being referenced in the document or not.
600
+ *
601
+ * 2. To determine if it needs to re-summarize in case used routes changed since last summary.
602
+ *
603
+ * 3. These are added to the summary generated by the data store.
604
+ *
605
+ * 4. To notify child contexts of their used routes. This is done immediately if the data store is loaded.
606
+ * Else, it is done when realizing the data store.
607
+ *
608
+ * 5. To update the timestamp when this data store or any children are marked as unreferenced.
609
+ *
610
+ * @param usedRoutes - The routes that are used in this data store.
611
+ */
612
+ public updateUsedRoutes(usedRoutes: string[]) {
613
+ // Update the used routes in this data store's summarizer node.
614
+ this.summarizerNode.updateUsedRoutes(usedRoutes);
615
+
616
+ /**
617
+ * Store the used routes to update the channel if the data store is not loaded yet. If the used routes changed
618
+ * since the previous run, the data store will be loaded during summarize since the used state changed. So, it's
619
+ * safe to only store the last used routes.
620
+ */
621
+ this.lastUsedRoutes = usedRoutes;
622
+
623
+ // If we are loaded, call the channel so it can update the used routes of the child contexts.
624
+ // If we are not loaded, we will update this when we are realized.
625
+ if (this.loaded) {
626
+ this.updateChannelUsedRoutes();
627
+ }
628
+ }
629
+
630
+ /**
631
+ * Called when a new outbound reference is added to another node. This is used by garbage collection to identify
632
+ * all references added in the system.
633
+ * @param srcHandle - The handle of the node that added the reference.
634
+ * @param outboundHandle - The handle of the outbound node that is referenced.
635
+ */
636
+ public addedGCOutboundReference(srcHandle: IFluidHandle, outboundHandle: IFluidHandle) {
637
+ this._containerRuntime.addedGCOutboundReference(srcHandle, outboundHandle);
638
+ }
639
+
640
+ /**
641
+ * Updates the used routes of the channel and its child contexts. The channel must be loaded before calling this.
642
+ * It is called in these two scenarios:
643
+ * 1. When the used routes of the data store is updated and the data store is loaded.
644
+ * 2. When the data store is realized. This updates the channel's used routes as per last GC run.
645
+ */
646
+ private updateChannelUsedRoutes() {
647
+ assert(this.loaded, 0x144 /* "Channel should be loaded when updating used routes" */);
648
+ assert(
649
+ this.channel !== undefined,
650
+ 0x145 /* "Channel should be present when data store is loaded" */,
651
+ );
652
+
653
+ // If there is no lastUsedRoutes, GC has not run up until this point.
654
+ if (this.lastUsedRoutes === undefined) {
655
+ return;
656
+ }
657
+
658
+ // Remove the route to this data store, if it exists.
659
+ const usedChannelRoutes = this.lastUsedRoutes.filter((id: string) => {
660
+ return id !== "/" && id !== "";
661
+ });
662
+ this.channel.updateUsedRoutes(usedChannelRoutes);
663
+ }
664
+
665
+ /**
666
+ * @deprecated 0.18.Should call request on the runtime directly
667
+ */
668
+ public async request(request: IRequest): Promise<IResponse> {
669
+ const runtime = await this.realize();
670
+ return runtime.request(request);
671
+ }
672
+
673
+ public submitMessage(type: string, content: any, localOpMetadata: unknown): void {
674
+ this.verifyNotClosed("submitMessage");
675
+ assert(!!this.channel, 0x146 /* "Channel must exist when submitting message" */);
676
+ const fluidDataStoreContent: FluidDataStoreMessage = {
677
+ content,
678
+ type,
679
+ };
680
+
681
+ // Summarizer clients should not submit messages.
682
+ this.identifyLocalChangeInSummarizer("DataStoreMessageSubmittedInSummarizer", type);
683
+
684
+ this._containerRuntime.submitDataStoreOp(this.id, fluidDataStoreContent, localOpMetadata);
685
+ }
686
+
687
+ /**
688
+ * This is called from a SharedSummaryBlock that does not generate ops but only wants to be part of the summary.
689
+ * It indicates that there is data in the object that needs to be summarized.
690
+ * We will update the latestSequenceNumber of the summary tracker of this
691
+ * store and of the object's channel.
692
+ *
693
+ * @param address - The address of the channel that is dirty.
694
+ *
695
+ */
696
+ public setChannelDirty(address: string): void {
697
+ this.verifyNotClosed("setChannelDirty");
698
+
699
+ // Get the latest sequence number.
700
+ const latestSequenceNumber = this.deltaManager.lastSequenceNumber;
701
+
702
+ this.summarizerNode.invalidate(latestSequenceNumber);
703
+
704
+ const channelSummarizerNode = this.summarizerNode.getChild(address);
705
+
706
+ if (channelSummarizerNode) {
707
+ channelSummarizerNode.invalidate(latestSequenceNumber); // TODO: lazy load problem?
708
+ }
709
+ }
710
+
711
+ public submitSignal(type: string, content: any) {
712
+ this.verifyNotClosed("submitSignal");
713
+
714
+ assert(!!this.channel, 0x147 /* "Channel must exist on submitting signal" */);
715
+ return this._containerRuntime.submitDataStoreSignal(this.id, type, content);
716
+ }
717
+
718
+ /**
719
+ * This is called by the data store channel when it becomes locally visible indicating that it is ready to become
720
+ * globally visible now.
721
+ */
722
+ public makeLocallyVisible() {
723
+ assert(this.channel !== undefined, 0x2cf /* "undefined channel on datastore context" */);
724
+ assert(
725
+ this.channel.visibilityState === VisibilityState.LocallyVisible,
726
+ 0x590 /* Channel must be locally visible */,
727
+ );
728
+ this.makeLocallyVisibleFn();
729
+ }
730
+
731
+ /** @deprecated - To be replaced by calling makeLocallyVisible directly */
732
+ public bindToContext() {
733
+ this.makeLocallyVisibleFn();
734
+ }
735
+
736
+ protected bindRuntime(channel: IFluidDataStoreChannel) {
737
+ if (this.channel) {
738
+ throw new Error("Runtime already bound");
739
+ }
740
+
741
+ try {
742
+ assert(
743
+ !this.detachedRuntimeCreation,
744
+ 0x148 /* "Detached runtime creation on runtime bind" */,
745
+ );
746
+ assert(this.channelDeferred !== undefined, 0x149 /* "Undefined channel deferral" */);
747
+ assert(this.pkg !== undefined, 0x14a /* "Undefined package path" */);
748
+
749
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
750
+ const pending = this.pending!;
751
+
752
+ // Apply all pending ops
753
+ for (const op of pending) {
754
+ channel.process(op, false, undefined /* localOpMetadata */);
755
+ }
756
+
757
+ this.thresholdOpsCounter.send("ProcessPendingOps", pending.length);
758
+ this.pending = undefined;
759
+
760
+ // And now mark the runtime active
761
+ this.loaded = true;
762
+ this.channel = channel;
763
+
764
+ // Freeze the package path to ensure that someone doesn't modify it when it is
765
+ // returned in packagePath().
766
+ Object.freeze(this.pkg);
767
+
768
+ /**
769
+ * Update the used routes of the channel. If GC has run before this data store was realized, we will have
770
+ * the used routes saved. So, this will ensure that all the child contexts have up-to-date used routes as
771
+ * per the last time GC was run.
772
+ * Also, this data store may have been realized during summarize. In that case, the child contexts need to
773
+ * have their used routes updated to determine if its needs to summarize again and to add it to the summary.
774
+ */
775
+ this.updateChannelUsedRoutes();
776
+
777
+ // And notify the pending promise it is now available
778
+ this.channelDeferred.resolve(this.channel);
779
+ } catch (error) {
780
+ this.channelDeferred?.reject(error);
781
+ this.logger.sendErrorEvent(
782
+ {
783
+ eventName: "BindRuntimeError",
784
+ fluidDataStoreId: {
785
+ value: this.id,
786
+ tag: TelemetryDataTag.CodeArtifact,
787
+ },
788
+ },
789
+ error,
790
+ );
791
+ }
792
+ }
793
+
794
+ public async getAbsoluteUrl(relativeUrl: string): Promise<string | undefined> {
795
+ if (this.attachState !== AttachState.Attached) {
796
+ return undefined;
797
+ }
798
+ return this._containerRuntime.getAbsoluteUrl(relativeUrl);
799
+ }
800
+
801
+ public abstract generateAttachMessage(): IAttachMessage;
802
+
803
+ public abstract getInitialSnapshotDetails(): Promise<ISnapshotDetails>;
804
+
805
+ /**
806
+ * @deprecated Sets the datastore as root, for aliasing purposes: #7948
807
+ * This method should not be used outside of the aliasing context.
808
+ * It will be removed, as the source of truth for this flag will be the aliasing blob.
809
+ */
810
+ public setInMemoryRoot(): void {
811
+ this._isInMemoryRoot = true;
812
+ }
813
+
814
+ /**
815
+ * @deprecated - The functionality to get base GC details has been moved to summarizer node.
816
+ */
817
+ public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
818
+ return {};
819
+ }
820
+
821
+ public reSubmit(contents: any, localOpMetadata: unknown) {
822
+ assert(!!this.channel, 0x14b /* "Channel must exist when resubmitting ops" */);
823
+ const innerContents = contents as FluidDataStoreMessage;
824
+ this.channel.reSubmit(innerContents.type, innerContents.content, localOpMetadata);
825
+ }
826
+
827
+ public rollback(contents: any, localOpMetadata: unknown) {
828
+ if (!this.channel) {
829
+ throw new Error("Channel must exist when rolling back ops");
830
+ }
831
+ if (!this.channel.rollback) {
832
+ throw new Error("Channel doesn't support rollback");
833
+ }
834
+ const innerContents = contents as FluidDataStoreMessage;
835
+ this.channel.rollback(innerContents.type, innerContents.content, localOpMetadata);
836
+ }
837
+
838
+ public async applyStashedOp(contents: any): Promise<unknown> {
839
+ if (!this.channel) {
840
+ await this.realize();
841
+ }
842
+ assert(!!this.channel, 0x14c /* "Channel must exist when rebasing ops" */);
843
+ const innerContents = contents as FluidDataStoreMessage;
844
+ return this.channel.applyStashedOp(innerContents.content);
845
+ }
846
+
847
+ private verifyNotClosed(
848
+ callSite: string,
849
+ checkTombstone = true,
850
+ safeTelemetryProps: ITelemetryProperties = {},
851
+ ) {
852
+ if (this.deleted) {
853
+ const messageString = `Context is deleted! Call site [${callSite}]`;
854
+ const error = new DataCorruptionError(messageString, safeTelemetryProps);
855
+ this.mc.logger.sendErrorEvent(
856
+ {
857
+ eventName: "GC_Deleted_DataStore_Changed",
858
+ callSite,
859
+ },
860
+ error,
861
+ );
862
+
863
+ throw error;
864
+ }
865
+
866
+ if (this._disposed) {
867
+ throw new Error(`Context is closed! Call site [${callSite}]`);
868
+ }
869
+
870
+ if (checkTombstone && this.tombstoned) {
871
+ const messageString = `Context is tombstoned! Call site [${callSite}]`;
872
+ const error = new DataCorruptionError(messageString, safeTelemetryProps);
873
+
874
+ sendGCUnexpectedUsageEvent(
875
+ this.mc,
876
+ {
877
+ eventName: "GC_Tombstone_DataStore_Changed",
878
+ category: this.throwOnTombstoneUsage ? "error" : "generic",
879
+ gcTombstoneEnforcementAllowed:
880
+ this._containerRuntime.gcTombstoneEnforcementAllowed,
881
+ callSite,
882
+ },
883
+ this.pkg,
884
+ error,
885
+ );
886
+ if (this.throwOnTombstoneUsage) {
887
+ throw error;
888
+ }
889
+ }
890
+ }
891
+
892
+ /**
893
+ * Summarizer client should not have local changes. These changes can become part of the summary and can break
894
+ * eventual consistency. For example, the next summary (say at ref seq# 100) may contain these changes whereas
895
+ * other clients that are up-to-date till seq# 100 may not have them yet.
896
+ */
897
+ protected identifyLocalChangeInSummarizer(eventName: string, type?: string) {
898
+ if (
899
+ this.clientDetails.type !== summarizerClientType ||
900
+ this.localChangesTelemetryCount <= 0
901
+ ) {
902
+ return;
903
+ }
904
+
905
+ // Log a telemetry if there are local changes in the summarizer. This will give us data on how often
906
+ // this is happening and which data stores do this. The eventual goal is to disallow local changes
907
+ // in the summarizer and the data will help us plan this.
908
+ this.mc.logger.sendTelemetryEvent({
909
+ eventName,
910
+ type,
911
+ fluidDataStoreId: {
912
+ value: this.id,
913
+ tag: TelemetryDataTag.CodeArtifact,
914
+ },
915
+ packageName: packagePathToTelemetryProperty(this.pkg),
916
+ isSummaryInProgress: this.summarizerNode.isSummaryInProgress?.(),
917
+ stack: generateStack(),
918
+ });
919
+ this.localChangesTelemetryCount--;
920
+ }
921
+
922
+ public getCreateChildSummarizerNodeFn(id: string, createParam: CreateChildSummarizerNodeParam) {
923
+ return (
924
+ summarizeInternal: SummarizeInternalFn,
925
+ getGCDataFn: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
926
+ ) =>
927
+ this.summarizerNode.createChild(
928
+ summarizeInternal,
929
+ id,
930
+ createParam,
931
+ // DDS will not create failure summaries
932
+ { throwOnFailure: true },
933
+ getGCDataFn,
934
+ );
935
+ }
936
+
937
+ public async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {
938
+ return this.containerRuntime.uploadBlob(blob);
939
+ }
817
940
  }
818
941
 
819
942
  export class RemoteFluidDataStoreContext extends FluidDataStoreContext {
820
- private readonly initSnapshotValue: ISnapshotTree | undefined;
821
- private readonly baseGCDetailsP: Promise<IGarbageCollectionDetailsBase>;
822
-
823
- constructor(props: IRemoteFluidDataStoreContextProps) {
824
- super(
825
- props,
826
- true /* existing */,
827
- BindState.Bound,
828
- false /* isLocalDataStore */,
829
- () => {
830
- throw new Error("Already attached");
831
- },
832
- );
833
-
834
- this.initSnapshotValue = props.snapshotTree;
835
- this.baseGCDetailsP = new LazyPromise<IGarbageCollectionDetailsBase>(async () => {
836
- return (await props.getBaseGCDetails()) ?? {};
837
- });
838
-
839
- if (props.snapshotTree !== undefined) {
840
- this.summarizerNode.updateBaseSummaryState(props.snapshotTree);
841
- }
842
- }
843
-
844
- private readonly initialSnapshotDetailsP = new LazyPromise<ISnapshotDetails>(async () => {
845
- let tree = this.initSnapshotValue;
846
- let isRootDataStore = true;
847
-
848
- if (!!tree && tree.blobs[dataStoreAttributesBlobName] !== undefined) {
849
- // Need to get through snapshot and use that to populate extraBlobs
850
- const attributes =
851
- await readAndParse<ReadFluidDataStoreAttributes>(this.storage, tree.blobs[dataStoreAttributesBlobName]);
852
-
853
- let pkgFromSnapshot: string[];
854
- // Use the snapshotFormatVersion to determine how the pkg is encoded in the snapshot.
855
- // For snapshotFormatVersion = "0.1" (1) or above, pkg is jsonified, otherwise it is just a string.
856
- const formatVersion = getAttributesFormatVersion(attributes);
857
- if (formatVersion < 1) {
858
- pkgFromSnapshot = attributes.pkg.startsWith("[\"") && attributes.pkg.endsWith("\"]")
859
- ? JSON.parse(attributes.pkg) as string[]
860
- : [attributes.pkg];
861
- } else {
862
- pkgFromSnapshot = JSON.parse(attributes.pkg) as string[];
863
- }
864
- this.pkg = pkgFromSnapshot;
865
-
866
- /**
867
- * If there is no isRootDataStore in the attributes blob, set it to true. This will ensure that
868
- * data stores in older documents are not garbage collected incorrectly. This may lead to additional
869
- * roots in the document but they won't break.
870
- */
871
- isRootDataStore = attributes.isRootDataStore ?? true;
872
-
873
- if (hasIsolatedChannels(attributes)) {
874
- tree = tree.trees[channelsTreeName];
875
- assert(tree !== undefined,
876
- 0x1fe /* "isolated channels subtree should exist in remote datastore snapshot" */);
877
- }
878
- }
879
-
880
- return {
881
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
882
- pkg: this.pkg!,
883
- isRootDataStore,
884
- snapshot: tree,
885
- };
886
- });
887
-
888
- public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
889
- return this.initialSnapshotDetailsP;
890
- }
891
-
892
- public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
893
- return this.baseGCDetailsP;
894
- }
895
-
896
- public generateAttachMessage(): IAttachMessage {
897
- throw new Error("Cannot attach remote store");
898
- }
943
+ private readonly initSnapshotValue: ISnapshotTree | undefined;
944
+
945
+ constructor(props: IRemoteFluidDataStoreContextProps) {
946
+ super(props, true /* existing */, false /* isLocalDataStore */, () => {
947
+ throw new Error("Already attached");
948
+ });
949
+
950
+ this.initSnapshotValue = props.snapshotTree;
951
+
952
+ if (props.snapshotTree !== undefined) {
953
+ this.summarizerNode.updateBaseSummaryState(props.snapshotTree);
954
+ }
955
+ }
956
+
957
+ private readonly initialSnapshotDetailsP = new LazyPromise<ISnapshotDetails>(async () => {
958
+ let tree = this.initSnapshotValue;
959
+ let isRootDataStore = true;
960
+
961
+ if (!!tree && tree.blobs[dataStoreAttributesBlobName] !== undefined) {
962
+ // Need to get through snapshot and use that to populate extraBlobs
963
+ const attributes = await readAndParse<ReadFluidDataStoreAttributes>(
964
+ this.storage,
965
+ tree.blobs[dataStoreAttributesBlobName],
966
+ );
967
+
968
+ let pkgFromSnapshot: string[];
969
+ // Use the snapshotFormatVersion to determine how the pkg is encoded in the snapshot.
970
+ // For snapshotFormatVersion = "0.1" (1) or above, pkg is jsonified, otherwise it is just a string.
971
+ const formatVersion = getAttributesFormatVersion(attributes);
972
+ if (formatVersion < 1) {
973
+ pkgFromSnapshot =
974
+ attributes.pkg.startsWith('["') && attributes.pkg.endsWith('"]')
975
+ ? (JSON.parse(attributes.pkg) as string[])
976
+ : [attributes.pkg];
977
+ } else {
978
+ pkgFromSnapshot = JSON.parse(attributes.pkg) as string[];
979
+ }
980
+ this.pkg = pkgFromSnapshot;
981
+
982
+ /**
983
+ * If there is no isRootDataStore in the attributes blob, set it to true. This will ensure that
984
+ * data stores in older documents are not garbage collected incorrectly. This may lead to additional
985
+ * roots in the document but they won't break.
986
+ */
987
+ isRootDataStore = attributes.isRootDataStore ?? true;
988
+
989
+ if (hasIsolatedChannels(attributes)) {
990
+ tree = tree.trees[channelsTreeName];
991
+ assert(
992
+ tree !== undefined,
993
+ 0x1fe /* "isolated channels subtree should exist in remote datastore snapshot" */,
994
+ );
995
+ }
996
+ }
997
+
998
+ return {
999
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
1000
+ pkg: this.pkg!,
1001
+ isRootDataStore,
1002
+ snapshot: tree,
1003
+ };
1004
+ });
1005
+
1006
+ public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
1007
+ return this.initialSnapshotDetailsP;
1008
+ }
1009
+
1010
+ public generateAttachMessage(): IAttachMessage {
1011
+ throw new Error("Cannot attach remote store");
1012
+ }
899
1013
  }
900
1014
 
901
1015
  /**
902
1016
  * Base class for detached & attached context classes
903
1017
  */
904
1018
  export class LocalFluidDataStoreContextBase extends FluidDataStoreContext {
905
- private readonly snapshotTree: ISnapshotTree | undefined;
906
- /**
907
- * @deprecated 0.16 Issue #1635, #3631
908
- */
909
- public readonly createProps?: any;
910
-
911
- constructor(props: ILocalFluidDataStoreContextProps) {
912
- super(
913
- props,
914
- props.snapshotTree !== undefined ? true : false /* existing */,
915
- props.snapshotTree ? BindState.Bound : BindState.NotBound,
916
- true /* isLocalDataStore */,
917
- props.makeLocallyVisibleFn,
918
- );
919
-
920
- this.snapshotTree = props.snapshotTree;
921
- if (props.isRootDataStore === true) {
922
- this.setInMemoryRoot();
923
- }
924
- this.createProps = props.createProps;
925
- this.attachListeners();
926
- }
927
-
928
- private attachListeners(): void {
929
- this.once("attaching", () => {
930
- assert(this.attachState === AttachState.Detached, 0x14d /* "Should move from detached to attaching" */);
931
- this._attachState = AttachState.Attaching;
932
- });
933
- this.once("attached", () => {
934
- assert(this.attachState === AttachState.Attaching, 0x14e /* "Should move from attaching to attached" */);
935
- this._attachState = AttachState.Attached;
936
- });
937
- }
938
-
939
- public generateAttachMessage(): IAttachMessage {
940
- assert(this.channel !== undefined, 0x14f /* "There should be a channel when generating attach message" */);
941
- assert(this.pkg !== undefined, 0x150 /* "pkg should be available in local data store context" */);
942
-
943
- const summarizeResult = this.channel.getAttachSummary();
944
-
945
- // Wrap dds summaries in .channels subtree.
946
- wrapSummaryInChannelsTree(summarizeResult);
947
-
948
- // Add data store's attributes to the summary.
949
- const attributes = createAttributes(
950
- this.pkg,
951
- this.isInMemoryRoot(),
952
- );
953
- addBlobToSummary(summarizeResult, dataStoreAttributesBlobName, JSON.stringify(attributes));
954
-
955
- // Attach message needs the summary in ITree format. Convert the ISummaryTree into an ITree.
956
- const snapshot = convertSummaryTreeToITree(summarizeResult.summary);
957
-
958
- const message: IAttachMessage = {
959
- id: this.id,
960
- snapshot,
961
- type: this.pkg[this.pkg.length - 1],
962
- };
963
-
964
- return message;
965
- }
966
-
967
- public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
968
- let snapshot = this.snapshotTree;
969
- let attributes: ReadFluidDataStoreAttributes;
970
- let isRootDataStore = false;
971
- if (snapshot !== undefined) {
972
- // Get the dataStore attributes.
973
- // Note: storage can be undefined in special case while detached.
974
- attributes = await getFluidDataStoreAttributes(this.storage, snapshot);
975
- if (hasIsolatedChannels(attributes)) {
976
- snapshot = snapshot.trees[channelsTreeName];
977
- assert(snapshot !== undefined,
978
- 0x1ff /* "isolated channels subtree should exist in local datastore snapshot" */);
979
- }
980
- if (this.pkg === undefined) {
981
- this.pkg = JSON.parse(attributes.pkg) as string[];
982
- // If there is no isRootDataStore in the attributes blob, set it to true. This ensures that data
983
- // stores in older documents are not garbage collected incorrectly. This may lead to additional
984
- // roots in the document but they won't break.
985
- if (attributes.isRootDataStore ?? true) {
986
- isRootDataStore = true;
987
- this.setInMemoryRoot();
988
- }
989
- }
990
- }
991
- assert(this.pkg !== undefined, 0x152 /* "pkg should be available in local data store" */);
992
-
993
- return {
994
- pkg: this.pkg,
995
- isRootDataStore,
996
- snapshot,
997
- };
998
- }
999
-
1000
- public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
1001
- // Local data store does not have initial summary.
1002
- return {};
1003
- }
1019
+ private readonly snapshotTree: ISnapshotTree | undefined;
1020
+ /**
1021
+ * @deprecated 0.16 Issue #1635, #3631
1022
+ */
1023
+ public readonly createProps?: any;
1024
+
1025
+ constructor(props: ILocalFluidDataStoreContextProps) {
1026
+ super(
1027
+ props,
1028
+ props.snapshotTree !== undefined ? true : false /* existing */,
1029
+ true /* isLocalDataStore */,
1030
+ props.makeLocallyVisibleFn,
1031
+ );
1032
+
1033
+ // Summarizer client should not create local data stores.
1034
+ this.identifyLocalChangeInSummarizer("DataStoreCreatedInSummarizer");
1035
+
1036
+ this.snapshotTree = props.snapshotTree;
1037
+ if (props.isRootDataStore === true) {
1038
+ this.setInMemoryRoot();
1039
+ }
1040
+ this.createProps = props.createProps;
1041
+ this.attachListeners();
1042
+ }
1043
+
1044
+ private attachListeners(): void {
1045
+ this.once("attaching", () => {
1046
+ assert(
1047
+ this.attachState === AttachState.Detached,
1048
+ 0x14d /* "Should move from detached to attaching" */,
1049
+ );
1050
+ this._attachState = AttachState.Attaching;
1051
+ });
1052
+ this.once("attached", () => {
1053
+ assert(
1054
+ this.attachState === AttachState.Attaching,
1055
+ 0x14e /* "Should move from attaching to attached" */,
1056
+ );
1057
+ this._attachState = AttachState.Attached;
1058
+ });
1059
+ }
1060
+
1061
+ public generateAttachMessage(): IAttachMessage {
1062
+ assert(
1063
+ this.channel !== undefined,
1064
+ 0x14f /* "There should be a channel when generating attach message" */,
1065
+ );
1066
+ assert(
1067
+ this.pkg !== undefined,
1068
+ 0x150 /* "pkg should be available in local data store context" */,
1069
+ );
1070
+
1071
+ const summarizeResult = this.channel.getAttachSummary();
1072
+
1073
+ // Wrap dds summaries in .channels subtree.
1074
+ wrapSummaryInChannelsTree(summarizeResult);
1075
+
1076
+ // Add data store's attributes to the summary.
1077
+ const attributes = createAttributes(this.pkg, this.isInMemoryRoot());
1078
+ addBlobToSummary(summarizeResult, dataStoreAttributesBlobName, JSON.stringify(attributes));
1079
+
1080
+ // Attach message needs the summary in ITree format. Convert the ISummaryTree into an ITree.
1081
+ const snapshot = convertSummaryTreeToITree(summarizeResult.summary);
1082
+
1083
+ const message: IAttachMessage = {
1084
+ id: this.id,
1085
+ snapshot,
1086
+ type: this.pkg[this.pkg.length - 1],
1087
+ };
1088
+
1089
+ return message;
1090
+ }
1091
+
1092
+ public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
1093
+ let snapshot = this.snapshotTree;
1094
+ let attributes: ReadFluidDataStoreAttributes;
1095
+ let isRootDataStore = false;
1096
+ if (snapshot !== undefined) {
1097
+ // Get the dataStore attributes.
1098
+ // Note: storage can be undefined in special case while detached.
1099
+ attributes = await getFluidDataStoreAttributes(this.storage, snapshot);
1100
+ if (hasIsolatedChannels(attributes)) {
1101
+ snapshot = snapshot.trees[channelsTreeName];
1102
+ assert(
1103
+ snapshot !== undefined,
1104
+ 0x1ff /* "isolated channels subtree should exist in local datastore snapshot" */,
1105
+ );
1106
+ }
1107
+ if (this.pkg === undefined) {
1108
+ this.pkg = JSON.parse(attributes.pkg) as string[];
1109
+ // If there is no isRootDataStore in the attributes blob, set it to true. This ensures that data
1110
+ // stores in older documents are not garbage collected incorrectly. This may lead to additional
1111
+ // roots in the document but they won't break.
1112
+ if (attributes.isRootDataStore ?? true) {
1113
+ isRootDataStore = true;
1114
+ this.setInMemoryRoot();
1115
+ }
1116
+ }
1117
+ }
1118
+ assert(this.pkg !== undefined, 0x152 /* "pkg should be available in local data store" */);
1119
+
1120
+ return {
1121
+ pkg: this.pkg,
1122
+ isRootDataStore,
1123
+ snapshot,
1124
+ };
1125
+ }
1126
+
1127
+ /**
1128
+ * A context should only be marked as deleted when its a remote context.
1129
+ * Session Expiry at the runtime level should have closed the container creating the local data store context
1130
+ * before delete is even possible. Session Expiry is at 30 days, and sweep is done 36+ days later from the time
1131
+ * it was unreferenced. Thus the sweeping container should have loaded from a snapshot and thus creating a remote
1132
+ * context.
1133
+ */
1134
+ public delete() {
1135
+ // TODO: GC:Validation - potentially prevent this from happening or asserting. Maybe throw here.
1136
+ sendGCUnexpectedUsageEvent(
1137
+ this.mc,
1138
+ {
1139
+ eventName: "GC_Deleted_DataStore_Unexpected_Delete",
1140
+ message: "Unexpected deletion of a local data store context",
1141
+ category: "error",
1142
+ gcTombstoneEnforcementAllowed: undefined,
1143
+ },
1144
+ this.pkg,
1145
+ );
1146
+ super.delete();
1147
+ }
1004
1148
  }
1005
1149
 
1006
1150
  /**
@@ -1010,9 +1154,9 @@ export class LocalFluidDataStoreContextBase extends FluidDataStoreContext {
1010
1154
  * Runtime is created using data store factory that is associated with this context.
1011
1155
  */
1012
1156
  export class LocalFluidDataStoreContext extends LocalFluidDataStoreContextBase {
1013
- constructor(props: ILocalFluidDataStoreContextProps) {
1014
- super(props);
1015
- }
1157
+ constructor(props: ILocalFluidDataStoreContextProps) {
1158
+ super(props);
1159
+ }
1016
1160
  }
1017
1161
 
1018
1162
  /**
@@ -1022,50 +1166,54 @@ export class LocalFluidDataStoreContext extends LocalFluidDataStoreContextBase {
1022
1166
  * Attachment process provides all missing parts - package path, data store runtime, and data store factory
1023
1167
  */
1024
1168
  export class LocalDetachedFluidDataStoreContext
1025
- extends LocalFluidDataStoreContextBase
1026
- implements IFluidDataStoreContextDetached {
1027
- constructor(props: ILocalFluidDataStoreContextProps) {
1028
- super(props);
1029
- this.detachedRuntimeCreation = true;
1030
- }
1031
-
1032
- public async attachRuntime(
1033
- registry: IProvideFluidDataStoreFactory,
1034
- dataStoreChannel: IFluidDataStoreChannel) {
1035
- assert(this.detachedRuntimeCreation, 0x154 /* "runtime creation is already attached" */);
1036
- this.detachedRuntimeCreation = false;
1037
-
1038
- assert(this.channelDeferred === undefined, 0x155 /* "channel deferral is already set" */);
1039
- this.channelDeferred = new Deferred<IFluidDataStoreChannel>();
1040
-
1041
- const factory = registry.IFluidDataStoreFactory;
1042
-
1043
- const entry = await this.factoryFromPackagePath(this.pkg);
1044
- assert(entry.factory === factory, 0x156 /* "Unexpected factory for package path" */);
1045
-
1046
- assert(this.registry === undefined, 0x157 /* "datastore registry already attached" */);
1047
- this.registry = entry.registry;
1048
-
1049
- super.bindRuntime(dataStoreChannel);
1050
-
1051
- // Load the handle to the data store's entryPoint to make sure that for a detached data store, the entryPoint
1052
- // initialization function is called before the data store gets attached and potentially connected to the
1053
- // delta stream, so it gets a chance to do things while the data store is still "purely local".
1054
- // This preserves the behavior from before we introduced entryPoints, where the instantiateDataStore method
1055
- // of data store factories tends to construct the data object (at least kick off an async method that returns
1056
- // it); that code moved to the entryPoint initialization function, so we want to ensure it still executes
1057
- // before the data store is attached.
1058
- await dataStoreChannel.entryPoint?.get();
1059
-
1060
- if (await this.isRoot()) {
1061
- dataStoreChannel.makeVisibleAndAttachGraph();
1062
- }
1063
- }
1064
-
1065
- public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
1066
- if (this.detachedRuntimeCreation) {
1067
- throw new Error("Detached Fluid Data Store context can't be realized! Please attach runtime first!");
1068
- }
1069
- return super.getInitialSnapshotDetails();
1070
- }
1169
+ extends LocalFluidDataStoreContextBase
1170
+ implements IFluidDataStoreContextDetached
1171
+ {
1172
+ constructor(props: ILocalFluidDataStoreContextProps) {
1173
+ super(props);
1174
+ this.detachedRuntimeCreation = true;
1175
+ }
1176
+
1177
+ public async attachRuntime(
1178
+ registry: IProvideFluidDataStoreFactory,
1179
+ dataStoreChannel: IFluidDataStoreChannel,
1180
+ ) {
1181
+ assert(this.detachedRuntimeCreation, 0x154 /* "runtime creation is already attached" */);
1182
+ this.detachedRuntimeCreation = false;
1183
+
1184
+ assert(this.channelDeferred === undefined, 0x155 /* "channel deferral is already set" */);
1185
+ this.channelDeferred = new Deferred<IFluidDataStoreChannel>();
1186
+
1187
+ const factory = registry.IFluidDataStoreFactory;
1188
+
1189
+ const entry = await this.factoryFromPackagePath(this.pkg);
1190
+ assert(entry.factory === factory, 0x156 /* "Unexpected factory for package path" */);
1191
+
1192
+ assert(this.registry === undefined, 0x157 /* "datastore registry already attached" */);
1193
+ this.registry = entry.registry;
1194
+
1195
+ super.bindRuntime(dataStoreChannel);
1196
+
1197
+ // Load the handle to the data store's entryPoint to make sure that for a detached data store, the entryPoint
1198
+ // initialization function is called before the data store gets attached and potentially connected to the
1199
+ // delta stream, so it gets a chance to do things while the data store is still "purely local".
1200
+ // This preserves the behavior from before we introduced entryPoints, where the instantiateDataStore method
1201
+ // of data store factories tends to construct the data object (at least kick off an async method that returns
1202
+ // it); that code moved to the entryPoint initialization function, so we want to ensure it still executes
1203
+ // before the data store is attached.
1204
+ await dataStoreChannel.entryPoint?.get();
1205
+
1206
+ if (await this.isRoot()) {
1207
+ dataStoreChannel.makeVisibleAndAttachGraph();
1208
+ }
1209
+ }
1210
+
1211
+ public async getInitialSnapshotDetails(): Promise<ISnapshotDetails> {
1212
+ if (this.detachedRuntimeCreation) {
1213
+ throw new Error(
1214
+ "Detached Fluid Data Store context can't be realized! Please attach runtime first!",
1215
+ );
1216
+ }
1217
+ return super.getInitialSnapshotDetails();
1218
+ }
1071
1219
  }