@fluidframework/container-runtime 2.0.0-internal.2.3.1 → 2.0.0-internal.3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blobManager.d.ts +3 -1
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +35 -2
- package/dist/blobManager.js.map +1 -1
- package/dist/containerRuntime.d.ts +45 -42
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +89 -40
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreContext.d.ts +1 -0
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +7 -2
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/garbageCollection.d.ts +15 -7
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +96 -36
- package/dist/garbageCollection.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +0 -1
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +4 -13
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +130 -160
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/summarizer.js.map +1 -1
- package/dist/summarizerClientElection.d.ts +1 -2
- package/dist/summarizerClientElection.d.ts.map +1 -1
- package/dist/summarizerClientElection.js +3 -30
- package/dist/summarizerClientElection.js.map +1 -1
- package/dist/summarizerTypes.d.ts +0 -4
- package/dist/summarizerTypes.d.ts.map +1 -1
- package/dist/summarizerTypes.js.map +1 -1
- package/lib/blobManager.d.ts +3 -1
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +35 -2
- package/lib/blobManager.js.map +1 -1
- package/lib/containerRuntime.d.ts +45 -42
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +89 -40
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreContext.d.ts +1 -0
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +7 -2
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/garbageCollection.d.ts +15 -7
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +97 -37
- package/lib/garbageCollection.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +0 -1
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +4 -13
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +130 -160
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/summarizer.js.map +1 -1
- package/lib/summarizerClientElection.d.ts +1 -2
- package/lib/summarizerClientElection.d.ts.map +1 -1
- package/lib/summarizerClientElection.js +3 -30
- package/lib/summarizerClientElection.js.map +1 -1
- package/lib/summarizerTypes.d.ts +0 -4
- package/lib/summarizerTypes.d.ts.map +1 -1
- package/lib/summarizerTypes.js.map +1 -1
- package/package.json +55 -20
- package/src/blobManager.ts +41 -2
- package/src/containerRuntime.ts +118 -85
- package/src/dataStoreContext.ts +12 -6
- package/src/garbageCollection.ts +103 -34
- package/src/opLifecycle/outbox.ts +0 -2
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +146 -187
- package/src/summarizer.ts +1 -1
- package/src/summarizerClientElection.ts +1 -30
- package/src/summarizerTypes.ts +0 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE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AC;SACZ;QAED,2GAA2G;QAC3G,oBAAoB,IAAI,MAAM,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,oBAAoB,IAAI,CAAC,EAAE,KAAK,CAAC,4CAA4C,CAAC,CAAC;QACtF,OAAO,oBAAoB,CAAC;IAChC,CAAC;IAEO,YAAY,CAAC,2BAAmC,EAAE,KAAqB;QAC3E,IAAI,oBAAoB,GAAG,2BAA2B,CAAC;QACvD,iEAAiE;QACjE,4DAA4D;QAC5D,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE;YACzB,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAC3C,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAChC,oBAAoB,EACpB,OAAO,CAAC,uBAAuB,EAC/B,OAAO,CAAC,mBAAmB,CAAC,QAAQ,EACpC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,QAAQ,CACnB,CAAC;YAEF,oBAAoB,EAAE,CAAC;SAC1B;QAED,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;IAC9C,CAAC;IAEM,UAAU;QACb,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACtC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;SACrD,CAAC;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IContainerContext } from \"@fluidframework/container-definitions\";\nimport { GenericError } from \"@fluidframework/container-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ICompressionRuntimeOptions } from \"../containerRuntime\";\nimport { PendingStateManager } from \"../pendingStateManager\";\nimport { BatchManager } from \"./batchManager\";\nimport { BatchMessage, IBatch } from \"./definitions\";\nimport { OpCompressor } from \"./opCompressor\";\nimport { OpSplitter } from \"./opSplitter\";\n\nexport interface IOutboxConfig {\n readonly compressionOptions: ICompressionRuntimeOptions;\n // The maximum size of a batch that we can send over the wire.\n readonly maxBatchSizeInBytes: number;\n readonly enableOpReentryCheck?: boolean;\n};\n\nexport interface IOutboxParameters {\n readonly shouldSend: () => boolean,\n readonly pendingStateManager: PendingStateManager,\n readonly containerContext: IContainerContext,\n readonly config: IOutboxConfig,\n readonly compressor: OpCompressor;\n readonly splitter: OpSplitter;\n readonly logger: ITelemetryLogger;\n}\n\nexport class Outbox {\n private readonly attachFlowBatch: BatchManager;\n private readonly mainBatch: BatchManager;\n private readonly defaultAttachFlowSoftLimitInBytes = 64 * 1024;\n\n constructor(private readonly params: IOutboxParameters) {\n const isCompressionEnabled = this.params.config.compressionOptions.minimumBatchSizeInBytes !== Number.POSITIVE_INFINITY;\n // We need to allow infinite size batches if we enable compression\n const hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;\n const softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;\n\n this.attachFlowBatch = new BatchManager({\n hardLimit,\n softLimit,\n enableOpReentryCheck: params.config.enableOpReentryCheck,\n }, params.logger);\n this.mainBatch = new BatchManager({\n hardLimit,\n enableOpReentryCheck: params.config.enableOpReentryCheck,\n }, params.logger);\n }\n\n public get isEmpty(): boolean {\n return this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;\n }\n\n public submit(message: BatchMessage) {\n if (!this.mainBatch.push(message)) {\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: (message.contents?.length) ?? 0,\n count: this.mainBatch.length,\n limit: this.mainBatch.options.hardLimit,\n });\n }\n }\n\n public submitAttach(message: BatchMessage) {\n if (!this.attachFlowBatch.push(message)) {\n // BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged\n // when queue is not empty.\n // Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit\n this.flushInternal(this.attachFlowBatch.popBatch());\n if (!this.attachFlowBatch.push(message)) {\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: (message.contents?.length) ?? 0,\n count: this.attachFlowBatch.length,\n limit: this.attachFlowBatch.options.hardLimit,\n });\n }\n }\n\n // If compression is enabled, we will always successfully receive\n // attach ops and compress then send them at the next JS turn, regardless\n // of the overall size of the accumulated ops in the batch.\n // However, it is more efficient to flush these ops faster, preferably\n // after they reach a size which would benefit from compression.\n if (this.attachFlowBatch.contentSizeInBytes >= this.params.config.compressionOptions.minimumBatchSizeInBytes) {\n this.flushInternal(this.attachFlowBatch.popBatch());\n }\n }\n\n public flush() {\n this.flushInternal(this.attachFlowBatch.popBatch());\n this.flushInternal(this.mainBatch.popBatch());\n }\n\n private flushInternal(rawBatch: IBatch) {\n const processedBatch = this.compressBatch(rawBatch);\n const clientSequenceNumber = this.sendBatch(processedBatch);\n\n this.persistBatch(clientSequenceNumber, rawBatch.content);\n }\n\n private compressBatch(batch: IBatch): IBatch {\n if (batch.content.length === 0\n || this.params.config.compressionOptions === undefined\n || this.params.config.compressionOptions.minimumBatchSizeInBytes > batch.contentSizeInBytes) {\n // Nothing to do if the batch is empty or if compression is disabled or if we don't need to compress\n return batch;\n }\n\n const compressedBatch = this.params.compressor.compressBatch(batch);\n if (compressedBatch.contentSizeInBytes <= this.params.config.maxBatchSizeInBytes) {\n // If we don't reach the maximum supported size of a batch, it can safely be sent as is\n return compressedBatch;\n }\n\n if (this.params.splitter.isBatchChunkingEnabled) {\n return this.params.splitter.splitCompressedBatch(compressedBatch);\n }\n\n // If we've reached this point, the runtime would attempt to send a batch larger than the allowed size\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: batch.contentSizeInBytes,\n count: batch.content.length,\n limit: this.params.config.maxBatchSizeInBytes,\n compressed: true,\n });\n }\n\n /**\n * Sends the batch object to the container context to be sent over the wire.\n *\n * @param batch - batch to be sent\n * @returns the client sequence number of the last batched op which was sent and\n * -1 if there are no ops or the container cannot send ops.\n */\n private sendBatch(batch: IBatch): number {\n let clientSequenceNumber: number = -1;\n const length = batch.content.length;\n\n // Did we disconnect in the middle of turn-based batch?\n // If so, do nothing, as pending state manager will resubmit it correctly on reconnect.\n if (length === 0 || !this.params.shouldSend()) {\n return clientSequenceNumber;\n }\n\n if (this.params.containerContext.submitBatchFn === undefined) {\n // Legacy path - supporting old loader versions. Can be removed only when LTS moves above\n // version that has support for batches (submitBatchFn)\n for (const message of batch.content) {\n // Legacy path doesn't support compressed payloads and will submit uncompressed payload anyways\n if (message.metadata?.compressed) {\n delete message.metadata.compressed;\n }\n\n clientSequenceNumber = this.params.containerContext.submitFn(\n MessageType.Operation,\n message.deserializedContent,\n true, // batch\n message.metadata);\n }\n\n this.params.containerContext.deltaManager.flush();\n } else {\n // returns clientSequenceNumber of last message in a batch\n clientSequenceNumber = this.params.containerContext.submitBatchFn(\n batch.content.map((message) => ({\n contents: message.contents,\n metadata: message.metadata,\n compression: message.compression,\n })));\n }\n\n // Convert from clientSequenceNumber of last message in the batch to clientSequenceNumber of first message.\n clientSequenceNumber -= length - 1;\n assert(clientSequenceNumber >= 0, 0x3d0 /* clientSequenceNumber can't be negative */);\n return clientSequenceNumber;\n }\n\n private persistBatch(initialClientSequenceNumber: number, batch: BatchMessage[]) {\n let clientSequenceNumber = initialClientSequenceNumber;\n // Let the PendingStateManager know that a message was submitted.\n // In future, need to shift toward keeping batch as a whole!\n for (const message of batch) {\n this.params.pendingStateManager.onSubmitMessage(\n message.deserializedContent.type,\n clientSequenceNumber,\n message.referenceSequenceNumber,\n message.deserializedContent.contents,\n message.localOpMetadata,\n message.metadata,\n );\n\n clientSequenceNumber++;\n }\n\n this.params.pendingStateManager.onFlush();\n }\n\n public checkpoint() {\n return {\n mainBatch: this.mainBatch.checkpoint(),\n attachFlowBatch: this.attachFlowBatch.checkpoint(),\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/opLif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AQ;gBAC1B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;aACnC,CAAC,CAAC,CAAC,CAAC;SACZ;QAED,2GAA2G;QAC3G,oBAAoB,IAAI,MAAM,GAAG,CAAC,CAAC;QACnC,MAAM,CAAC,oBAAoB,IAAI,CAAC,EAAE,KAAK,CAAC,4CAA4C,CAAC,CAAC;QACtF,OAAO,oBAAoB,CAAC;IAChC,CAAC;IAEO,YAAY,CAAC,2BAAmC,EAAE,KAAqB;QAC3E,IAAI,oBAAoB,GAAG,2BAA2B,CAAC;QACvD,iEAAiE;QACjE,4DAA4D;QAC5D,KAAK,MAAM,OAAO,IAAI,KAAK,EAAE;YACzB,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAC3C,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAChC,oBAAoB,EACpB,OAAO,CAAC,uBAAuB,EAC/B,OAAO,CAAC,mBAAmB,CAAC,QAAQ,EACpC,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,QAAQ,CACnB,CAAC;YAEF,oBAAoB,EAAE,CAAC;SAC1B;IACL,CAAC;IAEM,UAAU;QACb,OAAO;YACH,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACtC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;SACrD,CAAC;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IContainerContext } from \"@fluidframework/container-definitions\";\nimport { GenericError } from \"@fluidframework/container-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ICompressionRuntimeOptions } from \"../containerRuntime\";\nimport { PendingStateManager } from \"../pendingStateManager\";\nimport { BatchManager } from \"./batchManager\";\nimport { BatchMessage, IBatch } from \"./definitions\";\nimport { OpCompressor } from \"./opCompressor\";\nimport { OpSplitter } from \"./opSplitter\";\n\nexport interface IOutboxConfig {\n readonly compressionOptions: ICompressionRuntimeOptions;\n // The maximum size of a batch that we can send over the wire.\n readonly maxBatchSizeInBytes: number;\n readonly enableOpReentryCheck?: boolean;\n};\n\nexport interface IOutboxParameters {\n readonly shouldSend: () => boolean,\n readonly pendingStateManager: PendingStateManager,\n readonly containerContext: IContainerContext,\n readonly config: IOutboxConfig,\n readonly compressor: OpCompressor;\n readonly splitter: OpSplitter;\n readonly logger: ITelemetryLogger;\n}\n\nexport class Outbox {\n private readonly attachFlowBatch: BatchManager;\n private readonly mainBatch: BatchManager;\n private readonly defaultAttachFlowSoftLimitInBytes = 64 * 1024;\n\n constructor(private readonly params: IOutboxParameters) {\n const isCompressionEnabled = this.params.config.compressionOptions.minimumBatchSizeInBytes !== Number.POSITIVE_INFINITY;\n // We need to allow infinite size batches if we enable compression\n const hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;\n const softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;\n\n this.attachFlowBatch = new BatchManager({\n hardLimit,\n softLimit,\n enableOpReentryCheck: params.config.enableOpReentryCheck,\n }, params.logger);\n this.mainBatch = new BatchManager({\n hardLimit,\n enableOpReentryCheck: params.config.enableOpReentryCheck,\n }, params.logger);\n }\n\n public get isEmpty(): boolean {\n return this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;\n }\n\n public submit(message: BatchMessage) {\n if (!this.mainBatch.push(message)) {\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: (message.contents?.length) ?? 0,\n count: this.mainBatch.length,\n limit: this.mainBatch.options.hardLimit,\n });\n }\n }\n\n public submitAttach(message: BatchMessage) {\n if (!this.attachFlowBatch.push(message)) {\n // BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged\n // when queue is not empty.\n // Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit\n this.flushInternal(this.attachFlowBatch.popBatch());\n if (!this.attachFlowBatch.push(message)) {\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: (message.contents?.length) ?? 0,\n count: this.attachFlowBatch.length,\n limit: this.attachFlowBatch.options.hardLimit,\n });\n }\n }\n\n // If compression is enabled, we will always successfully receive\n // attach ops and compress then send them at the next JS turn, regardless\n // of the overall size of the accumulated ops in the batch.\n // However, it is more efficient to flush these ops faster, preferably\n // after they reach a size which would benefit from compression.\n if (this.attachFlowBatch.contentSizeInBytes >= this.params.config.compressionOptions.minimumBatchSizeInBytes) {\n this.flushInternal(this.attachFlowBatch.popBatch());\n }\n }\n\n public flush() {\n this.flushInternal(this.attachFlowBatch.popBatch());\n this.flushInternal(this.mainBatch.popBatch());\n }\n\n private flushInternal(rawBatch: IBatch) {\n const processedBatch = this.compressBatch(rawBatch);\n const clientSequenceNumber = this.sendBatch(processedBatch);\n\n this.persistBatch(clientSequenceNumber, rawBatch.content);\n }\n\n private compressBatch(batch: IBatch): IBatch {\n if (batch.content.length === 0\n || this.params.config.compressionOptions === undefined\n || this.params.config.compressionOptions.minimumBatchSizeInBytes > batch.contentSizeInBytes) {\n // Nothing to do if the batch is empty or if compression is disabled or if we don't need to compress\n return batch;\n }\n\n const compressedBatch = this.params.compressor.compressBatch(batch);\n if (compressedBatch.contentSizeInBytes <= this.params.config.maxBatchSizeInBytes) {\n // If we don't reach the maximum supported size of a batch, it can safely be sent as is\n return compressedBatch;\n }\n\n if (this.params.splitter.isBatchChunkingEnabled) {\n return this.params.splitter.splitCompressedBatch(compressedBatch);\n }\n\n // If we've reached this point, the runtime would attempt to send a batch larger than the allowed size\n throw new GenericError(\n \"BatchTooLarge\",\n /* error */ undefined,\n {\n opSize: batch.contentSizeInBytes,\n count: batch.content.length,\n limit: this.params.config.maxBatchSizeInBytes,\n compressed: true,\n });\n }\n\n /**\n * Sends the batch object to the container context to be sent over the wire.\n *\n * @param batch - batch to be sent\n * @returns the client sequence number of the last batched op which was sent and\n * -1 if there are no ops or the container cannot send ops.\n */\n private sendBatch(batch: IBatch): number {\n let clientSequenceNumber: number = -1;\n const length = batch.content.length;\n\n // Did we disconnect in the middle of turn-based batch?\n // If so, do nothing, as pending state manager will resubmit it correctly on reconnect.\n if (length === 0 || !this.params.shouldSend()) {\n return clientSequenceNumber;\n }\n\n if (this.params.containerContext.submitBatchFn === undefined) {\n // Legacy path - supporting old loader versions. Can be removed only when LTS moves above\n // version that has support for batches (submitBatchFn)\n for (const message of batch.content) {\n // Legacy path doesn't support compressed payloads and will submit uncompressed payload anyways\n if (message.metadata?.compressed) {\n delete message.metadata.compressed;\n }\n\n clientSequenceNumber = this.params.containerContext.submitFn(\n MessageType.Operation,\n message.deserializedContent,\n true, // batch\n message.metadata);\n }\n\n this.params.containerContext.deltaManager.flush();\n } else {\n // returns clientSequenceNumber of last message in a batch\n clientSequenceNumber = this.params.containerContext.submitBatchFn(\n batch.content.map((message) => ({\n contents: message.contents,\n metadata: message.metadata,\n compression: message.compression,\n })));\n }\n\n // Convert from clientSequenceNumber of last message in the batch to clientSequenceNumber of first message.\n clientSequenceNumber -= length - 1;\n assert(clientSequenceNumber >= 0, 0x3d0 /* clientSequenceNumber can't be negative */);\n return clientSequenceNumber;\n }\n\n private persistBatch(initialClientSequenceNumber: number, batch: BatchMessage[]) {\n let clientSequenceNumber = initialClientSequenceNumber;\n // Let the PendingStateManager know that a message was submitted.\n // In future, need to shift toward keeping batch as a whole!\n for (const message of batch) {\n this.params.pendingStateManager.onSubmitMessage(\n message.deserializedContent.type,\n clientSequenceNumber,\n message.referenceSequenceNumber,\n message.deserializedContent.contents,\n message.localOpMetadata,\n message.metadata,\n );\n\n clientSequenceNumber++;\n }\n }\n\n public checkpoint() {\n return {\n mainBatch: this.mainBatch.checkpoint(),\n attachFlowBatch: this.attachFlowBatch.checkpoint(),\n };\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/container-runtime";
|
|
8
|
-
export declare const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.3.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export const pkgName = "@fluidframework/container-runtime";
|
|
8
|
-
export const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export const pkgVersion = "2.0.0-internal.3.0.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,mCAAmC,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"2.0.0-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,mCAAmC,CAAC;AAC3D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"2.0.0-internal.3.0.0\";\n"]}
|
|
@@ -22,6 +22,7 @@ export interface IPendingMessage {
|
|
|
22
22
|
/**
|
|
23
23
|
* This represents an explicit flush call and is added to the pending queue when flush is called on the ContainerRuntime
|
|
24
24
|
* to flush pending messages.
|
|
25
|
+
* @deprecated Use batch metadata on IPendingMessage instead. To be removed in 2.0.0-internal.4.0.0 (AB#2496)
|
|
25
26
|
*/
|
|
26
27
|
export interface IPendingFlush {
|
|
27
28
|
type: "flush";
|
|
@@ -38,7 +39,6 @@ export interface IRuntimeStateHandler {
|
|
|
38
39
|
clientId(): string | undefined;
|
|
39
40
|
close(error?: ICriticalContainerError): void;
|
|
40
41
|
applyStashedOp: (type: ContainerMessageType, content: ISequencedDocumentMessage) => Promise<unknown>;
|
|
41
|
-
flush(): void;
|
|
42
42
|
reSubmit(type: ContainerMessageType, content: any, localOpMetadata: unknown, opMetadata: Record<string, unknown> | undefined): void;
|
|
43
43
|
rollback(type: ContainerMessageType, content: any, localOpMetadata: unknown): void;
|
|
44
44
|
orderSequentially(callback: () => void): void;
|
|
@@ -54,16 +54,15 @@ export interface IRuntimeStateHandler {
|
|
|
54
54
|
*/
|
|
55
55
|
export declare class PendingStateManager implements IDisposable {
|
|
56
56
|
private readonly stateHandler;
|
|
57
|
-
private readonly
|
|
58
|
-
private readonly
|
|
57
|
+
private readonly pendingMessages;
|
|
58
|
+
private readonly initialMessages;
|
|
59
59
|
private readonly disposeOnce;
|
|
60
|
-
private _pendingMessagesCount;
|
|
61
60
|
get pendingMessagesCount(): number;
|
|
62
61
|
private isProcessingBatch;
|
|
63
62
|
private pendingBatchBeginMessage;
|
|
64
63
|
private clientId;
|
|
65
64
|
/**
|
|
66
|
-
* Called to check if there are any pending messages in the pending
|
|
65
|
+
* Called to check if there are any pending messages in the pending message queue.
|
|
67
66
|
* @returns A boolean indicating whether there are messages or not.
|
|
68
67
|
*/
|
|
69
68
|
hasPendingMessages(): boolean;
|
|
@@ -80,10 +79,6 @@ export declare class PendingStateManager implements IDisposable {
|
|
|
80
79
|
* @param localOpMetadata - The local metadata associated with the message.
|
|
81
80
|
*/
|
|
82
81
|
onSubmitMessage(type: ContainerMessageType, clientSequenceNumber: number, referenceSequenceNumber: number, content: any, localOpMetadata: unknown, opMetadata: Record<string, unknown> | undefined): void;
|
|
83
|
-
/**
|
|
84
|
-
* Called when flush() is called on the ContainerRuntime to manually flush messages.
|
|
85
|
-
*/
|
|
86
|
-
onFlush(): void;
|
|
87
82
|
/**
|
|
88
83
|
* Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted
|
|
89
84
|
* @param seqNum - Sequence number at which to apply ops. Will apply all ops if seqNum is undefined.
|
|
@@ -105,10 +100,6 @@ export declare class PendingStateManager implements IDisposable {
|
|
|
105
100
|
* @param message - The message that is being processed.
|
|
106
101
|
*/
|
|
107
102
|
private maybeProcessBatchEnd;
|
|
108
|
-
/**
|
|
109
|
-
* Returns the next pending state from the pending state queue.
|
|
110
|
-
*/
|
|
111
|
-
private peekNextPendingState;
|
|
112
103
|
/**
|
|
113
104
|
* Called when the Container's connection state changes. If the Container gets connected, it replays all the pending
|
|
114
105
|
* states in its queue. This includes triggering resubmission of unacked ops.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pendingStateManager.d.ts","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,OAAO,EACH,yBAAyB,EAC5B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAG1D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC5B,IAAI,E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,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;IAenD;;;OAGG;IACU,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM;IAyB9C;;;;OAIG;IACI,0BAA0B,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO;IA8B9E;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAa9B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA2C5B;;;OAGG;IACI,mBAAmB;CA6D7B"}
|
|
@@ -17,38 +17,74 @@ import { pkgVersion } from "./packageVersion";
|
|
|
17
17
|
*/
|
|
18
18
|
export class PendingStateManager {
|
|
19
19
|
constructor(stateHandler, initialLocalState) {
|
|
20
|
-
var _a;
|
|
20
|
+
var _a, _b;
|
|
21
21
|
this.stateHandler = stateHandler;
|
|
22
|
-
this.
|
|
22
|
+
this.pendingMessages = new Deque();
|
|
23
|
+
this.initialMessages = new Deque();
|
|
23
24
|
this.disposeOnce = new Lazy(() => {
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
25
|
+
this.initialMessages.clear();
|
|
26
|
+
this.pendingMessages.clear();
|
|
26
27
|
});
|
|
27
|
-
// Maintains the count of messages that are currently unacked.
|
|
28
|
-
this._pendingMessagesCount = 0;
|
|
29
28
|
// Indicates whether we are processing a batch.
|
|
30
29
|
this.isProcessingBatch = false;
|
|
31
30
|
this.dispose = () => this.disposeOnce.value;
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Convert old local state format to the new format
|
|
33
|
+
* The old format contained "flush" messages as the indicator of batch ends
|
|
34
|
+
* The new format instead uses batch metadata on the last message to indicate batch ends
|
|
35
|
+
* ! TODO: Remove this conversion in "2.0.0-internal.4.0.0" as rollback from future version will be new format
|
|
36
|
+
* AB#2496 tracks removal
|
|
37
|
+
*/
|
|
38
|
+
if (initialLocalState === null || initialLocalState === void 0 ? void 0 : initialLocalState.pendingStates) {
|
|
39
|
+
const pendingStates = initialLocalState === null || initialLocalState === void 0 ? void 0 : initialLocalState.pendingStates;
|
|
40
|
+
let currentlyBatching = false;
|
|
41
|
+
for (let i = 0; i < pendingStates.length; i++) {
|
|
42
|
+
const initialState = pendingStates[i];
|
|
43
|
+
// Skip over "flush" messages
|
|
44
|
+
if (initialState.type === "message") {
|
|
45
|
+
if ((_a = initialState.opMetadata) === null || _a === void 0 ? void 0 : _a.batch) {
|
|
46
|
+
currentlyBatching = true;
|
|
47
|
+
}
|
|
48
|
+
else if (((_b = initialState.opMetadata) === null || _b === void 0 ? void 0 : _b.batch) === false) {
|
|
49
|
+
currentlyBatching = false;
|
|
50
|
+
}
|
|
51
|
+
else if (
|
|
52
|
+
// End of batch if we are currently batching and this is last message or next message is flush
|
|
53
|
+
currentlyBatching
|
|
54
|
+
&& (i === pendingStates.length - 1 || pendingStates[i + 1].type === "flush")) {
|
|
55
|
+
currentlyBatching = false;
|
|
56
|
+
initialState.opMetadata = Object.assign(Object.assign({}, initialState.opMetadata), { batch: false });
|
|
57
|
+
}
|
|
58
|
+
this.initialMessages.push(initialState);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
33
62
|
}
|
|
34
63
|
get pendingMessagesCount() {
|
|
35
|
-
return this.
|
|
64
|
+
return this.pendingMessages.length;
|
|
36
65
|
}
|
|
37
66
|
/**
|
|
38
|
-
* Called to check if there are any pending messages in the pending
|
|
67
|
+
* Called to check if there are any pending messages in the pending message queue.
|
|
39
68
|
* @returns A boolean indicating whether there are messages or not.
|
|
40
69
|
*/
|
|
41
70
|
hasPendingMessages() {
|
|
42
|
-
return this.
|
|
71
|
+
return !this.pendingMessages.isEmpty() || !this.initialMessages.isEmpty();
|
|
43
72
|
}
|
|
44
73
|
getLocalState() {
|
|
45
|
-
assert(this.
|
|
46
|
-
if (this.
|
|
74
|
+
assert(this.initialMessages.isEmpty(), 0x2e9 /* "Must call getLocalState() after applying initial states" */);
|
|
75
|
+
if (!this.pendingMessages.isEmpty()) {
|
|
47
76
|
return {
|
|
48
|
-
pendingStates: this.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
77
|
+
pendingStates: this.pendingMessages.toArray().reduce((arr, message) => {
|
|
78
|
+
var _a;
|
|
79
|
+
// delete localOpMetadata since it may not be serializable
|
|
80
|
+
// and will be regenerated by applyStashedOp()
|
|
81
|
+
arr.push(Object.assign(Object.assign({}, message), { localOpMetadata: undefined }));
|
|
82
|
+
// TODO: Remove in 2.0.0-internal.4.0.0 (AB#2496)
|
|
83
|
+
if (((_a = message.opMetadata) === null || _a === void 0 ? void 0 : _a.batch) === false) {
|
|
84
|
+
arr.push({ type: "flush" });
|
|
85
|
+
}
|
|
86
|
+
return arr;
|
|
87
|
+
}, new Array()),
|
|
52
88
|
};
|
|
53
89
|
}
|
|
54
90
|
}
|
|
@@ -71,20 +107,7 @@ export class PendingStateManager {
|
|
|
71
107
|
localOpMetadata,
|
|
72
108
|
opMetadata,
|
|
73
109
|
};
|
|
74
|
-
this.
|
|
75
|
-
this._pendingMessagesCount++;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Called when flush() is called on the ContainerRuntime to manually flush messages.
|
|
79
|
-
*/
|
|
80
|
-
onFlush() {
|
|
81
|
-
// If the previous state is not a message, flush is a no-op.
|
|
82
|
-
const previousState = this.pendingStates.peekBack();
|
|
83
|
-
if ((previousState === null || previousState === void 0 ? void 0 : previousState.type) !== "message") {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// An explicit flush is interesting and is tracked only if there are messages sent in TurnBased mode.
|
|
87
|
-
this.pendingStates.push({ type: "flush" });
|
|
110
|
+
this.pendingMessages.push(pendingMessage);
|
|
88
111
|
}
|
|
89
112
|
/**
|
|
90
113
|
* Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted
|
|
@@ -92,29 +115,23 @@ export class PendingStateManager {
|
|
|
92
115
|
*/
|
|
93
116
|
async applyStashedOpsAt(seqNum) {
|
|
94
117
|
// apply stashed ops at sequence number
|
|
95
|
-
while (!this.
|
|
118
|
+
while (!this.initialMessages.isEmpty()) {
|
|
96
119
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
throw new Error("loaded from snapshot too recent to apply stashed ops");
|
|
105
|
-
}
|
|
120
|
+
const nextMessage = this.initialMessages.peekFront();
|
|
121
|
+
if (seqNum !== undefined) {
|
|
122
|
+
if (nextMessage.referenceSequenceNumber > seqNum) {
|
|
123
|
+
break; // nothing left to do at this sequence number
|
|
124
|
+
}
|
|
125
|
+
if (nextMessage.referenceSequenceNumber < seqNum) {
|
|
126
|
+
throw new Error("loaded from snapshot too recent to apply stashed ops");
|
|
106
127
|
}
|
|
107
|
-
// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it
|
|
108
|
-
const localOpMetadata = await this.stateHandler.applyStashedOp(nextState.messageType, nextState.content);
|
|
109
|
-
nextState.localOpMetadata = localOpMetadata;
|
|
110
128
|
}
|
|
111
|
-
//
|
|
129
|
+
// applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it
|
|
130
|
+
const localOpMetadata = await this.stateHandler.applyStashedOp(nextMessage.messageType, nextMessage.content);
|
|
131
|
+
nextMessage.localOpMetadata = localOpMetadata;
|
|
132
|
+
// then we push onto pendingMessages which will cause PendingStateManager to resubmit when we connect
|
|
112
133
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
113
|
-
|
|
114
|
-
this.pendingStates.push(firstPendingState);
|
|
115
|
-
if (firstPendingState.type === "message") {
|
|
116
|
-
this._pendingMessagesCount++;
|
|
117
|
-
}
|
|
134
|
+
this.pendingMessages.push(this.initialMessages.shift());
|
|
118
135
|
}
|
|
119
136
|
}
|
|
120
137
|
/**
|
|
@@ -125,23 +142,21 @@ export class PendingStateManager {
|
|
|
125
142
|
processPendingLocalMessage(message) {
|
|
126
143
|
// Pre-processing part - This may be the start of a batch.
|
|
127
144
|
this.maybeProcessBatchBegin(message);
|
|
128
|
-
// Get the next
|
|
129
|
-
const
|
|
130
|
-
assert(
|
|
131
|
-
this.
|
|
145
|
+
// Get the next message from the pending queue. Verify a message exists.
|
|
146
|
+
const pendingMessage = this.pendingMessages.peekFront();
|
|
147
|
+
assert(pendingMessage !== undefined, 0x169 /* "No pending message found for this remote message" */);
|
|
148
|
+
this.pendingMessages.shift();
|
|
132
149
|
// Processing part - Verify that there has been no data corruption.
|
|
133
150
|
// The clientSequenceNumber of the incoming message must match that of the pending message.
|
|
134
|
-
if (
|
|
151
|
+
if (pendingMessage.clientSequenceNumber !== message.clientSequenceNumber) {
|
|
135
152
|
// Close the container because this could indicate data corruption.
|
|
136
|
-
const error = DataProcessingError.create("pending local message clientSequenceNumber mismatch", "unexpectedAckReceived", message, { expectedClientSequenceNumber:
|
|
153
|
+
const error = DataProcessingError.create("pending local message clientSequenceNumber mismatch", "unexpectedAckReceived", message, { expectedClientSequenceNumber: pendingMessage.clientSequenceNumber });
|
|
137
154
|
this.stateHandler.close(error);
|
|
138
155
|
return;
|
|
139
156
|
}
|
|
140
|
-
this._pendingMessagesCount--;
|
|
141
|
-
assert(this._pendingMessagesCount >= 0, 0x3d6 /* positive */);
|
|
142
157
|
// Post-processing part - If we are processing a batch then this could be the last message in the batch.
|
|
143
158
|
this.maybeProcessBatchEnd(message);
|
|
144
|
-
return
|
|
159
|
+
return pendingMessage.localOpMetadata;
|
|
145
160
|
}
|
|
146
161
|
/**
|
|
147
162
|
* This message could be the first message in batch. If so, set batch state marking the beginning of a batch.
|
|
@@ -149,20 +164,6 @@ export class PendingStateManager {
|
|
|
149
164
|
*/
|
|
150
165
|
maybeProcessBatchBegin(message) {
|
|
151
166
|
var _a;
|
|
152
|
-
/**
|
|
153
|
-
* We are checking if the next message is the start of a batch. It can happen in the following scenarios:
|
|
154
|
-
*
|
|
155
|
-
* 1. The FlushMode was set to TurnBased before this message was sent.
|
|
156
|
-
*
|
|
157
|
-
* 2. The FlushMode was already TurnBased and a flush was called before this message was sent. This essentially
|
|
158
|
-
* means that the flush marked the end of a previous batch and beginning of a new batch.
|
|
159
|
-
*
|
|
160
|
-
* Keep reading pending states from the queue until we encounter a message. It's possible that the FlushMode was
|
|
161
|
-
* updated a bunch of times without sending any messages.
|
|
162
|
-
*/
|
|
163
|
-
while (this.peekNextPendingState().type !== "message") {
|
|
164
|
-
this.pendingStates.shift();
|
|
165
|
-
}
|
|
166
167
|
// This message is the first in a batch if the "batch" property on the metadata is set to true
|
|
167
168
|
if ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.batch) {
|
|
168
169
|
// We should not already be processing a batch and there should be no pending batch begin message.
|
|
@@ -181,48 +182,36 @@ export class PendingStateManager {
|
|
|
181
182
|
if (!this.isProcessingBatch) {
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
184
|
-
const nextPendingState = this.peekNextPendingState();
|
|
185
|
-
if (nextPendingState.type === "message") {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
185
|
// There should be a pending batch begin message.
|
|
189
186
|
assert(this.pendingBatchBeginMessage !== undefined, 0x16d /* "There is no pending batch begin message" */);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
187
|
+
const batchEndMetadata = (_a = message.metadata) === null || _a === void 0 ? void 0 : _a.batch;
|
|
188
|
+
if (this.pendingMessages.isEmpty() || batchEndMetadata === false) {
|
|
189
|
+
// Get the batch begin metadata from the first message in the batch.
|
|
190
|
+
const batchBeginMetadata = (_b = this.pendingBatchBeginMessage.metadata) === null || _b === void 0 ? void 0 : _b.batch;
|
|
191
|
+
// There could be just a single message in the batch. If so, it should not have any batch metadata. If there
|
|
192
|
+
// are multiple messages in the batch, verify that we got the correct batch begin and end metadata.
|
|
193
|
+
if (this.pendingBatchBeginMessage === message) {
|
|
194
|
+
assert(batchBeginMetadata === undefined, 0x16e /* "Batch with single message should not have batch metadata" */);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
if (batchBeginMetadata !== true || batchEndMetadata !== false) {
|
|
198
|
+
this.stateHandler.close(DataProcessingError.create("Pending batch inconsistency", // Formerly known as asserts 0x16f and 0x170
|
|
199
|
+
"processPendingLocalMessage", message, {
|
|
200
|
+
runtimeVersion: pkgVersion,
|
|
201
|
+
batchClientId: this.pendingBatchBeginMessage.clientId,
|
|
202
|
+
clientId: this.stateHandler.clientId(),
|
|
203
|
+
hasBatchStart: batchBeginMetadata === true,
|
|
204
|
+
hasBatchEnd: batchEndMetadata === false,
|
|
205
|
+
messageType: message.type,
|
|
206
|
+
batchStartSequenceNumber: this.pendingBatchBeginMessage.clientSequenceNumber,
|
|
207
|
+
pendingMessagesCount: this.pendingMessagesCount,
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
213
210
|
}
|
|
211
|
+
// Clear the pending batch state now that we have processed the entire batch.
|
|
212
|
+
this.pendingBatchBeginMessage = undefined;
|
|
213
|
+
this.isProcessingBatch = false;
|
|
214
214
|
}
|
|
215
|
-
// Clear the pending batch state now that we have processed the entire batch.
|
|
216
|
-
this.pendingBatchBeginMessage = undefined;
|
|
217
|
-
this.isProcessingBatch = false;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Returns the next pending state from the pending state queue.
|
|
221
|
-
*/
|
|
222
|
-
peekNextPendingState() {
|
|
223
|
-
const nextPendingState = this.pendingStates.peekFront();
|
|
224
|
-
assert(!!nextPendingState, 0x171 /* "No pending state found for the remote message" */);
|
|
225
|
-
return nextPendingState;
|
|
226
215
|
}
|
|
227
216
|
/**
|
|
228
217
|
* Called when the Container's connection state changes. If the Container gets connected, it replays all the pending
|
|
@@ -234,63 +223,44 @@ export class PendingStateManager {
|
|
|
234
223
|
// This assert suggests we are about to send same ops twice, which will result in data loss.
|
|
235
224
|
assert(this.clientId !== this.stateHandler.clientId(), 0x173 /* "replayPendingStates called twice for same clientId!" */);
|
|
236
225
|
this.clientId = this.stateHandler.clientId();
|
|
237
|
-
assert(this.
|
|
238
|
-
let
|
|
239
|
-
if (
|
|
226
|
+
assert(this.initialMessages.isEmpty(), 0x174 /* "initial states should be empty before replaying pending" */);
|
|
227
|
+
let pendingMessagesCount = this.pendingMessages.length;
|
|
228
|
+
if (pendingMessagesCount === 0) {
|
|
240
229
|
return;
|
|
241
230
|
}
|
|
242
|
-
//
|
|
243
|
-
this._pendingMessagesCount = 0;
|
|
244
|
-
const messageBatchQueue = new Deque();
|
|
245
|
-
// Process exactly `pendingStatesCount` items in the queue as it represents the number of states that were
|
|
231
|
+
// Process exactly `pendingMessagesCount` items in the queue as it represents the number of messages that were
|
|
246
232
|
// pending when we connected. This is important because the `reSubmitFn` might add more items in the queue
|
|
247
233
|
// which must not be replayed.
|
|
248
|
-
while (
|
|
234
|
+
while (pendingMessagesCount > 0) {
|
|
249
235
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
this.stateHandler.reSubmit(
|
|
236
|
+
let pendingMessage = this.pendingMessages.shift();
|
|
237
|
+
pendingMessagesCount--;
|
|
238
|
+
assert(((_a = pendingMessage.opMetadata) === null || _a === void 0 ? void 0 : _a.batch) !== false, 0x41b /* We cannot process batches in chunks */);
|
|
239
|
+
/**
|
|
240
|
+
* We want to ensure grouped messages get processed in a batch.
|
|
241
|
+
* Note: It is not possible for the PendingStateManager to receive a partially acked batch. It will
|
|
242
|
+
* either receive the whole batch ack or nothing at all.
|
|
243
|
+
*/
|
|
244
|
+
if ((_b = pendingMessage.opMetadata) === null || _b === void 0 ? void 0 : _b.batch) {
|
|
245
|
+
assert(pendingMessagesCount > 0, 0x554 /* Last pending message cannot be a batch begin */);
|
|
246
|
+
this.stateHandler.orderSequentially(() => {
|
|
247
|
+
var _a, _b;
|
|
248
|
+
while (pendingMessagesCount >= 0) { // check is >= because batch end may be last pending message
|
|
249
|
+
this.stateHandler.reSubmit(pendingMessage.messageType, pendingMessage.content, pendingMessage.localOpMetadata, pendingMessage.opMetadata);
|
|
250
|
+
if (((_a = pendingMessage.opMetadata) === null || _a === void 0 ? void 0 : _a.batch) === false) {
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
assert(pendingMessagesCount > 0, 0x555 /* No batch end found */);
|
|
254
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
255
|
+
pendingMessage = this.pendingMessages.shift();
|
|
256
|
+
pendingMessagesCount--;
|
|
257
|
+
assert(((_b = pendingMessage.opMetadata) === null || _b === void 0 ? void 0 : _b.batch) !== true, 0x556 /* Batch start needs a corresponding batch end */);
|
|
264
258
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
* We can't rely on the "batch" property in the message metadata as it gets
|
|
270
|
-
* updated elsewhere and it is not the same object instance that gets updated.
|
|
271
|
-
*/
|
|
272
|
-
if (messageBatchQueue.length > 0) {
|
|
273
|
-
this.stateHandler.orderSequentially(() => {
|
|
274
|
-
while (messageBatchQueue.length > 0) {
|
|
275
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
276
|
-
const message = messageBatchQueue.dequeue();
|
|
277
|
-
this.stateHandler.reSubmit(message.messageType, message.content, message.localOpMetadata, message.opMetadata);
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
assert(messageBatchQueue.length === 0, 0x41c /* cannot flush in the middle of a batch */);
|
|
282
|
-
this.stateHandler.flush();
|
|
283
|
-
break;
|
|
284
|
-
default:
|
|
285
|
-
break;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
this.stateHandler.reSubmit(pendingMessage.messageType, pendingMessage.content, pendingMessage.localOpMetadata, pendingMessage.opMetadata);
|
|
286
263
|
}
|
|
287
|
-
pendingStatesCount--;
|
|
288
|
-
}
|
|
289
|
-
// There are some cases where ops are stashed but not flushed. We need to ensure they are resubmitted
|
|
290
|
-
while (messageBatchQueue.length > 0) {
|
|
291
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
292
|
-
const message = messageBatchQueue.dequeue();
|
|
293
|
-
this.stateHandler.reSubmit(message.messageType, message.content, message.localOpMetadata, message.opMetadata);
|
|
294
264
|
}
|
|
295
265
|
}
|
|
296
266
|
}
|