@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
@@ -4,12 +4,13 @@
4
4
  */
5
5
  import { v4 as uuid } from "uuid";
6
6
  import { createResponseError, generateHandleContextPath, responseToException, SummaryTreeBuilder, } from "@fluidframework/runtime-utils";
7
- import { assert, bufferToString, Deferred, stringToBuffer } from "@fluidframework/common-utils";
7
+ import { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter, } from "@fluidframework/common-utils";
8
8
  import { AttachState } from "@fluidframework/container-definitions";
9
- import { ChildLogger, loggerToMonitoringContext, PerformanceEvent } from "@fluidframework/telemetry-utils";
9
+ import { ChildLogger, loggerToMonitoringContext, PerformanceEvent, } from "@fluidframework/telemetry-utils";
10
+ import { TombstoneResponseHeaderKey } from "./containerRuntime";
11
+ import { sendGCUnexpectedUsageEvent, sweepAttachmentBlobsKey, throwOnTombstoneLoadKey } from "./gc";
10
12
  import { Throttler, formExponentialFn } from "./throttler";
11
- import { summarizerClientType } from "./summarizerClientElection";
12
- import { throwOnTombstoneUsageKey } from "./garbageCollectionConstants";
13
+ import { summarizerClientType } from "./summary";
13
14
  /**
14
15
  * This class represents blob (long string)
15
16
  * This object is used only when creating (writing) new blob and serialization purposes.
@@ -25,7 +26,9 @@ export class BlobHandle {
25
26
  this.attached = false;
26
27
  this.absolutePath = generateHandleContextPath(path, this.routeContext);
27
28
  }
28
- get IFluidHandle() { return this; }
29
+ get IFluidHandle() {
30
+ return this;
31
+ }
29
32
  get isAttached() {
30
33
  return this.attached;
31
34
  }
@@ -61,27 +64,33 @@ var PendingBlobStatus;
61
64
  PendingBlobStatus[PendingBlobStatus["OfflinePendingUpload"] = 2] = "OfflinePendingUpload";
62
65
  PendingBlobStatus[PendingBlobStatus["OfflinePendingOp"] = 3] = "OfflinePendingOp";
63
66
  })(PendingBlobStatus || (PendingBlobStatus = {}));
64
- export class BlobManager {
67
+ export class BlobManager extends TypedEventEmitter {
65
68
  constructor(routeContext, snapshot, getStorage,
66
69
  /**
67
- * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
68
- * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server
69
- * will then not delete the blob as long as it is listed as referenced in future summaries.
70
- * The summarizing client will know to include the storage ID in the summary when it sees the op.
70
+ * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
71
+ * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
72
+ * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
73
+ * include the storage ID in the summary when it sees the op.
71
74
  *
72
- * The op may also include a local ID to inform all clients of the relation to the storage
73
- * ID, without knowledge of which they cannot request the blob from storage. This is also
74
- * included in the redirect table in the summary.
75
+ * The op will also include a local ID to inform all clients of the relation to the storage ID, without
76
+ * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
77
+ * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
75
78
  */
76
79
  sendBlobAttachOp,
77
- // To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's
78
- // of the format `/<BlobManager.basePath>/<blobId>`.
79
- gcNodeUpdated, runtime, stashedBlobs = {}) {
80
+ // Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.
81
+ // blobPath's format - `/<BlobManager.basePath>/<blobId>`.
82
+ blobRequested,
83
+ // Called to check if a blob has been deleted by GC.
84
+ // blobPath's format - `/<BlobManager.basePath>/<blobId>`.
85
+ isBlobDeleted, runtime, stashedBlobs = {}, getCurrentReferenceTimestampMs) {
86
+ super();
80
87
  this.routeContext = routeContext;
81
88
  this.getStorage = getStorage;
82
89
  this.sendBlobAttachOp = sendBlobAttachOp;
83
- this.gcNodeUpdated = gcNodeUpdated;
90
+ this.blobRequested = blobRequested;
91
+ this.isBlobDeleted = isBlobDeleted;
84
92
  this.runtime = runtime;
93
+ this.getCurrentReferenceTimestampMs = getCurrentReferenceTimestampMs;
85
94
  /**
86
95
  * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.
87
96
  * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so
@@ -89,8 +98,9 @@ export class BlobManager {
89
98
  */
90
99
  this.pendingBlobs = new Map();
91
100
  /**
92
- * Track ops in flight for online flow. Used to avoid searching pendingBlobs since BlobAttach ops
93
- * don't include local ID in online flow.
101
+ * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
102
+ * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
103
+ * because we know that the server will not delete the blob corresponding to that storage ID.
94
104
  */
95
105
  this.opsInFlight = new Map();
96
106
  this.retryThrottler = new CancellableThrottler(new Throttler(60 * 1000, // 60 sec delay window
@@ -98,14 +108,15 @@ export class BlobManager {
98
108
  // throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)
99
109
  formExponentialFn({ coefficient: 20, initialDelay: 0 })));
100
110
  /**
101
- * This stores ides of tombstoned blobs.
111
+ * This stores IDs of tombstoned blobs.
102
112
  * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
103
113
  */
104
114
  this.tombstonedBlobs = new Set();
105
115
  this.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, "BlobManager"));
106
116
  // Read the feature flag that tells whether to throw when a tombstone blob is requested.
107
- this.throwOnTombstoneUsage =
108
- this.mc.config.getBoolean(throwOnTombstoneUsageKey) === true &&
117
+ this.throwOnTombstoneLoad =
118
+ this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
119
+ this.runtime.gcTombstoneEnforcementAllowed &&
109
120
  this.runtime.clientDetails.type !== summarizerClientType;
110
121
  this.runtime.on("disconnected", () => this.onDisconnected());
111
122
  this.redirectTable = this.load(snapshot);
@@ -121,12 +132,15 @@ export class BlobManager {
121
132
  });
122
133
  }
123
134
  get pendingOfflineUploads() {
124
- return Array.from(this.pendingBlobs.values())
125
- .filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
135
+ return Array.from(this.pendingBlobs.values()).filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
126
136
  }
127
137
  get hasPendingOfflineUploads() {
128
138
  return this.pendingOfflineUploads.length > 0;
129
139
  }
140
+ get hasPendingBlobs() {
141
+ return ((this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||
142
+ this.pendingBlobs.size > 0);
143
+ }
130
144
  /**
131
145
  * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
132
146
  */
@@ -151,14 +165,6 @@ export class BlobManager {
151
165
  }
152
166
  }
153
167
  }
154
- /**
155
- * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`
156
- * This path must match the path of the blob handle returned by the createBlob API because blobs are marked
157
- * referenced by storing these handles in a referenced DDS.
158
- */
159
- getBlobGCNodePath(blobId) {
160
- return `/${BlobManager.basePath}/${blobId}`;
161
- }
162
168
  /**
163
169
  * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is
164
170
  * detached or there are no (non-pending) attachment blobs in the document
@@ -169,21 +175,14 @@ export class BlobManager {
169
175
  const undefinedValueInTable = ids.delete(undefined);
170
176
  // For a detached container, entries are inserted into the redirect table with an undefined storage ID.
171
177
  // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.
172
- assert(!undefinedValueInTable || this.runtime.attachState === AttachState.Detached && ids.size === 0, 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
178
+ assert(!undefinedValueInTable ||
179
+ (this.runtime.attachState === AttachState.Detached && ids.size === 0), 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
173
180
  return ids;
174
181
  }
175
182
  async getBlob(blobId) {
176
- const request = { url: blobId };
177
- if (this.tombstonedBlobs.has(blobId)) {
178
- const error = responseToException(createResponseError(404, "Blob removed by gc", request), request);
179
- this.mc.logger.sendErrorEvent({
180
- eventName: "GC_Tombstone_Blob_Requested",
181
- url: request.url,
182
- }, error);
183
- if (this.throwOnTombstoneUsage) {
184
- throw error;
185
- }
186
- }
183
+ // Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,
184
+ // failing the call.
185
+ this.verifyBlobValidity(blobId);
187
186
  const pending = this.pendingBlobs.get(blobId);
188
187
  if (pending) {
189
188
  return pending.blob;
@@ -196,11 +195,12 @@ export class BlobManager {
196
195
  storageId = blobId;
197
196
  }
198
197
  else {
199
- storageId = this.redirectTable.get(blobId);
200
- assert(!!storageId, 0x11f /* "requesting unknown blobs" */);
198
+ const attachedStorageId = this.redirectTable.get(blobId);
199
+ assert(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
200
+ storageId = attachedStorageId;
201
201
  }
202
- // When a GC-able (not pending) blob is retrieved, let runtime know that the corresponding GC node got updated.
203
- this.gcNodeUpdated(this.getBlobGCNodePath(blobId));
202
+ // Let runtime know that the corresponding GC node was requested.
203
+ this.blobRequested(getGCNodePathFromBlobId(blobId));
204
204
  return PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "AttachmentReadBlob", id: storageId }, async () => {
205
205
  return this.getStorage().readBlob(storageId);
206
206
  }, { end: true, cancel: "error" });
@@ -213,7 +213,7 @@ export class BlobManager {
213
213
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
214
214
  // The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
215
215
  const response = await this.getStorage().createBlob(blob);
216
- this.redirectTable.set(response.id, undefined);
216
+ this.setRedirection(response.id, undefined);
217
217
  return this.getBlobHandle(response.id);
218
218
  }
219
219
  async createBlob(blob) {
@@ -226,8 +226,8 @@ export class BlobManager {
226
226
  await new Promise((resolve) => this.runtime.once("attached", resolve));
227
227
  }
228
228
  assert(this.runtime.attachState === AttachState.Attached, 0x385 /* For clarity and paranoid defense against adding future attachment states */);
229
- // Create a local ID for each blob. This is used to support blobs if/when the client goes
230
- // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.
229
+ // Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
230
+ // storage ID mapping is created.
231
231
  const localId = uuid();
232
232
  const pendingEntry = {
233
233
  blob,
@@ -241,25 +241,51 @@ export class BlobManager {
241
241
  async uploadBlob(localId, blob) {
242
242
  return PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "createBlob" }, async () => this.getStorage().createBlob(blob), { end: true, cancel: this.runtime.connected ? "error" : "generic" }).then((response) => this.onUploadResolve(localId, response), async (err) => this.onUploadReject(localId, err));
243
243
  }
244
+ /**
245
+ * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
246
+ * which is required for GC.
247
+ */
248
+ setRedirection(fromId, toId) {
249
+ this.redirectTable.set(fromId, toId);
250
+ }
251
+ deleteAndEmitsIfEmpty(id) {
252
+ if (this.pendingBlobs.has(id)) {
253
+ this.pendingBlobs.delete(id);
254
+ if (!this.hasPendingBlobs) {
255
+ this.emit("noPendingBlobs");
256
+ }
257
+ }
258
+ }
244
259
  onUploadResolve(localId, response) {
245
260
  var _a;
246
261
  const entry = this.pendingBlobs.get(localId);
247
262
  assert((entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OnlinePendingUpload ||
248
263
  (entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OfflinePendingUpload, 0x386 /* Must have pending blob entry for uploaded blob */);
249
264
  entry.storageId = response.id;
265
+ entry.localUploadTime = Date.now();
266
+ entry.minTTLInSeconds = response.minTTLInSeconds;
267
+ entry.serverUploadTime = this.getCurrentReferenceTimestampMs();
250
268
  if (this.runtime.connected) {
251
269
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
270
+ // Send a blob attach op. This serves two purposes:
271
+ // 1. If its a new blob, i.e., it isn't de-duped, the server will keep the blob alive if it sees this op
272
+ // until its storage ID is added to the next summary.
273
+ // 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
274
+ // blob from the server via the storage ID.
275
+ this.logTimeInfo(entry, "sendBlobAttachResolveTTL");
276
+ this.sendBlobAttachOp(localId, response.id);
252
277
  if (this.storageIds.has(response.id)) {
253
- // Storage may dedupe blobs and give us an ID we already know
254
- // no need to submit BlobAttach op in this case
255
- entry.handleP.resolve(this.getBlobHandle(response.id));
256
- this.pendingBlobs.delete(localId);
278
+ // The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
279
+ // an existing blob, we don't have to wait for the op to be ack'd since this step has already
280
+ // happened before and so, the server won't delete it.
281
+ this.setRedirection(localId, response.id);
282
+ entry.handleP.resolve(this.getBlobHandle(localId));
283
+ this.deleteAndEmitsIfEmpty(localId);
257
284
  }
258
285
  else {
259
- // Check for still-pending duplicates too; if an op is already in flight we can wait for that one
260
- if (!this.opsInFlight.has(response.id)) {
261
- this.sendBlobAttachOp(response.id);
262
- }
286
+ // If there is already an op for this storage ID, append the local ID to the list. Once any op for
287
+ // this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
288
+ // blob alive in storage.
263
289
  this.opsInFlight.set(response.id, ((_a = this.opsInFlight.get(response.id)) !== null && _a !== void 0 ? _a : []).concat(localId));
264
290
  entry.status = PendingBlobStatus.OnlinePendingOp;
265
291
  }
@@ -287,7 +313,9 @@ export class BlobManager {
287
313
  this.transitionToOffline(localId);
288
314
  }
289
315
  // we are probably not connected to storage but start another upload request in case we are
290
- entry.uploadP = this.retryThrottler.getDelay().then(async () => this.uploadBlob(localId, entry.blob));
316
+ entry.uploadP = this.retryThrottler
317
+ .getDelay()
318
+ .then(async () => this.uploadBlob(localId, entry.blob));
291
319
  return entry.uploadP;
292
320
  }
293
321
  else {
@@ -300,15 +328,21 @@ export class BlobManager {
300
328
  const entry = this.pendingBlobs.get(localId);
301
329
  assert(!!entry, 0x389 /* No pending blob entry */);
302
330
  assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), 0x38a /* Blob must be in online flow to transition to offline flow */);
303
- entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
304
- ? PendingBlobStatus.OfflinePendingUpload
305
- : PendingBlobStatus.OfflinePendingOp;
306
- // Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the
307
- // BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be
308
- // added to the document if the ops are not all successfully submitted upon reconnection.
309
- // storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
310
- // is called
311
- this.sendBlobAttachOp(entry.storageId, localId);
331
+ /**
332
+ * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
333
+ * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
334
+ * an invalid handle could be added to the document.
335
+ * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
336
+ * is called on reconnection.
337
+ */
338
+ if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
339
+ this.logTimeInfo(entry, "sendBlobAttachTransitionOfflineTTL");
340
+ this.sendBlobAttachOp(localId, entry.storageId);
341
+ }
342
+ entry.status =
343
+ entry.status === PendingBlobStatus.OnlinePendingUpload
344
+ ? PendingBlobStatus.OfflinePendingUpload
345
+ : PendingBlobStatus.OfflinePendingOp;
312
346
  entry.handleP.resolve(this.getBlobHandle(localId));
313
347
  }
314
348
  /**
@@ -318,45 +352,81 @@ export class BlobManager {
318
352
  */
319
353
  reSubmit(metadata) {
320
354
  assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
321
- const { blobId, localId } = metadata;
355
+ const { localId, blobId } = metadata;
356
+ assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
357
+ const pendingEntry = this.pendingBlobs.get(localId);
358
+ if (pendingEntry) {
359
+ this.logTimeInfo(pendingEntry, "sendBlobAttachResubmitTTL");
360
+ }
322
361
  if (!blobId) {
323
- assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
324
362
  // We submitted this op while offline. The blob should have been uploaded by now.
325
- const pendingEntry = this.pendingBlobs.get(localId);
326
363
  assert((pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.status) === PendingBlobStatus.OfflinePendingOp &&
327
364
  !!(pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.storageId), 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
328
- return this.sendBlobAttachOp(pendingEntry.storageId, localId);
365
+ return this.sendBlobAttachOp(localId, pendingEntry.storageId);
329
366
  }
330
- return this.sendBlobAttachOp(blobId, localId);
367
+ return this.sendBlobAttachOp(localId, blobId);
368
+ }
369
+ logTimeInfo(pendingEntry, eventName) {
370
+ var _a, _b;
371
+ let timeLapseSinceLocalUpload = 0;
372
+ let timeLapseSinceServerUpload = 0;
373
+ let expiredUsingLocalTime;
374
+ let expiredUsingServerTime;
375
+ if (pendingEntry.localUploadTime) {
376
+ timeLapseSinceLocalUpload = (Date.now() - pendingEntry.localUploadTime) / 1000;
377
+ expiredUsingLocalTime =
378
+ ((_a = pendingEntry.minTTLInSeconds) !== null && _a !== void 0 ? _a : 0) - timeLapseSinceLocalUpload < 0 ? true : false;
379
+ }
380
+ if (pendingEntry.serverUploadTime) {
381
+ timeLapseSinceServerUpload = (Date.now() - pendingEntry.serverUploadTime) / 1000;
382
+ expiredUsingServerTime =
383
+ ((_b = pendingEntry.minTTLInSeconds) !== null && _b !== void 0 ? _b : 0) - timeLapseSinceServerUpload < 0 ? true : false;
384
+ }
385
+ this.mc.logger.sendTelemetryEvent({
386
+ eventName,
387
+ entryStatus: pendingEntry.status,
388
+ timeLapseSinceLocalUpload,
389
+ timeLapseSinceServerUpload,
390
+ minTTLInSeconds: pendingEntry.minTTLInSeconds,
391
+ expiredUsingLocalTime,
392
+ expiredUsingServerTime,
393
+ });
331
394
  }
332
395
  processBlobAttachOp(message, local) {
333
396
  var _a, _b;
334
- assert((_a = message === null || message === void 0 ? void 0 : message.metadata) === null || _a === void 0 ? void 0 : _a.blobId, 0x12a /* "Missing blob id on metadata" */);
335
- if (message.metadata.localId !== undefined) {
336
- this.redirectTable.set(message.metadata.localId, message.metadata.blobId);
397
+ const localId = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.localId;
398
+ const blobId = (_b = message.metadata) === null || _b === void 0 ? void 0 : _b.blobId;
399
+ assert(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
400
+ // Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
401
+ // requested from the server.
402
+ // Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
403
+ // was sent when online.
404
+ if (localId !== undefined) {
405
+ this.setRedirection(localId, blobId);
337
406
  }
338
407
  // set identity (id -> id) entry
339
- this.redirectTable.set(message.metadata.blobId, message.metadata.blobId);
408
+ this.setRedirection(blobId, blobId);
340
409
  if (local) {
341
- if (message.metadata.localId === undefined) {
342
- // Since there is no local ID, we know this op was submitted while online.
343
- const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);
344
- assert(!!waitingBlobs, 0x38e /* local online BlobAttach op with no pending blob */);
345
- waitingBlobs.forEach((localId) => {
346
- const pendingBlobEntry = this.pendingBlobs.get(localId);
347
- assert(pendingBlobEntry !== undefined, 0x38f);
410
+ assert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
411
+ const waitingBlobs = this.opsInFlight.get(blobId);
412
+ if (waitingBlobs !== undefined) {
413
+ // For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
414
+ // This is safe because the server will keep the blob alive and the op containing the local ID to
415
+ // storage ID is already in flight and any op containing this local ID will be sequenced after that.
416
+ waitingBlobs.forEach((pendingLocalId) => {
417
+ const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
418
+ assert(pendingBlobEntry !== undefined, 0x38f /* local online BlobAttach op with no pending blob entry */);
348
419
  // It's possible we transitioned to offline flow while waiting for this op.
349
420
  if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
350
- pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));
351
- this.pendingBlobs.delete(localId);
421
+ this.setRedirection(pendingLocalId, blobId);
422
+ pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
423
+ this.deleteAndEmitsIfEmpty(pendingLocalId);
352
424
  }
353
425
  });
426
+ this.opsInFlight.delete(blobId);
354
427
  }
355
- else {
356
- // Each local ID is unique; get the pending blob entry and delete it
357
- assert(((_b = this.pendingBlobs.get(message.metadata.localId)) === null || _b === void 0 ? void 0 : _b.status) === PendingBlobStatus.OfflinePendingOp, 0x1f8 /* "local BlobAttach op with no pending blob" */);
358
- this.pendingBlobs.delete(message.metadata.localId);
359
- }
428
+ // For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
429
+ this.deleteAndEmitsIfEmpty(localId);
360
430
  }
361
431
  }
362
432
  /**
@@ -375,7 +445,8 @@ export class BlobManager {
375
445
  redirectTable = await tryFetchBlob(tableId);
376
446
  }
377
447
  const ids = Object.entries(blobsTree.blobs)
378
- .filter(([k, _]) => k !== this.redirectTableBlobName).map(([_, v]) => v);
448
+ .filter(([k, _]) => k !== this.redirectTableBlobName)
449
+ .map(([_, v]) => v);
379
450
  return { ids, redirectTable };
380
451
  }
381
452
  /**
@@ -397,6 +468,23 @@ export class BlobManager {
397
468
  }
398
469
  return table;
399
470
  }
471
+ summarize(telemetryContext) {
472
+ // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
473
+ const blobIds = this.storageIds.size > 0
474
+ ? Array.from(this.storageIds)
475
+ : Array.from(this.redirectTable.keys());
476
+ const builder = new SummaryTreeBuilder();
477
+ blobIds.forEach((blobId) => {
478
+ builder.addAttachment(blobId);
479
+ });
480
+ // Any non-identity entries in the table need to be saved in the summary
481
+ if (this.redirectTable.size > blobIds.length) {
482
+ builder.addBlob(BlobManager.redirectTableBlobName,
483
+ // filter out identity entries
484
+ JSON.stringify(Array.from(this.redirectTable.entries()).filter(([localId, storageId]) => localId !== storageId)));
485
+ }
486
+ return builder.getSummaryTree();
487
+ }
400
488
  /**
401
489
  * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be
402
490
  * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.
@@ -405,90 +493,155 @@ export class BlobManager {
405
493
  */
406
494
  getGCData(fullGC = false) {
407
495
  const gcData = { gcNodes: {} };
408
- /**
409
- * The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned
410
- * by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.
411
- */
412
- this.storageIds.forEach((blobId) => {
413
- gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];
414
- });
415
- // For some blobs, the handle returned on creation is based off of the localId. So, these
416
- // nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node
417
- // must also be marked referenced. So, we add a route from the localId node to the storageId node.
418
- // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
419
- // a blob may be referenced via its storageId handle.
420
496
  for (const [localId, storageId] of this.redirectTable) {
421
497
  assert(!!storageId, 0x390 /* Must be attached to get GC data */);
422
- // Add node for the localId and add a route to the storageId node. The storageId node will have been
423
- // added above when adding nodes for this.blobIds.
424
- gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
498
+ // Only return local ids as GC nodes because a blob can only be referenced via its local id. The storage
499
+ // id entries have the same key and value, ignore them.
500
+ // The outbound routes are empty because a blob node cannot reference other nodes. It can only be referenced
501
+ // by adding its handle to a referenced DDS.
502
+ if (localId !== storageId) {
503
+ gcData.gcNodes[getGCNodePathFromBlobId(localId)] = [];
504
+ }
425
505
  }
426
506
  return gcData;
427
507
  }
428
508
  /**
429
- * This is called to update blobs whose routes are used. The used blobs are removed from the tombstone list.
430
- * @param usedRoutes - The routes of the blob nodes that are used.
509
+ * This is called to update blobs whose routes are unused. The unused blobs are deleted.
510
+ * @param unusedRoutes - The routes of the blob nodes that are unused. These routes will be based off of local ids.
431
511
  */
432
- updateUsedRoutes(usedRoutes) {
433
- // The routes or blob node paths are in the same format as returned in getGCData -
434
- // `/<BlobManager.basePath>/<blobId>`.
435
- for (const route of usedRoutes) {
436
- const pathParts = route.split("/");
437
- assert(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x4bc /* Invalid blob node id in used routes. */);
438
- const blobId = pathParts[2];
439
- // Un-tombstone the blob if it was marked tombstone.
440
- this.tombstonedBlobs.delete(blobId);
512
+ updateUnusedRoutes(unusedRoutes) {
513
+ this.deleteBlobsFromRedirectTable(unusedRoutes);
514
+ }
515
+ /**
516
+ * Delete attachment blobs that are sweep ready.
517
+ * @param sweepReadyBlobRoutes - The routes of blobs that are sweep ready and should be deleted. These routes will
518
+ * be based off of local ids.
519
+ * @returns - The routes of blobs that were deleted.
520
+ */
521
+ deleteSweepReadyNodes(sweepReadyBlobRoutes) {
522
+ // If sweep for attachment blobs is not enabled, return empty list indicating nothing is deleted.
523
+ if (this.mc.config.getBoolean(sweepAttachmentBlobsKey) !== true) {
524
+ return [];
525
+ }
526
+ this.deleteBlobsFromRedirectTable(sweepReadyBlobRoutes);
527
+ return Array.from(sweepReadyBlobRoutes);
528
+ }
529
+ /**
530
+ * Delete blobs with the given routes from the redirect table.
531
+ * The routes are GC nodes paths of format -`/<BlobManager.basePath>/<blobId>`. The blob ids are all local ids.
532
+ * Deleting the blobs involves 2 steps:
533
+ * 1. The redirect table entry for the local ids are deleted.
534
+ * 2. If the storage ids corresponding to the deleted local ids are not in-use anymore, the redirect table entries
535
+ * for the storage ids are deleted as well.
536
+ *
537
+ * Note that this does not delete the blobs from storage service immediately. Deleting the blobs from redirect table
538
+ * will remove them the next summary. The service would them delete them some time in the future.
539
+ */
540
+ deleteBlobsFromRedirectTable(blobRoutes) {
541
+ if (blobRoutes.length === 0) {
542
+ return;
543
+ }
544
+ // This tracks the storage ids of local ids that are deleted. After the local ids have been deleted, if any of
545
+ // these storage ids are unused, they will be deleted as well.
546
+ const maybeUnusedStorageIds = new Set();
547
+ for (const route of blobRoutes) {
548
+ const blobId = getBlobIdFromGCNodePath(route);
549
+ if (!this.redirectTable.has(blobId)) {
550
+ this.mc.logger.sendErrorEvent({
551
+ eventName: "DeletedAttachmentBlobNotFound",
552
+ blobId,
553
+ });
554
+ continue;
555
+ }
556
+ const storageId = this.redirectTable.get(blobId);
557
+ assert(!!storageId, 0x5bb /* Must be attached to run GC */);
558
+ maybeUnusedStorageIds.add(storageId);
559
+ this.redirectTable.delete(blobId);
560
+ }
561
+ // Find out storage ids that are in-use and remove them from maybeUnusedStorageIds. A storage id is in-use if
562
+ // the redirect table has a local id -> storage id entry for it.
563
+ for (const [localId, storageId] of this.redirectTable.entries()) {
564
+ assert(!!storageId, 0x5bc /* Must be attached to run GC */);
565
+ // For every storage id, the redirect table has a id -> id entry. These do not make the storage id in-use.
566
+ if (maybeUnusedStorageIds.has(storageId) && localId !== storageId) {
567
+ maybeUnusedStorageIds.delete(storageId);
568
+ }
569
+ }
570
+ // For unused storage ids, delete their id -> id entries from the redirect table.
571
+ // This way they'll be absent from the next summary, and the service is free to delete them from storage.
572
+ for (const storageId of maybeUnusedStorageIds) {
573
+ this.redirectTable.delete(storageId);
441
574
  }
442
575
  }
443
576
  /**
444
- * This is called to update blobs whose routes are unused. The unused blobs are either deleted or marked as
445
- * tombstones.
446
- * @param unusedRoutes - The routes of the blob nodes that are unused.
447
- * @param tombstone - if true, the objects corresponding to unused routes are marked tombstones. Otherwise, they
448
- * are deleted.
577
+ * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
578
+ * accessing deleted content without actually deleting content from summaries.
579
+ * @param tombstonedRoutes - The routes of blob nodes that are tombstones.
449
580
  */
450
- updateUnusedRoutes(unusedRoutes, tombstone) {
581
+ updateTombstonedRoutes(tombstonedRoutes) {
582
+ const tombstonedBlobsSet = new Set();
451
583
  // The routes or blob node paths are in the same format as returned in getGCData -
452
584
  // `/<BlobManager.basePath>/<blobId>`.
453
- for (const route of unusedRoutes) {
454
- const pathParts = route.split("/");
455
- assert(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x2d5 /* "Invalid blob node id in unused routes." */);
456
- const blobId = pathParts[2];
457
- if (tombstone) {
458
- // If tombstone is set, add this blob to the tombstone list.
459
- this.tombstonedBlobs.add(blobId);
460
- }
461
- else {
462
- // The unused blobId could be a localId. If so, remove it from the redirect table and continue. The
463
- // corresponding storageId may still be used either directly or via other localIds.
464
- this.redirectTable.delete(blobId);
585
+ for (const route of tombstonedRoutes) {
586
+ const blobId = getBlobIdFromGCNodePath(route);
587
+ tombstonedBlobsSet.add(blobId);
588
+ }
589
+ // Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
590
+ for (const blobId of this.tombstonedBlobs) {
591
+ if (!tombstonedBlobsSet.has(blobId)) {
592
+ this.tombstonedBlobs.delete(blobId);
465
593
  }
466
594
  }
595
+ // Mark blobs that are now tombstoned by adding them to the tombstone list.
596
+ for (const blobId of tombstonedBlobsSet) {
597
+ this.tombstonedBlobs.add(blobId);
598
+ }
467
599
  }
468
- summarize(telemetryContext) {
469
- // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
470
- const blobIds = this.storageIds.size > 0 ? Array.from(this.storageIds) : Array.from(this.redirectTable.keys());
471
- const builder = new SummaryTreeBuilder();
472
- blobIds.forEach((blobId) => {
473
- builder.addAttachment(blobId);
474
- });
475
- // Any non-identity entries in the table need to be saved in the summary
476
- if (this.redirectTable.size > blobIds.length) {
477
- builder.addBlob(BlobManager.redirectTableBlobName,
478
- // filter out identity entries
479
- JSON.stringify(Array.from(this.redirectTable.entries())
480
- .filter(([localId, storageId]) => localId !== storageId)));
600
+ /**
601
+ * Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,
602
+ * log an error and throw if necessary.
603
+ */
604
+ verifyBlobValidity(blobId) {
605
+ /**
606
+ * A blob can be in one of the following states:
607
+ * 1. "deleted" - It has been deleted by garbage collection sweep phase.
608
+ * 2. "tombstoned" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.
609
+ * 3. "valid" - It has not been deleted or tombstoned.
610
+ */
611
+ let state = "valid";
612
+ if (this.isBlobDeleted(getGCNodePathFromBlobId(blobId))) {
613
+ state = "deleted";
614
+ }
615
+ else if (this.tombstonedBlobs.has(blobId)) {
616
+ state = "tombstoned";
617
+ }
618
+ if (state === "valid") {
619
+ return;
620
+ }
621
+ // If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt
622
+ // to load the blob.
623
+ const shouldFail = state === "deleted" || this.throwOnTombstoneLoad;
624
+ const request = { url: blobId };
625
+ const error = responseToException(createResponseError(404, "Blob was deleted", request, state === "tombstoned" ? { [TombstoneResponseHeaderKey]: true } : undefined), request);
626
+ sendGCUnexpectedUsageEvent(this.mc, {
627
+ eventName: state === "tombstoned"
628
+ ? "GC_Tombstone_Blob_Requested"
629
+ : "GC_Deleted_Blob_Requested",
630
+ category: shouldFail ? "error" : "generic",
631
+ gcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,
632
+ }, [BlobManager.basePath], error);
633
+ if (shouldFail) {
634
+ throw error;
481
635
  }
482
- return builder.getSummaryTree();
483
636
  }
484
637
  setRedirectTable(table) {
485
638
  assert(this.runtime.attachState === AttachState.Detached, 0x252 /* "redirect table can only be set in detached container" */);
486
639
  assert(this.redirectTable.size === table.size, 0x391 /* Redirect table size must match BlobManager's local ID count */);
487
640
  for (const [localId, storageId] of table) {
488
641
  assert(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
489
- this.redirectTable.set(localId, storageId);
642
+ this.setRedirection(localId, storageId);
490
643
  // set identity (id -> id) entry
491
- this.redirectTable.set(storageId, storageId);
644
+ this.setRedirection(storageId, storageId);
492
645
  }
493
646
  }
494
647
  getPendingBlobs() {
@@ -501,4 +654,20 @@ export class BlobManager {
501
654
  }
502
655
  BlobManager.basePath = "_blobs";
503
656
  BlobManager.redirectTableBlobName = ".redirectTable";
657
+ /**
658
+ * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`.
659
+ * This path must match the path of the blob handle returned by the createBlob API because blobs are marked
660
+ * referenced by storing these handles in a referenced DDS.
661
+ */
662
+ function getGCNodePathFromBlobId(blobId) {
663
+ return `/${BlobManager.basePath}/${blobId}`;
664
+ }
665
+ /**
666
+ * For a given GC node path, return the blobId. The node path is of the format `/<BlobManager.basePath>/<blobId>`.
667
+ */
668
+ function getBlobIdFromGCNodePath(nodePath) {
669
+ const pathParts = nodePath.split("/");
670
+ assert(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x5bd /* Invalid blob node path */);
671
+ return pathParts[2];
672
+ }
504
673
  //# sourceMappingURL=blobManager.js.map