@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/src/blobManager.ts
CHANGED
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
} from "@fluidframework/runtime-definitions";
|
|
25
25
|
import { Throttler, formExponentialFn, IThrottler } from "./throttler";
|
|
26
26
|
import { summarizerClientType } from "./summarizerClientElection";
|
|
27
|
-
import {
|
|
27
|
+
import { throwOnTombstoneLoadKey } from "./garbageCollectionConstants";
|
|
28
|
+
import { sendGCTombstoneEvent } from "./garbageCollectionTombstoneUtils";
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* This class represents blob (long string)
|
|
@@ -110,16 +111,21 @@ interface PendingBlob {
|
|
|
110
111
|
|
|
111
112
|
export interface IPendingBlobs { [id: string]: { blob: string; }; }
|
|
112
113
|
|
|
113
|
-
export
|
|
114
|
+
export interface IBlobManagerEvents {
|
|
115
|
+
(event: "noPendingBlobs", listener: () => void);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
|
|
114
119
|
public static readonly basePath = "_blobs";
|
|
115
120
|
private static readonly redirectTableBlobName = ".redirectTable";
|
|
116
121
|
private readonly mc: MonitoringContext;
|
|
117
122
|
|
|
118
123
|
/**
|
|
119
|
-
* Map of local
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
124
|
+
* Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should
|
|
125
|
+
* be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which
|
|
126
|
+
* gives local IDs; the storage IDs are filled in at attach time.
|
|
127
|
+
* Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client
|
|
128
|
+
* that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.
|
|
123
129
|
*/
|
|
124
130
|
private readonly redirectTable: Map<string, string | undefined>;
|
|
125
131
|
|
|
@@ -131,8 +137,9 @@ export class BlobManager {
|
|
|
131
137
|
private readonly pendingBlobs: Map<string, PendingBlob> = new Map();
|
|
132
138
|
|
|
133
139
|
/**
|
|
134
|
-
* Track ops in flight for online flow.
|
|
135
|
-
*
|
|
140
|
+
* Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,
|
|
141
|
+
* we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's
|
|
142
|
+
* because we know that the server will not delete the blob corresponding to that storage ID.
|
|
136
143
|
*/
|
|
137
144
|
private readonly opsInFlight: Map<string, string[]> = new Map();
|
|
138
145
|
|
|
@@ -144,9 +151,9 @@ export class BlobManager {
|
|
|
144
151
|
));
|
|
145
152
|
|
|
146
153
|
/** If true, throw an error when a tombstone attachment blob is retrieved. */
|
|
147
|
-
private readonly
|
|
154
|
+
private readonly throwOnTombstoneLoad: boolean;
|
|
148
155
|
/**
|
|
149
|
-
* This stores
|
|
156
|
+
* This stores IDs of tombstoned blobs.
|
|
150
157
|
* Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.
|
|
151
158
|
*/
|
|
152
159
|
private readonly tombstonedBlobs: Set<string> = new Set();
|
|
@@ -156,26 +163,28 @@ export class BlobManager {
|
|
|
156
163
|
snapshot: IBlobManagerLoadInfo,
|
|
157
164
|
private readonly getStorage: () => IDocumentStorageService,
|
|
158
165
|
/**
|
|
159
|
-
* Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
166
|
+
* Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is
|
|
167
|
+
* deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the
|
|
168
|
+
* the blob as long as it is listed as referenced in future summaries. The summarizing client will know to
|
|
169
|
+
* include the storage ID in the summary when it sees the op.
|
|
163
170
|
*
|
|
164
|
-
* The op
|
|
165
|
-
*
|
|
166
|
-
*
|
|
171
|
+
* The op will also include a local ID to inform all clients of the relation to the storage ID, without
|
|
172
|
+
* knowledge of which they cannot request the blob from storage. It's important that this op is sequenced
|
|
173
|
+
* before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.
|
|
167
174
|
*/
|
|
168
|
-
private readonly sendBlobAttachOp: (
|
|
175
|
+
private readonly sendBlobAttachOp: (localId: string, storageId?: string) => void,
|
|
169
176
|
// To be called when a blob node is requested. blobPath is the path of the blob's node in GC's graph. It's
|
|
170
177
|
// of the format `/<BlobManager.basePath>/<blobId>`.
|
|
171
|
-
private readonly
|
|
178
|
+
private readonly blobRequested: (blobPath: string) => void,
|
|
179
|
+
private readonly addedBlobReference: (fromNodePath: string, toNodePath: string) => void,
|
|
172
180
|
private readonly runtime: IBlobManagerRuntime,
|
|
173
181
|
stashedBlobs: IPendingBlobs = {},
|
|
174
182
|
) {
|
|
183
|
+
super();
|
|
175
184
|
this.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, "BlobManager"));
|
|
176
185
|
// Read the feature flag that tells whether to throw when a tombstone blob is requested.
|
|
177
|
-
this.
|
|
178
|
-
this.mc.config.getBoolean(
|
|
186
|
+
this.throwOnTombstoneLoad =
|
|
187
|
+
this.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&
|
|
179
188
|
this.runtime.clientDetails.type !== summarizerClientType;
|
|
180
189
|
|
|
181
190
|
this.runtime.on("disconnected", () => this.onDisconnected());
|
|
@@ -202,6 +211,11 @@ export class BlobManager {
|
|
|
202
211
|
return this.pendingOfflineUploads.length > 0;
|
|
203
212
|
}
|
|
204
213
|
|
|
214
|
+
public get hasPendingBlobs(): boolean {
|
|
215
|
+
return (this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0)
|
|
216
|
+
|| this.pendingBlobs.size > 0;
|
|
217
|
+
}
|
|
218
|
+
|
|
205
219
|
/**
|
|
206
220
|
* Upload blobs added while offline. This must be completed before connecting and resubmitting ops.
|
|
207
221
|
*/
|
|
@@ -260,12 +274,18 @@ export class BlobManager {
|
|
|
260
274
|
public async getBlob(blobId: string): Promise<ArrayBufferLike> {
|
|
261
275
|
const request = { url: blobId };
|
|
262
276
|
if (this.tombstonedBlobs.has(blobId) ) {
|
|
263
|
-
const error = responseToException(createResponseError(404, "Blob
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
277
|
+
const error = responseToException(createResponseError(404, "Blob was deleted", request), request);
|
|
278
|
+
sendGCTombstoneEvent(
|
|
279
|
+
this.mc,
|
|
280
|
+
{
|
|
281
|
+
eventName: "GC_Tombstone_Blob_Requested",
|
|
282
|
+
category: this.throwOnTombstoneLoad ? "error" : "generic",
|
|
283
|
+
isSummarizerClient: this.runtime.clientDetails.type === summarizerClientType,
|
|
284
|
+
},
|
|
285
|
+
[BlobManager.basePath],
|
|
286
|
+
error,
|
|
287
|
+
);
|
|
288
|
+
if (this.throwOnTombstoneLoad) {
|
|
269
289
|
throw error;
|
|
270
290
|
}
|
|
271
291
|
}
|
|
@@ -274,7 +294,7 @@ export class BlobManager {
|
|
|
274
294
|
if (pending) {
|
|
275
295
|
return pending.blob;
|
|
276
296
|
}
|
|
277
|
-
let storageId;
|
|
297
|
+
let storageId: string;
|
|
278
298
|
if (this.runtime.attachState === AttachState.Detached) {
|
|
279
299
|
assert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);
|
|
280
300
|
|
|
@@ -282,12 +302,13 @@ export class BlobManager {
|
|
|
282
302
|
// The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.
|
|
283
303
|
storageId = blobId;
|
|
284
304
|
} else {
|
|
285
|
-
|
|
286
|
-
assert(!!
|
|
305
|
+
const attachedStorageId = this.redirectTable.get(blobId);
|
|
306
|
+
assert(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
|
|
307
|
+
storageId = attachedStorageId;
|
|
287
308
|
}
|
|
288
309
|
|
|
289
|
-
//
|
|
290
|
-
this.
|
|
310
|
+
// Let runtime know that the corresponding GC node was requested.
|
|
311
|
+
this.blobRequested(this.getBlobGCNodePath(blobId));
|
|
291
312
|
|
|
292
313
|
return PerformanceEvent.timedExecAsync(
|
|
293
314
|
this.mc.logger,
|
|
@@ -313,7 +334,7 @@ export class BlobManager {
|
|
|
313
334
|
// Blobs created while the container is detached are stored in IDetachedBlobStorage.
|
|
314
335
|
// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
|
|
315
336
|
const response = await this.getStorage().createBlob(blob);
|
|
316
|
-
this.
|
|
337
|
+
this.setRedirection(response.id, undefined);
|
|
317
338
|
return this.getBlobHandle(response.id);
|
|
318
339
|
}
|
|
319
340
|
|
|
@@ -329,8 +350,8 @@ export class BlobManager {
|
|
|
329
350
|
assert(this.runtime.attachState === AttachState.Attached,
|
|
330
351
|
0x385 /* For clarity and paranoid defense against adding future attachment states */);
|
|
331
352
|
|
|
332
|
-
// Create a local ID for
|
|
333
|
-
//
|
|
353
|
+
// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
|
|
354
|
+
// storage ID mapping is created.
|
|
334
355
|
const localId = uuid();
|
|
335
356
|
const pendingEntry: PendingBlob = {
|
|
336
357
|
blob,
|
|
@@ -355,6 +376,28 @@ export class BlobManager {
|
|
|
355
376
|
);
|
|
356
377
|
}
|
|
357
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
|
|
381
|
+
* which is required for GC.
|
|
382
|
+
*/
|
|
383
|
+
private setRedirection(fromId: string, toId: string | undefined) {
|
|
384
|
+
this.redirectTable.set(fromId, toId);
|
|
385
|
+
// Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in
|
|
386
|
+
// detached mode. In this case, the entry will be updated when the blob is updated.
|
|
387
|
+
if (toId !== undefined) {
|
|
388
|
+
this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
private deleteAndEmitsIfEmpty(id: string) {
|
|
393
|
+
if (this.pendingBlobs.has(id)) {
|
|
394
|
+
this.pendingBlobs.delete(id);
|
|
395
|
+
if (!this.hasPendingBlobs) {
|
|
396
|
+
this.emit("noPendingBlobs");
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
358
401
|
private onUploadResolve(localId: string, response: ICreateBlobResponse) {
|
|
359
402
|
const entry = this.pendingBlobs.get(localId);
|
|
360
403
|
assert(entry?.status === PendingBlobStatus.OnlinePendingUpload ||
|
|
@@ -363,16 +406,23 @@ export class BlobManager {
|
|
|
363
406
|
entry.storageId = response.id;
|
|
364
407
|
if (this.runtime.connected) {
|
|
365
408
|
if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
|
|
409
|
+
// Send a blob attach op. This serves two purposes:
|
|
410
|
+
// 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
|
|
411
|
+
// until its storage ID is added to the next summary.
|
|
412
|
+
// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
|
|
413
|
+
// blob from the server via the storage ID.
|
|
414
|
+
this.sendBlobAttachOp(localId, response.id);
|
|
366
415
|
if (this.storageIds.has(response.id)) {
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
this.
|
|
416
|
+
// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
|
|
417
|
+
// an existing blob, we don't have to wait for the op to be ack'd since this step has already
|
|
418
|
+
// happened before and so, the server won't delete it.
|
|
419
|
+
this.setRedirection(localId, response.id);
|
|
420
|
+
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
421
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
371
422
|
} else {
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
423
|
+
// If there is already an op for this storage ID, append the local ID to the list. Once any op for
|
|
424
|
+
// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
|
|
425
|
+
// blob alive in storage.
|
|
376
426
|
this.opsInFlight.set(response.id, (this.opsInFlight.get(response.id) ?? []).concat(localId));
|
|
377
427
|
entry.status = PendingBlobStatus.OnlinePendingOp;
|
|
378
428
|
}
|
|
@@ -414,16 +464,21 @@ export class BlobManager {
|
|
|
414
464
|
assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status),
|
|
415
465
|
0x38a /* Blob must be in online flow to transition to offline flow */);
|
|
416
466
|
|
|
467
|
+
/**
|
|
468
|
+
* If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
|
|
469
|
+
* This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
|
|
470
|
+
* an invalid handle could be added to the document.
|
|
471
|
+
* storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
|
|
472
|
+
* is called on reconnection.
|
|
473
|
+
*/
|
|
474
|
+
if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
|
|
475
|
+
this.sendBlobAttachOp(localId, entry.storageId);
|
|
476
|
+
}
|
|
477
|
+
|
|
417
478
|
entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
|
|
418
479
|
? PendingBlobStatus.OfflinePendingUpload
|
|
419
480
|
: PendingBlobStatus.OfflinePendingOp;
|
|
420
481
|
|
|
421
|
-
// Submit a BlobAttach op. It's important we submit this op now before returning the blob handle so the
|
|
422
|
-
// BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise an invalid handle could be
|
|
423
|
-
// added to the document if the ops are not all successfully submitted upon reconnection.
|
|
424
|
-
// storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
|
|
425
|
-
// is called
|
|
426
|
-
this.sendBlobAttachOp(entry.storageId, localId);
|
|
427
482
|
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
428
483
|
}
|
|
429
484
|
|
|
@@ -434,33 +489,42 @@ export class BlobManager {
|
|
|
434
489
|
*/
|
|
435
490
|
public reSubmit(metadata: Record<string, unknown> | undefined) {
|
|
436
491
|
assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
|
|
437
|
-
const {
|
|
492
|
+
const { localId, blobId }: { localId?: string; blobId?: string } = metadata;
|
|
493
|
+
assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
|
|
438
494
|
if (!blobId) {
|
|
439
|
-
assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
|
|
440
495
|
// We submitted this op while offline. The blob should have been uploaded by now.
|
|
441
496
|
const pendingEntry = this.pendingBlobs.get(localId);
|
|
442
497
|
assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&
|
|
443
498
|
!!pendingEntry?.storageId, 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
|
|
444
|
-
return this.sendBlobAttachOp(pendingEntry.storageId
|
|
499
|
+
return this.sendBlobAttachOp(localId, pendingEntry.storageId);
|
|
445
500
|
}
|
|
446
|
-
return this.sendBlobAttachOp(
|
|
501
|
+
return this.sendBlobAttachOp(localId, blobId);
|
|
447
502
|
}
|
|
448
503
|
|
|
449
504
|
public processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
505
|
+
const localId = message.metadata?.localId;
|
|
506
|
+
const blobId = message.metadata?.blobId;
|
|
507
|
+
assert(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
|
|
508
|
+
|
|
509
|
+
// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
|
|
510
|
+
// requested from the server.
|
|
511
|
+
// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
|
|
512
|
+
// was sent when online.
|
|
513
|
+
if (localId !== undefined) {
|
|
514
|
+
this.setRedirection(localId, blobId);
|
|
453
515
|
}
|
|
454
516
|
// set identity (id -> id) entry
|
|
455
|
-
this.
|
|
517
|
+
this.setRedirection(blobId, blobId);
|
|
456
518
|
|
|
457
519
|
if (local) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
520
|
+
assert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
|
|
521
|
+
const waitingBlobs = this.opsInFlight.get(blobId);
|
|
522
|
+
if (waitingBlobs !== undefined) {
|
|
523
|
+
// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
|
|
524
|
+
// This is safe because the server will keep the blob alive and the op containing the local ID to
|
|
525
|
+
// storage ID is already in flight and any op containing this local ID will be sequenced after that.
|
|
526
|
+
waitingBlobs.forEach((pendingLocalId) => {
|
|
527
|
+
const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
|
|
464
528
|
assert(
|
|
465
529
|
pendingBlobEntry !== undefined,
|
|
466
530
|
0x38f, /* local online BlobAttach op with no pending blob entry */
|
|
@@ -468,16 +532,15 @@ export class BlobManager {
|
|
|
468
532
|
|
|
469
533
|
// It's possible we transitioned to offline flow while waiting for this op.
|
|
470
534
|
if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
|
|
471
|
-
|
|
472
|
-
|
|
535
|
+
this.setRedirection(pendingLocalId, blobId);
|
|
536
|
+
pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
|
|
537
|
+
this.deleteAndEmitsIfEmpty(pendingLocalId);
|
|
473
538
|
}
|
|
474
539
|
});
|
|
475
|
-
|
|
476
|
-
// Each local ID is unique; get the pending blob entry and delete it
|
|
477
|
-
assert(this.pendingBlobs.get(message.metadata.localId)?.status === PendingBlobStatus.OfflinePendingOp,
|
|
478
|
-
0x1f8 /* "local BlobAttach op with no pending blob" */);
|
|
479
|
-
this.pendingBlobs.delete(message.metadata.localId);
|
|
540
|
+
this.opsInFlight.delete(blobId);
|
|
480
541
|
}
|
|
542
|
+
// For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
|
|
543
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
481
544
|
}
|
|
482
545
|
}
|
|
483
546
|
|
|
@@ -531,75 +594,60 @@ export class BlobManager {
|
|
|
531
594
|
*/
|
|
532
595
|
public getGCData(fullGC: boolean = false): IGarbageCollectionData {
|
|
533
596
|
const gcData: IGarbageCollectionData = { gcNodes: {} };
|
|
534
|
-
/**
|
|
535
|
-
* The node path is of the format `/_blobs/blobId`. This path must match the path of the blob handle returned
|
|
536
|
-
* by the createBlob API because blobs are marked referenced by storing these handles in a referenced DDS.
|
|
537
|
-
*/
|
|
538
|
-
this.storageIds.forEach((blobId: string) => {
|
|
539
|
-
gcData.gcNodes[this.getBlobGCNodePath(blobId)] = [];
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
// For some blobs, the handle returned on creation is based off of the localId. So, these
|
|
543
|
-
// nodes can be referenced by storing the localId handle. When that happens, the corresponding storageId node
|
|
544
|
-
// must also be marked referenced. So, we add a route from the localId node to the storageId node.
|
|
545
|
-
// Note that because of de-duping, there can be multiple localIds that all redirect to the same storageId or
|
|
546
|
-
// a blob may be referenced via its storageId handle.
|
|
547
597
|
for (const [localId, storageId] of this.redirectTable) {
|
|
548
598
|
assert(!!storageId, 0x390 /* Must be attached to get GC data */);
|
|
549
|
-
// Add node for the localId and add a route to the storageId node. The storageId node will have been
|
|
550
|
-
// added above when adding nodes for this.blobIds.
|
|
551
599
|
gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
|
|
552
600
|
}
|
|
553
|
-
|
|
554
601
|
return gcData;
|
|
555
602
|
}
|
|
556
603
|
|
|
557
604
|
/**
|
|
558
|
-
* This is called to update blobs whose routes are
|
|
559
|
-
* @param
|
|
605
|
+
* This is called to update blobs whose routes are unused. The unused blobs are deleted.
|
|
606
|
+
* @param unusedRoutes - The routes of the blob nodes that are unused.
|
|
560
607
|
*/
|
|
561
|
-
public
|
|
608
|
+
public updateUnusedRoutes(unusedRoutes: string[]): void {
|
|
562
609
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
563
610
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
564
|
-
for (const route of
|
|
611
|
+
for (const route of unusedRoutes) {
|
|
565
612
|
const pathParts = route.split("/");
|
|
566
613
|
assert(
|
|
567
614
|
pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
568
|
-
|
|
615
|
+
0x2d5 /* "Invalid blob node id in unused routes." */,
|
|
569
616
|
);
|
|
570
617
|
const blobId = pathParts[2];
|
|
571
|
-
|
|
572
|
-
this.tombstonedBlobs.delete(blobId);
|
|
618
|
+
this.redirectTable.delete(blobId);
|
|
573
619
|
}
|
|
574
620
|
}
|
|
575
621
|
|
|
576
622
|
/**
|
|
577
|
-
* This is called to update blobs whose routes are
|
|
578
|
-
*
|
|
579
|
-
* @param
|
|
580
|
-
* @param tombstone - if true, the objects corresponding to unused routes are marked tombstones. Otherwise, they
|
|
581
|
-
* are deleted.
|
|
623
|
+
* This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
|
|
624
|
+
* accessing deleted content without actually deleting content from summaries.
|
|
625
|
+
* @param tombstonedRoutes - The routes of blob nodes that are tombstones.
|
|
582
626
|
*/
|
|
583
|
-
public
|
|
627
|
+
public updateTombstonedRoutes(tombstonedRoutes: string[]) {
|
|
628
|
+
const tombstonedBlobsSet: Set<string> = new Set();
|
|
584
629
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
585
630
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
586
|
-
for (const route of
|
|
631
|
+
for (const route of tombstonedRoutes) {
|
|
587
632
|
const pathParts = route.split("/");
|
|
588
633
|
assert(
|
|
589
634
|
pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
590
|
-
|
|
635
|
+
0x50f /* Invalid blob node id in tombstoned routes. */,
|
|
591
636
|
);
|
|
592
|
-
|
|
637
|
+
tombstonedBlobsSet.add(pathParts[2]);
|
|
638
|
+
}
|
|
593
639
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
// The unused blobId could be a localId. If so, remove it from the redirect table and continue. The
|
|
599
|
-
// corresponding storageId may still be used either directly or via other localIds.
|
|
600
|
-
this.redirectTable.delete(blobId);
|
|
640
|
+
// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
|
|
641
|
+
for (const blobId of this.tombstonedBlobs) {
|
|
642
|
+
if (!tombstonedBlobsSet.has(blobId)) {
|
|
643
|
+
this.tombstonedBlobs.delete(blobId);
|
|
601
644
|
}
|
|
602
645
|
}
|
|
646
|
+
|
|
647
|
+
// Mark blobs that are now tombstoned by adding them to the tombstone list.
|
|
648
|
+
for (const blobId of tombstonedBlobsSet) {
|
|
649
|
+
this.tombstonedBlobs.add(blobId);
|
|
650
|
+
}
|
|
603
651
|
}
|
|
604
652
|
|
|
605
653
|
public summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {
|
|
@@ -630,9 +678,9 @@ export class BlobManager {
|
|
|
630
678
|
0x391 /* Redirect table size must match BlobManager's local ID count */);
|
|
631
679
|
for (const [localId, storageId] of table) {
|
|
632
680
|
assert(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
|
|
633
|
-
this.
|
|
681
|
+
this.setRedirection(localId, storageId);
|
|
634
682
|
// set identity (id -> id) entry
|
|
635
|
-
this.
|
|
683
|
+
this.setRedirection(storageId, storageId);
|
|
636
684
|
}
|
|
637
685
|
}
|
|
638
686
|
|