@fluidframework/container-loader 1.2.0 → 2.0.0-internal.1.0.0.81589

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 (105) hide show
  1. package/dist/audience.d.ts +2 -2
  2. package/dist/audience.d.ts.map +1 -1
  3. package/dist/audience.js.map +1 -1
  4. package/dist/catchUpMonitor.d.ts +40 -0
  5. package/dist/catchUpMonitor.d.ts.map +1 -0
  6. package/dist/catchUpMonitor.js +74 -0
  7. package/dist/catchUpMonitor.js.map +1 -0
  8. package/dist/connectionManager.d.ts.map +1 -1
  9. package/dist/connectionManager.js +0 -1
  10. package/dist/connectionManager.js.map +1 -1
  11. package/dist/connectionState.d.ts +0 -5
  12. package/dist/connectionState.d.ts.map +1 -1
  13. package/dist/connectionState.js +0 -5
  14. package/dist/connectionState.js.map +1 -1
  15. package/dist/connectionStateHandler.d.ts +12 -4
  16. package/dist/connectionStateHandler.d.ts.map +1 -1
  17. package/dist/connectionStateHandler.js +47 -15
  18. package/dist/connectionStateHandler.js.map +1 -1
  19. package/dist/container.d.ts +8 -6
  20. package/dist/container.d.ts.map +1 -1
  21. package/dist/container.js +82 -46
  22. package/dist/container.js.map +1 -1
  23. package/dist/deltaManager.d.ts.map +1 -1
  24. package/dist/deltaManager.js +6 -6
  25. package/dist/deltaManager.js.map +1 -1
  26. package/dist/deltaManagerProxy.d.ts +4 -1
  27. package/dist/deltaManagerProxy.d.ts.map +1 -1
  28. package/dist/deltaQueue.d.ts +9 -2
  29. package/dist/deltaQueue.d.ts.map +1 -1
  30. package/dist/deltaQueue.js +31 -26
  31. package/dist/deltaQueue.js.map +1 -1
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/loader.d.ts +7 -0
  36. package/dist/loader.d.ts.map +1 -1
  37. package/dist/loader.js +4 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/packageVersion.d.ts +1 -1
  40. package/dist/packageVersion.d.ts.map +1 -1
  41. package/dist/packageVersion.js +1 -1
  42. package/dist/packageVersion.js.map +1 -1
  43. package/dist/protocol.d.ts +22 -0
  44. package/dist/protocol.d.ts.map +1 -0
  45. package/dist/protocol.js +52 -0
  46. package/dist/protocol.js.map +1 -0
  47. package/lib/audience.d.ts +2 -2
  48. package/lib/audience.d.ts.map +1 -1
  49. package/lib/audience.js.map +1 -1
  50. package/lib/catchUpMonitor.d.ts +40 -0
  51. package/lib/catchUpMonitor.d.ts.map +1 -0
  52. package/lib/catchUpMonitor.js +69 -0
  53. package/lib/catchUpMonitor.js.map +1 -0
  54. package/lib/connectionManager.d.ts.map +1 -1
  55. package/lib/connectionManager.js +0 -1
  56. package/lib/connectionManager.js.map +1 -1
  57. package/lib/connectionState.d.ts +0 -5
  58. package/lib/connectionState.d.ts.map +1 -1
  59. package/lib/connectionState.js +0 -5
  60. package/lib/connectionState.js.map +1 -1
  61. package/lib/connectionStateHandler.d.ts +12 -4
  62. package/lib/connectionStateHandler.d.ts.map +1 -1
  63. package/lib/connectionStateHandler.js +47 -15
  64. package/lib/connectionStateHandler.js.map +1 -1
  65. package/lib/container.d.ts +8 -6
  66. package/lib/container.d.ts.map +1 -1
  67. package/lib/container.js +82 -46
  68. package/lib/container.js.map +1 -1
  69. package/lib/deltaManager.d.ts.map +1 -1
  70. package/lib/deltaManager.js +6 -6
  71. package/lib/deltaManager.js.map +1 -1
  72. package/lib/deltaManagerProxy.d.ts +4 -1
  73. package/lib/deltaManagerProxy.d.ts.map +1 -1
  74. package/lib/deltaQueue.d.ts +9 -2
  75. package/lib/deltaQueue.d.ts.map +1 -1
  76. package/lib/deltaQueue.js +32 -27
  77. package/lib/deltaQueue.js.map +1 -1
  78. package/lib/index.d.ts +1 -0
  79. package/lib/index.d.ts.map +1 -1
  80. package/lib/index.js.map +1 -1
  81. package/lib/loader.d.ts +7 -0
  82. package/lib/loader.d.ts.map +1 -1
  83. package/lib/loader.js +4 -3
  84. package/lib/loader.js.map +1 -1
  85. package/lib/packageVersion.d.ts +1 -1
  86. package/lib/packageVersion.d.ts.map +1 -1
  87. package/lib/packageVersion.js +1 -1
  88. package/lib/packageVersion.js.map +1 -1
  89. package/lib/protocol.d.ts +22 -0
  90. package/lib/protocol.d.ts.map +1 -0
  91. package/lib/protocol.js +48 -0
  92. package/lib/protocol.js.map +1 -0
  93. package/package.json +23 -15
  94. package/src/audience.ts +2 -2
  95. package/src/catchUpMonitor.ts +99 -0
  96. package/src/connectionManager.ts +0 -1
  97. package/src/connectionState.ts +0 -6
  98. package/src/connectionStateHandler.ts +55 -15
  99. package/src/container.ts +115 -63
  100. package/src/deltaManager.ts +6 -4
  101. package/src/deltaQueue.ts +34 -28
  102. package/src/index.ts +4 -0
  103. package/src/loader.ts +13 -2
  104. package/src/packageVersion.ts +1 -1
  105. package/src/protocol.ts +96 -0
@@ -1 +1 @@
1
- {"version":3,"file":"deltaManager.d.ts","sourceRoot":"","sources":["../src/deltaManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EACH,gBAAgB,EAChB,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACH,qBAAqB,EACrB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAErB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAU,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAMzE,OAAO,EAEH,gBAAgB,EAEnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACH,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,WAAW,EACX,cAAc,EACjB,MAAM,sCAAsC,CAAC;AAY9C,OAAO,EACH,6BAA6B,EAC7B,kBAAkB,EACpB,MAAM,aAAa,CAAC;AAEtB,MAAM,WAAW,eAAe;IAC5B,IAA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@@ class DeltaManager extends common_utils_1.TypedEventEmitter {
256
256
  this._inboundSignal.resume();
257
257
  if (prefetchType !== "none") {
258
258
  const cacheOnly = prefetchType === "cached";
259
- await this.fetchMissingDeltasCore("DocumentOpen", cacheOnly, this.lastQueuedSequenceNumber);
259
+ await this.fetchMissingDeltasCore(`DocumentOpen_${prefetchType}`, cacheOnly);
260
260
  // Keep going with fetching ops from storage once we have all cached ops in.
261
261
  // But do not block load and make this request async / not blocking this api.
262
262
  // Ops processing will start once cached ops are in and and will stop when queue is empty
263
263
  // (which in most cases will happen when we are done processing cached ops)
264
264
  if (cacheOnly) {
265
265
  // fire and forget
266
- this.fetchMissingDeltas("DocumentOpen");
266
+ this.fetchMissingDeltas("PostDocumentOpen");
267
267
  }
268
268
  }
269
269
  // Ensure there is no need to call this.processPendingOps() at the end of boot sequence
@@ -290,7 +290,7 @@ class DeltaManager extends common_utils_1.TypedEventEmitter {
290
290
  }
291
291
  async getDeltas(from, // inclusive
292
292
  to, // exclusive
293
- callback, cacheOnly) {
293
+ fetchReason, callback, cacheOnly) {
294
294
  const docService = this.serviceProvider();
295
295
  if (docService === undefined) {
296
296
  throw new Error("Delta manager is not attached");
@@ -304,7 +304,7 @@ class DeltaManager extends common_utils_1.TypedEventEmitter {
304
304
  // It is possible that due to asynchrony (including await above), required ops were already
305
305
  // received through delta stream. Validate that before moving forward.
306
306
  if (this.lastQueuedSequenceNumber >= lastExpectedOp) {
307
- this.logger.sendPerformanceEvent(Object.assign({ reason: this.fetchReason, eventName: "ExtraStorageCall", early: true, from,
307
+ this.logger.sendPerformanceEvent(Object.assign({ reason: fetchReason, eventName: "ExtraStorageCall", early: true, from,
308
308
  to }, this.connectionManager.connectionVerboseProps));
309
309
  return;
310
310
  }
@@ -340,7 +340,7 @@ class DeltaManager extends common_utils_1.TypedEventEmitter {
340
340
  this.closeAbortController.signal.onabort = () => controller.abort();
341
341
  const stream = this.deltaStorage.fetchMessages(from, // inclusive
342
342
  to, // exclusive
343
- controller.signal, cacheOnly, this.fetchReason);
343
+ controller.signal, cacheOnly, fetchReason);
344
344
  // eslint-disable-next-line no-constant-condition
345
345
  while (true) {
346
346
  const result = await stream.read();
@@ -614,7 +614,7 @@ class DeltaManager extends common_utils_1.TypedEventEmitter {
614
614
  }
615
615
  const fetchReason = `${reason}_fetch`;
616
616
  this.fetchReason = fetchReason;
617
- await this.getDeltas(from, to, (messages) => {
617
+ await this.getDeltas(from, to, fetchReason, (messages) => {
618
618
  this.refreshDelayInfo(this.deltaStorageDelayId);
619
619
  this.enqueueMessages(messages, fetchReason);
620
620
  }, cacheOnly);
@@ -1 +1 @@
1
- {"version":3,"file":"deltaManager.js","sourceRoot":"","sources":["../src/deltaManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,wEAA8D;AAC9D,+BAAkC;AAgBlC,+DAAyE;AACzE,qEAIyC;AACzC,2EAI4C;AAC5C,+EAM8C;AAC9C,+DAGsC;AACtC,qEAKyC;AACzC,6CAA0C;AAqB1C;;;GAGG;AACH,MAAa,YACT,SAAQ,gCAA8C;IAgMtD,YACqB,eAAmD,EACnD,MAAwB,EACxB,OAAsB,EACvC,uBAAqF;QAErF,KAAK,EAAE,CAAC;QALS,oBAAe,GAAf,eAAe,CAAoC;QACnD,WAAM,GAAN,MAAM,CAAkB;QACxB,YAAO,GAAP,OAAO,CAAe;QAvLnC,YAAO,GAAgC,EAAE,CAAC;QAGlD,gFAAgF;QACxE,sBAAiB,GAAW,CAAC,CAAC;QAEtC,mCAAmC;QACnC,oHAAoH;QACpH,4EAA4E;QAC5E,mHAAmH;QACnH,+GAA+G;QAC/G,kDAAkD;QAClD,iEAAiE;QACzD,6BAAwB,GAAW,CAAC,CAAC;QACrC,0BAAqB,GAAW,CAAC,CAAC;QAClC,gCAA2B,GAAW,CAAC,CAAC;QAExC,aAAQ,GAAW,CAAC,CAAC;QAE7B;;UAEE;QACM,YAAO,GAAW,CAAC,CAAC;QAI5B,+CAA+C;QACvC,uBAAkB,G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. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ITelemetryLogger,\n IEventProvider,\n ITelemetryProperties,\n ITelemetryErrorEvent,\n} from \"@fluidframework/common-definitions\";\nimport {\n IDeltaHandlerStrategy,\n IDeltaManager,\n IDeltaManagerEvents,\n IDeltaQueue,\n ICriticalContainerError,\n IThrottlingWarning,\n IConnectionDetails,\n} from \"@fluidframework/container-definitions\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n normalizeError,\n logIfFalse,\n safeRaiseEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n IDocumentDeltaStorageService,\n IDocumentService,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport {\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalMessage,\n MessageType,\n ConnectionMode,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n NonRetryableError,\n isClientMessage,\n} from \"@fluidframework/driver-utils\";\nimport {\n ThrottlingWarning,\n DataCorruptionError,\n extractSafePropertiesFromMessage,\n DataProcessingError,\n} from \"@fluidframework/container-utils\";\nimport { DeltaQueue } from \"./deltaQueue\";\nimport {\n IConnectionManagerFactoryArgs,\n IConnectionManager,\n } from \"./contracts\";\n\nexport interface IConnectionArgs {\n mode?: ConnectionMode;\n fetchOpsFromStorage?: boolean;\n reason: string;\n}\n\n/**\n * Includes events emitted by the concrete implementation DeltaManager\n * but not exposed on the public interface IDeltaManager\n */\nexport interface IDeltaManagerInternalEvents extends IDeltaManagerEvents {\n (event: \"throttled\", listener: (error: IThrottlingWarning) => void);\n (event: \"closed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Manages the flow of both inbound and outbound messages. This class ensures that shared objects receive delta\n * messages in order regardless of possible network conditions or timings causing out of order delivery.\n */\nexport class DeltaManager<TConnectionManager extends IConnectionManager>\n extends TypedEventEmitter<IDeltaManagerInternalEvents>\n implements\n IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n IEventProvider<IDeltaManagerInternalEvents> {\n public readonly connectionManager: TConnectionManager;\n\n public get active(): boolean { return this._active(); }\n\n public get disposed() { return this.closed; }\n\n public get IDeltaSender() { return this; }\n\n private pending: ISequencedDocumentMessage[] = [];\n private fetchReason: string | undefined;\n\n // The minimum sequence number and last sequence number received from the server\n private minSequenceNumber: number = 0;\n\n // There are three numbers we track\n // * lastQueuedSequenceNumber is the last queued sequence number. If there are gaps in seq numbers, then this number\n // is not updated until we cover that gap, so it increases each time by 1.\n // * lastObservedSeqNumber is an estimation of last known sequence number for container in storage. It's initially\n // populated at web socket connection time (if storage provides that info) and is updated once ops shows up.\n // It's never less than lastQueuedSequenceNumber\n // * lastProcessedSequenceNumber - last processed sequence number\n private lastQueuedSequenceNumber: number = 0;\n private lastObservedSeqNumber: number = 0;\n private lastProcessedSequenceNumber: number = 0;\n private lastProcessedMessage: ISequencedDocumentMessage | undefined;\n private baseTerm: number = 0;\n\n /**\n * Track down the ops size.\n */\n private opsSize: number = 0;\n private prevEnqueueMessagesReason: string | undefined;\n private previouslyProcessedMessage: ISequencedDocumentMessage | undefined;\n\n // The sequence number we initially loaded from\n private initSequenceNumber: number = 0;\n\n private readonly _inbound: DeltaQueue<ISequencedDocumentMessage>;\n private readonly _inboundSignal: DeltaQueue<ISignalMessage>;\n\n private closed = false;\n\n private handler: IDeltaHandlerStrategy | undefined;\n private deltaStorage: IDocumentDeltaStorageService | undefined;\n\n private readonly throttlingIdSet = new Set<string>();\n private timeTillThrottling: number = 0;\n\n public readonly closeAbortController = new AbortController();\n\n private readonly deltaStorageDelayId = uuid();\n private readonly deltaStreamDelayId = uuid();\n\n private messageBuffer: IDocumentMessage[] = [];\n\n private _checkpointSequenceNumber: number | undefined;\n\n public get inbound(): IDeltaQueue<ISequencedDocumentMessage> {\n return this._inbound;\n }\n\n public get inboundSignal(): IDeltaQueue<ISignalMessage> {\n return this._inboundSignal;\n }\n\n public get initialSequenceNumber(): number {\n return this.initSequenceNumber;\n }\n\n public get lastSequenceNumber(): number {\n return this.lastProcessedSequenceNumber;\n }\n\n public get lastMessage() {\n return this.lastProcessedMessage;\n }\n\n public get lastKnownSeqNumber() {\n return this.lastObservedSeqNumber;\n }\n\n public get referenceTerm(): number {\n return this.baseTerm;\n }\n\n public get minimumSequenceNumber(): number {\n return this.minSequenceNumber;\n }\n\n /**\n * Tells if current connection has checkpoint information.\n * I.e. we know how far behind the client was at the time of establishing connection\n */\n public get hasCheckpointSequenceNumber() {\n // Valid to be called only if we have active connection.\n assert(this.connectionManager.connected, 0x0df /* \"Missing active connection\" */);\n return this._checkpointSequenceNumber !== undefined;\n }\n\n // Forwarding connection manager properties / IDeltaManager implementation\n public get maxMessageSize(): number { return this.connectionManager.maxMessageSize; }\n public get version() { return this.connectionManager.version; }\n public get serviceConfiguration() { return this.connectionManager.serviceConfiguration; }\n public get outbound() { return this.connectionManager.outbound; }\n public get readOnlyInfo() { return this.connectionManager.readOnlyInfo; }\n public get clientDetails() { return this.connectionManager.clientDetails; }\n\n public submit(type: MessageType, contents: any, batch = false, metadata?: any) {\n const messagePartial: Omit<IDocumentMessage, \"clientSequenceNumber\"> = {\n contents: JSON.stringify(contents),\n metadata,\n referenceSequenceNumber: this.lastProcessedSequenceNumber,\n type,\n };\n\n if (!batch) {\n this.flush();\n }\n\n const message = this.connectionManager.prepareMessageToSend(messagePartial);\n if (message === undefined) {\n return -1;\n }\n\n this.opsSize += message.contents.length;\n\n this.messageBuffer.push(message);\n\n this.emit(\"submitOp\", message);\n\n if (!batch) {\n this.flush();\n }\n\n return message.clientSequenceNumber;\n }\n\n public submitSignal(content: any) { return this.connectionManager.submitSignal(content); }\n\n public flush() {\n if (this.messageBuffer.length === 0) {\n return;\n }\n\n // The prepareFlush event allows listeners to append metadata to the batch prior to submission.\n this.emit(\"prepareSend\", this.messageBuffer);\n\n this.connectionManager.sendMessages(this.messageBuffer);\n this.messageBuffer = [];\n }\n\n public get connectionProps(): ITelemetryProperties {\n return {\n sequenceNumber: this.lastSequenceNumber,\n opsSize: this.opsSize > 0 ? this.opsSize : undefined,\n ...this.connectionManager.connectionProps,\n };\n }\n\n /**\n * Log error event with a bunch of internal to DeltaManager information about state of op processing\n * Used to diagnose connectivity issues related to op processing (i.e. cases where for some reason\n * we stop processing ops that results in no processing join op and thus moving to connected state)\n * @param event - Event to log.\n */\n public logConnectionIssue(event: ITelemetryErrorEvent) {\n assert(this.connectionManager.connected, 0x238 /* \"called only in connected state\" */);\n\n const pendingSorted = this.pending.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.logger.sendErrorEvent({\n ...event,\n // This directly tells us if fetching ops is in flight, and thus likely the reason of\n // stalled op processing\n fetchReason: this.fetchReason,\n // A bunch of useful sequence numbers to understand if we are holding some ops from processing\n lastQueuedSequenceNumber: this.lastQueuedSequenceNumber, // last sequential op\n lastProcessedSequenceNumber: this.lastProcessedSequenceNumber, // same as above, but after processing\n lastObserved: this.lastObservedSeqNumber, // last sequence we ever saw; may have gaps with above.\n // connection info\n ...this.connectionManager.connectionVerboseProps,\n pendingOps: this.pending.length, // Do we have any pending ops?\n pendingFirst: pendingSorted[0]?.sequenceNumber, // is the first pending op the one that we are missing?\n haveHandler: this.handler !== undefined, // do we have handler installed?\n inboundLength: this.inbound.length,\n inboundPaused: this.inbound.paused,\n });\n }\n\n constructor(\n private readonly serviceProvider: () => IDocumentService | undefined,\n private readonly logger: ITelemetryLogger,\n private readonly _active: () => boolean,\n createConnectionManager: (props: IConnectionManagerFactoryArgs) => TConnectionManager,\n ) {\n super();\n const props: IConnectionManagerFactoryArgs = {\n incomingOpHandler: (messages: ISequencedDocumentMessage[], reason: string) => {\n try {\n this.enqueueMessages(messages, reason);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"EnqueueMessages_Exception\" }, error);\n this.close(normalizeError(error));\n }\n },\n signalHandler: (message: ISignalMessage) => this._inboundSignal.push(message),\n reconnectionDelayHandler: (delayMs: number, error: unknown) =>\n this.emitDelayInfo(this.deltaStreamDelayId, delayMs, error),\n closeHandler: (error: any) => this.close(error),\n disconnectHandler: (reason: string) => this.disconnectHandler(reason),\n connectHandler: (connection: IConnectionDetails) => this.connectHandler(connection),\n pongHandler: (latency: number) => this.emit(\"pong\", latency),\n readonlyChangeHandler: (readonly?: boolean) => safeRaiseEvent(this, this.logger, \"readonly\", readonly),\n };\n\n this.connectionManager = createConnectionManager(props);\n\n this._inbound = new DeltaQueue<ISequencedDocumentMessage>(\n (op) => {\n this.processInboundMessage(op);\n });\n\n this._inbound.on(\"error\", (error) => {\n this.close(\n DataProcessingError.wrapIfUnrecognized(error, \"deltaManagerInboundErrorHandler\", this.lastMessage));\n });\n\n // Inbound signal queue\n this._inboundSignal = new DeltaQueue<ISignalMessage>((message) => {\n if (this.handler === undefined) {\n throw new Error(\"Attempted to process an inbound signal without a handler attached\");\n }\n this.handler.processSignal({\n clientId: message.clientId,\n content: JSON.parse(message.content as string),\n });\n });\n\n this._inboundSignal.on(\"error\", (error) => {\n this.close(normalizeError(error));\n });\n\n // Initially, all queues are created paused.\n // - outbound is flipped back and forth in setupNewSuccessfulConnection / disconnectFromDeltaStream\n // - inbound & inboundSignal are resumed in attachOpHandler() when we have handler setup\n }\n\n private connectHandler(connection: IConnectionDetails) {\n this.refreshDelayInfo(this.deltaStreamDelayId);\n\n const props = this.connectionManager.connectionVerboseProps;\n props.connectionLastQueuedSequenceNumber = this.lastQueuedSequenceNumber;\n props.connectionLastObservedSeqNumber = this.lastObservedSeqNumber;\n\n const checkpointSequenceNumber = connection.checkpointSequenceNumber;\n this._checkpointSequenceNumber = checkpointSequenceNumber;\n if (checkpointSequenceNumber !== undefined) {\n this.updateLatestKnownOpSeqNumber(checkpointSequenceNumber);\n }\n\n // We cancel all ops on lost of connectivity, and rely on DDSes to resubmit them.\n // Semantics are not well defined for batches (and they are broken right now on disconnects anyway),\n // but it's safe to assume (until better design is put into place) that batches should not exist\n // across multiple connections. Right now we assume runtime will not submit any ops in disconnected\n // state. As requirements change, so should these checks.\n assert(this.messageBuffer.length === 0, 0x0e9 /* \"messageBuffer is not empty on new connection\" */);\n\n this.opsSize = 0;\n\n this.emit(\n \"connect\",\n connection,\n checkpointSequenceNumber !== undefined ?\n this.lastObservedSeqNumber - this.lastSequenceNumber : undefined);\n\n // If we got some initial ops, then we know the gap and call above fetched ops to fill it.\n // Same is true for \"write\" mode even if we have no ops - we will get \"join\" own op very very soon.\n // However if we are connecting as view-only, then there is no good signal to realize if client is behind.\n // Thus we have to hit storage to see if any ops are there.\n if (checkpointSequenceNumber !== undefined) {\n // We know how far we are behind (roughly). If it's non-zero gap, fetch ops right away.\n if (checkpointSequenceNumber > this.lastQueuedSequenceNumber) {\n this.fetchMissingDeltas(\"AfterConnection\");\n }\n // we do not know the gap, and we will not learn about it if socket is quite - have to ask.\n } else if (connection.mode === \"read\") {\n this.fetchMissingDeltas(\"AfterReadConnection\");\n }\n }\n\n public dispose() {\n throw new Error(\"Not implemented.\");\n }\n\n /**\n * Sets the sequence number from which inbound messages should be returned\n */\n public async attachOpHandler(\n minSequenceNumber: number,\n sequenceNumber: number,\n term: number,\n handler: IDeltaHandlerStrategy,\n prefetchType: \"cached\" | \"all\" | \"none\" = \"none\",\n ) {\n this.initSequenceNumber = sequenceNumber;\n this.lastProcessedSequenceNumber = sequenceNumber;\n this.baseTerm = term;\n this.minSequenceNumber = minSequenceNumber;\n this.lastQueuedSequenceNumber = sequenceNumber;\n this.lastObservedSeqNumber = sequenceNumber;\n\n // We will use same check in other places to make sure all the seq number above are set properly.\n assert(this.handler === undefined, 0x0e2 /* \"DeltaManager already has attached op handler!\" */);\n this.handler = handler;\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n assert(!!(this.handler as any), 0x0e3 /* \"Newly set op handler is null/undefined!\" */);\n\n // There should be no pending fetch!\n // This API is called right after attachOpHandler by Container.load().\n // We might have connection already and it might have called fetchMissingDeltas() from\n // setupNewSuccessfulConnection. But it should do nothing, because there is no way to fetch ops before\n // we know snapshot sequence number that is set in attachOpHandler. So all such calls should be noop.\n assert(this.fetchReason === undefined, 0x268 /* \"There can't be pending fetch that early in boot sequence!\" */);\n\n if (this.closed) {\n return;\n }\n\n this._inbound.resume();\n this._inboundSignal.resume();\n\n if (prefetchType !== \"none\") {\n const cacheOnly = prefetchType === \"cached\";\n await this.fetchMissingDeltasCore(\"DocumentOpen\", cacheOnly, this.lastQueuedSequenceNumber);\n\n // Keep going with fetching ops from storage once we have all cached ops in.\n // But do not block load and make this request async / not blocking this api.\n // Ops processing will start once cached ops are in and and will stop when queue is empty\n // (which in most cases will happen when we are done processing cached ops)\n if (cacheOnly) {\n // fire and forget\n this.fetchMissingDeltas(\"DocumentOpen\");\n }\n }\n\n // Ensure there is no need to call this.processPendingOps() at the end of boot sequence\n assert(this.fetchReason !== undefined || this.pending.length === 0, 0x269 /* \"pending ops are not dropped\" */);\n }\n\n public connect(args: IConnectionArgs) {\n const fetchOpsFromStorage = args.fetchOpsFromStorage ?? true;\n logIfFalse(\n this.handler !== undefined || !fetchOpsFromStorage,\n this.logger,\n \"CantFetchWithoutBaseline\"); // can't fetch if no baseline\n\n // Note: There is race condition here.\n // We want to issue request to storage as soon as possible, to\n // reduce latency of becoming current, thus this code here.\n // But there is no ordering between fetching OPs and connection to delta stream\n // As result, we might be behind by the time we connect to delta stream\n // In case of r/w connection, that's not an issue, because we will hear our\n // own \"join\" message and realize any gap client has in ops.\n // But for view-only connection, we have no such signal, and with no traffic\n // on the wire, we might be always behind.\n // See comment at the end of \"connect\" handler\n if (fetchOpsFromStorage) {\n this.fetchMissingDeltas(args.reason);\n }\n\n this.connectionManager.connect(args.mode);\n }\n\n private async getDeltas(\n from: number, // inclusive\n to: number | undefined, // exclusive\n callback: (messages: ISequencedDocumentMessage[]) => void,\n cacheOnly: boolean) {\n const docService = this.serviceProvider();\n if (docService === undefined) {\n throw new Error(\"Delta manager is not attached\");\n }\n\n if (this.deltaStorage === undefined) {\n this.deltaStorage = await docService.connectToDeltaStorage();\n }\n\n let cancelFetch: (op: ISequencedDocumentMessage) => boolean;\n\n if (to !== undefined) {\n const lastExpectedOp = to - 1; // make it inclusive!\n\n // It is possible that due to asynchrony (including await above), required ops were already\n // received through delta stream. Validate that before moving forward.\n if (this.lastQueuedSequenceNumber >= lastExpectedOp) {\n this.logger.sendPerformanceEvent({\n reason: this.fetchReason,\n eventName: \"ExtraStorageCall\",\n early: true,\n from,\n to,\n ...this.connectionManager.connectionVerboseProps,\n });\n return;\n }\n\n // Be prepared for the case where webSocket would receive the ops that we are trying to fill through\n // storage. Ideally it should never happen (i.e. ops on socket are always ordered, and thus once we\n // detected gap, this gap can't be filled in later on through websocket).\n // And in practice that does look like the case. The place where this code gets hit is if we lost\n // connection and reconnected (likely to another box), and new socket's initial ops contains these ops.\n cancelFetch = (op: ISequencedDocumentMessage) => op.sequenceNumber >= lastExpectedOp;\n } else {\n // Unbound requests are made to proactively fetch ops, but also get up to date in cases where socket\n // is silent (and connection is \"read\", thus we might not have any data on how far client is behind).\n // Once we have any op coming in from socket, we can cancel it as it's not needed any more.\n // That said, if we have socket connection, make sure we got ops up to checkpointSequenceNumber!\n cancelFetch = (op: ISequencedDocumentMessage) => op.sequenceNumber >= this.lastObservedSeqNumber;\n }\n\n const controller = new AbortController();\n let opsFromFetch = false;\n\n const opListener = (op: ISequencedDocumentMessage) => {\n assert(op.sequenceNumber === this.lastQueuedSequenceNumber, 0x23a /* \"seq#'s\" */);\n // Ops that are coming from this request should not cancel itself.\n // This is useless for known ranges (to is defined) as it means request is over either way.\n // And it will cancel unbound request too early, not allowing us to learn where the end of the file is.\n if (!opsFromFetch && cancelFetch(op)) {\n controller.abort();\n this._inbound.off(\"push\", opListener);\n }\n };\n\n try {\n this._inbound.on(\"push\", opListener);\n assert(this.closeAbortController.signal.onabort === null, 0x1e8 /* \"reentrancy\" */);\n this.closeAbortController.signal.onabort = () => controller.abort();\n\n const stream = this.deltaStorage.fetchMessages(\n from, // inclusive\n to, // exclusive\n controller.signal,\n cacheOnly,\n this.fetchReason);\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await stream.read();\n if (result.done) {\n break;\n }\n try {\n opsFromFetch = true;\n callback(result.value);\n } finally {\n opsFromFetch = false;\n }\n }\n } finally {\n this.closeAbortController.signal.onabort = null;\n this._inbound.off(\"push\", opListener);\n assert(!opsFromFetch, 0x289 /* \"logic error\" */);\n }\n }\n\n /**\n * Closes the connection and clears inbound & outbound queues.\n */\n public close(error?: ICriticalContainerError): void {\n if (this.closed) {\n return;\n }\n this.closed = true;\n\n this.connectionManager.dispose(error);\n\n this.closeAbortController.abort();\n\n this._inbound.clear();\n this._inboundSignal.clear();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._inbound.pause();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._inboundSignal.pause();\n\n // Drop pending messages - this will ensure catchUp() does not go into infinite loop\n this.pending = [];\n\n // This needs to be the last thing we do (before removing listeners), as it causes\n // Container to dispose context and break ability of data stores / runtime to \"hear\"\n // from delta manager, including notification (above) about readonly state.\n this.emit(\"closed\", error);\n\n this.removeAllListeners();\n }\n\n public refreshDelayInfo(id: string) {\n this.throttlingIdSet.delete(id);\n if (this.throttlingIdSet.size === 0) {\n this.timeTillThrottling = 0;\n }\n }\n\n private disconnectHandler(reason: string) {\n this.messageBuffer.length = 0;\n this.emit(\"disconnect\", reason);\n }\n\n /**\n * Emit info about a delay in service communication on account of throttling.\n * @param id - Id of the connection that is delayed\n * @param delayMs - Duration of the delay\n * @param error - error object indicating the throttling\n */\n public emitDelayInfo(id: string, delayMs: number, error: unknown) {\n const timeNow = Date.now();\n this.throttlingIdSet.add(id);\n if (delayMs > 0 && (timeNow + delayMs > this.timeTillThrottling)) {\n this.timeTillThrottling = timeNow + delayMs;\n\n const throttlingWarning: IThrottlingWarning = ThrottlingWarning.wrap(\n error,\n delayMs / 1000 /* retryAfterSeconds */,\n this.logger,\n );\n this.emit(\"throttled\", throttlingWarning);\n }\n }\n\n // returns parts of message (in string format) that should never change for a given message.\n // Used for message comparison. It attempts to avoid comparing fields that potentially may differ.\n // for example, it's not clear if serverMetadata or timestamp property is a property of message or server state.\n // We only extract the most obvious fields that are sufficient (with high probability) to detect sequence number\n // reuse.\n // Also payload goes to telemetry, so no PII, including content!!\n // Note: It's possible for a duplicate op to be broadcasted and have everything the same except the timestamp.\n private comparableMessagePayload(m: ISequencedDocumentMessage) {\n return `${m.clientId}-${m.type}-${m.minimumSequenceNumber}-${m.referenceSequenceNumber}-${m.timestamp}`;\n }\n\n private enqueueMessages(\n messages: ISequencedDocumentMessage[],\n reason: string,\n allowGaps = false,\n ): void {\n if (this.handler === undefined) {\n // We did not setup handler yet.\n // This happens when we connect to web socket faster than we get attributes for container\n // and thus faster than attachOpHandler() is called\n // this.lastProcessedSequenceNumber is still zero, so we can't rely on this.fetchMissingDeltas()\n // to do the right thing.\n this.pending = this.pending.concat(messages);\n return;\n }\n\n // Pending ops should never just hang around for nothing.\n // This invariant will stay true through this function execution,\n // so there is no need to process pending ops here.\n // It's responsibility of\n // - attachOpHandler()\n // - fetchMissingDeltas() after it's done with querying storage\n assert(this.pending.length === 0 || this.fetchReason !== undefined, 0x1e9 /* \"Pending ops\" */);\n\n if (messages.length === 0) {\n return;\n }\n\n const from = messages[0].sequenceNumber;\n const last = messages[messages.length - 1].sequenceNumber;\n\n // Report stats about missing and duplicate ops\n // This helps better understand why we fetch ops from storage, and thus may delay\n // getting current / sending ops\n // It's possible that this batch is already too late - do not bother\n if (last > this.lastQueuedSequenceNumber) {\n let prev = from - 1;\n const initialGap = prev - this.lastQueuedSequenceNumber;\n let firstMissing: number | undefined;\n let duplicate = 0;\n let gap = 0;\n\n // Count all gaps and duplicates\n for (const message of messages) {\n if (message.sequenceNumber === prev) {\n duplicate++;\n } else if (message.sequenceNumber !== prev + 1) {\n gap++;\n if (firstMissing === undefined) {\n firstMissing = prev + 1;\n }\n }\n prev = message.sequenceNumber;\n }\n\n let eventName: string | undefined;\n\n // Report if we found some issues\n if (duplicate !== 0 || gap !== 0 && !allowGaps || initialGap > 0 && this.fetchReason === undefined) {\n eventName = \"enqueueMessages\";\n // Also report if we are fetching ops, and same range comes in, thus making this fetch obsolete.\n } else if (this.fetchReason !== undefined && this.fetchReason !== reason &&\n (from <= this.lastQueuedSequenceNumber + 1 && last > this.lastQueuedSequenceNumber)) {\n eventName = \"enqueueMessagesExtraFetch\";\n }\n\n // Report if there is something to report\n // Do not report when pending fetch is in progress, as such reporting will not\n // correctly take into account pending ops.\n if (eventName !== undefined) {\n this.logger.sendPerformanceEvent({\n eventName,\n reason,\n previousReason: this.prevEnqueueMessagesReason,\n from,\n to: last + 1, // exclusive, being consistent with the other telemetry / APIs\n length: messages.length,\n fetchReason: this.fetchReason,\n duplicate: duplicate > 0 ? duplicate : undefined,\n initialGap: initialGap !== 0 ? initialGap : undefined,\n gap: gap > 0 ? gap : undefined,\n firstMissing,\n dmInitialSeqNumber: this.initialSequenceNumber,\n ...this.connectionManager.connectionVerboseProps,\n });\n }\n }\n\n this.updateLatestKnownOpSeqNumber(messages[messages.length - 1].sequenceNumber);\n\n const n = this.previouslyProcessedMessage?.sequenceNumber;\n assert(n === undefined || n === this.lastQueuedSequenceNumber,\n 0x0ec /* \"Unexpected value for previously processed message's sequence number\" */);\n\n for (const message of messages) {\n // Check that the messages are arriving in the expected order\n if (message.sequenceNumber <= this.lastQueuedSequenceNumber) {\n // Validate that we do not have data loss, i.e. sequencing is reset and started again\n // with numbers that this client already observed before.\n if (this.previouslyProcessedMessage?.sequenceNumber === message.sequenceNumber) {\n const message1 = this.comparableMessagePayload(this.previouslyProcessedMessage);\n const message2 = this.comparableMessagePayload(message);\n if (message1 !== message2) {\n const error = new NonRetryableError(\n // This looks like a data corruption but the culprit was that the file was overwritten\n // in storage. See PR #5882.\n // Likely to be an issue with Fluid Services. Content does not match previous client\n // knowledge about this file. If the file is overwritten for any reason, this error can be\n // hit. One example is that some clients could be submitting ops to two different service\n // instances such that the same sequence number is reused for two different ops.\n // pre-0.58 error message: twoMessagesWithSameSeqNumAndDifferentPayload\n \"Found two messages with the same sequenceNumber but different payloads. Likely to be a \"\n + \"service issue\",\n DriverErrorType.fileOverwrittenInStorage,\n {\n clientId: this.connectionManager.clientId,\n sequenceNumber: message.sequenceNumber,\n message1,\n message2,\n driverVersion: undefined,\n },\n );\n this.close(error);\n }\n }\n } else if (message.sequenceNumber !== this.lastQueuedSequenceNumber + 1) {\n this.pending.push(message);\n this.fetchMissingDeltas(reason, message.sequenceNumber);\n } else {\n this.lastQueuedSequenceNumber = message.sequenceNumber;\n this.previouslyProcessedMessage = message;\n this._inbound.push(message);\n }\n }\n\n // When / if we report a gap in ops in the future, we want telemetry to correctly reflect source\n // of prior ops. But if we have some out of order ops (this.pending), then reporting current reason\n // becomes not accurate, as the gap existed before current batch, so we should just report \"unknown\".\n this.prevEnqueueMessagesReason = this.pending.length > 0 ? \"unknown\" : reason;\n }\n\n private processInboundMessage(message: ISequencedDocumentMessage): void {\n const startTime = Date.now();\n this.lastProcessedMessage = message;\n\n // All non-system messages are coming from some client, and should have clientId\n // System messages may have no clientId (but some do, like propose, noop, summarize)\n assert(\n message.clientId !== undefined\n || !(isClientMessage(message)),\n 0x0ed /* \"non-system message have to have clientId\" */,\n );\n\n // TODO Remove after SPO picks up the latest build.\n if (\n typeof message.contents === \"string\"\n && message.contents !== \"\"\n && message.type !== MessageType.ClientLeave\n ) {\n message.contents = JSON.parse(message.contents);\n }\n\n this.connectionManager.beforeProcessingIncomingOp(message);\n\n // Watch the minimum sequence number and be ready to update as needed\n if (this.minSequenceNumber > message.minimumSequenceNumber) {\n // pre-0.58 error message: msnMovesBackwards\n throw new DataCorruptionError(\"Found a lower minimumSequenceNumber (msn) than previously recorded\", {\n ...extractSafePropertiesFromMessage(message),\n clientId: this.connectionManager.clientId,\n });\n }\n this.minSequenceNumber = message.minimumSequenceNumber;\n\n if (message.sequenceNumber !== this.lastProcessedSequenceNumber + 1) {\n // pre-0.58 error message: nonSequentialSequenceNumber\n throw new DataCorruptionError(\"Found a non-Sequential sequenceNumber\", {\n ...extractSafePropertiesFromMessage(message),\n clientId: this.connectionManager.clientId,\n });\n }\n this.lastProcessedSequenceNumber = message.sequenceNumber;\n\n // a bunch of code assumes that this is true\n assert(this.lastProcessedSequenceNumber <= this.lastObservedSeqNumber,\n 0x267 /* \"lastObservedSeqNumber should be updated first\" */);\n\n // Back-compat for older server with no term\n if (message.term === undefined) {\n message.term = 1;\n }\n this.baseTerm = message.term;\n\n if (this.handler === undefined) {\n throw new Error(\"Attempted to process an inbound message without a handler attached\");\n }\n this.handler.process(message);\n\n const endTime = Date.now();\n\n // Should be last, after changing this.lastProcessedSequenceNumber above, as many callers\n // test this.lastProcessedSequenceNumber instead of using op.sequenceNumber itself.\n this.emit(\"op\", message, endTime - startTime);\n }\n\n /**\n * Retrieves the missing deltas between the given sequence numbers\n */\n private fetchMissingDeltas(reasonArg: string, to?: number) {\n this.fetchMissingDeltasCore(reasonArg, false /* cacheOnly */, to).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"fetchMissingDeltasException\" }, error);\n });\n }\n\n /**\n * Retrieves the missing deltas between the given sequence numbers\n */\n private async fetchMissingDeltasCore(\n reason: string,\n cacheOnly: boolean,\n to?: number) {\n // Exit out early if we're already fetching deltas\n if (this.fetchReason !== undefined) {\n return;\n }\n\n if (this.closed) {\n this.logger.sendTelemetryEvent({ eventName: \"fetchMissingDeltasClosedConnection\", reason });\n return;\n }\n\n if (this.handler === undefined) {\n // We do not poses yet any information\n assert(this.lastQueuedSequenceNumber === 0, 0x26b /* \"initial state\" */);\n return;\n }\n\n try {\n let from = this.lastQueuedSequenceNumber + 1;\n\n const n = this.previouslyProcessedMessage?.sequenceNumber;\n if (n !== undefined) {\n // If we already processed at least one op, then we have this.previouslyProcessedMessage populated\n // and can use it to validate that we are operating on same file, i.e. it was not overwritten.\n // Knowing about this mechanism, we could ask for op we already observed to increase validation.\n // This is especially useful when coming out of offline mode or loading from\n // very old cached (by client / driver) snapshot.\n assert(n === this.lastQueuedSequenceNumber, 0x0f2 /* \"previouslyProcessedMessage\" */);\n assert(from > 1, 0x0f3 /* \"not positive\" */);\n from--;\n }\n\n const fetchReason = `${reason}_fetch`;\n this.fetchReason = fetchReason;\n\n await this.getDeltas(\n from,\n to,\n (messages) => {\n this.refreshDelayInfo(this.deltaStorageDelayId);\n this.enqueueMessages(messages, fetchReason);\n },\n cacheOnly);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"GetDeltas_Exception\" }, error);\n this.close(normalizeError(error));\n } finally {\n this.refreshDelayInfo(this.deltaStorageDelayId);\n this.fetchReason = undefined;\n this.processPendingOps(reason);\n }\n }\n\n /**\n * Sorts pending ops and attempts to apply them\n */\n private processPendingOps(reason?: string): void {\n if (this.closed) {\n return;\n }\n\n assert(this.handler !== undefined, 0x26c /* \"handler should be installed\" */);\n\n const pendingSorted = this.pending.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.pending = [];\n // Given that we do not track where these ops came from any more, it's not very\n // actionably to report gaps in this range.\n this.enqueueMessages(pendingSorted, `${reason}_pending`, true /* allowGaps */);\n\n // Re-entrancy is ignored by fetchMissingDeltas, execution will come here when it's over\n if (this.fetchReason === undefined) {\n // See issue #7312 for more details\n // We observe cases where client gets into situation where it is not aware of missing ops\n // (i.e. client being behind), and as such, does not attempt to fetch them.\n // In some cases client may not have enough signal (example - \"read\" connection that is silent -\n // there is no easy way for client to realize it's behind, see a bit of commentary / logic at the\n // end of setupNewSuccessfulConnection). In other cases it should be able to learn that info (\"write\"\n // connection, learn by receiving its own join op), but data suggest it does not happen.\n // In 50% of these cases we do know we are behind through checkpointSequenceNumber on connection object\n // and thus can leverage that to trigger recovery. But this is not going to solve all the problems\n // (the other 50%), and thus these errors below should be looked at even if code below results in\n // recovery.\n if (this.lastQueuedSequenceNumber < this.lastObservedSeqNumber) {\n this.fetchMissingDeltas(\"OpsBehind\");\n }\n }\n }\n\n private updateLatestKnownOpSeqNumber(seq: number) {\n if (this.lastObservedSeqNumber < seq) {\n this.lastObservedSeqNumber = seq;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"deltaManager.js","sourceRoot":"","sources":["../src/deltaManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,wEAA8D;AAC9D,+BAAkC;AAgBlC,+DAAyE;AACzE,qEAIyC;AACzC,2EAI4C;AAC5C,+EAM8C;AAC9C,+DAGsC;AACtC,qEAKyC;AACzC,6CAA0C;AAqB1C;;;GAGG;AACH,MAAa,YACT,SAAQ,gCAA8C;IAgMtD,YACqB,eAAmD,EACnD,MAAwB,EACxB,OAAsB,EACvC,uBAAqF;QAErF,KAAK,EAAE,CAAC;QALS,oBAAe,GAAf,eAAe,CAAoC;QACnD,WAAM,GAAN,MAAM,CAAkB;QACxB,YAAO,GAAP,OAAO,CAAe;QAvLnC,YAAO,GAAgC,EAAE,CAAC;QAGlD,gFAAgF;QACxE,sBAAiB,GAAW,CAAC,CAAC;QAEtC,mCAAmC;QACnC,oHAAoH;QACpH,4EAA4E;QAC5E,mHAAmH;QACnH,+GAA+G;QAC/G,kDAAkD;QAClD,iEAAiE;QACzD,6BAAwB,GAAW,CAAC,CAAC;QACrC,0BAAqB,GAAW,CAAC,CAAC;QAClC,gCAA2B,GAAW,CAAC,CAAC;QAExC,aAAQ,GAAW,CAAC,CAAC;QAE7B;;UAEE;QACM,YAAO,GAAW,CAAC,CAAC;QAI5B,+CAA+C;QACvC,uBAAkB,GAAW,CAAC,CAAC;QAK/B,WAAM,GAAG,KAAK,CAAC;QAKN,oBAAe,GAAG,IAAI,GAAG,EAAU,CAAC;QAC7C,uBAAkB,GAAW,CAAC,CAAC;QAEvB,yBAAoB,GAAG,IAAI,0BAAe,EAAE,CAAC;QAE5C,wBAAmB,GAAG,IAAA,SAAI,GAAE,CAAC;QAC7B,uBAAkB,GAAG,IAAA,SAAI,GAAE,CAAC;QAErC,kBAAa,GAAuB,EAA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AAS,EAAE,KAAK,CAAC,mCAAmC,CAAC,CAAC;QAE9E,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,GAAG,CAAC,CAAC,cAAc,CAAC,CAAC;QACvF,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,+EAA+E;QAC/E,2CAA2C;QAC3C,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,GAAG,MAAM,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAE/E,wFAAwF;QACxF,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS,EAAE;YAChC,mCAAmC;YACnC,yFAAyF;YACzF,2EAA2E;YAC3E,gGAAgG;YAChG,iGAAiG;YACjG,qGAAqG;YACrG,wFAAwF;YACxF,uGAAuG;YACvG,kGAAkG;YAClG,iGAAiG;YACjG,YAAY;YACZ,IAAI,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,qBAAqB,EAAE;gBAC5D,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;aACxC;SACJ;IACL,CAAC;IAEO,4BAA4B,CAAC,GAAW;QAC5C,IAAI,IAAI,CAAC,qBAAqB,GAAG,GAAG,EAAE;YAClC,IAAI,CAAC,qBAAqB,GAAG,GAAG,CAAC;SACpC;IACL,CAAC;CACJ;AA51BD,oCA41BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { default as AbortController } from \"abort-controller\";\nimport { v4 as uuid } from \"uuid\";\nimport {\n ITelemetryLogger,\n IEventProvider,\n ITelemetryProperties,\n ITelemetryErrorEvent,\n} from \"@fluidframework/common-definitions\";\nimport {\n IDeltaHandlerStrategy,\n IDeltaManager,\n IDeltaManagerEvents,\n IDeltaQueue,\n ICriticalContainerError,\n IThrottlingWarning,\n IConnectionDetails,\n} from \"@fluidframework/container-definitions\";\nimport { assert, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport {\n normalizeError,\n logIfFalse,\n safeRaiseEvent,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n IDocumentDeltaStorageService,\n IDocumentService,\n DriverErrorType,\n} from \"@fluidframework/driver-definitions\";\nimport {\n IDocumentMessage,\n ISequencedDocumentMessage,\n ISignalMessage,\n MessageType,\n ConnectionMode,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n NonRetryableError,\n isClientMessage,\n} from \"@fluidframework/driver-utils\";\nimport {\n ThrottlingWarning,\n DataCorruptionError,\n extractSafePropertiesFromMessage,\n DataProcessingError,\n} from \"@fluidframework/container-utils\";\nimport { DeltaQueue } from \"./deltaQueue\";\nimport {\n IConnectionManagerFactoryArgs,\n IConnectionManager,\n } from \"./contracts\";\n\nexport interface IConnectionArgs {\n mode?: ConnectionMode;\n fetchOpsFromStorage?: boolean;\n reason: string;\n}\n\n/**\n * Includes events emitted by the concrete implementation DeltaManager\n * but not exposed on the public interface IDeltaManager\n */\nexport interface IDeltaManagerInternalEvents extends IDeltaManagerEvents {\n (event: \"throttled\", listener: (error: IThrottlingWarning) => void);\n (event: \"closed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Manages the flow of both inbound and outbound messages. This class ensures that shared objects receive delta\n * messages in order regardless of possible network conditions or timings causing out of order delivery.\n */\nexport class DeltaManager<TConnectionManager extends IConnectionManager>\n extends TypedEventEmitter<IDeltaManagerInternalEvents>\n implements\n IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n IEventProvider<IDeltaManagerInternalEvents> {\n public readonly connectionManager: TConnectionManager;\n\n public get active(): boolean { return this._active(); }\n\n public get disposed() { return this.closed; }\n\n public get IDeltaSender() { return this; }\n\n private pending: ISequencedDocumentMessage[] = [];\n private fetchReason: string | undefined;\n\n // The minimum sequence number and last sequence number received from the server\n private minSequenceNumber: number = 0;\n\n // There are three numbers we track\n // * lastQueuedSequenceNumber is the last queued sequence number. If there are gaps in seq numbers, then this number\n // is not updated until we cover that gap, so it increases each time by 1.\n // * lastObservedSeqNumber is an estimation of last known sequence number for container in storage. It's initially\n // populated at web socket connection time (if storage provides that info) and is updated once ops shows up.\n // It's never less than lastQueuedSequenceNumber\n // * lastProcessedSequenceNumber - last processed sequence number\n private lastQueuedSequenceNumber: number = 0;\n private lastObservedSeqNumber: number = 0;\n private lastProcessedSequenceNumber: number = 0;\n private lastProcessedMessage: ISequencedDocumentMessage | undefined;\n private baseTerm: number = 0;\n\n /**\n * Track down the ops size.\n */\n private opsSize: number = 0;\n private prevEnqueueMessagesReason: string | undefined;\n private previouslyProcessedMessage: ISequencedDocumentMessage | undefined;\n\n // The sequence number we initially loaded from\n private initSequenceNumber: number = 0;\n\n private readonly _inbound: DeltaQueue<ISequencedDocumentMessage>;\n private readonly _inboundSignal: DeltaQueue<ISignalMessage>;\n\n private closed = false;\n\n private handler: IDeltaHandlerStrategy | undefined;\n private deltaStorage: IDocumentDeltaStorageService | undefined;\n\n private readonly throttlingIdSet = new Set<string>();\n private timeTillThrottling: number = 0;\n\n public readonly closeAbortController = new AbortController();\n\n private readonly deltaStorageDelayId = uuid();\n private readonly deltaStreamDelayId = uuid();\n\n private messageBuffer: IDocumentMessage[] = [];\n\n private _checkpointSequenceNumber: number | undefined;\n\n public get inbound(): IDeltaQueue<ISequencedDocumentMessage> {\n return this._inbound;\n }\n\n public get inboundSignal(): IDeltaQueue<ISignalMessage> {\n return this._inboundSignal;\n }\n\n public get initialSequenceNumber(): number {\n return this.initSequenceNumber;\n }\n\n public get lastSequenceNumber(): number {\n return this.lastProcessedSequenceNumber;\n }\n\n public get lastMessage() {\n return this.lastProcessedMessage;\n }\n\n public get lastKnownSeqNumber() {\n return this.lastObservedSeqNumber;\n }\n\n public get referenceTerm(): number {\n return this.baseTerm;\n }\n\n public get minimumSequenceNumber(): number {\n return this.minSequenceNumber;\n }\n\n /**\n * Tells if current connection has checkpoint information.\n * I.e. we know how far behind the client was at the time of establishing connection\n */\n public get hasCheckpointSequenceNumber() {\n // Valid to be called only if we have active connection.\n assert(this.connectionManager.connected, 0x0df /* \"Missing active connection\" */);\n return this._checkpointSequenceNumber !== undefined;\n }\n\n // Forwarding connection manager properties / IDeltaManager implementation\n public get maxMessageSize(): number { return this.connectionManager.maxMessageSize; }\n public get version() { return this.connectionManager.version; }\n public get serviceConfiguration() { return this.connectionManager.serviceConfiguration; }\n public get outbound() { return this.connectionManager.outbound; }\n public get readOnlyInfo() { return this.connectionManager.readOnlyInfo; }\n public get clientDetails() { return this.connectionManager.clientDetails; }\n\n public submit(type: MessageType, contents: any, batch = false, metadata?: any) {\n const messagePartial: Omit<IDocumentMessage, \"clientSequenceNumber\"> = {\n contents: JSON.stringify(contents),\n metadata,\n referenceSequenceNumber: this.lastProcessedSequenceNumber,\n type,\n };\n\n if (!batch) {\n this.flush();\n }\n\n const message = this.connectionManager.prepareMessageToSend(messagePartial);\n if (message === undefined) {\n return -1;\n }\n\n this.opsSize += message.contents.length;\n\n this.messageBuffer.push(message);\n\n this.emit(\"submitOp\", message);\n\n if (!batch) {\n this.flush();\n }\n\n return message.clientSequenceNumber;\n }\n\n public submitSignal(content: any) { return this.connectionManager.submitSignal(content); }\n\n public flush() {\n if (this.messageBuffer.length === 0) {\n return;\n }\n\n // The prepareFlush event allows listeners to append metadata to the batch prior to submission.\n this.emit(\"prepareSend\", this.messageBuffer);\n\n this.connectionManager.sendMessages(this.messageBuffer);\n this.messageBuffer = [];\n }\n\n public get connectionProps(): ITelemetryProperties {\n return {\n sequenceNumber: this.lastSequenceNumber,\n opsSize: this.opsSize > 0 ? this.opsSize : undefined,\n ...this.connectionManager.connectionProps,\n };\n }\n\n /**\n * Log error event with a bunch of internal to DeltaManager information about state of op processing\n * Used to diagnose connectivity issues related to op processing (i.e. cases where for some reason\n * we stop processing ops that results in no processing join op and thus moving to connected state)\n * @param event - Event to log.\n */\n public logConnectionIssue(event: ITelemetryErrorEvent) {\n assert(this.connectionManager.connected, 0x238 /* \"called only in connected state\" */);\n\n const pendingSorted = this.pending.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.logger.sendErrorEvent({\n ...event,\n // This directly tells us if fetching ops is in flight, and thus likely the reason of\n // stalled op processing\n fetchReason: this.fetchReason,\n // A bunch of useful sequence numbers to understand if we are holding some ops from processing\n lastQueuedSequenceNumber: this.lastQueuedSequenceNumber, // last sequential op\n lastProcessedSequenceNumber: this.lastProcessedSequenceNumber, // same as above, but after processing\n lastObserved: this.lastObservedSeqNumber, // last sequence we ever saw; may have gaps with above.\n // connection info\n ...this.connectionManager.connectionVerboseProps,\n pendingOps: this.pending.length, // Do we have any pending ops?\n pendingFirst: pendingSorted[0]?.sequenceNumber, // is the first pending op the one that we are missing?\n haveHandler: this.handler !== undefined, // do we have handler installed?\n inboundLength: this.inbound.length,\n inboundPaused: this.inbound.paused,\n });\n }\n\n constructor(\n private readonly serviceProvider: () => IDocumentService | undefined,\n private readonly logger: ITelemetryLogger,\n private readonly _active: () => boolean,\n createConnectionManager: (props: IConnectionManagerFactoryArgs) => TConnectionManager,\n ) {\n super();\n const props: IConnectionManagerFactoryArgs = {\n incomingOpHandler: (messages: ISequencedDocumentMessage[], reason: string) => {\n try {\n this.enqueueMessages(messages, reason);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"EnqueueMessages_Exception\" }, error);\n this.close(normalizeError(error));\n }\n },\n signalHandler: (message: ISignalMessage) => this._inboundSignal.push(message),\n reconnectionDelayHandler: (delayMs: number, error: unknown) =>\n this.emitDelayInfo(this.deltaStreamDelayId, delayMs, error),\n closeHandler: (error: any) => this.close(error),\n disconnectHandler: (reason: string) => this.disconnectHandler(reason),\n connectHandler: (connection: IConnectionDetails) => this.connectHandler(connection),\n pongHandler: (latency: number) => this.emit(\"pong\", latency),\n readonlyChangeHandler: (readonly?: boolean) => safeRaiseEvent(this, this.logger, \"readonly\", readonly),\n };\n\n this.connectionManager = createConnectionManager(props);\n\n this._inbound = new DeltaQueue<ISequencedDocumentMessage>(\n (op) => {\n this.processInboundMessage(op);\n });\n\n this._inbound.on(\"error\", (error) => {\n this.close(\n DataProcessingError.wrapIfUnrecognized(error, \"deltaManagerInboundErrorHandler\", this.lastMessage));\n });\n\n // Inbound signal queue\n this._inboundSignal = new DeltaQueue<ISignalMessage>((message) => {\n if (this.handler === undefined) {\n throw new Error(\"Attempted to process an inbound signal without a handler attached\");\n }\n this.handler.processSignal({\n clientId: message.clientId,\n content: JSON.parse(message.content as string),\n });\n });\n\n this._inboundSignal.on(\"error\", (error) => {\n this.close(normalizeError(error));\n });\n\n // Initially, all queues are created paused.\n // - outbound is flipped back and forth in setupNewSuccessfulConnection / disconnectFromDeltaStream\n // - inbound & inboundSignal are resumed in attachOpHandler() when we have handler setup\n }\n\n private connectHandler(connection: IConnectionDetails) {\n this.refreshDelayInfo(this.deltaStreamDelayId);\n\n const props = this.connectionManager.connectionVerboseProps;\n props.connectionLastQueuedSequenceNumber = this.lastQueuedSequenceNumber;\n props.connectionLastObservedSeqNumber = this.lastObservedSeqNumber;\n\n const checkpointSequenceNumber = connection.checkpointSequenceNumber;\n this._checkpointSequenceNumber = checkpointSequenceNumber;\n if (checkpointSequenceNumber !== undefined) {\n this.updateLatestKnownOpSeqNumber(checkpointSequenceNumber);\n }\n\n // We cancel all ops on lost of connectivity, and rely on DDSes to resubmit them.\n // Semantics are not well defined for batches (and they are broken right now on disconnects anyway),\n // but it's safe to assume (until better design is put into place) that batches should not exist\n // across multiple connections. Right now we assume runtime will not submit any ops in disconnected\n // state. As requirements change, so should these checks.\n assert(this.messageBuffer.length === 0, 0x0e9 /* \"messageBuffer is not empty on new connection\" */);\n\n this.opsSize = 0;\n\n this.emit(\n \"connect\",\n connection,\n checkpointSequenceNumber !== undefined ?\n this.lastObservedSeqNumber - this.lastSequenceNumber : undefined);\n\n // If we got some initial ops, then we know the gap and call above fetched ops to fill it.\n // Same is true for \"write\" mode even if we have no ops - we will get \"join\" own op very very soon.\n // However if we are connecting as view-only, then there is no good signal to realize if client is behind.\n // Thus we have to hit storage to see if any ops are there.\n if (checkpointSequenceNumber !== undefined) {\n // We know how far we are behind (roughly). If it's non-zero gap, fetch ops right away.\n if (checkpointSequenceNumber > this.lastQueuedSequenceNumber) {\n this.fetchMissingDeltas(\"AfterConnection\");\n }\n // we do not know the gap, and we will not learn about it if socket is quite - have to ask.\n } else if (connection.mode === \"read\") {\n this.fetchMissingDeltas(\"AfterReadConnection\");\n }\n }\n\n public dispose() {\n throw new Error(\"Not implemented.\");\n }\n\n /**\n * Sets the sequence number from which inbound messages should be returned\n */\n public async attachOpHandler(\n minSequenceNumber: number,\n sequenceNumber: number,\n term: number,\n handler: IDeltaHandlerStrategy,\n prefetchType: \"cached\" | \"all\" | \"none\" = \"none\",\n ) {\n this.initSequenceNumber = sequenceNumber;\n this.lastProcessedSequenceNumber = sequenceNumber;\n this.baseTerm = term;\n this.minSequenceNumber = minSequenceNumber;\n this.lastQueuedSequenceNumber = sequenceNumber;\n this.lastObservedSeqNumber = sequenceNumber;\n\n // We will use same check in other places to make sure all the seq number above are set properly.\n assert(this.handler === undefined, 0x0e2 /* \"DeltaManager already has attached op handler!\" */);\n this.handler = handler;\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n assert(!!(this.handler as any), 0x0e3 /* \"Newly set op handler is null/undefined!\" */);\n\n // There should be no pending fetch!\n // This API is called right after attachOpHandler by Container.load().\n // We might have connection already and it might have called fetchMissingDeltas() from\n // setupNewSuccessfulConnection. But it should do nothing, because there is no way to fetch ops before\n // we know snapshot sequence number that is set in attachOpHandler. So all such calls should be noop.\n assert(this.fetchReason === undefined, 0x268 /* \"There can't be pending fetch that early in boot sequence!\" */);\n\n if (this.closed) {\n return;\n }\n\n this._inbound.resume();\n this._inboundSignal.resume();\n\n if (prefetchType !== \"none\") {\n const cacheOnly = prefetchType === \"cached\";\n await this.fetchMissingDeltasCore(`DocumentOpen_${prefetchType}`, cacheOnly);\n\n // Keep going with fetching ops from storage once we have all cached ops in.\n // But do not block load and make this request async / not blocking this api.\n // Ops processing will start once cached ops are in and and will stop when queue is empty\n // (which in most cases will happen when we are done processing cached ops)\n if (cacheOnly) {\n // fire and forget\n this.fetchMissingDeltas(\"PostDocumentOpen\");\n }\n }\n\n // Ensure there is no need to call this.processPendingOps() at the end of boot sequence\n assert(this.fetchReason !== undefined || this.pending.length === 0, 0x269 /* \"pending ops are not dropped\" */);\n }\n\n public connect(args: IConnectionArgs) {\n const fetchOpsFromStorage = args.fetchOpsFromStorage ?? true;\n logIfFalse(\n this.handler !== undefined || !fetchOpsFromStorage,\n this.logger,\n \"CantFetchWithoutBaseline\"); // can't fetch if no baseline\n\n // Note: There is race condition here.\n // We want to issue request to storage as soon as possible, to\n // reduce latency of becoming current, thus this code here.\n // But there is no ordering between fetching OPs and connection to delta stream\n // As result, we might be behind by the time we connect to delta stream\n // In case of r/w connection, that's not an issue, because we will hear our\n // own \"join\" message and realize any gap client has in ops.\n // But for view-only connection, we have no such signal, and with no traffic\n // on the wire, we might be always behind.\n // See comment at the end of \"connect\" handler\n if (fetchOpsFromStorage) {\n this.fetchMissingDeltas(args.reason);\n }\n\n this.connectionManager.connect(args.mode);\n }\n\n private async getDeltas(\n from: number, // inclusive\n to: number | undefined, // exclusive\n fetchReason: string,\n callback: (messages: ISequencedDocumentMessage[]) => void,\n cacheOnly: boolean) {\n const docService = this.serviceProvider();\n if (docService === undefined) {\n throw new Error(\"Delta manager is not attached\");\n }\n\n if (this.deltaStorage === undefined) {\n this.deltaStorage = await docService.connectToDeltaStorage();\n }\n\n let cancelFetch: (op: ISequencedDocumentMessage) => boolean;\n\n if (to !== undefined) {\n const lastExpectedOp = to - 1; // make it inclusive!\n\n // It is possible that due to asynchrony (including await above), required ops were already\n // received through delta stream. Validate that before moving forward.\n if (this.lastQueuedSequenceNumber >= lastExpectedOp) {\n this.logger.sendPerformanceEvent({\n reason: fetchReason,\n eventName: \"ExtraStorageCall\",\n early: true,\n from,\n to,\n ...this.connectionManager.connectionVerboseProps,\n });\n return;\n }\n\n // Be prepared for the case where webSocket would receive the ops that we are trying to fill through\n // storage. Ideally it should never happen (i.e. ops on socket are always ordered, and thus once we\n // detected gap, this gap can't be filled in later on through websocket).\n // And in practice that does look like the case. The place where this code gets hit is if we lost\n // connection and reconnected (likely to another box), and new socket's initial ops contains these ops.\n cancelFetch = (op: ISequencedDocumentMessage) => op.sequenceNumber >= lastExpectedOp;\n } else {\n // Unbound requests are made to proactively fetch ops, but also get up to date in cases where socket\n // is silent (and connection is \"read\", thus we might not have any data on how far client is behind).\n // Once we have any op coming in from socket, we can cancel it as it's not needed any more.\n // That said, if we have socket connection, make sure we got ops up to checkpointSequenceNumber!\n cancelFetch = (op: ISequencedDocumentMessage) => op.sequenceNumber >= this.lastObservedSeqNumber;\n }\n\n const controller = new AbortController();\n let opsFromFetch = false;\n\n const opListener = (op: ISequencedDocumentMessage) => {\n assert(op.sequenceNumber === this.lastQueuedSequenceNumber, 0x23a /* \"seq#'s\" */);\n // Ops that are coming from this request should not cancel itself.\n // This is useless for known ranges (to is defined) as it means request is over either way.\n // And it will cancel unbound request too early, not allowing us to learn where the end of the file is.\n if (!opsFromFetch && cancelFetch(op)) {\n controller.abort();\n this._inbound.off(\"push\", opListener);\n }\n };\n\n try {\n this._inbound.on(\"push\", opListener);\n assert(this.closeAbortController.signal.onabort === null, 0x1e8 /* \"reentrancy\" */);\n this.closeAbortController.signal.onabort = () => controller.abort();\n\n const stream = this.deltaStorage.fetchMessages(\n from, // inclusive\n to, // exclusive\n controller.signal,\n cacheOnly,\n fetchReason);\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await stream.read();\n if (result.done) {\n break;\n }\n try {\n opsFromFetch = true;\n callback(result.value);\n } finally {\n opsFromFetch = false;\n }\n }\n } finally {\n this.closeAbortController.signal.onabort = null;\n this._inbound.off(\"push\", opListener);\n assert(!opsFromFetch, 0x289 /* \"logic error\" */);\n }\n }\n\n /**\n * Closes the connection and clears inbound & outbound queues.\n */\n public close(error?: ICriticalContainerError): void {\n if (this.closed) {\n return;\n }\n this.closed = true;\n\n this.connectionManager.dispose(error);\n\n this.closeAbortController.abort();\n\n this._inbound.clear();\n this._inboundSignal.clear();\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._inbound.pause();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._inboundSignal.pause();\n\n // Drop pending messages - this will ensure catchUp() does not go into infinite loop\n this.pending = [];\n\n // This needs to be the last thing we do (before removing listeners), as it causes\n // Container to dispose context and break ability of data stores / runtime to \"hear\"\n // from delta manager, including notification (above) about readonly state.\n this.emit(\"closed\", error);\n\n this.removeAllListeners();\n }\n\n public refreshDelayInfo(id: string) {\n this.throttlingIdSet.delete(id);\n if (this.throttlingIdSet.size === 0) {\n this.timeTillThrottling = 0;\n }\n }\n\n private disconnectHandler(reason: string) {\n this.messageBuffer.length = 0;\n this.emit(\"disconnect\", reason);\n }\n\n /**\n * Emit info about a delay in service communication on account of throttling.\n * @param id - Id of the connection that is delayed\n * @param delayMs - Duration of the delay\n * @param error - error object indicating the throttling\n */\n public emitDelayInfo(id: string, delayMs: number, error: unknown) {\n const timeNow = Date.now();\n this.throttlingIdSet.add(id);\n if (delayMs > 0 && (timeNow + delayMs > this.timeTillThrottling)) {\n this.timeTillThrottling = timeNow + delayMs;\n\n const throttlingWarning: IThrottlingWarning = ThrottlingWarning.wrap(\n error,\n delayMs / 1000 /* retryAfterSeconds */,\n this.logger,\n );\n this.emit(\"throttled\", throttlingWarning);\n }\n }\n\n // returns parts of message (in string format) that should never change for a given message.\n // Used for message comparison. It attempts to avoid comparing fields that potentially may differ.\n // for example, it's not clear if serverMetadata or timestamp property is a property of message or server state.\n // We only extract the most obvious fields that are sufficient (with high probability) to detect sequence number\n // reuse.\n // Also payload goes to telemetry, so no PII, including content!!\n // Note: It's possible for a duplicate op to be broadcasted and have everything the same except the timestamp.\n private comparableMessagePayload(m: ISequencedDocumentMessage) {\n return `${m.clientId}-${m.type}-${m.minimumSequenceNumber}-${m.referenceSequenceNumber}-${m.timestamp}`;\n }\n\n private enqueueMessages(\n messages: ISequencedDocumentMessage[],\n reason: string,\n allowGaps = false,\n ): void {\n if (this.handler === undefined) {\n // We did not setup handler yet.\n // This happens when we connect to web socket faster than we get attributes for container\n // and thus faster than attachOpHandler() is called\n // this.lastProcessedSequenceNumber is still zero, so we can't rely on this.fetchMissingDeltas()\n // to do the right thing.\n this.pending = this.pending.concat(messages);\n return;\n }\n\n // Pending ops should never just hang around for nothing.\n // This invariant will stay true through this function execution,\n // so there is no need to process pending ops here.\n // It's responsibility of\n // - attachOpHandler()\n // - fetchMissingDeltas() after it's done with querying storage\n assert(this.pending.length === 0 || this.fetchReason !== undefined, 0x1e9 /* \"Pending ops\" */);\n\n if (messages.length === 0) {\n return;\n }\n\n const from = messages[0].sequenceNumber;\n const last = messages[messages.length - 1].sequenceNumber;\n\n // Report stats about missing and duplicate ops\n // This helps better understand why we fetch ops from storage, and thus may delay\n // getting current / sending ops\n // It's possible that this batch is already too late - do not bother\n if (last > this.lastQueuedSequenceNumber) {\n let prev = from - 1;\n const initialGap = prev - this.lastQueuedSequenceNumber;\n let firstMissing: number | undefined;\n let duplicate = 0;\n let gap = 0;\n\n // Count all gaps and duplicates\n for (const message of messages) {\n if (message.sequenceNumber === prev) {\n duplicate++;\n } else if (message.sequenceNumber !== prev + 1) {\n gap++;\n if (firstMissing === undefined) {\n firstMissing = prev + 1;\n }\n }\n prev = message.sequenceNumber;\n }\n\n let eventName: string | undefined;\n\n // Report if we found some issues\n if (duplicate !== 0 || gap !== 0 && !allowGaps || initialGap > 0 && this.fetchReason === undefined) {\n eventName = \"enqueueMessages\";\n // Also report if we are fetching ops, and same range comes in, thus making this fetch obsolete.\n } else if (this.fetchReason !== undefined && this.fetchReason !== reason &&\n (from <= this.lastQueuedSequenceNumber + 1 && last > this.lastQueuedSequenceNumber)) {\n eventName = \"enqueueMessagesExtraFetch\";\n }\n\n // Report if there is something to report\n // Do not report when pending fetch is in progress, as such reporting will not\n // correctly take into account pending ops.\n if (eventName !== undefined) {\n this.logger.sendPerformanceEvent({\n eventName,\n reason,\n previousReason: this.prevEnqueueMessagesReason,\n from,\n to: last + 1, // exclusive, being consistent with the other telemetry / APIs\n length: messages.length,\n fetchReason: this.fetchReason,\n duplicate: duplicate > 0 ? duplicate : undefined,\n initialGap: initialGap !== 0 ? initialGap : undefined,\n gap: gap > 0 ? gap : undefined,\n firstMissing,\n dmInitialSeqNumber: this.initialSequenceNumber,\n ...this.connectionManager.connectionVerboseProps,\n });\n }\n }\n\n this.updateLatestKnownOpSeqNumber(messages[messages.length - 1].sequenceNumber);\n\n const n = this.previouslyProcessedMessage?.sequenceNumber;\n assert(n === undefined || n === this.lastQueuedSequenceNumber,\n 0x0ec /* \"Unexpected value for previously processed message's sequence number\" */);\n\n for (const message of messages) {\n // Check that the messages are arriving in the expected order\n if (message.sequenceNumber <= this.lastQueuedSequenceNumber) {\n // Validate that we do not have data loss, i.e. sequencing is reset and started again\n // with numbers that this client already observed before.\n if (this.previouslyProcessedMessage?.sequenceNumber === message.sequenceNumber) {\n const message1 = this.comparableMessagePayload(this.previouslyProcessedMessage);\n const message2 = this.comparableMessagePayload(message);\n if (message1 !== message2) {\n const error = new NonRetryableError(\n // This looks like a data corruption but the culprit was that the file was overwritten\n // in storage. See PR #5882.\n // Likely to be an issue with Fluid Services. Content does not match previous client\n // knowledge about this file. If the file is overwritten for any reason, this error can be\n // hit. One example is that some clients could be submitting ops to two different service\n // instances such that the same sequence number is reused for two different ops.\n // pre-0.58 error message: twoMessagesWithSameSeqNumAndDifferentPayload\n \"Found two messages with the same sequenceNumber but different payloads. Likely to be a \"\n + \"service issue\",\n DriverErrorType.fileOverwrittenInStorage,\n {\n clientId: this.connectionManager.clientId,\n sequenceNumber: message.sequenceNumber,\n message1,\n message2,\n driverVersion: undefined,\n },\n );\n this.close(error);\n }\n }\n } else if (message.sequenceNumber !== this.lastQueuedSequenceNumber + 1) {\n this.pending.push(message);\n this.fetchMissingDeltas(reason, message.sequenceNumber);\n } else {\n this.lastQueuedSequenceNumber = message.sequenceNumber;\n this.previouslyProcessedMessage = message;\n this._inbound.push(message);\n }\n }\n\n // When / if we report a gap in ops in the future, we want telemetry to correctly reflect source\n // of prior ops. But if we have some out of order ops (this.pending), then reporting current reason\n // becomes not accurate, as the gap existed before current batch, so we should just report \"unknown\".\n this.prevEnqueueMessagesReason = this.pending.length > 0 ? \"unknown\" : reason;\n }\n\n private processInboundMessage(message: ISequencedDocumentMessage): void {\n const startTime = Date.now();\n this.lastProcessedMessage = message;\n\n // All non-system messages are coming from some client, and should have clientId\n // System messages may have no clientId (but some do, like propose, noop, summarize)\n assert(\n message.clientId !== undefined\n || !(isClientMessage(message)),\n 0x0ed /* \"non-system message have to have clientId\" */,\n );\n\n // TODO Remove after SPO picks up the latest build.\n if (\n typeof message.contents === \"string\"\n && message.contents !== \"\"\n && message.type !== MessageType.ClientLeave\n ) {\n message.contents = JSON.parse(message.contents);\n }\n\n this.connectionManager.beforeProcessingIncomingOp(message);\n\n // Watch the minimum sequence number and be ready to update as needed\n if (this.minSequenceNumber > message.minimumSequenceNumber) {\n // pre-0.58 error message: msnMovesBackwards\n throw new DataCorruptionError(\"Found a lower minimumSequenceNumber (msn) than previously recorded\", {\n ...extractSafePropertiesFromMessage(message),\n clientId: this.connectionManager.clientId,\n });\n }\n this.minSequenceNumber = message.minimumSequenceNumber;\n\n if (message.sequenceNumber !== this.lastProcessedSequenceNumber + 1) {\n // pre-0.58 error message: nonSequentialSequenceNumber\n throw new DataCorruptionError(\"Found a non-Sequential sequenceNumber\", {\n ...extractSafePropertiesFromMessage(message),\n clientId: this.connectionManager.clientId,\n });\n }\n this.lastProcessedSequenceNumber = message.sequenceNumber;\n\n // a bunch of code assumes that this is true\n assert(this.lastProcessedSequenceNumber <= this.lastObservedSeqNumber,\n 0x267 /* \"lastObservedSeqNumber should be updated first\" */);\n\n // Back-compat for older server with no term\n if (message.term === undefined) {\n message.term = 1;\n }\n this.baseTerm = message.term;\n\n if (this.handler === undefined) {\n throw new Error(\"Attempted to process an inbound message without a handler attached\");\n }\n this.handler.process(message);\n\n const endTime = Date.now();\n\n // Should be last, after changing this.lastProcessedSequenceNumber above, as many callers\n // test this.lastProcessedSequenceNumber instead of using op.sequenceNumber itself.\n this.emit(\"op\", message, endTime - startTime);\n }\n\n /**\n * Retrieves the missing deltas between the given sequence numbers\n */\n private fetchMissingDeltas(reasonArg: string, to?: number) {\n this.fetchMissingDeltasCore(reasonArg, false /* cacheOnly */, to).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"fetchMissingDeltasException\" }, error);\n });\n }\n\n /**\n * Retrieves the missing deltas between the given sequence numbers\n */\n private async fetchMissingDeltasCore(\n reason: string,\n cacheOnly: boolean,\n to?: number) {\n // Exit out early if we're already fetching deltas\n if (this.fetchReason !== undefined) {\n return;\n }\n\n if (this.closed) {\n this.logger.sendTelemetryEvent({ eventName: \"fetchMissingDeltasClosedConnection\", reason });\n return;\n }\n\n if (this.handler === undefined) {\n // We do not poses yet any information\n assert(this.lastQueuedSequenceNumber === 0, 0x26b /* \"initial state\" */);\n return;\n }\n\n try {\n let from = this.lastQueuedSequenceNumber + 1;\n\n const n = this.previouslyProcessedMessage?.sequenceNumber;\n if (n !== undefined) {\n // If we already processed at least one op, then we have this.previouslyProcessedMessage populated\n // and can use it to validate that we are operating on same file, i.e. it was not overwritten.\n // Knowing about this mechanism, we could ask for op we already observed to increase validation.\n // This is especially useful when coming out of offline mode or loading from\n // very old cached (by client / driver) snapshot.\n assert(n === this.lastQueuedSequenceNumber, 0x0f2 /* \"previouslyProcessedMessage\" */);\n assert(from > 1, 0x0f3 /* \"not positive\" */);\n from--;\n }\n\n const fetchReason = `${reason}_fetch`;\n this.fetchReason = fetchReason;\n\n await this.getDeltas(\n from,\n to,\n fetchReason,\n (messages) => {\n this.refreshDelayInfo(this.deltaStorageDelayId);\n this.enqueueMessages(messages, fetchReason);\n },\n cacheOnly);\n } catch (error) {\n this.logger.sendErrorEvent({ eventName: \"GetDeltas_Exception\" }, error);\n this.close(normalizeError(error));\n } finally {\n this.refreshDelayInfo(this.deltaStorageDelayId);\n this.fetchReason = undefined;\n this.processPendingOps(reason);\n }\n }\n\n /**\n * Sorts pending ops and attempts to apply them\n */\n private processPendingOps(reason?: string): void {\n if (this.closed) {\n return;\n }\n\n assert(this.handler !== undefined, 0x26c /* \"handler should be installed\" */);\n\n const pendingSorted = this.pending.sort((a, b) => a.sequenceNumber - b.sequenceNumber);\n this.pending = [];\n // Given that we do not track where these ops came from any more, it's not very\n // actionably to report gaps in this range.\n this.enqueueMessages(pendingSorted, `${reason}_pending`, true /* allowGaps */);\n\n // Re-entrancy is ignored by fetchMissingDeltas, execution will come here when it's over\n if (this.fetchReason === undefined) {\n // See issue #7312 for more details\n // We observe cases where client gets into situation where it is not aware of missing ops\n // (i.e. client being behind), and as such, does not attempt to fetch them.\n // In some cases client may not have enough signal (example - \"read\" connection that is silent -\n // there is no easy way for client to realize it's behind, see a bit of commentary / logic at the\n // end of setupNewSuccessfulConnection). In other cases it should be able to learn that info (\"write\"\n // connection, learn by receiving its own join op), but data suggest it does not happen.\n // In 50% of these cases we do know we are behind through checkpointSequenceNumber on connection object\n // and thus can leverage that to trigger recovery. But this is not going to solve all the problems\n // (the other 50%), and thus these errors below should be looked at even if code below results in\n // recovery.\n if (this.lastQueuedSequenceNumber < this.lastObservedSeqNumber) {\n this.fetchMissingDeltas(\"OpsBehind\");\n }\n }\n }\n\n private updateLatestKnownOpSeqNumber(seq: number) {\n if (this.lastObservedSeqNumber < seq) {\n this.lastObservedSeqNumber = seq;\n }\n }\n}\n"]}
@@ -20,7 +20,10 @@ export declare class DeltaQueueProxy<T> extends EventForwarder<IDeltaQueueEvents
20
20
  pause(): Promise<void>;
21
21
  systemResume(): Promise<void>;
22
22
  resume(): Promise<void>;
23
- waitTillProcessingDone(): Promise<void>;
23
+ waitTillProcessingDone(): Promise<{
24
+ count: number;
25
+ duration: number;
26
+ }>;
24
27
  }
25
28
  /**
26
29
  * Proxy to the real IDeltaManager - used to restrict access
@@ -1 +1 @@
1
- {"version":3,"file":"deltaManagerProxy.d.ts","sourceRoot":"","sources":["../src/deltaManagerProxy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EACH,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACjB,MAAM,sCAAsC,CAAC;AAE9C;;GAEG;AACH,qBAAa,eAAe,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAatF,OAAO,CAAC,QAAQ,CAAC,KAAK;IAZlC,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,IAAI,IAAI,OAAO,CAEzB;gBAE4B,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;IAI3C,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,OAAO,IAAI,CAAC,EAAE;IAKR,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAKtB,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7B,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,sBAAsB;CAGtC;AAED;;GAEG;AACH,qBAAa,iBACT,SAAQ,cAAc,CAAC,mBAAmB,CAC1C,YAAW,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC;IAyDzD,OAAO,CAAC,QAAQ,CAAC,YAAY;IAxDzC,SAAgB,OAAO,EAAE,WAAW,C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AAW,MAAM,IAAI,OAAO,CAE3B;IAED,IAAW,YAAY,IAAI,YAAY,CAEtC;gBAE4B,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC;IAQ9F,OAAO,IAAI,IAAI;IAOf,YAAY,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;IAIhC,KAAK,IAAI,IAAI;CAGvB"}
@@ -22,7 +22,7 @@ export declare class DeltaQueue<T> extends TypedEventEmitter<IDeltaQueueEvents<T
22
22
  * When processing is ongoing, holds a deferred that will resolve once processing stops.
23
23
  * Undefined when not processing.
24
24
  */
25
- private processingDeferred;
25
+ private processingPromise;
26
26
  get disposed(): boolean;
27
27
  /**
28
28
  * @returns True if the queue is paused, false if not.
@@ -30,7 +30,13 @@ export declare class DeltaQueue<T> extends TypedEventEmitter<IDeltaQueueEvents<T
30
30
  get paused(): boolean;
31
31
  get length(): number;
32
32
  get idle(): boolean;
33
- waitTillProcessingDone(): Promise<void>;
33
+ waitTillProcessingDone(): Promise<{
34
+ count: number;
35
+ duration: number;
36
+ } | {
37
+ count: number;
38
+ duration: number;
39
+ }>;
34
40
  /**
35
41
  * @param worker - A callback to process a delta.
36
42
  * @param logger - For logging telemetry.
@@ -49,6 +55,7 @@ export declare class DeltaQueue<T> extends TypedEventEmitter<IDeltaQueueEvents<T
49
55
  * not already started.
50
56
  */
51
57
  private ensureProcessing;
58
+ private anythingToProcess;
52
59
  /**
53
60
  * Executes the delta processing loop until a stop condition is reached.
54
61
  */
@@ -1 +1 @@
1
- {"version":3,"file":"deltaQueue.d.ts","sourceRoot":"","sources":["../src/deltaQueue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EAAiC,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGhG,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAChC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG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GtF,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAChC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACpB,KAAK,IAAI,IAAI,CAAC;CACjB;AAED,qBAAa,UAAU,CAAC,CAAC,CACrB,SAAQ,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAC9C,YAAW,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC;IA8C3C,OAAO,CAAC,QAAQ,CAAC,MAAM;IA7C3B,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAkB;IAEpC;;;OAGG;IACH,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,KAAK,CAAkB;IAE/B;;;OAGG;IACH,OAAO,CAAC,iBAAiB,CAA4D;IAErF,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED;;OAEG;IACH,IAAW,MAAM,IAAI,OAAO,CAE3B;IAED,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,IAAI,IAAI,OAAO,CAEzB;IAEY,sBAAsB;;;;;;;IAInC;;;OAGG;gBAEkB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;IAKxC,OAAO;IAKP,KAAK,IAAI,IAAI;IAIb,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,OAAO,IAAI,CAAC,EAAE;IAId,IAAI,CAAC,IAAI,EAAE,CAAC;IAUN,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,MAAM,IAAI,IAAI;IAMrB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,aAAa;CAuBxB"}
@@ -39,12 +39,11 @@ class DeltaQueue extends common_utils_1.TypedEventEmitter {
39
39
  return this.q.length;
40
40
  }
41
41
  get idle() {
42
- return this.processingDeferred === undefined && this.q.length === 0;
42
+ return this.processingPromise === undefined && this.q.length === 0;
43
43
  }
44
44
  async waitTillProcessingDone() {
45
- if (this.processingDeferred !== undefined) {
46
- return this.processingDeferred.promise;
47
- }
45
+ var _a;
46
+ return (_a = this.processingPromise) !== null && _a !== void 0 ? _a : { count: 0, duration: 0 };
48
47
  }
49
48
  dispose() {
50
49
  throw new Error("Not implemented.");
@@ -73,7 +72,7 @@ class DeltaQueue extends common_utils_1.TypedEventEmitter {
73
72
  this.pauseCount++;
74
73
  // If called from within the processing loop, we are in the middle of processing an op. Return a promise
75
74
  // that will resolve when processing has actually stopped.
76
- return this.waitTillProcessingDone();
75
+ await this.waitTillProcessingDone();
77
76
  }
78
77
  resume() {
79
78
  (0, common_utils_1.assert)(this.pauseCount > 0, 0x0f4 /* "Nonzero pause-count on resume()" */);
@@ -86,19 +85,29 @@ class DeltaQueue extends common_utils_1.TypedEventEmitter {
86
85
  * not already started.
87
86
  */
88
87
  ensureProcessing() {
89
- if (!this.paused && this.processingDeferred === undefined) {
90
- this.processingDeferred = new common_utils_1.Deferred();
88
+ if (this.anythingToProcess() && this.processingPromise === undefined) {
91
89
  // Use a resolved promise to start the processing on a separate stack.
92
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
93
- Promise.resolve().then(() => {
94
- this.processDeltas();
95
- if (this.processingDeferred !== undefined) {
96
- this.processingDeferred.resolve();
97
- this.processingDeferred = undefined;
98
- }
90
+ this.processingPromise = Promise.resolve().then(() => {
91
+ (0, common_utils_1.assert)(this.processingPromise !== undefined, "reentrancy?");
92
+ const result = this.processDeltas();
93
+ (0, common_utils_1.assert)(this.processingPromise !== undefined, "reentrancy?");
94
+ // WARNING: Do not move next line to .finally() clause!
95
+ // It runs async and creates a race condition where incoming ensureProcessing() call observes
96
+ // from previous run while previous run is over (but finally clause was not scheduled yet)
97
+ this.processingPromise = undefined;
98
+ return result;
99
+ }).catch((error) => {
100
+ this.error = error;
101
+ this.processingPromise = undefined;
102
+ this.emit("error", error);
103
+ return { count: 0, duration: 0 };
99
104
  });
105
+ (0, common_utils_1.assert)(this.processingPromise !== undefined, "processDeltas() should run async");
100
106
  }
101
107
  }
108
+ anythingToProcess() {
109
+ return this.q.length !== 0 && !this.paused && this.error === undefined;
110
+ }
102
111
  /**
103
112
  * Executes the delta processing loop until a stop condition is reached.
104
113
  */
@@ -107,25 +116,21 @@ class DeltaQueue extends common_utils_1.TypedEventEmitter {
107
116
  let count = 0;
108
117
  // For grouping to work we must process all local messages immediately and in the single turn.
109
118
  // So loop over them until no messages to process, we have become paused, or hit an error.
110
- while (!(this.q.length === 0 || this.paused || this.error !== undefined)) {
119
+ while (this.anythingToProcess()) {
111
120
  // Get the next message in the queue
112
121
  const next = this.q.shift();
113
122
  count++;
114
123
  // Process the message.
115
- try {
116
- // We know next is defined since we did a length check just prior to shifting.
117
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
118
- this.worker(next);
119
- this.emit("op", next);
120
- }
121
- catch (error) {
122
- this.error = error;
123
- this.emit("error", error);
124
- }
124
+ // We know next is defined since we did a length check just prior to shifting.
125
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
126
+ this.worker(next);
127
+ this.emit("op", next);
125
128
  }
129
+ const duration = common_utils_1.performance.now() - start;
126
130
  if (this.q.length === 0) {
127
- this.emit("idle", count, common_utils_1.performance.now() - start);
131
+ this.emit("idle", count, duration);
128
132
  }
133
+ return { count, duration };
129
134
  }
130
135
  }
131
136
  exports.DeltaQueue = DeltaQueue;
@@ -1 +1 @@
1
- {"version":3,"file":"deltaQueue.js","sourceRoot":"","sources":["../src/deltaQueue.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,+DAAgG;AAChG,4EAAuC;AAOvC,MAAa,UACT,SAAQ,gCAAuC;IA4C/C;;;OAGG;IACH,YACqB,MAA0B;QAE3C,KAAK,EAAE,CAAC;QAFS,WAAM,GAAN,MAAM,CAAoB;QA/CvC,eAAU,GAAY,KAAK,CAAC;QACnB,MAAC,GAAG,IAAI,4BAAK,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AI;gBACA,8EAA8E;gBAC9E,oEAAoE;gBACpE,IAAI,CAAC,MAAM,CAAC,IAAK,CAAC,CAAC;gBACnB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;aACzB;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;gBACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;aAC7B;SACJ;QAED,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,0BAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,CAAC;SACvD;IACL,CAAC;CACJ;AAhJD,gCAgJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDeltaQueue, IDeltaQueueEvents } from \"@fluidframework/container-definitions\";\nimport { assert, performance, Deferred, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport Deque from \"double-ended-queue\";\n\nexport interface IDeltaQueueWriter<T> {\n push(task: T): void;\n clear(): void;\n}\n\nexport class DeltaQueue<T>\n extends TypedEventEmitter<IDeltaQueueEvents<T>>\n implements IDeltaQueue<T>, IDeltaQueueWriter<T> {\n private isDisposed: boolean = false;\n private readonly q = new Deque<T>();\n\n /**\n * Tracks the number of pause requests for the queue\n * The DeltaQueue is create initially paused.\n */\n private pauseCount = 1;\n\n private error: any | undefined;\n\n /**\n * When processing is ongoing, holds a deferred that will resolve once processing stops.\n * Undefined when not processing.\n */\n private processingDeferred: Deferred<void> | undefined;\n\n public get disposed(): boolean {\n return this.isDisposed;\n }\n\n /**\n * @returns True if the queue is paused, false if not.\n */\n public get paused(): boolean {\n return this.pauseCount !== 0;\n }\n\n public get length(): number {\n return this.q.length;\n }\n\n public get idle(): boolean {\n return this.processingDeferred === undefined && this.q.length === 0;\n }\n\n public async waitTillProcessingDone(): Promise<void> {\n if (this.processingDeferred !== undefined) {\n return this.processingDeferred.promise;\n }\n }\n\n /**\n * @param worker - A callback to process a delta.\n * @param logger - For logging telemetry.\n */\n constructor(\n private readonly worker: (delta: T) => void,\n ) {\n super();\n }\n\n public dispose() {\n throw new Error(\"Not implemented.\");\n this.isDisposed = true;\n }\n\n public clear(): void {\n this.q.clear();\n }\n\n public peek(): T | undefined {\n return this.q.peekFront();\n }\n\n public toArray(): T[] {\n return this.q.toArray();\n }\n\n public push(task: T) {\n try {\n this.q.push(task);\n this.emit(\"push\", task);\n this.ensureProcessing();\n } catch (error) {\n this.emit(\"error\", error);\n }\n }\n\n public async pause(): Promise<void> {\n this.pauseCount++;\n // If called from within the processing loop, we are in the middle of processing an op. Return a promise\n // that will resolve when processing has actually stopped.\n return this.waitTillProcessingDone();\n }\n\n public resume(): void {\n assert(this.pauseCount > 0, 0x0f4 /* \"Nonzero pause-count on resume()\" */);\n this.pauseCount--;\n this.ensureProcessing();\n }\n\n /**\n * There are several actions that may need to kick off delta processing, so we want to guard against\n * accidental reentrancy. ensureProcessing can be called safely to start the processing loop if it is\n * not already started.\n */\n private ensureProcessing() {\n if (!this.paused && this.processingDeferred === undefined) {\n this.processingDeferred = new Deferred<void>();\n // Use a resolved promise to start the processing on a separate stack.\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n Promise.resolve().then(() => {\n this.processDeltas();\n if (this.processingDeferred !== undefined) {\n this.processingDeferred.resolve();\n this.processingDeferred = undefined;\n }\n });\n }\n }\n\n /**\n * Executes the delta processing loop until a stop condition is reached.\n */\n private processDeltas() {\n const start = performance.now();\n let count = 0;\n\n // For grouping to work we must process all local messages immediately and in the single turn.\n // So loop over them until no messages to process, we have become paused, or hit an error.\n while (!(this.q.length === 0 || this.paused || this.error !== undefined)) {\n // Get the next message in the queue\n const next = this.q.shift();\n count++;\n // Process the message.\n try {\n // We know next is defined since we did a length check just prior to shifting.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.worker(next!);\n this.emit(\"op\", next);\n } catch (error) {\n this.error = error;\n this.emit(\"error\", error);\n }\n }\n\n if (this.q.length === 0) {\n this.emit(\"idle\", count, performance.now() - start);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"deltaQueue.js","sourceRoot":"","sources":["../src/deltaQueue.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,+DAAsF;AACtF,4EAAuC;AAOvC,MAAa,UACT,SAAQ,gCAAuC;IA0C/C;;;OAGG;IACH,YACqB,MAA0B;QAE3C,KAAK,EAAE,CAAC;QAFS,WAAM,GAAN,MAAM,CAAoB;QA7CvC,eAAU,GAAY,KAAK,CAAC;QACnB,MAAC,GAAG,IAAI,4BAAK,EAAK,CAAC;QAEpC;;;WAGG;QACK,eAAU,GAAG,CAAC,CAAC;IAyCvB,CAAC;IA/BD,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,UAAU,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,IAAW,MAAM;QACb,OAAO,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,iBAAiB,KAAK,SAAS,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACvE,CAAC;IAEM,KAAK,CAAC,sBAAsB;;QAC/B,OAAO,MAAA,IAAI,CAAC,iBAAiB,mCAAI,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAC/D,CAAC;IAYM,OAAO;QACV,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;IAC3B,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IA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AC,CAAC,MAAM,KAAK,CAAC,EAAE;YACrB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;SACtC;QACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACJ;AAtJD,gCAsJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDeltaQueue, IDeltaQueueEvents } from \"@fluidframework/container-definitions\";\nimport { assert, performance, TypedEventEmitter } from \"@fluidframework/common-utils\";\nimport Deque from \"double-ended-queue\";\n\nexport interface IDeltaQueueWriter<T> {\n push(task: T): void;\n clear(): void;\n}\n\nexport class DeltaQueue<T>\n extends TypedEventEmitter<IDeltaQueueEvents<T>>\n implements IDeltaQueue<T>, IDeltaQueueWriter<T> {\n private isDisposed: boolean = false;\n private readonly q = new Deque<T>();\n\n /**\n * Tracks the number of pause requests for the queue\n * The DeltaQueue is create initially paused.\n */\n private pauseCount = 1;\n\n private error: any | undefined;\n\n /**\n * When processing is ongoing, holds a deferred that will resolve once processing stops.\n * Undefined when not processing.\n */\n private processingPromise: Promise<{ count: number; duration: number; }> | undefined;\n\n public get disposed(): boolean {\n return this.isDisposed;\n }\n\n /**\n * @returns True if the queue is paused, false if not.\n */\n public get paused(): boolean {\n return this.pauseCount !== 0;\n }\n\n public get length(): number {\n return this.q.length;\n }\n\n public get idle(): boolean {\n return this.processingPromise === undefined && this.q.length === 0;\n }\n\n public async waitTillProcessingDone() {\n return this.processingPromise ?? { count: 0, duration: 0 };\n }\n\n /**\n * @param worker - A callback to process a delta.\n * @param logger - For logging telemetry.\n */\n constructor(\n private readonly worker: (delta: T) => void,\n ) {\n super();\n }\n\n public dispose() {\n throw new Error(\"Not implemented.\");\n this.isDisposed = true;\n }\n\n public clear(): void {\n this.q.clear();\n }\n\n public peek(): T | undefined {\n return this.q.peekFront();\n }\n\n public toArray(): T[] {\n return this.q.toArray();\n }\n\n public push(task: T) {\n try {\n this.q.push(task);\n this.emit(\"push\", task);\n this.ensureProcessing();\n } catch (error) {\n this.emit(\"error\", error);\n }\n }\n\n public async pause(): Promise<void> {\n this.pauseCount++;\n // If called from within the processing loop, we are in the middle of processing an op. Return a promise\n // that will resolve when processing has actually stopped.\n await this.waitTillProcessingDone();\n }\n\n public resume(): void {\n assert(this.pauseCount > 0, 0x0f4 /* \"Nonzero pause-count on resume()\" */);\n this.pauseCount--;\n this.ensureProcessing();\n }\n\n /**\n * There are several actions that may need to kick off delta processing, so we want to guard against\n * accidental reentrancy. ensureProcessing can be called safely to start the processing loop if it is\n * not already started.\n */\n private ensureProcessing() {\n if (this.anythingToProcess() && this.processingPromise === undefined) {\n // Use a resolved promise to start the processing on a separate stack.\n this.processingPromise = Promise.resolve().then(() => {\n assert(this.processingPromise !== undefined, \"reentrancy?\");\n const result = this.processDeltas();\n assert(this.processingPromise !== undefined, \"reentrancy?\");\n // WARNING: Do not move next line to .finally() clause!\n // It runs async and creates a race condition where incoming ensureProcessing() call observes\n // from previous run while previous run is over (but finally clause was not scheduled yet)\n this.processingPromise = undefined;\n return result;\n }).catch((error) => {\n this.error = error;\n this.processingPromise = undefined;\n this.emit(\"error\", error);\n return { count: 0, duration: 0 };\n });\n assert(this.processingPromise !== undefined, \"processDeltas() should run async\");\n }\n }\n\n private anythingToProcess() {\n return this.q.length !== 0 && !this.paused && this.error === undefined;\n }\n\n /**\n * Executes the delta processing loop until a stop condition is reached.\n */\n private processDeltas() {\n const start = performance.now();\n let count = 0;\n\n // For grouping to work we must process all local messages immediately and in the single turn.\n // So loop over them until no messages to process, we have become paused, or hit an error.\n while (this.anythingToProcess()) {\n // Get the next message in the queue\n const next = this.q.shift();\n count++;\n // Process the message.\n // We know next is defined since we did a length check just prior to shifting.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.worker(next!);\n this.emit(\"op\", next);\n }\n\n const duration = performance.now() - start;\n if (this.q.length === 0) {\n this.emit(\"idle\", count, duration);\n }\n return { count, duration };\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -5,4 +5,5 @@
5
5
  export { ConnectionState } from "./connectionState";
6
6
  export { Container, IContainerLoadOptions, IContainerConfig, IPendingContainerState, waitContainerToCatchUp, } from "./container";
7
7
  export { ICodeDetailsLoader, IDetachedBlobStorage, IFluidModuleWithDetails, ILoaderOptions, ILoaderProps, ILoaderServices, Loader, RelativeLoader, } from "./loader";
8
+ export { IProtocolHandler, ProtocolHandlerBuilder, } from "./protocol";
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACH,SAAS,EACT,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,MAAM,EACN,cAAc,GACjB,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACH,SAAS,EACT,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,cAAc,EACd,YAAY,EACZ,eAAe,EACf,MAAM,EACN,cAAc,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACH,gBAAgB,EAChB,sBAAsB,GACzB,MAAM,YAAY,CAAC"}