@fluidframework/container-runtime 2.0.0-internal.1.0.0.83139 → 2.0.0-internal.1.1.1

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 (124) hide show
  1. package/.mocharc.js +12 -0
  2. package/dist/batchTracker.js +1 -1
  3. package/dist/batchTracker.js.map +1 -1
  4. package/dist/blobManager.d.ts +7 -1
  5. package/dist/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager.js +34 -17
  7. package/dist/blobManager.js.map +1 -1
  8. package/dist/containerRuntime.d.ts +3 -104
  9. package/dist/containerRuntime.d.ts.map +1 -1
  10. package/dist/containerRuntime.js +83 -395
  11. package/dist/containerRuntime.js.map +1 -1
  12. package/dist/dataStore.d.ts +1 -1
  13. package/dist/dataStore.d.ts.map +1 -1
  14. package/dist/dataStore.js +2 -3
  15. package/dist/dataStore.js.map +1 -1
  16. package/dist/dataStoreContext.d.ts +3 -5
  17. package/dist/dataStoreContext.d.ts.map +1 -1
  18. package/dist/dataStoreContext.js +13 -23
  19. package/dist/dataStoreContext.js.map +1 -1
  20. package/dist/dataStores.d.ts +1 -1
  21. package/dist/dataStores.d.ts.map +1 -1
  22. package/dist/dataStores.js +3 -8
  23. package/dist/dataStores.js.map +1 -1
  24. package/dist/garbageCollection.d.ts +37 -6
  25. package/dist/garbageCollection.d.ts.map +1 -1
  26. package/dist/garbageCollection.js +61 -65
  27. package/dist/garbageCollection.js.map +1 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/packageVersion.d.ts +1 -1
  33. package/dist/packageVersion.d.ts.map +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/pendingStateManager.d.ts.map +1 -1
  37. package/dist/pendingStateManager.js +15 -2
  38. package/dist/pendingStateManager.js.map +1 -1
  39. package/dist/runningSummarizer.js +1 -1
  40. package/dist/runningSummarizer.js.map +1 -1
  41. package/dist/scheduleManager.d.ts +28 -0
  42. package/dist/scheduleManager.d.ts.map +1 -0
  43. package/dist/scheduleManager.js +235 -0
  44. package/dist/scheduleManager.js.map +1 -0
  45. package/dist/summarizer.d.ts.map +1 -1
  46. package/dist/summarizer.js +20 -1
  47. package/dist/summarizer.js.map +1 -1
  48. package/dist/summaryCollection.js +1 -1
  49. package/dist/summaryCollection.js.map +1 -1
  50. package/dist/summaryGenerator.js +1 -1
  51. package/dist/summaryGenerator.js.map +1 -1
  52. package/dist/summaryManager.d.ts.map +1 -1
  53. package/dist/summaryManager.js +20 -5
  54. package/dist/summaryManager.js.map +1 -1
  55. package/lib/batchTracker.js +1 -1
  56. package/lib/batchTracker.js.map +1 -1
  57. package/lib/blobManager.d.ts +7 -1
  58. package/lib/blobManager.d.ts.map +1 -1
  59. package/lib/blobManager.js +35 -18
  60. package/lib/blobManager.js.map +1 -1
  61. package/lib/containerRuntime.d.ts +3 -104
  62. package/lib/containerRuntime.d.ts.map +1 -1
  63. package/lib/containerRuntime.js +84 -395
  64. package/lib/containerRuntime.js.map +1 -1
  65. package/lib/dataStore.d.ts +1 -1
  66. package/lib/dataStore.d.ts.map +1 -1
  67. package/lib/dataStore.js +2 -3
  68. package/lib/dataStore.js.map +1 -1
  69. package/lib/dataStoreContext.d.ts +3 -5
  70. package/lib/dataStoreContext.d.ts.map +1 -1
  71. package/lib/dataStoreContext.js +13 -23
  72. package/lib/dataStoreContext.js.map +1 -1
  73. package/lib/dataStores.d.ts +1 -1
  74. package/lib/dataStores.d.ts.map +1 -1
  75. package/lib/dataStores.js +3 -8
  76. package/lib/dataStores.js.map +1 -1
  77. package/lib/garbageCollection.d.ts +37 -6
  78. package/lib/garbageCollection.d.ts.map +1 -1
  79. package/lib/garbageCollection.js +47 -52
  80. package/lib/garbageCollection.js.map +1 -1
  81. package/lib/index.d.ts +2 -1
  82. package/lib/index.d.ts.map +1 -1
  83. package/lib/index.js +2 -1
  84. package/lib/index.js.map +1 -1
  85. package/lib/packageVersion.d.ts +1 -1
  86. package/lib/packageVersion.d.ts.map +1 -1
  87. package/lib/packageVersion.js +1 -1
  88. package/lib/packageVersion.js.map +1 -1
  89. package/lib/pendingStateManager.d.ts.map +1 -1
  90. package/lib/pendingStateManager.js +15 -2
  91. package/lib/pendingStateManager.js.map +1 -1
  92. package/lib/runningSummarizer.js +1 -1
  93. package/lib/runningSummarizer.js.map +1 -1
  94. package/lib/scheduleManager.d.ts +28 -0
  95. package/lib/scheduleManager.d.ts.map +1 -0
  96. package/lib/scheduleManager.js +231 -0
  97. package/lib/scheduleManager.js.map +1 -0
  98. package/lib/summarizer.d.ts.map +1 -1
  99. package/lib/summarizer.js +22 -3
  100. package/lib/summarizer.js.map +1 -1
  101. package/lib/summaryCollection.js +1 -1
  102. package/lib/summaryCollection.js.map +1 -1
  103. package/lib/summaryGenerator.js +1 -1
  104. package/lib/summaryGenerator.js.map +1 -1
  105. package/lib/summaryManager.d.ts.map +1 -1
  106. package/lib/summaryManager.js +20 -5
  107. package/lib/summaryManager.js.map +1 -1
  108. package/package.json +32 -19
  109. package/src/batchTracker.ts +1 -1
  110. package/src/blobManager.ts +43 -17
  111. package/src/containerRuntime.ts +113 -547
  112. package/src/dataStore.ts +1 -4
  113. package/src/dataStoreContext.ts +10 -25
  114. package/src/dataStores.ts +13 -19
  115. package/src/garbageCollection.ts +64 -69
  116. package/src/index.ts +1 -2
  117. package/src/packageVersion.ts +1 -1
  118. package/src/pendingStateManager.ts +18 -2
  119. package/src/runningSummarizer.ts +1 -1
  120. package/src/scheduleManager.ts +294 -0
  121. package/src/summarizer.ts +28 -3
  122. package/src/summaryCollection.ts +1 -1
  123. package/src/summaryGenerator.ts +1 -1
  124. package/src/summaryManager.ts +20 -5
package/.mocharc.js ADDED
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const getFluidTestMochaConfig = require('@fluidframework/mocha-test-setup/mocharc-common');
9
+
10
+ const packageDir = __dirname;
11
+ const config = getFluidTestMochaConfig(packageDir);
12
+ module.exports = config;
@@ -21,7 +21,7 @@ class BatchTracker {
21
21
  (0, common_utils_1.assert)(this.startBatchSequenceNumber !== undefined && this.batchProcessingStartTimeStamp !== undefined, 0x2ba /* "batchBegin must fire before batchEnd" */);
22
22
  const length = message.sequenceNumber - this.startBatchSequenceNumber + 1;
23
23
  if (length >= batchLengthThreshold) {
24
- this.logger.sendErrorEvent({
24
+ this.logger.sendPerformanceEvent({
25
25
  eventName: "LengthTooBig",
26
26
  length,
27
27
  threshold: batchLengthThreshold,
@@ -1 +1 @@
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,oBAA4B,EAC5B,sBAA8B,EAC9B,mBAAiC,GAAG,EAAE,CAAC,0BAAW,CAAC,GAAG,EAAE;QAJvC,sBAAiB,GAAjB,iBAAiB,CAAc;QAJ5C,sBAAiB,GAAW,CAAC,CAAC;QAUlC,IAAI,CAAC,MAAM,GAAG,6BAAW,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAErD,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,OAAkC,EAAE,EAAE;YAC3E,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC;YACvD,IAAI,CAAC,6BAA6B,GAAG,gBAAgB,EAAE,CAAC;YACxD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,KAAsB,EAAE,OAAkC,EAAE,EAA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ent":["/*!\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.sendErrorEvent({\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 - logger\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 * @returns\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,oBAA4B,EAC5B,sBAA8B,EAC9B,mBAAiC,GAAG,EAAE,CAAC,0BAAW,CAAC,GAAG,EAAE;QAJvC,sBAAiB,GAAjB,iBAAiB,CAAc;QAJ5C,sBAAiB,GAAW,CAAC,CAAC;QAUlC,IAAI,CAAC,MAAM,GAAG,6BAAW,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAErD,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,OAAkC,EAAE,EAAE;YAC3E,IAAI,CAAC,wBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC;YACvD,IAAI,CAAC,6BAA6B,GAAG,gBAAgB,EAAE,CAAC;YACxD,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC7B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,KAAsB,EAAE,OAAkC,EAAE,EAAE;YACjG,IAAA,qBAAM,EACF,IAAI,CAAC,wBAAwB,KAAK,SAAS,IAAI,IAAI,CAAC,6BAA6B,KAAK,SAAS,EAC/F,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAExD,MAAM,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,wBAAwB,GAAG,CAAC,CAAC;YAC1E,IAAI,MAAM,IAAI,oBAAoB,EAAE;gBAChC,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;oBAC7B,SAAS,EAAE,cAAc;oBACzB,MAAM;oBACN,SAAS,EAAE,oBAAoB;oBAC/B,sBAAsB,EAAE,OAAO,CAAC,cAAc;oBAC9C,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC,6BAA6B;oBACjE,UAAU,EAAE,KAAK,KAAK,SAAS;iBAClC,CAAC,CAAC;aACN;YAED,IAAI,IAAI,CAAC,iBAAiB,GAAG,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;;;;;;;;GAQG;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 - logger\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 * @returns\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"]}
@@ -35,6 +35,11 @@ export interface IBlobManagerLoadInfo {
35
35
  redirectTable?: [string, string][];
36
36
  }
37
37
  export declare type IBlobManagerRuntime = Pick<IContainerRuntime, "attachState" | "connected" | "logger"> & TypedEventEmitter<IContainerRuntimeEvents>;
38
+ export interface IPendingBlobs {
39
+ [id: string]: {
40
+ blob: string;
41
+ };
42
+ }
38
43
  export declare class BlobManager {
39
44
  private readonly routeContext;
40
45
  private readonly getStorage;
@@ -84,7 +89,7 @@ export declare class BlobManager {
84
89
  * ID, without knowledge of which they cannot request the blob from storage. This is also
85
90
  * included in the redirect table in the summary.
86
91
  */
87
- sendBlobAttachOp: (storageId?: string, localId?: string) => void, gcNodeUpdated: (blobPath: string) => void, runtime: IBlobManagerRuntime);
92
+ sendBlobAttachOp: (storageId?: string, localId?: string) => void, gcNodeUpdated: (blobPath: string) => void, runtime: IBlobManagerRuntime, stashedBlobs?: IPendingBlobs);
88
93
  private get pendingOfflineUploads();
89
94
  get hasPendingOfflineUploads(): boolean;
90
95
  /**
@@ -147,5 +152,6 @@ export declare class BlobManager {
147
152
  deleteUnusedRoutes(unusedRoutes: string[]): void;
148
153
  summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
149
154
  setRedirectTable(table: Map<string, string>): void;
155
+ getPendingBlobs(): IPendingBlobs;
150
156
  }
151
157
  //# sourceMappingURL=blobManager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"blobManager.d.ts","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":"AAAA;;;GAG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S,EAAE,aAAa,GAAG,SAAS,EACpC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAC1D,OAAO,CAAC,oBAAoB,CAAC;IAchC;;OAEG;IACH,OAAO,CAAC,IAAI;IAgBZ;;;;;OAKG;IACI,SAAS,CAAC,MAAM,GAAE,OAAe,GAAG,sBAAsB;IAyBjE;;;OAGG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;IAoBhD,SAAS,CAAC,gBAAgB,CAAC,EAAE,iBAAiB,GAAG,qBAAqB;IAqBtE,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAa3C,eAAe,IAAI,aAAa;CAO1C"}
@@ -78,7 +78,7 @@ class BlobManager {
78
78
  sendBlobAttachOp,
79
79
  // To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's
80
80
  // of the format `/<BlobManager.basePath>/<blobId>`.
81
- gcNodeUpdated, runtime) {
81
+ gcNodeUpdated, runtime, stashedBlobs = {}) {
82
82
  this.routeContext = routeContext;
83
83
  this.getStorage = getStorage;
84
84
  this.sendBlobAttachOp = sendBlobAttachOp;
@@ -102,6 +102,16 @@ class BlobManager {
102
102
  this.logger = telemetry_utils_1.ChildLogger.create(this.runtime.logger, "BlobManager");
103
103
  this.runtime.on("disconnected", () => this.onDisconnected());
104
104
  this.redirectTable = this.load(snapshot);
105
+ // Begin uploading stashed blobs from previous container instance
106
+ Object.entries(stashedBlobs).forEach(([localId, entry]) => {
107
+ const blob = (0, common_utils_1.stringToBuffer)(entry.blob, "base64");
108
+ this.pendingBlobs.set(localId, {
109
+ blob,
110
+ status: PendingBlobStatus.OfflinePendingUpload,
111
+ handleP: new common_utils_1.Deferred(),
112
+ uploadP: this.uploadBlob(localId, blob),
113
+ });
114
+ });
105
115
  }
106
116
  get pendingOfflineUploads() {
107
117
  return Array.from(this.pendingBlobs.values())
@@ -152,7 +162,7 @@ class BlobManager {
152
162
  const undefinedValueInTable = ids.delete(undefined);
153
163
  // For a detached container, entries are inserted into the redirect table with an undefined storage ID.
154
164
  // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.
155
- (0, common_utils_1.assert)(!undefinedValueInTable || this.runtime.attachState === container_definitions_1.AttachState.Detached && ids.size === 0, "'redirectTable' must contain only undefined while detached / defined values while attached");
165
+ (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 */);
156
166
  return ids;
157
167
  }
158
168
  async getBlob(blobId) {
@@ -162,7 +172,7 @@ class BlobManager {
162
172
  }
163
173
  let storageId;
164
174
  if (this.runtime.attachState === container_definitions_1.AttachState.Detached) {
165
- (0, common_utils_1.assert)(this.redirectTable.has(blobId), "requesting unknown blobs");
175
+ (0, common_utils_1.assert)(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);
166
176
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
167
177
  // The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.
168
178
  storageId = blobId;
@@ -178,7 +188,7 @@ class BlobManager {
178
188
  }, { end: true, cancel: "error" });
179
189
  }
180
190
  getBlobHandle(id) {
181
- (0, common_utils_1.assert)(this.redirectTable.has(id) || this.pendingBlobs.has(id), "requesting handle for unknown blob");
191
+ (0, common_utils_1.assert)(this.redirectTable.has(id) || this.pendingBlobs.has(id), 0x384 /* requesting handle for unknown blob */);
182
192
  return new BlobHandle(`${BlobManager.basePath}/${id}`, this.routeContext, async () => this.getBlob(id));
183
193
  }
184
194
  async createBlobDetached(blob) {
@@ -197,7 +207,7 @@ class BlobManager {
197
207
  this.logger.sendTelemetryEvent({ eventName: "CreateBlobWhileAttaching" });
198
208
  await new Promise((resolve) => this.runtime.once("attached", resolve));
199
209
  }
200
- (0, common_utils_1.assert)(this.runtime.attachState === container_definitions_1.AttachState.Attached, "For clarity and paranoid defense against adding future attachment states");
210
+ (0, common_utils_1.assert)(this.runtime.attachState === container_definitions_1.AttachState.Attached, 0x385 /* For clarity and paranoid defense against adding future attachment states */);
201
211
  // Create a local ID for each blob. This is used to support blobs if/when the client goes
202
212
  // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.
203
213
  const localId = (0, uuid_1.v4)();
@@ -217,7 +227,7 @@ class BlobManager {
217
227
  var _a;
218
228
  const entry = this.pendingBlobs.get(localId);
219
229
  (0, common_utils_1.assert)((entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OnlinePendingUpload ||
220
- (entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OfflinePendingUpload, "Must have pending blob entry for uploaded blob");
230
+ (entry === null || entry === void 0 ? void 0 : entry.status) === PendingBlobStatus.OfflinePendingUpload, 0x386 /* Must have pending blob entry for uploaded blob */);
221
231
  entry.storageId = response.id;
222
232
  if (this.runtime.connected) {
223
233
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
@@ -253,7 +263,7 @@ class BlobManager {
253
263
  }
254
264
  async onUploadReject(localId, error) {
255
265
  const entry = this.pendingBlobs.get(localId);
256
- (0, common_utils_1.assert)(!!entry, "Must have pending blob entry for blob which failed to upload");
266
+ (0, common_utils_1.assert)(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);
257
267
  if (!this.runtime.connected) {
258
268
  if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
259
269
  this.transitionToOffline(localId);
@@ -268,10 +278,10 @@ class BlobManager {
268
278
  }
269
279
  }
270
280
  transitionToOffline(localId) {
271
- (0, common_utils_1.assert)(!this.runtime.connected, "Must only transition to offline flow while runtime is disconnected");
281
+ (0, common_utils_1.assert)(!this.runtime.connected, 0x388 /* Must only transition to offline flow while runtime is disconnected */);
272
282
  const entry = this.pendingBlobs.get(localId);
273
- (0, common_utils_1.assert)(!!entry, "No pending blob entry");
274
- (0, common_utils_1.assert)([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), "Blob must be in online flow to transition to offline flow");
283
+ (0, common_utils_1.assert)(!!entry, 0x389 /* No pending blob entry */);
284
+ (0, common_utils_1.assert)([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), 0x38a /* Blob must be in online flow to transition to offline flow */);
275
285
  entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
276
286
  ? PendingBlobStatus.OfflinePendingUpload
277
287
  : PendingBlobStatus.OfflinePendingOp;
@@ -289,14 +299,14 @@ class BlobManager {
289
299
  * @param metadata - op metadata containing storage and/or local IDs
290
300
  */
291
301
  reSubmit(metadata) {
292
- (0, common_utils_1.assert)(!!metadata, "Resubmitted ops must have metadata");
302
+ (0, common_utils_1.assert)(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
293
303
  const { blobId, localId } = metadata;
294
304
  if (!blobId) {
295
- (0, common_utils_1.assert)(!!localId, "Submitted BlobAttach ops must have a blobId or localId");
305
+ (0, common_utils_1.assert)(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
296
306
  // We submitted this op while offline. The blob should have been uploaded by now.
297
307
  const pendingEntry = this.pendingBlobs.get(localId);
298
308
  (0, common_utils_1.assert)((pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.status) === PendingBlobStatus.OfflinePendingOp &&
299
- !!(pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.storageId), "blob must be uploaded before resubmitting BlobAttach op");
309
+ !!(pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.storageId), 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
300
310
  return this.sendBlobAttachOp(pendingEntry.storageId, localId);
301
311
  }
302
312
  return this.sendBlobAttachOp(blobId, localId);
@@ -313,10 +323,10 @@ class BlobManager {
313
323
  if (message.metadata.localId === undefined) {
314
324
  // Since there is no local ID, we know this op was submitted while online.
315
325
  const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);
316
- (0, common_utils_1.assert)(!!waitingBlobs, "local online BlobAttach op with no pending blob");
326
+ (0, common_utils_1.assert)(!!waitingBlobs, 0x38e /* local online BlobAttach op with no pending blob */);
317
327
  waitingBlobs.forEach((localId) => {
318
328
  const pendingBlobEntry = this.pendingBlobs.get(localId);
319
- (0, common_utils_1.assert)(pendingBlobEntry !== undefined, "local online BlobAttach op with no pending blob entry");
329
+ (0, common_utils_1.assert)(pendingBlobEntry !== undefined, 0x38f);
320
330
  // It's possible we transitioned to offline flow while waiting for this op.
321
331
  if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
322
332
  pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));
@@ -390,7 +400,7 @@ class BlobManager {
390
400
  // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
391
401
  // a blob may be referenced via its storageId handle.
392
402
  for (const [localId, storageId] of this.redirectTable) {
393
- (0, common_utils_1.assert)(!!storageId, "Must be attached to get GC data");
403
+ (0, common_utils_1.assert)(!!storageId, 0x390 /* Must be attached to get GC data */);
394
404
  // Add node for the localId and add a route to the storageId node. The storageId node will have been
395
405
  // added above when adding nodes for this.blobIds.
396
406
  gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
@@ -435,7 +445,7 @@ class BlobManager {
435
445
  }
436
446
  setRedirectTable(table) {
437
447
  (0, common_utils_1.assert)(this.runtime.attachState === container_definitions_1.AttachState.Detached, 0x252 /* "redirect table can only be set in detached container" */);
438
- (0, common_utils_1.assert)(this.redirectTable.size === table.size, "Redirect table size must match BlobManager's local ID count");
448
+ (0, common_utils_1.assert)(this.redirectTable.size === table.size, 0x391 /* Redirect table size must match BlobManager's local ID count */);
439
449
  for (const [localId, storageId] of table) {
440
450
  (0, common_utils_1.assert)(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
441
451
  this.redirectTable.set(localId, storageId);
@@ -443,6 +453,13 @@ class BlobManager {
443
453
  this.redirectTable.set(storageId, storageId);
444
454
  }
445
455
  }
456
+ getPendingBlobs() {
457
+ const blobs = {};
458
+ for (const [key, entry] of this.pendingBlobs) {
459
+ blobs[key] = { blob: (0, common_utils_1.bufferToString)(entry.blob, "base64") };
460
+ }
461
+ return blobs;
462
+ }
446
463
  }
447
464
  exports.BlobManager = BlobManager;
448
465
  BlobManager.basePath = "_blobs";
@@ -1 +1 @@
1
- {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAIlC,iEAA8F;AAE9F,+DAAmF;AAEnF,iFAAoE;AACpE,qEAAgF;AAMhF,2CAAuE;AAEvE;;;;;;GAMG;AACH,MAAa,UAAU;IAWnB,YACoB,IAAY,EACZ,YAAiC,EAC1C,GAAuB;QAFd,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAqB;QAC1C,QAAG,GAAH,GAAG,CAAoB;QAb1B,aAAQ,GAAY,KAAK,CAAC;QAe9B,IAAI,CAAC,YAAY,GAAG,IAAA,yCAAyB,EAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC3E,CAAC;IAdD,IAAW,YAAY,KAAmB,OAAO,IAAI,CAAC,CAAC,CAAC;IAExD,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAYM,WAAW;QACd,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACzB,CAAC;IAEM,IAAI,CAAC,MAAoB;QAC5B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAClD,CAAC;CACJ;AA1BD,gCA0BC;AAED,MAAM,oBAAoB;IACtB,YAA6B,SAAqB;QAArB,cAAS,GAAT,SAAS,CAAY;QAC1C,YAAO,GAAG,IAAI,uBAAQ,EAAQ,CAAC;IADe,CAAC;IAGhD,KAAK,CAAC,QAAQ;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AK,EAAE;YACtC,IAAA,qBAAM,EAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACzF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC3C,gCAAgC;YAChC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;SAChD;IACL,CAAC;;AA3cL,kCA4cC;AA3c0B,oBAAQ,GAAG,QAAQ,CAAC;AACnB,iCAAqB,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { ICreateBlobResponse, ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { generateHandleContextPath, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, Deferred, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IContainerRuntime, IContainerRuntimeEvents } from \"@fluidframework/container-runtime-definitions\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\n\n/**\n * This class represents blob (long string)\n * This object is used only when creating (writing) new blob and serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * DataObject.request() recognizes requests in the form of `/blobs/<id>`\n * and loads blob.\n */\nexport class BlobHandle implements IFluidHandle<ArrayBufferLike> {\n private attached: boolean = false;\n\n public get IFluidHandle(): IFluidHandle { return this; }\n\n public get isAttached(): boolean {\n return this.attached;\n }\n\n public readonly absolutePath: string;\n\n constructor(\n public readonly path: string,\n public readonly routeContext: IFluidHandleContext,\n public get: () => Promise<any>,\n ) {\n this.absolutePath = generateHandleContextPath(path, this.routeContext);\n }\n\n public attachGraph() {\n this.attached = true;\n }\n\n public bind(handle: IFluidHandle) {\n throw new Error(\"Cannot bind to blob handle\");\n }\n}\n\nclass CancellableThrottler {\n constructor(private readonly throttler: IThrottler) { }\n private cancelP = new Deferred<void>();\n\n public async getDelay(): Promise<void> {\n return Promise.race([\n this.cancelP.promise,\n new Promise<void>((resolve) => setTimeout(resolve, this.throttler.getDelay())),\n ]);\n }\n\n public cancel() {\n this.cancelP.resolve();\n this.cancelP = new Deferred<void>();\n }\n}\n\n/**\n * Information from a snapshot needed to load BlobManager\n */\nexport interface IBlobManagerLoadInfo {\n ids?: string[];\n redirectTable?: [string, string][];\n}\n\n// Restrict the IContainerRuntime interface to the subset required by BlobManager. This helps to make\n// the contract explicit and reduces the amount of mocking required for tests.\nexport type IBlobManagerRuntime =\n Pick<IContainerRuntime, \"attachState\" | \"connected\" | \"logger\"> & TypedEventEmitter<IContainerRuntimeEvents>;\n\n// Note that while offline we \"submit\" an op before uploading the blob, but we always\n// expect blobs to be uploaded before we actually see the op round-trip\nenum PendingBlobStatus {\n OnlinePendingUpload,\n OnlinePendingOp,\n OfflinePendingUpload,\n OfflinePendingOp,\n}\n\ninterface PendingBlob {\n blob: ArrayBufferLike;\n status: PendingBlobStatus;\n storageId?: string;\n handleP: Deferred<IFluidHandle<ArrayBufferLike>>;\n uploadP: Promise<ICreateBlobResponse>;\n}\n\nexport class BlobManager {\n public static readonly basePath = \"_blobs\";\n private static readonly redirectTableBlobName = \".redirectTable\";\n private readonly logger: ITelemetryLogger;\n\n /**\n * Map of local (offline/detached) IDs to storage IDs. Contains identity entries\n * (id → id) for storage IDs, so all requested IDs should be a key in this map.\n * Blobs created while the container is detached are stored in IDetachedBlobStorage\n * which gives local IDs; the storage IDs are filled in at attach time.\n */\n private readonly redirectTable: Map<string, string | undefined>;\n\n /**\n * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.\n * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so\n * we must save it. This is true for both the online and offline flow.\n */\n private readonly pendingBlobs: Map<string, PendingBlob> = new Map();\n\n /**\n * Track ops in flight for online flow. Used to avoid searching pendingBlobs since BlobAttach ops\n * don't include local ID in online flow.\n */\n private readonly opsInFlight: Map<string, string[]> = new Map();\n\n private readonly retryThrottler = new CancellableThrottler(new Throttler(\n 60 * 1000, // 60 sec delay window\n 30 * 1000, // 30 sec max delay\n // throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)\n formExponentialFn({ coefficient: 20, initialDelay: 0 }),\n ));\n\n constructor(\n private readonly routeContext: IFluidHandleContext,\n snapshot: IBlobManagerLoadInfo,\n private readonly getStorage: () => IDocumentStorageService,\n /**\n * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which\n * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server\n * will then not delete the blob as long as it is listed as referenced in future summaries.\n * The summarizing client will know to include the storage ID in the summary when it sees the op.\n *\n * The op may also include a local ID to inform all clients of the relation to the storage\n * ID, without knowledge of which they cannot request the blob from storage. This is also\n * included in the redirect table in the summary.\n */\n private readonly sendBlobAttachOp: (storageId?: string, localId?: string) => void,\n // To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's\n // of the format `/<BlobManager.basePath>/<blobId>`.\n private readonly gcNodeUpdated: (blobPath: string) => void,\n private readonly runtime: IBlobManagerRuntime,\n ) {\n this.logger = ChildLogger.create(this.runtime.logger, \"BlobManager\");\n this.runtime.on(\"disconnected\", () => this.onDisconnected());\n this.redirectTable = this.load(snapshot);\n }\n\n private get pendingOfflineUploads() {\n return Array.from(this.pendingBlobs.values())\n .filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);\n }\n\n public get hasPendingOfflineUploads(): boolean {\n return this.pendingOfflineUploads.length > 0;\n }\n\n /**\n * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n */\n public async onConnected() {\n this.retryThrottler.cancel();\n const pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);\n await PerformanceEvent.timedExecAsync(this.logger, {\n eventName: \"BlobUploadOnConnected\",\n count: pendingUploads.length,\n }, async () => Promise.all(pendingUploads),\n { start: true, end: true },\n );\n }\n\n /**\n * Transition online blobs waiting for BlobAttach op round-trip since we will not see the op until we are connected\n * again\n */\n private onDisconnected() {\n for (const [localId, entry] of this.pendingBlobs) {\n if (entry.status === PendingBlobStatus.OnlinePendingOp) {\n // This will submit another BlobAttach op for this blob. This is necessary because the one we sent\n // already didn't have the local ID.\n this.transitionToOffline(localId);\n }\n }\n }\n\n /**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`\n * This path must match the path of the blob handle returned by the createBlob API because blobs are marked\n * referenced by storing these handles in a referenced DDS.\n */\n private getBlobGCNodePath(blobId: string) {\n return `/${BlobManager.basePath}/${blobId}`;\n }\n\n /**\n * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is\n * detached or there are no (non-pending) attachment blobs in the document\n */\n private get storageIds(): Set<string> {\n const ids = new Set<string | undefined>(this.redirectTable.values());\n\n // If we are detached, we will not have storage IDs, only undefined\n const undefinedValueInTable = ids.delete(undefined);\n\n // For a detached container, entries are inserted into the redirect table with an undefined storage ID.\n // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.\n assert(!undefinedValueInTable || this.runtime.attachState === AttachState.Detached && ids.size === 0,\n \"'redirectTable' must contain only undefined while detached / defined values while attached\");\n\n return ids as Set<string>;\n }\n\n public async getBlob(blobId: string): Promise<ArrayBufferLike> {\n const pending = this.pendingBlobs.get(blobId);\n if (pending) {\n return pending.blob;\n }\n let storageId;\n if (this.runtime.attachState === AttachState.Detached) {\n assert(this.redirectTable.has(blobId), \"requesting unknown blobs\");\n\n // Blobs created while the container is detached are stored in IDetachedBlobStorage.\n // The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.\n storageId = blobId;\n } else {\n storageId = this.redirectTable.get(blobId);\n assert(!!storageId, 0x11f /* \"requesting unknown blobs\" */);\n }\n\n // When a GC-able (not pending) blob is retrieved, let runtime know that the corresponding GC node got updated.\n this.gcNodeUpdated(this.getBlobGCNodePath(blobId));\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"AttachmentReadBlob\", id: storageId },\n async () => {\n return this.getStorage().readBlob(storageId);\n },\n { end: true, cancel: \"error\" },\n );\n }\n\n private getBlobHandle(id: string): IFluidHandle<ArrayBufferLike> {\n assert(this.redirectTable.has(id) || this.pendingBlobs.has(id),\n \"requesting handle for unknown blob\");\n return new BlobHandle(\n `${BlobManager.basePath}/${id}`,\n this.routeContext,\n async () => this.getBlob(id),\n );\n }\n\n private async createBlobDetached(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n // Blobs created while the container is detached are stored in IDetachedBlobStorage.\n // The 'IDocumentStorageService.createBlob()' call below will respond with a localId.\n const response = await this.getStorage().createBlob(blob);\n this.redirectTable.set(response.id, undefined);\n return this.getBlobHandle(response.id);\n }\n\n public async createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n if (this.runtime.attachState === AttachState.Detached) {\n return this.createBlobDetached(blob);\n }\n if (this.runtime.attachState === AttachState.Attaching) {\n // blob upload is not supported in \"Attaching\" state\n this.logger.sendTelemetryEvent({ eventName: \"CreateBlobWhileAttaching\" });\n await new Promise<void>((resolve) => this.runtime.once(\"attached\", resolve));\n }\n assert(this.runtime.attachState === AttachState.Attached,\n \"For clarity and paranoid defense against adding future attachment states\");\n\n // Create a local ID for each blob. This is used to support blobs if/when the client goes\n // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.\n const localId = uuid();\n const pendingEntry: PendingBlob = {\n blob,\n status: PendingBlobStatus.OnlinePendingUpload,\n handleP: new Deferred(),\n uploadP: this.uploadBlob(localId, blob),\n };\n this.pendingBlobs.set(localId, pendingEntry);\n\n return pendingEntry.handleP.promise;\n }\n\n private async uploadBlob(localId: string, blob: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"createBlob\" },\n async () => this.getStorage().createBlob(blob),\n { end: true, cancel: this.runtime.connected ? \"error\" : \"generic\" },\n ).then(\n (response) => this.onUploadResolve(localId, response),\n async (err) => this.onUploadReject(localId, err),\n );\n }\n\n private onUploadResolve(localId: string, response: ICreateBlobResponse) {\n const entry = this.pendingBlobs.get(localId);\n assert(entry?.status === PendingBlobStatus.OnlinePendingUpload ||\n entry?.status === PendingBlobStatus.OfflinePendingUpload,\n \"Must have pending blob entry for uploaded blob\");\n entry.storageId = response.id;\n if (this.runtime.connected) {\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n if (this.storageIds.has(response.id)) {\n // Storage may dedupe blobs and give us an ID we already know\n // no need to submit BlobAttach op in this case\n entry.handleP.resolve(this.getBlobHandle(response.id));\n this.pendingBlobs.delete(localId);\n } else {\n // Check for still-pending duplicates too; if an op is already in flight we can wait for that one\n if (!this.opsInFlight.has(response.id)) {\n this.sendBlobAttachOp(response.id);\n }\n this.opsInFlight.set(response.id, (this.opsInFlight.get(response.id) ?? []).concat(localId));\n entry.status = PendingBlobStatus.OnlinePendingOp;\n }\n } else if (entry.status === PendingBlobStatus.OfflinePendingUpload) {\n // We already submitted a BlobAttach op for this blob when it was transitioned to offline flow\n entry.status = PendingBlobStatus.OfflinePendingOp;\n }\n } else {\n // connected to storage but not ordering service?\n this.logger.sendTelemetryEvent({ eventName: \"BlobUploadSuccessWhileDisconnected\" });\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n this.transitionToOffline(localId);\n }\n entry.status = PendingBlobStatus.OfflinePendingOp;\n }\n return response;\n }\n\n private async onUploadReject(localId: string, error) {\n const entry = this.pendingBlobs.get(localId);\n assert(!!entry, \"Must have pending blob entry for blob which failed to upload\");\n if (!this.runtime.connected) {\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n this.transitionToOffline(localId);\n }\n // we are probably not connected to storage but start another upload request in case we are\n entry.uploadP = this.retryThrottler.getDelay().then(async () => this.uploadBlob(localId, entry.blob));\n return entry.uploadP;\n } else {\n entry.handleP.reject(error);\n throw error;\n }\n }\n\n private transitionToOffline(localId: string) {\n assert(!this.runtime.connected, \"Must only transition to offline flow while runtime is disconnected\");\n const entry = this.pendingBlobs.get(localId);\n assert(!!entry, \"No pending blob entry\");\n assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status),\n \"Blob must be in online flow to transition to offline flow\");\n\n entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload\n ? PendingBlobStatus.OfflinePendingUpload\n : PendingBlobStatus.OfflinePendingOp;\n\n // Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the\n // BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be\n // added to the document if the ops are not all successfully submitted upon reconnection.\n // storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n // is called\n this.sendBlobAttachOp(entry.storageId, localId);\n entry.handleP.resolve(this.getBlobHandle(localId));\n }\n\n /**\n * Resubmit a BlobAttach op. Used to add storage IDs to ops that were\n * submitted to runtime while disconnected.\n * @param metadata - op metadata containing storage and/or local IDs\n */\n public reSubmit(metadata: Record<string, unknown> | undefined) {\n assert(!!metadata, \"Resubmitted ops must have metadata\");\n const { blobId, localId }: { blobId?: string; localId?: string; } = metadata;\n if (!blobId) {\n assert(!!localId, \"Submitted BlobAttach ops must have a blobId or localId\");\n // We submitted this op while offline. The blob should have been uploaded by now.\n const pendingEntry = this.pendingBlobs.get(localId);\n assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n !!pendingEntry?.storageId, \"blob must be uploaded before resubmitting BlobAttach op\");\n return this.sendBlobAttachOp(pendingEntry.storageId, localId);\n }\n return this.sendBlobAttachOp(blobId, localId);\n }\n\n public processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n assert(message?.metadata?.blobId, 0x12a /* \"Missing blob id on metadata\" */);\n if (message.metadata.localId !== undefined) {\n this.redirectTable.set(message.metadata.localId, message.metadata.blobId);\n }\n // set identity (id -> id) entry\n this.redirectTable.set(message.metadata.blobId, message.metadata.blobId);\n\n if (local) {\n if (message.metadata.localId === undefined) {\n // Since there is no local ID, we know this op was submitted while online.\n const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);\n assert(!!waitingBlobs, \"local online BlobAttach op with no pending blob\");\n waitingBlobs.forEach((localId) => {\n const pendingBlobEntry = this.pendingBlobs.get(localId);\n assert(pendingBlobEntry !== undefined, \"local online BlobAttach op with no pending blob entry\");\n\n // It's possible we transitioned to offline flow while waiting for this op.\n if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {\n pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));\n this.pendingBlobs.delete(localId);\n }\n });\n } else {\n // Each local ID is unique; get the pending blob entry and delete it\n assert(this.pendingBlobs.get(message.metadata.localId)?.status === PendingBlobStatus.OfflinePendingOp,\n 0x1f8 /* \"local BlobAttach op with no pending blob\" */);\n this.pendingBlobs.delete(message.metadata.localId);\n }\n }\n }\n\n /**\n * Reads blobs needed to load BlobManager from storage.\n * @param blobsTree - Tree containing IDs of previously attached blobs. We\n * look for the IDs in the blob entries of the tree since the both the r11s\n * and SPO drivers replace the attachment types returned in snapshot() with blobs.\n */\n public static async load(\n blobsTree: ISnapshotTree | undefined,\n tryFetchBlob: (id: string) => Promise<[string, string][]>,\n ): Promise<IBlobManagerLoadInfo> {\n if (!blobsTree) {\n return {};\n }\n let redirectTable;\n const tableId = blobsTree.blobs[this.redirectTableBlobName];\n if (tableId) {\n redirectTable = await tryFetchBlob(tableId);\n }\n const ids = Object.entries(blobsTree.blobs)\n .filter(([k, _]) => k !== this.redirectTableBlobName).map(([_, v]) => v);\n return { ids, redirectTable };\n }\n\n /**\n * Load a set of previously attached blob IDs and redirect table from a previous snapshot.\n */\n private load(snapshot: IBlobManagerLoadInfo): Map<string, string | undefined> {\n this.logger.sendTelemetryEvent({\n eventName: \"AttachmentBlobsLoaded\",\n count: snapshot.ids?.length ?? 0,\n redirectTable: snapshot.redirectTable?.length,\n });\n const table = new Map<string, string | undefined>(snapshot.redirectTable);\n if (snapshot.ids) {\n const detached = this.runtime.attachState === AttachState.Detached;\n // If we are detached, we don't have storage IDs yet, so set to undefined\n // Otherwise, set identity (id -> id) entries\n snapshot.ids.forEach((entry) => table.set(entry, detached ? undefined : entry));\n }\n return table;\n }\n\n /**\n * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be\n * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.\n * @param fullGC - true to bypass optimizations and force full generation of GC data. BlobManager doesn't care\n * about this for now because the data is a simple list of blob ids.\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n const gcData: IGarbageCollectionData = { gcNodes: {} };\n /**\n * The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned\n * by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.\n */\n this.storageIds.forEach((blobId: string) => {\n gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];\n });\n\n // For some blobs, the handle returned on creation is based off of the localId. So, these\n // nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node\n // must also be marked referenced. So, we add a route from the localId node to the storageId node.\n // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or\n // a blob may be referenced via its storageId handle.\n for (const [localId, storageId] of this.redirectTable) {\n assert(!!storageId, \"Must be attached to get GC data\");\n // Add node for the localId and add a route to the storageId node. The storageId node will have been\n // added above when adding nodes for this.blobIds.\n gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];\n }\n\n return gcData;\n }\n\n /**\n * When running GC in test mode, this is called to delete blobs that are unused.\n * @param unusedRoutes - These are the blob node ids that are unused and should be deleted.\n */\n public deleteUnusedRoutes(unusedRoutes: string[]): void {\n // The routes or blob node paths are in the same format as returned in getGCData -\n // `/<BlobManager.basePath>/<blobId>`.\n for (const route of unusedRoutes) {\n const pathParts = route.split(\"/\");\n assert(\n pathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n 0x2d5 /* \"Invalid blob node id in unused routes.\" */,\n );\n const blobId = pathParts[2];\n\n // The unused blobId could be a localId. If so, remove it from the redirect table and continue. The\n // corresponding storageId may still be used either directly or via other localIds.\n if (this.redirectTable?.has(blobId)) {\n this.redirectTable.delete(blobId);\n continue;\n }\n }\n }\n\n public summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached\n const blobIds = this.storageIds.size > 0 ? Array.from(this.storageIds) : Array.from(this.redirectTable.keys());\n const builder = new SummaryTreeBuilder();\n blobIds.forEach((blobId) => {\n builder.addAttachment(blobId);\n });\n\n // Any non-identity entries in the table need to be saved in the summary\n if (this.redirectTable.size > blobIds.length) {\n builder.addBlob(\n BlobManager.redirectTableBlobName,\n // filter out identity entries\n JSON.stringify(Array.from(this.redirectTable.entries())\n .filter(([localId, storageId]) => localId !== storageId)),\n );\n }\n\n return builder.getSummaryTree();\n }\n\n public setRedirectTable(table: Map<string, string>) {\n assert(this.runtime.attachState === AttachState.Detached,\n 0x252 /* \"redirect table can only be set in detached container\" */);\n assert(this.redirectTable.size === table.size, \"Redirect table size must match BlobManager's local ID count\");\n for (const [localId, storageId] of table) {\n assert(this.redirectTable.has(localId), 0x254 /* \"unrecognized id in redirect table\" */);\n this.redirectTable.set(localId, storageId);\n // set identity (id -> id) entry\n this.redirectTable.set(storageId, storageId);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA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,qBAAM,EAAC,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,mCAAW,CAAC,QAAQ,EACpD,KAAK,CAAC,4DAA4D,CAAC,CAAC;QACxE,IAAA,qBAAM,EAAC,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EACzC,KAAK,CAAC,iEAAiE,CAAC,CAAC;QAC7E,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,KAAK,EAAE;YACtC,IAAA,qBAAM,EAAC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,yCAAyC,CAAC,CAAC;YACzF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC3C,gCAAgC;YAChC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;SAChD;IACL,CAAC;IAEM,eAAe;QAClB,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE;YAC1C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAA,6BAAc,EAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;SAC/D;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;;AAneL,kCAoeC;AAne0B,oBAAQ,GAAG,QAAQ,CAAC;AACnB,iCAAqB,GAAG,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport { ICreateBlobResponse, ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport { generateHandleContextPath, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport { IContainerRuntime, IContainerRuntimeEvents } from \"@fluidframework/container-runtime-definitions\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\n\n/**\n * This class represents blob (long string)\n * This object is used only when creating (writing) new blob and serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * DataObject.request() recognizes requests in the form of `/blobs/<id>`\n * and loads blob.\n */\nexport class BlobHandle implements IFluidHandle<ArrayBufferLike> {\n private attached: boolean = false;\n\n public get IFluidHandle(): IFluidHandle { return this; }\n\n public get isAttached(): boolean {\n return this.attached;\n }\n\n public readonly absolutePath: string;\n\n constructor(\n public readonly path: string,\n public readonly routeContext: IFluidHandleContext,\n public get: () => Promise<any>,\n ) {\n this.absolutePath = generateHandleContextPath(path, this.routeContext);\n }\n\n public attachGraph() {\n this.attached = true;\n }\n\n public bind(handle: IFluidHandle) {\n throw new Error(\"Cannot bind to blob handle\");\n }\n}\n\nclass CancellableThrottler {\n constructor(private readonly throttler: IThrottler) { }\n private cancelP = new Deferred<void>();\n\n public async getDelay(): Promise<void> {\n return Promise.race([\n this.cancelP.promise,\n new Promise<void>((resolve) => setTimeout(resolve, this.throttler.getDelay())),\n ]);\n }\n\n public cancel() {\n this.cancelP.resolve();\n this.cancelP = new Deferred<void>();\n }\n}\n\n/**\n * Information from a snapshot needed to load BlobManager\n */\nexport interface IBlobManagerLoadInfo {\n ids?: string[];\n redirectTable?: [string, string][];\n}\n\n// Restrict the IContainerRuntime interface to the subset required by BlobManager. This helps to make\n// the contract explicit and reduces the amount of mocking required for tests.\nexport type IBlobManagerRuntime =\n Pick<IContainerRuntime, \"attachState\" | \"connected\" | \"logger\"> & TypedEventEmitter<IContainerRuntimeEvents>;\n\n// Note that while offline we \"submit\" an op before uploading the blob, but we always\n// expect blobs to be uploaded before we actually see the op round-trip\nenum PendingBlobStatus {\n OnlinePendingUpload,\n OnlinePendingOp,\n OfflinePendingUpload,\n OfflinePendingOp,\n}\n\ninterface PendingBlob {\n blob: ArrayBufferLike;\n status: PendingBlobStatus;\n storageId?: string;\n handleP: Deferred<IFluidHandle<ArrayBufferLike>>;\n uploadP: Promise<ICreateBlobResponse>;\n}\n\nexport interface IPendingBlobs { [id: string]: { blob: string; }; }\n\nexport class BlobManager {\n public static readonly basePath = \"_blobs\";\n private static readonly redirectTableBlobName = \".redirectTable\";\n private readonly logger: ITelemetryLogger;\n\n /**\n * Map of local (offline/detached) IDs to storage IDs. Contains identity entries\n * (id → id) for storage IDs, so all requested IDs should be a key in this map.\n * Blobs created while the container is detached are stored in IDetachedBlobStorage\n * which gives local IDs; the storage IDs are filled in at attach time.\n */\n private readonly redirectTable: Map<string, string | undefined>;\n\n /**\n * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.\n * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so\n * we must save it. This is true for both the online and offline flow.\n */\n private readonly pendingBlobs: Map<string, PendingBlob> = new Map();\n\n /**\n * Track ops in flight for online flow. Used to avoid searching pendingBlobs since BlobAttach ops\n * don't include local ID in online flow.\n */\n private readonly opsInFlight: Map<string, string[]> = new Map();\n\n private readonly retryThrottler = new CancellableThrottler(new Throttler(\n 60 * 1000, // 60 sec delay window\n 30 * 1000, // 30 sec max delay\n // throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)\n formExponentialFn({ coefficient: 20, initialDelay: 0 }),\n ));\n\n constructor(\n private readonly routeContext: IFluidHandleContext,\n snapshot: IBlobManagerLoadInfo,\n private readonly getStorage: () => IDocumentStorageService,\n /**\n * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which\n * the blob is deleted. The BlobAttach op notifies the server that blob is in use. The server\n * will then not delete the blob as long as it is listed as referenced in future summaries.\n * The summarizing client will know to include the storage ID in the summary when it sees the op.\n *\n * The op may also include a local ID to inform all clients of the relation to the storage\n * ID, without knowledge of which they cannot request the blob from storage. This is also\n * included in the redirect table in the summary.\n */\n private readonly sendBlobAttachOp: (storageId?: string, localId?: string) => void,\n // To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's\n // of the format `/<BlobManager.basePath>/<blobId>`.\n private readonly gcNodeUpdated: (blobPath: string) => void,\n private readonly runtime: IBlobManagerRuntime,\n stashedBlobs: IPendingBlobs = {},\n ) {\n this.logger = ChildLogger.create(this.runtime.logger, \"BlobManager\");\n this.runtime.on(\"disconnected\", () => this.onDisconnected());\n this.redirectTable = this.load(snapshot);\n\n // Begin uploading stashed blobs from previous container instance\n Object.entries(stashedBlobs).forEach(([localId, entry]) => {\n const blob = stringToBuffer(entry.blob, \"base64\");\n this.pendingBlobs.set(localId, {\n blob,\n status: PendingBlobStatus.OfflinePendingUpload,\n handleP: new Deferred(),\n uploadP: this.uploadBlob(localId, blob),\n });\n });\n }\n\n private get pendingOfflineUploads() {\n return Array.from(this.pendingBlobs.values())\n .filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);\n }\n\n public get hasPendingOfflineUploads(): boolean {\n return this.pendingOfflineUploads.length > 0;\n }\n\n /**\n * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n */\n public async onConnected() {\n this.retryThrottler.cancel();\n const pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);\n await PerformanceEvent.timedExecAsync(this.logger, {\n eventName: \"BlobUploadOnConnected\",\n count: pendingUploads.length,\n }, async () => Promise.all(pendingUploads),\n { start: true, end: true },\n );\n }\n\n /**\n * Transition online blobs waiting for BlobAttach op round-trip since we will not see the op until we are connected\n * again\n */\n private onDisconnected() {\n for (const [localId, entry] of this.pendingBlobs) {\n if (entry.status === PendingBlobStatus.OnlinePendingOp) {\n // This will submit another BlobAttach op for this blob. This is necessary because the one we sent\n // already didn't have the local ID.\n this.transitionToOffline(localId);\n }\n }\n }\n\n /**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`\n * This path must match the path of the blob handle returned by the createBlob API because blobs are marked\n * referenced by storing these handles in a referenced DDS.\n */\n private getBlobGCNodePath(blobId: string) {\n return `/${BlobManager.basePath}/${blobId}`;\n }\n\n /**\n * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is\n * detached or there are no (non-pending) attachment blobs in the document\n */\n private get storageIds(): Set<string> {\n const ids = new Set<string | undefined>(this.redirectTable.values());\n\n // If we are detached, we will not have storage IDs, only undefined\n const undefinedValueInTable = ids.delete(undefined);\n\n // For a detached container, entries are inserted into the redirect table with an undefined storage ID.\n // For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.\n assert(!undefinedValueInTable || this.runtime.attachState === AttachState.Detached && ids.size === 0,\n 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);\n\n return ids as Set<string>;\n }\n\n public async getBlob(blobId: string): Promise<ArrayBufferLike> {\n const pending = this.pendingBlobs.get(blobId);\n if (pending) {\n return pending.blob;\n }\n let storageId;\n if (this.runtime.attachState === AttachState.Detached) {\n assert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);\n\n // Blobs created while the container is detached are stored in IDetachedBlobStorage.\n // The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.\n storageId = blobId;\n } else {\n storageId = this.redirectTable.get(blobId);\n assert(!!storageId, 0x11f /* \"requesting unknown blobs\" */);\n }\n\n // When a GC-able (not pending) blob is retrieved, let runtime know that the corresponding GC node got updated.\n this.gcNodeUpdated(this.getBlobGCNodePath(blobId));\n\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"AttachmentReadBlob\", id: storageId },\n async () => {\n return this.getStorage().readBlob(storageId);\n },\n { end: true, cancel: \"error\" },\n );\n }\n\n private getBlobHandle(id: string): IFluidHandle<ArrayBufferLike> {\n assert(this.redirectTable.has(id) || this.pendingBlobs.has(id),\n 0x384 /* requesting handle for unknown blob */);\n return new BlobHandle(\n `${BlobManager.basePath}/${id}`,\n this.routeContext,\n async () => this.getBlob(id),\n );\n }\n\n private async createBlobDetached(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n // Blobs created while the container is detached are stored in IDetachedBlobStorage.\n // The 'IDocumentStorageService.createBlob()' call below will respond with a localId.\n const response = await this.getStorage().createBlob(blob);\n this.redirectTable.set(response.id, undefined);\n return this.getBlobHandle(response.id);\n }\n\n public async createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n if (this.runtime.attachState === AttachState.Detached) {\n return this.createBlobDetached(blob);\n }\n if (this.runtime.attachState === AttachState.Attaching) {\n // blob upload is not supported in \"Attaching\" state\n this.logger.sendTelemetryEvent({ eventName: \"CreateBlobWhileAttaching\" });\n await new Promise<void>((resolve) => this.runtime.once(\"attached\", resolve));\n }\n assert(this.runtime.attachState === AttachState.Attached,\n 0x385 /* For clarity and paranoid defense against adding future attachment states */);\n\n // Create a local ID for each blob. This is used to support blobs if/when the client goes\n // offline since we don't have the ID from storage yet. If online flow succeeds this won't be used.\n const localId = uuid();\n const pendingEntry: PendingBlob = {\n blob,\n status: PendingBlobStatus.OnlinePendingUpload,\n handleP: new Deferred(),\n uploadP: this.uploadBlob(localId, blob),\n };\n this.pendingBlobs.set(localId, pendingEntry);\n\n return pendingEntry.handleP.promise;\n }\n\n private async uploadBlob(localId: string, blob: ArrayBufferLike): Promise<ICreateBlobResponse> {\n return PerformanceEvent.timedExecAsync(\n this.logger,\n { eventName: \"createBlob\" },\n async () => this.getStorage().createBlob(blob),\n { end: true, cancel: this.runtime.connected ? \"error\" : \"generic\" },\n ).then(\n (response) => this.onUploadResolve(localId, response),\n async (err) => this.onUploadReject(localId, err),\n );\n }\n\n private onUploadResolve(localId: string, response: ICreateBlobResponse) {\n const entry = this.pendingBlobs.get(localId);\n assert(entry?.status === PendingBlobStatus.OnlinePendingUpload ||\n entry?.status === PendingBlobStatus.OfflinePendingUpload,\n 0x386 /* Must have pending blob entry for uploaded blob */);\n entry.storageId = response.id;\n if (this.runtime.connected) {\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n if (this.storageIds.has(response.id)) {\n // Storage may dedupe blobs and give us an ID we already know\n // no need to submit BlobAttach op in this case\n entry.handleP.resolve(this.getBlobHandle(response.id));\n this.pendingBlobs.delete(localId);\n } else {\n // Check for still-pending duplicates too; if an op is already in flight we can wait for that one\n if (!this.opsInFlight.has(response.id)) {\n this.sendBlobAttachOp(response.id);\n }\n this.opsInFlight.set(response.id, (this.opsInFlight.get(response.id) ?? []).concat(localId));\n entry.status = PendingBlobStatus.OnlinePendingOp;\n }\n } else if (entry.status === PendingBlobStatus.OfflinePendingUpload) {\n // We already submitted a BlobAttach op for this blob when it was transitioned to offline flow\n entry.status = PendingBlobStatus.OfflinePendingOp;\n }\n } else {\n // connected to storage but not ordering service?\n this.logger.sendTelemetryEvent({ eventName: \"BlobUploadSuccessWhileDisconnected\" });\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n this.transitionToOffline(localId);\n }\n entry.status = PendingBlobStatus.OfflinePendingOp;\n }\n return response;\n }\n\n private async onUploadReject(localId: string, error) {\n const entry = this.pendingBlobs.get(localId);\n assert(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);\n if (!this.runtime.connected) {\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n this.transitionToOffline(localId);\n }\n // we are probably not connected to storage but start another upload request in case we are\n entry.uploadP = this.retryThrottler.getDelay().then(async () => this.uploadBlob(localId, entry.blob));\n return entry.uploadP;\n } else {\n entry.handleP.reject(error);\n throw error;\n }\n }\n\n private transitionToOffline(localId: string) {\n assert(!this.runtime.connected, 0x388 /* Must only transition to offline flow while runtime is disconnected */);\n const entry = this.pendingBlobs.get(localId);\n assert(!!entry, 0x389 /* No pending blob entry */);\n assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status),\n 0x38a /* Blob must be in online flow to transition to offline flow */);\n\n entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload\n ? PendingBlobStatus.OfflinePendingUpload\n : PendingBlobStatus.OfflinePendingOp;\n\n // Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the\n // BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be\n // added to the document if the ops are not all successfully submitted upon reconnection.\n // storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n // is called\n this.sendBlobAttachOp(entry.storageId, localId);\n entry.handleP.resolve(this.getBlobHandle(localId));\n }\n\n /**\n * Resubmit a BlobAttach op. Used to add storage IDs to ops that were\n * submitted to runtime while disconnected.\n * @param metadata - op metadata containing storage and/or local IDs\n */\n public reSubmit(metadata: Record<string, unknown> | undefined) {\n assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);\n const { blobId, localId }: { blobId?: string; localId?: string; } = metadata;\n if (!blobId) {\n assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);\n // We submitted this op while offline. The blob should have been uploaded by now.\n const pendingEntry = this.pendingBlobs.get(localId);\n assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n !!pendingEntry?.storageId, 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);\n return this.sendBlobAttachOp(pendingEntry.storageId, localId);\n }\n return this.sendBlobAttachOp(blobId, localId);\n }\n\n public processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n assert(message?.metadata?.blobId, 0x12a /* \"Missing blob id on metadata\" */);\n if (message.metadata.localId !== undefined) {\n this.redirectTable.set(message.metadata.localId, message.metadata.blobId);\n }\n // set identity (id -> id) entry\n this.redirectTable.set(message.metadata.blobId, message.metadata.blobId);\n\n if (local) {\n if (message.metadata.localId === undefined) {\n // Since there is no local ID, we know this op was submitted while online.\n const waitingBlobs = this.opsInFlight.get(message.metadata.blobId);\n assert(!!waitingBlobs, 0x38e /* local online BlobAttach op with no pending blob */);\n waitingBlobs.forEach((localId) => {\n const pendingBlobEntry = this.pendingBlobs.get(localId);\n assert(\n pendingBlobEntry !== undefined,\n 0x38f, /* local online BlobAttach op with no pending blob entry */\n );\n\n // It's possible we transitioned to offline flow while waiting for this op.\n if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {\n pendingBlobEntry.handleP.resolve(this.getBlobHandle(message.metadata.blobId));\n this.pendingBlobs.delete(localId);\n }\n });\n } else {\n // Each local ID is unique; get the pending blob entry and delete it\n assert(this.pendingBlobs.get(message.metadata.localId)?.status === PendingBlobStatus.OfflinePendingOp,\n 0x1f8 /* \"local BlobAttach op with no pending blob\" */);\n this.pendingBlobs.delete(message.metadata.localId);\n }\n }\n }\n\n /**\n * Reads blobs needed to load BlobManager from storage.\n * @param blobsTree - Tree containing IDs of previously attached blobs. We\n * look for the IDs in the blob entries of the tree since the both the r11s\n * and SPO drivers replace the attachment types returned in snapshot() with blobs.\n */\n public static async load(\n blobsTree: ISnapshotTree | undefined,\n tryFetchBlob: (id: string) => Promise<[string, string][]>,\n ): Promise<IBlobManagerLoadInfo> {\n if (!blobsTree) {\n return {};\n }\n let redirectTable;\n const tableId = blobsTree.blobs[this.redirectTableBlobName];\n if (tableId) {\n redirectTable = await tryFetchBlob(tableId);\n }\n const ids = Object.entries(blobsTree.blobs)\n .filter(([k, _]) => k !== this.redirectTableBlobName).map(([_, v]) => v);\n return { ids, redirectTable };\n }\n\n /**\n * Load a set of previously attached blob IDs and redirect table from a previous snapshot.\n */\n private load(snapshot: IBlobManagerLoadInfo): Map<string, string | undefined> {\n this.logger.sendTelemetryEvent({\n eventName: \"AttachmentBlobsLoaded\",\n count: snapshot.ids?.length ?? 0,\n redirectTable: snapshot.redirectTable?.length,\n });\n const table = new Map<string, string | undefined>(snapshot.redirectTable);\n if (snapshot.ids) {\n const detached = this.runtime.attachState === AttachState.Detached;\n // If we are detached, we don't have storage IDs yet, so set to undefined\n // Otherwise, set identity (id -> id) entries\n snapshot.ids.forEach((entry) => table.set(entry, detached ? undefined : entry));\n }\n return table;\n }\n\n /**\n * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be\n * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.\n * @param fullGC - true to bypass optimizations and force full generation of GC data. BlobManager doesn't care\n * about this for now because the data is a simple list of blob ids.\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n const gcData: IGarbageCollectionData = { gcNodes: {} };\n /**\n * The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned\n * by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.\n */\n this.storageIds.forEach((blobId: string) => {\n gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];\n });\n\n // For some blobs, the handle returned on creation is based off of the localId. So, these\n // nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node\n // must also be marked referenced. So, we add a route from the localId node to the storageId node.\n // Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or\n // a blob may be referenced via its storageId handle.\n for (const [localId, storageId] of this.redirectTable) {\n assert(!!storageId, 0x390 /* Must be attached to get GC data */);\n // Add node for the localId and add a route to the storageId node. The storageId node will have been\n // added above when adding nodes for this.blobIds.\n gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];\n }\n\n return gcData;\n }\n\n /**\n * When running GC in test mode, this is called to delete blobs that are unused.\n * @param unusedRoutes - These are the blob node ids that are unused and should be deleted.\n */\n public deleteUnusedRoutes(unusedRoutes: string[]): void {\n // The routes or blob node paths are in the same format as returned in getGCData -\n // `/<BlobManager.basePath>/<blobId>`.\n for (const route of unusedRoutes) {\n const pathParts = route.split(\"/\");\n assert(\n pathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n 0x2d5 /* \"Invalid blob node id in unused routes.\" */,\n );\n const blobId = pathParts[2];\n\n // The unused blobId could be a localId. If so, remove it from the redirect table and continue. The\n // corresponding storageId may still be used either directly or via other localIds.\n if (this.redirectTable?.has(blobId)) {\n this.redirectTable.delete(blobId);\n continue;\n }\n }\n }\n\n public summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n // if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached\n const blobIds = this.storageIds.size > 0 ? Array.from(this.storageIds) : Array.from(this.redirectTable.keys());\n const builder = new SummaryTreeBuilder();\n blobIds.forEach((blobId) => {\n builder.addAttachment(blobId);\n });\n\n // Any non-identity entries in the table need to be saved in the summary\n if (this.redirectTable.size > blobIds.length) {\n builder.addBlob(\n BlobManager.redirectTableBlobName,\n // filter out identity entries\n JSON.stringify(Array.from(this.redirectTable.entries())\n .filter(([localId, storageId]) => localId !== storageId)),\n );\n }\n\n return builder.getSummaryTree();\n }\n\n public setRedirectTable(table: Map<string, string>) {\n assert(this.runtime.attachState === AttachState.Detached,\n 0x252 /* \"redirect table can only be set in detached container\" */);\n assert(this.redirectTable.size === table.size,\n 0x391 /* Redirect table size must match BlobManager's local ID count */);\n for (const [localId, storageId] of table) {\n assert(this.redirectTable.has(localId), 0x254 /* \"unrecognized id in redirect table\" */);\n this.redirectTable.set(localId, storageId);\n // set identity (id -> id) entry\n this.redirectTable.set(storageId, storageId);\n }\n }\n\n public getPendingBlobs(): IPendingBlobs {\n const blobs = {};\n for (const [key, entry] of this.pendingBlobs) {\n blobs[key] = { blob: bufferToString(entry.blob, \"base64\") };\n }\n return blobs;\n }\n}\n"]}