@fluidframework/container-runtime 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.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 -8
- package/dist/batchTracker.d.ts +1 -2
- package/dist/batchTracker.d.ts.map +1 -1
- package/dist/batchTracker.js.map +1 -1
- package/dist/blobManager.d.ts +45 -34
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +135 -102
- package/dist/blobManager.js.map +1 -1
- package/dist/containerRuntime.d.ts +54 -8
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +143 -72
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreContext.d.ts +1 -1
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +6 -8
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStores.d.ts +12 -9
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +41 -35
- package/dist/dataStores.js.map +1 -1
- package/dist/garbageCollection.d.ts +41 -20
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +205 -150
- 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/garbageCollectionTombstoneUtils.d.ts +14 -0
- package/dist/garbageCollectionTombstoneUtils.d.ts.map +1 -0
- package/dist/garbageCollectionTombstoneUtils.js +23 -0
- package/dist/garbageCollectionTombstoneUtils.js.map +1 -0
- package/dist/index.d.ts +1 -2
- 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 +35 -1
- 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 +30 -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 +114 -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 +24 -14
- 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/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/runningSummarizer.d.ts.map +1 -1
- package/dist/runningSummarizer.js +0 -1
- 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 +9 -20
- package/dist/scheduleManager.js.map +1 -1
- package/dist/summarizer.d.ts +0 -1
- package/dist/summarizer.d.ts.map +1 -1
- package/dist/summarizer.js +2 -1
- package/dist/summarizer.js.map +1 -1
- package/dist/summarizerTypes.d.ts +1 -0
- package/dist/summarizerTypes.d.ts.map +1 -1
- package/dist/summarizerTypes.js.map +1 -1
- package/dist/summaryFormat.d.ts.map +1 -1
- package/dist/summaryFormat.js +1 -2
- package/dist/summaryFormat.js.map +1 -1
- package/lib/batchTracker.d.ts +1 -2
- package/lib/batchTracker.d.ts.map +1 -1
- package/lib/batchTracker.js.map +1 -1
- package/lib/blobManager.d.ts +45 -34
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +137 -104
- package/lib/blobManager.js.map +1 -1
- package/lib/containerRuntime.d.ts +54 -8
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +140 -69
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreContext.d.ts +1 -1
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +7 -9
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStores.d.ts +12 -9
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +44 -38
- package/lib/dataStores.js.map +1 -1
- package/lib/garbageCollection.d.ts +41 -20
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +201 -146
- 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/garbageCollectionTombstoneUtils.d.ts +14 -0
- package/lib/garbageCollectionTombstoneUtils.d.ts.map +1 -0
- package/lib/garbageCollectionTombstoneUtils.js +19 -0
- package/lib/garbageCollectionTombstoneUtils.js.map +1 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -2
- 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 +35 -1
- 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 +30 -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 +112 -4
- 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 +24 -14
- 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/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/runningSummarizer.d.ts.map +1 -1
- package/lib/runningSummarizer.js +0 -1
- 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 +9 -20
- package/lib/scheduleManager.js.map +1 -1
- package/lib/summarizer.d.ts +0 -1
- package/lib/summarizer.d.ts.map +1 -1
- package/lib/summarizer.js +2 -1
- package/lib/summarizer.js.map +1 -1
- package/lib/summarizerTypes.d.ts +1 -0
- package/lib/summarizerTypes.d.ts.map +1 -1
- package/lib/summarizerTypes.js.map +1 -1
- package/lib/summaryFormat.d.ts.map +1 -1
- package/lib/summaryFormat.js +1 -2
- package/lib/summaryFormat.js.map +1 -1
- package/package.json +20 -19
- package/src/batchTracker.ts +1 -1
- package/src/blobManager.ts +159 -111
- package/src/containerRuntime.ts +202 -73
- package/src/dataStoreContext.ts +15 -16
- package/src/dataStores.ts +61 -45
- package/src/garbageCollection.ts +258 -183
- package/src/garbageCollectionConstants.ts +10 -7
- package/src/garbageCollectionTombstoneUtils.ts +28 -0
- package/src/index.ts +2 -5
- package/src/opLifecycle/batchManager.ts +59 -1
- package/src/opLifecycle/definitions.ts +27 -1
- package/src/opLifecycle/index.ts +2 -1
- package/src/opLifecycle/opCompressor.ts +29 -12
- package/src/opLifecycle/opDecompressor.ts +39 -18
- package/src/opLifecycle/opSplitter.ts +141 -7
- package/src/opLifecycle/outbox.ts +32 -16
- package/src/opLifecycle/remoteMessageProcessor.ts +19 -3
- package/src/packageVersion.ts +1 -1
- package/src/runningSummarizer.ts +0 -1
- package/src/scheduleManager.ts +19 -30
- package/src/summarizer.ts +1 -1
- package/src/summarizerTypes.ts +1 -0
- package/src/summaryFormat.ts +1 -2
package/dist/blobManager.js
CHANGED
|
@@ -13,6 +13,7 @@ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
|
13
13
|
const throttler_1 = require("./throttler");
|
|
14
14
|
const summarizerClientElection_1 = require("./summarizerClientElection");
|
|
15
15
|
const garbageCollectionConstants_1 = require("./garbageCollectionConstants");
|
|
16
|
+
const garbageCollectionTombstoneUtils_1 = require("./garbageCollectionTombstoneUtils");
|
|
16
17
|
/**
|
|
17
18
|
* This class represents blob (long string)
|
|
18
19
|
* This object is used only when creating (writing) new blob and serialization purposes.
|
|
@@ -65,26 +66,28 @@ var PendingBlobStatus;
|
|
|
65
66
|
PendingBlobStatus[PendingBlobStatus["OfflinePendingUpload"] = 2] = "OfflinePendingUpload";
|
|
66
67
|
PendingBlobStatus[PendingBlobStatus["OfflinePendingOp"] = 3] = "OfflinePendingOp";
|
|
67
68
|
})(PendingBlobStatus || (PendingBlobStatus = {}));
|
|
68
|
-
class BlobManager {
|
|
69
|
+
class BlobManager extends common_utils_1.TypedEventEmitter {
|
|
69
70
|
constructor(routeContext, snapshot, getStorage,
|
|
70
71
|
/**
|
|
71
|
-
* Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
72
|
+
* Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
|
|
73
|
+
* deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
|
|
74
|
+
* the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
|
|
75
|
+
* include the storage ID in the summary when it sees the op.
|
|
75
76
|
*
|
|
76
|
-
* The op
|
|
77
|
-
*
|
|
78
|
-
*
|
|
77
|
+
* The op will also include a local ID to inform all clients of the relation to the storage ID, without
|
|
78
|
+
* knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
|
|
79
|
+
* before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
|
|
79
80
|
*/
|
|
80
81
|
sendBlobAttachOp,
|
|
81
82
|
// To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's
|
|
82
83
|
// of the format `/<BlobManager.basePath>/<blobId>`.
|
|
83
|
-
|
|
84
|
+
blobRequested, addedBlobReference, runtime, stashedBlobs = {}) {
|
|
85
|
+
super();
|
|
84
86
|
this.routeContext = routeContext;
|
|
85
87
|
this.getStorage = getStorage;
|
|
86
88
|
this.sendBlobAttachOp = sendBlobAttachOp;
|
|
87
|
-
this.
|
|
89
|
+
this.blobRequested = blobRequested;
|
|
90
|
+
this.addedBlobReference = addedBlobReference;
|
|
88
91
|
this.runtime = runtime;
|
|
89
92
|
/**
|
|
90
93
|
* Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.
|
|
@@ -93,8 +96,9 @@ class BlobManager {
|
|
|
93
96
|
*/
|
|
94
97
|
this.pendingBlobs = new Map();
|
|
95
98
|
/**
|
|
96
|
-
* Track ops in flight for online flow.
|
|
97
|
-
*
|
|
99
|
+
* Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
|
|
100
|
+
* we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
|
|
101
|
+
* because we know that the server will not delete the blob corresponding to that storage ID.
|
|
98
102
|
*/
|
|
99
103
|
this.opsInFlight = new Map();
|
|
100
104
|
this.retryThrottler = new CancellableThrottler(new throttler_1.Throttler(60 * 1000, // 60 sec delay window
|
|
@@ -102,14 +106,14 @@ class BlobManager {
|
|
|
102
106
|
// throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)
|
|
103
107
|
(0, throttler_1.formExponentialFn)({ coefficient: 20, initialDelay: 0 })));
|
|
104
108
|
/**
|
|
105
|
-
* This stores
|
|
109
|
+
* This stores IDs of tombstoned blobs.
|
|
106
110
|
* Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
|
|
107
111
|
*/
|
|
108
112
|
this.tombstonedBlobs = new Set();
|
|
109
113
|
this.mc = (0, telemetry_utils_1.loggerToMonitoringContext)(telemetry_utils_1.ChildLogger.create(this.runtime.logger, "BlobManager"));
|
|
110
114
|
// Read the feature flag that tells whether to throw when a tombstone blob is requested.
|
|
111
|
-
this.
|
|
112
|
-
this.mc.config.getBoolean(garbageCollectionConstants_1.
|
|
115
|
+
this.throwOnTombstoneLoad =
|
|
116
|
+
this.mc.config.getBoolean(garbageCollectionConstants_1.throwOnTombstoneLoadKey) === true &&
|
|
113
117
|
this.runtime.clientDetails.type !== summarizerClientElection_1.summarizerClientType;
|
|
114
118
|
this.runtime.on("disconnected", () => this.onDisconnected());
|
|
115
119
|
this.redirectTable = this.load(snapshot);
|
|
@@ -131,6 +135,10 @@ class BlobManager {
|
|
|
131
135
|
get hasPendingOfflineUploads() {
|
|
132
136
|
return this.pendingOfflineUploads.length > 0;
|
|
133
137
|
}
|
|
138
|
+
get hasPendingBlobs() {
|
|
139
|
+
return (this.runtime.attachState !== container_definitions_1.AttachState.Attached && this.redirectTable.size > 0)
|
|
140
|
+
|| this.pendingBlobs.size > 0;
|
|
141
|
+
}
|
|
134
142
|
/**
|
|
135
143
|
* Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
|
|
136
144
|
*/
|
|
@@ -179,12 +187,13 @@ class BlobManager {
|
|
|
179
187
|
async getBlob(blobId) {
|
|
180
188
|
const request = { url: blobId };
|
|
181
189
|
if (this.tombstonedBlobs.has(blobId)) {
|
|
182
|
-
const error = (0, runtime_utils_1.responseToException)((0, runtime_utils_1.createResponseError)(404, "Blob
|
|
183
|
-
this.mc
|
|
190
|
+
const error = (0, runtime_utils_1.responseToException)((0, runtime_utils_1.createResponseError)(404, "Blob was deleted", request), request);
|
|
191
|
+
(0, garbageCollectionTombstoneUtils_1.sendGCTombstoneEvent)(this.mc, {
|
|
184
192
|
eventName: "GC_Tombstone_Blob_Requested",
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
category: this.throwOnTombstoneLoad ? "error" : "generic",
|
|
194
|
+
isSummarizerClient: this.runtime.clientDetails.type === summarizerClientElection_1.summarizerClientType,
|
|
195
|
+
}, [BlobManager.basePath], error);
|
|
196
|
+
if (this.throwOnTombstoneLoad) {
|
|
188
197
|
throw error;
|
|
189
198
|
}
|
|
190
199
|
}
|
|
@@ -200,11 +209,12 @@ class BlobManager {
|
|
|
200
209
|
storageId = blobId;
|
|
201
210
|
}
|
|
202
211
|
else {
|
|
203
|
-
|
|
204
|
-
(0, common_utils_1.assert)(!!
|
|
212
|
+
const attachedStorageId = this.redirectTable.get(blobId);
|
|
213
|
+
(0, common_utils_1.assert)(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
|
|
214
|
+
storageId = attachedStorageId;
|
|
205
215
|
}
|
|
206
|
-
//
|
|
207
|
-
this.
|
|
216
|
+
// Let runtime know that the corresponding GC node was requested.
|
|
217
|
+
this.blobRequested(this.getBlobGCNodePath(blobId));
|
|
208
218
|
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "AttachmentReadBlob", id: storageId }, async () => {
|
|
209
219
|
return this.getStorage().readBlob(storageId);
|
|
210
220
|
}, { end: true, cancel: "error" });
|
|
@@ -217,7 +227,7 @@ class BlobManager {
|
|
|
217
227
|
// Blobs created while the container is detached are stored in IDetachedBlobStorage.
|
|
218
228
|
// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
|
|
219
229
|
const response = await this.getStorage().createBlob(blob);
|
|
220
|
-
this.
|
|
230
|
+
this.setRedirection(response.id, undefined);
|
|
221
231
|
return this.getBlobHandle(response.id);
|
|
222
232
|
}
|
|
223
233
|
async createBlob(blob) {
|
|
@@ -230,8 +240,8 @@ class BlobManager {
|
|
|
230
240
|
await new Promise((resolve) => this.runtime.once("attached", resolve));
|
|
231
241
|
}
|
|
232
242
|
(0, common_utils_1.assert)(this.runtime.attachState === container_definitions_1.AttachState.Attached, 0x385 /* For clarity and paranoid defense against adding future attachment states */);
|
|
233
|
-
// Create a local ID for
|
|
234
|
-
//
|
|
243
|
+
// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
|
|
244
|
+
// storage ID mapping is created.
|
|
235
245
|
const localId = (0, uuid_1.v4)();
|
|
236
246
|
const pendingEntry = {
|
|
237
247
|
blob,
|
|
@@ -245,6 +255,26 @@ class BlobManager {
|
|
|
245
255
|
async uploadBlob(localId, blob) {
|
|
246
256
|
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.mc.logger, { eventName: "createBlob" }, async () => this.getStorage().createBlob(blob), { end: true, cancel: this.runtime.connected ? "error" : "generic" }).then((response) => this.onUploadResolve(localId, response), async (err) => this.onUploadReject(localId, err));
|
|
247
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
|
|
260
|
+
* which is required for GC.
|
|
261
|
+
*/
|
|
262
|
+
setRedirection(fromId, toId) {
|
|
263
|
+
this.redirectTable.set(fromId, toId);
|
|
264
|
+
// Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in
|
|
265
|
+
// detached mode. In this case, the entry will be updated when the blob is updated.
|
|
266
|
+
if (toId !== undefined) {
|
|
267
|
+
this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
deleteAndEmitsIfEmpty(id) {
|
|
271
|
+
if (this.pendingBlobs.has(id)) {
|
|
272
|
+
this.pendingBlobs.delete(id);
|
|
273
|
+
if (!this.hasPendingBlobs) {
|
|
274
|
+
this.emit("noPendingBlobs");
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
248
278
|
onUploadResolve(localId, response) {
|
|
249
279
|
var _a;
|
|
250
280
|
const entry = this.pendingBlobs.get(localId);
|
|
@@ -253,17 +283,24 @@ class BlobManager {
|
|
|
253
283
|
entry.storageId = response.id;
|
|
254
284
|
if (this.runtime.connected) {
|
|
255
285
|
if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
|
|
286
|
+
// Send a blob attach op. This serves two purposes:
|
|
287
|
+
// 1. If its a new blob, i.e., it isn't de-duped, the server will keep the blob alive if it sees this op
|
|
288
|
+
// until its storage ID is added to the next summary.
|
|
289
|
+
// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
|
|
290
|
+
// blob from the server via the storage ID.
|
|
291
|
+
this.sendBlobAttachOp(localId, response.id);
|
|
256
292
|
if (this.storageIds.has(response.id)) {
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
|
|
260
|
-
this.
|
|
293
|
+
// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
|
|
294
|
+
// an existing blob, we don't have to wait for the op to be ack'd since this step has already
|
|
295
|
+
// happened before and so, the server won't delete it.
|
|
296
|
+
this.setRedirection(localId, response.id);
|
|
297
|
+
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
298
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
261
299
|
}
|
|
262
300
|
else {
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
301
|
+
// If there is already an op for this storage ID, append the local ID to the list. Once any op for
|
|
302
|
+
// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
|
|
303
|
+
// blob alive in storage.
|
|
267
304
|
this.opsInFlight.set(response.id, ((_a = this.opsInFlight.get(response.id)) !== null && _a !== void 0 ? _a : []).concat(localId));
|
|
268
305
|
entry.status = PendingBlobStatus.OnlinePendingOp;
|
|
269
306
|
}
|
|
@@ -304,15 +341,19 @@ class BlobManager {
|
|
|
304
341
|
const entry = this.pendingBlobs.get(localId);
|
|
305
342
|
(0, common_utils_1.assert)(!!entry, 0x389 /* No pending blob entry */);
|
|
306
343
|
(0, common_utils_1.assert)([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status), 0x38a /* Blob must be in online flow to transition to offline flow */);
|
|
344
|
+
/**
|
|
345
|
+
* If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
|
|
346
|
+
* This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
|
|
347
|
+
* an invalid handle could be added to the document.
|
|
348
|
+
* storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
|
|
349
|
+
* is called on reconnection.
|
|
350
|
+
*/
|
|
351
|
+
if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
|
|
352
|
+
this.sendBlobAttachOp(localId, entry.storageId);
|
|
353
|
+
}
|
|
307
354
|
entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
|
|
308
355
|
? PendingBlobStatus.OfflinePendingUpload
|
|
309
356
|
: PendingBlobStatus.OfflinePendingOp;
|
|
310
|
-
// Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the
|
|
311
|
-
// BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be
|
|
312
|
-
// added to the document if the ops are not all successfully submitted upon reconnection.
|
|
313
|
-
// storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
|
|
314
|
-
// is called
|
|
315
|
-
this.sendBlobAttachOp(entry.storageId, localId);
|
|
316
357
|
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
317
358
|
}
|
|
318
359
|
/**
|
|
@@ -322,45 +363,52 @@ class BlobManager {
|
|
|
322
363
|
*/
|
|
323
364
|
reSubmit(metadata) {
|
|
324
365
|
(0, common_utils_1.assert)(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
|
|
325
|
-
const {
|
|
366
|
+
const { localId, blobId } = metadata;
|
|
367
|
+
(0, common_utils_1.assert)(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
|
|
326
368
|
if (!blobId) {
|
|
327
|
-
(0, common_utils_1.assert)(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
|
|
328
369
|
// We submitted this op while offline. The blob should have been uploaded by now.
|
|
329
370
|
const pendingEntry = this.pendingBlobs.get(localId);
|
|
330
371
|
(0, common_utils_1.assert)((pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.status) === PendingBlobStatus.OfflinePendingOp &&
|
|
331
372
|
!!(pendingEntry === null || pendingEntry === void 0 ? void 0 : pendingEntry.storageId), 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
|
|
332
|
-
return this.sendBlobAttachOp(pendingEntry.storageId
|
|
373
|
+
return this.sendBlobAttachOp(localId, pendingEntry.storageId);
|
|
333
374
|
}
|
|
334
|
-
return this.sendBlobAttachOp(
|
|
375
|
+
return this.sendBlobAttachOp(localId, blobId);
|
|
335
376
|
}
|
|
336
377
|
processBlobAttachOp(message, local) {
|
|
337
378
|
var _a, _b;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
379
|
+
const localId = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.localId;
|
|
380
|
+
const blobId = (_b = message.metadata) === null || _b === void 0 ? void 0 : _b.blobId;
|
|
381
|
+
(0, common_utils_1.assert)(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
|
|
382
|
+
// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
|
|
383
|
+
// requested from the server.
|
|
384
|
+
// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
|
|
385
|
+
// was sent when online.
|
|
386
|
+
if (localId !== undefined) {
|
|
387
|
+
this.setRedirection(localId, blobId);
|
|
341
388
|
}
|
|
342
389
|
// set identity (id -> id) entry
|
|
343
|
-
this.
|
|
390
|
+
this.setRedirection(blobId, blobId);
|
|
344
391
|
if (local) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
392
|
+
(0, common_utils_1.assert)(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
|
|
393
|
+
const waitingBlobs = this.opsInFlight.get(blobId);
|
|
394
|
+
if (waitingBlobs !== undefined) {
|
|
395
|
+
// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
|
|
396
|
+
// This is safe because the server will keep the blob alive and the op containing the local ID to
|
|
397
|
+
// storage ID is already in flight and any op containing this local ID will be sequenced after that.
|
|
398
|
+
waitingBlobs.forEach((pendingLocalId) => {
|
|
399
|
+
const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
|
|
351
400
|
(0, common_utils_1.assert)(pendingBlobEntry !== undefined, 0x38f);
|
|
352
401
|
// It's possible we transitioned to offline flow while waiting for this op.
|
|
353
402
|
if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
|
|
354
|
-
|
|
355
|
-
|
|
403
|
+
this.setRedirection(pendingLocalId, blobId);
|
|
404
|
+
pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
|
|
405
|
+
this.deleteAndEmitsIfEmpty(pendingLocalId);
|
|
356
406
|
}
|
|
357
407
|
});
|
|
408
|
+
this.opsInFlight.delete(blobId);
|
|
358
409
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
(0, common_utils_1.assert)(((_b = this.pendingBlobs.get(message.metadata.localId)) === null || _b === void 0 ? void 0 : _b.status) === PendingBlobStatus.OfflinePendingOp, 0x1f8 /* "local BlobAttach op with no pending blob" */);
|
|
362
|
-
this.pendingBlobs.delete(message.metadata.localId);
|
|
363
|
-
}
|
|
410
|
+
// For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
|
|
411
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
364
412
|
}
|
|
365
413
|
}
|
|
366
414
|
/**
|
|
@@ -409,65 +457,50 @@ class BlobManager {
|
|
|
409
457
|
*/
|
|
410
458
|
getGCData(fullGC = false) {
|
|
411
459
|
const gcData = { gcNodes: {} };
|
|
412
|
-
/**
|
|
413
|
-
* The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned
|
|
414
|
-
* by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.
|
|
415
|
-
*/
|
|
416
|
-
this.storageIds.forEach((blobId) => {
|
|
417
|
-
gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];
|
|
418
|
-
});
|
|
419
|
-
// For some blobs, the handle returned on creation is based off of the localId. So, these
|
|
420
|
-
// nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node
|
|
421
|
-
// must also be marked referenced. So, we add a route from the localId node to the storageId node.
|
|
422
|
-
// Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
|
|
423
|
-
// a blob may be referenced via its storageId handle.
|
|
424
460
|
for (const [localId, storageId] of this.redirectTable) {
|
|
425
461
|
(0, common_utils_1.assert)(!!storageId, 0x390 /* Must be attached to get GC data */);
|
|
426
|
-
// Add node for the localId and add a route to the storageId node. The storageId node will have been
|
|
427
|
-
// added above when adding nodes for this.blobIds.
|
|
428
462
|
gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
|
|
429
463
|
}
|
|
430
464
|
return gcData;
|
|
431
465
|
}
|
|
432
466
|
/**
|
|
433
|
-
* This is called to update blobs whose routes are
|
|
434
|
-
* @param
|
|
467
|
+
* This is called to update blobs whose routes are unused. The unused blobs are deleted.
|
|
468
|
+
* @param unusedRoutes - The routes of the blob nodes that are unused.
|
|
435
469
|
*/
|
|
436
|
-
|
|
470
|
+
updateUnusedRoutes(unusedRoutes) {
|
|
437
471
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
438
472
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
439
|
-
for (const route of
|
|
473
|
+
for (const route of unusedRoutes) {
|
|
440
474
|
const pathParts = route.split("/");
|
|
441
|
-
(0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
475
|
+
(0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x2d5 /* "Invalid blob node id in unused routes." */);
|
|
442
476
|
const blobId = pathParts[2];
|
|
443
|
-
|
|
444
|
-
this.tombstonedBlobs.delete(blobId);
|
|
477
|
+
this.redirectTable.delete(blobId);
|
|
445
478
|
}
|
|
446
479
|
}
|
|
447
480
|
/**
|
|
448
|
-
* This is called to update blobs whose routes are
|
|
449
|
-
*
|
|
450
|
-
* @param
|
|
451
|
-
* @param tombstone - if true, the objects corresponding to unused routes are marked tombstones. Otherwise, they
|
|
452
|
-
* are deleted.
|
|
481
|
+
* This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
|
|
482
|
+
* accessing deleted content without actually deleting content from summaries.
|
|
483
|
+
* @param tombstonedRoutes - The routes of blob nodes that are tombstones.
|
|
453
484
|
*/
|
|
454
|
-
|
|
485
|
+
updateTombstonedRoutes(tombstonedRoutes) {
|
|
486
|
+
const tombstonedBlobsSet = new Set();
|
|
455
487
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
456
488
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
457
|
-
for (const route of
|
|
489
|
+
for (const route of tombstonedRoutes) {
|
|
458
490
|
const pathParts = route.split("/");
|
|
459
|
-
(0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
// The unused blobId could be a localId. If so, remove it from the redirect table and continue. The
|
|
467
|
-
// corresponding storageId may still be used either directly or via other localIds.
|
|
468
|
-
this.redirectTable.delete(blobId);
|
|
491
|
+
(0, common_utils_1.assert)(pathParts.length === 3 && pathParts[1] === BlobManager.basePath, 0x50f /* Invalid blob node id in tombstoned routes. */);
|
|
492
|
+
tombstonedBlobsSet.add(pathParts[2]);
|
|
493
|
+
}
|
|
494
|
+
// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
|
|
495
|
+
for (const blobId of this.tombstonedBlobs) {
|
|
496
|
+
if (!tombstonedBlobsSet.has(blobId)) {
|
|
497
|
+
this.tombstonedBlobs.delete(blobId);
|
|
469
498
|
}
|
|
470
499
|
}
|
|
500
|
+
// Mark blobs that are now tombstoned by adding them to the tombstone list.
|
|
501
|
+
for (const blobId of tombstonedBlobsSet) {
|
|
502
|
+
this.tombstonedBlobs.add(blobId);
|
|
503
|
+
}
|
|
471
504
|
}
|
|
472
505
|
summarize(telemetryContext) {
|
|
473
506
|
// if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached
|
|
@@ -490,9 +523,9 @@ class BlobManager {
|
|
|
490
523
|
(0, common_utils_1.assert)(this.redirectTable.size === table.size, 0x391 /* Redirect table size must match BlobManager's local ID count */);
|
|
491
524
|
for (const [localId, storageId] of table) {
|
|
492
525
|
(0, common_utils_1.assert)(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
|
|
493
|
-
this.
|
|
526
|
+
this.setRedirection(localId, storageId);
|
|
494
527
|
// set identity (id -> id) entry
|
|
495
|
-
this.
|
|
528
|
+
this.setRedirection(storageId, storageId);
|
|
496
529
|
}
|
|
497
530
|
}
|
|
498
531
|
getPendingBlobs() {
|