@fluidframework/container-runtime 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.0
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 +44 -33
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +130 -97
- package/dist/blobManager.js.map +1 -1
- package/dist/containerRuntime.d.ts +39 -8
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +117 -61
- 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 +4 -3
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStores.d.ts +9 -6
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +30 -24
- 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 -151
- package/dist/garbageCollection.js.map +1 -1
- package/dist/garbageCollectionConstants.d.ts +6 -3
- package/dist/garbageCollectionConstants.d.ts.map +1 -1
- package/dist/garbageCollectionConstants.js +7 -7
- package/dist/garbageCollectionConstants.js.map +1 -1
- package/dist/garbageCollectionTombstoneUtils.d.ts +13 -0
- package/dist/garbageCollectionTombstoneUtils.d.ts.map +1 -0
- package/dist/garbageCollectionTombstoneUtils.js +28 -0
- package/dist/garbageCollectionTombstoneUtils.js.map +1 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 +44 -33
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +131 -98
- package/lib/blobManager.js.map +1 -1
- package/lib/containerRuntime.d.ts +39 -8
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +115 -59
- 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 +5 -4
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStores.d.ts +9 -6
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +32 -26
- 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 -147
- package/lib/garbageCollection.js.map +1 -1
- package/lib/garbageCollectionConstants.d.ts +6 -3
- package/lib/garbageCollectionConstants.d.ts.map +1 -1
- package/lib/garbageCollectionConstants.js +6 -6
- package/lib/garbageCollectionConstants.js.map +1 -1
- package/lib/garbageCollectionTombstoneUtils.d.ts +13 -0
- package/lib/garbageCollectionTombstoneUtils.d.ts.map +1 -0
- package/lib/garbageCollectionTombstoneUtils.js +24 -0
- package/lib/garbageCollectionTombstoneUtils.js.map +1 -0
- package/lib/index.d.ts +0 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -1
- 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 +37 -19
- package/src/batchTracker.ts +1 -1
- package/src/blobManager.ts +146 -103
- package/src/containerRuntime.ts +166 -65
- package/src/dataStoreContext.ts +5 -5
- package/src/dataStores.ts +40 -30
- package/src/garbageCollection.ts +254 -183
- package/src/garbageCollectionConstants.ts +7 -6
- package/src/garbageCollectionTombstoneUtils.ts +31 -0
- package/src/index.ts +0 -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
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import { Throttler, formExponentialFn, IThrottler } from "./throttler";
|
|
26
26
|
import { summarizerClientType } from "./summarizerClientElection";
|
|
27
27
|
import { throwOnTombstoneUsageKey } 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
|
|
|
@@ -146,7 +153,7 @@ export class BlobManager {
|
|
|
146
153
|
/** If true, throw an error when a tombstone attachment blob is retrieved. */
|
|
147
154
|
private readonly throwOnTombstoneUsage: 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,22 +163,24 @@ 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
186
|
this.throwOnTombstoneUsage =
|
|
@@ -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
|
*/
|
|
@@ -261,10 +275,11 @@ export class BlobManager {
|
|
|
261
275
|
const request = { url: blobId };
|
|
262
276
|
if (this.tombstonedBlobs.has(blobId) ) {
|
|
263
277
|
const error = responseToException(createResponseError(404, "Blob removed by gc", request), request);
|
|
264
|
-
|
|
278
|
+
const event = {
|
|
265
279
|
eventName: "GC_Tombstone_Blob_Requested",
|
|
266
280
|
url: request.url,
|
|
267
|
-
}
|
|
281
|
+
};
|
|
282
|
+
sendGCTombstoneEvent(this.mc, event, this.runtime.clientDetails.type === summarizerClientType, [BlobManager.basePath], error);
|
|
268
283
|
if (this.throwOnTombstoneUsage) {
|
|
269
284
|
throw error;
|
|
270
285
|
}
|
|
@@ -274,7 +289,7 @@ export class BlobManager {
|
|
|
274
289
|
if (pending) {
|
|
275
290
|
return pending.blob;
|
|
276
291
|
}
|
|
277
|
-
let storageId;
|
|
292
|
+
let storageId: string;
|
|
278
293
|
if (this.runtime.attachState === AttachState.Detached) {
|
|
279
294
|
assert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);
|
|
280
295
|
|
|
@@ -282,12 +297,13 @@ export class BlobManager {
|
|
|
282
297
|
// The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.
|
|
283
298
|
storageId = blobId;
|
|
284
299
|
} else {
|
|
285
|
-
|
|
286
|
-
assert(!!
|
|
300
|
+
const attachedStorageId = this.redirectTable.get(blobId);
|
|
301
|
+
assert(!!attachedStorageId, 0x11f /* "requesting unknown blobs" */);
|
|
302
|
+
storageId = attachedStorageId;
|
|
287
303
|
}
|
|
288
304
|
|
|
289
|
-
//
|
|
290
|
-
this.
|
|
305
|
+
// Let runtime know that the corresponding GC node was requested.
|
|
306
|
+
this.blobRequested(this.getBlobGCNodePath(blobId));
|
|
291
307
|
|
|
292
308
|
return PerformanceEvent.timedExecAsync(
|
|
293
309
|
this.mc.logger,
|
|
@@ -313,7 +329,7 @@ export class BlobManager {
|
|
|
313
329
|
// Blobs created while the container is detached are stored in IDetachedBlobStorage.
|
|
314
330
|
// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.
|
|
315
331
|
const response = await this.getStorage().createBlob(blob);
|
|
316
|
-
this.
|
|
332
|
+
this.setRedirection(response.id, undefined);
|
|
317
333
|
return this.getBlobHandle(response.id);
|
|
318
334
|
}
|
|
319
335
|
|
|
@@ -329,8 +345,8 @@ export class BlobManager {
|
|
|
329
345
|
assert(this.runtime.attachState === AttachState.Attached,
|
|
330
346
|
0x385 /* For clarity and paranoid defense against adding future attachment states */);
|
|
331
347
|
|
|
332
|
-
// Create a local ID for
|
|
333
|
-
//
|
|
348
|
+
// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
|
|
349
|
+
// storage ID mapping is created.
|
|
334
350
|
const localId = uuid();
|
|
335
351
|
const pendingEntry: PendingBlob = {
|
|
336
352
|
blob,
|
|
@@ -355,6 +371,28 @@ export class BlobManager {
|
|
|
355
371
|
);
|
|
356
372
|
}
|
|
357
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added
|
|
376
|
+
* which is required for GC.
|
|
377
|
+
*/
|
|
378
|
+
private setRedirection(fromId: string, toId: string | undefined) {
|
|
379
|
+
this.redirectTable.set(fromId, toId);
|
|
380
|
+
// Notify runtime of a reference added if toId is not undefined. It can be undefined when a blob is uploaded in
|
|
381
|
+
// detached mode. In this case, the entry will be updated when the blob is updated.
|
|
382
|
+
if (toId !== undefined) {
|
|
383
|
+
this.addedBlobReference(this.getBlobGCNodePath(fromId), this.getBlobGCNodePath(toId));
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
private deleteAndEmitsIfEmpty(id: string) {
|
|
388
|
+
if (this.pendingBlobs.has(id)) {
|
|
389
|
+
this.pendingBlobs.delete(id);
|
|
390
|
+
if (!this.hasPendingBlobs) {
|
|
391
|
+
this.emit("noPendingBlobs");
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
358
396
|
private onUploadResolve(localId: string, response: ICreateBlobResponse) {
|
|
359
397
|
const entry = this.pendingBlobs.get(localId);
|
|
360
398
|
assert(entry?.status === PendingBlobStatus.OnlinePendingUpload ||
|
|
@@ -363,16 +401,23 @@ export class BlobManager {
|
|
|
363
401
|
entry.storageId = response.id;
|
|
364
402
|
if (this.runtime.connected) {
|
|
365
403
|
if (entry.status === PendingBlobStatus.OnlinePendingUpload) {
|
|
404
|
+
// Send a blob attach op. This serves two purposes:
|
|
405
|
+
// 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
|
|
406
|
+
// until its storage ID is added to the next summary.
|
|
407
|
+
// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the
|
|
408
|
+
// blob from the server via the storage ID.
|
|
409
|
+
this.sendBlobAttachOp(localId, response.id);
|
|
366
410
|
if (this.storageIds.has(response.id)) {
|
|
367
|
-
//
|
|
368
|
-
//
|
|
369
|
-
|
|
370
|
-
this.
|
|
411
|
+
// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is
|
|
412
|
+
// an existing blob, we don't have to wait for the op to be ack'd since this step has already
|
|
413
|
+
// happened before and so, the server won't delete it.
|
|
414
|
+
this.setRedirection(localId, response.id);
|
|
415
|
+
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
416
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
371
417
|
} else {
|
|
372
|
-
//
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
418
|
+
// If there is already an op for this storage ID, append the local ID to the list. Once any op for
|
|
419
|
+
// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the
|
|
420
|
+
// blob alive in storage.
|
|
376
421
|
this.opsInFlight.set(response.id, (this.opsInFlight.get(response.id) ?? []).concat(localId));
|
|
377
422
|
entry.status = PendingBlobStatus.OnlinePendingOp;
|
|
378
423
|
}
|
|
@@ -414,16 +459,21 @@ export class BlobManager {
|
|
|
414
459
|
assert([PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(entry.status),
|
|
415
460
|
0x38a /* Blob must be in online flow to transition to offline flow */);
|
|
416
461
|
|
|
462
|
+
/**
|
|
463
|
+
* If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.
|
|
464
|
+
* This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,
|
|
465
|
+
* an invalid handle could be added to the document.
|
|
466
|
+
* storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()
|
|
467
|
+
* is called on reconnection.
|
|
468
|
+
*/
|
|
469
|
+
if (entry.status !== PendingBlobStatus.OnlinePendingOp) {
|
|
470
|
+
this.sendBlobAttachOp(localId, entry.storageId);
|
|
471
|
+
}
|
|
472
|
+
|
|
417
473
|
entry.status = entry.status === PendingBlobStatus.OnlinePendingUpload
|
|
418
474
|
? PendingBlobStatus.OfflinePendingUpload
|
|
419
475
|
: PendingBlobStatus.OfflinePendingOp;
|
|
420
476
|
|
|
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
477
|
entry.handleP.resolve(this.getBlobHandle(localId));
|
|
428
478
|
}
|
|
429
479
|
|
|
@@ -434,33 +484,42 @@ export class BlobManager {
|
|
|
434
484
|
*/
|
|
435
485
|
public reSubmit(metadata: Record<string, unknown> | undefined) {
|
|
436
486
|
assert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);
|
|
437
|
-
const {
|
|
487
|
+
const { localId, blobId }: { localId?: string; blobId?: string } = metadata;
|
|
488
|
+
assert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);
|
|
438
489
|
if (!blobId) {
|
|
439
|
-
assert(!!localId, 0x38c /* Submitted BlobAttach ops must have a blobId or localId */);
|
|
440
490
|
// We submitted this op while offline. The blob should have been uploaded by now.
|
|
441
491
|
const pendingEntry = this.pendingBlobs.get(localId);
|
|
442
492
|
assert(pendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&
|
|
443
493
|
!!pendingEntry?.storageId, 0x38d /* blob must be uploaded before resubmitting BlobAttach op */);
|
|
444
|
-
return this.sendBlobAttachOp(pendingEntry.storageId
|
|
494
|
+
return this.sendBlobAttachOp(localId, pendingEntry.storageId);
|
|
445
495
|
}
|
|
446
|
-
return this.sendBlobAttachOp(
|
|
496
|
+
return this.sendBlobAttachOp(localId, blobId);
|
|
447
497
|
}
|
|
448
498
|
|
|
449
499
|
public processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
500
|
+
const localId = message.metadata?.localId;
|
|
501
|
+
const blobId = message.metadata?.blobId;
|
|
502
|
+
assert(blobId !== undefined, 0x12a /* "Missing blob id on metadata" */);
|
|
503
|
+
|
|
504
|
+
// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be
|
|
505
|
+
// requested from the server.
|
|
506
|
+
// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that
|
|
507
|
+
// was sent when online.
|
|
508
|
+
if (localId !== undefined) {
|
|
509
|
+
this.setRedirection(localId, blobId);
|
|
453
510
|
}
|
|
454
511
|
// set identity (id -> id) entry
|
|
455
|
-
this.
|
|
512
|
+
this.setRedirection(blobId, blobId);
|
|
456
513
|
|
|
457
514
|
if (local) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
515
|
+
assert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);
|
|
516
|
+
const waitingBlobs = this.opsInFlight.get(blobId);
|
|
517
|
+
if (waitingBlobs !== undefined) {
|
|
518
|
+
// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.
|
|
519
|
+
// This is safe because the server will keep the blob alive and the op containing the local ID to
|
|
520
|
+
// storage ID is already in flight and any op containing this local ID will be sequenced after that.
|
|
521
|
+
waitingBlobs.forEach((pendingLocalId) => {
|
|
522
|
+
const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
|
|
464
523
|
assert(
|
|
465
524
|
pendingBlobEntry !== undefined,
|
|
466
525
|
0x38f, /* local online BlobAttach op with no pending blob entry */
|
|
@@ -468,16 +527,15 @@ export class BlobManager {
|
|
|
468
527
|
|
|
469
528
|
// It's possible we transitioned to offline flow while waiting for this op.
|
|
470
529
|
if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
|
|
471
|
-
|
|
472
|
-
|
|
530
|
+
this.setRedirection(pendingLocalId, blobId);
|
|
531
|
+
pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
|
|
532
|
+
this.deleteAndEmitsIfEmpty(pendingLocalId);
|
|
473
533
|
}
|
|
474
534
|
});
|
|
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);
|
|
535
|
+
this.opsInFlight.delete(blobId);
|
|
480
536
|
}
|
|
537
|
+
// For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
|
|
538
|
+
this.deleteAndEmitsIfEmpty(localId);
|
|
481
539
|
}
|
|
482
540
|
}
|
|
483
541
|
|
|
@@ -531,75 +589,60 @@ export class BlobManager {
|
|
|
531
589
|
*/
|
|
532
590
|
public getGCData(fullGC: boolean = false): IGarbageCollectionData {
|
|
533
591
|
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
592
|
for (const [localId, storageId] of this.redirectTable) {
|
|
548
593
|
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
594
|
gcData.gcNodes[this.getBlobGCNodePath(localId)] = [this.getBlobGCNodePath(storageId)];
|
|
552
595
|
}
|
|
553
|
-
|
|
554
596
|
return gcData;
|
|
555
597
|
}
|
|
556
598
|
|
|
557
599
|
/**
|
|
558
|
-
* This is called to update blobs whose routes are
|
|
559
|
-
* @param
|
|
600
|
+
* This is called to update blobs whose routes are unused. The unused blobs are deleted.
|
|
601
|
+
* @param unusedRoutes - The routes of the blob nodes that are unused.
|
|
560
602
|
*/
|
|
561
|
-
public
|
|
603
|
+
public updateUnusedRoutes(unusedRoutes: string[]): void {
|
|
562
604
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
563
605
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
564
|
-
for (const route of
|
|
606
|
+
for (const route of unusedRoutes) {
|
|
565
607
|
const pathParts = route.split("/");
|
|
566
608
|
assert(
|
|
567
609
|
pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
568
|
-
|
|
610
|
+
0x2d5 /* "Invalid blob node id in unused routes." */,
|
|
569
611
|
);
|
|
570
612
|
const blobId = pathParts[2];
|
|
571
|
-
|
|
572
|
-
this.tombstonedBlobs.delete(blobId);
|
|
613
|
+
this.redirectTable.delete(blobId);
|
|
573
614
|
}
|
|
574
615
|
}
|
|
575
616
|
|
|
576
617
|
/**
|
|
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.
|
|
618
|
+
* This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with
|
|
619
|
+
* accessing deleted content without actually deleting content from summaries.
|
|
620
|
+
* @param tombstonedRoutes - The routes of blob nodes that are tombstones.
|
|
582
621
|
*/
|
|
583
|
-
public
|
|
622
|
+
public updateTombstonedRoutes(tombstonedRoutes: string[]) {
|
|
623
|
+
const tombstonedBlobsSet: Set<string> = new Set();
|
|
584
624
|
// The routes or blob node paths are in the same format as returned in getGCData -
|
|
585
625
|
// `/<BlobManager.basePath>/<blobId>`.
|
|
586
|
-
for (const route of
|
|
626
|
+
for (const route of tombstonedRoutes) {
|
|
587
627
|
const pathParts = route.split("/");
|
|
588
628
|
assert(
|
|
589
629
|
pathParts.length === 3 && pathParts[1] === BlobManager.basePath,
|
|
590
|
-
|
|
630
|
+
0x50f /* Invalid blob node id in tombstoned routes. */,
|
|
591
631
|
);
|
|
592
|
-
|
|
632
|
+
tombstonedBlobsSet.add(pathParts[2]);
|
|
633
|
+
}
|
|
593
634
|
|
|
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);
|
|
635
|
+
// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.
|
|
636
|
+
for (const blobId of this.tombstonedBlobs) {
|
|
637
|
+
if (!tombstonedBlobsSet.has(blobId)) {
|
|
638
|
+
this.tombstonedBlobs.delete(blobId);
|
|
601
639
|
}
|
|
602
640
|
}
|
|
641
|
+
|
|
642
|
+
// Mark blobs that are now tombstoned by adding them to the tombstone list.
|
|
643
|
+
for (const blobId of tombstonedBlobsSet) {
|
|
644
|
+
this.tombstonedBlobs.add(blobId);
|
|
645
|
+
}
|
|
603
646
|
}
|
|
604
647
|
|
|
605
648
|
public summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {
|
|
@@ -630,9 +673,9 @@ export class BlobManager {
|
|
|
630
673
|
0x391 /* Redirect table size must match BlobManager's local ID count */);
|
|
631
674
|
for (const [localId, storageId] of table) {
|
|
632
675
|
assert(this.redirectTable.has(localId), 0x254 /* "unrecognized id in redirect table" */);
|
|
633
|
-
this.
|
|
676
|
+
this.setRedirection(localId, storageId);
|
|
634
677
|
// set identity (id -> id) entry
|
|
635
|
-
this.
|
|
678
|
+
this.setRedirection(storageId, storageId);
|
|
636
679
|
}
|
|
637
680
|
}
|
|
638
681
|
|