@fluidframework/container-runtime 2.0.0-dev.1.4.6.106135 → 2.0.0-dev.2.3.0.115467
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -1
- package/dist/blobManager.d.ts +20 -5
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +57 -15
- package/dist/blobManager.js.map +1 -1
- package/dist/containerRuntime.d.ts +88 -51
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +205 -300
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStore.d.ts.map +1 -1
- package/dist/dataStore.js +6 -0
- package/dist/dataStore.js.map +1 -1
- package/dist/dataStoreContext.d.ts +14 -21
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +71 -57
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStoreContexts.js +1 -1
- package/dist/dataStoreContexts.js.map +1 -1
- package/dist/dataStores.d.ts +11 -10
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +51 -20
- package/dist/dataStores.js.map +1 -1
- package/dist/garbageCollection.d.ts +40 -32
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +227 -161
- package/dist/garbageCollection.js.map +1 -1
- package/dist/garbageCollectionConstants.d.ts +19 -0
- package/dist/garbageCollectionConstants.d.ts.map +1 -0
- package/dist/garbageCollectionConstants.js +34 -0
- package/dist/garbageCollectionConstants.js.map +1 -0
- package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/dist/gcSweepReadyUsageDetection.js +5 -14
- package/dist/gcSweepReadyUsageDetection.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/dist/opLifecycle/batchManager.d.ts +30 -0
- package/dist/opLifecycle/batchManager.d.ts.map +1 -0
- package/dist/{batchManager.js → opLifecycle/batchManager.js} +25 -15
- package/dist/opLifecycle/batchManager.js.map +1 -0
- package/dist/opLifecycle/definitions.d.ts +40 -0
- package/dist/opLifecycle/definitions.d.ts.map +1 -0
- package/dist/opLifecycle/definitions.js +7 -0
- package/dist/opLifecycle/definitions.js.map +1 -0
- package/dist/opLifecycle/index.d.ts +12 -0
- package/dist/opLifecycle/index.d.ts.map +1 -0
- package/dist/opLifecycle/index.js +21 -0
- package/dist/opLifecycle/index.js.map +1 -0
- package/dist/opLifecycle/opCompressor.d.ts +18 -0
- package/dist/opLifecycle/opCompressor.d.ts.map +1 -0
- package/dist/opLifecycle/opCompressor.js +53 -0
- package/dist/opLifecycle/opCompressor.js.map +1 -0
- package/dist/opLifecycle/opDecompressor.d.ts +20 -0
- package/dist/opLifecycle/opDecompressor.d.ts.map +1 -0
- package/dist/opLifecycle/opDecompressor.js +72 -0
- package/dist/opLifecycle/opDecompressor.js.map +1 -0
- package/dist/opLifecycle/opSplitter.d.ts +17 -0
- package/dist/opLifecycle/opSplitter.d.ts.map +1 -0
- package/dist/opLifecycle/opSplitter.js +61 -0
- package/dist/opLifecycle/opSplitter.js.map +1 -0
- package/dist/opLifecycle/outbox.d.ts +47 -0
- package/dist/opLifecycle/outbox.d.ts.map +1 -0
- package/dist/opLifecycle/outbox.js +153 -0
- package/dist/opLifecycle/outbox.js.map +1 -0
- package/dist/opLifecycle/remoteMessageProcessor.d.ts +26 -0
- package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
- package/dist/opLifecycle/remoteMessageProcessor.js +81 -0
- package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -0
- 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 +6 -26
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +42 -62
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/runningSummarizer.d.ts +3 -2
- package/dist/runningSummarizer.d.ts.map +1 -1
- package/dist/runningSummarizer.js +10 -3
- package/dist/runningSummarizer.js.map +1 -1
- package/dist/scheduleManager.js.map +1 -1
- package/dist/summarizer.js +7 -2
- package/dist/summarizer.js.map +1 -1
- package/dist/summarizerClientElection.js +1 -1
- package/dist/summarizerClientElection.js.map +1 -1
- package/dist/summarizerHeuristics.d.ts.map +1 -1
- package/dist/summarizerHeuristics.js +0 -3
- package/dist/summarizerHeuristics.js.map +1 -1
- package/dist/summarizerTypes.d.ts +19 -2
- package/dist/summarizerTypes.d.ts.map +1 -1
- package/dist/summarizerTypes.js.map +1 -1
- package/dist/summaryFormat.d.ts +4 -2
- package/dist/summaryFormat.d.ts.map +1 -1
- package/dist/summaryFormat.js +2 -2
- package/dist/summaryFormat.js.map +1 -1
- package/dist/summaryGenerator.d.ts.map +1 -1
- package/dist/summaryGenerator.js +3 -2
- package/dist/summaryGenerator.js.map +1 -1
- package/dist/summaryManager.d.ts.map +1 -1
- package/dist/summaryManager.js +10 -6
- package/dist/summaryManager.js.map +1 -1
- package/garbageCollection.md +27 -22
- package/lib/blobManager.d.ts +20 -5
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +59 -17
- package/lib/blobManager.js.map +1 -1
- package/lib/containerRuntime.d.ts +88 -51
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +203 -297
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStore.d.ts.map +1 -1
- package/lib/dataStore.js +6 -0
- package/lib/dataStore.js.map +1 -1
- package/lib/dataStoreContext.d.ts +14 -21
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +75 -61
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStoreContexts.js +1 -1
- package/lib/dataStoreContexts.js.map +1 -1
- package/lib/dataStores.d.ts +11 -10
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +53 -22
- package/lib/dataStores.js.map +1 -1
- package/lib/garbageCollection.d.ts +40 -32
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +220 -154
- package/lib/garbageCollection.js.map +1 -1
- package/lib/garbageCollectionConstants.d.ts +19 -0
- package/lib/garbageCollectionConstants.d.ts.map +1 -0
- package/lib/garbageCollectionConstants.js +31 -0
- package/lib/garbageCollectionConstants.js.map +1 -0
- package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/lib/gcSweepReadyUsageDetection.js +4 -13
- package/lib/gcSweepReadyUsageDetection.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -4
- package/lib/index.js.map +1 -1
- package/lib/opLifecycle/batchManager.d.ts +30 -0
- package/lib/opLifecycle/batchManager.d.ts.map +1 -0
- package/lib/{batchManager.js → opLifecycle/batchManager.js} +25 -15
- package/lib/opLifecycle/batchManager.js.map +1 -0
- package/lib/opLifecycle/definitions.d.ts +40 -0
- package/lib/opLifecycle/definitions.d.ts.map +1 -0
- package/lib/opLifecycle/definitions.js +6 -0
- package/lib/opLifecycle/definitions.js.map +1 -0
- package/lib/opLifecycle/index.d.ts +12 -0
- package/lib/opLifecycle/index.d.ts.map +1 -0
- package/lib/opLifecycle/index.js +11 -0
- package/lib/opLifecycle/index.js.map +1 -0
- package/lib/opLifecycle/opCompressor.d.ts +18 -0
- package/lib/opLifecycle/opCompressor.d.ts.map +1 -0
- package/lib/opLifecycle/opCompressor.js +49 -0
- package/lib/opLifecycle/opCompressor.js.map +1 -0
- package/lib/opLifecycle/opDecompressor.d.ts +20 -0
- package/lib/opLifecycle/opDecompressor.d.ts.map +1 -0
- package/lib/opLifecycle/opDecompressor.js +68 -0
- package/lib/opLifecycle/opDecompressor.js.map +1 -0
- package/lib/opLifecycle/opSplitter.d.ts +17 -0
- package/lib/opLifecycle/opSplitter.d.ts.map +1 -0
- package/lib/opLifecycle/opSplitter.js +57 -0
- package/lib/opLifecycle/opSplitter.js.map +1 -0
- package/lib/opLifecycle/outbox.d.ts +47 -0
- package/lib/opLifecycle/outbox.d.ts.map +1 -0
- package/lib/opLifecycle/outbox.js +149 -0
- package/lib/opLifecycle/outbox.js.map +1 -0
- package/lib/opLifecycle/remoteMessageProcessor.d.ts +26 -0
- package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
- package/lib/opLifecycle/remoteMessageProcessor.js +76 -0
- package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -0
- 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 +6 -26
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +42 -62
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/runningSummarizer.d.ts +3 -2
- package/lib/runningSummarizer.d.ts.map +1 -1
- package/lib/runningSummarizer.js +10 -3
- package/lib/runningSummarizer.js.map +1 -1
- package/lib/scheduleManager.js.map +1 -1
- package/lib/summarizer.js +7 -2
- package/lib/summarizer.js.map +1 -1
- package/lib/summarizerClientElection.js +1 -1
- package/lib/summarizerClientElection.js.map +1 -1
- package/lib/summarizerHeuristics.d.ts.map +1 -1
- package/lib/summarizerHeuristics.js +0 -3
- package/lib/summarizerHeuristics.js.map +1 -1
- package/lib/summarizerTypes.d.ts +19 -2
- package/lib/summarizerTypes.d.ts.map +1 -1
- package/lib/summarizerTypes.js.map +1 -1
- package/lib/summaryFormat.d.ts +4 -2
- package/lib/summaryFormat.d.ts.map +1 -1
- package/lib/summaryFormat.js +1 -1
- package/lib/summaryFormat.js.map +1 -1
- package/lib/summaryGenerator.d.ts.map +1 -1
- package/lib/summaryGenerator.js +3 -2
- package/lib/summaryGenerator.js.map +1 -1
- package/lib/summaryManager.d.ts.map +1 -1
- package/lib/summaryManager.js +10 -6
- package/lib/summaryManager.js.map +1 -1
- package/package.json +32 -71
- package/prettier.config.cjs +8 -0
- package/src/blobManager.ts +74 -19
- package/src/containerRuntime.ts +286 -369
- package/src/dataStore.ts +13 -1
- package/src/dataStoreContext.ts +100 -76
- package/src/dataStoreContexts.ts +1 -1
- package/src/dataStores.ts +61 -22
- package/src/garbageCollection.ts +282 -163
- package/src/garbageCollectionConstants.ts +35 -0
- package/src/gcSweepReadyUsageDetection.ts +3 -11
- package/src/index.ts +9 -8
- package/src/{batchManager.ts → opLifecycle/batchManager.ts} +42 -28
- package/src/opLifecycle/definitions.ts +44 -0
- package/src/opLifecycle/index.ts +17 -0
- package/src/opLifecycle/opCompressor.ts +64 -0
- package/src/opLifecycle/opDecompressor.ts +84 -0
- package/src/opLifecycle/opSplitter.ts +78 -0
- package/src/opLifecycle/outbox.ts +204 -0
- package/src/opLifecycle/remoteMessageProcessor.ts +90 -0
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +57 -96
- package/src/runningSummarizer.ts +11 -3
- package/src/scheduleManager.ts +1 -0
- package/src/summarizer.ts +6 -6
- package/src/summarizerClientElection.ts +1 -1
- package/src/summarizerHeuristics.ts +0 -3
- package/src/summarizerTypes.ts +20 -7
- package/src/summaryFormat.ts +5 -3
- package/src/summaryGenerator.ts +3 -2
- package/src/summaryManager.ts +18 -7
- package/dist/batchManager.d.ts +0 -37
- package/dist/batchManager.d.ts.map +0 -1
- package/dist/batchManager.js.map +0 -1
- package/lib/batchManager.d.ts +0 -37
- package/lib/batchManager.d.ts.map +0 -1
- package/lib/batchManager.js.map +0 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OpDecompressor = void 0;
|
|
8
|
+
const lz4js_1 = require("lz4js");
|
|
9
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
10
|
+
const containerRuntime_1 = require("../containerRuntime");
|
|
11
|
+
/**
|
|
12
|
+
* State machine that "unrolls" contents of compressed batches of ops after decompressing them.
|
|
13
|
+
* This class relies on some implicit contracts defined below:
|
|
14
|
+
* 1. A compressed batch will have its first message with batch metadata set to true and compressed set to true
|
|
15
|
+
* 2. Messages in the middle of a compressed batch will have neither batch metadata nor the compression property set
|
|
16
|
+
* 3. The final message of a batch will have batch metadata set to false
|
|
17
|
+
* 4. An individually compressed op will have undefined batch metadata and compression set to true
|
|
18
|
+
*/
|
|
19
|
+
class OpDecompressor {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.activeBatch = false;
|
|
22
|
+
this.processedCount = 0;
|
|
23
|
+
}
|
|
24
|
+
processMessage(message) {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f;
|
|
26
|
+
// We're checking for compression = true or top level compression property so
|
|
27
|
+
// that we can enable compression without waiting on all ordering services
|
|
28
|
+
// to pick up protocol change. Eventually only the top level property should
|
|
29
|
+
// be used.
|
|
30
|
+
if (((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.batch) === true
|
|
31
|
+
&& (((_b = message.metadata) === null || _b === void 0 ? void 0 : _b.compressed) || message.compression !== undefined)) {
|
|
32
|
+
// Beginning of a compressed batch
|
|
33
|
+
(0, common_utils_1.assert)(this.activeBatch === false, 0x4b8 /* shouldn't have multiple active batches */);
|
|
34
|
+
if (message.compression) {
|
|
35
|
+
// lz4 is the only supported compression algorithm for now
|
|
36
|
+
(0, common_utils_1.assert)(message.compression === containerRuntime_1.CompressionAlgorithms.lz4, 0x4b9 /* lz4 is currently the only supported compression algorithm */);
|
|
37
|
+
}
|
|
38
|
+
this.activeBatch = true;
|
|
39
|
+
const contents = common_utils_1.IsoBuffer.from(message.contents.packedContents, "base64");
|
|
40
|
+
const decompressedMessage = (0, lz4js_1.decompress)(contents);
|
|
41
|
+
const intoString = (0, common_utils_1.Uint8ArrayToString)(decompressedMessage);
|
|
42
|
+
const asObj = JSON.parse(intoString);
|
|
43
|
+
this.rootMessageContents = asObj;
|
|
44
|
+
return Object.assign(Object.assign({}, message), { contents: this.rootMessageContents[this.processedCount++] });
|
|
45
|
+
}
|
|
46
|
+
if (this.rootMessageContents !== undefined && ((_c = message.metadata) === null || _c === void 0 ? void 0 : _c.batch) === undefined && this.activeBatch) {
|
|
47
|
+
// Continuation of compressed batch
|
|
48
|
+
return Object.assign(Object.assign({}, message), { contents: this.rootMessageContents[this.processedCount++] });
|
|
49
|
+
}
|
|
50
|
+
if (this.rootMessageContents !== undefined && ((_d = message.metadata) === null || _d === void 0 ? void 0 : _d.batch) === false) {
|
|
51
|
+
// End of compressed batch
|
|
52
|
+
const returnMessage = Object.assign(Object.assign({}, message), { contents: this.rootMessageContents[this.processedCount++] });
|
|
53
|
+
this.activeBatch = false;
|
|
54
|
+
this.rootMessageContents = undefined;
|
|
55
|
+
this.processedCount = 0;
|
|
56
|
+
return returnMessage;
|
|
57
|
+
}
|
|
58
|
+
if (((_e = message.metadata) === null || _e === void 0 ? void 0 : _e.batch) === undefined &&
|
|
59
|
+
(((_f = message.metadata) === null || _f === void 0 ? void 0 : _f.compressed) || message.compression === containerRuntime_1.CompressionAlgorithms.lz4)) {
|
|
60
|
+
// Single compressed message
|
|
61
|
+
(0, common_utils_1.assert)(this.activeBatch === false, 0x4ba /* shouldn't receive compressed message in middle of a batch */);
|
|
62
|
+
const contents = common_utils_1.IsoBuffer.from(message.contents.packedContents, "base64");
|
|
63
|
+
const decompressedMessage = (0, lz4js_1.decompress)(contents);
|
|
64
|
+
const intoString = new TextDecoder().decode(decompressedMessage);
|
|
65
|
+
const asObj = JSON.parse(intoString);
|
|
66
|
+
return Object.assign(Object.assign({}, message), { contents: asObj[0] });
|
|
67
|
+
}
|
|
68
|
+
return message;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.OpDecompressor = OpDecompressor;
|
|
72
|
+
//# sourceMappingURL=opDecompressor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opDecompressor.js","sourceRoot":"","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mB,CAAC,CAAC;YACjE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAErC,uCAAY,OAAO,KAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,IAAG;SAC7C;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAjED,wCAiEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { decompress } from \"lz4js\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { assert, IsoBuffer, Uint8ArrayToString } from \"@fluidframework/common-utils\";\nimport { CompressionAlgorithms } from \"../containerRuntime\";\n\n/**\n * State machine that \"unrolls\" contents of compressed batches of ops after decompressing them.\n * This class relies on some implicit contracts defined below:\n * 1. A compressed batch will have its first message with batch metadata set to true and compressed set to true\n * 2. Messages in the middle of a compressed batch will have neither batch metadata nor the compression property set\n * 3. The final message of a batch will have batch metadata set to false\n * 4. An individually compressed op will have undefined batch metadata and compression set to true\n */\nexport class OpDecompressor {\n private activeBatch = false;\n private rootMessageContents: any | undefined;\n private processedCount = 0;\n\n public processMessage(message: ISequencedDocumentMessage): ISequencedDocumentMessage {\n // We're checking for compression = true or top level compression property so\n // that we can enable compression without waiting on all ordering services\n // to pick up protocol change. Eventually only the top level property should\n // be used.\n if (message.metadata?.batch === true\n && (message.metadata?.compressed || message.compression !== undefined)) {\n // Beginning of a compressed batch\n assert(this.activeBatch === false, 0x4b8 /* shouldn't have multiple active batches */);\n if (message.compression) {\n // lz4 is the only supported compression algorithm for now\n assert(message.compression === CompressionAlgorithms.lz4,\n 0x4b9 /* lz4 is currently the only supported compression algorithm */);\n }\n\n this.activeBatch = true;\n\n const contents = IsoBuffer.from(message.contents.packedContents, \"base64\");\n const decompressedMessage = decompress(contents);\n const intoString = Uint8ArrayToString(decompressedMessage);\n const asObj = JSON.parse(intoString);\n this.rootMessageContents = asObj;\n\n return { ...message, contents: this.rootMessageContents[this.processedCount++] };\n }\n\n if (this.rootMessageContents !== undefined && message.metadata?.batch === undefined && this.activeBatch) {\n // Continuation of compressed batch\n return { ...message, contents: this.rootMessageContents[this.processedCount++] };\n }\n\n if (this.rootMessageContents !== undefined && message.metadata?.batch === false) {\n // End of compressed batch\n const returnMessage = {\n ...message,\n contents: this.rootMessageContents[this.processedCount++]\n };\n\n this.activeBatch = false;\n this.rootMessageContents = undefined;\n this.processedCount = 0;\n\n return returnMessage;\n }\n\n if (message.metadata?.batch === undefined &&\n (message.metadata?.compressed || message.compression === CompressionAlgorithms.lz4)) {\n // Single compressed message\n assert(this.activeBatch === false, 0x4ba /* shouldn't receive compressed message in middle of a batch */);\n\n const contents = IsoBuffer.from(message.contents.packedContents, \"base64\");\n const decompressedMessage = decompress(contents);\n const intoString = new TextDecoder().decode(decompressedMessage);\n const asObj = JSON.parse(intoString);\n\n return { ...message, contents: asObj[0] };\n }\n\n return message;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
6
|
+
/**
|
|
7
|
+
* Responsible for creating and reconstructing chunked messages.
|
|
8
|
+
*/
|
|
9
|
+
export declare class OpSplitter {
|
|
10
|
+
private readonly chunkMap;
|
|
11
|
+
constructor(chunks: [string, string[]][]);
|
|
12
|
+
get chunks(): ReadonlyMap<string, string[]>;
|
|
13
|
+
processRemoteMessage(message: ISequencedDocumentMessage): ISequencedDocumentMessage;
|
|
14
|
+
clearPartialChunks(clientId: string): void;
|
|
15
|
+
private addChunk;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=opSplitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opSplitter.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/opSplitter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AAIjF;;GAEG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;gBAErC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE;IAIxC,IAAW,MAAM,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAEjD;IAEM,oBAAoB,CAAC,OAAO,EAAE,yBAAyB,GAAG,yBAAyB;IAyBnF,kBAAkB,CAAC,QAAQ,EAAE,MAAM;IAM1C,OAAO,CAAC,QAAQ;CAqBnB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OpSplitter = void 0;
|
|
8
|
+
const container_utils_1 = require("@fluidframework/container-utils");
|
|
9
|
+
const containerRuntime_1 = require("../containerRuntime");
|
|
10
|
+
/**
|
|
11
|
+
* Responsible for creating and reconstructing chunked messages.
|
|
12
|
+
*/
|
|
13
|
+
class OpSplitter {
|
|
14
|
+
constructor(chunks) {
|
|
15
|
+
this.chunkMap = new Map(chunks);
|
|
16
|
+
}
|
|
17
|
+
get chunks() {
|
|
18
|
+
return this.chunkMap;
|
|
19
|
+
}
|
|
20
|
+
processRemoteMessage(message) {
|
|
21
|
+
if (message.type !== containerRuntime_1.ContainerMessageType.ChunkedOp) {
|
|
22
|
+
return message;
|
|
23
|
+
}
|
|
24
|
+
const clientId = message.clientId;
|
|
25
|
+
const chunkedContent = message.contents;
|
|
26
|
+
this.addChunk(clientId, chunkedContent, message);
|
|
27
|
+
if (chunkedContent.chunkId < chunkedContent.totalChunks) {
|
|
28
|
+
// We are processing the op in chunks but haven't reached
|
|
29
|
+
// the last chunk yet in order to reconstruct the original op
|
|
30
|
+
return message;
|
|
31
|
+
}
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
33
|
+
const serializedContent = this.chunkMap.get(clientId).join("");
|
|
34
|
+
this.clearPartialChunks(clientId);
|
|
35
|
+
const newMessage = Object.assign({}, message);
|
|
36
|
+
newMessage.contents = serializedContent === "" ? undefined : JSON.parse(serializedContent);
|
|
37
|
+
newMessage.type = chunkedContent.originalType;
|
|
38
|
+
return newMessage;
|
|
39
|
+
}
|
|
40
|
+
clearPartialChunks(clientId) {
|
|
41
|
+
if (this.chunkMap.has(clientId)) {
|
|
42
|
+
this.chunkMap.delete(clientId);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
addChunk(clientId, chunkedContent, originalMessage) {
|
|
46
|
+
let map = this.chunkMap.get(clientId);
|
|
47
|
+
if (map === undefined) {
|
|
48
|
+
map = [];
|
|
49
|
+
this.chunkMap.set(clientId, map);
|
|
50
|
+
}
|
|
51
|
+
if (chunkedContent.chunkId !== map.length + 1) {
|
|
52
|
+
// We are expecting the chunks to be processed sequentially, in the same order as they are sent.
|
|
53
|
+
// Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)
|
|
54
|
+
// holding the existing chunks for that particular clientId.
|
|
55
|
+
throw new container_utils_1.DataCorruptionError("Chunk Id mismatch", Object.assign(Object.assign({}, (0, container_utils_1.extractSafePropertiesFromMessage)(originalMessage)), { chunkMapLength: map.length, chunkId: chunkedContent.chunkId, totalChunks: chunkedContent.totalChunks }));
|
|
56
|
+
}
|
|
57
|
+
map.push(chunkedContent.contents);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.OpSplitter = OpSplitter;
|
|
61
|
+
//# sourceMappingURL=opSplitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opSplitter.js","sourceRoot":"","sources":["../../src/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AC,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;SAClC;IACL,CAAC;IAEO,QAAQ,CAAC,QAAgB,EAAE,cAA0B,EAAE,eAA0C;QACrG,IAAI,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACtC,IAAI,GAAG,KAAK,SAAS,EAAE;YACnB,GAAG,GAAG,EAAE,CAAC;YACT,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;SACpC;QAED,IAAI,cAAc,CAAC,OAAO,KAAK,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3C,gGAAgG;YAChG,sGAAsG;YACtG,4DAA4D;YAC5D,MAAM,IAAI,qCAAmB,CAAC,mBAAmB,kCAC1C,IAAA,kDAAgC,EAAC,eAAe,CAAC,KACpD,cAAc,EAAE,GAAG,CAAC,MAAM,EAC1B,OAAO,EAAE,cAAc,CAAC,OAAO,EAC/B,WAAW,EAAE,cAAc,CAAC,WAAW,IACzC,CAAC;SACN;QAED,GAAG,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC;CACJ;AAhED,gCAgEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { DataCorruptionError, extractSafePropertiesFromMessage } from \"@fluidframework/container-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ContainerMessageType } from \"../containerRuntime\";\nimport { IChunkedOp } from \"./definitions\";\n\n/**\n * Responsible for creating and reconstructing chunked messages.\n */\nexport class OpSplitter {\n // Local copy of incomplete received chunks.\n private readonly chunkMap: Map<string, string[]>;\n\n constructor(chunks: [string, string[]][]) {\n this.chunkMap = new Map<string, string[]>(chunks);\n }\n\n public get chunks(): ReadonlyMap<string, string[]> {\n return this.chunkMap;\n }\n\n public processRemoteMessage(message: ISequencedDocumentMessage): ISequencedDocumentMessage {\n if (message.type !== ContainerMessageType.ChunkedOp) {\n return message;\n }\n\n const clientId = message.clientId;\n const chunkedContent = message.contents as IChunkedOp;\n this.addChunk(clientId, chunkedContent, message);\n\n if (chunkedContent.chunkId < chunkedContent.totalChunks) {\n // We are processing the op in chunks but haven't reached\n // the last chunk yet in order to reconstruct the original op\n return message;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const serializedContent = this.chunkMap.get(clientId)!.join(\"\");\n this.clearPartialChunks(clientId);\n\n const newMessage = { ...message };\n newMessage.contents = serializedContent === \"\" ? undefined : JSON.parse(serializedContent);\n newMessage.type = chunkedContent.originalType;\n return newMessage;\n }\n\n public clearPartialChunks(clientId: string) {\n if (this.chunkMap.has(clientId)) {\n this.chunkMap.delete(clientId);\n }\n }\n\n private addChunk(clientId: string, chunkedContent: IChunkedOp, originalMessage: ISequencedDocumentMessage) {\n let map = this.chunkMap.get(clientId);\n if (map === undefined) {\n map = [];\n this.chunkMap.set(clientId, map);\n }\n\n if (chunkedContent.chunkId !== map.length + 1) {\n // We are expecting the chunks to be processed sequentially, in the same order as they are sent.\n // Therefore, the chunkId of the incoming op needs to match the length of the array (1-based indexing)\n // holding the existing chunks for that particular clientId.\n throw new DataCorruptionError(\"Chunk Id mismatch\", {\n ...extractSafePropertiesFromMessage(originalMessage),\n chunkMapLength: map.length,\n chunkId: chunkedContent.chunkId,\n totalChunks: chunkedContent.totalChunks,\n });\n }\n\n map.push(chunkedContent.contents);\n }\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { IContainerContext } from "@fluidframework/container-definitions";
|
|
6
|
+
import { ICompressionRuntimeOptions } from "../containerRuntime";
|
|
7
|
+
import { PendingStateManager } from "../pendingStateManager";
|
|
8
|
+
import { BatchMessage } from "./definitions";
|
|
9
|
+
import { OpCompressor } from "./opCompressor";
|
|
10
|
+
export interface IOutboxConfig {
|
|
11
|
+
readonly compressionOptions: ICompressionRuntimeOptions;
|
|
12
|
+
readonly maxBatchSizeInBytes: number;
|
|
13
|
+
}
|
|
14
|
+
export interface IOutboxParameters {
|
|
15
|
+
readonly shouldSend: () => boolean;
|
|
16
|
+
readonly pendingStateManager: PendingStateManager;
|
|
17
|
+
readonly containerContext: IContainerContext;
|
|
18
|
+
readonly config: IOutboxConfig;
|
|
19
|
+
readonly compressor: OpCompressor;
|
|
20
|
+
}
|
|
21
|
+
export declare class Outbox {
|
|
22
|
+
private readonly params;
|
|
23
|
+
private readonly attachFlowBatch;
|
|
24
|
+
private readonly mainBatch;
|
|
25
|
+
private readonly defaultAttachFlowSoftLimitInBytes;
|
|
26
|
+
constructor(params: IOutboxParameters);
|
|
27
|
+
get isEmpty(): boolean;
|
|
28
|
+
submit(message: BatchMessage): void;
|
|
29
|
+
submitAttach(message: BatchMessage): void;
|
|
30
|
+
flush(): void;
|
|
31
|
+
private flushInternal;
|
|
32
|
+
private compressBatch;
|
|
33
|
+
/**
|
|
34
|
+
* Sends the batch object to the container context to be sent over the wire.
|
|
35
|
+
*
|
|
36
|
+
* @param batch - batch to be sent
|
|
37
|
+
* @returns the client sequence number of the last batched op which was sent and
|
|
38
|
+
* -1 if there are no ops or the container cannot send ops.
|
|
39
|
+
*/
|
|
40
|
+
private sendBatch;
|
|
41
|
+
private persistBatch;
|
|
42
|
+
checkpoint(): {
|
|
43
|
+
mainBatch: import("./definitions").IBatchCheckpoint;
|
|
44
|
+
attachFlowBatch: import("./definitions").IBatchCheckpoint;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=outbox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outbox.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":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
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Outbox = void 0;
|
|
8
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
9
|
+
const container_utils_1 = require("@fluidframework/container-utils");
|
|
10
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
11
|
+
const batchManager_1 = require("./batchManager");
|
|
12
|
+
;
|
|
13
|
+
class Outbox {
|
|
14
|
+
constructor(params) {
|
|
15
|
+
this.params = params;
|
|
16
|
+
this.defaultAttachFlowSoftLimitInBytes = 64 * 1024;
|
|
17
|
+
const isCompressionEnabled = this.params.config.compressionOptions.minimumBatchSizeInBytes !== Number.POSITIVE_INFINITY;
|
|
18
|
+
// We need to allow infinite size batches if we enable compression
|
|
19
|
+
const hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;
|
|
20
|
+
const softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;
|
|
21
|
+
this.attachFlowBatch = new batchManager_1.BatchManager({
|
|
22
|
+
hardLimit,
|
|
23
|
+
softLimit,
|
|
24
|
+
});
|
|
25
|
+
this.mainBatch = new batchManager_1.BatchManager({
|
|
26
|
+
hardLimit
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
get isEmpty() {
|
|
30
|
+
return this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;
|
|
31
|
+
}
|
|
32
|
+
submit(message) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
if (!this.mainBatch.push(message)) {
|
|
35
|
+
throw new container_utils_1.GenericError("BatchTooLarge",
|
|
36
|
+
/* error */ undefined, {
|
|
37
|
+
opSize: (_b = ((_a = message.contents) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0,
|
|
38
|
+
count: this.mainBatch.length,
|
|
39
|
+
limit: this.mainBatch.options.hardLimit,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
submitAttach(message) {
|
|
44
|
+
var _a, _b;
|
|
45
|
+
if (!this.attachFlowBatch.push(message)) {
|
|
46
|
+
// BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged
|
|
47
|
+
// when queue is not empty.
|
|
48
|
+
// Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit
|
|
49
|
+
this.flushInternal(this.attachFlowBatch.popBatch());
|
|
50
|
+
if (!this.attachFlowBatch.push(message)) {
|
|
51
|
+
throw new container_utils_1.GenericError("BatchTooLarge",
|
|
52
|
+
/* error */ undefined, {
|
|
53
|
+
opSize: (_b = ((_a = message.contents) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0,
|
|
54
|
+
count: this.attachFlowBatch.length,
|
|
55
|
+
limit: this.attachFlowBatch.options.hardLimit,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// If compression is enabled, we will always successfully receive
|
|
60
|
+
// attach ops and compress then send them at the next JS turn, regardless
|
|
61
|
+
// of the overall size of the accumulated ops in the batch.
|
|
62
|
+
// However, it is more efficient to flush these ops faster, preferably
|
|
63
|
+
// after they reach a size which would benefit from compression.
|
|
64
|
+
if (this.attachFlowBatch.contentSizeInBytes >= this.params.config.compressionOptions.minimumBatchSizeInBytes) {
|
|
65
|
+
this.flushInternal(this.attachFlowBatch.popBatch());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
flush() {
|
|
69
|
+
this.flushInternal(this.attachFlowBatch.popBatch());
|
|
70
|
+
this.flushInternal(this.mainBatch.popBatch());
|
|
71
|
+
}
|
|
72
|
+
flushInternal(rawBatch) {
|
|
73
|
+
const processedBatch = this.compressBatch(rawBatch);
|
|
74
|
+
const clientSequenceNumber = this.sendBatch(processedBatch);
|
|
75
|
+
this.persistBatch(clientSequenceNumber, rawBatch.content);
|
|
76
|
+
}
|
|
77
|
+
compressBatch(batch) {
|
|
78
|
+
if (batch.content.length === 0
|
|
79
|
+
|| this.params.config.compressionOptions === undefined
|
|
80
|
+
|| this.params.config.compressionOptions.minimumBatchSizeInBytes > batch.contentSizeInBytes) {
|
|
81
|
+
// Nothing to do if the batch is empty or if compression is disabled or if we don't need to compress
|
|
82
|
+
return batch;
|
|
83
|
+
}
|
|
84
|
+
const compressedBatch = this.params.compressor.compressBatch(batch);
|
|
85
|
+
if (compressedBatch.contentSizeInBytes > this.params.config.maxBatchSizeInBytes) {
|
|
86
|
+
throw new container_utils_1.GenericError("BatchTooLarge",
|
|
87
|
+
/* error */ undefined, {
|
|
88
|
+
opSize: batch.contentSizeInBytes,
|
|
89
|
+
count: batch.content.length,
|
|
90
|
+
limit: this.params.config.maxBatchSizeInBytes,
|
|
91
|
+
compressed: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// If we don't reach the maximum supported size of a batch, it safe to be sent as is
|
|
95
|
+
return compressedBatch;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Sends the batch object to the container context to be sent over the wire.
|
|
99
|
+
*
|
|
100
|
+
* @param batch - batch to be sent
|
|
101
|
+
* @returns the client sequence number of the last batched op which was sent and
|
|
102
|
+
* -1 if there are no ops or the container cannot send ops.
|
|
103
|
+
*/
|
|
104
|
+
sendBatch(batch) {
|
|
105
|
+
var _a;
|
|
106
|
+
let clientSequenceNumber = -1;
|
|
107
|
+
const length = batch.content.length;
|
|
108
|
+
// Did we disconnect in the middle of turn-based batch?
|
|
109
|
+
// If so, do nothing, as pending state manager will resubmit it correctly on reconnect.
|
|
110
|
+
if (length === 0 || !this.params.shouldSend()) {
|
|
111
|
+
return clientSequenceNumber;
|
|
112
|
+
}
|
|
113
|
+
if (this.params.containerContext.submitBatchFn === undefined) {
|
|
114
|
+
// Legacy path - supporting old loader versions. Can be removed only when LTS moves above
|
|
115
|
+
// version that has support for batches (submitBatchFn)
|
|
116
|
+
for (const message of batch.content) {
|
|
117
|
+
// Legacy path doesn't support compressed payloads and will submit uncompressed payload anyways
|
|
118
|
+
if ((_a = message.metadata) === null || _a === void 0 ? void 0 : _a.compressed) {
|
|
119
|
+
delete message.metadata.compressed;
|
|
120
|
+
}
|
|
121
|
+
clientSequenceNumber = this.params.containerContext.submitFn(protocol_definitions_1.MessageType.Operation, message.deserializedContent, true, // batch
|
|
122
|
+
message.metadata);
|
|
123
|
+
}
|
|
124
|
+
this.params.containerContext.deltaManager.flush();
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// returns clientSequenceNumber of last message in a batch
|
|
128
|
+
clientSequenceNumber = this.params.containerContext.submitBatchFn(batch.content.map((message) => ({ contents: message.contents, metadata: message.metadata })));
|
|
129
|
+
}
|
|
130
|
+
// Convert from clientSequenceNumber of last message in the batch to clientSequenceNumber of first message.
|
|
131
|
+
clientSequenceNumber -= length - 1;
|
|
132
|
+
(0, common_utils_1.assert)(clientSequenceNumber >= 0, 0x3d0 /* clientSequenceNumber can't be negative */);
|
|
133
|
+
return clientSequenceNumber;
|
|
134
|
+
}
|
|
135
|
+
persistBatch(initialClientSequenceNumber, batch) {
|
|
136
|
+
let clientSequenceNumber = initialClientSequenceNumber;
|
|
137
|
+
// Let the PendingStateManager know that a message was submitted.
|
|
138
|
+
// In future, need to shift toward keeping batch as a whole!
|
|
139
|
+
for (const message of batch) {
|
|
140
|
+
this.params.pendingStateManager.onSubmitMessage(message.deserializedContent.type, clientSequenceNumber, message.referenceSequenceNumber, message.deserializedContent.contents, message.localOpMetadata, message.metadata);
|
|
141
|
+
clientSequenceNumber++;
|
|
142
|
+
}
|
|
143
|
+
this.params.pendingStateManager.onFlush();
|
|
144
|
+
}
|
|
145
|
+
checkpoint() {
|
|
146
|
+
return {
|
|
147
|
+
mainBatch: this.mainBatch.checkpoint(),
|
|
148
|
+
attachFlowBatch: this.attachFlowBatch.checkpoint(),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+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,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;AA9KD,wBA8KC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\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\";\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};\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}\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 });\n this.mainBatch = new BatchManager({\n hardLimit\n });\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 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 // If we don't reach the maximum supported size of a batch, it safe to be sent as is\n return compressedBatch;\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) => ({ contents: message.contents, metadata: message.metadata })));\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"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
6
|
+
import { OpDecompressor } from "./opDecompressor";
|
|
7
|
+
import { OpSplitter } from "./opSplitter";
|
|
8
|
+
export declare class RemoteMessageProcessor {
|
|
9
|
+
private readonly opSplitter;
|
|
10
|
+
private readonly opDecompressor;
|
|
11
|
+
constructor(opSplitter: OpSplitter, opDecompressor: OpDecompressor);
|
|
12
|
+
get partialMessages(): ReadonlyMap<string, string[]>;
|
|
13
|
+
clearPartialMessagesFor(clientId: string): void;
|
|
14
|
+
process(remoteMessage: ISequencedDocumentMessage): ISequencedDocumentMessage;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Unpacks runtime messages.
|
|
18
|
+
*
|
|
19
|
+
* @remarks This API makes no promises regarding backward-compatibility. This is internal API.
|
|
20
|
+
* @param message - message (as it observed in storage / service)
|
|
21
|
+
* @returns unpacked runtime message
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function unpackRuntimeMessage(message: ISequencedDocumentMessage): boolean;
|
|
26
|
+
//# sourceMappingURL=remoteMessageProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteMessageProcessor.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,sBAAsB;IAE3B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBADd,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc;IAGnD,IAAW,eAAe,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAE1D;IAEM,uBAAuB,CAAC,QAAQ,EAAE,MAAM;IAIxC,OAAO,CAAC,aAAa,EAAE,yBAAyB,GAAG,yBAAyB;CAStF;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkBhF"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.unpackRuntimeMessage = exports.RemoteMessageProcessor = void 0;
|
|
8
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
9
|
+
const containerRuntime_1 = require("../containerRuntime");
|
|
10
|
+
class RemoteMessageProcessor {
|
|
11
|
+
constructor(opSplitter, opDecompressor) {
|
|
12
|
+
this.opSplitter = opSplitter;
|
|
13
|
+
this.opDecompressor = opDecompressor;
|
|
14
|
+
}
|
|
15
|
+
get partialMessages() {
|
|
16
|
+
return this.opSplitter.chunks;
|
|
17
|
+
}
|
|
18
|
+
clearPartialMessagesFor(clientId) {
|
|
19
|
+
this.opSplitter.clearPartialChunks(clientId);
|
|
20
|
+
}
|
|
21
|
+
process(remoteMessage) {
|
|
22
|
+
let message = copy(remoteMessage);
|
|
23
|
+
message = this.opDecompressor.processMessage(message);
|
|
24
|
+
unpackRuntimeMessage(message);
|
|
25
|
+
message = this.opSplitter.processRemoteMessage(message);
|
|
26
|
+
return message;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.RemoteMessageProcessor = RemoteMessageProcessor;
|
|
30
|
+
const copy = (remoteMessage) => {
|
|
31
|
+
// Do shallow copy of message, as the processing flow will modify it.
|
|
32
|
+
// There might be multiple container instances receiving same message
|
|
33
|
+
// We do not need to make deep copy, as each layer will just replace message.content itself,
|
|
34
|
+
// but would not modify contents details
|
|
35
|
+
const message = Object.assign({}, remoteMessage);
|
|
36
|
+
// back-compat: ADO #1385: eventually should become unconditional, but only for runtime messages!
|
|
37
|
+
// System message may have no contents, or in some cases (mostly for back-compat) they may have actual objects.
|
|
38
|
+
// Old ops may contain empty string (I assume noops).
|
|
39
|
+
if (typeof message.contents === "string" && message.contents !== "") {
|
|
40
|
+
message.contents = JSON.parse(message.contents);
|
|
41
|
+
}
|
|
42
|
+
return message;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* For a given message, it moves the nested contents and type on level up.
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
const unpack = (message) => {
|
|
49
|
+
const innerContents = message.contents;
|
|
50
|
+
message.type = innerContents.type;
|
|
51
|
+
message.contents = innerContents.contents;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Unpacks runtime messages.
|
|
55
|
+
*
|
|
56
|
+
* @remarks This API makes no promises regarding backward-compatibility. This is internal API.
|
|
57
|
+
* @param message - message (as it observed in storage / service)
|
|
58
|
+
* @returns unpacked runtime message
|
|
59
|
+
*
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
function unpackRuntimeMessage(message) {
|
|
63
|
+
if (message.type !== protocol_definitions_1.MessageType.Operation) {
|
|
64
|
+
// Legacy format, but it's already "unpacked",
|
|
65
|
+
// i.e. message.type is actually ContainerMessageType.
|
|
66
|
+
// Or it's non-runtime message.
|
|
67
|
+
// Nothing to do in such case.
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// legacy op format?
|
|
71
|
+
if (message.contents.address !== undefined && message.contents.type === undefined) {
|
|
72
|
+
message.type = containerRuntime_1.ContainerMessageType.FluidDataStoreOp;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// new format
|
|
76
|
+
unpack(message);
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
exports.unpackRuntimeMessage = unpackRuntimeMessage;
|
|
81
|
+
//# sourceMappingURL=remoteMessageProcessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remoteMessageProcessor.js","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+EAA8F;AAC9F,0DAAoF;AAIpF,MAAa,sBAAsB;IAC/B,YACqB,UAAsB,EACtB,cAA8B;QAD9B,eAAU,GAAV,UAAU,CAAY;QACtB,mBAAc,GAAd,cAAc,CAAgB;IAC/C,CAAC;IAEL,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAClC,CAAC;IAEM,uBAAuB,CAAC,QAAgB;QAC3C,IAAI,CAAC,UAAU,CAAC,kB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C;KAChB;IAED,oBAAoB;IACpB,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE;QAC/E,OAAO,CAAC,IAAI,GAAG,uCAAoB,CAAC,gBAAgB,CAAC;KACxD;SAAM;QACH,aAAa;QACb,MAAM,CAAC,OAAO,CAAC,CAAC;KACnB;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAlBD,oDAkBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport { ContainerMessageType, ContainerRuntimeMessage } from \"../containerRuntime\";\nimport { OpDecompressor } from \"./opDecompressor\";\nimport { OpSplitter } from \"./opSplitter\";\n\nexport class RemoteMessageProcessor {\n constructor(\n private readonly opSplitter: OpSplitter,\n private readonly opDecompressor: OpDecompressor,\n ) { }\n\n public get partialMessages(): ReadonlyMap<string, string[]> {\n return this.opSplitter.chunks;\n }\n\n public clearPartialMessagesFor(clientId: string) {\n this.opSplitter.clearPartialChunks(clientId);\n }\n\n public process(remoteMessage: ISequencedDocumentMessage): ISequencedDocumentMessage {\n let message = copy(remoteMessage);\n\n message = this.opDecompressor.processMessage(message);\n unpackRuntimeMessage(message);\n message = this.opSplitter.processRemoteMessage(message);\n\n return message;\n }\n}\n\nconst copy = (remoteMessage: ISequencedDocumentMessage): ISequencedDocumentMessage => {\n // Do shallow copy of message, as the processing flow will modify it.\n // There might be multiple container instances receiving same message\n // We do not need to make deep copy, as each layer will just replace message.content itself,\n // but would not modify contents details\n const message = { ...remoteMessage };\n\n // back-compat: ADO #1385: eventually should become unconditional, but only for runtime messages!\n // System message may have no contents, or in some cases (mostly for back-compat) they may have actual objects.\n // Old ops may contain empty string (I assume noops).\n if (typeof message.contents === \"string\" && message.contents !== \"\") {\n message.contents = JSON.parse(message.contents);\n }\n\n return message;\n};\n\n/**\n * For a given message, it moves the nested contents and type on level up.\n *\n */\nconst unpack = (message: ISequencedDocumentMessage) => {\n const innerContents = message.contents as ContainerRuntimeMessage;\n message.type = innerContents.type;\n message.contents = innerContents.contents;\n};\n\n/**\n * Unpacks runtime messages.\n *\n * @remarks This API makes no promises regarding backward-compatibility. This is internal API.\n * @param message - message (as it observed in storage / service)\n * @returns unpacked runtime message\n *\n * @internal\n */\nexport function unpackRuntimeMessage(message: ISequencedDocumentMessage): boolean {\n if (message.type !== MessageType.Operation) {\n // Legacy format, but it's already \"unpacked\",\n // i.e. message.type is actually ContainerMessageType.\n // Or it's non-runtime message.\n // Nothing to do in such case.\n return false;\n }\n\n // legacy op format?\n if (message.contents.address !== undefined && message.contents.type === undefined) {\n message.type = ContainerMessageType.FluidDataStoreOp;\n } else {\n // new format\n unpack(message);\n }\n\n return true;\n}\n"]}
|
package/dist/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-dev.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-dev.2.3.0.115467";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/container-runtime";
|
|
11
|
-
exports.pkgVersion = "2.0.0-dev.
|
|
11
|
+
exports.pkgVersion = "2.0.0-dev.2.3.0.115467";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,wBAAwB,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-dev.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,wBAAwB,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-dev.2.3.0.115467\";\n"]}
|