@fluidframework/container-runtime 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.0

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 (195) hide show
  1. package/.eslintrc.js +19 -8
  2. package/dist/batchTracker.d.ts +1 -2
  3. package/dist/batchTracker.d.ts.map +1 -1
  4. package/dist/batchTracker.js.map +1 -1
  5. package/dist/blobManager.d.ts +44 -33
  6. package/dist/blobManager.d.ts.map +1 -1
  7. package/dist/blobManager.js +130 -97
  8. package/dist/blobManager.js.map +1 -1
  9. package/dist/containerRuntime.d.ts +39 -8
  10. package/dist/containerRuntime.d.ts.map +1 -1
  11. package/dist/containerRuntime.js +117 -61
  12. package/dist/containerRuntime.js.map +1 -1
  13. package/dist/dataStoreContext.d.ts +1 -1
  14. package/dist/dataStoreContext.d.ts.map +1 -1
  15. package/dist/dataStoreContext.js +4 -3
  16. package/dist/dataStoreContext.js.map +1 -1
  17. package/dist/dataStores.d.ts +9 -6
  18. package/dist/dataStores.d.ts.map +1 -1
  19. package/dist/dataStores.js +30 -24
  20. package/dist/dataStores.js.map +1 -1
  21. package/dist/garbageCollection.d.ts +41 -20
  22. package/dist/garbageCollection.d.ts.map +1 -1
  23. package/dist/garbageCollection.js +205 -151
  24. package/dist/garbageCollection.js.map +1 -1
  25. package/dist/garbageCollectionConstants.d.ts +6 -3
  26. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  27. package/dist/garbageCollectionConstants.js +7 -7
  28. package/dist/garbageCollectionConstants.js.map +1 -1
  29. package/dist/garbageCollectionTombstoneUtils.d.ts +13 -0
  30. package/dist/garbageCollectionTombstoneUtils.d.ts.map +1 -0
  31. package/dist/garbageCollectionTombstoneUtils.js +28 -0
  32. package/dist/garbageCollectionTombstoneUtils.js.map +1 -0
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +1 -5
  36. package/dist/index.js.map +1 -1
  37. package/dist/opLifecycle/batchManager.d.ts +13 -1
  38. package/dist/opLifecycle/batchManager.d.ts.map +1 -1
  39. package/dist/opLifecycle/batchManager.js +35 -1
  40. package/dist/opLifecycle/batchManager.js.map +1 -1
  41. package/dist/opLifecycle/definitions.d.ts +25 -1
  42. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  43. package/dist/opLifecycle/definitions.js.map +1 -1
  44. package/dist/opLifecycle/index.d.ts +2 -2
  45. package/dist/opLifecycle/index.d.ts.map +1 -1
  46. package/dist/opLifecycle/index.js +2 -1
  47. package/dist/opLifecycle/index.js.map +1 -1
  48. package/dist/opLifecycle/opCompressor.d.ts +1 -1
  49. package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
  50. package/dist/opLifecycle/opCompressor.js +24 -10
  51. package/dist/opLifecycle/opCompressor.js.map +1 -1
  52. package/dist/opLifecycle/opDecompressor.d.ts +2 -1
  53. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  54. package/dist/opLifecycle/opDecompressor.js +30 -17
  55. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  56. package/dist/opLifecycle/opSplitter.d.ts +34 -2
  57. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  58. package/dist/opLifecycle/opSplitter.js +114 -5
  59. package/dist/opLifecycle/opSplitter.js.map +1 -1
  60. package/dist/opLifecycle/outbox.d.ts +5 -0
  61. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  62. package/dist/opLifecycle/outbox.js +24 -14
  63. package/dist/opLifecycle/outbox.js.map +1 -1
  64. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  65. package/dist/opLifecycle/remoteMessageProcessor.js +17 -2
  66. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  67. package/dist/packageVersion.d.ts +1 -1
  68. package/dist/packageVersion.js +1 -1
  69. package/dist/packageVersion.js.map +1 -1
  70. package/dist/runningSummarizer.d.ts.map +1 -1
  71. package/dist/runningSummarizer.js +0 -1
  72. package/dist/runningSummarizer.js.map +1 -1
  73. package/dist/scheduleManager.d.ts +0 -1
  74. package/dist/scheduleManager.d.ts.map +1 -1
  75. package/dist/scheduleManager.js +9 -20
  76. package/dist/scheduleManager.js.map +1 -1
  77. package/dist/summarizer.d.ts +0 -1
  78. package/dist/summarizer.d.ts.map +1 -1
  79. package/dist/summarizer.js +2 -1
  80. package/dist/summarizer.js.map +1 -1
  81. package/dist/summarizerTypes.d.ts +1 -0
  82. package/dist/summarizerTypes.d.ts.map +1 -1
  83. package/dist/summarizerTypes.js.map +1 -1
  84. package/dist/summaryFormat.d.ts.map +1 -1
  85. package/dist/summaryFormat.js +1 -2
  86. package/dist/summaryFormat.js.map +1 -1
  87. package/lib/batchTracker.d.ts +1 -2
  88. package/lib/batchTracker.d.ts.map +1 -1
  89. package/lib/batchTracker.js.map +1 -1
  90. package/lib/blobManager.d.ts +44 -33
  91. package/lib/blobManager.d.ts.map +1 -1
  92. package/lib/blobManager.js +131 -98
  93. package/lib/blobManager.js.map +1 -1
  94. package/lib/containerRuntime.d.ts +39 -8
  95. package/lib/containerRuntime.d.ts.map +1 -1
  96. package/lib/containerRuntime.js +115 -59
  97. package/lib/containerRuntime.js.map +1 -1
  98. package/lib/dataStoreContext.d.ts +1 -1
  99. package/lib/dataStoreContext.d.ts.map +1 -1
  100. package/lib/dataStoreContext.js +5 -4
  101. package/lib/dataStoreContext.js.map +1 -1
  102. package/lib/dataStores.d.ts +9 -6
  103. package/lib/dataStores.d.ts.map +1 -1
  104. package/lib/dataStores.js +32 -26
  105. package/lib/dataStores.js.map +1 -1
  106. package/lib/garbageCollection.d.ts +41 -20
  107. package/lib/garbageCollection.d.ts.map +1 -1
  108. package/lib/garbageCollection.js +201 -147
  109. package/lib/garbageCollection.js.map +1 -1
  110. package/lib/garbageCollectionConstants.d.ts +6 -3
  111. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  112. package/lib/garbageCollectionConstants.js +6 -6
  113. package/lib/garbageCollectionConstants.js.map +1 -1
  114. package/lib/garbageCollectionTombstoneUtils.d.ts +13 -0
  115. package/lib/garbageCollectionTombstoneUtils.d.ts.map +1 -0
  116. package/lib/garbageCollectionTombstoneUtils.js +24 -0
  117. package/lib/garbageCollectionTombstoneUtils.js.map +1 -0
  118. package/lib/index.d.ts +0 -1
  119. package/lib/index.d.ts.map +1 -1
  120. package/lib/index.js +0 -1
  121. package/lib/index.js.map +1 -1
  122. package/lib/opLifecycle/batchManager.d.ts +13 -1
  123. package/lib/opLifecycle/batchManager.d.ts.map +1 -1
  124. package/lib/opLifecycle/batchManager.js +35 -1
  125. package/lib/opLifecycle/batchManager.js.map +1 -1
  126. package/lib/opLifecycle/definitions.d.ts +25 -1
  127. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  128. package/lib/opLifecycle/definitions.js.map +1 -1
  129. package/lib/opLifecycle/index.d.ts +2 -2
  130. package/lib/opLifecycle/index.d.ts.map +1 -1
  131. package/lib/opLifecycle/index.js +1 -1
  132. package/lib/opLifecycle/index.js.map +1 -1
  133. package/lib/opLifecycle/opCompressor.d.ts +1 -1
  134. package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
  135. package/lib/opLifecycle/opCompressor.js +24 -10
  136. package/lib/opLifecycle/opCompressor.js.map +1 -1
  137. package/lib/opLifecycle/opDecompressor.d.ts +2 -1
  138. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  139. package/lib/opLifecycle/opDecompressor.js +30 -17
  140. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  141. package/lib/opLifecycle/opSplitter.d.ts +34 -2
  142. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  143. package/lib/opLifecycle/opSplitter.js +112 -4
  144. package/lib/opLifecycle/opSplitter.js.map +1 -1
  145. package/lib/opLifecycle/outbox.d.ts +5 -0
  146. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  147. package/lib/opLifecycle/outbox.js +24 -14
  148. package/lib/opLifecycle/outbox.js.map +1 -1
  149. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  150. package/lib/opLifecycle/remoteMessageProcessor.js +17 -2
  151. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  152. package/lib/packageVersion.d.ts +1 -1
  153. package/lib/packageVersion.js +1 -1
  154. package/lib/packageVersion.js.map +1 -1
  155. package/lib/runningSummarizer.d.ts.map +1 -1
  156. package/lib/runningSummarizer.js +0 -1
  157. package/lib/runningSummarizer.js.map +1 -1
  158. package/lib/scheduleManager.d.ts +0 -1
  159. package/lib/scheduleManager.d.ts.map +1 -1
  160. package/lib/scheduleManager.js +9 -20
  161. package/lib/scheduleManager.js.map +1 -1
  162. package/lib/summarizer.d.ts +0 -1
  163. package/lib/summarizer.d.ts.map +1 -1
  164. package/lib/summarizer.js +2 -1
  165. package/lib/summarizer.js.map +1 -1
  166. package/lib/summarizerTypes.d.ts +1 -0
  167. package/lib/summarizerTypes.d.ts.map +1 -1
  168. package/lib/summarizerTypes.js.map +1 -1
  169. package/lib/summaryFormat.d.ts.map +1 -1
  170. package/lib/summaryFormat.js +1 -2
  171. package/lib/summaryFormat.js.map +1 -1
  172. package/package.json +37 -19
  173. package/src/batchTracker.ts +1 -1
  174. package/src/blobManager.ts +146 -103
  175. package/src/containerRuntime.ts +166 -65
  176. package/src/dataStoreContext.ts +5 -5
  177. package/src/dataStores.ts +40 -30
  178. package/src/garbageCollection.ts +254 -183
  179. package/src/garbageCollectionConstants.ts +7 -6
  180. package/src/garbageCollectionTombstoneUtils.ts +31 -0
  181. package/src/index.ts +0 -5
  182. package/src/opLifecycle/batchManager.ts +59 -1
  183. package/src/opLifecycle/definitions.ts +27 -1
  184. package/src/opLifecycle/index.ts +2 -1
  185. package/src/opLifecycle/opCompressor.ts +29 -12
  186. package/src/opLifecycle/opDecompressor.ts +39 -18
  187. package/src/opLifecycle/opSplitter.ts +141 -7
  188. package/src/opLifecycle/outbox.ts +32 -16
  189. package/src/opLifecycle/remoteMessageProcessor.ts +19 -3
  190. package/src/packageVersion.ts +1 -1
  191. package/src/runningSummarizer.ts +0 -1
  192. package/src/scheduleManager.ts +19 -30
  193. package/src/summarizer.ts +1 -1
  194. package/src/summarizerTypes.ts +1 -0
  195. package/src/summaryFormat.ts +1 -2
package/.eslintrc.js CHANGED
@@ -4,13 +4,24 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- "extends": [
8
- require.resolve("@fluidframework/eslint-config-fluid"), "prettier"
9
- ],
10
- "parserOptions": {
11
- "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
12
10
  },
13
- "rules": {
11
+ rules: {
14
12
  "@typescript-eslint/strict-boolean-expressions": "off",
15
- }
16
- }
13
+
14
+ // This library is used in the browser, so we don't want dependencies on most node libraries.
15
+ "import/no-nodejs-modules": ["error", { allow: ["events"] }],
16
+ },
17
+ overrides: [
18
+ {
19
+ // Rules only for test files
20
+ files: ["*.spec.ts", "src/test/**"],
21
+ rules: {
22
+ // Test files are run in node only so additional node libraries can be used.
23
+ "import/no-nodejs-modules": ["error", { allow: ["assert", "crypto", "events"] }],
24
+ },
25
+ },
26
+ ],
27
+ };
@@ -2,8 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- /// <reference types="node" />
6
- import EventEmitter from "events";
5
+ import { EventEmitter } from "events";
7
6
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
8
7
  export declare class BatchTracker {
9
8
  private readonly batchEventEmitter;
@@ -1 +1 @@
1
- {"version":3,"file":"batchTracker.d.ts","sourceRoot":"","sources":["../src/batchTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAKtE,qBAAa,YAAY;IAOjB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IANtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,6BAA6B,CAAqB;gBAGrC,iBAAiB,EAAE,YAAY,EAChD,MAAM,EAAE,gBAAgB,EACxB,oBAAoB,EAAE,MAAM,EAC5B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAM,MAAgC;CAyC/D;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,sBACN,YAAY,UACvB,gBAAgB,yBACF,MAAM,2BACJ,MAAM,iBAC4D,CAAC"}
1
+ {"version":3,"file":"batchTracker.d.ts","sourceRoot":"","sources":["../src/batchTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAKtE,qBAAa,YAAY;IAOjB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IANtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,wBAAwB,CAAqB;IACrD,OAAO,CAAC,iBAAiB,CAAa;IACtC,OAAO,CAAC,6BAA6B,CAAqB;gBAGrC,iBAAiB,EAAE,YAAY,EAChD,MAAM,EAAE,gBAAgB,EACxB,oBAAoB,EAAE,MAAM,EAC5B,sBAAsB,EAAE,MAAM,EAC9B,gBAAgB,GAAE,MAAM,MAAgC;CAyC/D;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,sBACN,YAAY,UACvB,gBAAgB,yBACF,MAAM,2BACJ,MAAM,iBAC4D,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"batchTracker.js","sourceRoot":"","sources":["../src/batchTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAAmE;AAEnE,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AAG,sBAAsB,KAAK,CAAC,EAAE;gBACvD,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;oBAC7B,SAAS,EAAE,QAAQ;oBACnB,MAAM;oBACN,YAAY,EAAE,sBAAsB;oBACpC,sBAAsB,EAAE,OAAO,CAAC,cAAc;oBAC9C,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,6BAA6B;iBACpE,CAAC,CAAC;aACN;YAED,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,6BAA6B,GAAG,SAAS,CAAC;QACnD,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AApDD,oCAoDC;AAED;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAC5B,iBAA+B,EAC/B,MAAwB,EACxB,uBAA+B,IAAI,EACnC,yBAAiC,IAAI,EACvC,EAAE,CAAC,IAAI,YAAY,CAAC,iBAAiB,EAAE,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;AALlF,QAAA,gBAAgB,oBAKkE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport EventEmitter from \"events\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\n\nexport class BatchTracker {\n private readonly logger: ITelemetryLogger;\n private startBatchSequenceNumber: number | undefined;\n private trackedBatchCount: number = 0;\n private batchProcessingStartTimeStamp: number | undefined;\n\n constructor(\n private readonly batchEventEmitter: EventEmitter,\n logger: ITelemetryLogger,\n batchLengthThreshold: number,\n batchCountSamplingRate: number,\n dateTimeProvider: () => number = () => performance.now(),\n ) {\n this.logger = ChildLogger.create(logger, \"Batching\");\n\n this.batchEventEmitter.on(\"batchBegin\", (message: ISequencedDocumentMessage) => {\n this.startBatchSequenceNumber = message.sequenceNumber;\n this.batchProcessingStartTimeStamp = dateTimeProvider();\n this.trackedBatchCount++;\n });\n\n this.batchEventEmitter.on(\"batchEnd\", (error: any | undefined, message: ISequencedDocumentMessage) => {\n assert(\n this.startBatchSequenceNumber !== undefined && this.batchProcessingStartTimeStamp !== undefined,\n 0x2ba /* \"batchBegin must fire before batchEnd\" */);\n\n const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;\n if (length >= batchLengthThreshold) {\n this.logger.sendPerformanceEvent({\n eventName: \"LengthTooBig\",\n length,\n threshold: batchLengthThreshold,\n batchEndSequenceNumber: message.sequenceNumber,\n duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,\n batchError: error !== undefined,\n });\n }\n\n if (this.trackedBatchCount % batchCountSamplingRate === 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"Length\",\n length,\n samplingRate: batchCountSamplingRate,\n batchEndSequenceNumber: message.sequenceNumber,\n duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,\n });\n }\n\n this.startBatchSequenceNumber = undefined;\n this.batchProcessingStartTimeStamp = undefined;\n });\n }\n}\n\n/**\n * Track batch sizes in terms of op counts and processing times\n *\n * @param batchEventEmitter - event emitter which tracks the lifecycle of batch operations\n * @param logger - See {@link @fluidframework/common-definitions#ITelemetryLogger}\n * @param batchLengthThreshold - threshold for the length of a batch when to send an error event\n * @param batchCountSamplingRate - rate for batches for which to send an event with its characteristics\n */\nexport const BindBatchTracker = (\n batchEventEmitter: EventEmitter,\n logger: ITelemetryLogger,\n batchLengthThreshold: number = 1000,\n batchCountSamplingRate: number = 1000,\n) => new BatchTracker(batchEventEmitter, logger, batchLengthThreshold, batchCountSamplingRate);\n"]}
1
+ {"version":3,"file":"batchTracker.js","sourceRoot":"","sources":["../src/batchTracker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAAmE;AAEnE,qEAA8D;AAE9D,MAAa,YAAY;IAMrB,YACqB,iBAA+B,EAChD,MAAwB,EACxB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oB,CAAC;oBAC7B,SAAS,EAAE,QAAQ;oBACnB,MAAM;oBACN,YAAY,EAAE,sBAAsB;oBACpC,sBAAsB,EAAE,OAAO,CAAC,cAAc;oBAC9C,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,6BAA6B;iBACpE,CAAC,CAAC;aACN;YAED,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;YAC1C,IAAI,CAAC,6BAA6B,GAAG,SAAS,CAAC;QACnD,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AApDD,oCAoDC;AAED;;;;;;;GAOG;AACI,MAAM,gBAAgB,GAAG,CAC5B,iBAA+B,EAC/B,MAAwB,EACxB,uBAA+B,IAAI,EACnC,yBAAiC,IAAI,EACvC,EAAE,CAAC,IAAI,YAAY,CAAC,iBAAiB,EAAE,MAAM,EAAE,oBAAoB,EAAE,sBAAsB,CAAC,CAAC;AALlF,QAAA,gBAAgB,oBAKkE","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\n\nexport class BatchTracker {\n private readonly logger: ITelemetryLogger;\n private startBatchSequenceNumber: number | undefined;\n private trackedBatchCount: number = 0;\n private batchProcessingStartTimeStamp: number | undefined;\n\n constructor(\n private readonly batchEventEmitter: EventEmitter,\n logger: ITelemetryLogger,\n batchLengthThreshold: number,\n batchCountSamplingRate: number,\n dateTimeProvider: () => number = () => performance.now(),\n ) {\n this.logger = ChildLogger.create(logger, \"Batching\");\n\n this.batchEventEmitter.on(\"batchBegin\", (message: ISequencedDocumentMessage) => {\n this.startBatchSequenceNumber = message.sequenceNumber;\n this.batchProcessingStartTimeStamp = dateTimeProvider();\n this.trackedBatchCount++;\n });\n\n this.batchEventEmitter.on(\"batchEnd\", (error: any | undefined, message: ISequencedDocumentMessage) => {\n assert(\n this.startBatchSequenceNumber !== undefined && this.batchProcessingStartTimeStamp !== undefined,\n 0x2ba /* \"batchBegin must fire before batchEnd\" */);\n\n const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;\n if (length >= batchLengthThreshold) {\n this.logger.sendPerformanceEvent({\n eventName: \"LengthTooBig\",\n length,\n threshold: batchLengthThreshold,\n batchEndSequenceNumber: message.sequenceNumber,\n duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,\n batchError: error !== undefined,\n });\n }\n\n if (this.trackedBatchCount % batchCountSamplingRate === 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"Length\",\n length,\n samplingRate: batchCountSamplingRate,\n batchEndSequenceNumber: message.sequenceNumber,\n duration: dateTimeProvider() - this.batchProcessingStartTimeStamp,\n });\n }\n\n this.startBatchSequenceNumber = undefined;\n this.batchProcessingStartTimeStamp = undefined;\n });\n }\n}\n\n/**\n * Track batch sizes in terms of op counts and processing times\n *\n * @param batchEventEmitter - event emitter which tracks the lifecycle of batch operations\n * @param logger - See {@link @fluidframework/common-definitions#ITelemetryLogger}\n * @param batchLengthThreshold - threshold for the length of a batch when to send an error event\n * @param batchCountSamplingRate - rate for batches for which to send an event with its characteristics\n */\nexport const BindBatchTracker = (\n batchEventEmitter: EventEmitter,\n logger: ITelemetryLogger,\n batchLengthThreshold: number = 1000,\n batchCountSamplingRate: number = 1000,\n) => new BatchTracker(batchEventEmitter, logger, batchLengthThreshold, batchCountSamplingRate);\n"]}
@@ -40,30 +40,35 @@ export interface IPendingBlobs {
40
40
  blob: string;
41
41
  };
42
42
  }
43
- export declare class BlobManager {
43
+ export interface IBlobManagerEvents {
44
+ (event: "noPendingBlobs", listener: () => void): any;
45
+ }
46
+ export declare class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
44
47
  private readonly routeContext;
45
48
  private readonly getStorage;
46
49
  /**
47
- * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
48
- * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server
49
- * will then not delete the blob as long as it is listed as referenced in future summaries.
50
- * The summarizing client will know to include the storage ID in the summary when it sees the op.
50
+ * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
51
+ * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
52
+ * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
53
+ * include the storage ID in the summary when it sees the op.
51
54
  *
52
- * The op may also include a local ID to inform all clients of the relation to the storage
53
- * ID, without knowledge of which they cannot request the blob from storage. This is also
54
- * included in the redirect table in the summary.
55
+ * The op will also include a local ID to inform all clients of the relation to the storage ID, without
56
+ * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
57
+ * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
55
58
  */
56
59
  private readonly sendBlobAttachOp;
57
- private readonly gcNodeUpdated;
60
+ private readonly blobRequested;
61
+ private readonly addedBlobReference;
58
62
  private readonly runtime;
59
63
  static readonly basePath = "_blobs";
60
64
  private static readonly redirectTableBlobName;
61
65
  private readonly mc;
62
66
  /**
63
- * Map of local (offline/detached) IDs to storage IDs. Contains identity entries
64
- * (id id) for storage IDs, so all requested IDs should be a key in this map.
65
- * Blobs created while the container is detached are stored in IDetachedBlobStorage
66
- * which gives local IDs; the storage IDs are filled in at attach time.
67
+ * Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should
68
+ * be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which
69
+ * gives local IDs; the storage IDs are filled in at attach time.
70
+ * Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client
71
+ * that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.
67
72
  */
68
73
  private readonly redirectTable;
69
74
  /**
@@ -73,32 +78,34 @@ export declare class BlobManager {
73
78
  */
74
79
  private readonly pendingBlobs;
75
80
  /**
76
- * Track ops in flight for online flow. Used to avoid searching pendingBlobs since BlobAttach ops
77
- * don't include local ID in online flow.
81
+ * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
82
+ * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
83
+ * because we know that the server will not delete the blob corresponding to that storage ID.
78
84
  */
79
85
  private readonly opsInFlight;
80
86
  private readonly retryThrottler;
81
87
  /** If true, throw an error when a tombstone attachment blob is retrieved. */
82
88
  private readonly throwOnTombstoneUsage;
83
89
  /**
84
- * This stores ides of tombstoned blobs.
90
+ * This stores IDs of tombstoned blobs.
85
91
  * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
86
92
  */
87
93
  private readonly tombstonedBlobs;
88
94
  constructor(routeContext: IFluidHandleContext, snapshot: IBlobManagerLoadInfo, getStorage: () => IDocumentStorageService,
89
95
  /**
90
- * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
91
- * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server
92
- * will then not delete the blob as long as it is listed as referenced in future summaries.
93
- * The summarizing client will know to include the storage ID in the summary when it sees the op.
96
+ * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
97
+ * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
98
+ * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
99
+ * include the storage ID in the summary when it sees the op.
94
100
  *
95
- * The op may also include a local ID to inform all clients of the relation to the storage
96
- * ID, without knowledge of which they cannot request the blob from storage. This is also
97
- * included in the redirect table in the summary.
101
+ * The op will also include a local ID to inform all clients of the relation to the storage ID, without
102
+ * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
103
+ * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
98
104
  */
99
- sendBlobAttachOp: (storageId?: string, localId?: string) => void, gcNodeUpdated: (blobPath: string) => void, runtime: IBlobManagerRuntime, stashedBlobs?: IPendingBlobs);
105
+ sendBlobAttachOp: (localId: string, storageId?: string) => void, blobRequested: (blobPath: string) => void, addedBlobReference: (fromNodePath: string, toNodePath: string) => void, runtime: IBlobManagerRuntime, stashedBlobs?: IPendingBlobs);
100
106
  private get pendingOfflineUploads();
101
107
  get hasPendingOfflineUploads(): boolean;
108
+ get hasPendingBlobs(): boolean;
102
109
  /**
103
110
  * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
104
111
  */
@@ -124,6 +131,12 @@ export declare class BlobManager {
124
131
  private createBlobDetached;
125
132
  createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;
126
133
  private uploadBlob;
134
+ /**
135
+ * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
136
+ * which is required for GC.
137
+ */
138
+ private setRedirection;
139
+ private deleteAndEmitsIfEmpty;
127
140
  private onUploadResolve;
128
141
  private onUploadReject;
129
142
  private transitionToOffline;
@@ -153,18 +166,16 @@ export declare class BlobManager {
153
166
  */
154
167
  getGCData(fullGC?: boolean): IGarbageCollectionData;
155
168
  /**
156
- * This is called to update blobs whose routes are used. The used blobs are removed from the tombstone list.
157
- * @param usedRoutes - The routes of the blob nodes that are used.
169
+ * This is called to update blobs whose routes are unused. The unused blobs are deleted.
170
+ * @param unusedRoutes - The routes of the blob nodes that are unused.
158
171
  */
159
- updateUsedRoutes(usedRoutes: string[]): void;
172
+ updateUnusedRoutes(unusedRoutes: string[]): void;
160
173
  /**
161
- * This is called to update blobs whose routes are unused. The unused blobs are either deleted or marked as
162
- * tombstones.
163
- * @param unusedRoutes - The routes of the blob nodes that are unused.
164
- * @param tombstone - if true, the objects corresponding to unused routes are marked tombstones. Otherwise, they
165
- * are deleted.
174
+ * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
175
+ * accessing deleted content without actually deleting content from summaries.
176
+ * @param tombstonedRoutes - The routes of blob nodes that are tombstones.
166
177
  */
167
- updateUnusedRoutes(unusedRoutes: string[], tombstone: boolean): void;
178
+ updateTombstonedRoutes(tombstonedRoutes: string[]): void;
168
179
  summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
169
180
  setRedirectTable(table: Map<string, string>): void;
170
181
  getPendingBlobs(): IPendingBlobs;
@@ -1 +1 @@
1
- {"version":3,"file":"blobManager.d.ts","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAuB,yBAAyB,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAOrH,OAAO,EAAoD,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAG3G,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EACpB,MAAM,qCAAqC,CAAC;AAK7C;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,YAAY,CAAC,eAAe,CAAC;aAYxC,IAAI,EAAE,MAAM;aACZ,YAAY,EAAE,mBAAmB;IAC1C,GAAG,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC;IAblC,OAAO,CAAC,QAAQ,CAAkB;IAElC,IAAW,YAAY,IAAI,YAAY,CAAiB;IAExD,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED,SAAgB,YAAY,EAAE,MAAM,CAAC;gBAGjB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,mBAAmB,EAC1C,GAAG,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC;IAK3B,WAAW;IAIX,IAAI,CAAC,MAAM,EAAE,YAAY;CAGnC;AAmBD;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;IACf,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CACtC;AAID,oBAAY,mBAA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IAchC;;OAEG;IACH,OAAO,CAAC,IAAI;IAgBZ;;;;;OAKG;IACI,SAAS,CAAC,MAAM,GAAE,OAAe,GAAG,sBAAsB;IASjE;;;OAGG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;IAcvD;;;;OAIG;IACI,sBAAsB,CAAC,gBAAgB,EAAE,MAAM,EAAE;IA0BjD,SAAS,CAAC,gBAAgB,CAAC,EAAE,iBAAiB,GAAG,qBAAqB;IAqBtE,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAa3C,eAAe,IAAI,aAAa;CAO1C"}
@@ -13,6 +13,7 @@ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
13
13
  const throttler_1 = require("./throttler");
14
14
  const summarizerClientElection_1 = require("./summarizerClientElection");
15
15
  const garbageCollectionConstants_1 = require("./garbageCollectionConstants");
16
+ const garbageCollectionTombstoneUtils_1 = require("./garbageCollectionTombstoneUtils");
16
17
  /**
17
18
  * This class represents blob (long string)
18
19
  * This object is used only when creating (writing) new blob and serialization purposes.
@@ -65,26 +66,28 @@ var PendingBlobStatus;
65
66
  PendingBlobStatus[PendingBlobStatus["OfflinePendingUpload"] = 2] = "OfflinePendingUpload";
66
67
  PendingBlobStatus[PendingBlobStatus["OfflinePendingOp"] = 3] = "OfflinePendingOp";
67
68
  })(PendingBlobStatus || (PendingBlobStatus = {}));
68
- class BlobManager {
69
+ class BlobManager extends common_utils_1.TypedEventEmitter {
69
70
  constructor(routeContext, snapshot, getStorage,
70
71
  /**
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.
72
+ * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
73
+ * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
74
+ * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
75
+ * include the storage ID in the summary when it sees the op.
75
76
  *
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.
77
+ * The op will also include a local ID to inform all clients of the relation to the storage ID, without
78
+ * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
79
+ * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
79
80
  */
80
81
  sendBlobAttachOp,
81
82
  // 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
83
  // of the format `/<BlobManager.basePath>/<blobId>`.
83
- gcNodeUpdated, runtime, stashedBlobs = {}) {
84
+ blobRequested, addedBlobReference, runtime, stashedBlobs = {}) {
85
+ super();
84
86
  this.routeContext = routeContext;
85
87
  this.getStorage = getStorage;
86
88
  this.sendBlobAttachOp = sendBlobAttachOp;
87
- this.gcNodeUpdated = gcNodeUpdated;
89
+ this.blobRequested = blobRequested;
90
+ this.addedBlobReference = addedBlobReference;
88
91
  this.runtime = runtime;
89
92
  /**
90
93
  * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.
@@ -93,8 +96,9 @@ class BlobManager {
93
96
  */
94
97
  this.pendingBlobs = new Map();
95
98
  /**
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.
99
+ * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
100
+ * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
101
+ * because we know that the server will not delete the blob corresponding to that storage ID.
98
102
  */
99
103
  this.opsInFlight = new Map();
100
104
  this.retryThrottler = new CancellableThrottler(new throttler_1.Throttler(60 * 1000, // 60 sec delay window
@@ -102,7 +106,7 @@ class BlobManager {
102
106
  // throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)
103
107
  (0, throttler_1.formExponentialFn)({ coefficient: 20, initialDelay: 0 })));
104
108
  /**
105
- * This stores ides of tombstoned blobs.
109
+ * This stores IDs of tombstoned blobs.
106
110
  * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
107
111
  */
108
112
  this.tombstonedBlobs = new Set();
@@ -131,6 +135,10 @@ class BlobManager {
131
135
  get hasPendingOfflineUploads() {
132
136
  return this.pendingOfflineUploads.length > 0;
133
137
  }
138
+ get hasPendingBlobs() {
139
+ return (this.runtime.attachState !== container_definitions_1.AttachState.Attached && this.redirectTable.size > 0)
140
+ || this.pendingBlobs.size > 0;
141
+ }
134
142
  /**
135
143
  * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
136
144
  */
@@ -180,10 +188,11 @@ class BlobManager {
180
188
  const request = { url: blobId };
181
189
  if (this.tombstonedBlobs.has(blobId)) {
182
190
  const error = (0, runtime_utils_1.responseToException)((0, runtime_utils_1.createResponseError)(404, "Blob removed by gc", request), request);
183
- this.mc.logger.sendErrorEvent({
191
+ const event = {
184
192
  eventName: "GC_Tombstone_Blob_Requested",
185
193
  url: request.url,
186
- }, error);
194
+ };
195
+ (0, garbageCollectionTombstoneUtils_1.sendGCTombstoneEvent)(this.mc, event, this.runtime.clientDetails.type === summarizerClientElection_1.summarizerClientType, [BlobManager.basePath], error);
187
196
  if (this.throwOnTombstoneUsage) {
188
197
  throw error;
189
198
  }
@@ -200,11 +209,12 @@ class BlobManager {
200
209
  storageId = blobId;
201
210
  }
202
211
  else {
203
- storageId = this.redirectTable.get(blobId);
204
- (0, common_utils_1.assert)(!!storageId, 0x11f /* "requesting unknown blobs" */);
212
+ const attachedStorageId = this.redirectTable.get(blobId);
213
+ (0, common_utils_1.assert)(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
214
+ storageId = attachedStorageId;
205
215
  }
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));
216
+ // Let runtime know that the corresponding GC node was requested.
217
+ this.blobRequested(this.getBlobGCNodePath(blobId));
208
218
  return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "AttachmentReadBlob", id: storageId }, async () => {
209
219
  return this.getStorage().readBlob(storageId);
210
220
  }, { end: true, cancel: "error" });
@@ -217,7 +227,7 @@ class BlobManager {
217
227
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
218
228
  // The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
219
229
  const response = await this.getStorage().createBlob(blob);
220
- this.redirectTable.set(response.id, undefined);
230
+ this.setRedirection(response.id, undefined);
221
231
  return this.getBlobHandle(response.id);
222
232
  }
223
233
  async createBlob(blob) {
@@ -230,8 +240,8 @@ class BlobManager {
230
240
  await new Promise((resolve) => this.runtime.once("attached", resolve));
231
241
  }
232
242
  (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.
243
+ // Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
244
+ // storage ID mapping is created.
235
245
  const localId = (0, uuid_1.v4)();
236
246
  const pendingEntry = {
237
247
  blob,
@@ -245,6 +255,26 @@ class BlobManager {
245
255
  async uploadBlob(localId, blob) {
246
256
  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
257
  }
258
+ /**
259
+ * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
260
+ * which is required for GC.
261
+ */
262
+ setRedirection(fromId, toId) {
263
+ this.redirectTable.set(fromId, toId);
264
+ // Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in
265
+ // detached mode. In this case, the entry will be updated when the blob is updated.
266
+ if (toId !== undefined) {
267
+ this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));
268
+ }
269
+ }
270
+ deleteAndEmitsIfEmpty(id) {
271
+ if (this.pendingBlobs.has(id)) {
272
+ this.pendingBlobs.delete(id);
273
+ if (!this.hasPendingBlobs) {
274
+ this.emit("noPendingBlobs");
275
+ }
276
+ }
277
+ }
248
278
  onUploadResolve(localId, response) {
249
279
  var _a;
250
280
  const entry = this.pendingBlobs.get(localId);
@@ -253,17 +283,24 @@ class BlobManager {
253
283
  entry.storageId = response.id;
254
284
  if (this.runtime.connected) {
255
285
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
286
+ // Send a blob attach op. This serves two purposes:
287
+ // 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
288
+ // until its storage ID is added to the next summary.
289
+ // 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
290
+ // blob from the server via the storage ID.
291
+ this.sendBlobAttachOp(localId, response.id);
256
292
  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);
293
+ // The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
294
+ // an existing blob, we don't have to wait for the op to be ack'd since this step has already
295
+ // happened before and so, the server won't delete it.
296
+ this.setRedirection(localId, response.id);
297
+ entry.handleP.resolve(this.getBlobHandle(localId));
298
+ this.deleteAndEmitsIfEmpty(localId);
261
299
  }
262
300
  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
- }
301
+ // If there is already an op for this storage ID, append the local ID to the list. Once any op for
302
+ // this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
303
+ // blob alive in storage.
267
304
  this.opsInFlight.set(response.id, ((_a = this.opsInFlight.get(response.id)) !== null && _a !== void 0 ? _a : []).concat(localId));
268
305
  entry.status = PendingBlobStatus.OnlinePendingOp;
269
306
  }
@@ -304,15 +341,19 @@ class BlobManager {
304
341
  const entry = this.pendingBlobs.get(localId);
305
342
  (0, common_utils_1.assert)(!!entry, 0x389 /* No pending blob entry */);
306
343
  (0, common_utils_1.assert)([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), 0x38a /* Blob must be in online flow to transition to offline flow */);
344
+ /**
345
+ * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
346
+ * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
347
+ * an invalid handle could be added to the document.
348
+ * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
349
+ * is called on reconnection.
350
+ */
351
+ if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
352
+ this.sendBlobAttachOp(localId, entry.storageId);
353
+ }
307
354
  entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
308
355
  ? PendingBlobStatus.OfflinePendingUpload
309
356
  : 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);
316
357
  entry.handleP.resolve(this.getBlobHandle(localId));
317
358
  }
318
359
  /**
@@ -322,45 +363,52 @@ class BlobManager {
322
363
  */
323
364
  reSubmit(metadata) {
324
365
  (0, common_utils_1.assert)(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
325
- const { blobId, localId } = metadata;
366
+ const { localId, blobId } = metadata;
367
+ (0, common_utils_1.assert)(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
326
368
  if (!blobId) {
327
- (0, common_utils_1.assert)(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
328
369
  // We submitted this op while offline. The blob should have been uploaded by now.
329
370
  const pendingEntry = this.pendingBlobs.get(localId);
330
371
  (0, common_utils_1.assert)((pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.status) === PendingBlobStatus.OfflinePendingOp &&
331
372
  !!(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);
373
+ return this.sendBlobAttachOp(localId, pendingEntry.storageId);
333
374
  }
334
- return this.sendBlobAttachOp(blobId, localId);
375
+ return this.sendBlobAttachOp(localId, blobId);
335
376
  }
336
377
  processBlobAttachOp(message, local) {
337
378
  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);
379
+ const localId = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.localId;
380
+ const blobId = (_b = message.metadata) === null || _b === void 0 ? void 0 : _b.blobId;
381
+ (0, common_utils_1.assert)(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
382
+ // Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
383
+ // requested from the server.
384
+ // Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
385
+ // was sent when online.
386
+ if (localId !== undefined) {
387
+ this.setRedirection(localId, blobId);
341
388
  }
342
389
  // set identity (id -> id) entry
343
- this.redirectTable.set(message.metadata.blobId, message.metadata.blobId);
390
+ this.setRedirection(blobId, blobId);
344
391
  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);
392
+ (0, common_utils_1.assert)(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
393
+ const waitingBlobs = this.opsInFlight.get(blobId);
394
+ if (waitingBlobs !== undefined) {
395
+ // For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
396
+ // This is safe because the server will keep the blob alive and the op containing the local ID to
397
+ // storage ID is already in flight and any op containing this local ID will be sequenced after that.
398
+ waitingBlobs.forEach((pendingLocalId) => {
399
+ const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
351
400
  (0, common_utils_1.assert)(pendingBlobEntry !== undefined, 0x38f);
352
401
  // It's possible we transitioned to offline flow while waiting for this op.
353
402
  if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
354
- pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));
355
- this.pendingBlobs.delete(localId);
403
+ this.setRedirection(pendingLocalId, blobId);
404
+ pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
405
+ this.deleteAndEmitsIfEmpty(pendingLocalId);
356
406
  }
357
407
  });
408
+ this.opsInFlight.delete(blobId);
358
409
  }
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
- }
410
+ // For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
411
+ this.deleteAndEmitsIfEmpty(localId);
364
412
  }
365
413
  }
366
414
  /**
@@ -409,65 +457,50 @@ class BlobManager {
409
457
  */
410
458
  getGCData(fullGC = false) {
411
459
  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
460
  for (const [localId, storageId] of this.redirectTable) {
425
461
  (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
462
  gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
429
463
  }
430
464
  return gcData;
431
465
  }
432
466
  /**
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.
467
+ * This is called to update blobs whose routes are unused. The unused blobs are deleted.
468
+ * @param unusedRoutes - The routes of the blob nodes that are unused.
435
469
  */
436
- updateUsedRoutes(usedRoutes) {
470
+ updateUnusedRoutes(unusedRoutes) {
437
471
  // The routes or blob node paths are in the same format as returned in getGCData -
438
472
  // `/<BlobManager.basePath>/<blobId>`.
439
- for (const route of usedRoutes) {
473
+ for (const route of unusedRoutes) {
440
474
  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. */);
475
+ (0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x2d5 /* "Invalid blob node id in unused routes." */);
442
476
  const blobId = pathParts[2];
443
- // Un-tombstone the blob if it was marked tombstone.
444
- this.tombstonedBlobs.delete(blobId);
477
+ this.redirectTable.delete(blobId);
445
478
  }
446
479
  }
447
480
  /**
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.
481
+ * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
482
+ * accessing deleted content without actually deleting content from summaries.
483
+ * @param tombstonedRoutes - The routes of blob nodes that are tombstones.
453
484
  */
454
- updateUnusedRoutes(unusedRoutes, tombstone) {
485
+ updateTombstonedRoutes(tombstonedRoutes) {
486
+ const tombstonedBlobsSet = new Set();
455
487
  // The routes or blob node paths are in the same format as returned in getGCData -
456
488
  // `/<BlobManager.basePath>/<blobId>`.
457
- for (const route of unusedRoutes) {
489
+ for (const route of tombstonedRoutes) {
458
490
  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);
491
+ (0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x50f /* Invalid blob node id in tombstoned routes. */);
492
+ tombstonedBlobsSet.add(pathParts[2]);
493
+ }
494
+ // Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
495
+ for (const blobId of this.tombstonedBlobs) {
496
+ if (!tombstonedBlobsSet.has(blobId)) {
497
+ this.tombstonedBlobs.delete(blobId);
469
498
  }
470
499
  }
500
+ // Mark blobs that are now tombstoned by adding them to the tombstone list.
501
+ for (const blobId of tombstonedBlobsSet) {
502
+ this.tombstonedBlobs.add(blobId);
503
+ }
471
504
  }
472
505
  summarize(telemetryContext) {
473
506
  // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
@@ -490,9 +523,9 @@ class BlobManager {
490
523
  (0, common_utils_1.assert)(this.redirectTable.size === table.size, 0x391 /* Redirect table size must match BlobManager's local ID count */);
491
524
  for (const [localId, storageId] of table) {
492
525
  (0, common_utils_1.assert)(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
493
- this.redirectTable.set(localId, storageId);
526
+ this.setRedirection(localId, storageId);
494
527
  // set identity (id -> id) entry
495
- this.redirectTable.set(storageId, storageId);
528
+ this.setRedirection(storageId, storageId);
496
529
  }
497
530
  }
498
531
  getPendingBlobs() {