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