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