@fluidframework/container-runtime 2.0.0-dev.2.2.0.111723 → 2.0.0-dev.3.1.0.125672

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 (365) 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 +62 -28
  9. package/dist/blobManager.d.ts.map +1 -1
  10. package/dist/blobManager.js +256 -102
  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 +110 -78
  19. package/dist/containerRuntime.d.ts.map +1 -1
  20. package/dist/containerRuntime.js +336 -331
  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 +2 -1
  26. package/dist/dataStoreContext.d.ts.map +1 -1
  27. package/dist/dataStoreContext.js +40 -23
  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 +12 -9
  36. package/dist/dataStores.d.ts.map +1 -1
  37. package/dist/dataStores.js +69 -46
  38. package/dist/dataStores.js.map +1 -1
  39. package/dist/deltaScheduler.d.ts.map +1 -1
  40. package/dist/deltaScheduler.js +8 -3
  41. package/dist/deltaScheduler.js.map +1 -1
  42. package/dist/garbageCollection.d.ts +57 -42
  43. package/dist/garbageCollection.d.ts.map +1 -1
  44. package/dist/garbageCollection.js +371 -239
  45. package/dist/garbageCollection.js.map +1 -1
  46. package/dist/garbageCollectionConstants.d.ts +23 -0
  47. package/dist/garbageCollectionConstants.d.ts.map +1 -0
  48. package/dist/garbageCollectionConstants.js +36 -0
  49. package/dist/garbageCollectionConstants.js.map +1 -0
  50. package/dist/garbageCollectionHelpers.d.ts +15 -0
  51. package/dist/garbageCollectionHelpers.d.ts.map +1 -0
  52. package/dist/garbageCollectionHelpers.js +27 -0
  53. package/dist/garbageCollectionHelpers.js.map +1 -0
  54. package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
  55. package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
  56. package/dist/gcSweepReadyUsageDetection.js +15 -11
  57. package/dist/gcSweepReadyUsageDetection.js.map +1 -1
  58. package/dist/index.d.ts +4 -3
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +5 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/opLifecycle/batchManager.d.ts +42 -0
  63. package/dist/opLifecycle/batchManager.d.ts.map +1 -0
  64. package/dist/opLifecycle/batchManager.js +124 -0
  65. package/dist/opLifecycle/batchManager.js.map +1 -0
  66. package/dist/opLifecycle/definitions.d.ts +64 -0
  67. package/dist/opLifecycle/definitions.d.ts.map +1 -0
  68. package/dist/opLifecycle/definitions.js +7 -0
  69. package/dist/opLifecycle/definitions.js.map +1 -0
  70. package/dist/opLifecycle/index.d.ts +12 -0
  71. package/dist/opLifecycle/index.d.ts.map +1 -0
  72. package/dist/opLifecycle/index.js +22 -0
  73. package/dist/opLifecycle/index.js.map +1 -0
  74. package/dist/{opCompressor.d.ts → opLifecycle/opCompressor.d.ts} +3 -3
  75. package/dist/opLifecycle/opCompressor.d.ts.map +1 -0
  76. package/dist/opLifecycle/opCompressor.js +67 -0
  77. package/dist/opLifecycle/opCompressor.js.map +1 -0
  78. package/dist/{opDecompressor.d.ts → opLifecycle/opDecompressor.d.ts} +2 -1
  79. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -0
  80. package/dist/{opDecompressor.js → opLifecycle/opDecompressor.js} +37 -21
  81. package/dist/opLifecycle/opDecompressor.js.map +1 -0
  82. package/dist/opLifecycle/opSplitter.d.ts +49 -0
  83. package/dist/opLifecycle/opSplitter.d.ts.map +1 -0
  84. package/dist/opLifecycle/opSplitter.js +173 -0
  85. package/dist/opLifecycle/opSplitter.js.map +1 -0
  86. package/dist/opLifecycle/outbox.d.ts +52 -0
  87. package/dist/opLifecycle/outbox.d.ts.map +1 -0
  88. package/dist/opLifecycle/outbox.js +164 -0
  89. package/dist/opLifecycle/outbox.js.map +1 -0
  90. package/dist/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  91. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  92. package/dist/opLifecycle/remoteMessageProcessor.js +96 -0
  93. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -0
  94. package/dist/opProperties.d.ts.map +1 -1
  95. package/dist/opProperties.js +1 -3
  96. package/dist/opProperties.js.map +1 -1
  97. package/dist/orderedClientElection.d.ts.map +1 -1
  98. package/dist/orderedClientElection.js +10 -4
  99. package/dist/orderedClientElection.js.map +1 -1
  100. package/dist/packageVersion.d.ts +1 -1
  101. package/dist/packageVersion.js +1 -1
  102. package/dist/packageVersion.js.map +1 -1
  103. package/dist/pendingStateManager.d.ts +4 -13
  104. package/dist/pendingStateManager.d.ts.map +1 -1
  105. package/dist/pendingStateManager.js +134 -161
  106. package/dist/pendingStateManager.js.map +1 -1
  107. package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
  108. package/dist/runWhileConnectedCoordinator.js.map +1 -1
  109. package/dist/runningSummarizer.d.ts.map +1 -1
  110. package/dist/runningSummarizer.js +34 -22
  111. package/dist/runningSummarizer.js.map +1 -1
  112. package/dist/scheduleManager.d.ts +0 -1
  113. package/dist/scheduleManager.d.ts.map +1 -1
  114. package/dist/scheduleManager.js +11 -21
  115. package/dist/scheduleManager.js.map +1 -1
  116. package/dist/serializedSnapshotStorage.d.ts.map +1 -1
  117. package/dist/serializedSnapshotStorage.js +3 -1
  118. package/dist/serializedSnapshotStorage.js.map +1 -1
  119. package/dist/summarizer.d.ts +2 -3
  120. package/dist/summarizer.d.ts.map +1 -1
  121. package/dist/summarizer.js +39 -18
  122. package/dist/summarizer.js.map +1 -1
  123. package/dist/summarizerClientElection.d.ts +1 -2
  124. package/dist/summarizerClientElection.d.ts.map +1 -1
  125. package/dist/summarizerClientElection.js +3 -30
  126. package/dist/summarizerClientElection.js.map +1 -1
  127. package/dist/summarizerHandle.d.ts.map +1 -1
  128. package/dist/summarizerHandle.js.map +1 -1
  129. package/dist/summarizerHeuristics.d.ts.map +1 -1
  130. package/dist/summarizerHeuristics.js +6 -9
  131. package/dist/summarizerHeuristics.js.map +1 -1
  132. package/dist/summarizerTypes.d.ts +22 -25
  133. package/dist/summarizerTypes.d.ts.map +1 -1
  134. package/dist/summarizerTypes.js.map +1 -1
  135. package/dist/summaryCollection.d.ts.map +1 -1
  136. package/dist/summaryCollection.js +18 -8
  137. package/dist/summaryCollection.js.map +1 -1
  138. package/dist/summaryFormat.d.ts.map +1 -1
  139. package/dist/summaryFormat.js +18 -11
  140. package/dist/summaryFormat.js.map +1 -1
  141. package/dist/summaryGenerator.d.ts.map +1 -1
  142. package/dist/summaryGenerator.js +32 -14
  143. package/dist/summaryGenerator.js.map +1 -1
  144. package/dist/summaryManager.d.ts.map +1 -1
  145. package/dist/summaryManager.js +21 -9
  146. package/dist/summaryManager.js.map +1 -1
  147. package/dist/throttler.d.ts +2 -2
  148. package/dist/throttler.d.ts.map +1 -1
  149. package/dist/throttler.js +4 -4
  150. package/dist/throttler.js.map +1 -1
  151. package/garbageCollection.md +15 -2
  152. package/lib/batchTracker.d.ts +1 -2
  153. package/lib/batchTracker.d.ts.map +1 -1
  154. package/lib/batchTracker.js +2 -1
  155. package/lib/batchTracker.js.map +1 -1
  156. package/lib/blobManager.d.ts +62 -28
  157. package/lib/blobManager.d.ts.map +1 -1
  158. package/lib/blobManager.js +259 -105
  159. package/lib/blobManager.js.map +1 -1
  160. package/lib/connectionTelemetry.d.ts.map +1 -1
  161. package/lib/connectionTelemetry.js +11 -9
  162. package/lib/connectionTelemetry.js.map +1 -1
  163. package/lib/containerHandleContext.d.ts.map +1 -1
  164. package/lib/containerHandleContext.js +3 -1
  165. package/lib/containerHandleContext.js.map +1 -1
  166. package/lib/containerRuntime.d.ts +110 -78
  167. package/lib/containerRuntime.d.ts.map +1 -1
  168. package/lib/containerRuntime.js +340 -334
  169. package/lib/containerRuntime.js.map +1 -1
  170. package/lib/dataStore.d.ts.map +1 -1
  171. package/lib/dataStore.js +11 -9
  172. package/lib/dataStore.js.map +1 -1
  173. package/lib/dataStoreContext.d.ts +2 -1
  174. package/lib/dataStoreContext.d.ts.map +1 -1
  175. package/lib/dataStoreContext.js +41 -24
  176. package/lib/dataStoreContext.js.map +1 -1
  177. package/lib/dataStoreContexts.d.ts.map +1 -1
  178. package/lib/dataStoreContexts.js +7 -3
  179. package/lib/dataStoreContexts.js.map +1 -1
  180. package/lib/dataStoreRegistry.d.ts.map +1 -1
  181. package/lib/dataStoreRegistry.js +3 -1
  182. package/lib/dataStoreRegistry.js.map +1 -1
  183. package/lib/dataStores.d.ts +12 -9
  184. package/lib/dataStores.d.ts.map +1 -1
  185. package/lib/dataStores.js +75 -52
  186. package/lib/dataStores.js.map +1 -1
  187. package/lib/deltaScheduler.d.ts.map +1 -1
  188. package/lib/deltaScheduler.js +9 -4
  189. package/lib/deltaScheduler.js.map +1 -1
  190. package/lib/garbageCollection.d.ts +57 -42
  191. package/lib/garbageCollection.d.ts.map +1 -1
  192. package/lib/garbageCollection.js +364 -232
  193. package/lib/garbageCollection.js.map +1 -1
  194. package/lib/garbageCollectionConstants.d.ts +23 -0
  195. package/lib/garbageCollectionConstants.d.ts.map +1 -0
  196. package/lib/garbageCollectionConstants.js +33 -0
  197. package/lib/garbageCollectionConstants.js.map +1 -0
  198. package/lib/garbageCollectionHelpers.d.ts +15 -0
  199. package/lib/garbageCollectionHelpers.d.ts.map +1 -0
  200. package/lib/garbageCollectionHelpers.js +23 -0
  201. package/lib/garbageCollectionHelpers.js.map +1 -0
  202. package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
  203. package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
  204. package/lib/gcSweepReadyUsageDetection.js +15 -11
  205. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  206. package/lib/index.d.ts +4 -3
  207. package/lib/index.d.ts.map +1 -1
  208. package/lib/index.js +3 -3
  209. package/lib/index.js.map +1 -1
  210. package/lib/opLifecycle/batchManager.d.ts +42 -0
  211. package/lib/opLifecycle/batchManager.d.ts.map +1 -0
  212. package/lib/opLifecycle/batchManager.js +120 -0
  213. package/lib/opLifecycle/batchManager.js.map +1 -0
  214. package/lib/opLifecycle/definitions.d.ts +64 -0
  215. package/lib/opLifecycle/definitions.d.ts.map +1 -0
  216. package/lib/opLifecycle/definitions.js +6 -0
  217. package/lib/opLifecycle/definitions.js.map +1 -0
  218. package/lib/opLifecycle/index.d.ts +12 -0
  219. package/lib/opLifecycle/index.d.ts.map +1 -0
  220. package/lib/opLifecycle/index.js +11 -0
  221. package/lib/opLifecycle/index.js.map +1 -0
  222. package/lib/{opCompressor.d.ts → opLifecycle/opCompressor.d.ts} +3 -3
  223. package/lib/opLifecycle/opCompressor.d.ts.map +1 -0
  224. package/lib/opLifecycle/opCompressor.js +63 -0
  225. package/lib/opLifecycle/opCompressor.js.map +1 -0
  226. package/lib/{opDecompressor.d.ts → opLifecycle/opDecompressor.d.ts} +2 -1
  227. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -0
  228. package/lib/{opDecompressor.js → opLifecycle/opDecompressor.js} +37 -21
  229. package/lib/opLifecycle/opDecompressor.js.map +1 -0
  230. package/lib/opLifecycle/opSplitter.d.ts +49 -0
  231. package/lib/opLifecycle/opSplitter.d.ts.map +1 -0
  232. package/lib/opLifecycle/opSplitter.js +168 -0
  233. package/lib/opLifecycle/opSplitter.js.map +1 -0
  234. package/lib/opLifecycle/outbox.d.ts +52 -0
  235. package/lib/opLifecycle/outbox.d.ts.map +1 -0
  236. package/lib/opLifecycle/outbox.js +160 -0
  237. package/lib/opLifecycle/outbox.js.map +1 -0
  238. package/lib/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  239. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  240. package/lib/opLifecycle/remoteMessageProcessor.js +91 -0
  241. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -0
  242. package/lib/opProperties.d.ts.map +1 -1
  243. package/lib/opProperties.js +1 -3
  244. package/lib/opProperties.js.map +1 -1
  245. package/lib/orderedClientElection.d.ts.map +1 -1
  246. package/lib/orderedClientElection.js +10 -4
  247. package/lib/orderedClientElection.js.map +1 -1
  248. package/lib/packageVersion.d.ts +1 -1
  249. package/lib/packageVersion.js +1 -1
  250. package/lib/packageVersion.js.map +1 -1
  251. package/lib/pendingStateManager.d.ts +4 -13
  252. package/lib/pendingStateManager.d.ts.map +1 -1
  253. package/lib/pendingStateManager.js +134 -161
  254. package/lib/pendingStateManager.js.map +1 -1
  255. package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
  256. package/lib/runWhileConnectedCoordinator.js.map +1 -1
  257. package/lib/runningSummarizer.d.ts.map +1 -1
  258. package/lib/runningSummarizer.js +35 -23
  259. package/lib/runningSummarizer.js.map +1 -1
  260. package/lib/scheduleManager.d.ts +0 -1
  261. package/lib/scheduleManager.d.ts.map +1 -1
  262. package/lib/scheduleManager.js +11 -21
  263. package/lib/scheduleManager.js.map +1 -1
  264. package/lib/serializedSnapshotStorage.d.ts.map +1 -1
  265. package/lib/serializedSnapshotStorage.js +3 -1
  266. package/lib/serializedSnapshotStorage.js.map +1 -1
  267. package/lib/summarizer.d.ts +2 -3
  268. package/lib/summarizer.d.ts.map +1 -1
  269. package/lib/summarizer.js +39 -18
  270. package/lib/summarizer.js.map +1 -1
  271. package/lib/summarizerClientElection.d.ts +1 -2
  272. package/lib/summarizerClientElection.d.ts.map +1 -1
  273. package/lib/summarizerClientElection.js +3 -30
  274. package/lib/summarizerClientElection.js.map +1 -1
  275. package/lib/summarizerHandle.d.ts.map +1 -1
  276. package/lib/summarizerHandle.js.map +1 -1
  277. package/lib/summarizerHeuristics.d.ts.map +1 -1
  278. package/lib/summarizerHeuristics.js +6 -9
  279. package/lib/summarizerHeuristics.js.map +1 -1
  280. package/lib/summarizerTypes.d.ts +22 -25
  281. package/lib/summarizerTypes.d.ts.map +1 -1
  282. package/lib/summarizerTypes.js.map +1 -1
  283. package/lib/summaryCollection.d.ts.map +1 -1
  284. package/lib/summaryCollection.js +18 -8
  285. package/lib/summaryCollection.js.map +1 -1
  286. package/lib/summaryFormat.d.ts.map +1 -1
  287. package/lib/summaryFormat.js +20 -13
  288. package/lib/summaryFormat.js.map +1 -1
  289. package/lib/summaryGenerator.d.ts.map +1 -1
  290. package/lib/summaryGenerator.js +32 -14
  291. package/lib/summaryGenerator.js.map +1 -1
  292. package/lib/summaryManager.d.ts.map +1 -1
  293. package/lib/summaryManager.js +21 -9
  294. package/lib/summaryManager.js.map +1 -1
  295. package/lib/throttler.d.ts +2 -2
  296. package/lib/throttler.d.ts.map +1 -1
  297. package/lib/throttler.js +4 -4
  298. package/lib/throttler.js.map +1 -1
  299. package/package.json +28 -38
  300. package/prettier.config.cjs +1 -1
  301. package/src/batchTracker.ts +55 -50
  302. package/src/blobManager.ts +802 -541
  303. package/src/connectionTelemetry.ts +280 -249
  304. package/src/containerHandleContext.ts +27 -29
  305. package/src/containerRuntime.ts +3125 -2982
  306. package/src/dataStore.ts +172 -159
  307. package/src/dataStoreContext.ts +1049 -992
  308. package/src/dataStoreContexts.ts +178 -161
  309. package/src/dataStoreRegistry.ts +25 -20
  310. package/src/dataStores.ts +785 -711
  311. package/src/deltaScheduler.ts +158 -150
  312. package/src/garbageCollection.ts +1797 -1558
  313. package/src/garbageCollectionConstants.ts +38 -0
  314. package/src/garbageCollectionHelpers.ts +37 -0
  315. package/src/gcSweepReadyUsageDetection.ts +90 -84
  316. package/src/index.ts +68 -69
  317. package/src/opLifecycle/batchManager.ts +167 -0
  318. package/src/opLifecycle/definitions.ts +70 -0
  319. package/src/opLifecycle/index.ts +18 -0
  320. package/src/opLifecycle/opCompressor.ts +82 -0
  321. package/src/opLifecycle/opDecompressor.ts +124 -0
  322. package/src/opLifecycle/opSplitter.ts +238 -0
  323. package/src/opLifecycle/outbox.ts +228 -0
  324. package/src/opLifecycle/remoteMessageProcessor.ts +106 -0
  325. package/src/opProperties.ts +11 -9
  326. package/src/orderedClientElection.ts +489 -457
  327. package/src/packageVersion.ts +1 -1
  328. package/src/pendingStateManager.ts +379 -381
  329. package/src/runWhileConnectedCoordinator.ts +78 -71
  330. package/src/runningSummarizer.ts +619 -582
  331. package/src/scheduleManager.ts +299 -280
  332. package/src/serializedSnapshotStorage.ts +116 -111
  333. package/src/summarizer.ts +417 -381
  334. package/src/summarizerClientElection.ts +107 -129
  335. package/src/summarizerHandle.ts +11 -9
  336. package/src/summarizerHeuristics.ts +183 -186
  337. package/src/summarizerTypes.ts +344 -333
  338. package/src/summaryCollection.ts +378 -349
  339. package/src/summaryFormat.ts +146 -127
  340. package/src/summaryGenerator.ts +464 -406
  341. package/src/summaryManager.ts +377 -348
  342. package/src/throttler.ts +131 -122
  343. package/tsconfig.esnext.json +6 -6
  344. package/tsconfig.json +9 -13
  345. package/dist/batchManager.d.ts +0 -42
  346. package/dist/batchManager.d.ts.map +0 -1
  347. package/dist/batchManager.js +0 -83
  348. package/dist/batchManager.js.map +0 -1
  349. package/dist/opCompressor.d.ts.map +0 -1
  350. package/dist/opCompressor.js +0 -50
  351. package/dist/opCompressor.js.map +0 -1
  352. package/dist/opDecompressor.d.ts.map +0 -1
  353. package/dist/opDecompressor.js.map +0 -1
  354. package/lib/batchManager.d.ts +0 -42
  355. package/lib/batchManager.d.ts.map +0 -1
  356. package/lib/batchManager.js +0 -79
  357. package/lib/batchManager.js.map +0 -1
  358. package/lib/opCompressor.d.ts.map +0 -1
  359. package/lib/opCompressor.js +0 -46
  360. package/lib/opCompressor.js.map +0 -1
  361. package/lib/opDecompressor.d.ts.map +0 -1
  362. package/lib/opDecompressor.js.map +0 -1
  363. package/src/batchManager.ts +0 -108
  364. package/src/opCompressor.ts +0 -59
  365. package/src/opDecompressor.ts +0 -82
@@ -3,11 +3,15 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { v4 as uuid } from "uuid";
6
- import { generateHandleContextPath, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
7
- import { assert, bufferToString, Deferred, stringToBuffer } from "@fluidframework/common-utils";
6
+ import { createResponseError, generateHandleContextPath, responseToException, SummaryTreeBuilder, } from "@fluidframework/runtime-utils";
7
+ import { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter, } from "@fluidframework/common-utils";
8
8
  import { AttachState } from "@fluidframework/container-definitions";
9
- import { ChildLogger, PerformanceEvent } from "@fluidframework/telemetry-utils";
9
+ import { ChildLogger, loggerToMonitoringContext, PerformanceEvent, } from "@fluidframework/telemetry-utils";
10
+ import { TombstoneResponseHeaderKey } from "./containerRuntime";
10
11
  import { Throttler, formExponentialFn } from "./throttler";
12
+ import { summarizerClientType } from "./summarizerClientElection";
13
+ import { throwOnTombstoneLoadKey } from "./garbageCollectionConstants";
14
+ import { sendGCUnexpectedUsageEvent } from "./garbageCollectionHelpers";
11
15
  /**
12
16
  * This class represents blob (long string)
13
17
  * This object is used only when creating (writing) new blob and serialization purposes.
@@ -23,7 +27,9 @@ export class BlobHandle {
23
27
  this.attached = false;
24
28
  this.absolutePath = generateHandleContextPath(path, this.routeContext);
25
29
  }
26
- get IFluidHandle() { return this; }
30
+ get IFluidHandle() {
31
+ return this;
32
+ }
27
33
  get isAttached() {
28
34
  return this.attached;
29
35
  }
@@ -59,27 +65,38 @@ var PendingBlobStatus;
59
65
  PendingBlobStatus[PendingBlobStatus["OfflinePendingUpload"] = 2] = "OfflinePendingUpload";
60
66
  PendingBlobStatus[PendingBlobStatus["OfflinePendingOp"] = 3] = "OfflinePendingOp";
61
67
  })(PendingBlobStatus || (PendingBlobStatus = {}));
62
- export class BlobManager {
68
+ export class BlobManager extends TypedEventEmitter {
63
69
  constructor(routeContext, snapshot, getStorage,
64
70
  /**
65
- * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
66
- * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server
67
- * will then not delete the blob as long as it is listed as referenced in future summaries.
68
- * The summarizing client will know to include the storage ID in the summary when it sees the op.
71
+ * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
72
+ * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
73
+ * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
74
+ * include the storage ID in the summary when it sees the op.
69
75
  *
70
- * The op may also include a local ID to inform all clients of the relation to the storage
71
- * ID, without knowledge of which they cannot request the blob from storage. This is also
72
- * included in the redirect table in the summary.
76
+ * The op will also include a local ID to inform all clients of the relation to the storage ID, without
77
+ * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
78
+ * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
73
79
  */
74
80
  sendBlobAttachOp,
75
- // To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's
76
- // of the format `/<BlobManager.basePath>/<blobId>`.
77
- gcNodeUpdated, runtime, stashedBlobs = {}) {
81
+ // Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.
82
+ // blobPath's format - `/<BlobManager.basePath>/<blobId>`.
83
+ blobRequested,
84
+ // Called when a reference is added to a blob. For instance, when creating a localId / storageId to storageId
85
+ // mapping in the redirect table.
86
+ // Node path formats - `/<BlobManager.basePath>/<blobId>`.
87
+ addedBlobReference,
88
+ // Called to check if a blob has been deleted by GC.
89
+ // blobPath's format - `/<BlobManager.basePath>/<blobId>`.
90
+ isBlobDeleted, runtime, stashedBlobs = {}, getCurrentReferenceTimestampMs) {
91
+ super();
78
92
  this.routeContext = routeContext;
79
93
  this.getStorage = getStorage;
80
94
  this.sendBlobAttachOp = sendBlobAttachOp;
81
- this.gcNodeUpdated = gcNodeUpdated;
95
+ this.blobRequested = blobRequested;
96
+ this.addedBlobReference = addedBlobReference;
97
+ this.isBlobDeleted = isBlobDeleted;
82
98
  this.runtime = runtime;
99
+ this.getCurrentReferenceTimestampMs = getCurrentReferenceTimestampMs;
83
100
  /**
84
101
  * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.
85
102
  * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so
@@ -87,15 +104,25 @@ export class BlobManager {
87
104
  */
88
105
  this.pendingBlobs = new Map();
89
106
  /**
90
- * Track ops in flight for online flow. Used to avoid searching pendingBlobs since BlobAttach ops
91
- * don't include local ID in online flow.
107
+ * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
108
+ * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
109
+ * because we know that the server will not delete the blob corresponding to that storage ID.
92
110
  */
93
111
  this.opsInFlight = new Map();
94
112
  this.retryThrottler = new CancellableThrottler(new Throttler(60 * 1000, // 60 sec delay window
95
113
  30 * 1000, // 30 sec max delay
96
114
  // throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)
97
115
  formExponentialFn({ coefficient: 20, initialDelay: 0 })));
98
- this.logger = ChildLogger.create(this.runtime.logger, "BlobManager");
116
+ /**
117
+ * This stores IDs of tombstoned blobs.
118
+ * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
119
+ */
120
+ this.tombstonedBlobs = new Set();
121
+ this.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, "BlobManager"));
122
+ // Read the feature flag that tells whether to throw when a tombstone blob is requested.
123
+ this.throwOnTombstoneLoad =
124
+ this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
125
+ this.runtime.clientDetails.type !== summarizerClientType;
99
126
  this.runtime.on("disconnected", () => this.onDisconnected());
100
127
  this.redirectTable = this.load(snapshot);
101
128
  // Begin uploading stashed blobs from previous container instance
@@ -110,19 +137,22 @@ export class BlobManager {
110
137
  });
111
138
  }
112
139
  get pendingOfflineUploads() {
113
- return Array.from(this.pendingBlobs.values())
114
- .filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
140
+ return Array.from(this.pendingBlobs.values()).filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
115
141
  }
116
142
  get hasPendingOfflineUploads() {
117
143
  return this.pendingOfflineUploads.length > 0;
118
144
  }
145
+ get hasPendingBlobs() {
146
+ return ((this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||
147
+ this.pendingBlobs.size > 0);
148
+ }
119
149
  /**
120
150
  * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
121
151
  */
122
152
  async onConnected() {
123
153
  this.retryThrottler.cancel();
124
154
  const pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);
125
- await PerformanceEvent.timedExecAsync(this.logger, {
155
+ await PerformanceEvent.timedExecAsync(this.mc.logger, {
126
156
  eventName: "BlobUploadOnConnected",
127
157
  count: pendingUploads.length,
128
158
  }, async () => Promise.all(pendingUploads), { start: true, end: true });
@@ -158,10 +188,14 @@ export class BlobManager {
158
188
  const undefinedValueInTable = ids.delete(undefined);
159
189
  // For a detached container, entries are inserted into the redirect table with an undefined storage ID.
160
190
  // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.
161
- assert(!undefinedValueInTable || this.runtime.attachState === AttachState.Detached && ids.size === 0, 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
191
+ assert(!undefinedValueInTable ||
192
+ (this.runtime.attachState === AttachState.Detached && ids.size === 0), 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
162
193
  return ids;
163
194
  }
164
195
  async getBlob(blobId) {
196
+ // Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,
197
+ // failing the call.
198
+ this.verifyBlobValidity(blobId);
165
199
  const pending = this.pendingBlobs.get(blobId);
166
200
  if (pending) {
167
201
  return pending.blob;
@@ -174,12 +208,13 @@ export class BlobManager {
174
208
  storageId = blobId;
175
209
  }
176
210
  else {
177
- storageId = this.redirectTable.get(blobId);
178
- assert(!!storageId, 0x11f /* "requesting unknown blobs" */);
211
+ const attachedStorageId = this.redirectTable.get(blobId);
212
+ assert(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
213
+ storageId = attachedStorageId;
179
214
  }
180
- // When a GC-able (not pending) blob is retrieved, let runtime know that the corresponding GC node got updated.
181
- this.gcNodeUpdated(this.getBlobGCNodePath(blobId));
182
- return PerformanceEvent.timedExecAsync(this.logger, { eventName: "AttachmentReadBlob", id: storageId }, async () => {
215
+ // Let runtime know that the corresponding GC node was requested.
216
+ this.blobRequested(this.getBlobGCNodePath(blobId));
217
+ return PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "AttachmentReadBlob", id: storageId }, async () => {
183
218
  return this.getStorage().readBlob(storageId);
184
219
  }, { end: true, cancel: "error" });
185
220
  }
@@ -191,7 +226,7 @@ export class BlobManager {
191
226
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
192
227
  // The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
193
228
  const response = await this.getStorage().createBlob(blob);
194
- this.redirectTable.set(response.id, undefined);
229
+ this.setRedirection(response.id, undefined);
195
230
  return this.getBlobHandle(response.id);
196
231
  }
197
232
  async createBlob(blob) {
@@ -200,12 +235,12 @@ export class BlobManager {
200
235
  }
201
236
  if (this.runtime.attachState === AttachState.Attaching) {
202
237
  // blob upload is not supported in "Attaching" state
203
- this.logger.sendTelemetryEvent({ eventName: "CreateBlobWhileAttaching" });
238
+ this.mc.logger.sendTelemetryEvent({ eventName: "CreateBlobWhileAttaching" });
204
239
  await new Promise((resolve) => this.runtime.once("attached", resolve));
205
240
  }
206
241
  assert(this.runtime.attachState === AttachState.Attached, 0x385 /* For clarity and paranoid defense against adding future attachment states */);
207
- // Create a local ID for each blob. This is used to support blobs if/when the client goes
208
- // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.
242
+ // Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
243
+ // storage ID mapping is created.
209
244
  const localId = uuid();
210
245
  const pendingEntry = {
211
246
  blob,
@@ -217,7 +252,27 @@ export class BlobManager {
217
252
  return pendingEntry.handleP.promise;
218
253
  }
219
254
  async uploadBlob(localId, blob) {
220
- return PerformanceEvent.timedExecAsync(this.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));
255
+ 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));
256
+ }
257
+ /**
258
+ * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
259
+ * which is required for GC.
260
+ */
261
+ setRedirection(fromId, toId) {
262
+ this.redirectTable.set(fromId, toId);
263
+ // Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in
264
+ // detached mode. In this case, the entry will be updated when the blob is updated.
265
+ if (toId !== undefined) {
266
+ this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));
267
+ }
268
+ }
269
+ deleteAndEmitsIfEmpty(id) {
270
+ if (this.pendingBlobs.has(id)) {
271
+ this.pendingBlobs.delete(id);
272
+ if (!this.hasPendingBlobs) {
273
+ this.emit("noPendingBlobs");
274
+ }
275
+ }
221
276
  }
222
277
  onUploadResolve(localId, response) {
223
278
  var _a;
@@ -225,19 +280,30 @@ export class BlobManager {
225
280
  assert((entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OnlinePendingUpload ||
226
281
  (entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OfflinePendingUpload, 0x386 /* Must have pending blob entry for uploaded blob */);
227
282
  entry.storageId = response.id;
283
+ entry.localUploadTime = Date.now();
284
+ entry.minTTLInSeconds = response.minTTLInSeconds;
285
+ entry.serverUploadTime = this.getCurrentReferenceTimestampMs();
228
286
  if (this.runtime.connected) {
229
287
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
288
+ // Send a blob attach op. This serves two purposes:
289
+ // 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
290
+ // until its storage ID is added to the next summary.
291
+ // 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
292
+ // blob from the server via the storage ID.
293
+ this.logTimeInfo(entry, "sendBlobAttachResolveTTL");
294
+ this.sendBlobAttachOp(localId, response.id);
230
295
  if (this.storageIds.has(response.id)) {
231
- // Storage may dedupe blobs and give us an ID we already know
232
- // no need to submit BlobAttach op in this case
233
- entry.handleP.resolve(this.getBlobHandle(response.id));
234
- this.pendingBlobs.delete(localId);
296
+ // The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
297
+ // an existing blob, we don't have to wait for the op to be ack'd since this step has already
298
+ // happened before and so, the server won't delete it.
299
+ this.setRedirection(localId, response.id);
300
+ entry.handleP.resolve(this.getBlobHandle(localId));
301
+ this.deleteAndEmitsIfEmpty(localId);
235
302
  }
236
303
  else {
237
- // Check for still-pending duplicates too; if an op is already in flight we can wait for that one
238
- if (!this.opsInFlight.has(response.id)) {
239
- this.sendBlobAttachOp(response.id);
240
- }
304
+ // If there is already an op for this storage ID, append the local ID to the list. Once any op for
305
+ // this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
306
+ // blob alive in storage.
241
307
  this.opsInFlight.set(response.id, ((_a = this.opsInFlight.get(response.id)) !== null && _a !== void 0 ? _a : []).concat(localId));
242
308
  entry.status = PendingBlobStatus.OnlinePendingOp;
243
309
  }
@@ -249,7 +315,7 @@ export class BlobManager {
249
315
  }
250
316
  else {
251
317
  // connected to storage but not ordering service?
252
- this.logger.sendTelemetryEvent({ eventName: "BlobUploadSuccessWhileDisconnected" });
318
+ this.mc.logger.sendTelemetryEvent({ eventName: "BlobUploadSuccessWhileDisconnected" });
253
319
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
254
320
  this.transitionToOffline(localId);
255
321
  }
@@ -265,7 +331,9 @@ export class BlobManager {
265
331
  this.transitionToOffline(localId);
266
332
  }
267
333
  // we are probably not connected to storage but start another upload request in case we are
268
- entry.uploadP = this.retryThrottler.getDelay().then(async () => this.uploadBlob(localId, entry.blob));
334
+ entry.uploadP = this.retryThrottler
335
+ .getDelay()
336
+ .then(async () => this.uploadBlob(localId, entry.blob));
269
337
  return entry.uploadP;
270
338
  }
271
339
  else {
@@ -278,15 +346,21 @@ export class BlobManager {
278
346
  const entry = this.pendingBlobs.get(localId);
279
347
  assert(!!entry, 0x389 /* No pending blob entry */);
280
348
  assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), 0x38a /* Blob must be in online flow to transition to offline flow */);
281
- entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
282
- ? PendingBlobStatus.OfflinePendingUpload
283
- : PendingBlobStatus.OfflinePendingOp;
284
- // Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the
285
- // BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be
286
- // added to the document if the ops are not all successfully submitted upon reconnection.
287
- // storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
288
- // is called
289
- this.sendBlobAttachOp(entry.storageId, localId);
349
+ /**
350
+ * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
351
+ * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
352
+ * an invalid handle could be added to the document.
353
+ * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
354
+ * is called on reconnection.
355
+ */
356
+ if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
357
+ this.logTimeInfo(entry, "sendBlobAttachTransitionOfflineTTL");
358
+ this.sendBlobAttachOp(localId, entry.storageId);
359
+ }
360
+ entry.status =
361
+ entry.status === PendingBlobStatus.OnlinePendingUpload
362
+ ? PendingBlobStatus.OfflinePendingUpload
363
+ : PendingBlobStatus.OfflinePendingOp;
290
364
  entry.handleP.resolve(this.getBlobHandle(localId));
291
365
  }
292
366
  /**
@@ -296,45 +370,81 @@ export class BlobManager {
296
370
  */
297
371
  reSubmit(metadata) {
298
372
  assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
299
- const { blobId, localId } = metadata;
373
+ const { localId, blobId } = metadata;
374
+ assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
375
+ const pendingEntry = this.pendingBlobs.get(localId);
376
+ if (pendingEntry) {
377
+ this.logTimeInfo(pendingEntry, "sendBlobAttachResubmitTTL");
378
+ }
300
379
  if (!blobId) {
301
- assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
302
380
  // We submitted this op while offline. The blob should have been uploaded by now.
303
- const pendingEntry = this.pendingBlobs.get(localId);
304
381
  assert((pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.status) === PendingBlobStatus.OfflinePendingOp &&
305
382
  !!(pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.storageId), 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
306
- return this.sendBlobAttachOp(pendingEntry.storageId, localId);
383
+ return this.sendBlobAttachOp(localId, pendingEntry.storageId);
307
384
  }
308
- return this.sendBlobAttachOp(blobId, localId);
385
+ return this.sendBlobAttachOp(localId, blobId);
386
+ }
387
+ logTimeInfo(pendingEntry, eventName) {
388
+ var _a, _b;
389
+ let timeLapseSinceLocalUpload = 0;
390
+ let timeLapseSinceServerUpload = 0;
391
+ let expiredUsingLocalTime;
392
+ let expiredUsingServerTime;
393
+ if (pendingEntry.localUploadTime) {
394
+ timeLapseSinceLocalUpload = (Date.now() - pendingEntry.localUploadTime) / 1000;
395
+ expiredUsingLocalTime =
396
+ ((_a = pendingEntry.minTTLInSeconds) !== null && _a !== void 0 ? _a : 0) - timeLapseSinceLocalUpload < 0 ? true : false;
397
+ }
398
+ if (pendingEntry.serverUploadTime) {
399
+ timeLapseSinceServerUpload = (Date.now() - pendingEntry.serverUploadTime) / 1000;
400
+ expiredUsingServerTime =
401
+ ((_b = pendingEntry.minTTLInSeconds) !== null && _b !== void 0 ? _b : 0) - timeLapseSinceServerUpload < 0 ? true : false;
402
+ }
403
+ this.mc.logger.sendTelemetryEvent({
404
+ eventName,
405
+ entryStatus: pendingEntry.status,
406
+ timeLapseSinceLocalUpload,
407
+ timeLapseSinceServerUpload,
408
+ minTTLInSeconds: pendingEntry.minTTLInSeconds,
409
+ expiredUsingLocalTime,
410
+ expiredUsingServerTime,
411
+ });
309
412
  }
310
413
  processBlobAttachOp(message, local) {
311
414
  var _a, _b;
312
- 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" */);
313
- if (message.metadata.localId !== undefined) {
314
- this.redirectTable.set(message.metadata.localId, message.metadata.blobId);
415
+ const localId = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.localId;
416
+ const blobId = (_b = message.metadata) === null || _b === void 0 ? void 0 : _b.blobId;
417
+ assert(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
418
+ // Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
419
+ // requested from the server.
420
+ // Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
421
+ // was sent when online.
422
+ if (localId !== undefined) {
423
+ this.setRedirection(localId, blobId);
315
424
  }
316
425
  // set identity (id -> id) entry
317
- this.redirectTable.set(message.metadata.blobId, message.metadata.blobId);
426
+ this.setRedirection(blobId, blobId);
318
427
  if (local) {
319
- if (message.metadata.localId === undefined) {
320
- // Since there is no local ID, we know this op was submitted while online.
321
- const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);
322
- assert(!!waitingBlobs, 0x38e /* local online BlobAttach op with no pending blob */);
323
- waitingBlobs.forEach((localId) => {
324
- const pendingBlobEntry = this.pendingBlobs.get(localId);
325
- assert(pendingBlobEntry !== undefined, 0x38f);
428
+ assert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
429
+ const waitingBlobs = this.opsInFlight.get(blobId);
430
+ if (waitingBlobs !== undefined) {
431
+ // For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
432
+ // This is safe because the server will keep the blob alive and the op containing the local ID to
433
+ // storage ID is already in flight and any op containing this local ID will be sequenced after that.
434
+ waitingBlobs.forEach((pendingLocalId) => {
435
+ const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
436
+ assert(pendingBlobEntry !== undefined, 0x38f /* local online BlobAttach op with no pending blob entry */);
326
437
  // It's possible we transitioned to offline flow while waiting for this op.
327
438
  if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
328
- pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));
329
- this.pendingBlobs.delete(localId);
439
+ this.setRedirection(pendingLocalId, blobId);
440
+ pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
441
+ this.deleteAndEmitsIfEmpty(pendingLocalId);
330
442
  }
331
443
  });
444
+ this.opsInFlight.delete(blobId);
332
445
  }
333
- else {
334
- // Each local ID is unique; get the pending blob entry and delete it
335
- 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" */);
336
- this.pendingBlobs.delete(message.metadata.localId);
337
- }
446
+ // For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
447
+ this.deleteAndEmitsIfEmpty(localId);
338
448
  }
339
449
  }
340
450
  /**
@@ -353,7 +463,8 @@ export class BlobManager {
353
463
  redirectTable = await tryFetchBlob(tableId);
354
464
  }
355
465
  const ids = Object.entries(blobsTree.blobs)
356
- .filter(([k, _]) => k !== this.redirectTableBlobName).map(([_, v]) => v);
466
+ .filter(([k, _]) => k !== this.redirectTableBlobName)
467
+ .map(([_, v]) => v);
357
468
  return { ids, redirectTable };
358
469
  }
359
470
  /**
@@ -361,7 +472,7 @@ export class BlobManager {
361
472
  */
362
473
  load(snapshot) {
363
474
  var _a, _b, _c;
364
- this.logger.sendTelemetryEvent({
475
+ this.mc.logger.sendTelemetryEvent({
365
476
  eventName: "AttachmentBlobsLoaded",
366
477
  count: (_b = (_a = snapshot.ids) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0,
367
478
  redirectTable: (_c = snapshot.redirectTable) === null || _c === void 0 ? void 0 : _c.length,
@@ -383,49 +494,93 @@ export class BlobManager {
383
494
  */
384
495
  getGCData(fullGC = false) {
385
496
  const gcData = { gcNodes: {} };
386
- /**
387
- * The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned
388
- * by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.
389
- */
390
- this.storageIds.forEach((blobId) => {
391
- gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];
392
- });
393
- // For some blobs, the handle returned on creation is based off of the localId. So, these
394
- // nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node
395
- // must also be marked referenced. So, we add a route from the localId node to the storageId node.
396
- // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
397
- // a blob may be referenced via its storageId handle.
398
497
  for (const [localId, storageId] of this.redirectTable) {
399
498
  assert(!!storageId, 0x390 /* Must be attached to get GC data */);
400
- // Add node for the localId and add a route to the storageId node. The storageId node will have been
401
- // added above when adding nodes for this.blobIds.
402
499
  gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
403
500
  }
404
501
  return gcData;
405
502
  }
406
503
  /**
407
- * When running GC in test mode, this is called to delete blobs that are unused.
408
- * @param unusedRoutes - These are the blob node ids that are unused and should be deleted.
504
+ * This is called to update blobs whose routes are unused. The unused blobs are deleted.
505
+ * @param unusedRoutes - The routes of the blob nodes that are unused.
409
506
  */
410
- deleteUnusedRoutes(unusedRoutes) {
411
- var _a;
507
+ updateUnusedRoutes(unusedRoutes) {
412
508
  // The routes or blob node paths are in the same format as returned in getGCData -
413
509
  // `/<BlobManager.basePath>/<blobId>`.
414
510
  for (const route of unusedRoutes) {
415
511
  const pathParts = route.split("/");
416
512
  assert(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x2d5 /* "Invalid blob node id in unused routes." */);
417
513
  const blobId = pathParts[2];
418
- // The unused blobId could be a localId. If so, remove it from the redirect table and continue. The
419
- // corresponding storageId may still be used either directly or via other localIds.
420
- if ((_a = this.redirectTable) === null || _a === void 0 ? void 0 : _a.has(blobId)) {
421
- this.redirectTable.delete(blobId);
422
- continue;
514
+ this.redirectTable.delete(blobId);
515
+ }
516
+ }
517
+ /**
518
+ * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
519
+ * accessing deleted content without actually deleting content from summaries.
520
+ * @param tombstonedRoutes - The routes of blob nodes that are tombstones.
521
+ */
522
+ updateTombstonedRoutes(tombstonedRoutes) {
523
+ const tombstonedBlobsSet = new Set();
524
+ // The routes or blob node paths are in the same format as returned in getGCData -
525
+ // `/<BlobManager.basePath>/<blobId>`.
526
+ for (const route of tombstonedRoutes) {
527
+ const pathParts = route.split("/");
528
+ assert(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x50f /* Invalid blob node id in tombstoned routes. */);
529
+ tombstonedBlobsSet.add(pathParts[2]);
530
+ }
531
+ // Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
532
+ for (const blobId of this.tombstonedBlobs) {
533
+ if (!tombstonedBlobsSet.has(blobId)) {
534
+ this.tombstonedBlobs.delete(blobId);
423
535
  }
424
536
  }
537
+ // Mark blobs that are now tombstoned by adding them to the tombstone list.
538
+ for (const blobId of tombstonedBlobsSet) {
539
+ this.tombstonedBlobs.add(blobId);
540
+ }
541
+ }
542
+ /**
543
+ * Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,
544
+ * log an error and throw if necessary.
545
+ */
546
+ verifyBlobValidity(blobId) {
547
+ /**
548
+ * A blob can be in one of the following states:
549
+ * 1. "deleted" - It has been deleted by garbage collection sweep phase.
550
+ * 2. "tombstoned" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.
551
+ * 3. "valid" - It has not been deleted or tombstoned.
552
+ */
553
+ let state = "valid";
554
+ if (this.isBlobDeleted(this.getBlobGCNodePath(blobId))) {
555
+ state = "deleted";
556
+ }
557
+ else if (this.tombstonedBlobs.has(blobId)) {
558
+ state = "tombstoned";
559
+ }
560
+ if (state === "valid") {
561
+ return;
562
+ }
563
+ // If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt
564
+ // to load the blob.
565
+ const shouldFail = state === "deleted" || this.throwOnTombstoneLoad;
566
+ const request = { url: blobId };
567
+ const error = responseToException(createResponseError(404, "Blob was deleted", request, state === "tombstoned" ? { [TombstoneResponseHeaderKey]: true } : undefined), request);
568
+ sendGCUnexpectedUsageEvent(this.mc, {
569
+ eventName: state === "tombstoned"
570
+ ? "GC_Tombstone_Blob_Requested"
571
+ : "GC_Deleted_Blob_Requested",
572
+ category: shouldFail ? "error" : "generic",
573
+ isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
574
+ }, [BlobManager.basePath], error);
575
+ if (shouldFail) {
576
+ throw error;
577
+ }
425
578
  }
426
579
  summarize(telemetryContext) {
427
580
  // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
428
- const blobIds = this.storageIds.size > 0 ? Array.from(this.storageIds) : Array.from(this.redirectTable.keys());
581
+ const blobIds = this.storageIds.size > 0
582
+ ? Array.from(this.storageIds)
583
+ : Array.from(this.redirectTable.keys());
429
584
  const builder = new SummaryTreeBuilder();
430
585
  blobIds.forEach((blobId) => {
431
586
  builder.addAttachment(blobId);
@@ -434,8 +589,7 @@ export class BlobManager {
434
589
  if (this.redirectTable.size > blobIds.length) {
435
590
  builder.addBlob(BlobManager.redirectTableBlobName,
436
591
  // filter out identity entries
437
- JSON.stringify(Array.from(this.redirectTable.entries())
438
- .filter(([localId, storageId]) => localId !== storageId)));
592
+ JSON.stringify(Array.from(this.redirectTable.entries()).filter(([localId, storageId]) => localId !== storageId)));
439
593
  }
440
594
  return builder.getSummaryTree();
441
595
  }
@@ -444,9 +598,9 @@ export class BlobManager {
444
598
  assert(this.redirectTable.size === table.size, 0x391 /* Redirect table size must match BlobManager's local ID count */);
445
599
  for (const [localId, storageId] of table) {
446
600
  assert(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
447
- this.redirectTable.set(localId, storageId);
601
+ this.setRedirection(localId, storageId);
448
602
  // set identity (id -> id) entry
449
- this.redirectTable.set(storageId, storageId);
603
+ this.setRedirection(storageId, storageId);
450
604
  }
451
605
  }
452
606
  getPendingBlobs() {