@fluidframework/container-runtime 2.10.0-304831 → 2.10.0-306579

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 (64) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/api-report/container-runtime.legacy.alpha.api.md +1 -1
  3. package/container-runtime.test-files.tar +0 -0
  4. package/dist/blobManager/blobManager.d.ts +6 -1
  5. package/dist/blobManager/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager/blobManager.js +22 -3
  7. package/dist/blobManager/blobManager.js.map +1 -1
  8. package/dist/connectionTelemetry.d.ts +2 -3
  9. package/dist/connectionTelemetry.d.ts.map +1 -1
  10. package/dist/connectionTelemetry.js.map +1 -1
  11. package/dist/containerHandleContext.d.ts +6 -2
  12. package/dist/containerHandleContext.d.ts.map +1 -1
  13. package/dist/containerHandleContext.js.map +1 -1
  14. package/dist/containerRuntime.d.ts +2 -1
  15. package/dist/containerRuntime.d.ts.map +1 -1
  16. package/dist/containerRuntime.js +15 -6
  17. package/dist/containerRuntime.js.map +1 -1
  18. package/dist/deltaManagerProxies.d.ts +8 -8
  19. package/dist/deltaManagerProxies.d.ts.map +1 -1
  20. package/dist/deltaManagerProxies.js.map +1 -1
  21. package/dist/deltaScheduler.d.ts +3 -3
  22. package/dist/deltaScheduler.d.ts.map +1 -1
  23. package/dist/deltaScheduler.js.map +1 -1
  24. package/dist/packageVersion.d.ts +1 -1
  25. package/dist/packageVersion.js +1 -1
  26. package/dist/packageVersion.js.map +1 -1
  27. package/dist/scheduleManager.d.ts +3 -3
  28. package/dist/scheduleManager.d.ts.map +1 -1
  29. package/dist/scheduleManager.js.map +1 -1
  30. package/lib/blobManager/blobManager.d.ts +6 -1
  31. package/lib/blobManager/blobManager.d.ts.map +1 -1
  32. package/lib/blobManager/blobManager.js +22 -3
  33. package/lib/blobManager/blobManager.js.map +1 -1
  34. package/lib/connectionTelemetry.d.ts +2 -3
  35. package/lib/connectionTelemetry.d.ts.map +1 -1
  36. package/lib/connectionTelemetry.js.map +1 -1
  37. package/lib/containerHandleContext.d.ts +6 -2
  38. package/lib/containerHandleContext.d.ts.map +1 -1
  39. package/lib/containerHandleContext.js.map +1 -1
  40. package/lib/containerRuntime.d.ts +2 -1
  41. package/lib/containerRuntime.d.ts.map +1 -1
  42. package/lib/containerRuntime.js +16 -7
  43. package/lib/containerRuntime.js.map +1 -1
  44. package/lib/deltaManagerProxies.d.ts +8 -8
  45. package/lib/deltaManagerProxies.d.ts.map +1 -1
  46. package/lib/deltaManagerProxies.js.map +1 -1
  47. package/lib/deltaScheduler.d.ts +3 -3
  48. package/lib/deltaScheduler.d.ts.map +1 -1
  49. package/lib/deltaScheduler.js.map +1 -1
  50. package/lib/packageVersion.d.ts +1 -1
  51. package/lib/packageVersion.js +1 -1
  52. package/lib/packageVersion.js.map +1 -1
  53. package/lib/scheduleManager.d.ts +3 -3
  54. package/lib/scheduleManager.d.ts.map +1 -1
  55. package/lib/scheduleManager.js.map +1 -1
  56. package/package.json +70 -18
  57. package/src/blobManager/blobManager.ts +27 -4
  58. package/src/connectionTelemetry.ts +3 -3
  59. package/src/containerHandleContext.ts +5 -2
  60. package/src/containerRuntime.ts +17 -12
  61. package/src/deltaManagerProxies.ts +5 -18
  62. package/src/deltaScheduler.ts +4 -7
  63. package/src/packageVersion.ts +1 -1
  64. package/src/scheduleManager.ts +3 -3
package/.eslintrc.cjs CHANGED
@@ -13,6 +13,7 @@ module.exports = {
13
13
  },
14
14
  rules: {
15
15
  "@typescript-eslint/strict-boolean-expressions": "off",
16
+ "@fluid-internal/fluid/no-unchecked-record-access": "warn",
16
17
  },
17
18
  overrides: [
18
19
  {
@@ -67,7 +67,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents
67
67
  // (undocumented)
68
68
  deleteChildSummarizerNode(id: string): void;
69
69
  deleteSweepReadyNodes(sweepReadyRoutes: readonly string[]): readonly string[];
70
- readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
70
+ get deltaManager(): IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
71
71
  // (undocumented)
72
72
  dispose(error?: Error): void;
73
73
  // (undocumented)
Binary file
@@ -6,7 +6,7 @@ import { TypedEventEmitter } from "@fluid-internal/client-utils";
6
6
  import { ICriticalContainerError } from "@fluidframework/container-definitions";
7
7
  import { IContainerRuntime, IContainerRuntimeEvents } from "@fluidframework/container-runtime-definitions/internal";
8
8
  import { IFluidHandleContext, type IFluidHandleInternal } from "@fluidframework/core-interfaces/internal";
9
- import { IDocumentStorageService } from "@fluidframework/driver-definitions/internal";
9
+ import { IDocumentStorageService, ICreateBlobResponse } from "@fluidframework/driver-definitions/internal";
10
10
  import { IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext, type ISequencedMessageEnvelope } from "@fluidframework/runtime-definitions/internal";
11
11
  import { FluidHandleBase } from "@fluidframework/runtime-utils/internal";
12
12
  import { type IBlobManagerLoadInfo } from "./blobManagerSnapSum.js";
@@ -71,6 +71,9 @@ export declare class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
71
71
  private readonly isBlobDeleted;
72
72
  private readonly runtime;
73
73
  private readonly closeContainer;
74
+ private readonly localBlobIdGenerator;
75
+ private readonly pendingStashedBlobs;
76
+ private stashedBlobsUploadP;
74
77
  constructor(props: {
75
78
  readonly routeContext: IFluidHandleContext;
76
79
  snapshot: IBlobManagerLoadInfo;
@@ -91,7 +94,9 @@ export declare class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {
91
94
  readonly runtime: IBlobManagerRuntime;
92
95
  stashedBlobs: IPendingBlobs | undefined;
93
96
  readonly closeContainer: (error?: ICriticalContainerError) => void;
97
+ readonly localBlobIdGenerator?: (() => string) | undefined;
94
98
  });
99
+ waitForStashedBlobs(): Promise<(void | ICreateBlobResponse)[]>;
95
100
  get allBlobsAttached(): boolean;
96
101
  get hasPendingBlobs(): boolean;
97
102
  private createAbortError;
@@ -1 +1 @@
1
- {"version":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CAiFrC;AAkBD;;GAEG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,gCACL,CAAC;AAEnC,eAAO,MAAM,gBAAgB,cACjB,MAAM,EAAE,wCAE2C,CAAC"}
@@ -65,13 +65,17 @@ class BlobManager extends client_utils_1.TypedEventEmitter {
65
65
  */
66
66
  this.opsInFlight = new Map();
67
67
  this.stopAttaching = false;
68
- const { routeContext, snapshot, getStorage, sendBlobAttachOp, blobRequested, isBlobDeleted, runtime, stashedBlobs, closeContainer, } = props;
68
+ // TODO: consider to replace with a lazy promise
69
+ this.pendingStashedBlobs = new Map();
70
+ this.stashedBlobsUploadP = undefined;
71
+ const { routeContext, snapshot, getStorage, sendBlobAttachOp, blobRequested, isBlobDeleted, runtime, stashedBlobs, closeContainer, localBlobIdGenerator, } = props;
69
72
  this.routeContext = routeContext;
70
73
  this.getStorage = getStorage;
71
74
  this.blobRequested = blobRequested;
72
75
  this.isBlobDeleted = isBlobDeleted;
73
76
  this.runtime = runtime;
74
77
  this.closeContainer = closeContainer;
78
+ this.localBlobIdGenerator = localBlobIdGenerator ?? uuid_1.v4;
75
79
  this.mc = (0, internal_4.createChildMonitoringContext)({
76
80
  logger: this.runtime.baseLogger,
77
81
  namespace: "BlobManager",
@@ -100,12 +104,18 @@ class BlobManager extends client_utils_1.TypedEventEmitter {
100
104
  return;
101
105
  }
102
106
  }
107
+ this.pendingStashedBlobs.set(localId, this.uploadBlob(localId, blob));
103
108
  this.pendingBlobs.set(localId, {
104
109
  ...pendingEntry,
105
110
  ...stashedPendingBlobOverrides,
106
- uploadP: this.uploadBlob(localId, blob),
111
+ uploadP: this.pendingStashedBlobs.get(localId),
107
112
  });
108
113
  });
114
+ this.waitForStashedBlobs()
115
+ .catch(() => { })
116
+ .finally(() => {
117
+ this.pendingStashedBlobs.clear();
118
+ });
109
119
  this.sendBlobAttachOp = (localId, blobId) => {
110
120
  const pendingEntry = this.pendingBlobs.get(localId);
111
121
  (0, internal_1.assert)(pendingEntry !== undefined, 0x725 /* Must have pending blob entry for upcoming op */);
@@ -131,6 +141,15 @@ class BlobManager extends client_utils_1.TypedEventEmitter {
131
141
  return sendBlobAttachOp(localId, blobId);
132
142
  };
133
143
  }
144
+ async waitForStashedBlobs() {
145
+ if (!this.stashedBlobsUploadP) {
146
+ this.stashedBlobsUploadP = Promise.all(this.pendingStashedBlobs.values()).finally(() => {
147
+ this.stashedBlobsUploadP = undefined;
148
+ return;
149
+ });
150
+ }
151
+ return this.stashedBlobsUploadP;
152
+ }
134
153
  get allBlobsAttached() {
135
154
  for (const [, entry] of this.pendingBlobs) {
136
155
  if (entry.attached === false) {
@@ -231,7 +250,7 @@ class BlobManager extends client_utils_1.TypedEventEmitter {
231
250
  }
232
251
  // Create a local ID for the blob. After uploading it to storage and before returning it, a local ID to
233
252
  // storage ID mapping is created.
234
- const localId = (0, uuid_1.v4)();
253
+ const localId = this.localBlobIdGenerator();
235
254
  const pendingEntry = {
236
255
  blob,
237
256
  handleP: new internal_1.Deferred(),
@@ -1 +1 @@
1
- {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../../src/blobManager/blobManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAIsC;AACtC,iFAA6F;AAS7F,kEAAuE;AAKvE,oEAAsF;AAOtF,qEAKgD;AAChD,uEAOkD;AAClD,+BAAkC;AAIlC,mEAKiC;AAEjC;;;;;;GAMG;AACH,MAAa,UAAW,SAAQ,0BAAgC;IAG/D,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC;IACtD,CAAC;IAID,YACiB,IAAY,EACZ,YAAiC,EAC1C,GAAmC,EACzB,aAA0B;QAE3C,KAAK,EAAE,CAAC;QALQ,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAqB;QAC1C,QAAG,GAAH,GAAG,CAAgC;QACzB,kBAAa,GAAb,aAAa,CAAa;QAZpC,aAAQ,GAAY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sD,EAAE,CAC9F,IAAA,wBAAgB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AADtB,QAAA,UAAU,cACY;AAE5B,MAAM,gBAAgB,GAAG,CAC/B,SAAmB,EACqC,EAAE,CAC1D,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,2BAAmB,CAAC;AAHnD,QAAA,gBAAgB,oBAGmC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tTypedEventEmitter,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { AttachState, ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tIContainerRuntime,\n\tIContainerRuntimeEvents,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport {\n\tIFluidHandleContext,\n\ttype IFluidHandleInternal,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tICreateBlobResponse,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canRetryOnError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\ttype ISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tFluidHandleBase,\n\tcreateResponseError,\n\tgenerateHandleContextPath,\n\tresponseToException,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tGenericError,\n\tLoggingError,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { IBlobMetadata } from \"../metadata.js\";\n\nimport {\n\tgetStorageIds,\n\tsummarizeBlobManagerState,\n\ttoRedirectTable,\n\ttype IBlobManagerLoadInfo,\n} from \"./blobManagerSnapSum.js\";\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 extends FluidHandleBase<ArrayBufferLike> {\n\tprivate attached: boolean = false;\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<ArrayBufferLike>,\n\t\tprivate readonly onAttachGraph?: () => void,\n\t) {\n\t\tsuper();\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: IFluidHandleInternal) {\n\t\tthrow new Error(\"Cannot bind to blob handle\");\n\t}\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\" | \"baseLogger\" | \"clientDetails\"\n> &\n\tTypedEventEmitter<IContainerRuntimeEvents>;\n\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse &\n\tPartial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n\tblob: ArrayBufferLike;\n\topsent?: boolean;\n\tstorageId?: string;\n\thandleP: Deferred<BlobHandle>;\n\tuploadP?: Promise<ICreateBlobResponse | void>;\n\tuploadTime?: number;\n\tminTTLInSeconds?: number;\n\tattached?: boolean;\n\tacked?: boolean;\n\tabortSignal?: AbortSignal;\n\tstashedUpload?: boolean;\n}\n\nexport interface IPendingBlobs {\n\t[id: string]: {\n\t\tblob: string;\n\t\tstorageId?: string;\n\t\tuploadTime?: number;\n\t\tminTTLInSeconds?: number;\n\t\tacked?: boolean;\n\t};\n}\n\nexport interface IBlobManagerEvents {\n\t(event: \"noPendingBlobs\", listener: () => void);\n}\n\nconst stashedPendingBlobOverrides: Pick<\n\tPendingBlob,\n\t\"stashedUpload\" | \"storageId\" | \"minTTLInSeconds\" | \"uploadTime\"\n> = {\n\tstashedUpload: true,\n\tstorageId: undefined,\n\tminTTLInSeconds: undefined,\n\tuploadTime: undefined,\n} as const;\n\nexport const blobManagerBasePath = \"_blobs\" as const;\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\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 we have not yet seen a BlobAttach op round-trip and not yet attached to a DDS.\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 sendBlobAttachOp: (localId: string, storageId?: string) => void;\n\tprivate stopAttaching: boolean = false;\n\n\tprivate readonly routeContext: IFluidHandleContext;\n\tprivate readonly getStorage: () => IDocumentStorageService;\n\t// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.\n\t// blobPath's format - `/<basePath>/<blobId>`.\n\tprivate readonly blobRequested: (blobPath: string) => void;\n\t// Called to check if a blob has been deleted by GC.\n\t// blobPath's format - `/<basePath>/<blobId>`.\n\tprivate readonly isBlobDeleted: (blobPath: string) => boolean;\n\tprivate readonly runtime: IBlobManagerRuntime;\n\tprivate readonly closeContainer: (error?: ICriticalContainerError) => void;\n\n\tconstructor(props: {\n\t\treadonly routeContext: IFluidHandleContext;\n\t\tsnapshot: IBlobManagerLoadInfo;\n\t\treadonly 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 - `/<basePath>/<blobId>`.\n\t\treadonly blobRequested: (blobPath: string) => void;\n\t\t// Called to check if a blob has been deleted by GC.\n\t\t// blobPath's format - `/<basePath>/<blobId>`.\n\t\treadonly isBlobDeleted: (blobPath: string) => boolean;\n\t\treadonly runtime: IBlobManagerRuntime;\n\t\tstashedBlobs: IPendingBlobs | undefined;\n\t\treadonly closeContainer: (error?: ICriticalContainerError) => void;\n\t}) {\n\t\tsuper();\n\t\tconst {\n\t\t\trouteContext,\n\t\t\tsnapshot,\n\t\t\tgetStorage,\n\t\t\tsendBlobAttachOp,\n\t\t\tblobRequested,\n\t\t\tisBlobDeleted,\n\t\t\truntime,\n\t\t\tstashedBlobs,\n\t\t\tcloseContainer,\n\t\t} = props;\n\t\tthis.routeContext = routeContext;\n\t\tthis.getStorage = getStorage;\n\t\tthis.blobRequested = blobRequested;\n\t\tthis.isBlobDeleted = isBlobDeleted;\n\t\tthis.runtime = runtime;\n\t\tthis.closeContainer = closeContainer;\n\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: this.runtime.baseLogger,\n\t\t\tnamespace: \"BlobManager\",\n\t\t});\n\n\t\tthis.redirectTable = toRedirectTable(snapshot, this.mc.logger, this.runtime.attachState);\n\n\t\t// Begin uploading stashed blobs from previous container instance\n\t\tObject.entries(stashedBlobs ?? {}).forEach(([localId, entry]) => {\n\t\t\tconst { acked, storageId, minTTLInSeconds, uploadTime } = entry;\n\t\t\tconst blob = stringToBuffer(entry.blob, \"base64\");\n\t\t\tconst pendingEntry: PendingBlob = {\n\t\t\t\tblob,\n\t\t\t\topsent: true,\n\t\t\t\thandleP: new Deferred(),\n\t\t\t\tstorageId,\n\t\t\t\tuploadP: undefined,\n\t\t\t\tuploadTime,\n\t\t\t\tminTTLInSeconds,\n\t\t\t\tattached: true,\n\t\t\t\tacked,\n\t\t\t};\n\t\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\t\tif (storageId !== undefined && minTTLInSeconds && uploadTime) {\n\t\t\t\tconst timeLapseSinceLocalUpload = (Date.now() - 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 (minTTLInSeconds - timeLapseSinceLocalUpload > minTTLInSeconds / 2) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\t...pendingEntry,\n\t\t\t\t...stashedPendingBlobOverrides,\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\tassert(\n\t\t\t\tpendingEntry !== undefined,\n\t\t\t\t0x725 /* Must have pending blob entry for upcoming op */,\n\t\t\t);\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\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(\"Trying to submit a BlobAttach for expired blob\", undefined, {\n\t\t\t\t\t\t\tlocalId,\n\t\t\t\t\t\t\tblobId,\n\t\t\t\t\t\t\tsecondsSinceUpload,\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\tpendingEntry.opsent = true;\n\t\t\treturn sendBlobAttachOp(localId, blobId);\n\t\t};\n\t}\n\n\tpublic get allBlobsAttached(): boolean {\n\t\tfor (const [, entry] of this.pendingBlobs) {\n\t\t\tif (entry.attached === false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\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\tprivate createAbortError(pending?: PendingBlob) {\n\t\treturn new LoggingError(\"uploadBlob aborted\", {\n\t\t\tacked: pending?.acked,\n\t\t\tuploadTime: pending?.uploadTime,\n\t\t});\n\t}\n\n\tpublic hasPendingStashedUploads(): boolean {\n\t\treturn Array.from(this.pendingBlobs.values()).some((e) => e.stashedUpload === true);\n\t}\n\t/**\n\t * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n\t */\n\tpublic async trackPendingStashedUploads(): Promise<void> {\n\t\tconst pendingUploads = Array.from(this.pendingBlobs.values())\n\t\t\t.filter((e) => e.stashedUpload === true)\n\t\t\t.map(async (e) => e.uploadP);\n\t\tif (pendingUploads.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"BlobUploadProcessStashedChanges\",\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\tpublic async getBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\t// Verify that the blob is not deleted, i.e., it has not been garbage collected. If it is, this will throw\n\t\t// an error, failing the call.\n\t\tthis.verifyBlobNotDeleted(blobId);\n\t\t// Let runtime know that the corresponding GC node was requested.\n\t\t// Note that this will throw if the blob is inactive or tombstoned and throwing on incorrect usage\n\t\t// is configured.\n\t\tthis.blobRequested(getGCNodePathFromBlobId(blobId));\n\n\t\tconst pending = this.pendingBlobs.get(blobId);\n\t\tif (pending) {\n\t\t\treturn pending.blob;\n\t\t}\n\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\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\t// Create a callback function for once the blob has been attached\n\t\tconst callback = pending\n\t\t\t? () => {\n\t\t\t\t\tpending.attached = true;\n\t\t\t\t\t// Notify listeners (e.g. serialization process) that blob has been attached\n\t\t\t\t\tthis.emit(\"blobAttached\", pending);\n\t\t\t\t\tthis.deletePendingBlobMaybe(id);\n\t\t\t\t}\n\t\t\t: undefined;\n\t\treturn new BlobHandle(\n\t\t\tgetGCNodePathFromBlobId(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<IFluidHandleInternal<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(\n\t\tblob: ArrayBufferLike,\n\t\tsignal?: AbortSignal,\n\t): Promise<IFluidHandleInternal<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\tif (signal?.aborted) {\n\t\t\tthrow this.createAbortError();\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\thandleP: new Deferred(),\n\t\t\tuploadP: this.uploadBlob(localId, blob),\n\t\t\tattached: false,\n\t\t\tacked: false,\n\t\t\tabortSignal: signal,\n\t\t\topsent: false,\n\t\t};\n\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\tconst abortListener = () => {\n\t\t\tif (!pendingEntry.acked) {\n\t\t\t\tpendingEntry.handleP.reject(this.createAbortError(pendingEntry));\n\t\t\t}\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", abortListener, { once: true });\n\n\t\treturn pendingEntry.handleP.promise.finally(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", abortListener);\n\t\t});\n\t}\n\n\tprivate async uploadBlob(\n\t\tlocalId: string,\n\t\tblob: ArrayBufferLike,\n\t): Promise<ICreateBlobResponse | void> {\n\t\treturn runWithRetry(\n\t\t\tasync () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await this.getStorage().createBlob(blob);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst entry = this.pendingBlobs.get(localId);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!!entry,\n\t\t\t\t\t\t0x387 /* Must have pending blob entry for blob which failed to upload */,\n\t\t\t\t\t);\n\t\t\t\t\tif (entry.opsent && !canRetryOnError(error)) {\n\t\t\t\t\t\tthrow wrapError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t() => new LoggingError(`uploadBlob error`, { canRetry: true }),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"createBlob\",\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\tcancel: this.pendingBlobs.get(localId)?.abortSignal,\n\t\t\t},\n\t\t).then(\n\t\t\t(response) => this.onUploadResolve(localId, response),\n\t\t\t(error) => {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"UploadBlobReject\",\n\t\t\t\t\terror,\n\t\t\t\t\tlocalId,\n\t\t\t\t});\n\t\t\t\t// it will only reject if we haven't sent an op\n\t\t\t\t// and is a non-retriable error. It will only reject\n\t\t\t\t// the promise but not throw any error outside.\n\t\t\t\tthis.pendingBlobs.get(localId)?.handleP.reject(error);\n\t\t\t\tthis.deletePendingBlob(localId);\n\t\t\t},\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.deletePendingBlob(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deletePendingBlob(id: string) {\n\t\tif (this.pendingBlobs.delete(id) && !this.hasPendingBlobs) {\n\t\t\tthis.emit(\"noPendingBlobs\");\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\tif ((entry.abortSignal?.aborted === true && !entry.opsent) || this.stopAttaching) {\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"BlobAborted\",\n\t\t\t\tlocalId,\n\t\t\t});\n\t\t\tthis.deletePendingBlob(localId);\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tentry.storageId === undefined,\n\t\t\t0x386 /* Must have pending blob entry for uploaded blob */,\n\t\t);\n\t\tentry.stashedUpload = undefined;\n\t\tentry.storageId = response.id;\n\t\tentry.uploadTime = Date.now();\n\t\tentry.minTTLInSeconds = response.minTTLInSeconds;\n\t\t// Send a blob attach op. This serves two purposes:\n\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// until its storage ID is added to the next summary.\n\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// blob from the server via the storage ID.\n\t\tif (!entry.opsent) {\n\t\t\tthis.sendBlobAttachOp(localId, response.id);\n\t\t}\n\t\tconst storageIds = getStorageIds(this.redirectTable, this.runtime.attachState);\n\t\tif (storageIds.has(response.id)) {\n\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// 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// happened before and so, the server won't delete it.\n\t\t\tthis.setRedirection(localId, response.id);\n\t\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t} else {\n\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// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n\t\t\t// blob alive in storage.\n\t\t\tthis.opsInFlight.set(\n\t\t\t\tresponse.id,\n\t\t\t\t(this.opsInFlight.get(response.id) ?? []).concat(localId),\n\t\t\t);\n\t\t}\n\t\treturn response;\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?.opsent === true && !!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 processBlobAttachMessage(message: ISequencedMessageEnvelope, local: boolean) {\n\t\tconst localId = (message.metadata as IBlobMetadata | undefined)?.localId;\n\t\tconst blobId = (message.metadata as IBlobMetadata | undefined)?.blobId;\n\n\t\tif (localId) {\n\t\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\t\tif (pendingEntry?.abortSignal?.aborted) {\n\t\t\t\tthis.deletePendingBlob(localId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\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\t\t\t\t\tthis.setRedirection(pendingLocalId, blobId);\n\t\t\t\t\tentry.acked = true;\n\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n\t\t\t\t\tthis.deletePendingBlobMaybe(pendingLocalId);\n\t\t\t\t});\n\t\t\t\tthis.opsInFlight.delete(blobId);\n\t\t\t}\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\tlocalEntry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n\t\treturn summarizeBlobManagerState(this.redirectTable, this.runtime.attachState);\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 * 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: readonly string[]): readonly string[] {\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 -`/<blobManagerBasePath>/<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: readonly 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\t// If the blob hasn't already been deleted, log an error because this should never happen.\n\t\t\t// If the blob has already been deleted, log a telemetry event. This can happen because multiple GC\n\t\t\t// sweep ops can contain the same data store. It would be interesting to track how often this happens.\n\t\t\tconst alreadyDeleted = this.isBlobDeleted(route);\n\t\t\tif (!this.redirectTable.has(blobId)) {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"DeletedAttachmentBlobNotFound\",\n\t\t\t\t\tcategory: alreadyDeleted ? \"generic\" : \"error\",\n\t\t\t\t\tblobId,\n\t\t\t\t\tdetails: { alreadyDeleted },\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 * Verifies that the blob with given id is not deleted, 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 verifyBlobNotDeleted(blobId: string) {\n\t\tif (!this.isBlobDeleted(getGCNodePathFromBlobId(blobId))) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst request = { url: blobId };\n\t\tconst error = responseToException(\n\t\t\tcreateResponseError(404, `Blob was deleted`, request),\n\t\t\trequest,\n\t\t);\n\t\t// Only log deleted events. Tombstone events are logged by garbage collector.\n\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t{\n\t\t\t\teventName: \"GC_Deleted_Blob_Requested\",\n\t\t\t\tpkg: blobManagerBasePath,\n\t\t\t},\n\t\t\terror,\n\t\t);\n\t\tthrow error;\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(this.redirectTable.has(localId), 0x254 /* \"unrecognized id in redirect table\" */);\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\t/**\n\t * Part of container serialization when imminent closure is enabled (Currently when calling closeAndGetPendingLocalState).\n\t * This asynchronous function resolves all pending createBlob calls and waits for each blob\n\t * to be attached. It will also send BlobAttach ops for each pending blob that hasn't sent it\n\t * yet so that serialized container can resubmit them when rehydrated.\n\t *\n\t * @param stopBlobAttachingSignal - Optional signal to abort the blob attaching process.\n\t * @returns - A promise that resolves with the details of the attached blobs,\n\t * or undefined if no blobs were processed.\n\t */\n\tpublic async attachAndGetPendingBlobs(\n\t\tstopBlobAttachingSignal?: AbortSignal,\n\t): Promise<IPendingBlobs | undefined> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"GetPendingBlobs\" },\n\t\t\tasync () => {\n\t\t\t\tif (this.pendingBlobs.size === 0) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst blobs = {};\n\t\t\t\tconst localBlobs = new Set<PendingBlob>();\n\t\t\t\t// This while is used to stash blobs created while attaching and getting blobs\n\t\t\t\twhile (localBlobs.size < this.pendingBlobs.size) {\n\t\t\t\t\tconst attachBlobsP: Promise<void>[] = [];\n\t\t\t\t\tfor (const [id, entry] of this.pendingBlobs) {\n\t\t\t\t\t\tif (!localBlobs.has(entry)) {\n\t\t\t\t\t\t\tlocalBlobs.add(entry);\n\t\t\t\t\t\t\t// In order to follow natural blob creation flow we need to:\n\t\t\t\t\t\t\t// 1 send the blob attach op\n\t\t\t\t\t\t\t// 2 resolve the blob handle\n\t\t\t\t\t\t\t// 3 wait for op referencing the blob\n\t\t\t\t\t\t\tif (!entry.opsent) {\n\t\t\t\t\t\t\t\tthis.sendBlobAttachOp(id, entry.storageId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Resolving the blob handle to let hosts continue with their operations (it will resolve\n\t\t\t\t\t\t\t// original createBlob call) and let them attach the blob. This is a lie we told since the upload\n\t\t\t\t\t\t\t// hasn't finished yet, but it's fine since we will retry on rehydration.\n\t\t\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(id));\n\t\t\t\t\t\t\t// Array of promises that will resolve when blobs get attached.\n\t\t\t\t\t\t\tattachBlobsP.push(\n\t\t\t\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\t\tstopBlobAttachingSignal?.addEventListener(\n\t\t\t\t\t\t\t\t\t\t\"abort\",\n\t\t\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\t\t\tthis.stopAttaching = true;\n\t\t\t\t\t\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{ once: true },\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tconst onBlobAttached = (attachedEntry) => {\n\t\t\t\t\t\t\t\t\t\tif (attachedEntry === entry) {\n\t\t\t\t\t\t\t\t\t\t\tthis.off(\"blobAttached\", onBlobAttached);\n\t\t\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tif (!entry.attached) {\n\t\t\t\t\t\t\t\t\t\tthis.on(\"blobAttached\", onBlobAttached);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}),\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\t// Wait for all blobs to be attached. This is important, otherwise serialized container\n\t\t\t\t\t// could send the blobAttach op without any op that references the blob, making it useless.\n\t\t\t\t\tawait Promise.allSettled(attachBlobsP).catch(() => {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tfor (const [id, entry] of this.pendingBlobs) {\n\t\t\t\t\tif (stopBlobAttachingSignal?.aborted && !entry.attached) {\n\t\t\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\t\t\teventName: \"UnableToStashBlob\",\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tassert(entry.attached === true, 0x790 /* stashed blob should be attached */);\n\t\t\t\t\tblobs[id] = {\n\t\t\t\t\t\tblob: bufferToString(entry.blob, \"base64\"),\n\t\t\t\t\t\tstorageId: entry.storageId,\n\t\t\t\t\t\tacked: entry.acked,\n\t\t\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn Object.keys(blobs).length > 0 ? blobs : undefined;\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<blobManagerBasePath>/<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 */\nconst getGCNodePathFromBlobId = (blobId: string) => `/${blobManagerBasePath}/${blobId}`;\n\n/**\n * For a given GC node path, return the blobId. The node path is of the format `/<basePath>/<blobId>`.\n */\nconst getBlobIdFromGCNodePath = (nodePath: string) => {\n\tconst pathParts = nodePath.split(\"/\");\n\tassert(areBlobPathParts(pathParts), 0x5bd /* Invalid blob node path */);\n\treturn pathParts[2];\n};\n\n/**\n * Returns whether a given path is for attachment blobs that are in the format - \"/blobManagerBasePath/...\".\n */\nexport const isBlobPath = (path: string): path is `/${typeof blobManagerBasePath}/${string}` =>\n\tareBlobPathParts(path.split(\"/\"));\n\nexport const areBlobPathParts = (\n\tpathParts: string[],\n): pathParts is [\"\", typeof blobManagerBasePath, string] =>\n\tpathParts.length === 3 && pathParts[1] === blobManagerBasePath;\n"]}
1
+ {"version":3,"file":"blobManager.js","sourceRoot":"","sources":["../../src/blobManager/blobManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAIsC;AACtC,iFAA6F;AAS7F,kEAAuE;AAKvE,oEAAsF;AAOtF,qEAKgD;AAChD,uEAOkD;AAClD,+BAAkC;AAIlC,mEAKiC;AAEjC;;;;;;GAMG;AACH,MAAa,UAAW,SAAQ,0BAAgC;IAG/D,IAAW,UAAU;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,IAAI,IAAI,CAAC,QAAQ,CAAC;IACtD,CAAC;IAID,YACiB,IAAY,EACZ,YAAiC,EAC1C,GAAmC,EACzB,aAA0B;QAE3C,KAAK,EAAE,CAAC;QALQ,SAAI,GAAJ,IAAI,CAAQ;QACZ,iBAAY,GAAZ,YAAY,CAAqB;QAC1C,QAAG,GAAH,GAAG,CAAgC;QACzB,kBAAa,GAAb,aAAa,CAAa;QAZpC,aAAQ,GAAY,KAAK,CAAC;QAejC,IAAI,CAAC,YAAY,GAAG,IAAA,oCAAyB,EAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IACxE,CAAC;IAEM,WAAW;QACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;YACrB,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;QACxB,CAAC;IACF,CAAC;IAEM,IAAI,CAAC,MAA4B;QACvC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC/C,CAAC;CACD;AA7BD,gCA6BC;AAyCD,MAAM,2BAA2B,GAG7B;IACH,aAAa,EAAE,IAAI;I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C,IAAI,2BAAmB,IAAI,MAAM,EAAE,CAAC;AAExF;;GAEG;AACH,MAAM,uBAAuB,GAAG,CAAC,QAAgB,EAAE,EAAE;IACpD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,IAAA,iBAAM,EAAC,IAAA,wBAAgB,EAAC,SAAS,CAAC,EAAE,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACxE,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC;AAEF;;GAEG;AACI,MAAM,UAAU,GAAG,CAAC,IAAY,EAAsD,EAAE,CAC9F,IAAA,wBAAgB,EAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AADtB,QAAA,UAAU,cACY;AAE5B,MAAM,gBAAgB,GAAG,CAC/B,SAAmB,EACqC,EAAE,CAC1D,SAAS,CAAC,MAAM,KAAK,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,2BAAmB,CAAC;AAHnD,QAAA,gBAAgB,oBAGmC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tTypedEventEmitter,\n\tbufferToString,\n\tstringToBuffer,\n} from \"@fluid-internal/client-utils\";\nimport { AttachState, ICriticalContainerError } from \"@fluidframework/container-definitions\";\nimport {\n\tIContainerRuntime,\n\tIContainerRuntimeEvents,\n} from \"@fluidframework/container-runtime-definitions/internal\";\nimport {\n\tIFluidHandleContext,\n\ttype IFluidHandleInternal,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { assert, Deferred } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentStorageService,\n\tICreateBlobResponse,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { canRetryOnError, runWithRetry } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\ttype ISequencedMessageEnvelope,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tFluidHandleBase,\n\tcreateResponseError,\n\tgenerateHandleContextPath,\n\tresponseToException,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tGenericError,\n\tLoggingError,\n\tMonitoringContext,\n\tPerformanceEvent,\n\tcreateChildMonitoringContext,\n\twrapError,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { v4 as uuid } from \"uuid\";\n\nimport { IBlobMetadata } from \"../metadata.js\";\n\nimport {\n\tgetStorageIds,\n\tsummarizeBlobManagerState,\n\ttoRedirectTable,\n\ttype IBlobManagerLoadInfo,\n} from \"./blobManagerSnapSum.js\";\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 extends FluidHandleBase<ArrayBufferLike> {\n\tprivate attached: boolean = false;\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<ArrayBufferLike>,\n\t\tprivate readonly onAttachGraph?: () => void,\n\t) {\n\t\tsuper();\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: IFluidHandleInternal) {\n\t\tthrow new Error(\"Cannot bind to blob handle\");\n\t}\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\" | \"baseLogger\" | \"clientDetails\"\n> &\n\tTypedEventEmitter<IContainerRuntimeEvents>;\n\ntype ICreateBlobResponseWithTTL = ICreateBlobResponse &\n\tPartial<Record<\"minTTLInSeconds\", number>>;\n\ninterface PendingBlob {\n\tblob: ArrayBufferLike;\n\topsent?: boolean;\n\tstorageId?: string;\n\thandleP: Deferred<BlobHandle>;\n\tuploadP?: Promise<ICreateBlobResponse | void>;\n\tuploadTime?: number;\n\tminTTLInSeconds?: number;\n\tattached?: boolean;\n\tacked?: boolean;\n\tabortSignal?: AbortSignal;\n\tstashedUpload?: boolean;\n}\n\nexport interface IPendingBlobs {\n\t[id: string]: {\n\t\tblob: string;\n\t\tstorageId?: string;\n\t\tuploadTime?: number;\n\t\tminTTLInSeconds?: number;\n\t\tacked?: boolean;\n\t};\n}\n\nexport interface IBlobManagerEvents {\n\t(event: \"noPendingBlobs\", listener: () => void);\n}\n\nconst stashedPendingBlobOverrides: Pick<\n\tPendingBlob,\n\t\"stashedUpload\" | \"storageId\" | \"minTTLInSeconds\" | \"uploadTime\"\n> = {\n\tstashedUpload: true,\n\tstorageId: undefined,\n\tminTTLInSeconds: undefined,\n\tuploadTime: undefined,\n} as const;\n\nexport const blobManagerBasePath = \"_blobs\" as const;\n\nexport class BlobManager extends TypedEventEmitter<IBlobManagerEvents> {\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 we have not yet seen a BlobAttach op round-trip and not yet attached to a DDS.\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 sendBlobAttachOp: (localId: string, storageId?: string) => void;\n\tprivate stopAttaching: boolean = false;\n\n\tprivate readonly routeContext: IFluidHandleContext;\n\tprivate readonly getStorage: () => IDocumentStorageService;\n\t// Called when a blob node is requested. blobPath is the path of the blob's node in GC's graph.\n\t// blobPath's format - `/<basePath>/<blobId>`.\n\tprivate readonly blobRequested: (blobPath: string) => void;\n\t// Called to check if a blob has been deleted by GC.\n\t// blobPath's format - `/<basePath>/<blobId>`.\n\tprivate readonly isBlobDeleted: (blobPath: string) => boolean;\n\tprivate readonly runtime: IBlobManagerRuntime;\n\tprivate readonly closeContainer: (error?: ICriticalContainerError) => void;\n\tprivate readonly localBlobIdGenerator: () => string;\n\t// TODO: consider to replace with a lazy promise\n\tprivate readonly pendingStashedBlobs: Map<string, Promise<ICreateBlobResponse | void>> =\n\t\tnew Map();\n\tprivate stashedBlobsUploadP: Promise<(void | ICreateBlobResponse)[]> | undefined = undefined;\n\n\tconstructor(props: {\n\t\treadonly routeContext: IFluidHandleContext;\n\t\tsnapshot: IBlobManagerLoadInfo;\n\t\treadonly 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 - `/<basePath>/<blobId>`.\n\t\treadonly blobRequested: (blobPath: string) => void;\n\t\t// Called to check if a blob has been deleted by GC.\n\t\t// blobPath's format - `/<basePath>/<blobId>`.\n\t\treadonly isBlobDeleted: (blobPath: string) => boolean;\n\t\treadonly runtime: IBlobManagerRuntime;\n\t\tstashedBlobs: IPendingBlobs | undefined;\n\t\treadonly closeContainer: (error?: ICriticalContainerError) => void;\n\t\treadonly localBlobIdGenerator?: (() => string) | undefined;\n\t}) {\n\t\tsuper();\n\t\tconst {\n\t\t\trouteContext,\n\t\t\tsnapshot,\n\t\t\tgetStorage,\n\t\t\tsendBlobAttachOp,\n\t\t\tblobRequested,\n\t\t\tisBlobDeleted,\n\t\t\truntime,\n\t\t\tstashedBlobs,\n\t\t\tcloseContainer,\n\t\t\tlocalBlobIdGenerator,\n\t\t} = props;\n\t\tthis.routeContext = routeContext;\n\t\tthis.getStorage = getStorage;\n\t\tthis.blobRequested = blobRequested;\n\t\tthis.isBlobDeleted = isBlobDeleted;\n\t\tthis.runtime = runtime;\n\t\tthis.closeContainer = closeContainer;\n\t\tthis.localBlobIdGenerator = localBlobIdGenerator ?? uuid;\n\n\t\tthis.mc = createChildMonitoringContext({\n\t\t\tlogger: this.runtime.baseLogger,\n\t\t\tnamespace: \"BlobManager\",\n\t\t});\n\n\t\tthis.redirectTable = toRedirectTable(snapshot, this.mc.logger, this.runtime.attachState);\n\n\t\t// Begin uploading stashed blobs from previous container instance\n\t\tObject.entries(stashedBlobs ?? {}).forEach(([localId, entry]) => {\n\t\t\tconst { acked, storageId, minTTLInSeconds, uploadTime } = entry;\n\t\t\tconst blob = stringToBuffer(entry.blob, \"base64\");\n\t\t\tconst pendingEntry: PendingBlob = {\n\t\t\t\tblob,\n\t\t\t\topsent: true,\n\t\t\t\thandleP: new Deferred(),\n\t\t\t\tstorageId,\n\t\t\t\tuploadP: undefined,\n\t\t\t\tuploadTime,\n\t\t\t\tminTTLInSeconds,\n\t\t\t\tattached: true,\n\t\t\t\tacked,\n\t\t\t};\n\t\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\t\tif (storageId !== undefined && minTTLInSeconds && uploadTime) {\n\t\t\t\tconst timeLapseSinceLocalUpload = (Date.now() - 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 (minTTLInSeconds - timeLapseSinceLocalUpload > minTTLInSeconds / 2) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.pendingStashedBlobs.set(localId, this.uploadBlob(localId, blob));\n\t\t\tthis.pendingBlobs.set(localId, {\n\t\t\t\t...pendingEntry,\n\t\t\t\t...stashedPendingBlobOverrides,\n\t\t\t\tuploadP: this.pendingStashedBlobs.get(localId),\n\t\t\t});\n\t\t});\n\t\tthis.waitForStashedBlobs()\n\t\t\t.catch(() => {})\n\t\t\t.finally(() => {\n\t\t\t\tthis.pendingStashedBlobs.clear();\n\t\t\t});\n\t\tthis.sendBlobAttachOp = (localId: string, blobId?: string) => {\n\t\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\t\tassert(\n\t\t\t\tpendingEntry !== undefined,\n\t\t\t\t0x725 /* Must have pending blob entry for upcoming op */,\n\t\t\t);\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\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(\"Trying to submit a BlobAttach for expired blob\", undefined, {\n\t\t\t\t\t\t\tlocalId,\n\t\t\t\t\t\t\tblobId,\n\t\t\t\t\t\t\tsecondsSinceUpload,\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\tpendingEntry.opsent = true;\n\t\t\treturn sendBlobAttachOp(localId, blobId);\n\t\t};\n\t}\n\n\tpublic async waitForStashedBlobs(): Promise<(void | ICreateBlobResponse)[]> {\n\t\tif (!this.stashedBlobsUploadP) {\n\t\t\tthis.stashedBlobsUploadP = Promise.all(this.pendingStashedBlobs.values()).finally(() => {\n\t\t\t\tthis.stashedBlobsUploadP = undefined;\n\t\t\t\treturn;\n\t\t\t});\n\t\t}\n\n\t\treturn this.stashedBlobsUploadP;\n\t}\n\n\tpublic get allBlobsAttached(): boolean {\n\t\tfor (const [, entry] of this.pendingBlobs) {\n\t\t\tif (entry.attached === false) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\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\tprivate createAbortError(pending?: PendingBlob) {\n\t\treturn new LoggingError(\"uploadBlob aborted\", {\n\t\t\tacked: pending?.acked,\n\t\t\tuploadTime: pending?.uploadTime,\n\t\t});\n\t}\n\n\tpublic hasPendingStashedUploads(): boolean {\n\t\treturn Array.from(this.pendingBlobs.values()).some((e) => e.stashedUpload === true);\n\t}\n\t/**\n\t * Upload blobs added while offline. This must be completed before connecting and resubmitting ops.\n\t */\n\tpublic async trackPendingStashedUploads(): Promise<void> {\n\t\tconst pendingUploads = Array.from(this.pendingBlobs.values())\n\t\t\t.filter((e) => e.stashedUpload === true)\n\t\t\t.map(async (e) => e.uploadP);\n\t\tif (pendingUploads.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\teventName: \"BlobUploadProcessStashedChanges\",\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\tpublic async getBlob(blobId: string): Promise<ArrayBufferLike> {\n\t\t// Verify that the blob is not deleted, i.e., it has not been garbage collected. If it is, this will throw\n\t\t// an error, failing the call.\n\t\tthis.verifyBlobNotDeleted(blobId);\n\t\t// Let runtime know that the corresponding GC node was requested.\n\t\t// Note that this will throw if the blob is inactive or tombstoned and throwing on incorrect usage\n\t\t// is configured.\n\t\tthis.blobRequested(getGCNodePathFromBlobId(blobId));\n\n\t\tconst pending = this.pendingBlobs.get(blobId);\n\t\tif (pending) {\n\t\t\treturn pending.blob;\n\t\t}\n\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\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\t// Create a callback function for once the blob has been attached\n\t\tconst callback = pending\n\t\t\t? () => {\n\t\t\t\t\tpending.attached = true;\n\t\t\t\t\t// Notify listeners (e.g. serialization process) that blob has been attached\n\t\t\t\t\tthis.emit(\"blobAttached\", pending);\n\t\t\t\t\tthis.deletePendingBlobMaybe(id);\n\t\t\t\t}\n\t\t\t: undefined;\n\t\treturn new BlobHandle(\n\t\t\tgetGCNodePathFromBlobId(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<IFluidHandleInternal<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(\n\t\tblob: ArrayBufferLike,\n\t\tsignal?: AbortSignal,\n\t): Promise<IFluidHandleInternal<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\tif (signal?.aborted) {\n\t\t\tthrow this.createAbortError();\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 = this.localBlobIdGenerator();\n\t\tconst pendingEntry: PendingBlob = {\n\t\t\tblob,\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\tabortSignal: signal,\n\t\t\topsent: false,\n\t\t};\n\t\tthis.pendingBlobs.set(localId, pendingEntry);\n\n\t\tconst abortListener = () => {\n\t\t\tif (!pendingEntry.acked) {\n\t\t\t\tpendingEntry.handleP.reject(this.createAbortError(pendingEntry));\n\t\t\t}\n\t\t};\n\t\tsignal?.addEventListener(\"abort\", abortListener, { once: true });\n\n\t\treturn pendingEntry.handleP.promise.finally(() => {\n\t\t\tsignal?.removeEventListener(\"abort\", abortListener);\n\t\t});\n\t}\n\n\tprivate async uploadBlob(\n\t\tlocalId: string,\n\t\tblob: ArrayBufferLike,\n\t): Promise<ICreateBlobResponse | void> {\n\t\treturn runWithRetry(\n\t\t\tasync () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await this.getStorage().createBlob(blob);\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst entry = this.pendingBlobs.get(localId);\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!!entry,\n\t\t\t\t\t\t0x387 /* Must have pending blob entry for blob which failed to upload */,\n\t\t\t\t\t);\n\t\t\t\t\tif (entry.opsent && !canRetryOnError(error)) {\n\t\t\t\t\t\tthrow wrapError(\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t\t() => new LoggingError(`uploadBlob error`, { canRetry: true }),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t},\n\t\t\t\"createBlob\",\n\t\t\tthis.mc.logger,\n\t\t\t{\n\t\t\t\tcancel: this.pendingBlobs.get(localId)?.abortSignal,\n\t\t\t},\n\t\t).then(\n\t\t\t(response) => this.onUploadResolve(localId, response),\n\t\t\t(error) => {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"UploadBlobReject\",\n\t\t\t\t\terror,\n\t\t\t\t\tlocalId,\n\t\t\t\t});\n\t\t\t\t// it will only reject if we haven't sent an op\n\t\t\t\t// and is a non-retriable error. It will only reject\n\t\t\t\t// the promise but not throw any error outside.\n\t\t\t\tthis.pendingBlobs.get(localId)?.handleP.reject(error);\n\t\t\t\tthis.deletePendingBlob(localId);\n\t\t\t},\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.deletePendingBlob(id);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate deletePendingBlob(id: string) {\n\t\tif (this.pendingBlobs.delete(id) && !this.hasPendingBlobs) {\n\t\t\tthis.emit(\"noPendingBlobs\");\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\tif ((entry.abortSignal?.aborted === true && !entry.opsent) || this.stopAttaching) {\n\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\teventName: \"BlobAborted\",\n\t\t\t\tlocalId,\n\t\t\t});\n\t\t\tthis.deletePendingBlob(localId);\n\t\t\treturn;\n\t\t}\n\t\tassert(\n\t\t\tentry.storageId === undefined,\n\t\t\t0x386 /* Must have pending blob entry for uploaded blob */,\n\t\t);\n\t\tentry.stashedUpload = undefined;\n\t\tentry.storageId = response.id;\n\t\tentry.uploadTime = Date.now();\n\t\tentry.minTTLInSeconds = response.minTTLInSeconds;\n\t\t// Send a blob attach op. This serves two purposes:\n\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// until its storage ID is added to the next summary.\n\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// blob from the server via the storage ID.\n\t\tif (!entry.opsent) {\n\t\t\tthis.sendBlobAttachOp(localId, response.id);\n\t\t}\n\t\tconst storageIds = getStorageIds(this.redirectTable, this.runtime.attachState);\n\t\tif (storageIds.has(response.id)) {\n\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// 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// happened before and so, the server won't delete it.\n\t\t\tthis.setRedirection(localId, response.id);\n\t\t\tentry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t} else {\n\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// this storage ID is ack'd, all pending blobs for it can be resolved since the op will keep the\n\t\t\t// blob alive in storage.\n\t\t\tthis.opsInFlight.set(\n\t\t\t\tresponse.id,\n\t\t\t\t(this.opsInFlight.get(response.id) ?? []).concat(localId),\n\t\t\t);\n\t\t}\n\t\treturn response;\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?.opsent === true && !!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 processBlobAttachMessage(message: ISequencedMessageEnvelope, local: boolean) {\n\t\tconst localId = (message.metadata as IBlobMetadata | undefined)?.localId;\n\t\tconst blobId = (message.metadata as IBlobMetadata | undefined)?.blobId;\n\n\t\tif (localId) {\n\t\t\tconst pendingEntry = this.pendingBlobs.get(localId);\n\t\t\tif (pendingEntry?.abortSignal?.aborted) {\n\t\t\t\tthis.deletePendingBlob(localId);\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\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\t\t\t\t\tthis.setRedirection(pendingLocalId, blobId);\n\t\t\t\t\tentry.acked = true;\n\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(pendingLocalId));\n\t\t\t\t\tthis.deletePendingBlobMaybe(pendingLocalId);\n\t\t\t\t});\n\t\t\t\tthis.opsInFlight.delete(blobId);\n\t\t\t}\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\tlocalEntry.handleP.resolve(this.getBlobHandle(localId));\n\t\t\t\tthis.deletePendingBlobMaybe(localId);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic summarize(telemetryContext?: ITelemetryContext): ISummaryTreeWithStats {\n\t\treturn summarizeBlobManagerState(this.redirectTable, this.runtime.attachState);\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 * 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: readonly string[]): readonly string[] {\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 -`/<blobManagerBasePath>/<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: readonly 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\t// If the blob hasn't already been deleted, log an error because this should never happen.\n\t\t\t// If the blob has already been deleted, log a telemetry event. This can happen because multiple GC\n\t\t\t// sweep ops can contain the same data store. It would be interesting to track how often this happens.\n\t\t\tconst alreadyDeleted = this.isBlobDeleted(route);\n\t\t\tif (!this.redirectTable.has(blobId)) {\n\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\teventName: \"DeletedAttachmentBlobNotFound\",\n\t\t\t\t\tcategory: alreadyDeleted ? \"generic\" : \"error\",\n\t\t\t\t\tblobId,\n\t\t\t\t\tdetails: { alreadyDeleted },\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 * Verifies that the blob with given id is not deleted, 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 verifyBlobNotDeleted(blobId: string) {\n\t\tif (!this.isBlobDeleted(getGCNodePathFromBlobId(blobId))) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst request = { url: blobId };\n\t\tconst error = responseToException(\n\t\t\tcreateResponseError(404, `Blob was deleted`, request),\n\t\t\trequest,\n\t\t);\n\t\t// Only log deleted events. Tombstone events are logged by garbage collector.\n\t\tthis.mc.logger.sendErrorEvent(\n\t\t\t{\n\t\t\t\teventName: \"GC_Deleted_Blob_Requested\",\n\t\t\t\tpkg: blobManagerBasePath,\n\t\t\t},\n\t\t\terror,\n\t\t);\n\t\tthrow error;\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(this.redirectTable.has(localId), 0x254 /* \"unrecognized id in redirect table\" */);\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\t/**\n\t * Part of container serialization when imminent closure is enabled (Currently when calling closeAndGetPendingLocalState).\n\t * This asynchronous function resolves all pending createBlob calls and waits for each blob\n\t * to be attached. It will also send BlobAttach ops for each pending blob that hasn't sent it\n\t * yet so that serialized container can resubmit them when rehydrated.\n\t *\n\t * @param stopBlobAttachingSignal - Optional signal to abort the blob attaching process.\n\t * @returns - A promise that resolves with the details of the attached blobs,\n\t * or undefined if no blobs were processed.\n\t */\n\tpublic async attachAndGetPendingBlobs(\n\t\tstopBlobAttachingSignal?: AbortSignal,\n\t): Promise<IPendingBlobs | undefined> {\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.mc.logger,\n\t\t\t{ eventName: \"GetPendingBlobs\" },\n\t\t\tasync () => {\n\t\t\t\tif (this.pendingBlobs.size === 0) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst blobs = {};\n\t\t\t\tconst localBlobs = new Set<PendingBlob>();\n\t\t\t\t// This while is used to stash blobs created while attaching and getting blobs\n\t\t\t\twhile (localBlobs.size < this.pendingBlobs.size) {\n\t\t\t\t\tconst attachBlobsP: Promise<void>[] = [];\n\t\t\t\t\tfor (const [id, entry] of this.pendingBlobs) {\n\t\t\t\t\t\tif (!localBlobs.has(entry)) {\n\t\t\t\t\t\t\tlocalBlobs.add(entry);\n\t\t\t\t\t\t\t// In order to follow natural blob creation flow we need to:\n\t\t\t\t\t\t\t// 1 send the blob attach op\n\t\t\t\t\t\t\t// 2 resolve the blob handle\n\t\t\t\t\t\t\t// 3 wait for op referencing the blob\n\t\t\t\t\t\t\tif (!entry.opsent) {\n\t\t\t\t\t\t\t\tthis.sendBlobAttachOp(id, entry.storageId);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Resolving the blob handle to let hosts continue with their operations (it will resolve\n\t\t\t\t\t\t\t// original createBlob call) and let them attach the blob. This is a lie we told since the upload\n\t\t\t\t\t\t\t// hasn't finished yet, but it's fine since we will retry on rehydration.\n\t\t\t\t\t\t\tentry.handleP.resolve(this.getBlobHandle(id));\n\t\t\t\t\t\t\t// Array of promises that will resolve when blobs get attached.\n\t\t\t\t\t\t\tattachBlobsP.push(\n\t\t\t\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\t\t\t\tstopBlobAttachingSignal?.addEventListener(\n\t\t\t\t\t\t\t\t\t\t\"abort\",\n\t\t\t\t\t\t\t\t\t\t() => {\n\t\t\t\t\t\t\t\t\t\t\tthis.stopAttaching = true;\n\t\t\t\t\t\t\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t{ once: true },\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tconst onBlobAttached = (attachedEntry) => {\n\t\t\t\t\t\t\t\t\t\tif (attachedEntry === entry) {\n\t\t\t\t\t\t\t\t\t\t\tthis.off(\"blobAttached\", onBlobAttached);\n\t\t\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\tif (!entry.attached) {\n\t\t\t\t\t\t\t\t\t\tthis.on(\"blobAttached\", onBlobAttached);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}),\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\t// Wait for all blobs to be attached. This is important, otherwise serialized container\n\t\t\t\t\t// could send the blobAttach op without any op that references the blob, making it useless.\n\t\t\t\t\tawait Promise.allSettled(attachBlobsP).catch(() => {\n\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tfor (const [id, entry] of this.pendingBlobs) {\n\t\t\t\t\tif (stopBlobAttachingSignal?.aborted && !entry.attached) {\n\t\t\t\t\t\tthis.mc.logger.sendTelemetryEvent({\n\t\t\t\t\t\t\teventName: \"UnableToStashBlob\",\n\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tassert(entry.attached === true, 0x790 /* stashed blob should be attached */);\n\t\t\t\t\tblobs[id] = {\n\t\t\t\t\t\tblob: bufferToString(entry.blob, \"base64\"),\n\t\t\t\t\t\tstorageId: entry.storageId,\n\t\t\t\t\t\tacked: entry.acked,\n\t\t\t\t\t\tminTTLInSeconds: entry.minTTLInSeconds,\n\t\t\t\t\t\tuploadTime: entry.uploadTime,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\treturn Object.keys(blobs).length > 0 ? blobs : undefined;\n\t\t\t},\n\t\t);\n\t}\n}\n\n/**\n * For a blobId, returns its path in GC's graph. The node path is of the format `/<blobManagerBasePath>/<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 */\nconst getGCNodePathFromBlobId = (blobId: string) => `/${blobManagerBasePath}/${blobId}`;\n\n/**\n * For a given GC node path, return the blobId. The node path is of the format `/<basePath>/<blobId>`.\n */\nconst getBlobIdFromGCNodePath = (nodePath: string) => {\n\tconst pathParts = nodePath.split(\"/\");\n\tassert(areBlobPathParts(pathParts), 0x5bd /* Invalid blob node path */);\n\treturn pathParts[2];\n};\n\n/**\n * Returns whether a given path is for attachment blobs that are in the format - \"/blobManagerBasePath/...\".\n */\nexport const isBlobPath = (path: string): path is `/${typeof blobManagerBasePath}/${string}` =>\n\tareBlobPathParts(path.split(\"/\"));\n\nexport const areBlobPathParts = (\n\tpathParts: string[],\n): pathParts is [\"\", typeof blobManagerBasePath, string] =>\n\tpathParts.length === 3 && pathParts[1] === blobManagerBasePath;\n"]}
@@ -2,10 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { IDeltaManager } from "@fluidframework/container-definitions/internal";
5
+ import { IDeltaManagerFull } from "@fluidframework/container-definitions/internal";
6
6
  import { IContainerRuntimeEvents } from "@fluidframework/container-runtime-definitions/internal";
7
7
  import { IEventProvider } from "@fluidframework/core-interfaces";
8
- import { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal";
9
8
  import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
10
9
  /**
11
10
  * We report various latency-related errors when waiting for op roundtrip takes longer than that amout of time.
@@ -62,5 +61,5 @@ export interface IPerfSignalReport {
62
61
  * @param containerRuntimeEvents - Emitter of events for the container runtime.
63
62
  * @param logger - Telemetry logger to write events to.
64
63
  */
65
- export declare function ReportOpPerfTelemetry(clientId: string | undefined, deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, containerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>, logger: ITelemetryLoggerExt): void;
64
+ export declare function ReportOpPerfTelemetry(clientId: string | undefined, deltaManager: IDeltaManagerFull, containerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>, logger: ITelemetryLoggerExt): void;
66
65
  //# sourceMappingURL=connectionTelemetry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connectionTelemetry.d.ts","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,wDAAwD,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EACN,gBAAgB,EAEhB,yBAAyB,EACzB,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAEN,mBAAmB,EAK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oBACR,iFAAiF;oBACjF,yDAAyD;oBACzD,gBAAgB,EAAE,eAAe,CAAC,yBAAyB;oBAC3D,kGAAkG;oBAClG,eAAe,EAAE,IAAI,CAAC,2BAA2B;oBACjD,oFAAoF;oBACpF,iBAAiB,EAAE,IAAI,CAAC,qBAAqB;iBAC7C;aACD,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;;AA5VuB,sCAAsB,GAAG,GAAG,AAAN,CAAO;AAG7B,yCAAyB,GAAG,GAAG,AAAN,CAAO;AAGhC,yCAAyB,GAAG,GAAG,AAAN,CAAO;AA4YzD;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACpC,QAA4B,EAC5B,YAAwE,EACxE,sBAA+D,EAC/D,MAA2B;IAE3B,IAAI,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC;AAPD,sDAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { IContainerRuntimeEvents } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { IEventProvider } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentMessage,\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIEventSampler,\n\tITelemetryLoggerExt,\n\tISampledTelemetryLogger,\n\tcreateChildLogger,\n\tcreateSampledLogger,\n\tformatTick,\n} from \"@fluidframework/telemetry-utils/internal\";\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 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\t// Performance Data to be reported for ops round trips and processing.\n\tprivate readonly latencyStatistics = new Map<\n\t\tnumber,\n\t\t{\n\t\t\topProcessingTimes: Partial<IOpPerfTimings>;\n\t\t\topPerfData: Partial<IOpPerfTelemetryProperties>;\n\t\t}\n\t>();\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\t/** Count of no-ops sent by this client. This variable is reset everytime the OpStats sampled event is logged */\n\tprivate noOpCountForTelemetry = 0;\n\t/** Cumulative size of the ops processed by this client. This variable is reset everytime the OpStats sampled event is logged */\n\tprivate processedOpSizeForTelemetry = 0;\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate static readonly OP_LATENCY_SAMPLE_RATE = 500;\n\tprivate readonly opLatencyLogger: ISampledTelemetryLogger;\n\n\tprivate static readonly DELTA_LATENCY_SAMPLE_RATE = 100;\n\tprivate readonly deltaLatencyLogger: ISampledTelemetryLogger;\n\n\tprivate static readonly PROCESSED_OPS_SAMPLE_RATE = 500;\n\n\t/**\n\t * A sampled logger to log Ops that have been processed by the current client, the NoOp sent and the\n\t * size of the ops processed within one sampling window of this log event.\n\t * The data from this logger will be used to monitor the efficiency of NoOp-heuristics or to get approximate collab window size.\n\t * Note: no log events are sent when sampling is disabled, because logging at every op will be too noisy.\n\t */\n\tprivate readonly opsLogger: ISampledTelemetryLogger;\n\n\t/**\n\t * Create an instance of OpPerfTelemetry which starts monitoring and generating telemetry related to op performance.\n\t *\n\t * @param clientId - The clientId of the current container.\n\t * @param deltaManager - DeltaManager instance to monitor.\n\t * @param containerRuntimeEvents - Emitter of events for the container runtime.\n\t * @param logger - Telemetry logger to write events to.\n\t */\n\tpublic constructor(\n\t\t/**\n\t\t * The clientId of the current container.\n\t\t *\n\t\t * @remarks Until the container connects to the server and receives an ack for its own join op, this can be undefined.\n\t\t * It gets updated in response to event changes once the value provided by the server is available.\n\t\t * If the container loses its connection, this could be the last known clientId.\n\t\t */\n\t\tprivate clientId: string | undefined,\n\t\t/**\n\t\t * DeltaManager instance to monitor.\n\t\t */\n\t\tprivate readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\t/**\n\t\t * Emitter of events for the container runtime.\n\t\t */\n\t\tcontainerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>,\n\t\t/**\n\t\t * Telemetry logger to write events to.\n\t\t */\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpPerf\" });\n\n\t\tconst deltaLatencyEventSampler: IEventSampler = (() => {\n\t\t\tlet eventCount = -1;\n\t\t\treturn {\n\t\t\t\tsample: () => {\n\t\t\t\t\teventCount++;\n\t\t\t\t\tconst shouldSample = eventCount % OpPerfTelemetry.DELTA_LATENCY_SAMPLE_RATE === 0;\n\t\t\t\t\tif (shouldSample) {\n\t\t\t\t\t\teventCount = 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn shouldSample;\n\t\t\t\t},\n\t\t\t};\n\t\t})();\n\n\t\tthis.deltaLatencyLogger = createSampledLogger(logger, deltaLatencyEventSampler);\n\n\t\t// The SampledLogger here is used get access to the isSamplingDisabled property derived from\n\t\t// telemetry config properties. The actual sampling logic for op messages happens outside this SampledLogger\n\t\t// due to complexity of the different asynchronus scenarios of the op message lifecycle.\n\t\tthis.opLatencyLogger = createSampledLogger(logger);\n\n\t\tconst opsEventSampler: IEventSampler = (() => {\n\t\t\tlet eventCount = 0;\n\t\t\treturn {\n\t\t\t\tsample: () => {\n\t\t\t\t\teventCount++;\n\t\t\t\t\tconst shouldSample = eventCount % OpPerfTelemetry.PROCESSED_OPS_SAMPLE_RATE === 0;\n\t\t\t\t\tif (shouldSample) {\n\t\t\t\t\t\teventCount = 0;\n\t\t\t\t\t\tthis.noOpCountForTelemetry = 0;\n\t\t\t\t\t\tthis.processedOpSizeForTelemetry = 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn shouldSample;\n\t\t\t\t},\n\t\t\t};\n\t\t})();\n\t\tthis.opsLogger = createSampledLogger(\n\t\t\tlogger,\n\t\t\topsEventSampler,\n\t\t\ttrue /* skipLoggingWhenSamplingIsDisabled */,\n\t\t);\n\n\t\tthis.deltaManager.on(\"pong\", (latency) => this.recordPingTime(latency));\n\t\tthis.deltaManager.on(\"submitOp\", (message) => this.beforeOpSubmit(message));\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterProcessingOp(message));\n\t\tthis.deltaManager.on(\"connect\", (details, opsBehind) => {\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.connectionOpSeqNumber = undefined;\n\t\t\tthis.firstConnection = false;\n\t\t\tthis.latencyStatistics.clear();\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\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === msg.clientSequenceNumber)\n\t\t\t\t) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst latencyStats = this.latencyStatistics.get(msg.clientSequenceNumber)!;\n\t\t\t\t\tassert(latencyStats !== undefined, 0x7c2 /* Latency stats for op should exist */);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tlatencyStats.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\tlatencyStats.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\tlatencyStats.opProcessingTimes.outboundPushEventTime = Date.now();\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tlatencyStats.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\tlatencyStats.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\tlatencyStats.opPerfData.durationOutboundBatching =\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.outboundPushEventTime -\n\t\t\t\t\t\tlatencyStats.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\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber)\n\t\t\t) {\n\t\t\t\t// We do an explicit check for undefined right after this\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst latencyStats = this.latencyStatistics.get(message.clientSequenceNumber)!;\n\t\t\t\tassert(latencyStats !== undefined, 0x7c3 /* Latency stats for op should exist */);\n\t\t\t\tif (latencyStats.opProcessingTimes.outboundPushEventTime !== undefined) {\n\t\t\t\t\tlatencyStats.opProcessingTimes.inboundPushEventTime = Date.now();\n\t\t\t\t\tlatencyStats.opPerfData.durationNetwork =\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.inboundPushEventTime -\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.outboundPushEventTime;\n\t\t\t\t\tlatencyStats.opPerfData.lengthInboundQueue = this.deltaManager.inbound.length;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (isRuntimeMessage(message) && typeof message.contents === \"string\") {\n\t\t\t\tthis.processedOpSizeForTelemetry += message.contents.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\n\t\tcontainerRuntimeEvents.on(\"connected\", (newClientId) => {\n\t\t\tthis.clientId = newClientId;\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? 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 DELTA_LATENCY_SAMPLE_RATE pongs, including the first time, if it is a \"write\" client.\n\t\tif (this.deltaManager.active) {\n\t\t\tthis.deltaLatencyLogger.sendPerformanceEvent({\n\t\t\t\teventName: \"DeltaLatency\",\n\t\t\t\tduration: latency,\n\t\t\t});\n\t\t}\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.opLatencyLogger.isSamplingDisabled ||\n\t\t\t(this.clientSequenceNumberForLatencyStatistics === undefined &&\n\t\t\t\tmessage.clientSequenceNumber % OpPerfTelemetry.OP_LATENCY_SAMPLE_RATE === 1)\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.latencyStatistics.get(message.clientSequenceNumber) === undefined,\n\t\t\t\t0x7c4 /* Existing op perf data for client sequence number */,\n\t\t\t);\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = message.clientSequenceNumber;\n\t\t\tthis.latencyStatistics.set(message.clientSequenceNumber, {\n\t\t\t\topProcessingTimes: {\n\t\t\t\t\tsubmitOpEventTime: Date.now(),\n\t\t\t\t},\n\t\t\t\topPerfData: {},\n\t\t\t});\n\t\t}\n\n\t\tif (message.type === MessageType.NoOp) {\n\t\t\t// Count the number of no-ops submitted by this client.\n\t\t\t// The value is reset when we log the OpStats sampled event.\n\t\t\tthis.noOpCountForTelemetry++;\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\tmessage.type === MessageType.Operation &&\n\t\t\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber)\n\t\t) {\n\t\t\t// We do an explicit check for undefined right after this\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst latencyData = this.latencyStatistics.get(message.clientSequenceNumber)!;\n\t\t\tassert(latencyData !== undefined, 0x7c5 /* Undefined latency statistics for op */);\n\t\t\tassert(\n\t\t\t\tlatencyData.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t0x120 /* \"Undefined latency statistics for op (op send time)\" */,\n\t\t\t);\n\t\t\tconst currentTime = Date.now();\n\t\t\tif (latencyData.opProcessingTimes.inboundPushEventTime !== undefined) {\n\t\t\t\tlatencyData.opPerfData.durationInboundToProcessing =\n\t\t\t\t\tcurrentTime - latencyData.opProcessingTimes.inboundPushEventTime;\n\t\t\t}\n\t\t\tconst duration = currentTime - latencyData.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\t\t\tthis.opLatencyLogger.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...latencyData.opPerfData,\n\t\t\t});\n\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.latencyStatistics.delete(message.clientSequenceNumber);\n\t\t}\n\n\t\tif (isRuntimeMessage(message)) {\n\t\t\t// Sampled logging of Ops that have been processed by the current client, the NoOp sent and the\n\t\t\t// size of the ops processed within one sampling window of this log event.\n\t\t\t// This data will be used to monitor the efficiency of NoOp-heuristics or to get approximate collab window size.\n\t\t\tthis.opsLogger.sendPerformanceEvent({\n\t\t\t\teventName: \"OpStats\",\n\t\t\t\t// Logging as 'details' property to avoid adding new column name to the log tables */\n\t\t\t\tdetails: {\n\t\t\t\t\t// Count of the ops processed by the current client. Note: these counts are after\n\t\t\t\t\t// compression/grouping/chunking (if enabled) of the ops.\n\t\t\t\t\tprocessedOpCount: OpPerfTelemetry.PROCESSED_OPS_SAMPLE_RATE,\n\t\t\t\t\t// Cumulative size of all the ops processed by the current client since the last OpStats event log\n\t\t\t\t\tprocessedOpSize: this.processedOpSizeForTelemetry,\n\t\t\t\t\t// Count of all the NoOp sent by the current client since the last OpStats event log\n\t\t\t\t\tsubmitedNoOpCount: this.noOpCountForTelemetry,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n}\nexport interface IPerfSignalReport {\n\t/**\n\t * Identifier to track broadcast signals being submitted in order to\n\t * allow collection of data around the roundtrip of signal messages.\n\t */\n\tbroadcastSignalSequenceNumber: number;\n\n\t/**\n\t * Accumulates the total number of broadcast signals sent during the current signal latency measurement window.\n\t * This value represents the total number of signals sent since the latency measurement began and is used\n\t * logged in telemetry when the latency measurement completes.\n\t */\n\ttotalSignalsSentInLatencyWindow: number;\n\n\t/**\n\t * Counts the number of broadcast signals sent since the last latency measurement was initiated.\n\t * This counter increments with each broadcast signal sent. When a new latency measurement starts,\n\t * this counter is added to `totalSignalsSentInLatencyWindow` and then reset to zero.\n\t */\n\tsignalsSentSinceLastLatencyMeasurement: number;\n\n\t/**\n\t * Number of signals that were expected but not received.\n\t */\n\tsignalsLost: number;\n\n\t/**\n\t * Number of signals received out of order/non-sequentially.\n\t */\n\tsignalsOutOfOrder: number;\n\n\t/**\n\t * Timestamp before submitting the signal we will trace.\n\t */\n\tsignalTimestamp: number;\n\n\t/**\n\t * Signal we will trace for roundtrip latency.\n\t */\n\troundTripSignalSequenceNumber: number | undefined;\n\n\t/**\n\t * Next expected signal sequence number to be received.\n\t */\n\ttrackingSignalSequenceNumber: number | undefined;\n\n\t/**\n\t * Inclusive lower bound of signal monitoring window.\n\t */\n\tminimumTrackingSignalSequenceNumber: number | undefined;\n}\n\n/**\n * Starts monitoring and generation of telemetry related to op performance.\n *\n * @param clientId - The clientId of the current container.\n * @param deltaManager - DeltaManager instance to monitor.\n * @param containerRuntimeEvents - Emitter of events for the container runtime.\n * @param logger - Telemetry logger to write events to.\n */\nexport function ReportOpPerfTelemetry(\n\tclientId: string | undefined,\n\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\tcontainerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>,\n\tlogger: ITelemetryLoggerExt,\n): void {\n\tnew OpPerfTelemetry(clientId, deltaManager, containerRuntimeEvents, logger);\n}\n"]}
1
+ {"version":3,"file":"connectionTelemetry.js","sourceRoot":"","sources":["../src/connectionTelemetry.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA2D;AAI3D,kEAA6D;AAC7D,0EAIqD;AACrD,oEAAyE;AACzE,uEAOkD;AAElD;;GAEG;AACU,QAAA,gBAAgB,GAAG,IAAI,CAAC;AAgCrC,MAAM,eAAe;IA8CpB;;;;;;;OAOG;IACH;IACC;;;;;;OAMG;IACK,QAA4B;IACpC;;OAEG;IACc,YAA+B;IA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C;YAC1D,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,IAAA,2BAAgB,EAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,+FAA+F;YAC/F,0EAA0E;YAC1E,gHAAgH;YAChH,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC;gBACnC,SAAS,EAAE,SAAS;gBACpB,qFAAqF;gBACrF,OAAO,EAAE;oBACR,iFAAiF;oBACjF,yDAAyD;oBACzD,gBAAgB,EAAE,eAAe,CAAC,yBAAyB;oBAC3D,kGAAkG;oBAClG,eAAe,EAAE,IAAI,CAAC,2BAA2B;oBACjD,oFAAoF;oBACpF,iBAAiB,EAAE,IAAI,CAAC,qBAAqB;iBAC7C;aACD,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;;AA5VuB,sCAAsB,GAAG,GAAG,AAAN,CAAO;AAG7B,yCAAyB,GAAG,GAAG,AAAN,CAAO;AAGhC,yCAAyB,GAAG,GAAG,AAAN,CAAO;AA4YzD;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACpC,QAA4B,EAC5B,YAA+B,EAC/B,sBAA+D,EAC/D,MAA2B;IAE3B,IAAI,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,CAAC,CAAC;AAC7E,CAAC;AAPD,sDAOC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { performance } from \"@fluid-internal/client-utils\";\nimport { IDeltaManagerFull } from \"@fluidframework/container-definitions/internal\";\nimport { IContainerRuntimeEvents } from \"@fluidframework/container-runtime-definitions/internal\";\nimport { IEventProvider } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentMessage,\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { isRuntimeMessage } from \"@fluidframework/driver-utils/internal\";\nimport {\n\tIEventSampler,\n\tITelemetryLoggerExt,\n\tISampledTelemetryLogger,\n\tcreateChildLogger,\n\tcreateSampledLogger,\n\tformatTick,\n} from \"@fluidframework/telemetry-utils/internal\";\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 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\t// Performance Data to be reported for ops round trips and processing.\n\tprivate readonly latencyStatistics = new Map<\n\t\tnumber,\n\t\t{\n\t\t\topProcessingTimes: Partial<IOpPerfTimings>;\n\t\t\topPerfData: Partial<IOpPerfTelemetryProperties>;\n\t\t}\n\t>();\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\t/** Count of no-ops sent by this client. This variable is reset everytime the OpStats sampled event is logged */\n\tprivate noOpCountForTelemetry = 0;\n\t/** Cumulative size of the ops processed by this client. This variable is reset everytime the OpStats sampled event is logged */\n\tprivate processedOpSizeForTelemetry = 0;\n\n\tprivate readonly logger: ITelemetryLoggerExt;\n\n\tprivate static readonly OP_LATENCY_SAMPLE_RATE = 500;\n\tprivate readonly opLatencyLogger: ISampledTelemetryLogger;\n\n\tprivate static readonly DELTA_LATENCY_SAMPLE_RATE = 100;\n\tprivate readonly deltaLatencyLogger: ISampledTelemetryLogger;\n\n\tprivate static readonly PROCESSED_OPS_SAMPLE_RATE = 500;\n\n\t/**\n\t * A sampled logger to log Ops that have been processed by the current client, the NoOp sent and the\n\t * size of the ops processed within one sampling window of this log event.\n\t * The data from this logger will be used to monitor the efficiency of NoOp-heuristics or to get approximate collab window size.\n\t * Note: no log events are sent when sampling is disabled, because logging at every op will be too noisy.\n\t */\n\tprivate readonly opsLogger: ISampledTelemetryLogger;\n\n\t/**\n\t * Create an instance of OpPerfTelemetry which starts monitoring and generating telemetry related to op performance.\n\t *\n\t * @param clientId - The clientId of the current container.\n\t * @param deltaManager - DeltaManager instance to monitor.\n\t * @param containerRuntimeEvents - Emitter of events for the container runtime.\n\t * @param logger - Telemetry logger to write events to.\n\t */\n\tpublic constructor(\n\t\t/**\n\t\t * The clientId of the current container.\n\t\t *\n\t\t * @remarks Until the container connects to the server and receives an ack for its own join op, this can be undefined.\n\t\t * It gets updated in response to event changes once the value provided by the server is available.\n\t\t * If the container loses its connection, this could be the last known clientId.\n\t\t */\n\t\tprivate clientId: string | undefined,\n\t\t/**\n\t\t * DeltaManager instance to monitor.\n\t\t */\n\t\tprivate readonly deltaManager: IDeltaManagerFull,\n\t\t/**\n\t\t * Emitter of events for the container runtime.\n\t\t */\n\t\tcontainerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>,\n\t\t/**\n\t\t * Telemetry logger to write events to.\n\t\t */\n\t\tlogger: ITelemetryLoggerExt,\n\t) {\n\t\tthis.logger = createChildLogger({ logger, namespace: \"OpPerf\" });\n\n\t\tconst deltaLatencyEventSampler: IEventSampler = (() => {\n\t\t\tlet eventCount = -1;\n\t\t\treturn {\n\t\t\t\tsample: () => {\n\t\t\t\t\teventCount++;\n\t\t\t\t\tconst shouldSample = eventCount % OpPerfTelemetry.DELTA_LATENCY_SAMPLE_RATE === 0;\n\t\t\t\t\tif (shouldSample) {\n\t\t\t\t\t\teventCount = 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn shouldSample;\n\t\t\t\t},\n\t\t\t};\n\t\t})();\n\n\t\tthis.deltaLatencyLogger = createSampledLogger(logger, deltaLatencyEventSampler);\n\n\t\t// The SampledLogger here is used get access to the isSamplingDisabled property derived from\n\t\t// telemetry config properties. The actual sampling logic for op messages happens outside this SampledLogger\n\t\t// due to complexity of the different asynchronus scenarios of the op message lifecycle.\n\t\tthis.opLatencyLogger = createSampledLogger(logger);\n\n\t\tconst opsEventSampler: IEventSampler = (() => {\n\t\t\tlet eventCount = 0;\n\t\t\treturn {\n\t\t\t\tsample: () => {\n\t\t\t\t\teventCount++;\n\t\t\t\t\tconst shouldSample = eventCount % OpPerfTelemetry.PROCESSED_OPS_SAMPLE_RATE === 0;\n\t\t\t\t\tif (shouldSample) {\n\t\t\t\t\t\teventCount = 0;\n\t\t\t\t\t\tthis.noOpCountForTelemetry = 0;\n\t\t\t\t\t\tthis.processedOpSizeForTelemetry = 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn shouldSample;\n\t\t\t\t},\n\t\t\t};\n\t\t})();\n\t\tthis.opsLogger = createSampledLogger(\n\t\t\tlogger,\n\t\t\topsEventSampler,\n\t\t\ttrue /* skipLoggingWhenSamplingIsDisabled */,\n\t\t);\n\n\t\tthis.deltaManager.on(\"pong\", (latency) => this.recordPingTime(latency));\n\t\tthis.deltaManager.on(\"submitOp\", (message) => this.beforeOpSubmit(message));\n\t\tthis.deltaManager.on(\"op\", (message) => this.afterProcessingOp(message));\n\t\tthis.deltaManager.on(\"connect\", (details, opsBehind) => {\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.connectionOpSeqNumber = undefined;\n\t\t\tthis.firstConnection = false;\n\t\t\tthis.latencyStatistics.clear();\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\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === msg.clientSequenceNumber)\n\t\t\t\t) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tconst latencyStats = this.latencyStatistics.get(msg.clientSequenceNumber)!;\n\t\t\t\t\tassert(latencyStats !== undefined, 0x7c2 /* Latency stats for op should exist */);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tlatencyStats.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\tlatencyStats.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\tlatencyStats.opProcessingTimes.outboundPushEventTime = Date.now();\n\n\t\t\t\t\tassert(\n\t\t\t\t\t\tlatencyStats.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\tlatencyStats.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\tlatencyStats.opPerfData.durationOutboundBatching =\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.outboundPushEventTime -\n\t\t\t\t\t\tlatencyStats.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\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber)\n\t\t\t) {\n\t\t\t\t// We do an explicit check for undefined right after this\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\tconst latencyStats = this.latencyStatistics.get(message.clientSequenceNumber)!;\n\t\t\t\tassert(latencyStats !== undefined, 0x7c3 /* Latency stats for op should exist */);\n\t\t\t\tif (latencyStats.opProcessingTimes.outboundPushEventTime !== undefined) {\n\t\t\t\t\tlatencyStats.opProcessingTimes.inboundPushEventTime = Date.now();\n\t\t\t\t\tlatencyStats.opPerfData.durationNetwork =\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.inboundPushEventTime -\n\t\t\t\t\t\tlatencyStats.opProcessingTimes.outboundPushEventTime;\n\t\t\t\t\tlatencyStats.opPerfData.lengthInboundQueue = this.deltaManager.inbound.length;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (isRuntimeMessage(message) && typeof message.contents === \"string\") {\n\t\t\t\tthis.processedOpSizeForTelemetry += message.contents.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\n\t\tcontainerRuntimeEvents.on(\"connected\", (newClientId) => {\n\t\t\tthis.clientId = newClientId;\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? 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 DELTA_LATENCY_SAMPLE_RATE pongs, including the first time, if it is a \"write\" client.\n\t\tif (this.deltaManager.active) {\n\t\t\tthis.deltaLatencyLogger.sendPerformanceEvent({\n\t\t\t\teventName: \"DeltaLatency\",\n\t\t\t\tduration: latency,\n\t\t\t});\n\t\t}\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.opLatencyLogger.isSamplingDisabled ||\n\t\t\t(this.clientSequenceNumberForLatencyStatistics === undefined &&\n\t\t\t\tmessage.clientSequenceNumber % OpPerfTelemetry.OP_LATENCY_SAMPLE_RATE === 1)\n\t\t) {\n\t\t\tassert(\n\t\t\t\tthis.latencyStatistics.get(message.clientSequenceNumber) === undefined,\n\t\t\t\t0x7c4 /* Existing op perf data for client sequence number */,\n\t\t\t);\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = message.clientSequenceNumber;\n\t\t\tthis.latencyStatistics.set(message.clientSequenceNumber, {\n\t\t\t\topProcessingTimes: {\n\t\t\t\t\tsubmitOpEventTime: Date.now(),\n\t\t\t\t},\n\t\t\t\topPerfData: {},\n\t\t\t});\n\t\t}\n\n\t\tif (message.type === MessageType.NoOp) {\n\t\t\t// Count the number of no-ops submitted by this client.\n\t\t\t// The value is reset when we log the OpStats sampled event.\n\t\t\tthis.noOpCountForTelemetry++;\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\tmessage.type === MessageType.Operation &&\n\t\t\t(this.opLatencyLogger.isSamplingDisabled ||\n\t\t\t\tthis.clientSequenceNumberForLatencyStatistics === message.clientSequenceNumber)\n\t\t) {\n\t\t\t// We do an explicit check for undefined right after this\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst latencyData = this.latencyStatistics.get(message.clientSequenceNumber)!;\n\t\t\tassert(latencyData !== undefined, 0x7c5 /* Undefined latency statistics for op */);\n\t\t\tassert(\n\t\t\t\tlatencyData.opProcessingTimes.submitOpEventTime !== undefined,\n\t\t\t\t0x120 /* \"Undefined latency statistics for op (op send time)\" */,\n\t\t\t);\n\t\t\tconst currentTime = Date.now();\n\t\t\tif (latencyData.opProcessingTimes.inboundPushEventTime !== undefined) {\n\t\t\t\tlatencyData.opPerfData.durationInboundToProcessing =\n\t\t\t\t\tcurrentTime - latencyData.opProcessingTimes.inboundPushEventTime;\n\t\t\t}\n\t\t\tconst duration = currentTime - latencyData.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\t\t\tthis.opLatencyLogger.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...latencyData.opPerfData,\n\t\t\t});\n\n\t\t\tthis.clientSequenceNumberForLatencyStatistics = undefined;\n\t\t\tthis.latencyStatistics.delete(message.clientSequenceNumber);\n\t\t}\n\n\t\tif (isRuntimeMessage(message)) {\n\t\t\t// Sampled logging of Ops that have been processed by the current client, the NoOp sent and the\n\t\t\t// size of the ops processed within one sampling window of this log event.\n\t\t\t// This data will be used to monitor the efficiency of NoOp-heuristics or to get approximate collab window size.\n\t\t\tthis.opsLogger.sendPerformanceEvent({\n\t\t\t\teventName: \"OpStats\",\n\t\t\t\t// Logging as 'details' property to avoid adding new column name to the log tables */\n\t\t\t\tdetails: {\n\t\t\t\t\t// Count of the ops processed by the current client. Note: these counts are after\n\t\t\t\t\t// compression/grouping/chunking (if enabled) of the ops.\n\t\t\t\t\tprocessedOpCount: OpPerfTelemetry.PROCESSED_OPS_SAMPLE_RATE,\n\t\t\t\t\t// Cumulative size of all the ops processed by the current client since the last OpStats event log\n\t\t\t\t\tprocessedOpSize: this.processedOpSizeForTelemetry,\n\t\t\t\t\t// Count of all the NoOp sent by the current client since the last OpStats event log\n\t\t\t\t\tsubmitedNoOpCount: this.noOpCountForTelemetry,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\t}\n}\nexport interface IPerfSignalReport {\n\t/**\n\t * Identifier to track broadcast signals being submitted in order to\n\t * allow collection of data around the roundtrip of signal messages.\n\t */\n\tbroadcastSignalSequenceNumber: number;\n\n\t/**\n\t * Accumulates the total number of broadcast signals sent during the current signal latency measurement window.\n\t * This value represents the total number of signals sent since the latency measurement began and is used\n\t * logged in telemetry when the latency measurement completes.\n\t */\n\ttotalSignalsSentInLatencyWindow: number;\n\n\t/**\n\t * Counts the number of broadcast signals sent since the last latency measurement was initiated.\n\t * This counter increments with each broadcast signal sent. When a new latency measurement starts,\n\t * this counter is added to `totalSignalsSentInLatencyWindow` and then reset to zero.\n\t */\n\tsignalsSentSinceLastLatencyMeasurement: number;\n\n\t/**\n\t * Number of signals that were expected but not received.\n\t */\n\tsignalsLost: number;\n\n\t/**\n\t * Number of signals received out of order/non-sequentially.\n\t */\n\tsignalsOutOfOrder: number;\n\n\t/**\n\t * Timestamp before submitting the signal we will trace.\n\t */\n\tsignalTimestamp: number;\n\n\t/**\n\t * Signal we will trace for roundtrip latency.\n\t */\n\troundTripSignalSequenceNumber: number | undefined;\n\n\t/**\n\t * Next expected signal sequence number to be received.\n\t */\n\ttrackingSignalSequenceNumber: number | undefined;\n\n\t/**\n\t * Inclusive lower bound of signal monitoring window.\n\t */\n\tminimumTrackingSignalSequenceNumber: number | undefined;\n}\n\n/**\n * Starts monitoring and generation of telemetry related to op performance.\n *\n * @param clientId - The clientId of the current container.\n * @param deltaManager - DeltaManager instance to monitor.\n * @param containerRuntimeEvents - Emitter of events for the container runtime.\n * @param logger - Telemetry logger to write events to.\n */\nexport function ReportOpPerfTelemetry(\n\tclientId: string | undefined,\n\tdeltaManager: IDeltaManagerFull,\n\tcontainerRuntimeEvents: IEventProvider<IContainerRuntimeEvents>,\n\tlogger: ITelemetryLoggerExt,\n): void {\n\tnew OpPerfTelemetry(clientId, deltaManager, containerRuntimeEvents, logger);\n}\n"]}