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