@fluidframework/container-runtime 2.0.0-internal.5.2.0 → 2.0.0-internal.5.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.
Files changed (171) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/blobManager.d.ts +5 -2
  3. package/dist/blobManager.d.ts.map +1 -1
  4. package/dist/blobManager.js +51 -22
  5. package/dist/blobManager.js.map +1 -1
  6. package/dist/connectionTelemetry.d.ts.map +1 -1
  7. package/dist/connectionTelemetry.js +8 -1
  8. package/dist/connectionTelemetry.js.map +1 -1
  9. package/dist/containerRuntime.d.ts +4 -15
  10. package/dist/containerRuntime.d.ts.map +1 -1
  11. package/dist/containerRuntime.js +12 -7
  12. package/dist/containerRuntime.js.map +1 -1
  13. package/dist/dataStoreContext.d.ts.map +1 -1
  14. package/dist/dataStoreContext.js +4 -3
  15. package/dist/dataStoreContext.js.map +1 -1
  16. package/dist/dataStoreContexts.d.ts.map +1 -1
  17. package/dist/dataStoreContexts.js +2 -1
  18. package/dist/dataStoreContexts.js.map +1 -1
  19. package/dist/dataStores.d.ts +1 -2
  20. package/dist/dataStores.d.ts.map +1 -1
  21. package/dist/dataStores.js +2 -1
  22. package/dist/dataStores.js.map +1 -1
  23. package/dist/gc/garbageCollection.d.ts.map +1 -1
  24. package/dist/gc/garbageCollection.js +4 -3
  25. package/dist/gc/garbageCollection.js.map +1 -1
  26. package/dist/gc/gcTelemetry.d.ts +1 -1
  27. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  28. package/dist/gc/gcTelemetry.js.map +1 -1
  29. package/dist/metadata.d.ts +18 -0
  30. package/dist/metadata.d.ts.map +1 -0
  31. package/dist/metadata.js +7 -0
  32. package/dist/metadata.js.map +1 -0
  33. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  34. package/dist/opLifecycle/opDecompressor.js +14 -8
  35. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  36. package/dist/opLifecycle/opGroupingManager.d.ts +1 -1
  37. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  38. package/dist/opLifecycle/opGroupingManager.js +2 -6
  39. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  40. package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
  41. package/dist/opLifecycle/opSplitter.js +2 -0
  42. package/dist/opLifecycle/opSplitter.js.map +1 -1
  43. package/dist/opLifecycle/outbox.d.ts +5 -1
  44. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  45. package/dist/opLifecycle/outbox.js +45 -27
  46. package/dist/opLifecycle/outbox.js.map +1 -1
  47. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  48. package/dist/opLifecycle/remoteMessageProcessor.js +3 -1
  49. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  50. package/dist/packageVersion.d.ts +1 -1
  51. package/dist/packageVersion.js +1 -1
  52. package/dist/packageVersion.js.map +1 -1
  53. package/dist/pendingStateManager.d.ts +1 -1
  54. package/dist/pendingStateManager.d.ts.map +1 -1
  55. package/dist/pendingStateManager.js +13 -5
  56. package/dist/pendingStateManager.js.map +1 -1
  57. package/dist/scheduleManager.d.ts.map +1 -1
  58. package/dist/scheduleManager.js +8 -2
  59. package/dist/scheduleManager.js.map +1 -1
  60. package/dist/summary/summarizerNode/summarizerNode.d.ts +1 -1
  61. package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  62. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  63. package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  64. package/dist/summary/summarizerNode/summarizerNodeWithGc.js +3 -2
  65. package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  66. package/dist/summary/summarizerTypes.d.ts +2 -1
  67. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  68. package/dist/summary/summarizerTypes.js.map +1 -1
  69. package/dist/summary/summaryCollection.d.ts.map +1 -1
  70. package/dist/summary/summaryCollection.js +4 -0
  71. package/dist/summary/summaryCollection.js.map +1 -1
  72. package/dist/summary/summaryGenerator.d.ts +1 -1
  73. package/dist/summary/summaryGenerator.d.ts.map +1 -1
  74. package/dist/summary/summaryGenerator.js.map +1 -1
  75. package/lib/blobManager.d.ts +5 -2
  76. package/lib/blobManager.d.ts.map +1 -1
  77. package/lib/blobManager.js +51 -22
  78. package/lib/blobManager.js.map +1 -1
  79. package/lib/connectionTelemetry.d.ts.map +1 -1
  80. package/lib/connectionTelemetry.js +8 -1
  81. package/lib/connectionTelemetry.js.map +1 -1
  82. package/lib/containerRuntime.d.ts +4 -15
  83. package/lib/containerRuntime.d.ts.map +1 -1
  84. package/lib/containerRuntime.js +12 -7
  85. package/lib/containerRuntime.js.map +1 -1
  86. package/lib/dataStoreContext.d.ts.map +1 -1
  87. package/lib/dataStoreContext.js +4 -3
  88. package/lib/dataStoreContext.js.map +1 -1
  89. package/lib/dataStoreContexts.d.ts.map +1 -1
  90. package/lib/dataStoreContexts.js +2 -1
  91. package/lib/dataStoreContexts.js.map +1 -1
  92. package/lib/dataStores.d.ts +1 -2
  93. package/lib/dataStores.d.ts.map +1 -1
  94. package/lib/dataStores.js +2 -1
  95. package/lib/dataStores.js.map +1 -1
  96. package/lib/gc/garbageCollection.d.ts.map +1 -1
  97. package/lib/gc/garbageCollection.js +2 -1
  98. package/lib/gc/garbageCollection.js.map +1 -1
  99. package/lib/gc/gcTelemetry.d.ts +1 -1
  100. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  101. package/lib/gc/gcTelemetry.js.map +1 -1
  102. package/lib/metadata.d.ts +18 -0
  103. package/lib/metadata.d.ts.map +1 -0
  104. package/lib/metadata.js +6 -0
  105. package/lib/metadata.js.map +1 -0
  106. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  107. package/lib/opLifecycle/opDecompressor.js +14 -8
  108. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  109. package/lib/opLifecycle/opGroupingManager.d.ts +1 -1
  110. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  111. package/lib/opLifecycle/opGroupingManager.js +2 -6
  112. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  113. package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
  114. package/lib/opLifecycle/opSplitter.js +2 -0
  115. package/lib/opLifecycle/opSplitter.js.map +1 -1
  116. package/lib/opLifecycle/outbox.d.ts +5 -1
  117. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  118. package/lib/opLifecycle/outbox.js +45 -27
  119. package/lib/opLifecycle/outbox.js.map +1 -1
  120. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  121. package/lib/opLifecycle/remoteMessageProcessor.js +3 -1
  122. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  123. package/lib/packageVersion.d.ts +1 -1
  124. package/lib/packageVersion.js +1 -1
  125. package/lib/packageVersion.js.map +1 -1
  126. package/lib/pendingStateManager.d.ts +1 -1
  127. package/lib/pendingStateManager.d.ts.map +1 -1
  128. package/lib/pendingStateManager.js +13 -5
  129. package/lib/pendingStateManager.js.map +1 -1
  130. package/lib/scheduleManager.d.ts.map +1 -1
  131. package/lib/scheduleManager.js +8 -2
  132. package/lib/scheduleManager.js.map +1 -1
  133. package/lib/summary/summarizerNode/summarizerNode.d.ts +1 -1
  134. package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -1
  135. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  136. package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  137. package/lib/summary/summarizerNode/summarizerNodeWithGc.js +2 -1
  138. package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  139. package/lib/summary/summarizerTypes.d.ts +2 -1
  140. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  141. package/lib/summary/summarizerTypes.js.map +1 -1
  142. package/lib/summary/summaryCollection.d.ts.map +1 -1
  143. package/lib/summary/summaryCollection.js +4 -0
  144. package/lib/summary/summaryCollection.js.map +1 -1
  145. package/lib/summary/summaryGenerator.d.ts +1 -1
  146. package/lib/summary/summaryGenerator.d.ts.map +1 -1
  147. package/lib/summary/summaryGenerator.js.map +1 -1
  148. package/package.json +19 -18
  149. package/src/blobManager.ts +68 -27
  150. package/src/connectionTelemetry.ts +10 -1
  151. package/src/containerRuntime.ts +14 -25
  152. package/src/dataStoreContext.ts +5 -4
  153. package/src/dataStoreContexts.ts +2 -1
  154. package/src/dataStores.ts +8 -3
  155. package/src/gc/garbageCollection.ts +2 -1
  156. package/src/gc/gcTelemetry.ts +1 -1
  157. package/src/metadata.ts +19 -0
  158. package/src/opLifecycle/README.md +20 -0
  159. package/src/opLifecycle/opDecompressor.ts +41 -13
  160. package/src/opLifecycle/opGroupingManager.ts +14 -7
  161. package/src/opLifecycle/opSplitter.ts +3 -1
  162. package/src/opLifecycle/outbox.ts +61 -38
  163. package/src/opLifecycle/remoteMessageProcessor.ts +5 -1
  164. package/src/packageVersion.ts +1 -1
  165. package/src/pendingStateManager.ts +20 -9
  166. package/src/scheduleManager.ts +15 -6
  167. package/src/summary/summarizerNode/summarizerNode.ts +1 -1
  168. package/src/summary/summarizerNode/summarizerNodeWithGc.ts +2 -1
  169. package/src/summary/summarizerTypes.ts +2 -1
  170. package/src/summary/summaryCollection.ts +6 -2
  171. package/src/summary/summaryGenerator.ts +1 -1
@@ -20,10 +20,11 @@ import { summarizerClientType } from "./summary";
20
20
  * and loads blob.
21
21
  */
22
22
  export class BlobHandle {
23
- constructor(path, routeContext, get) {
23
+ constructor(path, routeContext, get, onAttachGraph) {
24
24
  this.path = path;
25
25
  this.routeContext = routeContext;
26
26
  this.get = get;
27
+ this.onAttachGraph = onAttachGraph;
27
28
  this.attached = false;
28
29
  this.absolutePath = generateHandleContextPath(path, this.routeContext);
29
30
  }
@@ -34,7 +35,11 @@ export class BlobHandle {
34
35
  return this.routeContext.isAttached && this.attached;
35
36
  }
36
37
  attachGraph() {
37
- this.attached = true;
38
+ var _a;
39
+ if (!this.attached) {
40
+ this.attached = true;
41
+ (_a = this.onAttachGraph) === null || _a === void 0 ? void 0 : _a.call(this);
42
+ }
38
43
  }
39
44
  bind(handle) {
40
45
  throw new Error("Cannot bind to blob handle");
@@ -123,6 +128,8 @@ export class BlobManager extends TypedEventEmitter {
123
128
  // Begin uploading stashed blobs from previous container instance
124
129
  Object.entries(stashedBlobs).forEach(([localId, entry]) => {
125
130
  const blob = stringToBuffer(entry.blob, "base64");
131
+ const attached = entry.attached;
132
+ const acked = entry.acked;
126
133
  if (entry.minTTLInSeconds && entry.uploadTime) {
127
134
  const timeLapseSinceLocalUpload = (Date.now() - entry.uploadTime) / 1000;
128
135
  // stashed entries with more than half-life in storage will not be reuploaded
@@ -134,6 +141,8 @@ export class BlobManager extends TypedEventEmitter {
134
141
  uploadP: undefined,
135
142
  uploadTime: entry.uploadTime,
136
143
  minTTLInSeconds: entry.minTTLInSeconds,
144
+ attached,
145
+ acked,
137
146
  });
138
147
  return;
139
148
  }
@@ -143,6 +152,8 @@ export class BlobManager extends TypedEventEmitter {
143
152
  status: PendingBlobStatus.OfflinePendingUpload,
144
153
  handleP: new Deferred(),
145
154
  uploadP: this.uploadBlob(localId, blob),
155
+ attached,
156
+ acked,
146
157
  });
147
158
  });
148
159
  this.sendBlobAttachOp = (localId, blobId) => {
@@ -246,7 +257,14 @@ export class BlobManager extends TypedEventEmitter {
246
257
  }
247
258
  getBlobHandle(id) {
248
259
  assert(this.redirectTable.has(id) || this.pendingBlobs.has(id), 0x384 /* requesting handle for unknown blob */);
249
- return new BlobHandle(`${BlobManager.basePath}/${id}`, this.routeContext, async () => this.getBlob(id));
260
+ const pending = this.pendingBlobs.get(id);
261
+ const callback = pending
262
+ ? () => {
263
+ pending.attached = true;
264
+ this.deletePendingBlobMaybe(id);
265
+ }
266
+ : undefined;
267
+ return new BlobHandle(`${BlobManager.basePath}/${id}`, this.routeContext, async () => this.getBlob(id), callback);
250
268
  }
251
269
  async createBlobDetached(blob) {
252
270
  // Blobs created while the container is detached are stored in IDetachedBlobStorage.
@@ -273,6 +291,8 @@ export class BlobManager extends TypedEventEmitter {
273
291
  status: PendingBlobStatus.OnlinePendingUpload,
274
292
  handleP: new Deferred(),
275
293
  uploadP: this.uploadBlob(localId, blob),
294
+ attached: false,
295
+ acked: false,
276
296
  };
277
297
  this.pendingBlobs.set(localId, pendingEntry);
278
298
  return pendingEntry.handleP.promise;
@@ -287,11 +307,14 @@ export class BlobManager extends TypedEventEmitter {
287
307
  setRedirection(fromId, toId) {
288
308
  this.redirectTable.set(fromId, toId);
289
309
  }
290
- deleteAndEmitsIfEmpty(id) {
310
+ deletePendingBlobMaybe(id) {
291
311
  if (this.pendingBlobs.has(id)) {
292
- this.pendingBlobs.delete(id);
293
- if (!this.hasPendingBlobs) {
294
- this.emit("noPendingBlobs");
312
+ const entry = this.pendingBlobs.get(id);
313
+ if ((entry === null || entry === void 0 ? void 0 : entry.attached) && (entry === null || entry === void 0 ? void 0 : entry.acked)) {
314
+ this.pendingBlobs.delete(id);
315
+ if (!this.hasPendingBlobs) {
316
+ this.emit("noPendingBlobs");
317
+ }
295
318
  }
296
319
  }
297
320
  }
@@ -318,7 +341,7 @@ export class BlobManager extends TypedEventEmitter {
318
341
  // happened before and so, the server won't delete it.
319
342
  this.setRedirection(localId, response.id);
320
343
  entry.handleP.resolve(this.getBlobHandle(localId));
321
- this.deleteAndEmitsIfEmpty(localId);
344
+ this.deletePendingBlobMaybe(localId);
322
345
  }
323
346
  else {
324
347
  // If there is already an op for this storage ID, append the local ID to the list. Once any op for
@@ -422,19 +445,25 @@ export class BlobManager extends TypedEventEmitter {
422
445
  // This is safe because the server will keep the blob alive and the op containing the local ID to
423
446
  // storage ID is already in flight and any op containing this local ID will be sequenced after that.
424
447
  waitingBlobs.forEach((pendingLocalId) => {
425
- const pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);
426
- assert(pendingBlobEntry !== undefined, 0x38f /* local online BlobAttach op with no pending blob entry */);
448
+ const entry = this.pendingBlobs.get(pendingLocalId);
449
+ assert(entry !== undefined, 0x38f /* local online BlobAttach op with no pending blob entry */);
427
450
  // It's possible we transitioned to offline flow while waiting for this op.
428
- if (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {
451
+ if (entry.status === PendingBlobStatus.OnlinePendingOp) {
429
452
  this.setRedirection(pendingLocalId, blobId);
430
- pendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));
431
- this.deleteAndEmitsIfEmpty(pendingLocalId);
453
+ entry.acked = true;
454
+ entry.handleP.resolve(this.getBlobHandle(pendingLocalId));
455
+ this.deletePendingBlobMaybe(pendingLocalId);
432
456
  }
433
457
  });
434
458
  this.opsInFlight.delete(blobId);
435
459
  }
436
- // For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.
437
- this.deleteAndEmitsIfEmpty(localId);
460
+ // offline flow does not resolve the handle (since it was already resolved)
461
+ // but we still need to delete the entry in case is acked and attached.
462
+ const localEntry = this.pendingBlobs.get(localId);
463
+ if (localEntry) {
464
+ localEntry.acked = true;
465
+ this.deletePendingBlobMaybe(localId);
466
+ }
438
467
  }
439
468
  }
440
469
  /**
@@ -655,13 +684,13 @@ export class BlobManager extends TypedEventEmitter {
655
684
  getPendingBlobs() {
656
685
  const blobs = {};
657
686
  for (const [key, entry] of this.pendingBlobs) {
658
- blobs[key] = entry.minTTLInSeconds
659
- ? {
660
- blob: bufferToString(entry.blob, "base64"),
661
- uploadTime: entry.uploadTime,
662
- minTTLInSeconds: entry.minTTLInSeconds,
663
- }
664
- : { blob: bufferToString(entry.blob, "base64") };
687
+ blobs[key] = {
688
+ blob: bufferToString(entry.blob, "base64"),
689
+ attached: entry.attached,
690
+ acked: entry.acked,
691
+ minTTLInSeconds: entry.minTTLInSeconds,
692
+ uploadTime: entry.uploadTime,
693
+ };
665
694
  }
666
695
  return blobs;
667
696
  }
@@ -1 +1 @@
1
- {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"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copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tcreateResponseError,\n\tgenerateHandleContextPath,\n\tresponseToException,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport {\n\tassert,\n\tbufferToString,\n\tDeferred,\n\tstringToBuffer,\n\tTypedEventEmitter,\n} from \"@fluidframework/common-utils\";\nimport {\n\tIContainerRuntime,\n\tIContainerRuntimeEvents,\n} from \"@fluidframework/container-runtime-definitions\";\nimport { AttachState, ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tChildLogger,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { GenericError } from \"@fluidframework/container-utils\";\nimport { ContainerRuntime, TombstoneResponseHeaderKey } from \"./containerRuntime\";\nimport { sendGCUnexpectedUsageEvent, sweepAttachmentBlobsKey, throwOnTombstoneLoadKey } from \"./gc\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\nimport { summarizerClientType } from \"./summary\";\n\n/**\n * This class represents blob (long string)\n * This object is used only when creating (writing) new blob and serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * DataObject.request() recognizes requests in the form of `/blobs/<id>`\n * and loads blob.\n */\nexport class BlobHandle implements IFluidHandle<ArrayBufferLike> {\n\tprivate attached: boolean = false;\n\n\tpublic get IFluidHandle(): IFluidHandle {\n\t\treturn this;\n\t}\n\n\tpublic get isAttached(): boolean {\n\t\treturn this.routeContext.isAttached && this.attached;\n\t}\n\n\tpublic readonly absolutePath: string;\n\n\tconstructor(\n\t\tpublic readonly path: string,\n\t\tpublic readonly routeContext: IFluidHandleContext,\n\t\tpublic get: () => Promise<any>,\n\t) {\n\t\tthis.absolutePath = generateHandleContextPath(path, this.routeContext);\n\t}\n\n\tpublic attachGraph() {\n\t\tthis.attached = true;\n\t}\n\n\tpublic bind(handle: IFluidHandle) {\n\t\tthrow new Error(\"Cannot bind to blob handle\");\n\t}\n}\n\nclass CancellableThrottler {\n\tconstructor(private readonly throttler: IThrottler) {}\n\tprivate cancelP = new Deferred<void>();\n\n\tpublic async getDelay(): Promise<void> {\n\t\treturn Promise.race([\n\t\t\tthis.cancelP.promise,\n\t\t\tnew Promise<void>((resolve) => setTimeout(resolve, this.throttler.getDelay())),\n\t\t]);\n\t}\n\n\tpublic cancel() {\n\t\tthis.cancelP.resolve();\n\t\tthis.cancelP = new Deferred<void>();\n\t}\n}\n\n/**\n * Information from a snapshot needed to load BlobManager\n */\nexport interface IBlobManagerLoadInfo {\n\tids?: string[];\n\tredirectTable?: [string, string][];\n}\n\n// Restrict the IContainerRuntime interface to the subset required by BlobManager. This helps to make\n// the contract explicit and reduces the amount of mocking required for tests.\nexport type IBlobManagerRuntime = Pick<\n\tIContainerRuntime,\n\t\"attachState\" | \"connected\" | \"logger\" | \"clientDetails\"\n> &\n\tPick<ContainerRuntime, \"gcTombstoneEnforcementAllowed\"> &\n\tTypedEventEmitter<IContainerRuntimeEvents>;\n\n// Note that while offline we \"submit\" an op before uploading the blob, but we always\n// expect blobs to be uploaded before we actually see the op round-trip\nenum PendingBlobStatus {\n\tOnlinePendingUpload,\n\tOnlinePendingOp,\n\tOfflinePendingUpload,\n\tOfflinePendingOp,\n}\n\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse & Partial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n\tblob: ArrayBufferLike;\n\tstatus: PendingBlobStatus;\n\tstorageId?: string;\n\thandleP: Deferred<IFluidHandle<ArrayBufferLike>>;\n\tuploadP?: Promise<ICreateBlobResponse>;\n\tuploadTime?: number;\n\tminTTLInSeconds?: number;\n}\n\nexport interface IPendingBlobs {\n\t[id: string]: { blob: string; uploadTime?: number; minTTLInSeconds?: number };\n}\n\nexport interface IBlobManagerEvents {\n\t(event: \"noPendingBlobs\", listener: () => void);\n}\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\n\tpublic static readonly basePath = \"_blobs\";\n\tprivate static readonly redirectTableBlobName = \".redirectTable\";\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should\n\t * be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which\n\t * gives local IDs; the storage IDs are filled in at attach time.\n\t * Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client\n\t * that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.\n\t */\n\tprivate readonly redirectTable: Map<string, string | undefined>;\n\n\t/**\n\t * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.\n\t * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so\n\t * we must save it. This is true for both the online and offline flow.\n\t */\n\tprivate readonly pendingBlobs: Map<string, PendingBlob> = new Map();\n\n\t/**\n\t * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,\n\t * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's\n\t * because we know that the server will not delete the blob corresponding to that storage ID.\n\t */\n\tprivate readonly opsInFlight: Map<string, string[]> = new Map();\n\n\tprivate readonly retryThrottler = new CancellableThrottler(\n\t\tnew Throttler(\n\t\t\t60 * 1000, // 60 sec delay window\n\t\t\t30 * 1000, // 30 sec max delay\n\t\t\t// throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)\n\t\t\tformExponentialFn({ coefficient: 20, initialDelay: 0 }),\n\t\t),\n\t);\n\n\t/** If true, throw an error when a tombstone attachment blob is retrieved. */\n\tprivate readonly throwOnTombstoneLoad: boolean;\n\t/**\n\t * This stores IDs of tombstoned blobs.\n\t * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.\n\t */\n\tprivate readonly tombstonedBlobs: Set<string> = new Set();\n\n\tprivate readonly sendBlobAttachOp: (localId: string, storageId?: string) => void;\n\n\tconstructor(\n\t\tprivate readonly routeContext: IFluidHandleContext,\n\t\tsnapshot: IBlobManagerLoadInfo,\n\t\tprivate readonly getStorage: () => IDocumentStorageService,\n\t\t/**\n\t\t * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is\n\t\t * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the\n\t\t * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to\n\t\t * include the storage ID in the summary when it sees the op.\n\t\t *\n\t\t * The op will also include a local ID to inform all clients of the relation to the storage ID, without\n\t\t * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced\n\t\t * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.\n\t\t */\n\t\tsendBlobAttachOp: (localId: string, storageId?: string) => void,\n\t\t// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly blobRequested: (blobPath: string) => void,\n\t\t// Called to check if a blob has been deleted by GC.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly isBlobDeleted: (blobPath: string) => boolean,\n\t\tprivate readonly runtime: IBlobManagerRuntime,\n\t\tstashedBlobs: IPendingBlobs = {},\n\t\tprivate readonly closeContainer: (error?: ICriticalContainerError) => void,\n\t) {\n\t\tsuper();\n\t\tthis.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, \"BlobManager\"));\n\t\t// Read the feature flag that tells whether to throw when a tombstone blob is requested.\n\t\tthis.throwOnTombstoneLoad =\n\t\t\tthis.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&\n\t\t\tthis.runtime.gcTombstoneEnforcementAllowed &&\n\t\t\tthis.runtime.clientDetails.type !== summarizerClientType;\n\n\t\tthis.runtime.on(\"disconnected\", () => this.onDisconnected());\n\t\tthis.redirectTable = this.load(snapshot);\n\n\t\t// Begin uploading stashed blobs from previous container instance\n\t\tObject.entries(stashedBlobs).forEach(([localId, entry]) => {\n\t\t\tconst blob = stringToBuffer(entry.blob, \"base64\");\n\t\t\tif (entry.minTTLInSeconds && entry.uploadTime) {\n\t\t\t\tconst timeLapseSinceLocalUpload = (Date.now() - entry.uploadTime) / 1000;\n\t\t\t\t// stashed entries with more than half-life in storage will not be reuploaded\n\t\t\t\tif (entry.minTTLInSeconds - timeLapseSinceLocalUpload > entry.minTTLInSeconds / 2) {\n\t\t\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\t\t\tblob,\n\t\t\t\t\t\tstatus: PendingBlobStatus.OfflinePendingOp,\n\t\t\t\t\t\thandleP: new Deferred(),\n\t\t\t\t\t\tuploadP: undefined,\n\t\t\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\tblob,\n\t\t\t\tstatus: PendingBlobStatus.OfflinePendingUpload,\n\t\t\t\thandleP: new Deferred(),\n\t\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t\t});\n\t\t});\n\n\t\tthis.sendBlobAttachOp = (localId: string, blobId?: string) => {\n\t\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\t\tif (pendingEntry?.uploadTime && pendingEntry?.minTTLInSeconds) {\n\t\t\t\tconst secondsSinceUpload = (Date.now() - pendingEntry.uploadTime) / 1000;\n\t\t\t\tconst expired = pendingEntry.minTTLInSeconds - secondsSinceUpload < 0;\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"sendBlobAttach\",\n\t\t\t\t\tentryStatus: pendingEntry.status,\n\t\t\t\t\tsecondsSinceUpload,\n\t\t\t\t\tminTTLInSeconds: pendingEntry.minTTLInSeconds,\n\t\t\t\t\texpired,\n\t\t\t\t});\n\t\t\t\tif (expired) {\n\t\t\t\t\t// we want to avoid submitting ops with broken handles\n\t\t\t\t\tthis.closeContainer(\n\t\t\t\t\t\tnew GenericError(\n\t\t\t\t\t\t\t\"Trying to submit a BlobAttach for expired blob\",\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlocalId,\n\t\t\t\t\t\t\t\tblobId,\n\t\t\t\t\t\t\t\tentryStatus: pendingEntry.status,\n\t\t\t\t\t\t\t\tsecondsSinceUpload,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sendBlobAttachOp(localId, blobId);\n\t\t};\n\t}\n\n\tprivate get pendingOfflineUploads() {\n\t\treturn Array.from(this.pendingBlobs.values()).filter(\n\t\t\t(e) => e.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t);\n\t}\n\n\tpublic get hasPendingOfflineUploads(): boolean {\n\t\treturn this.pendingOfflineUploads.length > 0;\n\t}\n\n\tpublic get hasPendingBlobs(): boolean {\n\t\treturn (\n\t\t\t(this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||\n\t\t\tthis.pendingBlobs.size > 0\n\t\t);\n\t}\n\n\t/**\n\t * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n\t */\n\tpublic async onConnected() {\n\t\tthis.retryThrottler.cancel();\n\t\tconst pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);\n\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"BlobUploadOnConnected\",\n\t\t\t\tcount: pendingUploads.length,\n\t\t\t},\n\t\t\tasync () => Promise.all(pendingUploads),\n\t\t\t{ start: true, end: true },\n\t\t);\n\t}\n\n\t/**\n\t * Transition online blobs waiting for BlobAttach op round-trip since we will not see the op until we are connected\n\t * again\n\t */\n\tprivate onDisconnected() {\n\t\tfor (const [localId, entry] of this.pendingBlobs) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t// This will submit another BlobAttach op for this blob. This is necessary because the one we sent\n\t\t\t\t// already didn't have the local ID.\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is\n\t * detached or there are no (non-pending) attachment blobs in the document\n\t */\n\tprivate get storageIds(): Set<string> {\n\t\tconst ids = new Set<string | undefined>(this.redirectTable.values());\n\n\t\t// If we are detached, we will not have storage IDs, only undefined\n\t\tconst undefinedValueInTable = ids.delete(undefined);\n\n\t\t// For a detached container, entries are inserted into the redirect table with an undefined storage ID.\n\t\t// For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.\n\t\tassert(\n\t\t\t!undefinedValueInTable ||\n\t\t\t\t(this.runtime.attachState === AttachState.Detached && ids.size === 0),\n\t\t\t0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */,\n\t\t);\n\n\t\treturn ids as Set<string>;\n\t}\n\n\tpublic async getBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\t// Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,\n\t\t// failing the call.\n\t\tthis.verifyBlobValidity(blobId);\n\n\t\tconst pending = this.pendingBlobs.get(blobId);\n\t\tif (pending) {\n\t\t\treturn pending.blob;\n\t\t}\n\t\tlet storageId: string;\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tassert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);\n\n\t\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t\t// The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.\n\t\t\tstorageId = blobId;\n\t\t} else {\n\t\t\tconst attachedStorageId = this.redirectTable.get(blobId);\n\t\t\tassert(!!attachedStorageId, 0x11f /* \"requesting unknown blobs\" */);\n\t\t\tstorageId = attachedStorageId;\n\t\t}\n\n\t\t// Let runtime know that the corresponding GC node was requested.\n\t\tthis.blobRequested(getGCNodePathFromBlobId(blobId));\n\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"AttachmentReadBlob\", id: storageId },\n\t\t\tasync () => {\n\t\t\t\treturn this.getStorage().readBlob(storageId);\n\t\t\t},\n\t\t\t{ end: true, cancel: \"error\" },\n\t\t);\n\t}\n\n\tprivate getBlobHandle(id: string): IFluidHandle<ArrayBufferLike> {\n\t\tassert(\n\t\t\tthis.redirectTable.has(id) || this.pendingBlobs.has(id),\n\t\t\t0x384 /* requesting handle for unknown blob */,\n\t\t);\n\t\treturn new BlobHandle(`${BlobManager.basePath}/${id}`, this.routeContext, async () =>\n\t\t\tthis.getBlob(id),\n\t\t);\n\t}\n\n\tprivate async createBlobDetached(\n\t\tblob: ArrayBufferLike,\n\t): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.\n\t\tconst response = await this.getStorage().createBlob(blob);\n\t\tthis.setRedirection(response.id, undefined);\n\t\treturn this.getBlobHandle(response.id);\n\t}\n\n\tpublic async createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn this.createBlobDetached(blob);\n\t\t}\n\t\tif (this.runtime.attachState === AttachState.Attaching) {\n\t\t\t// blob upload is not supported in \"Attaching\" state\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"CreateBlobWhileAttaching\" });\n\t\t\tawait new Promise<void>((resolve) => this.runtime.once(\"attached\", resolve));\n\t\t}\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Attached,\n\t\t\t0x385 /* For clarity and paranoid defense against adding future attachment states */,\n\t\t);\n\n\t\t// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to\n\t\t// storage ID mapping is created.\n\t\tconst localId = uuid();\n\t\tconst pendingEntry: PendingBlob = {\n\t\t\tblob,\n\t\t\tstatus: PendingBlobStatus.OnlinePendingUpload,\n\t\t\thandleP: new Deferred(),\n\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t};\n\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\treturn pendingEntry.handleP.promise;\n\t}\n\n\tprivate async uploadBlob(localId: string, blob: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"createBlob\" },\n\t\t\tasync () => this.getStorage().createBlob(blob),\n\t\t\t{ end: true, cancel: this.runtime.connected ? \"error\" : \"generic\" },\n\t\t).then(\n\t\t\t(response) => this.onUploadResolve(localId, response),\n\t\t\tasync (err) => this.onUploadReject(localId, err),\n\t\t);\n\t}\n\n\t/**\n\t * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added\n\t * which is required for GC.\n\t */\n\tprivate setRedirection(fromId: string, toId: string | undefined) {\n\t\tthis.redirectTable.set(fromId, toId);\n\t}\n\n\tprivate deleteAndEmitsIfEmpty(id: string) {\n\t\tif (this.pendingBlobs.has(id)) {\n\t\t\tthis.pendingBlobs.delete(id);\n\t\t\tif (!this.hasPendingBlobs) {\n\t\t\t\tthis.emit(\"noPendingBlobs\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onUploadResolve(localId: string, response: ICreateBlobResponseWithTTL) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(entry !== undefined, 0x6c8 /* pending blob entry not found for uploaded blob */);\n\t\tassert(\n\t\t\tentry.status === PendingBlobStatus.OnlinePendingUpload ||\n\t\t\t\tentry.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t\t0x386 /* Must have pending blob entry for uploaded blob */,\n\t\t);\n\t\tentry.storageId = response.id;\n\t\tentry.uploadTime = Date.now();\n\t\tentry.minTTLInSeconds = response.minTTLInSeconds;\n\t\tif (this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\t// Send a blob attach op. This serves two purposes:\n\t\t\t\t// 1. If its a new blob, i.e., it isn't de-duped, the server will keep the blob alive if it sees this op\n\t\t\t\t// until its storage ID is added to the next summary.\n\t\t\t\t// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the\n\t\t\t\t// blob from the server via the storage ID.\n\t\t\t\tthis.sendBlobAttachOp(localId, response.id);\n\t\t\t\tif (this.storageIds.has(response.id)) {\n\t\t\t\t\t// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is\n\t\t\t\t\t// an existing blob, we don't have to wait for the op to be ack'd since this step has already\n\t\t\t\t\t// happened before and so, the server won't delete it.\n\t\t\t\t\tthis.setRedirection(localId, response.id);\n\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\t\t\tthis.deleteAndEmitsIfEmpty(localId);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is already an op for this storage ID, append the local ID to the list. Once any op for\n\t\t\t\t\t// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n\t\t\t\t\t// blob alive in storage.\n\t\t\t\t\tthis.opsInFlight.set(\n\t\t\t\t\t\tresponse.id,\n\t\t\t\t\t\t(this.opsInFlight.get(response.id) ?? []).concat(localId),\n\t\t\t\t\t);\n\t\t\t\t\tentry.status = PendingBlobStatus.OnlinePendingOp;\n\t\t\t\t}\n\t\t\t} else if (entry.status === PendingBlobStatus.OfflinePendingUpload) {\n\t\t\t\t// We already submitted a BlobAttach op for this blob when it was transitioned to offline flow\n\t\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t\t}\n\t\t} else {\n\t\t\t// connected to storage but not ordering service?\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"BlobUploadSuccessWhileDisconnected\" });\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t}\n\t\treturn response;\n\t}\n\n\tprivate async onUploadReject(localId: string, error) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);\n\t\tif (!this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\t// we are probably not connected to storage but start another upload request in case we are\n\t\t\tentry.uploadP = this.retryThrottler\n\t\t\t\t.getDelay()\n\t\t\t\t.then(async () => this.uploadBlob(localId, entry.blob));\n\t\t\treturn entry.uploadP;\n\t\t} else {\n\t\t\tentry.handleP.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate transitionToOffline(localId: string) {\n\t\tassert(\n\t\t\t!this.runtime.connected,\n\t\t\t0x388 /* Must only transition to offline flow while runtime is disconnected */,\n\t\t);\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x389 /* No pending blob entry */);\n\t\tassert(\n\t\t\t[PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(\n\t\t\t\tentry.status,\n\t\t\t),\n\t\t\t0x38a /* Blob must be in online flow to transition to offline flow */,\n\t\t);\n\n\t\t/**\n\t\t * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.\n\t\t * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,\n\t\t * an invalid handle could be added to the document.\n\t\t * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n\t\t * is called on reconnection.\n\t\t */\n\t\tif (entry.status !== PendingBlobStatus.OnlinePendingOp) {\n\t\t\tthis.sendBlobAttachOp(localId, entry.storageId);\n\t\t}\n\n\t\tentry.status =\n\t\t\tentry.status === PendingBlobStatus.OnlinePendingUpload\n\t\t\t\t? PendingBlobStatus.OfflinePendingUpload\n\t\t\t\t: PendingBlobStatus.OfflinePendingOp;\n\n\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t}\n\n\t/**\n\t * Resubmit a BlobAttach op. Used to add storage IDs to ops that were\n\t * submitted to runtime while disconnected.\n\t * @param metadata - op metadata containing storage and/or local IDs\n\t */\n\tpublic reSubmit(metadata: Record<string, unknown> | undefined) {\n\t\tassert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);\n\t\tconst { localId, blobId }: { localId?: string; blobId?: string } = metadata;\n\t\tassert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);\n\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\n\t\tif (!blobId) {\n\t\t\t// We submitted this op while offline. The blob should have been uploaded by now.\n\t\t\tassert(\n\t\t\t\tpendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n\t\t\t\t\t!!pendingEntry?.storageId,\n\t\t\t\t0x38d /* blob must be uploaded before resubmitting BlobAttach op */,\n\t\t\t);\n\t\t\treturn this.sendBlobAttachOp(localId, pendingEntry.storageId);\n\t\t}\n\t\treturn this.sendBlobAttachOp(localId, blobId);\n\t}\n\n\tpublic processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n\t\tconst localId = message.metadata?.localId;\n\t\tconst blobId = message.metadata?.blobId;\n\t\tassert(blobId !== undefined, 0x12a /* \"Missing blob id on metadata\" */);\n\n\t\t// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be\n\t\t// requested from the server.\n\t\t// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that\n\t\t// was sent when online.\n\t\tif (localId !== undefined) {\n\t\t\tthis.setRedirection(localId, blobId);\n\t\t}\n\t\t// set identity (id -> id) entry\n\t\tthis.setRedirection(blobId, blobId);\n\n\t\tif (local) {\n\t\t\tassert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);\n\t\t\tconst waitingBlobs = this.opsInFlight.get(blobId);\n\t\t\tif (waitingBlobs !== undefined) {\n\t\t\t\t// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.\n\t\t\t\t// This is safe because the server will keep the blob alive and the op containing the local ID to\n\t\t\t\t// storage ID is already in flight and any op containing this local ID will be sequenced after that.\n\t\t\t\twaitingBlobs.forEach((pendingLocalId) => {\n\t\t\t\t\tconst pendingBlobEntry = this.pendingBlobs.get(pendingLocalId);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tpendingBlobEntry !== undefined,\n\t\t\t\t\t\t0x38f /* local online BlobAttach op with no pending blob entry */,\n\t\t\t\t\t);\n\n\t\t\t\t\t// It's possible we transitioned to offline flow while waiting for this op.\n\t\t\t\t\tif (pendingBlobEntry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t\t\tthis.setRedirection(pendingLocalId, blobId);\n\t\t\t\t\t\tpendingBlobEntry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n\t\t\t\t\t\tthis.deleteAndEmitsIfEmpty(pendingLocalId);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tthis.opsInFlight.delete(blobId);\n\t\t\t}\n\t\t\t// For blobs that were transitioned to offline flow while waiting for this op, the entry should be deleted.\n\t\t\tthis.deleteAndEmitsIfEmpty(localId);\n\t\t}\n\t}\n\n\t/**\n\t * Reads blobs needed to load BlobManager from storage.\n\t * @param blobsTree - Tree containing IDs of previously attached blobs. We\n\t * look for the IDs in the blob entries of the tree since the both the r11s\n\t * and SPO drivers replace the attachment types returned in snapshot() with blobs.\n\t */\n\tpublic static async load(\n\t\tblobsTree: ISnapshotTree | undefined,\n\t\ttryFetchBlob: (id: string) => Promise<[string, string][]>,\n\t): Promise<IBlobManagerLoadInfo> {\n\t\tif (!blobsTree) {\n\t\t\treturn {};\n\t\t}\n\t\tlet redirectTable;\n\t\tconst tableId = blobsTree.blobs[this.redirectTableBlobName];\n\t\tif (tableId) {\n\t\t\tredirectTable = await tryFetchBlob(tableId);\n\t\t}\n\t\tconst ids = Object.entries(blobsTree.blobs)\n\t\t\t.filter(([k, _]) => k !== this.redirectTableBlobName)\n\t\t\t.map(([_, v]) => v);\n\t\treturn { ids, redirectTable };\n\t}\n\n\t/**\n\t * Load a set of previously attached blob IDs and redirect table from a previous snapshot.\n\t */\n\tprivate load(snapshot: IBlobManagerLoadInfo): Map<string, string | undefined> {\n\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\teventName: \"AttachmentBlobsLoaded\",\n\t\t\tcount: snapshot.ids?.length ?? 0,\n\t\t\tredirectTable: snapshot.redirectTable?.length,\n\t\t});\n\t\tconst table = new Map<string, string | undefined>(snapshot.redirectTable);\n\t\tif (snapshot.ids) {\n\t\t\tconst detached = this.runtime.attachState === AttachState.Detached;\n\t\t\t// If we are detached, we don't have storage IDs yet, so set to undefined\n\t\t\t// Otherwise, set identity (id -> id) entries\n\t\t\tsnapshot.ids.forEach((entry) => table.set(entry, detached ? undefined : entry));\n\t\t}\n\t\treturn table;\n\t}\n\n\tpublic summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n\t\t// if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached\n\t\tconst blobIds =\n\t\t\tthis.storageIds.size > 0\n\t\t\t\t? Array.from(this.storageIds)\n\t\t\t\t: Array.from(this.redirectTable.keys());\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tblobIds.forEach((blobId) => {\n\t\t\tbuilder.addAttachment(blobId);\n\t\t});\n\n\t\t// Any non-identity entries in the table need to be saved in the summary\n\t\tif (this.redirectTable.size > blobIds.length) {\n\t\t\tbuilder.addBlob(\n\t\t\t\tBlobManager.redirectTableBlobName,\n\t\t\t\t// filter out identity entries\n\t\t\t\tJSON.stringify(\n\t\t\t\t\tArray.from(this.redirectTable.entries()).filter(\n\t\t\t\t\t\t([localId, storageId]) => localId !== storageId,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be\n\t * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.\n\t * @param fullGC - true to bypass optimizations and force full generation of GC data. BlobManager doesn't care\n\t * about this for now because the data is a simple list of blob ids.\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\tconst gcData: IGarbageCollectionData = { gcNodes: {} };\n\t\tfor (const [localId, storageId] of this.redirectTable) {\n\t\t\tassert(!!storageId, 0x390 /* Must be attached to get GC data */);\n\t\t\t// Only return local ids as GC nodes because a blob can only be referenced via its local id. The storage\n\t\t\t// id entries have the same key and value, ignore them.\n\t\t\t// The outbound routes are empty because a blob node cannot reference other nodes. It can only be referenced\n\t\t\t// by adding its handle to a referenced DDS.\n\t\t\tif (localId !== storageId) {\n\t\t\t\tgcData.gcNodes[getGCNodePathFromBlobId(localId)] = [];\n\t\t\t}\n\t\t}\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are unused. The unused blobs are deleted.\n\t * @param unusedRoutes - The routes of the blob nodes that are unused. These routes will be based off of local ids.\n\t */\n\tpublic updateUnusedRoutes(unusedRoutes: string[]): void {\n\t\tthis.deleteBlobsFromRedirectTable(unusedRoutes);\n\t}\n\n\t/**\n\t * Delete attachment blobs that are sweep ready.\n\t * @param sweepReadyBlobRoutes - The routes of blobs that are sweep ready and should be deleted. These routes will\n\t * be based off of local ids.\n\t * @returns - The routes of blobs that were deleted.\n\t */\n\tpublic deleteSweepReadyNodes(sweepReadyBlobRoutes: string[]): string[] {\n\t\t// If sweep for attachment blobs is not enabled, return empty list indicating nothing is deleted.\n\t\tif (this.mc.config.getBoolean(sweepAttachmentBlobsKey) !== true) {\n\t\t\treturn [];\n\t\t}\n\n\t\tthis.deleteBlobsFromRedirectTable(sweepReadyBlobRoutes);\n\t\treturn Array.from(sweepReadyBlobRoutes);\n\t}\n\n\t/**\n\t * Delete blobs with the given routes from the redirect table.\n\t * The routes are GC nodes paths of format -`/<BlobManager.basePath>/<blobId>`. The blob ids are all local ids.\n\t * Deleting the blobs involves 2 steps:\n\t * 1. The redirect table entry for the local ids are deleted.\n\t * 2. If the storage ids corresponding to the deleted local ids are not in-use anymore, the redirect table entries\n\t * for the storage ids are deleted as well.\n\t *\n\t * Note that this does not delete the blobs from storage service immediately. Deleting the blobs from redirect table\n\t * will remove them the next summary. The service would them delete them some time in the future.\n\t */\n\tprivate deleteBlobsFromRedirectTable(blobRoutes: string[]) {\n\t\tif (blobRoutes.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// This tracks the storage ids of local ids that are deleted. After the local ids have been deleted, if any of\n\t\t// these storage ids are unused, they will be deleted as well.\n\t\tconst maybeUnusedStorageIds: Set<string> = new Set();\n\t\tfor (const route of blobRoutes) {\n\t\t\tconst blobId = getBlobIdFromGCNodePath(route);\n\t\t\tif (!this.redirectTable.has(blobId)) {\n\t\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"DeletedAttachmentBlobNotFound\",\n\t\t\t\t\tblobId,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst storageId = this.redirectTable.get(blobId);\n\t\t\tassert(!!storageId, 0x5bb /* Must be attached to run GC */);\n\t\t\tmaybeUnusedStorageIds.add(storageId);\n\t\t\tthis.redirectTable.delete(blobId);\n\t\t}\n\n\t\t// Find out storage ids that are in-use and remove them from maybeUnusedStorageIds. A storage id is in-use if\n\t\t// the redirect table has a local id -> storage id entry for it.\n\t\tfor (const [localId, storageId] of this.redirectTable.entries()) {\n\t\t\tassert(!!storageId, 0x5bc /* Must be attached to run GC */);\n\t\t\t// For every storage id, the redirect table has a id -> id entry. These do not make the storage id in-use.\n\t\t\tif (maybeUnusedStorageIds.has(storageId) && localId !== storageId) {\n\t\t\t\tmaybeUnusedStorageIds.delete(storageId);\n\t\t\t}\n\t\t}\n\n\t\t// For unused storage ids, delete their id -> id entries from the redirect table.\n\t\t// This way they'll be absent from the next summary, and the service is free to delete them from storage.\n\t\tfor (const storageId of maybeUnusedStorageIds) {\n\t\t\tthis.redirectTable.delete(storageId);\n\t\t}\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with\n\t * accessing deleted content without actually deleting content from summaries.\n\t * @param tombstonedRoutes - The routes of blob nodes that are tombstones.\n\t */\n\tpublic updateTombstonedRoutes(tombstonedRoutes: string[]) {\n\t\tconst tombstonedBlobsSet: Set<string> = new Set();\n\t\t// The routes or blob node paths are in the same format as returned in getGCData -\n\t\t// `/<BlobManager.basePath>/<blobId>`.\n\t\tfor (const route of tombstonedRoutes) {\n\t\t\tconst blobId = getBlobIdFromGCNodePath(route);\n\t\t\ttombstonedBlobsSet.add(blobId);\n\t\t}\n\n\t\t// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.\n\t\tfor (const blobId of this.tombstonedBlobs) {\n\t\t\tif (!tombstonedBlobsSet.has(blobId)) {\n\t\t\t\tthis.tombstonedBlobs.delete(blobId);\n\t\t\t}\n\t\t}\n\n\t\t// Mark blobs that are now tombstoned by adding them to the tombstone list.\n\t\tfor (const blobId of tombstonedBlobsSet) {\n\t\t\tthis.tombstonedBlobs.add(blobId);\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,\n\t * log an error and throw if necessary.\n\t */\n\tprivate verifyBlobValidity(blobId: string) {\n\t\t/**\n\t\t * A blob can be in one of the following states:\n\t\t * 1. \"deleted\" - It has been deleted by garbage collection sweep phase.\n\t\t * 2. \"tombstoned\" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.\n\t\t * 3. \"valid\" - It has not been deleted or tombstoned.\n\t\t */\n\t\tlet state: \"valid\" | \"tombstoned\" | \"deleted\" = \"valid\";\n\t\tif (this.isBlobDeleted(getGCNodePathFromBlobId(blobId))) {\n\t\t\tstate = \"deleted\";\n\t\t} else if (this.tombstonedBlobs.has(blobId)) {\n\t\t\tstate = \"tombstoned\";\n\t\t}\n\n\t\tif (state === \"valid\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt\n\t\t// to load the blob.\n\t\tconst shouldFail = state === \"deleted\" || this.throwOnTombstoneLoad;\n\t\tconst request = { url: blobId };\n\t\tconst error = responseToException(\n\t\t\tcreateResponseError(\n\t\t\t\t404,\n\t\t\t\t\"Blob was deleted\",\n\t\t\t\trequest,\n\t\t\t\tstate === \"tombstoned\" ? { [TombstoneResponseHeaderKey]: true } : undefined,\n\t\t\t),\n\t\t\trequest,\n\t\t);\n\t\tsendGCUnexpectedUsageEvent(\n\t\t\tthis.mc,\n\t\t\t{\n\t\t\t\teventName:\n\t\t\t\t\tstate === \"tombstoned\"\n\t\t\t\t\t\t? \"GC_Tombstone_Blob_Requested\"\n\t\t\t\t\t\t: \"GC_Deleted_Blob_Requested\",\n\t\t\t\tcategory: shouldFail ? \"error\" : \"generic\",\n\t\t\t\tgcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,\n\t\t\t},\n\t\t\t[BlobManager.basePath],\n\t\t\terror,\n\t\t);\n\t\tif (shouldFail) {\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic setRedirectTable(table: Map<string, string>) {\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Detached,\n\t\t\t0x252 /* \"redirect table can only be set in detached container\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.redirectTable.size === table.size,\n\t\t\t0x391 /* Redirect table size must match BlobManager's local ID count */,\n\t\t);\n\t\tfor (const [localId, storageId] of table) {\n\t\t\tassert(\n\t\t\t\tthis.redirectTable.has(localId),\n\t\t\t\t0x254 /* \"unrecognized id in redirect table\" */,\n\t\t\t);\n\t\t\tthis.setRedirection(localId, storageId);\n\t\t\t// set identity (id -> id) entry\n\t\t\tthis.setRedirection(storageId, storageId);\n\t\t}\n\t}\n\n\tpublic getPendingBlobs(): IPendingBlobs {\n\t\tconst blobs = {};\n\t\tfor (const [key, entry] of this.pendingBlobs) {\n\t\t\tblobs[key] = entry.minTTLInSeconds\n\t\t\t\t? {\n\t\t\t\t\t\tblob: bufferToString(entry.blob, \"base64\"),\n\t\t\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\t }\n\t\t\t\t: { blob: bufferToString(entry.blob, \"base64\") };\n\t\t}\n\t\treturn blobs;\n\t}\n}\n\n/**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`.\n * This path must match the path of the blob handle returned by the createBlob API because blobs are marked\n * referenced by storing these handles in a referenced DDS.\n */\nfunction getGCNodePathFromBlobId(blobId: string) {\n\treturn `/${BlobManager.basePath}/${blobId}`;\n}\n\n/**\n * For a given GC node path, return the blobId. The node path is of the format `/<BlobManager.basePath>/<blobId>`.\n */\nfunction getBlobIdFromGCNodePath(nodePath: string) {\n\tconst pathParts = nodePath.split(\"/\");\n\tassert(\n\t\tpathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n\t\t0x5bd /* Invalid blob node path */,\n\t);\n\treturn pathParts[2];\n}\n"]}
1
+ {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../src/blobManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAQlC,OAAO,EACN,mBAAmB,EACnB,yBAAyB,EACzB,mBAAmB,EACnB,kBAAkB,GAClB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,MAAM,EACN,cAAc,EACd,QAAQ,EACR,cAAc,EACd,iBAAiB,GACjB,MAAM,8BAA8B,CAA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Q,EAAE,KAAK,CAAC,QAAQ;gBACxB,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,eAAe,EAAE,KAAK,CAAC,eAAe;gBACtC,UAAU,EAAE,KAAK,CAAC,UAAU;aAC5B,CAAC;SACF;QACD,OAAO,KAAK,CAAC;IACd,CAAC;;AA3xBsB,oBAAQ,GAAG,QAAQ,CAAC;AACnB,iCAAqB,GAAG,gBAAgB,CAAC;AA6xBlE;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,MAAc;IAC9C,OAAO,IAAI,WAAW,CAAC,QAAQ,IAAI,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,QAAgB;IAChD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,MAAM,CACL,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,QAAQ,EAC/D,KAAK,CAAC,4BAA4B,CAClC,CAAC;IACF,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { IDocumentStorageService } from \"@fluidframework/driver-definitions\";\nimport {\n\tICreateBlobResponse,\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\tcreateResponseError,\n\tgenerateHandleContextPath,\n\tresponseToException,\n\tSummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport {\n\tassert,\n\tbufferToString,\n\tDeferred,\n\tstringToBuffer,\n\tTypedEventEmitter,\n} from \"@fluidframework/common-utils\";\nimport {\n\tIContainerRuntime,\n\tIContainerRuntimeEvents,\n} from \"@fluidframework/container-runtime-definitions\";\nimport { AttachState, ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tChildLogger,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tPerformanceEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { GenericError } from \"@fluidframework/container-utils\";\nimport { ContainerRuntime, TombstoneResponseHeaderKey } from \"./containerRuntime\";\nimport { sendGCUnexpectedUsageEvent, sweepAttachmentBlobsKey, throwOnTombstoneLoadKey } from \"./gc\";\nimport { Throttler, formExponentialFn, IThrottler } from \"./throttler\";\nimport { summarizerClientType } from \"./summary\";\nimport { IBlobMetadata } from \"./metadata\";\n\n/**\n * This class represents blob (long string)\n * This object is used only when creating (writing) new blob and serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * DataObject.request() recognizes requests in the form of `/blobs/<id>`\n * and loads blob.\n */\nexport class BlobHandle implements IFluidHandle<ArrayBufferLike> {\n\tprivate attached: boolean = false;\n\n\tpublic get IFluidHandle(): IFluidHandle {\n\t\treturn this;\n\t}\n\n\tpublic get isAttached(): boolean {\n\t\treturn this.routeContext.isAttached && this.attached;\n\t}\n\n\tpublic readonly absolutePath: string;\n\n\tconstructor(\n\t\tpublic readonly path: string,\n\t\tpublic readonly routeContext: IFluidHandleContext,\n\t\tpublic get: () => Promise<any>,\n\t\tprivate readonly onAttachGraph?: () => void,\n\t) {\n\t\tthis.absolutePath = generateHandleContextPath(path, this.routeContext);\n\t}\n\n\tpublic attachGraph() {\n\t\tif (!this.attached) {\n\t\t\tthis.attached = true;\n\t\t\tthis.onAttachGraph?.();\n\t\t}\n\t}\n\n\tpublic bind(handle: IFluidHandle) {\n\t\tthrow new Error(\"Cannot bind to blob handle\");\n\t}\n}\n\nclass CancellableThrottler {\n\tconstructor(private readonly throttler: IThrottler) {}\n\tprivate cancelP = new Deferred<void>();\n\n\tpublic async getDelay(): Promise<void> {\n\t\treturn Promise.race([\n\t\t\tthis.cancelP.promise,\n\t\t\tnew Promise<void>((resolve) => setTimeout(resolve, this.throttler.getDelay())),\n\t\t]);\n\t}\n\n\tpublic cancel() {\n\t\tthis.cancelP.resolve();\n\t\tthis.cancelP = new Deferred<void>();\n\t}\n}\n\n/**\n * Information from a snapshot needed to load BlobManager\n */\nexport interface IBlobManagerLoadInfo {\n\tids?: string[];\n\tredirectTable?: [string, string][];\n}\n\n// Restrict the IContainerRuntime interface to the subset required by BlobManager. This helps to make\n// the contract explicit and reduces the amount of mocking required for tests.\nexport type IBlobManagerRuntime = Pick<\n\tIContainerRuntime,\n\t\"attachState\" | \"connected\" | \"logger\" | \"clientDetails\"\n> &\n\tPick<ContainerRuntime, \"gcTombstoneEnforcementAllowed\"> &\n\tTypedEventEmitter<IContainerRuntimeEvents>;\n\n// Note that while offline we \"submit\" an op before uploading the blob, but we always\n// expect blobs to be uploaded before we actually see the op round-trip\nenum PendingBlobStatus {\n\tOnlinePendingUpload,\n\tOnlinePendingOp,\n\tOfflinePendingUpload,\n\tOfflinePendingOp,\n}\n\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse & Partial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n\tblob: ArrayBufferLike;\n\tstatus: PendingBlobStatus;\n\tstorageId?: string;\n\thandleP: Deferred<BlobHandle>;\n\tuploadP?: Promise<ICreateBlobResponse>;\n\tuploadTime?: number;\n\tminTTLInSeconds?: number;\n\tattached?: boolean;\n\tacked?: boolean;\n}\n\nexport interface IPendingBlobs {\n\t[id: string]: {\n\t\tblob: string;\n\t\tuploadTime?: number;\n\t\tminTTLInSeconds?: number;\n\t\tattached?: boolean;\n\t\tacked?: boolean;\n\t};\n}\n\nexport interface IBlobManagerEvents {\n\t(event: \"noPendingBlobs\", listener: () => void);\n}\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\n\tpublic static readonly basePath = \"_blobs\";\n\tprivate static readonly redirectTableBlobName = \".redirectTable\";\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Map of local IDs to storage IDs. Contains identity entries (id → id) for storage IDs. All requested IDs should\n\t * be a key in this map. Blobs created while the container is detached are stored in IDetachedBlobStorage which\n\t * gives local IDs; the storage IDs are filled in at attach time.\n\t * Note: It contains mappings from all clients, i.e., from remote clients as well. local ID comes from the client\n\t * that uploaded the blob but its mapping to storage ID is needed in all clients in order to retrieve the blob.\n\t */\n\tprivate readonly redirectTable: Map<string, string | undefined>;\n\n\t/**\n\t * Blobs which have not been uploaded or for which we have not yet seen a BlobAttach op round-trip.\n\t * Until we see the op round-trip, there is a possibility we may need to re-upload the blob, so\n\t * we must save it. This is true for both the online and offline flow.\n\t */\n\tprivate readonly pendingBlobs: Map<string, PendingBlob> = new Map();\n\n\t/**\n\t * Track ops in flight for online flow. This is used for optimizations where if we receive an ack for a storage ID,\n\t * we can resolve all pending blobs with the same storage ID even though they may have different local IDs. That's\n\t * because we know that the server will not delete the blob corresponding to that storage ID.\n\t */\n\tprivate readonly opsInFlight: Map<string, string[]> = new Map();\n\n\tprivate readonly retryThrottler = new CancellableThrottler(\n\t\tnew Throttler(\n\t\t\t60 * 1000, // 60 sec delay window\n\t\t\t30 * 1000, // 30 sec max delay\n\t\t\t// throttling function increases exponentially (0ms, 40ms, 80ms, 160ms, etc)\n\t\t\tformExponentialFn({ coefficient: 20, initialDelay: 0 }),\n\t\t),\n\t);\n\n\t/** If true, throw an error when a tombstone attachment blob is retrieved. */\n\tprivate readonly throwOnTombstoneLoad: boolean;\n\t/**\n\t * This stores IDs of tombstoned blobs.\n\t * Tombstone is a temporary feature that imitates a blob getting swept by garbage collection.\n\t */\n\tprivate readonly tombstonedBlobs: Set<string> = new Set();\n\n\tprivate readonly sendBlobAttachOp: (localId: string, storageId?: string) => void;\n\n\tconstructor(\n\t\tprivate readonly routeContext: IFluidHandleContext,\n\t\tsnapshot: IBlobManagerLoadInfo,\n\t\tprivate readonly getStorage: () => IDocumentStorageService,\n\t\t/**\n\t\t * Submit a BlobAttach op. When a blob is uploaded, there is a short grace period before which the blob is\n\t\t * deleted. The BlobAttach op notifies the server that blob is in use. The server will then not delete the\n\t\t * the blob as long as it is listed as referenced in future summaries. The summarizing client will know to\n\t\t * include the storage ID in the summary when it sees the op.\n\t\t *\n\t\t * The op will also include a local ID to inform all clients of the relation to the storage ID, without\n\t\t * knowledge of which they cannot request the blob from storage. It's important that this op is sequenced\n\t\t * before any ops that reference the local ID, otherwise, an invalid handle could be added to the document.\n\t\t */\n\t\tsendBlobAttachOp: (localId: string, storageId?: string) => void,\n\t\t// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly blobRequested: (blobPath: string) => void,\n\t\t// Called to check if a blob has been deleted by GC.\n\t\t// blobPath's format - `/<BlobManager.basePath>/<blobId>`.\n\t\tprivate readonly isBlobDeleted: (blobPath: string) => boolean,\n\t\tprivate readonly runtime: IBlobManagerRuntime,\n\t\tstashedBlobs: IPendingBlobs = {},\n\t\tprivate readonly closeContainer: (error?: ICriticalContainerError) => void,\n\t) {\n\t\tsuper();\n\t\tthis.mc = loggerToMonitoringContext(ChildLogger.create(this.runtime.logger, \"BlobManager\"));\n\t\t// Read the feature flag that tells whether to throw when a tombstone blob is requested.\n\t\tthis.throwOnTombstoneLoad =\n\t\t\tthis.mc.config.getBoolean(throwOnTombstoneLoadKey) === true &&\n\t\t\tthis.runtime.gcTombstoneEnforcementAllowed &&\n\t\t\tthis.runtime.clientDetails.type !== summarizerClientType;\n\n\t\tthis.runtime.on(\"disconnected\", () => this.onDisconnected());\n\n\t\tthis.redirectTable = this.load(snapshot);\n\n\t\t// Begin uploading stashed blobs from previous container instance\n\t\tObject.entries(stashedBlobs).forEach(([localId, entry]) => {\n\t\t\tconst blob = stringToBuffer(entry.blob, \"base64\");\n\t\t\tconst attached = entry.attached;\n\t\t\tconst acked = entry.acked;\n\t\t\tif (entry.minTTLInSeconds && entry.uploadTime) {\n\t\t\t\tconst timeLapseSinceLocalUpload = (Date.now() - entry.uploadTime) / 1000;\n\t\t\t\t// stashed entries with more than half-life in storage will not be reuploaded\n\t\t\t\tif (entry.minTTLInSeconds - timeLapseSinceLocalUpload > entry.minTTLInSeconds / 2) {\n\t\t\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\t\t\tblob,\n\t\t\t\t\t\tstatus: PendingBlobStatus.OfflinePendingOp,\n\t\t\t\t\t\thandleP: new Deferred(),\n\t\t\t\t\t\tuploadP: undefined,\n\t\t\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\t\t\tattached,\n\t\t\t\t\t\tacked,\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\tblob,\n\t\t\t\tstatus: PendingBlobStatus.OfflinePendingUpload,\n\t\t\t\thandleP: new Deferred(),\n\t\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t\t\tattached,\n\t\t\t\tacked,\n\t\t\t});\n\t\t});\n\n\t\tthis.sendBlobAttachOp = (localId: string, blobId?: string) => {\n\t\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\t\tif (pendingEntry?.uploadTime && pendingEntry?.minTTLInSeconds) {\n\t\t\t\tconst secondsSinceUpload = (Date.now() - pendingEntry.uploadTime) / 1000;\n\t\t\t\tconst expired = pendingEntry.minTTLInSeconds - secondsSinceUpload < 0;\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"sendBlobAttach\",\n\t\t\t\t\tentryStatus: pendingEntry.status,\n\t\t\t\t\tsecondsSinceUpload,\n\t\t\t\t\tminTTLInSeconds: pendingEntry.minTTLInSeconds,\n\t\t\t\t\texpired,\n\t\t\t\t});\n\t\t\t\tif (expired) {\n\t\t\t\t\t// we want to avoid submitting ops with broken handles\n\t\t\t\t\tthis.closeContainer(\n\t\t\t\t\t\tnew GenericError(\n\t\t\t\t\t\t\t\"Trying to submit a BlobAttach for expired blob\",\n\t\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tlocalId,\n\t\t\t\t\t\t\t\tblobId,\n\t\t\t\t\t\t\t\tentryStatus: pendingEntry.status,\n\t\t\t\t\t\t\t\tsecondsSinceUpload,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn sendBlobAttachOp(localId, blobId);\n\t\t};\n\t}\n\n\tprivate get pendingOfflineUploads() {\n\t\treturn Array.from(this.pendingBlobs.values()).filter(\n\t\t\t(e) => e.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t);\n\t}\n\n\tpublic get hasPendingOfflineUploads(): boolean {\n\t\treturn this.pendingOfflineUploads.length > 0;\n\t}\n\n\tpublic get hasPendingBlobs(): boolean {\n\t\treturn (\n\t\t\t(this.runtime.attachState !== AttachState.Attached && this.redirectTable.size > 0) ||\n\t\t\tthis.pendingBlobs.size > 0\n\t\t);\n\t}\n\n\t/**\n\t * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n\t */\n\tpublic async onConnected() {\n\t\tthis.retryThrottler.cancel();\n\t\tconst pendingUploads = this.pendingOfflineUploads.map(async (e) => e.uploadP);\n\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"BlobUploadOnConnected\",\n\t\t\t\tcount: pendingUploads.length,\n\t\t\t},\n\t\t\tasync () => Promise.all(pendingUploads),\n\t\t\t{ start: true, end: true },\n\t\t);\n\t}\n\n\t/**\n\t * Transition online blobs waiting for BlobAttach op round-trip since we will not see the op until we are connected\n\t * again\n\t */\n\tprivate onDisconnected() {\n\t\tfor (const [localId, entry] of this.pendingBlobs) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t// This will submit another BlobAttach op for this blob. This is necessary because the one we sent\n\t\t\t\t// already didn't have the local ID.\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Set of actual storage IDs (i.e., IDs that can be requested from storage). This will be empty if the container is\n\t * detached or there are no (non-pending) attachment blobs in the document\n\t */\n\tprivate get storageIds(): Set<string> {\n\t\tconst ids = new Set<string | undefined>(this.redirectTable.values());\n\n\t\t// If we are detached, we will not have storage IDs, only undefined\n\t\tconst undefinedValueInTable = ids.delete(undefined);\n\n\t\t// For a detached container, entries are inserted into the redirect table with an undefined storage ID.\n\t\t// For an attached container, entries are inserted w/storage ID after the BlobAttach op round-trips.\n\t\tassert(\n\t\t\t!undefinedValueInTable ||\n\t\t\t\t(this.runtime.attachState === AttachState.Detached && ids.size === 0),\n\t\t\t0x382 /* 'redirectTable' must contain only undefined while detached / defined values while attached */,\n\t\t);\n\n\t\treturn ids as Set<string>;\n\t}\n\n\tpublic async getBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\t// Verify that the blob is valid, i.e., it has not been garbage collected. If it is, this will throw an error,\n\t\t// failing the call.\n\t\tthis.verifyBlobValidity(blobId);\n\n\t\tconst pending = this.pendingBlobs.get(blobId);\n\t\tif (pending) {\n\t\t\treturn pending.blob;\n\t\t}\n\t\tlet storageId: string;\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\tassert(this.redirectTable.has(blobId), 0x383 /* requesting unknown blobs */);\n\n\t\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t\t// The 'IDocumentStorageService.readBlob()' call below will retrieve these via localId.\n\t\t\tstorageId = blobId;\n\t\t} else {\n\t\t\tconst attachedStorageId = this.redirectTable.get(blobId);\n\t\t\tassert(!!attachedStorageId, 0x11f /* \"requesting unknown blobs\" */);\n\t\t\tstorageId = attachedStorageId;\n\t\t}\n\n\t\t// Let runtime know that the corresponding GC node was requested.\n\t\tthis.blobRequested(getGCNodePathFromBlobId(blobId));\n\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"AttachmentReadBlob\", id: storageId },\n\t\t\tasync () => {\n\t\t\t\treturn this.getStorage().readBlob(storageId);\n\t\t\t},\n\t\t\t{ end: true, cancel: \"error\" },\n\t\t);\n\t}\n\n\tprivate getBlobHandle(id: string): BlobHandle {\n\t\tassert(\n\t\t\tthis.redirectTable.has(id) || this.pendingBlobs.has(id),\n\t\t\t0x384 /* requesting handle for unknown blob */,\n\t\t);\n\t\tconst pending = this.pendingBlobs.get(id);\n\t\tconst callback = pending\n\t\t\t? () => {\n\t\t\t\t\tpending.attached = true;\n\t\t\t\t\tthis.deletePendingBlobMaybe(id);\n\t\t\t }\n\t\t\t: undefined;\n\t\treturn new BlobHandle(\n\t\t\t`${BlobManager.basePath}/${id}`,\n\t\t\tthis.routeContext,\n\t\t\tasync () => this.getBlob(id),\n\t\t\tcallback,\n\t\t);\n\t}\n\n\tprivate async createBlobDetached(\n\t\tblob: ArrayBufferLike,\n\t): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\t// Blobs created while the container is detached are stored in IDetachedBlobStorage.\n\t\t// The 'IDocumentStorageService.createBlob()' call below will respond with a localId.\n\t\tconst response = await this.getStorage().createBlob(blob);\n\t\tthis.setRedirection(response.id, undefined);\n\t\treturn this.getBlobHandle(response.id);\n\t}\n\n\tpublic async createBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\tif (this.runtime.attachState === AttachState.Detached) {\n\t\t\treturn this.createBlobDetached(blob);\n\t\t}\n\t\tif (this.runtime.attachState === AttachState.Attaching) {\n\t\t\t// blob upload is not supported in \"Attaching\" state\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"CreateBlobWhileAttaching\" });\n\t\t\tawait new Promise<void>((resolve) => this.runtime.once(\"attached\", resolve));\n\t\t}\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Attached,\n\t\t\t0x385 /* For clarity and paranoid defense against adding future attachment states */,\n\t\t);\n\n\t\t// Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to\n\t\t// storage ID mapping is created.\n\t\tconst localId = uuid();\n\t\tconst pendingEntry: PendingBlob = {\n\t\t\tblob,\n\t\t\tstatus: PendingBlobStatus.OnlinePendingUpload,\n\t\t\thandleP: new Deferred(),\n\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t\tattached: false,\n\t\t\tacked: false,\n\t\t};\n\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\treturn pendingEntry.handleP.promise;\n\t}\n\n\tprivate async uploadBlob(localId: string, blob: ArrayBufferLike): Promise<ICreateBlobResponse> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"createBlob\" },\n\t\t\tasync () => this.getStorage().createBlob(blob),\n\t\t\t{ end: true, cancel: this.runtime.connected ? \"error\" : \"generic\" },\n\t\t).then(\n\t\t\t(response) => this.onUploadResolve(localId, response),\n\t\t\tasync (err) => this.onUploadReject(localId, err),\n\t\t);\n\t}\n\n\t/**\n\t * Set up a mapping in the redirect table from fromId to toId. Also, notify the runtime that a reference is added\n\t * which is required for GC.\n\t */\n\tprivate setRedirection(fromId: string, toId: string | undefined) {\n\t\tthis.redirectTable.set(fromId, toId);\n\t}\n\n\tprivate deletePendingBlobMaybe(id: string) {\n\t\tif (this.pendingBlobs.has(id)) {\n\t\t\tconst entry = this.pendingBlobs.get(id);\n\t\t\tif (entry?.attached && entry?.acked) {\n\t\t\t\tthis.pendingBlobs.delete(id);\n\t\t\t\tif (!this.hasPendingBlobs) {\n\t\t\t\t\tthis.emit(\"noPendingBlobs\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate onUploadResolve(localId: string, response: ICreateBlobResponseWithTTL) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(entry !== undefined, 0x6c8 /* pending blob entry not found for uploaded blob */);\n\t\tassert(\n\t\t\tentry.status === PendingBlobStatus.OnlinePendingUpload ||\n\t\t\t\tentry.status === PendingBlobStatus.OfflinePendingUpload,\n\t\t\t0x386 /* Must have pending blob entry for uploaded blob */,\n\t\t);\n\t\tentry.storageId = response.id;\n\t\tentry.uploadTime = Date.now();\n\t\tentry.minTTLInSeconds = response.minTTLInSeconds;\n\t\tif (this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\t// Send a blob attach op. This serves two purposes:\n\t\t\t\t// 1. If its a new blob, i.e., it isn't de-duped, the server will keep the blob alive if it sees this op\n\t\t\t\t// until its storage ID is added to the next summary.\n\t\t\t\t// 2. It will create a local ID to storage ID mapping in all clients which is needed to retrieve the\n\t\t\t\t// blob from the server via the storage ID.\n\t\t\t\tthis.sendBlobAttachOp(localId, response.id);\n\t\t\t\tif (this.storageIds.has(response.id)) {\n\t\t\t\t\t// The blob is de-duped. Set up a local ID to storage ID mapping and return the blob. Since this is\n\t\t\t\t\t// an existing blob, we don't have to wait for the op to be ack'd since this step has already\n\t\t\t\t\t// happened before and so, the server won't delete it.\n\t\t\t\t\tthis.setRedirection(localId, response.id);\n\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is already an op for this storage ID, append the local ID to the list. Once any op for\n\t\t\t\t\t// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n\t\t\t\t\t// blob alive in storage.\n\t\t\t\t\tthis.opsInFlight.set(\n\t\t\t\t\t\tresponse.id,\n\t\t\t\t\t\t(this.opsInFlight.get(response.id) ?? []).concat(localId),\n\t\t\t\t\t);\n\t\t\t\t\tentry.status = PendingBlobStatus.OnlinePendingOp;\n\t\t\t\t}\n\t\t\t} else if (entry.status === PendingBlobStatus.OfflinePendingUpload) {\n\t\t\t\t// We already submitted a BlobAttach op for this blob when it was transitioned to offline flow\n\t\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t\t}\n\t\t} else {\n\t\t\t// connected to storage but not ordering service?\n\t\t\tthis.mc.logger.sendTelemetryEvent({ eventName: \"BlobUploadSuccessWhileDisconnected\" });\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\tentry.status = PendingBlobStatus.OfflinePendingOp;\n\t\t}\n\t\treturn response;\n\t}\n\n\tprivate async onUploadReject(localId: string, error) {\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x387 /* Must have pending blob entry for blob which failed to upload */);\n\t\tif (!this.runtime.connected) {\n\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingUpload) {\n\t\t\t\tthis.transitionToOffline(localId);\n\t\t\t}\n\t\t\t// we are probably not connected to storage but start another upload request in case we are\n\t\t\tentry.uploadP = this.retryThrottler\n\t\t\t\t.getDelay()\n\t\t\t\t.then(async () => this.uploadBlob(localId, entry.blob));\n\t\t\treturn entry.uploadP;\n\t\t} else {\n\t\t\tentry.handleP.reject(error);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tprivate transitionToOffline(localId: string) {\n\t\tassert(\n\t\t\t!this.runtime.connected,\n\t\t\t0x388 /* Must only transition to offline flow while runtime is disconnected */,\n\t\t);\n\t\tconst entry = this.pendingBlobs.get(localId);\n\t\tassert(!!entry, 0x389 /* No pending blob entry */);\n\t\tassert(\n\t\t\t[PendingBlobStatus.OnlinePendingUpload, PendingBlobStatus.OnlinePendingOp].includes(\n\t\t\t\tentry.status,\n\t\t\t),\n\t\t\t0x38a /* Blob must be in online flow to transition to offline flow */,\n\t\t);\n\n\t\t/**\n\t\t * If we haven't already submitted a BlobAttach op for this entry, send it before returning the blob handle.\n\t\t * This will make sure that the BlobAttach op is sequenced prior to any ops referencing the handle. Otherwise,\n\t\t * an invalid handle could be added to the document.\n\t\t * storageId may be undefined but since we are not connected we will have a chance to add it when reSubmit()\n\t\t * is called on reconnection.\n\t\t */\n\t\tif (entry.status !== PendingBlobStatus.OnlinePendingOp) {\n\t\t\tthis.sendBlobAttachOp(localId, entry.storageId);\n\t\t}\n\n\t\tentry.status =\n\t\t\tentry.status === PendingBlobStatus.OnlinePendingUpload\n\t\t\t\t? PendingBlobStatus.OfflinePendingUpload\n\t\t\t\t: PendingBlobStatus.OfflinePendingOp;\n\n\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t}\n\n\t/**\n\t * Resubmit a BlobAttach op. Used to add storage IDs to ops that were\n\t * submitted to runtime while disconnected.\n\t * @param metadata - op metadata containing storage and/or local IDs\n\t */\n\tpublic reSubmit(metadata: Record<string, unknown> | undefined) {\n\t\tassert(!!metadata, 0x38b /* Resubmitted ops must have metadata */);\n\t\tconst { localId, blobId }: { localId?: string; blobId?: string } = metadata;\n\t\tassert(localId !== undefined, 0x50d /* local ID not available on reSubmit */);\n\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\n\t\tif (!blobId) {\n\t\t\t// We submitted this op while offline. The blob should have been uploaded by now.\n\t\t\tassert(\n\t\t\t\tpendingEntry?.status === PendingBlobStatus.OfflinePendingOp &&\n\t\t\t\t\t!!pendingEntry?.storageId,\n\t\t\t\t0x38d /* blob must be uploaded before resubmitting BlobAttach op */,\n\t\t\t);\n\t\t\treturn this.sendBlobAttachOp(localId, pendingEntry.storageId);\n\t\t}\n\t\treturn this.sendBlobAttachOp(localId, blobId);\n\t}\n\n\tpublic processBlobAttachOp(message: ISequencedDocumentMessage, local: boolean) {\n\t\tconst localId = (message.metadata as IBlobMetadata | undefined)?.localId;\n\t\tconst blobId = (message.metadata as IBlobMetadata | undefined)?.blobId;\n\t\tassert(blobId !== undefined, 0x12a /* \"Missing blob id on metadata\" */);\n\n\t\t// Set up a mapping from local ID to storage ID. This is crucial since without this the blob cannot be\n\t\t// requested from the server.\n\t\t// Note: The check for undefined is needed for back-compat when localId was not part of the BlobAttach op that\n\t\t// was sent when online.\n\t\tif (localId !== undefined) {\n\t\t\tthis.setRedirection(localId, blobId);\n\t\t}\n\t\t// set identity (id -> id) entry\n\t\tthis.setRedirection(blobId, blobId);\n\n\t\tif (local) {\n\t\t\tassert(localId !== undefined, 0x50e /* local ID not present in blob attach message */);\n\t\t\tconst waitingBlobs = this.opsInFlight.get(blobId);\n\t\t\tif (waitingBlobs !== undefined) {\n\t\t\t\t// For each op corresponding to this storage ID that we are waiting for, resolve the pending blob.\n\t\t\t\t// This is safe because the server will keep the blob alive and the op containing the local ID to\n\t\t\t\t// storage ID is already in flight and any op containing this local ID will be sequenced after that.\n\t\t\t\twaitingBlobs.forEach((pendingLocalId) => {\n\t\t\t\t\tconst entry = this.pendingBlobs.get(pendingLocalId);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tentry !== undefined,\n\t\t\t\t\t\t0x38f /* local online BlobAttach op with no pending blob entry */,\n\t\t\t\t\t);\n\n\t\t\t\t\t// It's possible we transitioned to offline flow while waiting for this op.\n\t\t\t\t\tif (entry.status === PendingBlobStatus.OnlinePendingOp) {\n\t\t\t\t\t\tthis.setRedirection(pendingLocalId, blobId);\n\t\t\t\t\t\tentry.acked = true;\n\t\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n\t\t\t\t\t\tthis.deletePendingBlobMaybe(pendingLocalId);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\tthis.opsInFlight.delete(blobId);\n\t\t\t}\n\t\t\t// offline flow does not resolve the handle (since it was already resolved)\n\t\t\t// but we still need to delete the entry in case is acked and attached.\n\t\t\tconst localEntry = this.pendingBlobs.get(localId);\n\t\t\tif (localEntry) {\n\t\t\t\tlocalEntry.acked = true;\n\t\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Reads blobs needed to load BlobManager from storage.\n\t * @param blobsTree - Tree containing IDs of previously attached blobs. We\n\t * look for the IDs in the blob entries of the tree since the both the r11s\n\t * and SPO drivers replace the attachment types returned in snapshot() with blobs.\n\t */\n\tpublic static async load(\n\t\tblobsTree: ISnapshotTree | undefined,\n\t\ttryFetchBlob: (id: string) => Promise<[string, string][]>,\n\t): Promise<IBlobManagerLoadInfo> {\n\t\tif (!blobsTree) {\n\t\t\treturn {};\n\t\t}\n\t\tlet redirectTable;\n\t\tconst tableId = blobsTree.blobs[this.redirectTableBlobName];\n\t\tif (tableId) {\n\t\t\tredirectTable = await tryFetchBlob(tableId);\n\t\t}\n\t\tconst ids = Object.entries(blobsTree.blobs)\n\t\t\t.filter(([k, _]) => k !== this.redirectTableBlobName)\n\t\t\t.map(([_, v]) => v);\n\t\treturn { ids, redirectTable };\n\t}\n\n\t/**\n\t * Load a set of previously attached blob IDs and redirect table from a previous snapshot.\n\t */\n\tprivate load(snapshot: IBlobManagerLoadInfo): Map<string, string | undefined> {\n\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\teventName: \"AttachmentBlobsLoaded\",\n\t\t\tcount: snapshot.ids?.length ?? 0,\n\t\t\tredirectTable: snapshot.redirectTable?.length,\n\t\t});\n\t\tconst table = new Map<string, string | undefined>(snapshot.redirectTable);\n\t\tif (snapshot.ids) {\n\t\t\tconst detached = this.runtime.attachState === AttachState.Detached;\n\t\t\t// If we are detached, we don't have storage IDs yet, so set to undefined\n\t\t\t// Otherwise, set identity (id -> id) entries\n\t\t\tsnapshot.ids.forEach((entry) => table.set(entry, detached ? undefined : entry));\n\t\t}\n\t\treturn table;\n\t}\n\n\tpublic summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n\t\t// if storageIds is empty, it means we are detached and have only local IDs, or that there are no blobs attached\n\t\tconst blobIds =\n\t\t\tthis.storageIds.size > 0\n\t\t\t\t? Array.from(this.storageIds)\n\t\t\t\t: Array.from(this.redirectTable.keys());\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tblobIds.forEach((blobId) => {\n\t\t\tbuilder.addAttachment(blobId);\n\t\t});\n\n\t\t// Any non-identity entries in the table need to be saved in the summary\n\t\tif (this.redirectTable.size > blobIds.length) {\n\t\t\tbuilder.addBlob(\n\t\t\t\tBlobManager.redirectTableBlobName,\n\t\t\t\t// filter out identity entries\n\t\t\t\tJSON.stringify(\n\t\t\t\t\tArray.from(this.redirectTable.entries()).filter(\n\t\t\t\t\t\t([localId, storageId]) => localId !== storageId,\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn builder.getSummaryTree();\n\t}\n\n\t/**\n\t * Generates data used for garbage collection. Each blob uploaded represents a node in the GC graph as it can be\n\t * individually referenced by storing its handle in a referenced DDS. Returns the list of blob ids as GC nodes.\n\t * @param fullGC - true to bypass optimizations and force full generation of GC data. BlobManager doesn't care\n\t * about this for now because the data is a simple list of blob ids.\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\tconst gcData: IGarbageCollectionData = { gcNodes: {} };\n\t\tfor (const [localId, storageId] of this.redirectTable) {\n\t\t\tassert(!!storageId, 0x390 /* Must be attached to get GC data */);\n\t\t\t// Only return local ids as GC nodes because a blob can only be referenced via its local id. The storage\n\t\t\t// id entries have the same key and value, ignore them.\n\t\t\t// The outbound routes are empty because a blob node cannot reference other nodes. It can only be referenced\n\t\t\t// by adding its handle to a referenced DDS.\n\t\t\tif (localId !== storageId) {\n\t\t\t\tgcData.gcNodes[getGCNodePathFromBlobId(localId)] = [];\n\t\t\t}\n\t\t}\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are unused. The unused blobs are deleted.\n\t * @param unusedRoutes - The routes of the blob nodes that are unused. These routes will be based off of local ids.\n\t */\n\tpublic updateUnusedRoutes(unusedRoutes: string[]): void {\n\t\tthis.deleteBlobsFromRedirectTable(unusedRoutes);\n\t}\n\n\t/**\n\t * Delete attachment blobs that are sweep ready.\n\t * @param sweepReadyBlobRoutes - The routes of blobs that are sweep ready and should be deleted. These routes will\n\t * be based off of local ids.\n\t * @returns - The routes of blobs that were deleted.\n\t */\n\tpublic deleteSweepReadyNodes(sweepReadyBlobRoutes: string[]): string[] {\n\t\t// If sweep for attachment blobs is not enabled, return empty list indicating nothing is deleted.\n\t\tif (this.mc.config.getBoolean(sweepAttachmentBlobsKey) !== true) {\n\t\t\treturn [];\n\t\t}\n\n\t\tthis.deleteBlobsFromRedirectTable(sweepReadyBlobRoutes);\n\t\treturn Array.from(sweepReadyBlobRoutes);\n\t}\n\n\t/**\n\t * Delete blobs with the given routes from the redirect table.\n\t * The routes are GC nodes paths of format -`/<BlobManager.basePath>/<blobId>`. The blob ids are all local ids.\n\t * Deleting the blobs involves 2 steps:\n\t * 1. The redirect table entry for the local ids are deleted.\n\t * 2. If the storage ids corresponding to the deleted local ids are not in-use anymore, the redirect table entries\n\t * for the storage ids are deleted as well.\n\t *\n\t * Note that this does not delete the blobs from storage service immediately. Deleting the blobs from redirect table\n\t * will remove them the next summary. The service would them delete them some time in the future.\n\t */\n\tprivate deleteBlobsFromRedirectTable(blobRoutes: string[]) {\n\t\tif (blobRoutes.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\t// This tracks the storage ids of local ids that are deleted. After the local ids have been deleted, if any of\n\t\t// these storage ids are unused, they will be deleted as well.\n\t\tconst maybeUnusedStorageIds: Set<string> = new Set();\n\t\tfor (const route of blobRoutes) {\n\t\t\tconst blobId = getBlobIdFromGCNodePath(route);\n\t\t\tif (!this.redirectTable.has(blobId)) {\n\t\t\t\tthis.mc.logger.sendErrorEvent({\n\t\t\t\t\teventName: \"DeletedAttachmentBlobNotFound\",\n\t\t\t\t\tblobId,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst storageId = this.redirectTable.get(blobId);\n\t\t\tassert(!!storageId, 0x5bb /* Must be attached to run GC */);\n\t\t\tmaybeUnusedStorageIds.add(storageId);\n\t\t\tthis.redirectTable.delete(blobId);\n\t\t}\n\n\t\t// Find out storage ids that are in-use and remove them from maybeUnusedStorageIds. A storage id is in-use if\n\t\t// the redirect table has a local id -> storage id entry for it.\n\t\tfor (const [localId, storageId] of this.redirectTable.entries()) {\n\t\t\tassert(!!storageId, 0x5bc /* Must be attached to run GC */);\n\t\t\t// For every storage id, the redirect table has a id -> id entry. These do not make the storage id in-use.\n\t\t\tif (maybeUnusedStorageIds.has(storageId) && localId !== storageId) {\n\t\t\t\tmaybeUnusedStorageIds.delete(storageId);\n\t\t\t}\n\t\t}\n\n\t\t// For unused storage ids, delete their id -> id entries from the redirect table.\n\t\t// This way they'll be absent from the next summary, and the service is free to delete them from storage.\n\t\tfor (const storageId of maybeUnusedStorageIds) {\n\t\t\tthis.redirectTable.delete(storageId);\n\t\t}\n\t}\n\n\t/**\n\t * This is called to update blobs whose routes are tombstones. Tombstoned blobs enable testing scenarios with\n\t * accessing deleted content without actually deleting content from summaries.\n\t * @param tombstonedRoutes - The routes of blob nodes that are tombstones.\n\t */\n\tpublic updateTombstonedRoutes(tombstonedRoutes: string[]) {\n\t\tconst tombstonedBlobsSet: Set<string> = new Set();\n\t\t// The routes or blob node paths are in the same format as returned in getGCData -\n\t\t// `/<BlobManager.basePath>/<blobId>`.\n\t\tfor (const route of tombstonedRoutes) {\n\t\t\tconst blobId = getBlobIdFromGCNodePath(route);\n\t\t\ttombstonedBlobsSet.add(blobId);\n\t\t}\n\n\t\t// Remove blobs from the tombstone list that were tombstoned but aren't anymore as per the tombstoneRoutes.\n\t\tfor (const blobId of this.tombstonedBlobs) {\n\t\t\tif (!tombstonedBlobsSet.has(blobId)) {\n\t\t\t\tthis.tombstonedBlobs.delete(blobId);\n\t\t\t}\n\t\t}\n\n\t\t// Mark blobs that are now tombstoned by adding them to the tombstone list.\n\t\tfor (const blobId of tombstonedBlobsSet) {\n\t\t\tthis.tombstonedBlobs.add(blobId);\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that the blob with given id is valid, i.e., it has not been garbage collected. If the blob is GC'd,\n\t * log an error and throw if necessary.\n\t */\n\tprivate verifyBlobValidity(blobId: string) {\n\t\t/**\n\t\t * A blob can be in one of the following states:\n\t\t * 1. \"deleted\" - It has been deleted by garbage collection sweep phase.\n\t\t * 2. \"tombstoned\" - It is ready for deletion but sweep phase isn't enabled and tombstone feature is enabled.\n\t\t * 3. \"valid\" - It has not been deleted or tombstoned.\n\t\t */\n\t\tlet state: \"valid\" | \"tombstoned\" | \"deleted\" = \"valid\";\n\t\tif (this.isBlobDeleted(getGCNodePathFromBlobId(blobId))) {\n\t\t\tstate = \"deleted\";\n\t\t} else if (this.tombstonedBlobs.has(blobId)) {\n\t\t\tstate = \"tombstoned\";\n\t\t}\n\n\t\tif (state === \"valid\") {\n\t\t\treturn;\n\t\t}\n\n\t\t// If the blob is deleted or throw on tombstone load is enabled, throw an error which will fail any attempt\n\t\t// to load the blob.\n\t\tconst shouldFail = state === \"deleted\" || this.throwOnTombstoneLoad;\n\t\tconst request = { url: blobId };\n\t\tconst error = responseToException(\n\t\t\tcreateResponseError(\n\t\t\t\t404,\n\t\t\t\t\"Blob was deleted\",\n\t\t\t\trequest,\n\t\t\t\tstate === \"tombstoned\" ? { [TombstoneResponseHeaderKey]: true } : undefined,\n\t\t\t),\n\t\t\trequest,\n\t\t);\n\t\tsendGCUnexpectedUsageEvent(\n\t\t\tthis.mc,\n\t\t\t{\n\t\t\t\teventName:\n\t\t\t\t\tstate === \"tombstoned\"\n\t\t\t\t\t\t? \"GC_Tombstone_Blob_Requested\"\n\t\t\t\t\t\t: \"GC_Deleted_Blob_Requested\",\n\t\t\t\tcategory: shouldFail ? \"error\" : \"generic\",\n\t\t\t\tgcTombstoneEnforcementAllowed: this.runtime.gcTombstoneEnforcementAllowed,\n\t\t\t},\n\t\t\t[BlobManager.basePath],\n\t\t\terror,\n\t\t);\n\t\tif (shouldFail) {\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\tpublic setRedirectTable(table: Map<string, string>) {\n\t\tassert(\n\t\t\tthis.runtime.attachState === AttachState.Detached,\n\t\t\t0x252 /* \"redirect table can only be set in detached container\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.redirectTable.size === table.size,\n\t\t\t0x391 /* Redirect table size must match BlobManager's local ID count */,\n\t\t);\n\t\tfor (const [localId, storageId] of table) {\n\t\t\tassert(\n\t\t\t\tthis.redirectTable.has(localId),\n\t\t\t\t0x254 /* \"unrecognized id in redirect table\" */,\n\t\t\t);\n\t\t\tthis.setRedirection(localId, storageId);\n\t\t\t// set identity (id -> id) entry\n\t\t\tthis.setRedirection(storageId, storageId);\n\t\t}\n\t}\n\n\tpublic getPendingBlobs(): IPendingBlobs {\n\t\tconst blobs = {};\n\t\tfor (const [key, entry] of this.pendingBlobs) {\n\t\t\tblobs[key] = {\n\t\t\t\tblob: bufferToString(entry.blob, \"base64\"),\n\t\t\t\tattached: entry.attached,\n\t\t\t\tacked: entry.acked,\n\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t};\n\t\t}\n\t\treturn blobs;\n\t}\n}\n\n/**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<BlobManager.basePath>/<blobId>`.\n * This path must match the path of the blob handle returned by the createBlob API because blobs are marked\n * referenced by storing these handles in a referenced DDS.\n */\nfunction getGCNodePathFromBlobId(blobId: string) {\n\treturn `/${BlobManager.basePath}/${blobId}`;\n}\n\n/**\n * For a given GC node path, return the blobId. The node path is of the format `/<BlobManager.basePath>/<blobId>`.\n */\nfunction getBlobIdFromGCNodePath(nodePath: string) {\n\tconst pathParts = nodePath.split(\"/\");\n\tassert(\n\t\tpathParts.length === 3 && pathParts[1] === BlobManager.basePath,\n\t\t0x5bd /* Invalid blob node path */,\n\t);\n\treturn pathParts[2];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"connectionTelemetry.d.ts","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,mBAAmB,EAAgC,MAAM,iCAAiC,CAAC;AACpG,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QAG3B"}
@@ -106,7 +106,14 @@ class OpPerfTelemetry {
106
106
  }
107
107
  recordPingTime(latency) {
108
108
  this.pingLatency = latency;
109
- // logging one in every 1000 pongs, including the first time, if it is a "write" client.
109
+ // Log if latency is longer than 1 min
110
+ if (latency > 1000 * 60) {
111
+ this.logger.sendErrorEvent({
112
+ eventName: "LatencyTooLong",
113
+ duration: latency,
114
+ });
115
+ }
116
+ // logging one in every 100 pongs, including the first time, if it is a "write" client.
110
117
  if (this.pongCount % 100 === 0 && this.deltaManager.active) {
111
118
  this.logger.sendPerformanceEvent({
112
119
  eventName: "DeltaLatency",
@@ -1 +1 @@
1
- {"version":3,"file":"connectionTelemetry.js","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,WAAW,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEpG,OAAO,EAGN,WAAW,GACX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEnE;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAgCrC,MAAM,eAAe;IAuBpB,YACS,QAA4B,EACnB,YAAwE,EACzF,MAA2B;QAFnB,aAAQ,GAAR,QAAQ,CAAoB;QACnB,iBAAY,GAAZ,YAAY,CAA4D;QAxBlF,cAAS,GAAW,CAAC,CAAC;QAKtB,yBAAoB,GAAW,CAAC,CAAC;QAIjC,sBAAiB,GAA4B,EAAE,CAAC;QAExD,sEAAsE;QAC9D,eAAU,GAAwC,EAAE,CAAC;QAErD,oBAAe,GAAG,IAAI,CAAC;QAEd,aAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACtC,wBAAmB,GAAG,CAAC,CAAC;QACxB,QAAG,GAAG,CAAC,CAAC;QASf,IAAI,CAAC,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC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,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC;YAEvE,IAAI,CAAC,MAAM,CAAC,oBAAoB,iBAC/B,SAAS,EAAE,iBAAiB,EAC5B,cAAc,EACd,uBAAuB,EAAE,OAAO,CAAC,uBAAuB,EACxD,QAAQ;gBACR,QAAQ,EACR,WAAW,EAAE,IAAI,CAAC,WAAW,EAC7B,WAAW,EACV,IAAI,CAAC,YAAY,CAAC,kBAAkB,GAAG,IAAI,CAAC,YAAY,CAAC,qBAAqB,IAC5E,IAAI,CAAC,UAAU,EACjB,CAAC;YACH,IAAI,CAAC,wCAAwC,GAAG,SAAS,CAAC;YAC1D,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC;SAC5B;IACF,CAAC;CACD;AAuBD,MAAM,UAAU,qBAAqB,CACpC,QAA4B,EAC5B,YAAwE,EACxE,MAA2B;IAE3B,IAAI,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt, ChildLogger, TelemetryLogger } from \"@fluidframework/telemetry-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport {\n\tIDocumentMessage,\n\tISequencedDocumentMessage,\n\tMessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\n\n/**\n * We report various latency-related errors when waiting for op roundtrip takes longer than that amout of time.\n */\nexport const latencyThreshold = 5000;\n\n// Phases in OpPerfTelemetry:\n// 1.\tOp is added to DeltaManager (DM) buffer.\n// 2.\tOp is sent to service (op leaves outbound queue).\n// \t - Note: We do not know for sure when op is sent, we only track when it is added to outbound queue.\n// If outbound queue is paused, time queue is paused is counted as network time.\n// 3.\tOp received from service back (pushed to inbound queue).\n// 4.\tOp is processed.\ninterface IOpPerfTelemetryProperties {\n\t/** Measure time between (1) and (2) - Measure time outbound op is sitting in queue due to active batch */\n\tdurationOutboundBatching: number; // was durationOutboundQueue in previous versions\n\t/** Measure time between (2) and (3) - Track how long it took for op to be acked by service */\n\tdurationNetwork: number; // was durationInboundQueue\n\t/** Measure time between (3) and (4) - Time between DM's inbound \"push\" event until DM's \"op\" event */\n\tdurationInboundToProcessing: number;\n\t/** Length of the DeltaManager's inbound queue at the time of the DM's inbound \"push\" event (3) */\n\tlengthInboundQueue: number;\n}\n\n/**\n * Timings collected at various moments during the op processing.\n */\ninterface IOpPerfTimings {\n\t/** Starting time for (1) */\n\tsubmitOpEventTime: number;\n\t/** Starting time for (2) */\n\toutboundPushEventTime: number;\n\t/** Starting time for (3) */\n\tinboundPushEventTime: number;\n}\n\nclass OpPerfTelemetry {\n\tprivate pongCount: number = 0;\n\tprivate pingLatency: number | undefined;\n\n\t// Collab window tracking. This is timestamp of %1000 message.\n\tprivate sequenceNumberForMsnTracking: number | undefined;\n\tprivate msnTrackingTimestamp: number = 0;\n\t// To track round trip time for every %500 client message.\n\tprivate clientSequenceNumberForLatencyStatistics: number | undefined;\n\n\tprivate opProcessingTimes: Partial<IOpPerfTimings> = {};\n\n\t// Performance Data to be reported for ops round trips and processing.\n\tprivate opPerfData: Partial<IOpPerfTelemetryProperties> = {};\n\n\tprivate firstConnection = true;\n\tprivate connectionOpSeqNumber: number | undefined;\n\tprivate readonly bootTime = performance.now();\n\tprivate connectionStartTime = 0;\n\tprivate gap = 0;\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic constructor(\n\t\tprivate clientId: string | undefined,\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logger = ChildLogger.create(logger, \"OpPerf\");\n\n\t\tthis.deltaManager.on(\"pong\", (latency) => this.recordPingTime(latency));\n\t\tthis.deltaManager.on(\"submitOp\", (message) => this.beforeOpSubmit(message));\n\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterProcessingOp(message));\n\n\t\tthis.deltaManager.on(\"connect\", (details, opsBehind) => {\n\t\t\tthis.clientId = details.clientId;\n\t\t\tif (opsBehind !== undefined) {\n\t\t\t\tthis.connectionOpSeqNumber = this.deltaManager.lastKnownSeqNumber;\n\t\t\t\tthis.gap = opsBehind;\n\t\t\t\tthis.connectionStartTime = performance.now();\n\n\t\t\t\t// We might be already up-today. If so, report it right away.\n\t\t\t\tif (this.gap <= 0) {\n\t\t\t\t\tthis.reportGettingUpToDate();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tthis.deltaManager.on(\"disconnect\", () => {\n\t\t\tthis.sequenceNumberForMsnTracking = undefined;\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.opProcessingTimes = {};\n\t\t\tthis.opPerfData = {};\n\t\t\tthis.connectionOpSeqNumber = undefined;\n\t\t\tthis.firstConnection = false;\n\t\t\tthis.pongCount = 0;\n\t\t});\n\n\t\tthis.deltaManager.outbound.on(\"push\", (messages) => {\n\t\t\tfor (const msg of messages) {\n\t\t\t\tif (\n\t\t\t\t\tmsg.type === MessageType.Operation &&\n\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === msg.clientSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime === undefined,\n\t\t\t\t\t\t0x2c8 /* \"outboundPushEventTime should be undefined\" */,\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opPerfData.durationNetwork === undefined,\n\t\t\t\t\t\t0x2c9 /* \"durationNetwork should be undefined\" */,\n\t\t\t\t\t);\n\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime = Date.now();\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opPerfData.durationOutboundBatching === undefined,\n\t\t\t\t\t\t0x2ca /* \"durationOutboundBatching should be undefined\" */,\n\t\t\t\t\t);\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t\t\t0x2cb /* \"submitOpEventTime should be undefined\" */,\n\t\t\t\t\t);\n\n\t\t\t\t\tthis.opPerfData.durationOutboundBatching =\n\t\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime -\n\t\t\t\t\t\tthis.opProcessingTimes.submitOpEventTime;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.deltaManager.inbound.on(\"push\", (message: ISequencedDocumentMessage) => {\n\t\t\tif (\n\t\t\t\tthis.clientId === message.clientId &&\n\t\t\t\tmessage.type === MessageType.Operation &&\n\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber &&\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime !== undefined\n\t\t\t) {\n\t\t\t\tthis.opProcessingTimes.inboundPushEventTime = Date.now();\n\t\t\t\tthis.opPerfData.durationNetwork =\n\t\t\t\t\tthis.opProcessingTimes.inboundPushEventTime -\n\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime;\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime = undefined;\n\t\t\t\tthis.opPerfData.lengthInboundQueue = this.deltaManager.inbound.length;\n\t\t\t}\n\t\t});\n\n\t\tthis.deltaManager.inbound.on(\"idle\", (count: number, duration: number) => {\n\t\t\t// Do not want to log zero for sure.\n\t\t\t// We are more interested in aggregates, so logging only if we are processing some number of ops\n\t\t\t// Cut-off is arbitrary - can be increased or decreased based on amount of data collected and questions we\n\t\t\t// want to get answered\n\t\t\t// back-compat: Once 0.36 loader version saturates (count & duration args were added there),\n\t\t\t// we can remove typeof check.\n\t\t\tif (typeof count === \"number\" && count >= 100) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"GetDeltas_OpProcessing\",\n\t\t\t\t\tcount,\n\t\t\t\t\tduration,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate reportGettingUpToDate() {\n\t\tthis.connectionOpSeqNumber = undefined;\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"ConnectionSpeed\",\n\t\t\tduration: performance.now() - this.connectionStartTime,\n\t\t\tops: this.gap,\n\t\t\t// track time to connect only for first connection.\n\t\t\ttimeToConnect: this.firstConnection\n\t\t\t\t? TelemetryLogger.formatTick(this.connectionStartTime - this.bootTime)\n\t\t\t\t: undefined,\n\t\t\tfirstConnection: this.firstConnection,\n\t\t});\n\t}\n\n\tprivate recordPingTime(latency: number) {\n\t\tthis.pingLatency = latency;\n\t\t// logging one in every 1000 pongs, including the first time, if it is a \"write\" client.\n\t\tif (this.pongCount % 100 === 0 && this.deltaManager.active) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"DeltaLatency\",\n\t\t\t\tduration: latency,\n\t\t\t});\n\t\t}\n\t\tthis.pongCount++;\n\t}\n\n\tprivate beforeOpSubmit(message: IDocumentMessage) {\n\t\t// start with first client op and measure latency every 500 client ops\n\t\tif (\n\t\t\tthis.clientSequenceNumberForLatencyStatistics === undefined &&\n\t\t\tmessage.clientSequenceNumber % 500 === 1\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime === undefined,\n\t\t\t\t0x2cc /* \"OpTimeSittingInboundQueue should be undefined\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tthis.opPerfData.durationNetwork === undefined,\n\t\t\t\t0x2cd /* \"durationNetwork should be undefined\" */,\n\t\t\t);\n\t\t\tthis.opProcessingTimes.submitOpEventTime = Date.now();\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = message.clientSequenceNumber;\n\t\t}\n\t}\n\n\tprivate afterProcessingOp(message: ISequencedDocumentMessage) {\n\t\tconst sequenceNumber = message.sequenceNumber;\n\n\t\tif (sequenceNumber === this.connectionOpSeqNumber) {\n\t\t\tthis.reportGettingUpToDate();\n\t\t}\n\n\t\t// Record collab window max size after every 1000th op.\n\t\tif (this.sequenceNumberForMsnTracking === undefined && sequenceNumber % 1000 === 0) {\n\t\t\tthis.sequenceNumberForMsnTracking = sequenceNumber;\n\t\t\tthis.msnTrackingTimestamp = message.timestamp;\n\t\t}\n\t\tif (\n\t\t\tthis.sequenceNumberForMsnTracking !== undefined &&\n\t\t\tmessage.minimumSequenceNumber >= this.sequenceNumberForMsnTracking\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.msnTrackingTimestamp !== undefined,\n\t\t\t\t0x2ce /* \"msnTrackingTimestamp should not be undefined\" */,\n\t\t\t);\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"MsnStatistics\",\n\t\t\t\tsequenceNumber,\n\t\t\t\tmsnDistance: sequenceNumber - this.sequenceNumberForMsnTracking,\n\t\t\t\tduration: message.timestamp - this.msnTrackingTimestamp,\n\t\t\t});\n\t\t\tthis.sequenceNumberForMsnTracking = undefined;\n\t\t}\n\n\t\tif (\n\t\t\tthis.clientId === message.clientId &&\n\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t0x120 /* \"Undefined latency statistics (op send time)\" */,\n\t\t\t);\n\t\t\tconst currentTime = Date.now();\n\n\t\t\tif (this.opProcessingTimes.inboundPushEventTime !== undefined) {\n\t\t\t\tthis.opPerfData.durationInboundToProcessing =\n\t\t\t\t\tcurrentTime - this.opProcessingTimes.inboundPushEventTime;\n\t\t\t}\n\n\t\t\tconst duration = currentTime - this.opProcessingTimes.submitOpEventTime;\n\n\t\t\t// One of the core expectations for Fluid service is to be fast.\n\t\t\t// When it's not the case, we want to learn about it and be able to investigate, so\n\t\t\t// raise awareness.\n\t\t\t// This also helps identify cases where it's due to client behavior (sending too many ops)\n\t\t\t// that results in overwhelming ordering service and thus starting to see long latencies.\n\t\t\t// The threshold could be adjusted, but ideally it stays workload-agnostic, as service\n\t\t\t// performance impacts all workloads relying on service.\n\t\t\tconst category = duration > latencyThreshold ? \"error\" : \"performance\";\n\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"OpRoundtripTime\",\n\t\t\t\tsequenceNumber,\n\t\t\t\treferenceSequenceNumber: message.referenceSequenceNumber,\n\t\t\t\tduration,\n\t\t\t\tcategory,\n\t\t\t\tpingLatency: this.pingLatency,\n\t\t\t\tmsnDistance:\n\t\t\t\t\tthis.deltaManager.lastSequenceNumber - this.deltaManager.minimumSequenceNumber,\n\t\t\t\t...this.opPerfData,\n\t\t\t});\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.opPerfData = {};\n\t\t\tthis.opProcessingTimes = {};\n\t\t}\n\t}\n}\nexport interface IPerfSignalReport {\n\t/**\n\t * Identifier for the signal being submitted in order to\n\t * allow collection of data around the roundtrip of signal messages.\n\t */\n\tsignalSequenceNumber: number;\n\t/**\n\t * Number of signals that were expected but not received.\n\t */\n\tsignalsLost: number;\n\n\t/**\n\t * Timestamp before submitting the signal we will trace.\n\t */\n\tsignalTimestamp: number;\n\n\t/**\n\t * Expected Signal Sequence to be received.\n\t */\n\ttrackingSignalSequenceNumber: number | undefined;\n}\n\nexport function ReportOpPerfTelemetry(\n\tclientId: string | undefined,\n\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\tlogger: ITelemetryLoggerExt,\n) {\n\tnew OpPerfTelemetry(clientId, deltaManager, logger);\n}\n"]}
1
+ {"version":3,"file":"connectionTelemetry.js","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAuB,WAAW,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEpG,OAAO,EAGN,WAAW,GACX,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8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AI,CAAC,iBAAiB,GAAG,EAAE,CAAC;SAC5B;IACF,CAAC;CACD;AAuBD,MAAM,UAAU,qBAAqB,CACpC,QAA4B,EAC5B,YAAwE,EACxE,MAA2B;IAE3B,IAAI,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLoggerExt, ChildLogger, TelemetryLogger } from \"@fluidframework/telemetry-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport {\n\tIDocumentMessage,\n\tISequencedDocumentMessage,\n\tMessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\n\n/**\n * We report various latency-related errors when waiting for op roundtrip takes longer than that amout of time.\n */\nexport const latencyThreshold = 5000;\n\n// Phases in OpPerfTelemetry:\n// 1.\tOp is added to DeltaManager (DM) buffer.\n// 2.\tOp is sent to service (op leaves outbound queue).\n// \t - Note: We do not know for sure when op is sent, we only track when it is added to outbound queue.\n// If outbound queue is paused, time queue is paused is counted as network time.\n// 3.\tOp received from service back (pushed to inbound queue).\n// 4.\tOp is processed.\ninterface IOpPerfTelemetryProperties {\n\t/** Measure time between (1) and (2) - Measure time outbound op is sitting in queue due to active batch */\n\tdurationOutboundBatching: number; // was durationOutboundQueue in previous versions\n\t/** Measure time between (2) and (3) - Track how long it took for op to be acked by service */\n\tdurationNetwork: number; // was durationInboundQueue\n\t/** Measure time between (3) and (4) - Time between DM's inbound \"push\" event until DM's \"op\" event */\n\tdurationInboundToProcessing: number;\n\t/** Length of the DeltaManager's inbound queue at the time of the DM's inbound \"push\" event (3) */\n\tlengthInboundQueue: number;\n}\n\n/**\n * Timings collected at various moments during the op processing.\n */\ninterface IOpPerfTimings {\n\t/** Starting time for (1) */\n\tsubmitOpEventTime: number;\n\t/** Starting time for (2) */\n\toutboundPushEventTime: number;\n\t/** Starting time for (3) */\n\tinboundPushEventTime: number;\n}\n\nclass OpPerfTelemetry {\n\tprivate pongCount: number = 0;\n\tprivate pingLatency: number | undefined;\n\n\t// Collab window tracking. This is timestamp of %1000 message.\n\tprivate sequenceNumberForMsnTracking: number | undefined;\n\tprivate msnTrackingTimestamp: number = 0;\n\t// To track round trip time for every %500 client message.\n\tprivate clientSequenceNumberForLatencyStatistics: number | undefined;\n\n\tprivate opProcessingTimes: Partial<IOpPerfTimings> = {};\n\n\t// Performance Data to be reported for ops round trips and processing.\n\tprivate opPerfData: Partial<IOpPerfTelemetryProperties> = {};\n\n\tprivate firstConnection = true;\n\tprivate connectionOpSeqNumber: number | undefined;\n\tprivate readonly bootTime = performance.now();\n\tprivate connectionStartTime = 0;\n\tprivate gap = 0;\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tpublic constructor(\n\t\tprivate clientId: string | undefined,\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logger = ChildLogger.create(logger, \"OpPerf\");\n\n\t\tthis.deltaManager.on(\"pong\", (latency) => this.recordPingTime(latency));\n\t\tthis.deltaManager.on(\"submitOp\", (message) => this.beforeOpSubmit(message));\n\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterProcessingOp(message));\n\n\t\tthis.deltaManager.on(\"connect\", (details, opsBehind) => {\n\t\t\tthis.clientId = details.clientId;\n\t\t\tif (opsBehind !== undefined) {\n\t\t\t\tthis.connectionOpSeqNumber = this.deltaManager.lastKnownSeqNumber;\n\t\t\t\tthis.gap = opsBehind;\n\t\t\t\tthis.connectionStartTime = performance.now();\n\n\t\t\t\t// We might be already up-today. If so, report it right away.\n\t\t\t\tif (this.gap <= 0) {\n\t\t\t\t\tthis.reportGettingUpToDate();\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\tthis.deltaManager.on(\"disconnect\", () => {\n\t\t\tthis.sequenceNumberForMsnTracking = undefined;\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.opProcessingTimes = {};\n\t\t\tthis.opPerfData = {};\n\t\t\tthis.connectionOpSeqNumber = undefined;\n\t\t\tthis.firstConnection = false;\n\t\t\tthis.pongCount = 0;\n\t\t});\n\n\t\tthis.deltaManager.outbound.on(\"push\", (messages) => {\n\t\t\tfor (const msg of messages) {\n\t\t\t\tif (\n\t\t\t\t\tmsg.type === MessageType.Operation &&\n\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === msg.clientSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime === undefined,\n\t\t\t\t\t\t0x2c8 /* \"outboundPushEventTime should be undefined\" */,\n\t\t\t\t\t);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opPerfData.durationNetwork === undefined,\n\t\t\t\t\t\t0x2c9 /* \"durationNetwork should be undefined\" */,\n\t\t\t\t\t);\n\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime = Date.now();\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opPerfData.durationOutboundBatching === undefined,\n\t\t\t\t\t\t0x2ca /* \"durationOutboundBatching should be undefined\" */,\n\t\t\t\t\t);\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tthis.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t\t\t0x2cb /* \"submitOpEventTime should be undefined\" */,\n\t\t\t\t\t);\n\n\t\t\t\t\tthis.opPerfData.durationOutboundBatching =\n\t\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime -\n\t\t\t\t\t\tthis.opProcessingTimes.submitOpEventTime;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.deltaManager.inbound.on(\"push\", (message: ISequencedDocumentMessage) => {\n\t\t\tif (\n\t\t\t\tthis.clientId === message.clientId &&\n\t\t\t\tmessage.type === MessageType.Operation &&\n\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber &&\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime !== undefined\n\t\t\t) {\n\t\t\t\tthis.opProcessingTimes.inboundPushEventTime = Date.now();\n\t\t\t\tthis.opPerfData.durationNetwork =\n\t\t\t\t\tthis.opProcessingTimes.inboundPushEventTime -\n\t\t\t\t\tthis.opProcessingTimes.outboundPushEventTime;\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime = undefined;\n\t\t\t\tthis.opPerfData.lengthInboundQueue = this.deltaManager.inbound.length;\n\t\t\t}\n\t\t});\n\n\t\tthis.deltaManager.inbound.on(\"idle\", (count: number, duration: number) => {\n\t\t\t// Do not want to log zero for sure.\n\t\t\t// We are more interested in aggregates, so logging only if we are processing some number of ops\n\t\t\t// Cut-off is arbitrary - can be increased or decreased based on amount of data collected and questions we\n\t\t\t// want to get answered\n\t\t\t// back-compat: Once 0.36 loader version saturates (count & duration args were added there),\n\t\t\t// we can remove typeof check.\n\t\t\tif (typeof count === \"number\" && count >= 100) {\n\t\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\t\teventName: \"GetDeltas_OpProcessing\",\n\t\t\t\t\tcount,\n\t\t\t\t\tduration,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate reportGettingUpToDate() {\n\t\tthis.connectionOpSeqNumber = undefined;\n\t\tthis.logger.sendPerformanceEvent({\n\t\t\teventName: \"ConnectionSpeed\",\n\t\t\tduration: performance.now() - this.connectionStartTime,\n\t\t\tops: this.gap,\n\t\t\t// track time to connect only for first connection.\n\t\t\ttimeToConnect: this.firstConnection\n\t\t\t\t? TelemetryLogger.formatTick(this.connectionStartTime - this.bootTime)\n\t\t\t\t: undefined,\n\t\t\tfirstConnection: this.firstConnection,\n\t\t});\n\t}\n\n\tprivate recordPingTime(latency: number) {\n\t\tthis.pingLatency = latency;\n\n\t\t// Log if latency is longer than 1 min\n\t\tif (latency > 1000 * 60) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"LatencyTooLong\",\n\t\t\t\tduration: latency,\n\t\t\t});\n\t\t}\n\n\t\t// logging one in every 100 pongs, including the first time, if it is a \"write\" client.\n\t\tif (this.pongCount % 100 === 0 && this.deltaManager.active) {\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"DeltaLatency\",\n\t\t\t\tduration: latency,\n\t\t\t});\n\t\t}\n\t\tthis.pongCount++;\n\t}\n\n\tprivate beforeOpSubmit(message: IDocumentMessage) {\n\t\t// start with first client op and measure latency every 500 client ops\n\t\tif (\n\t\t\tthis.clientSequenceNumberForLatencyStatistics === undefined &&\n\t\t\tmessage.clientSequenceNumber % 500 === 1\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.opProcessingTimes.outboundPushEventTime === undefined,\n\t\t\t\t0x2cc /* \"OpTimeSittingInboundQueue should be undefined\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tthis.opPerfData.durationNetwork === undefined,\n\t\t\t\t0x2cd /* \"durationNetwork should be undefined\" */,\n\t\t\t);\n\t\t\tthis.opProcessingTimes.submitOpEventTime = Date.now();\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = message.clientSequenceNumber;\n\t\t}\n\t}\n\n\tprivate afterProcessingOp(message: ISequencedDocumentMessage) {\n\t\tconst sequenceNumber = message.sequenceNumber;\n\n\t\tif (sequenceNumber === this.connectionOpSeqNumber) {\n\t\t\tthis.reportGettingUpToDate();\n\t\t}\n\n\t\t// Record collab window max size after every 1000th op.\n\t\tif (this.sequenceNumberForMsnTracking === undefined && sequenceNumber % 1000 === 0) {\n\t\t\tthis.sequenceNumberForMsnTracking = sequenceNumber;\n\t\t\tthis.msnTrackingTimestamp = message.timestamp;\n\t\t}\n\t\tif (\n\t\t\tthis.sequenceNumberForMsnTracking !== undefined &&\n\t\t\tmessage.minimumSequenceNumber >= this.sequenceNumberForMsnTracking\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.msnTrackingTimestamp !== undefined,\n\t\t\t\t0x2ce /* \"msnTrackingTimestamp should not be undefined\" */,\n\t\t\t);\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"MsnStatistics\",\n\t\t\t\tsequenceNumber,\n\t\t\t\tmsnDistance: sequenceNumber - this.sequenceNumberForMsnTracking,\n\t\t\t\tduration: message.timestamp - this.msnTrackingTimestamp,\n\t\t\t});\n\t\t\tthis.sequenceNumberForMsnTracking = undefined;\n\t\t}\n\n\t\tif (\n\t\t\tthis.clientId === message.clientId &&\n\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t0x120 /* \"Undefined latency statistics (op send time)\" */,\n\t\t\t);\n\t\t\tconst currentTime = Date.now();\n\n\t\t\tif (this.opProcessingTimes.inboundPushEventTime !== undefined) {\n\t\t\t\tthis.opPerfData.durationInboundToProcessing =\n\t\t\t\t\tcurrentTime - this.opProcessingTimes.inboundPushEventTime;\n\t\t\t}\n\n\t\t\tconst duration = currentTime - this.opProcessingTimes.submitOpEventTime;\n\n\t\t\t// One of the core expectations for Fluid service is to be fast.\n\t\t\t// When it's not the case, we want to learn about it and be able to investigate, so\n\t\t\t// raise awareness.\n\t\t\t// This also helps identify cases where it's due to client behavior (sending too many ops)\n\t\t\t// that results in overwhelming ordering service and thus starting to see long latencies.\n\t\t\t// The threshold could be adjusted, but ideally it stays workload-agnostic, as service\n\t\t\t// performance impacts all workloads relying on service.\n\t\t\tconst category = duration > latencyThreshold ? \"error\" : \"performance\";\n\n\t\t\tthis.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"OpRoundtripTime\",\n\t\t\t\tsequenceNumber,\n\t\t\t\treferenceSequenceNumber: message.referenceSequenceNumber,\n\t\t\t\tduration,\n\t\t\t\tcategory,\n\t\t\t\tpingLatency: this.pingLatency,\n\t\t\t\tmsnDistance:\n\t\t\t\t\tthis.deltaManager.lastSequenceNumber - this.deltaManager.minimumSequenceNumber,\n\t\t\t\t...this.opPerfData,\n\t\t\t});\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.opPerfData = {};\n\t\t\tthis.opProcessingTimes = {};\n\t\t}\n\t}\n}\nexport interface IPerfSignalReport {\n\t/**\n\t * Identifier for the signal being submitted in order to\n\t * allow collection of data around the roundtrip of signal messages.\n\t */\n\tsignalSequenceNumber: number;\n\t/**\n\t * Number of signals that were expected but not received.\n\t */\n\tsignalsLost: number;\n\n\t/**\n\t * Timestamp before submitting the signal we will trace.\n\t */\n\tsignalTimestamp: number;\n\n\t/**\n\t * Expected Signal Sequence to be received.\n\t */\n\ttrackingSignalSequenceNumber: number | undefined;\n}\n\nexport function ReportOpPerfTelemetry(\n\tclientId: string | undefined,\n\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\tlogger: ITelemetryLoggerExt,\n) {\n\tnew OpPerfTelemetry(clientId, deltaManager, logger);\n}\n"]}
@@ -1,3 +1,7 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
1
5
  import { FluidObject, IFluidHandle, IFluidHandleContext, IFluidRouter, IRequest, IResponse } from "@fluidframework/core-interfaces";
2
6
  import { IAudience, IContainerContext, IDeltaManager, IRuntime, ICriticalContainerError, AttachState, ILoaderOptions } from "@fluidframework/container-definitions";
3
7
  import { IContainerRuntime, IContainerRuntimeEvents } from "@fluidframework/container-runtime-definitions";
@@ -207,24 +211,9 @@ export interface IContainerRuntimeOptions {
207
211
  * By default, the feature is disabled. If enabled from options, the `Fluid.ContainerRuntime.DisableGroupedBatching`
208
212
  * flag can be used to disable it at runtime.
209
213
  *
210
- * For safety, {@link IContainerRuntimeOptions#enableBatchRebasing} needs to also be enabled to ensure
211
- * consistency across clients.
212
- *
213
214
  * @experimental Not ready for use.
214
215
  */
215
216
  readonly enableGroupedBatching?: boolean;
216
- /**
217
- * Configures if the runtime should rebase a batch of ops when it detects op reentrancy,
218
- * when an op is created as the result of processing another op. Usually this is the case
219
- * when changes are made to a DDS inside a DDS 'onChanged' event handler. This means that the
220
- * reentrant op will have a different reference sequence number than the rest of the ops in
221
- * the batch, resulting in a different view of the state of the data model. Therefore all ops
222
- * must be resubmitted and rebased to the current reference sequence number to be in agreement
223
- * about the state of the data model.
224
- *
225
- * @experimental Not ready for use.
226
- */
227
- readonly enableBatchRebasing?: boolean;
228
217
  }
229
218
  /**
230
219
  * The summary tree returned by the root node. It adds state relevant to the root of the tree.