@fluidframework/container-runtime 2.0.0-internal.3.0.5 → 2.0.0-internal.3.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.
- package/.eslintrc.js +19 -19
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/batchTracker.d.ts.map +1 -1
- package/dist/batchTracker.js +2 -1
- package/dist/batchTracker.js.map +1 -1
- package/dist/blobManager.d.ts +9 -2
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +80 -33
- package/dist/blobManager.js.map +1 -1
- package/dist/connectionTelemetry.d.ts.map +1 -1
- package/dist/connectionTelemetry.js +11 -9
- package/dist/connectionTelemetry.js.map +1 -1
- package/dist/containerHandleContext.d.ts.map +1 -1
- package/dist/containerHandleContext.js +3 -1
- package/dist/containerHandleContext.js.map +1 -1
- package/dist/containerRuntime.d.ts +11 -1
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +116 -72
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStore.d.ts.map +1 -1
- package/dist/dataStore.js +11 -9
- package/dist/dataStore.js.map +1 -1
- package/dist/dataStoreContext.d.ts +18 -13
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +68 -55
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStoreContexts.d.ts.map +1 -1
- package/dist/dataStoreContexts.js +7 -3
- package/dist/dataStoreContexts.js.map +1 -1
- package/dist/dataStoreRegistry.d.ts.map +1 -1
- package/dist/dataStoreRegistry.js +3 -1
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts +26 -1
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +103 -18
- package/dist/dataStores.js.map +1 -1
- package/dist/deltaScheduler.d.ts.map +1 -1
- package/dist/deltaScheduler.js +8 -3
- package/dist/deltaScheduler.js.map +1 -1
- package/dist/garbageCollection.d.ts +33 -14
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +178 -92
- package/dist/garbageCollection.js.map +1 -1
- package/dist/garbageCollectionConstants.d.ts +1 -0
- package/dist/garbageCollectionConstants.d.ts.map +1 -1
- package/dist/garbageCollectionConstants.js +4 -1
- package/dist/garbageCollectionConstants.js.map +1 -1
- package/dist/garbageCollectionHelpers.d.ts +26 -0
- package/dist/garbageCollectionHelpers.d.ts.map +1 -0
- package/dist/garbageCollectionHelpers.js +45 -0
- package/dist/garbageCollectionHelpers.js.map +1 -0
- package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
- package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/dist/gcSweepReadyUsageDetection.js +14 -10
- package/dist/gcSweepReadyUsageDetection.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/opLifecycle/batchManager.d.ts +5 -5
- package/dist/opLifecycle/batchManager.d.ts.map +1 -1
- package/dist/opLifecycle/batchManager.js +19 -12
- package/dist/opLifecycle/batchManager.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts.map +1 -1
- package/dist/opLifecycle/definitions.js.map +1 -1
- package/dist/opLifecycle/index.d.ts.map +1 -1
- package/dist/opLifecycle/index.js.map +1 -1
- package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opCompressor.js.map +1 -1
- package/dist/opLifecycle/opDecompressor.d.ts +0 -4
- package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opDecompressor.js +7 -43
- package/dist/opLifecycle/opDecompressor.js.map +1 -1
- package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
- package/dist/opLifecycle/opSplitter.js +4 -1
- package/dist/opLifecycle/opSplitter.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +20 -19
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/dist/opProperties.d.ts.map +1 -1
- package/dist/opProperties.js +1 -3
- package/dist/opProperties.js.map +1 -1
- package/dist/orderedClientElection.d.ts.map +1 -1
- package/dist/orderedClientElection.js +10 -4
- package/dist/orderedClientElection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +7 -0
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +7 -4
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
- package/dist/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/runningSummarizer.d.ts.map +1 -1
- package/dist/runningSummarizer.js +34 -21
- package/dist/runningSummarizer.js.map +1 -1
- package/dist/scheduleManager.d.ts.map +1 -1
- package/dist/scheduleManager.js +3 -2
- package/dist/scheduleManager.js.map +1 -1
- package/dist/serializedSnapshotStorage.d.ts +2 -2
- package/dist/serializedSnapshotStorage.d.ts.map +1 -1
- package/dist/serializedSnapshotStorage.js +5 -3
- package/dist/serializedSnapshotStorage.js.map +1 -1
- package/dist/summarizer.d.ts +2 -2
- package/dist/summarizer.d.ts.map +1 -1
- package/dist/summarizer.js +37 -17
- package/dist/summarizer.js.map +1 -1
- package/dist/summarizerClientElection.d.ts.map +1 -1
- package/dist/summarizerClientElection.js.map +1 -1
- package/dist/summarizerHandle.d.ts.map +1 -1
- package/dist/summarizerHandle.js.map +1 -1
- package/dist/summarizerHeuristics.d.ts.map +1 -1
- package/dist/summarizerHeuristics.js +6 -9
- package/dist/summarizerHeuristics.js.map +1 -1
- package/dist/summarizerTypes.d.ts +21 -21
- package/dist/summarizerTypes.d.ts.map +1 -1
- package/dist/summarizerTypes.js.map +1 -1
- package/dist/summaryCollection.d.ts.map +1 -1
- package/dist/summaryCollection.js +18 -8
- package/dist/summaryCollection.js.map +1 -1
- package/dist/summaryFormat.d.ts +5 -2
- package/dist/summaryFormat.d.ts.map +1 -1
- package/dist/summaryFormat.js +18 -10
- package/dist/summaryFormat.js.map +1 -1
- package/dist/summaryGenerator.d.ts.map +1 -1
- package/dist/summaryGenerator.js +35 -16
- package/dist/summaryGenerator.js.map +1 -1
- package/dist/summaryManager.d.ts.map +1 -1
- package/dist/summaryManager.js +21 -9
- package/dist/summaryManager.js.map +1 -1
- package/dist/throttler.d.ts +2 -2
- package/dist/throttler.d.ts.map +1 -1
- package/dist/throttler.js +4 -4
- package/dist/throttler.js.map +1 -1
- package/garbageCollection.md +15 -2
- package/lib/batchTracker.d.ts.map +1 -1
- package/lib/batchTracker.js +2 -1
- package/lib/batchTracker.js.map +1 -1
- package/lib/blobManager.d.ts +9 -2
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +82 -35
- package/lib/blobManager.js.map +1 -1
- package/lib/connectionTelemetry.d.ts.map +1 -1
- package/lib/connectionTelemetry.js +11 -9
- package/lib/connectionTelemetry.js.map +1 -1
- package/lib/containerHandleContext.d.ts.map +1 -1
- package/lib/containerHandleContext.js +3 -1
- package/lib/containerHandleContext.js.map +1 -1
- package/lib/containerRuntime.d.ts +11 -1
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +122 -78
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStore.d.ts.map +1 -1
- package/lib/dataStore.js +11 -9
- package/lib/dataStore.js.map +1 -1
- package/lib/dataStoreContext.d.ts +18 -13
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +71 -58
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStoreContexts.d.ts.map +1 -1
- package/lib/dataStoreContexts.js +7 -3
- package/lib/dataStoreContexts.js.map +1 -1
- package/lib/dataStoreRegistry.d.ts.map +1 -1
- package/lib/dataStoreRegistry.js +3 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts +26 -1
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +109 -24
- package/lib/dataStores.js.map +1 -1
- package/lib/deltaScheduler.d.ts.map +1 -1
- package/lib/deltaScheduler.js +9 -4
- package/lib/deltaScheduler.js.map +1 -1
- package/lib/garbageCollection.d.ts +33 -14
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +180 -94
- package/lib/garbageCollection.js.map +1 -1
- package/lib/garbageCollectionConstants.d.ts +1 -0
- package/lib/garbageCollectionConstants.d.ts.map +1 -1
- package/lib/garbageCollectionConstants.js +3 -0
- package/lib/garbageCollectionConstants.js.map +1 -1
- package/lib/garbageCollectionHelpers.d.ts +26 -0
- package/lib/garbageCollectionHelpers.d.ts.map +1 -0
- package/lib/garbageCollectionHelpers.js +40 -0
- package/lib/garbageCollectionHelpers.js.map +1 -0
- package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
- package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/lib/gcSweepReadyUsageDetection.js +14 -10
- package/lib/gcSweepReadyUsageDetection.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/opLifecycle/batchManager.d.ts +5 -5
- package/lib/opLifecycle/batchManager.d.ts.map +1 -1
- package/lib/opLifecycle/batchManager.js +19 -12
- package/lib/opLifecycle/batchManager.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts.map +1 -1
- package/lib/opLifecycle/definitions.js.map +1 -1
- package/lib/opLifecycle/index.d.ts.map +1 -1
- package/lib/opLifecycle/index.js.map +1 -1
- package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opCompressor.js.map +1 -1
- package/lib/opLifecycle/opDecompressor.d.ts +0 -4
- package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opDecompressor.js +7 -43
- package/lib/opLifecycle/opDecompressor.js.map +1 -1
- package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
- package/lib/opLifecycle/opSplitter.js +5 -2
- package/lib/opLifecycle/opSplitter.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +20 -19
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/lib/opProperties.d.ts.map +1 -1
- package/lib/opProperties.js +1 -3
- package/lib/opProperties.js.map +1 -1
- package/lib/orderedClientElection.d.ts.map +1 -1
- package/lib/orderedClientElection.js +10 -4
- package/lib/orderedClientElection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +7 -0
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +7 -4
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
- package/lib/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/runningSummarizer.d.ts.map +1 -1
- package/lib/runningSummarizer.js +35 -22
- package/lib/runningSummarizer.js.map +1 -1
- package/lib/scheduleManager.d.ts.map +1 -1
- package/lib/scheduleManager.js +3 -2
- package/lib/scheduleManager.js.map +1 -1
- package/lib/serializedSnapshotStorage.d.ts +2 -2
- package/lib/serializedSnapshotStorage.d.ts.map +1 -1
- package/lib/serializedSnapshotStorage.js +5 -3
- package/lib/serializedSnapshotStorage.js.map +1 -1
- package/lib/summarizer.d.ts +2 -2
- package/lib/summarizer.d.ts.map +1 -1
- package/lib/summarizer.js +37 -17
- package/lib/summarizer.js.map +1 -1
- package/lib/summarizerClientElection.d.ts.map +1 -1
- package/lib/summarizerClientElection.js.map +1 -1
- package/lib/summarizerHandle.d.ts.map +1 -1
- package/lib/summarizerHandle.js.map +1 -1
- package/lib/summarizerHeuristics.d.ts.map +1 -1
- package/lib/summarizerHeuristics.js +6 -9
- package/lib/summarizerHeuristics.js.map +1 -1
- package/lib/summarizerTypes.d.ts +21 -21
- package/lib/summarizerTypes.d.ts.map +1 -1
- package/lib/summarizerTypes.js.map +1 -1
- package/lib/summaryCollection.d.ts.map +1 -1
- package/lib/summaryCollection.js +18 -8
- package/lib/summaryCollection.js.map +1 -1
- package/lib/summaryFormat.d.ts +5 -2
- package/lib/summaryFormat.d.ts.map +1 -1
- package/lib/summaryFormat.js +20 -12
- package/lib/summaryFormat.js.map +1 -1
- package/lib/summaryGenerator.d.ts.map +1 -1
- package/lib/summaryGenerator.js +35 -16
- package/lib/summaryGenerator.js.map +1 -1
- package/lib/summaryManager.d.ts.map +1 -1
- package/lib/summaryManager.js +21 -9
- package/lib/summaryManager.js.map +1 -1
- package/lib/throttler.d.ts +2 -2
- package/lib/throttler.d.ts.map +1 -1
- package/lib/throttler.js +4 -4
- package/lib/throttler.js.map +1 -1
- package/package.json +121 -115
- package/prettier.config.cjs +1 -1
- package/src/batchTracker.ts +54 -49
- package/src/blobManager.ts +793 -672
- package/src/connectionTelemetry.ts +280 -249
- package/src/containerHandleContext.ts +27 -29
- package/src/containerRuntime.ts +3168 -2988
- package/src/dataStore.ts +172 -159
- package/src/dataStoreContext.ts +1098 -1055
- package/src/dataStoreContexts.ts +178 -161
- package/src/dataStoreRegistry.ts +25 -20
- package/src/dataStores.ts +884 -728
- package/src/deltaScheduler.ts +158 -150
- package/src/garbageCollection.ts +1860 -1688
- package/src/garbageCollectionConstants.ts +3 -0
- package/src/garbageCollectionHelpers.ts +61 -0
- package/src/gcSweepReadyUsageDetection.ts +89 -83
- package/src/index.ts +67 -66
- package/src/opLifecycle/README.md +152 -0
- package/src/opLifecycle/batchManager.ts +145 -141
- package/src/opLifecycle/definitions.ts +29 -29
- package/src/opLifecycle/index.ts +5 -5
- package/src/opLifecycle/opCompressor.ts +54 -53
- package/src/opLifecycle/opDecompressor.ts +100 -128
- package/src/opLifecycle/opSplitter.ts +214 -188
- package/src/opLifecycle/outbox.ts +204 -195
- package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
- package/src/opProperties.ts +11 -9
- package/src/orderedClientElection.ts +489 -457
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +384 -338
- package/src/runWhileConnectedCoordinator.ts +78 -71
- package/src/runningSummarizer.ts +619 -581
- package/src/scheduleManager.ts +299 -269
- package/src/serializedSnapshotStorage.ts +126 -112
- package/src/summarizer.ts +417 -381
- package/src/summarizerClientElection.ts +107 -100
- package/src/summarizerHandle.ts +11 -9
- package/src/summarizerHeuristics.ts +183 -186
- package/src/summarizerTypes.ts +344 -330
- package/src/summaryCollection.ts +378 -349
- package/src/summaryFormat.ts +165 -143
- package/src/summaryGenerator.ts +465 -410
- package/src/summaryManager.ts +377 -348
- package/src/throttler.ts +131 -122
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
- package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
- package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
- package/dist/garbageCollectionTombstoneUtils.js +0 -23
- package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
- package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
- package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
- package/lib/garbageCollectionTombstoneUtils.js +0 -19
- package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
- package/src/garbageCollectionTombstoneUtils.ts +0 -28
package/lib/blobManager.js
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { v4 as uuid } from "uuid";
|
|
6
6
|
import { createResponseError, generateHandleContextPath, responseToException, SummaryTreeBuilder, } from "@fluidframework/runtime-utils";
|
|
7
|
-
import { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter } from "@fluidframework/common-utils";
|
|
7
|
+
import { assert, bufferToString, Deferred, stringToBuffer, TypedEventEmitter, } from "@fluidframework/common-utils";
|
|
8
8
|
import { AttachState } from "@fluidframework/container-definitions";
|
|
9
|
-
import { ChildLogger, loggerToMonitoringContext, PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
9
|
+
import { ChildLogger, loggerToMonitoringContext, PerformanceEvent, } from "@fluidframework/telemetry-utils";
|
|
10
|
+
import { TombstoneResponseHeaderKey } from "./containerRuntime";
|
|
10
11
|
import { Throttler, formExponentialFn } from "./throttler";
|
|
11
12
|
import { summarizerClientType } from "./summarizerClientElection";
|
|
12
13
|
import { throwOnTombstoneLoadKey } from "./garbageCollectionConstants";
|
|
13
|
-
import {
|
|
14
|
+
import { sendGCUnexpectedUsageEvent } from "./garbageCollectionHelpers";
|
|
14
15
|
/**
|
|
15
16
|
* This class represents blob (long string)
|
|
16
17
|
* This object is used only when creating (writing) new blob and serialization purposes.
|
|
@@ -26,7 +27,9 @@ export class BlobHandle {
|
|
|
26
27
|
this.attached = false;
|
|
27
28
|
this.absolutePath = generateHandleContextPath(path, this.routeContext);
|
|
28
29
|
}
|
|
29
|
-
get IFluidHandle() {
|
|
30
|
+
get IFluidHandle() {
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
30
33
|
get isAttached() {
|
|
31
34
|
return this.attached;
|
|
32
35
|
}
|
|
@@ -75,15 +78,23 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
75
78
|
* before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
|
|
76
79
|
*/
|
|
77
80
|
sendBlobAttachOp,
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
blobRequested,
|
|
81
|
+
// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.
|
|
82
|
+
// blobPath's format - `/<BlobManager.basePath>/<blobId>`.
|
|
83
|
+
blobRequested,
|
|
84
|
+
// Called when a reference is added to a blob. For instance, when creating a localId / storageId to storageId
|
|
85
|
+
// mapping in the redirect table.
|
|
86
|
+
// Node path formats - `/<BlobManager.basePath>/<blobId>`.
|
|
87
|
+
addedBlobReference,
|
|
88
|
+
// Called to check if a blob has been deleted by GC.
|
|
89
|
+
// blobPath's format - `/<BlobManager.basePath>/<blobId>`.
|
|
90
|
+
isBlobDeleted, runtime, stashedBlobs = {}, getCurrentReferenceTimestampMs) {
|
|
81
91
|
super();
|
|
82
92
|
this.routeContext = routeContext;
|
|
83
93
|
this.getStorage = getStorage;
|
|
84
94
|
this.sendBlobAttachOp = sendBlobAttachOp;
|
|
85
95
|
this.blobRequested = blobRequested;
|
|
86
96
|
this.addedBlobReference = addedBlobReference;
|
|
97
|
+
this.isBlobDeleted = isBlobDeleted;
|
|
87
98
|
this.runtime = runtime;
|
|
88
99
|
this.getCurrentReferenceTimestampMs = getCurrentReferenceTimestampMs;
|
|
89
100
|
/**
|
|
@@ -111,6 +122,7 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
111
122
|
// Read the feature flag that tells whether to throw when a tombstone blob is requested.
|
|
112
123
|
this.throwOnTombstoneLoad =
|
|
113
124
|
this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
|
|
125
|
+
this.runtime.gcTombstoneEnforcementAllowed &&
|
|
114
126
|
this.runtime.clientDetails.type !== summarizerClientType;
|
|
115
127
|
this.runtime.on("disconnected", () => this.onDisconnected());
|
|
116
128
|
this.redirectTable = this.load(snapshot);
|
|
@@ -126,15 +138,14 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
126
138
|
});
|
|
127
139
|
}
|
|
128
140
|
get pendingOfflineUploads() {
|
|
129
|
-
return Array.from(this.pendingBlobs.values())
|
|
130
|
-
.filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
|
|
141
|
+
return Array.from(this.pendingBlobs.values()).filter((e) => e.status === PendingBlobStatus.OfflinePendingUpload);
|
|
131
142
|
}
|
|
132
143
|
get hasPendingOfflineUploads() {
|
|
133
144
|
return this.pendingOfflineUploads.length > 0;
|
|
134
145
|
}
|
|
135
146
|
get hasPendingBlobs() {
|
|
136
|
-
return (this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0)
|
|
137
|
-
|
|
147
|
+
return ((this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||
|
|
148
|
+
this.pendingBlobs.size > 0);
|
|
138
149
|
}
|
|
139
150
|
/**
|
|
140
151
|
* Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
|
|
@@ -178,22 +189,14 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
178
189
|
const undefinedValueInTable = ids.delete(undefined);
|
|
179
190
|
// For a detached container, entries are inserted into the redirect table with an undefined storage ID.
|
|
180
191
|
// For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.
|
|
181
|
-
assert(!undefinedValueInTable ||
|
|
192
|
+
assert(!undefinedValueInTable ||
|
|
193
|
+
(this.runtime.attachState === AttachState.Detached && ids.size === 0), 0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */);
|
|
182
194
|
return ids;
|
|
183
195
|
}
|
|
184
196
|
async getBlob(blobId) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
sendGCTombstoneEvent(this.mc, {
|
|
189
|
-
eventName: "GC_Tombstone_Blob_Requested",
|
|
190
|
-
category: this.throwOnTombstoneLoad ? "error" : "generic",
|
|
191
|
-
isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
|
|
192
|
-
}, [BlobManager.basePath], error);
|
|
193
|
-
if (this.throwOnTombstoneLoad) {
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
+
// Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,
|
|
198
|
+
// failing the call.
|
|
199
|
+
this.verifyBlobValidity(blobId);
|
|
197
200
|
const pending = this.pendingBlobs.get(blobId);
|
|
198
201
|
if (pending) {
|
|
199
202
|
return pending.blob;
|
|
@@ -329,7 +332,9 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
329
332
|
this.transitionToOffline(localId);
|
|
330
333
|
}
|
|
331
334
|
// we are probably not connected to storage but start another upload request in case we are
|
|
332
|
-
entry.uploadP = this.retryThrottler
|
|
335
|
+
entry.uploadP = this.retryThrottler
|
|
336
|
+
.getDelay()
|
|
337
|
+
.then(async () => this.uploadBlob(localId, entry.blob));
|
|
333
338
|
return entry.uploadP;
|
|
334
339
|
}
|
|
335
340
|
else {
|
|
@@ -353,9 +358,10 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
353
358
|
this.logTimeInfo(entry, "sendBlobAttachTransitionOfflineTTL");
|
|
354
359
|
this.sendBlobAttachOp(localId, entry.storageId);
|
|
355
360
|
}
|
|
356
|
-
entry.status =
|
|
357
|
-
|
|
358
|
-
|
|
361
|
+
entry.status =
|
|
362
|
+
entry.status === PendingBlobStatus.OnlinePendingUpload
|
|
363
|
+
? PendingBlobStatus.OfflinePendingUpload
|
|
364
|
+
: PendingBlobStatus.OfflinePendingOp;
|
|
359
365
|
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
360
366
|
}
|
|
361
367
|
/**
|
|
@@ -387,11 +393,13 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
387
393
|
let expiredUsingServerTime;
|
|
388
394
|
if (pendingEntry.localUploadTime) {
|
|
389
395
|
timeLapseSinceLocalUpload = (Date.now() - pendingEntry.localUploadTime) / 1000;
|
|
390
|
-
expiredUsingLocalTime =
|
|
396
|
+
expiredUsingLocalTime =
|
|
397
|
+
((_a = pendingEntry.minTTLInSeconds) !== null && _a !== void 0 ? _a : 0) - timeLapseSinceLocalUpload < 0 ? true : false;
|
|
391
398
|
}
|
|
392
399
|
if (pendingEntry.serverUploadTime) {
|
|
393
400
|
timeLapseSinceServerUpload = (Date.now() - pendingEntry.serverUploadTime) / 1000;
|
|
394
|
-
expiredUsingServerTime =
|
|
401
|
+
expiredUsingServerTime =
|
|
402
|
+
((_b = pendingEntry.minTTLInSeconds) !== null && _b !== void 0 ? _b : 0) - timeLapseSinceServerUpload < 0 ? true : false;
|
|
395
403
|
}
|
|
396
404
|
this.mc.logger.sendTelemetryEvent({
|
|
397
405
|
eventName,
|
|
@@ -426,7 +434,7 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
426
434
|
// storage ID is already in flight and any op containing this local ID will be sequenced after that.
|
|
427
435
|
waitingBlobs.forEach((pendingLocalId) => {
|
|
428
436
|
const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
|
|
429
|
-
assert(pendingBlobEntry !== undefined, 0x38f);
|
|
437
|
+
assert(pendingBlobEntry !== undefined, 0x38f /* local online BlobAttach op with no pending blob entry */);
|
|
430
438
|
// It's possible we transitioned to offline flow while waiting for this op.
|
|
431
439
|
if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
|
|
432
440
|
this.setRedirection(pendingLocalId, blobId);
|
|
@@ -456,7 +464,8 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
456
464
|
redirectTable = await tryFetchBlob(tableId);
|
|
457
465
|
}
|
|
458
466
|
const ids = Object.entries(blobsTree.blobs)
|
|
459
|
-
.filter(([k, _]) => k !== this.redirectTableBlobName)
|
|
467
|
+
.filter(([k, _]) => k !== this.redirectTableBlobName)
|
|
468
|
+
.map(([_, v]) => v);
|
|
460
469
|
return { ids, redirectTable };
|
|
461
470
|
}
|
|
462
471
|
/**
|
|
@@ -531,9 +540,48 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
531
540
|
this.tombstonedBlobs.add(blobId);
|
|
532
541
|
}
|
|
533
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,
|
|
545
|
+
* log an error and throw if necessary.
|
|
546
|
+
*/
|
|
547
|
+
verifyBlobValidity(blobId) {
|
|
548
|
+
/**
|
|
549
|
+
* A blob can be in one of the following states:
|
|
550
|
+
* 1. "deleted" - It has been deleted by garbage collection sweep phase.
|
|
551
|
+
* 2. "tombstoned" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.
|
|
552
|
+
* 3. "valid" - It has not been deleted or tombstoned.
|
|
553
|
+
*/
|
|
554
|
+
let state = "valid";
|
|
555
|
+
if (this.isBlobDeleted(this.getBlobGCNodePath(blobId))) {
|
|
556
|
+
state = "deleted";
|
|
557
|
+
}
|
|
558
|
+
else if (this.tombstonedBlobs.has(blobId)) {
|
|
559
|
+
state = "tombstoned";
|
|
560
|
+
}
|
|
561
|
+
if (state === "valid") {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
// If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt
|
|
565
|
+
// to load the blob.
|
|
566
|
+
const shouldFail = state === "deleted" || this.throwOnTombstoneLoad;
|
|
567
|
+
const request = { url: blobId };
|
|
568
|
+
const error = responseToException(createResponseError(404, "Blob was deleted", request, state === "tombstoned" ? { [TombstoneResponseHeaderKey]: true } : undefined), request);
|
|
569
|
+
sendGCUnexpectedUsageEvent(this.mc, {
|
|
570
|
+
eventName: state === "tombstoned"
|
|
571
|
+
? "GC_Tombstone_Blob_Requested"
|
|
572
|
+
: "GC_Deleted_Blob_Requested",
|
|
573
|
+
category: shouldFail ? "error" : "generic",
|
|
574
|
+
gcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,
|
|
575
|
+
}, [BlobManager.basePath], error);
|
|
576
|
+
if (shouldFail) {
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
534
580
|
summarize(telemetryContext) {
|
|
535
581
|
// if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
|
|
536
|
-
const blobIds = this.storageIds.size > 0
|
|
582
|
+
const blobIds = this.storageIds.size > 0
|
|
583
|
+
? Array.from(this.storageIds)
|
|
584
|
+
: Array.from(this.redirectTable.keys());
|
|
537
585
|
const builder = new SummaryTreeBuilder();
|
|
538
586
|
blobIds.forEach((blobId) => {
|
|
539
587
|
builder.addAttachment(blobId);
|
|
@@ -542,8 +590,7 @@ export class BlobManager extends TypedEventEmitter {
|
|
|
542
590
|
if (this.redirectTable.size > blobIds.length) {
|
|
543
591
|
builder.addBlob(BlobManager.redirectTableBlobName,
|
|
544
592
|
// filter out identity entries
|
|
545
|
-
JSON.stringify(Array.from(this.redirectTable.entries())
|
|
546
|
-
.filter(([localId, storageId]) => localId !== storageId)));
|
|
593
|
+
JSON.stringify(Array.from(this.redirectTable.entries()).filter(([localId, storageId]) => localId !== storageId)));
|
|
547
594
|
}
|
|
548
595
|
return builder.getSummaryTree();
|
|
549
596
|
}
|
package/lib/blobManager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAIlC,OAAO,EACH,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,GACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEnH,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAqB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAM9H,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAc,MAAM,aAAa,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE;;;;;;GAMG;AACH,MAAM,OAAO,UAAU;IAWnB,YACoB,IAAY,EACZ,YAAiC,EAC1C,GAAuB;QAFd,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAqB;QAC1C,QAAG,GAAH,GAAG,CAAo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AAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;SAC7C;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,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;SAC/D;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;;AAhmBsB,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 {\n createResponseError,\n generateHandleContextPath,\n responseToException,\n SummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\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, loggerToMonitoringContext, MonitoringContext, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { throwOnTombstoneLoadKey } from \"./garbageCollectionConstants\";\nimport { sendGCTombstoneEvent } from \"./garbageCollectionTombstoneUtils\";\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\" | \"clientDetails\"> & 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\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse & Partial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n blob: ArrayBufferLike;\n status: PendingBlobStatus;\n storageId?: string;\n handleP: Deferred<IFluidHandle<ArrayBufferLike>>;\n uploadP: Promise<ICreateBlobResponse>;\n localUploadTime?: number;\n serverUploadTime?: number;\n minTTLInSeconds?: number;\n}\n\nexport interface IPendingBlobs { [id: string]: { blob: string; }; }\n\nexport interface IBlobManagerEvents {\n (event: \"noPendingBlobs\", listener: () => void);\n}\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\n public static readonly basePath = \"_blobs\";\n private static readonly redirectTableBlobName = \".redirectTable\";\n private readonly mc: MonitoringContext;\n\n /**\n * Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should\n * be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which\n * gives local IDs; the storage IDs are filled in at attach time.\n * Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client\n * that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.\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. This is used for optimizations where if we receive an ack for a storage ID,\n * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's\n * because we know that the server will not delete the blob corresponding to that storage ID.\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 /** If true, throw an error when a tombstone attachment blob is retrieved. */\n private readonly throwOnTombstoneLoad: boolean;\n /**\n * This stores IDs of tombstoned blobs.\n * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.\n */\n private readonly tombstonedBlobs: Set<string> = new Set();\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 the blob is\n * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the\n * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to\n * include the storage ID in the summary when it sees the op.\n *\n * The op will also include a local ID to inform all clients of the relation to the storage ID, without\n * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced\n * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.\n */\n private readonly sendBlobAttachOp: (localId: string, storageId?: 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 blobRequested: (blobPath: string) => void,\n private readonly addedBlobReference: (fromNodePath: string, toNodePath: string) => void,\n private readonly runtime: IBlobManagerRuntime,\n stashedBlobs: IPendingBlobs = {},\n private readonly getCurrentReferenceTimestampMs: () => number | undefined,\n ) {\n super();\n this.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, \"BlobManager\"));\n // Read the feature flag that tells whether to throw when a tombstone blob is requested.\n this.throwOnTombstoneLoad =\n this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&\n this.runtime.clientDetails.type !== summarizerClientType;\n\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 public get hasPendingBlobs(): boolean {\n return (this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0)\n || this.pendingBlobs.size > 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.mc.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 request = { url: blobId };\n if (this.tombstonedBlobs.has(blobId) ) {\n const error = responseToException(createResponseError(404, \"Blob was deleted\", request), request);\n sendGCTombstoneEvent(\n this.mc,\n {\n eventName: \"GC_Tombstone_Blob_Requested\",\n category: this.throwOnTombstoneLoad ? \"error\" : \"generic\",\n isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,\n },\n [BlobManager.basePath],\n error,\n );\n if (this.throwOnTombstoneLoad) {\n throw error;\n }\n }\n\n const pending = this.pendingBlobs.get(blobId);\n if (pending) {\n return pending.blob;\n }\n let storageId: string;\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 const attachedStorageId = this.redirectTable.get(blobId);\n assert(!!attachedStorageId, 0x11f /* \"requesting unknown blobs\" */);\n storageId = attachedStorageId;\n }\n\n // Let runtime know that the corresponding GC node was requested.\n this.blobRequested(this.getBlobGCNodePath(blobId));\n\n return PerformanceEvent.timedExecAsync(\n this.mc.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.setRedirection(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.mc.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 the blob. After uploading it to storage and before returning it, a local ID to\n // storage ID mapping is created.\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.mc.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 /**\n * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added\n * which is required for GC.\n */\n private setRedirection(fromId: string, toId: string | undefined) {\n this.redirectTable.set(fromId, toId);\n // Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in\n // detached mode. In this case, the entry will be updated when the blob is updated.\n if (toId !== undefined) {\n this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));\n }\n }\n\n private deleteAndEmitsIfEmpty(id: string) {\n if (this.pendingBlobs.has(id)) {\n this.pendingBlobs.delete(id);\n if (!this.hasPendingBlobs) {\n this.emit(\"noPendingBlobs\");\n }\n }\n }\n\n private onUploadResolve(localId: string, response: ICreateBlobResponseWithTTL) {\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 entry.localUploadTime = Date.now();\n entry.minTTLInSeconds = response.minTTLInSeconds;\n entry.serverUploadTime = this.getCurrentReferenceTimestampMs();\n if (this.runtime.connected) {\n if (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n // Send a blob attach op. This serves two purposes:\n // 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\n // until its storage ID is added to the next summary.\n // 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the\n // blob from the server via the storage ID.\n this.logTimeInfo(entry, \"sendBlobAttachResolveTTL\");\n this.sendBlobAttachOp(localId, response.id);\n if (this.storageIds.has(response.id)) {\n // The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is\n // an existing blob, we don't have to wait for the op to be ack'd since this step has already\n // happened before and so, the server won't delete it.\n this.setRedirection(localId, response.id);\n entry.handleP.resolve(this.getBlobHandle(localId));\n this.deleteAndEmitsIfEmpty(localId);\n } else {\n // If there is already an op for this storage ID, append the local ID to the list. Once any op for\n // this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n // blob alive in storage.\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.mc.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 /**\n * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.\n * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,\n * an invalid handle could be added to the document.\n * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n * is called on reconnection.\n */\n if (entry.status !== PendingBlobStatus.OnlinePendingOp) {\n this.logTimeInfo(entry, \"sendBlobAttachTransitionOfflineTTL\");\n this.sendBlobAttachOp(localId, entry.storageId);\n }\n\n entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload\n ? PendingBlobStatus.OfflinePendingUpload\n : PendingBlobStatus.OfflinePendingOp;\n\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 { localId, blobId }: { localId?: string; blobId?: string } = metadata;\n assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);\n const pendingEntry = this.pendingBlobs.get(localId);\n if (pendingEntry) {\n this.logTimeInfo(pendingEntry, \"sendBlobAttachResubmitTTL\");\n }\n if (!blobId) {\n // We submitted this op while offline. The blob should have been uploaded by now.\n assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n !!pendingEntry?.storageId, 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);\n return this.sendBlobAttachOp(localId, pendingEntry.storageId);\n }\n return this.sendBlobAttachOp(localId, blobId);\n }\n\n private logTimeInfo(pendingEntry: PendingBlob, eventName: string) {\n let timeLapseSinceLocalUpload: number = 0;\n let timeLapseSinceServerUpload: number = 0;\n let expiredUsingLocalTime;\n let expiredUsingServerTime;\n if(pendingEntry.localUploadTime){\n timeLapseSinceLocalUpload = (Date.now() - pendingEntry.localUploadTime) / 1000;\n expiredUsingLocalTime = (pendingEntry.minTTLInSeconds?? 0) - timeLapseSinceLocalUpload < 0 ? true : false;\n }\n if(pendingEntry.serverUploadTime){\n timeLapseSinceServerUpload = (Date.now() - pendingEntry.serverUploadTime) / 1000;\n expiredUsingServerTime = (pendingEntry.minTTLInSeconds?? 0) - timeLapseSinceServerUpload < 0 ? true : false;\n }\n this.mc.logger.sendTelemetryEvent({\n eventName,\n entryStatus: pendingEntry.status,\n timeLapseSinceLocalUpload,\n timeLapseSinceServerUpload,\n minTTLInSeconds: pendingEntry.minTTLInSeconds,\n expiredUsingLocalTime,\n expiredUsingServerTime,\n });\n\n }\n\n public processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n const localId = message.metadata?.localId;\n const blobId = message.metadata?.blobId;\n assert(blobId !== undefined, 0x12a /* \"Missing blob id on metadata\" */);\n\n // Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be\n // requested from the server.\n // Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that\n // was sent when online.\n if (localId !== undefined) {\n this.setRedirection(localId, blobId);\n }\n // set identity (id -> id) entry\n this.setRedirection(blobId, blobId);\n\n if (local) {\n assert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);\n const waitingBlobs = this.opsInFlight.get(blobId);\n if (waitingBlobs !== undefined) {\n // For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.\n // This is safe because the server will keep the blob alive and the op containing the local ID to\n // storage ID is already in flight and any op containing this local ID will be sequenced after that.\n waitingBlobs.forEach((pendingLocalId) => {\n const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);\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 this.setRedirection(pendingLocalId, blobId);\n pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n this.deleteAndEmitsIfEmpty(pendingLocalId);\n }\n });\n this.opsInFlight.delete(blobId);\n }\n // For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.\n this.deleteAndEmitsIfEmpty(localId);\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.mc.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 for (const [localId, storageId] of this.redirectTable) {\n assert(!!storageId, 0x390 /* Must be attached to get GC data */);\n gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];\n }\n return gcData;\n }\n\n /**\n * This is called to update blobs whose routes are unused. The unused blobs are deleted.\n * @param unusedRoutes - The routes of the blob nodes that are unused.\n */\n public updateUnusedRoutes(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 this.redirectTable.delete(blobId);\n }\n }\n\n /**\n * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with\n * accessing deleted content without actually deleting content from summaries.\n * @param tombstonedRoutes - The routes of blob nodes that are tombstones.\n */\n public updateTombstonedRoutes(tombstonedRoutes: string[]) {\n const tombstonedBlobsSet: Set<string> = new Set();\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 tombstonedRoutes) {\n const pathParts = route.split(\"/\");\n assert(\n pathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n 0x50f /* Invalid blob node id in tombstoned routes. */,\n );\n tombstonedBlobsSet.add(pathParts[2]);\n }\n\n // Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.\n for (const blobId of this.tombstonedBlobs) {\n if (!tombstonedBlobsSet.has(blobId)) {\n this.tombstonedBlobs.delete(blobId);\n }\n }\n\n // Mark blobs that are now tombstoned by adding them to the tombstone list.\n for (const blobId of tombstonedBlobsSet) {\n this.tombstonedBlobs.add(blobId);\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.setRedirection(localId, storageId);\n // set identity (id -> id) entry\n this.setRedirection(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"]}
|
|
1
|
+
{"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IA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,MAAM,CACL,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EACtC,KAAK,CAAC,iEAAiE,CACvE,CAAC;QACF,KAAK,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,IAAI,KAAK,EAAE;YACzC,MAAM,CACL,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAC/B,KAAK,CAAC,yCAAyC,CAC/C,CAAC;YACF,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YACxC,gCAAgC;YAChC,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;SAC1C;IACF,CAAC;IAEM,eAAe;QACrB,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,YAAY,EAAE;YAC7C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;SAC5D;QACD,OAAO,KAAK,CAAC;IACd,CAAC;;AA9rBsB,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 {\n\tICreateBlobResponse,\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tcreateResponseError,\n\tgenerateHandleContextPath,\n\tresponseToException,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport {\n\tassert,\n\tbufferToString,\n\tDeferred,\n\tstringToBuffer,\n\tTypedEventEmitter,\n} from \"@fluidframework/common-utils\";\nimport {\n\tIContainerRuntime,\n\tIContainerRuntimeEvents,\n} from \"@fluidframework/container-runtime-definitions\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport {\n\tChildLogger,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { ContainerRuntime, TombstoneResponseHeaderKey } from \"./containerRuntime\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { throwOnTombstoneLoadKey } from \"./garbageCollectionConstants\";\nimport { sendGCUnexpectedUsageEvent } from \"./garbageCollectionHelpers\";\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\tprivate attached: boolean = false;\n\n\tpublic get IFluidHandle(): IFluidHandle {\n\t\treturn this;\n\t}\n\n\tpublic get isAttached(): boolean {\n\t\treturn this.attached;\n\t}\n\n\tpublic readonly absolutePath: string;\n\n\tconstructor(\n\t\tpublic readonly path: string,\n\t\tpublic readonly routeContext: IFluidHandleContext,\n\t\tpublic get: () => Promise<any>,\n\t) {\n\t\tthis.absolutePath = generateHandleContextPath(path, this.routeContext);\n\t}\n\n\tpublic attachGraph() {\n\t\tthis.attached = true;\n\t}\n\n\tpublic bind(handle: IFluidHandle) {\n\t\tthrow new Error(\"Cannot bind to blob handle\");\n\t}\n}\n\nclass CancellableThrottler {\n\tconstructor(private readonly throttler: IThrottler) {}\n\tprivate cancelP = new Deferred<void>();\n\n\tpublic async getDelay(): Promise<void> {\n\t\treturn Promise.race([\n\t\t\tthis.cancelP.promise,\n\t\t\tnew Promise<void>((resolve) => setTimeout(resolve, this.throttler.getDelay())),\n\t\t]);\n\t}\n\n\tpublic cancel() {\n\t\tthis.cancelP.resolve();\n\t\tthis.cancelP = new Deferred<void>();\n\t}\n}\n\n/**\n * Information from a snapshot needed to load BlobManager\n */\nexport interface IBlobManagerLoadInfo {\n\tids?: string[];\n\tredirectTable?: [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 = Pick<\n\tIContainerRuntime,\n\t\"attachState\" | \"connected\" | \"logger\" | \"clientDetails\"\n> &\n\tPick<ContainerRuntime, \"gcTombstoneEnforcementAllowed\"> &\n\tTypedEventEmitter<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\tOnlinePendingUpload,\n\tOnlinePendingOp,\n\tOfflinePendingUpload,\n\tOfflinePendingOp,\n}\n\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse & Partial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n\tblob: ArrayBufferLike;\n\tstatus: PendingBlobStatus;\n\tstorageId?: string;\n\thandleP: Deferred<IFluidHandle<ArrayBufferLike>>;\n\tuploadP: Promise<ICreateBlobResponse>;\n\tlocalUploadTime?: number;\n\tserverUploadTime?: number;\n\tminTTLInSeconds?: number;\n}\n\nexport interface IPendingBlobs {\n\t[id: string]: { blob: string };\n}\n\nexport interface IBlobManagerEvents {\n\t(event: \"noPendingBlobs\", listener: () => void);\n}\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\n\tpublic static readonly basePath = \"_blobs\";\n\tprivate static readonly redirectTableBlobName = \".redirectTable\";\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should\n\t * be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which\n\t * gives local IDs; the storage IDs are filled in at attach time.\n\t * Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client\n\t * that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.\n\t */\n\tprivate readonly redirectTable: Map<string, string | undefined>;\n\n\t/**\n\t * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.\n\t * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so\n\t * we must save it. This is true for both the online and offline flow.\n\t */\n\tprivate readonly pendingBlobs: Map<string, PendingBlob> = new Map();\n\n\t/**\n\t * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,\n\t * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's\n\t * because we know that the server will not delete the blob corresponding to that storage ID.\n\t */\n\tprivate readonly opsInFlight: Map<string, string[]> = new Map();\n\n\tprivate readonly retryThrottler = new CancellableThrottler(\n\t\tnew Throttler(\n\t\t\t60 * 1000, // 60 sec delay window\n\t\t\t30 * 1000, // 30 sec max delay\n\t\t\t// throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)\n\t\t\tformExponentialFn({ coefficient: 20, initialDelay: 0 }),\n\t\t),\n\t);\n\n\t/** If true, throw an error when a tombstone attachment blob is retrieved. */\n\tprivate readonly throwOnTombstoneLoad: boolean;\n\t/**\n\t * This stores IDs of tombstoned blobs.\n\t * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.\n\t */\n\tprivate readonly tombstonedBlobs: Set<string> = new Set();\n\n\tconstructor(\n\t\tprivate readonly routeContext: IFluidHandleContext,\n\t\tsnapshot: IBlobManagerLoadInfo,\n\t\tprivate readonly getStorage: () => IDocumentStorageService,\n\t\t/**\n\t\t * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is\n\t\t * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the\n\t\t * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to\n\t\t * include the storage ID in the summary when it sees the op.\n\t\t *\n\t\t * The op will also include a local ID to inform all clients of the relation to the storage ID, without\n\t\t * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced\n\t\t * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.\n\t\t */\n\t\tprivate readonly sendBlobAttachOp: (localId: string, storageId?: string) => void,\n\t\t// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly blobRequested: (blobPath: string) => void,\n\t\t// Called when a reference is added to a blob. For instance, when creating a localId / storageId to storageId\n\t\t// mapping in the redirect table.\n\t\t// Node path formats - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly addedBlobReference: (fromNodePath: string, toNodePath: string) => void,\n\t\t// Called to check if a blob has been deleted by GC.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly isBlobDeleted: (blobPath: string) => boolean,\n\t\tprivate readonly runtime: IBlobManagerRuntime,\n\t\tstashedBlobs: IPendingBlobs = {},\n\t\tprivate readonly getCurrentReferenceTimestampMs: () => number | undefined,\n\t) {\n\t\tsuper();\n\t\tthis.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, \"BlobManager\"));\n\t\t// Read the feature flag that tells whether to throw when a tombstone blob is requested.\n\t\tthis.throwOnTombstoneLoad =\n\t\t\tthis.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&\n\t\t\tthis.runtime.gcTombstoneEnforcementAllowed &&\n\t\t\tthis.runtime.clientDetails.type !== summarizerClientType;\n\n\t\tthis.runtime.on(\"disconnected\", () => this.onDisconnected());\n\t\tthis.redirectTable = this.load(snapshot);\n\n\t\t// Begin uploading stashed blobs from previous container instance\n\t\tObject.entries(stashedBlobs).forEach(([localId, entry]) => {\n\t\t\tconst blob = stringToBuffer(entry.blob, \"base64\");\n\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\tblob,\n\t\t\t\tstatus: PendingBlobStatus.OfflinePendingUpload,\n\t\t\t\thandleP: new Deferred(),\n\t\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate get pendingOfflineUploads() {\n\t\treturn Array.from(this.pendingBlobs.values()).filter(\n\t\t\t(e) => e.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t);\n\t}\n\n\tpublic get hasPendingOfflineUploads(): boolean {\n\t\treturn this.pendingOfflineUploads.length > 0;\n\t}\n\n\tpublic get hasPendingBlobs(): boolean {\n\t\treturn (\n\t\t\t(this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||\n\t\t\tthis.pendingBlobs.size > 0\n\t\t);\n\t}\n\n\t/**\n\t * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n\t */\n\tpublic async onConnected() {\n\t\tthis.retryThrottler.cancel();\n\t\tconst pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);\n\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"BlobUploadOnConnected\",\n\t\t\t\tcount: pendingUploads.length,\n\t\t\t},\n\t\t\tasync () => Promise.all(pendingUploads),\n\t\t\t{ start: true, end: true },\n\t\t);\n\t}\n\n\t/**\n\t * Transition online blobs waiting for BlobAttach op round-trip since we will not see the op until we are connected\n\t * again\n\t */\n\tprivate onDisconnected() {\n\t\tfor (const [localId, entry] of this.pendingBlobs) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t// This will submit another BlobAttach op for this blob. This is necessary because the one we sent\n\t\t\t\t// already didn't have the local ID.\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`\n\t * This path must match the path of the blob handle returned by the createBlob API because blobs are marked\n\t * referenced by storing these handles in a referenced DDS.\n\t */\n\tprivate getBlobGCNodePath(blobId: string) {\n\t\treturn `/${BlobManager.basePath}/${blobId}`;\n\t}\n\n\t/**\n\t * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is\n\t * detached or there are no (non-pending) attachment blobs in the document\n\t */\n\tprivate get storageIds(): Set<string> {\n\t\tconst ids = new Set<string | undefined>(this.redirectTable.values());\n\n\t\t// If we are detached, we will not have storage IDs, only undefined\n\t\tconst undefinedValueInTable = ids.delete(undefined);\n\n\t\t// For a detached container, entries are inserted into the redirect table with an undefined storage ID.\n\t\t// For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.\n\t\tassert(\n\t\t\t!undefinedValueInTable ||\n\t\t\t\t(this.runtime.attachState === AttachState.Detached && ids.size === 0),\n\t\t\t0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */,\n\t\t);\n\n\t\treturn ids as Set<string>;\n\t}\n\n\tpublic async getBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\t// Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,\n\t\t// failing the call.\n\t\tthis.verifyBlobValidity(blobId);\n\n\t\tconst pending = this.pendingBlobs.get(blobId);\n\t\tif (pending) {\n\t\t\treturn pending.blob;\n\t\t}\n\t\tlet storageId: string;\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tassert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);\n\n\t\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t\t// The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.\n\t\t\tstorageId = blobId;\n\t\t} else {\n\t\t\tconst attachedStorageId = this.redirectTable.get(blobId);\n\t\t\tassert(!!attachedStorageId, 0x11f /* \"requesting unknown blobs\" */);\n\t\t\tstorageId = attachedStorageId;\n\t\t}\n\n\t\t// Let runtime know that the corresponding GC node was requested.\n\t\tthis.blobRequested(this.getBlobGCNodePath(blobId));\n\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"AttachmentReadBlob\", id: storageId },\n\t\t\tasync () => {\n\t\t\t\treturn this.getStorage().readBlob(storageId);\n\t\t\t},\n\t\t\t{ end: true, cancel: \"error\" },\n\t\t);\n\t}\n\n\tprivate getBlobHandle(id: string): IFluidHandle<ArrayBufferLike> {\n\t\tassert(\n\t\t\tthis.redirectTable.has(id) || this.pendingBlobs.has(id),\n\t\t\t0x384 /* requesting handle for unknown blob */,\n\t\t);\n\t\treturn new BlobHandle(`${BlobManager.basePath}/${id}`, this.routeContext, async () =>\n\t\t\tthis.getBlob(id),\n\t\t);\n\t}\n\n\tprivate async createBlobDetached(\n\t\tblob: ArrayBufferLike,\n\t): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.\n\t\tconst response = await this.getStorage().createBlob(blob);\n\t\tthis.setRedirection(response.id, undefined);\n\t\treturn this.getBlobHandle(response.id);\n\t}\n\n\tpublic async createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn this.createBlobDetached(blob);\n\t\t}\n\t\tif (this.runtime.attachState === AttachState.Attaching) {\n\t\t\t// blob upload is not supported in \"Attaching\" state\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"CreateBlobWhileAttaching\" });\n\t\t\tawait new Promise<void>((resolve) => this.runtime.once(\"attached\", resolve));\n\t\t}\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Attached,\n\t\t\t0x385 /* For clarity and paranoid defense against adding future attachment states */,\n\t\t);\n\n\t\t// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to\n\t\t// storage ID mapping is created.\n\t\tconst localId = uuid();\n\t\tconst pendingEntry: PendingBlob = {\n\t\t\tblob,\n\t\t\tstatus: PendingBlobStatus.OnlinePendingUpload,\n\t\t\thandleP: new Deferred(),\n\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t};\n\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\treturn pendingEntry.handleP.promise;\n\t}\n\n\tprivate async uploadBlob(localId: string, blob: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"createBlob\" },\n\t\t\tasync () => this.getStorage().createBlob(blob),\n\t\t\t{ end: true, cancel: this.runtime.connected ? \"error\" : \"generic\" },\n\t\t).then(\n\t\t\t(response) => this.onUploadResolve(localId, response),\n\t\t\tasync (err) => this.onUploadReject(localId, err),\n\t\t);\n\t}\n\n\t/**\n\t * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added\n\t * which is required for GC.\n\t */\n\tprivate setRedirection(fromId: string, toId: string | undefined) {\n\t\tthis.redirectTable.set(fromId, toId);\n\t\t// Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in\n\t\t// detached mode. In this case, the entry will be updated when the blob is updated.\n\t\tif (toId !== undefined) {\n\t\t\tthis.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));\n\t\t}\n\t}\n\n\tprivate deleteAndEmitsIfEmpty(id: string) {\n\t\tif (this.pendingBlobs.has(id)) {\n\t\t\tthis.pendingBlobs.delete(id);\n\t\t\tif (!this.hasPendingBlobs) {\n\t\t\t\tthis.emit(\"noPendingBlobs\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onUploadResolve(localId: string, response: ICreateBlobResponseWithTTL) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(\n\t\t\tentry?.status === PendingBlobStatus.OnlinePendingUpload ||\n\t\t\t\tentry?.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t\t0x386 /* Must have pending blob entry for uploaded blob */,\n\t\t);\n\t\tentry.storageId = response.id;\n\t\tentry.localUploadTime = Date.now();\n\t\tentry.minTTLInSeconds = response.minTTLInSeconds;\n\t\tentry.serverUploadTime = this.getCurrentReferenceTimestampMs();\n\t\tif (this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\t// Send a blob attach op. This serves two purposes:\n\t\t\t\t// 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\n\t\t\t\t// until its storage ID is added to the next summary.\n\t\t\t\t// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the\n\t\t\t\t// blob from the server via the storage ID.\n\t\t\t\tthis.logTimeInfo(entry, \"sendBlobAttachResolveTTL\");\n\t\t\t\tthis.sendBlobAttachOp(localId, response.id);\n\t\t\t\tif (this.storageIds.has(response.id)) {\n\t\t\t\t\t// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is\n\t\t\t\t\t// an existing blob, we don't have to wait for the op to be ack'd since this step has already\n\t\t\t\t\t// happened before and so, the server won't delete it.\n\t\t\t\t\tthis.setRedirection(localId, response.id);\n\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\t\t\tthis.deleteAndEmitsIfEmpty(localId);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is already an op for this storage ID, append the local ID to the list. Once any op for\n\t\t\t\t\t// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n\t\t\t\t\t// blob alive in storage.\n\t\t\t\t\tthis.opsInFlight.set(\n\t\t\t\t\t\tresponse.id,\n\t\t\t\t\t\t(this.opsInFlight.get(response.id) ?? []).concat(localId),\n\t\t\t\t\t);\n\t\t\t\t\tentry.status = PendingBlobStatus.OnlinePendingOp;\n\t\t\t\t}\n\t\t\t} else if (entry.status === PendingBlobStatus.OfflinePendingUpload) {\n\t\t\t\t// We already submitted a BlobAttach op for this blob when it was transitioned to offline flow\n\t\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t\t}\n\t\t} else {\n\t\t\t// connected to storage but not ordering service?\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"BlobUploadSuccessWhileDisconnected\" });\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t}\n\t\treturn response;\n\t}\n\n\tprivate async onUploadReject(localId: string, error) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);\n\t\tif (!this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\t// we are probably not connected to storage but start another upload request in case we are\n\t\t\tentry.uploadP = this.retryThrottler\n\t\t\t\t.getDelay()\n\t\t\t\t.then(async () => this.uploadBlob(localId, entry.blob));\n\t\t\treturn entry.uploadP;\n\t\t} else {\n\t\t\tentry.handleP.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate transitionToOffline(localId: string) {\n\t\tassert(\n\t\t\t!this.runtime.connected,\n\t\t\t0x388 /* Must only transition to offline flow while runtime is disconnected */,\n\t\t);\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x389 /* No pending blob entry */);\n\t\tassert(\n\t\t\t[PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(\n\t\t\t\tentry.status,\n\t\t\t),\n\t\t\t0x38a /* Blob must be in online flow to transition to offline flow */,\n\t\t);\n\n\t\t/**\n\t\t * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.\n\t\t * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,\n\t\t * an invalid handle could be added to the document.\n\t\t * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n\t\t * is called on reconnection.\n\t\t */\n\t\tif (entry.status !== PendingBlobStatus.OnlinePendingOp) {\n\t\t\tthis.logTimeInfo(entry, \"sendBlobAttachTransitionOfflineTTL\");\n\t\t\tthis.sendBlobAttachOp(localId, entry.storageId);\n\t\t}\n\n\t\tentry.status =\n\t\t\tentry.status === PendingBlobStatus.OnlinePendingUpload\n\t\t\t\t? PendingBlobStatus.OfflinePendingUpload\n\t\t\t\t: PendingBlobStatus.OfflinePendingOp;\n\n\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t}\n\n\t/**\n\t * Resubmit a BlobAttach op. Used to add storage IDs to ops that were\n\t * submitted to runtime while disconnected.\n\t * @param metadata - op metadata containing storage and/or local IDs\n\t */\n\tpublic reSubmit(metadata: Record<string, unknown> | undefined) {\n\t\tassert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);\n\t\tconst { localId, blobId }: { localId?: string; blobId?: string } = metadata;\n\t\tassert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);\n\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\tif (pendingEntry) {\n\t\t\tthis.logTimeInfo(pendingEntry, \"sendBlobAttachResubmitTTL\");\n\t\t}\n\t\tif (!blobId) {\n\t\t\t// We submitted this op while offline. The blob should have been uploaded by now.\n\t\t\tassert(\n\t\t\t\tpendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n\t\t\t\t\t!!pendingEntry?.storageId,\n\t\t\t\t0x38d /* blob must be uploaded before resubmitting BlobAttach op */,\n\t\t\t);\n\t\t\treturn this.sendBlobAttachOp(localId, pendingEntry.storageId);\n\t\t}\n\t\treturn this.sendBlobAttachOp(localId, blobId);\n\t}\n\n\tprivate logTimeInfo(pendingEntry: PendingBlob, eventName: string) {\n\t\tlet timeLapseSinceLocalUpload: number = 0;\n\t\tlet timeLapseSinceServerUpload: number = 0;\n\t\tlet expiredUsingLocalTime;\n\t\tlet expiredUsingServerTime;\n\t\tif (pendingEntry.localUploadTime) {\n\t\t\ttimeLapseSinceLocalUpload = (Date.now() - pendingEntry.localUploadTime) / 1000;\n\t\t\texpiredUsingLocalTime =\n\t\t\t\t(pendingEntry.minTTLInSeconds ?? 0) - timeLapseSinceLocalUpload < 0 ? true : false;\n\t\t}\n\t\tif (pendingEntry.serverUploadTime) {\n\t\t\ttimeLapseSinceServerUpload = (Date.now() - pendingEntry.serverUploadTime) / 1000;\n\t\t\texpiredUsingServerTime =\n\t\t\t\t(pendingEntry.minTTLInSeconds ?? 0) - timeLapseSinceServerUpload < 0 ? true : false;\n\t\t}\n\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\teventName,\n\t\t\tentryStatus: pendingEntry.status,\n\t\t\ttimeLapseSinceLocalUpload,\n\t\t\ttimeLapseSinceServerUpload,\n\t\t\tminTTLInSeconds: pendingEntry.minTTLInSeconds,\n\t\t\texpiredUsingLocalTime,\n\t\t\texpiredUsingServerTime,\n\t\t});\n\t}\n\n\tpublic processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n\t\tconst localId = message.metadata?.localId;\n\t\tconst blobId = message.metadata?.blobId;\n\t\tassert(blobId !== undefined, 0x12a /* \"Missing blob id on metadata\" */);\n\n\t\t// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be\n\t\t// requested from the server.\n\t\t// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that\n\t\t// was sent when online.\n\t\tif (localId !== undefined) {\n\t\t\tthis.setRedirection(localId, blobId);\n\t\t}\n\t\t// set identity (id -> id) entry\n\t\tthis.setRedirection(blobId, blobId);\n\n\t\tif (local) {\n\t\t\tassert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);\n\t\t\tconst waitingBlobs = this.opsInFlight.get(blobId);\n\t\t\tif (waitingBlobs !== undefined) {\n\t\t\t\t// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.\n\t\t\t\t// This is safe because the server will keep the blob alive and the op containing the local ID to\n\t\t\t\t// storage ID is already in flight and any op containing this local ID will be sequenced after that.\n\t\t\t\twaitingBlobs.forEach((pendingLocalId) => {\n\t\t\t\t\tconst pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpendingBlobEntry !== undefined,\n\t\t\t\t\t\t0x38f /* local online BlobAttach op with no pending blob entry */,\n\t\t\t\t\t);\n\n\t\t\t\t\t// It's possible we transitioned to offline flow while waiting for this op.\n\t\t\t\t\tif (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t\t\tthis.setRedirection(pendingLocalId, blobId);\n\t\t\t\t\t\tpendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n\t\t\t\t\t\tthis.deleteAndEmitsIfEmpty(pendingLocalId);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tthis.opsInFlight.delete(blobId);\n\t\t\t}\n\t\t\t// For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.\n\t\t\tthis.deleteAndEmitsIfEmpty(localId);\n\t\t}\n\t}\n\n\t/**\n\t * Reads blobs needed to load BlobManager from storage.\n\t * @param blobsTree - Tree containing IDs of previously attached blobs. We\n\t * look for the IDs in the blob entries of the tree since the both the r11s\n\t * and SPO drivers replace the attachment types returned in snapshot() with blobs.\n\t */\n\tpublic static async load(\n\t\tblobsTree: ISnapshotTree | undefined,\n\t\ttryFetchBlob: (id: string) => Promise<[string, string][]>,\n\t): Promise<IBlobManagerLoadInfo> {\n\t\tif (!blobsTree) {\n\t\t\treturn {};\n\t\t}\n\t\tlet redirectTable;\n\t\tconst tableId = blobsTree.blobs[this.redirectTableBlobName];\n\t\tif (tableId) {\n\t\t\tredirectTable = await tryFetchBlob(tableId);\n\t\t}\n\t\tconst ids = Object.entries(blobsTree.blobs)\n\t\t\t.filter(([k, _]) => k !== this.redirectTableBlobName)\n\t\t\t.map(([_, v]) => v);\n\t\treturn { ids, redirectTable };\n\t}\n\n\t/**\n\t * Load a set of previously attached blob IDs and redirect table from a previous snapshot.\n\t */\n\tprivate load(snapshot: IBlobManagerLoadInfo): Map<string, string | undefined> {\n\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\teventName: \"AttachmentBlobsLoaded\",\n\t\t\tcount: snapshot.ids?.length ?? 0,\n\t\t\tredirectTable: snapshot.redirectTable?.length,\n\t\t});\n\t\tconst table = new Map<string, string | undefined>(snapshot.redirectTable);\n\t\tif (snapshot.ids) {\n\t\t\tconst detached = this.runtime.attachState === AttachState.Detached;\n\t\t\t// If we are detached, we don't have storage IDs yet, so set to undefined\n\t\t\t// Otherwise, set identity (id -> id) entries\n\t\t\tsnapshot.ids.forEach((entry) => table.set(entry, detached ? undefined : entry));\n\t\t}\n\t\treturn table;\n\t}\n\n\t/**\n\t * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be\n\t * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.\n\t * @param fullGC - true to bypass optimizations and force full generation of GC data. BlobManager doesn't care\n\t * about this for now because the data is a simple list of blob ids.\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\tconst gcData: IGarbageCollectionData = { gcNodes: {} };\n\t\tfor (const [localId, storageId] of this.redirectTable) {\n\t\t\tassert(!!storageId, 0x390 /* Must be attached to get GC data */);\n\t\t\tgcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];\n\t\t}\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are unused. The unused blobs are deleted.\n\t * @param unusedRoutes - The routes of the blob nodes that are unused.\n\t */\n\tpublic updateUnusedRoutes(unusedRoutes: string[]): void {\n\t\t// The routes or blob node paths are in the same format as returned in getGCData -\n\t\t// `/<BlobManager.basePath>/<blobId>`.\n\t\tfor (const route of unusedRoutes) {\n\t\t\tconst pathParts = route.split(\"/\");\n\t\t\tassert(\n\t\t\t\tpathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n\t\t\t\t0x2d5 /* \"Invalid blob node id in unused routes.\" */,\n\t\t\t);\n\t\t\tconst blobId = pathParts[2];\n\t\t\tthis.redirectTable.delete(blobId);\n\t\t}\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with\n\t * accessing deleted content without actually deleting content from summaries.\n\t * @param tombstonedRoutes - The routes of blob nodes that are tombstones.\n\t */\n\tpublic updateTombstonedRoutes(tombstonedRoutes: string[]) {\n\t\tconst tombstonedBlobsSet: Set<string> = new Set();\n\t\t// The routes or blob node paths are in the same format as returned in getGCData -\n\t\t// `/<BlobManager.basePath>/<blobId>`.\n\t\tfor (const route of tombstonedRoutes) {\n\t\t\tconst pathParts = route.split(\"/\");\n\t\t\tassert(\n\t\t\t\tpathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n\t\t\t\t0x50f /* Invalid blob node id in tombstoned routes. */,\n\t\t\t);\n\t\t\ttombstonedBlobsSet.add(pathParts[2]);\n\t\t}\n\n\t\t// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.\n\t\tfor (const blobId of this.tombstonedBlobs) {\n\t\t\tif (!tombstonedBlobsSet.has(blobId)) {\n\t\t\t\tthis.tombstonedBlobs.delete(blobId);\n\t\t\t}\n\t\t}\n\n\t\t// Mark blobs that are now tombstoned by adding them to the tombstone list.\n\t\tfor (const blobId of tombstonedBlobsSet) {\n\t\t\tthis.tombstonedBlobs.add(blobId);\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,\n\t * log an error and throw if necessary.\n\t */\n\tprivate verifyBlobValidity(blobId: string) {\n\t\t/**\n\t\t * A blob can be in one of the following states:\n\t\t * 1. \"deleted\" - It has been deleted by garbage collection sweep phase.\n\t\t * 2. \"tombstoned\" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.\n\t\t * 3. \"valid\" - It has not been deleted or tombstoned.\n\t\t */\n\t\tlet state: \"valid\" | \"tombstoned\" | \"deleted\" = \"valid\";\n\t\tif (this.isBlobDeleted(this.getBlobGCNodePath(blobId))) {\n\t\t\tstate = \"deleted\";\n\t\t} else if (this.tombstonedBlobs.has(blobId)) {\n\t\t\tstate = \"tombstoned\";\n\t\t}\n\n\t\tif (state === \"valid\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt\n\t\t// to load the blob.\n\t\tconst shouldFail = state === \"deleted\" || this.throwOnTombstoneLoad;\n\t\tconst request = { url: blobId };\n\t\tconst error = responseToException(\n\t\t\tcreateResponseError(\n\t\t\t\t404,\n\t\t\t\t\"Blob was deleted\",\n\t\t\t\trequest,\n\t\t\t\tstate === \"tombstoned\" ? { [TombstoneResponseHeaderKey]: true } : undefined,\n\t\t\t),\n\t\t\trequest,\n\t\t);\n\t\tsendGCUnexpectedUsageEvent(\n\t\t\tthis.mc,\n\t\t\t{\n\t\t\t\teventName:\n\t\t\t\t\tstate === \"tombstoned\"\n\t\t\t\t\t\t? \"GC_Tombstone_Blob_Requested\"\n\t\t\t\t\t\t: \"GC_Deleted_Blob_Requested\",\n\t\t\t\tcategory: shouldFail ? \"error\" : \"generic\",\n\t\t\t\tgcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,\n\t\t\t},\n\t\t\t[BlobManager.basePath],\n\t\t\terror,\n\t\t);\n\t\tif (shouldFail) {\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n\t\t// if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached\n\t\tconst blobIds =\n\t\t\tthis.storageIds.size > 0\n\t\t\t\t? Array.from(this.storageIds)\n\t\t\t\t: Array.from(this.redirectTable.keys());\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tblobIds.forEach((blobId) => {\n\t\t\tbuilder.addAttachment(blobId);\n\t\t});\n\n\t\t// Any non-identity entries in the table need to be saved in the summary\n\t\tif (this.redirectTable.size > blobIds.length) {\n\t\t\tbuilder.addBlob(\n\t\t\t\tBlobManager.redirectTableBlobName,\n\t\t\t\t// filter out identity entries\n\t\t\t\tJSON.stringify(\n\t\t\t\t\tArray.from(this.redirectTable.entries()).filter(\n\t\t\t\t\t\t([localId, storageId]) => localId !== storageId,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tpublic setRedirectTable(table: Map<string, string>) {\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Detached,\n\t\t\t0x252 /* \"redirect table can only be set in detached container\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.redirectTable.size === table.size,\n\t\t\t0x391 /* Redirect table size must match BlobManager's local ID count */,\n\t\t);\n\t\tfor (const [localId, storageId] of table) {\n\t\t\tassert(\n\t\t\t\tthis.redirectTable.has(localId),\n\t\t\t\t0x254 /* \"unrecognized id in redirect table\" */,\n\t\t\t);\n\t\t\tthis.setRedirection(localId, storageId);\n\t\t\t// set identity (id -> id) entry\n\t\t\tthis.setRedirection(storageId, storageId);\n\t\t}\n\t}\n\n\tpublic getPendingBlobs(): IPendingBlobs {\n\t\tconst blobs = {};\n\t\tfor (const [key, entry] of this.pendingBlobs) {\n\t\t\tblobs[key] = { blob: bufferToString(entry.blob, \"base64\") };\n\t\t}\n\t\treturn blobs;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connectionTelemetry.d.ts","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"connectionTelemetry.d.ts","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EACN,gBAAgB,EAChB,yBAAyB,EAEzB,MAAM,sCAAsC,CAAC;AAG9C;;GAEG;AACH,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAgRrC,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,4BAA4B,EAAE,MAAM,GAAG,SAAS,CAAC;CACjD;AAED,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,MAAM,EAAE,gBAAgB,QAGxB"}
|
|
@@ -56,8 +56,9 @@ class OpPerfTelemetry {
|
|
|
56
56
|
this.opProcessingTimes.outboundPushEventTime = Date.now();
|
|
57
57
|
assert(this.opPerfData.durationOutboundBatching === undefined, 0x2ca /* "durationOutboundBatching should be undefined" */);
|
|
58
58
|
assert(this.opProcessingTimes.submitOpEventTime !== undefined, 0x2cb /* "submitOpEventTime should be undefined" */);
|
|
59
|
-
this.opPerfData.durationOutboundBatching =
|
|
60
|
-
|
|
59
|
+
this.opPerfData.durationOutboundBatching =
|
|
60
|
+
this.opProcessingTimes.outboundPushEventTime -
|
|
61
|
+
this.opProcessingTimes.submitOpEventTime;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
});
|
|
@@ -67,8 +68,9 @@ class OpPerfTelemetry {
|
|
|
67
68
|
this.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber &&
|
|
68
69
|
this.opProcessingTimes.outboundPushEventTime !== undefined) {
|
|
69
70
|
this.opProcessingTimes.inboundPushEventTime = Date.now();
|
|
70
|
-
this.opPerfData.durationNetwork =
|
|
71
|
-
|
|
71
|
+
this.opPerfData.durationNetwork =
|
|
72
|
+
this.opProcessingTimes.inboundPushEventTime -
|
|
73
|
+
this.opProcessingTimes.outboundPushEventTime;
|
|
72
74
|
this.opProcessingTimes.outboundPushEventTime = undefined;
|
|
73
75
|
this.opPerfData.lengthInboundQueue = this.deltaManager.inbound.length;
|
|
74
76
|
}
|
|
@@ -96,9 +98,9 @@ class OpPerfTelemetry {
|
|
|
96
98
|
duration: performance.now() - this.connectionStartTime,
|
|
97
99
|
ops: this.gap,
|
|
98
100
|
// track time to connect only for first connection.
|
|
99
|
-
timeToConnect: this.firstConnection
|
|
100
|
-
TelemetryLogger.formatTick(this.connectionStartTime - this.bootTime)
|
|
101
|
-
undefined,
|
|
101
|
+
timeToConnect: this.firstConnection
|
|
102
|
+
? TelemetryLogger.formatTick(this.connectionStartTime - this.bootTime)
|
|
103
|
+
: undefined,
|
|
102
104
|
firstConnection: this.firstConnection,
|
|
103
105
|
});
|
|
104
106
|
}
|
|
@@ -149,8 +151,8 @@ class OpPerfTelemetry {
|
|
|
149
151
|
assert(this.opProcessingTimes.submitOpEventTime !== undefined, 0x120 /* "Undefined latency statistics (op send time)" */);
|
|
150
152
|
const currentTime = Date.now();
|
|
151
153
|
if (this.opProcessingTimes.inboundPushEventTime !== undefined) {
|
|
152
|
-
this.opPerfData.durationInboundToProcessing =
|
|
153
|
-
- this.opProcessingTimes.inboundPushEventTime;
|
|
154
|
+
this.opPerfData.durationInboundToProcessing =
|
|
155
|
+
currentTime - this.opProcessingTimes.inboundPushEventTime;
|
|
154
156
|
}
|
|
155
157
|
const duration = currentTime - this.opProcessingTimes.submitOpEventTime;
|
|
156
158
|
// One of the core expectations for Fluid service is to be fast.
|