@fluidframework/container-runtime 2.0.0-internal.2.1.1 → 2.0.0-internal.2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/.eslintrc.js +1 -1
  2. package/dist/blobManager.d.ts +20 -5
  3. package/dist/blobManager.d.ts.map +1 -1
  4. package/dist/blobManager.js +57 -15
  5. package/dist/blobManager.js.map +1 -1
  6. package/dist/containerRuntime.d.ts +39 -40
  7. package/dist/containerRuntime.d.ts.map +1 -1
  8. package/dist/containerRuntime.js +115 -278
  9. package/dist/containerRuntime.js.map +1 -1
  10. package/dist/dataStoreContext.d.ts +3 -1
  11. package/dist/dataStoreContext.d.ts.map +1 -1
  12. package/dist/dataStoreContext.js +21 -3
  13. package/dist/dataStoreContext.js.map +1 -1
  14. package/dist/dataStores.d.ts +8 -5
  15. package/dist/dataStores.d.ts.map +1 -1
  16. package/dist/dataStores.js +26 -13
  17. package/dist/dataStores.js.map +1 -1
  18. package/dist/garbageCollection.d.ts +15 -17
  19. package/dist/garbageCollection.d.ts.map +1 -1
  20. package/dist/garbageCollection.js +92 -106
  21. package/dist/garbageCollection.js.map +1 -1
  22. package/dist/garbageCollectionConstants.d.ts +19 -0
  23. package/dist/garbageCollectionConstants.d.ts.map +1 -0
  24. package/dist/garbageCollectionConstants.js +34 -0
  25. package/dist/garbageCollectionConstants.js.map +1 -0
  26. package/dist/gcSweepReadyUsageDetection.js +2 -2
  27. package/dist/gcSweepReadyUsageDetection.js.map +1 -1
  28. package/dist/index.d.ts +4 -2
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +8 -6
  31. package/dist/index.js.map +1 -1
  32. package/dist/opLifecycle/batchManager.d.ts +30 -0
  33. package/dist/opLifecycle/batchManager.d.ts.map +1 -0
  34. package/dist/{batchManager.js → opLifecycle/batchManager.js} +25 -10
  35. package/dist/opLifecycle/batchManager.js.map +1 -0
  36. package/dist/opLifecycle/definitions.d.ts +40 -0
  37. package/dist/opLifecycle/definitions.d.ts.map +1 -0
  38. package/dist/opLifecycle/definitions.js +7 -0
  39. package/dist/opLifecycle/definitions.js.map +1 -0
  40. package/dist/opLifecycle/index.d.ts +12 -0
  41. package/dist/opLifecycle/index.d.ts.map +1 -0
  42. package/dist/opLifecycle/index.js +21 -0
  43. package/dist/opLifecycle/index.js.map +1 -0
  44. package/dist/opLifecycle/opCompressor.d.ts +18 -0
  45. package/dist/opLifecycle/opCompressor.d.ts.map +1 -0
  46. package/dist/opLifecycle/opCompressor.js +53 -0
  47. package/dist/opLifecycle/opCompressor.js.map +1 -0
  48. package/dist/opLifecycle/opDecompressor.d.ts +20 -0
  49. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -0
  50. package/dist/opLifecycle/opDecompressor.js +72 -0
  51. package/dist/opLifecycle/opDecompressor.js.map +1 -0
  52. package/dist/opLifecycle/opSplitter.d.ts +17 -0
  53. package/dist/opLifecycle/opSplitter.d.ts.map +1 -0
  54. package/dist/opLifecycle/opSplitter.js +61 -0
  55. package/dist/opLifecycle/opSplitter.js.map +1 -0
  56. package/dist/opLifecycle/outbox.d.ts +47 -0
  57. package/dist/opLifecycle/outbox.d.ts.map +1 -0
  58. package/dist/opLifecycle/outbox.js +153 -0
  59. package/dist/opLifecycle/outbox.js.map +1 -0
  60. package/dist/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  61. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  62. package/dist/opLifecycle/remoteMessageProcessor.js +81 -0
  63. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -0
  64. package/dist/packageVersion.d.ts +1 -1
  65. package/dist/packageVersion.js +1 -1
  66. package/dist/packageVersion.js.map +1 -1
  67. package/dist/summaryFormat.js +2 -2
  68. package/dist/summaryFormat.js.map +1 -1
  69. package/lib/blobManager.d.ts +20 -5
  70. package/lib/blobManager.d.ts.map +1 -1
  71. package/lib/blobManager.js +59 -17
  72. package/lib/blobManager.js.map +1 -1
  73. package/lib/containerRuntime.d.ts +39 -40
  74. package/lib/containerRuntime.d.ts.map +1 -1
  75. package/lib/containerRuntime.js +113 -275
  76. package/lib/containerRuntime.js.map +1 -1
  77. package/lib/dataStoreContext.d.ts +3 -1
  78. package/lib/dataStoreContext.d.ts.map +1 -1
  79. package/lib/dataStoreContext.js +23 -5
  80. package/lib/dataStoreContext.js.map +1 -1
  81. package/lib/dataStores.d.ts +8 -5
  82. package/lib/dataStores.d.ts.map +1 -1
  83. package/lib/dataStores.js +28 -15
  84. package/lib/dataStores.js.map +1 -1
  85. package/lib/garbageCollection.d.ts +15 -17
  86. package/lib/garbageCollection.d.ts.map +1 -1
  87. package/lib/garbageCollection.js +72 -86
  88. package/lib/garbageCollection.js.map +1 -1
  89. package/lib/garbageCollectionConstants.d.ts +19 -0
  90. package/lib/garbageCollectionConstants.d.ts.map +1 -0
  91. package/lib/garbageCollectionConstants.js +31 -0
  92. package/lib/garbageCollectionConstants.js.map +1 -0
  93. package/lib/gcSweepReadyUsageDetection.js +1 -1
  94. package/lib/gcSweepReadyUsageDetection.js.map +1 -1
  95. package/lib/index.d.ts +4 -2
  96. package/lib/index.d.ts.map +1 -1
  97. package/lib/index.js +3 -2
  98. package/lib/index.js.map +1 -1
  99. package/lib/opLifecycle/batchManager.d.ts +30 -0
  100. package/lib/opLifecycle/batchManager.d.ts.map +1 -0
  101. package/lib/{batchManager.js → opLifecycle/batchManager.js} +25 -10
  102. package/lib/opLifecycle/batchManager.js.map +1 -0
  103. package/lib/opLifecycle/definitions.d.ts +40 -0
  104. package/lib/opLifecycle/definitions.d.ts.map +1 -0
  105. package/lib/opLifecycle/definitions.js +6 -0
  106. package/lib/opLifecycle/definitions.js.map +1 -0
  107. package/lib/opLifecycle/index.d.ts +12 -0
  108. package/lib/opLifecycle/index.d.ts.map +1 -0
  109. package/lib/opLifecycle/index.js +11 -0
  110. package/lib/opLifecycle/index.js.map +1 -0
  111. package/lib/opLifecycle/opCompressor.d.ts +18 -0
  112. package/lib/opLifecycle/opCompressor.d.ts.map +1 -0
  113. package/lib/opLifecycle/opCompressor.js +49 -0
  114. package/lib/opLifecycle/opCompressor.js.map +1 -0
  115. package/lib/opLifecycle/opDecompressor.d.ts +20 -0
  116. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -0
  117. package/lib/opLifecycle/opDecompressor.js +68 -0
  118. package/lib/opLifecycle/opDecompressor.js.map +1 -0
  119. package/lib/opLifecycle/opSplitter.d.ts +17 -0
  120. package/lib/opLifecycle/opSplitter.d.ts.map +1 -0
  121. package/lib/opLifecycle/opSplitter.js +57 -0
  122. package/lib/opLifecycle/opSplitter.js.map +1 -0
  123. package/lib/opLifecycle/outbox.d.ts +47 -0
  124. package/lib/opLifecycle/outbox.d.ts.map +1 -0
  125. package/lib/opLifecycle/outbox.js +149 -0
  126. package/lib/opLifecycle/outbox.js.map +1 -0
  127. package/lib/opLifecycle/remoteMessageProcessor.d.ts +26 -0
  128. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -0
  129. package/lib/opLifecycle/remoteMessageProcessor.js +76 -0
  130. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -0
  131. package/lib/packageVersion.d.ts +1 -1
  132. package/lib/packageVersion.js +1 -1
  133. package/lib/packageVersion.js.map +1 -1
  134. package/lib/summaryFormat.js +1 -1
  135. package/lib/summaryFormat.js.map +1 -1
  136. package/package.json +35 -21
  137. package/prettier.config.cjs +8 -0
  138. package/src/blobManager.ts +74 -19
  139. package/src/containerRuntime.ts +144 -341
  140. package/src/dataStoreContext.ts +33 -5
  141. package/src/dataStores.ts +32 -16
  142. package/src/garbageCollection.ts +106 -82
  143. package/src/garbageCollectionConstants.ts +35 -0
  144. package/src/gcSweepReadyUsageDetection.ts +1 -1
  145. package/src/index.ts +6 -4
  146. package/src/{batchManager.ts → opLifecycle/batchManager.ts} +41 -23
  147. package/src/opLifecycle/definitions.ts +44 -0
  148. package/src/opLifecycle/index.ts +17 -0
  149. package/src/opLifecycle/opCompressor.ts +64 -0
  150. package/src/opLifecycle/opDecompressor.ts +84 -0
  151. package/src/opLifecycle/opSplitter.ts +78 -0
  152. package/src/opLifecycle/outbox.ts +204 -0
  153. package/src/opLifecycle/remoteMessageProcessor.ts +90 -0
  154. package/src/packageVersion.ts +1 -1
  155. package/src/summaryFormat.ts +1 -1
  156. package/dist/batchManager.d.ts +0 -36
  157. package/dist/batchManager.d.ts.map +0 -1
  158. package/dist/batchManager.js.map +0 -1
  159. package/lib/batchManager.d.ts +0 -36
  160. package/lib/batchManager.d.ts.map +0 -1
  161. package/lib/batchManager.js.map +0 -1
@@ -0,0 +1,204 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { assert } from "@fluidframework/common-utils";
7
+ import { IContainerContext } from "@fluidframework/container-definitions";
8
+ import { GenericError } from "@fluidframework/container-utils";
9
+ import { MessageType } from "@fluidframework/protocol-definitions";
10
+ import { ICompressionRuntimeOptions } from "../containerRuntime";
11
+ import { PendingStateManager } from "../pendingStateManager";
12
+ import { BatchManager } from "./batchManager";
13
+ import { BatchMessage, IBatch } from "./definitions";
14
+ import { OpCompressor } from "./opCompressor";
15
+
16
+ export interface IOutboxConfig {
17
+ readonly compressionOptions: ICompressionRuntimeOptions;
18
+ // The maximum size of a batch that we can send over the wire.
19
+ readonly maxBatchSizeInBytes: number;
20
+ };
21
+
22
+ export interface IOutboxParameters {
23
+ readonly shouldSend: () => boolean,
24
+ readonly pendingStateManager: PendingStateManager,
25
+ readonly containerContext: IContainerContext,
26
+ readonly config: IOutboxConfig,
27
+ readonly compressor: OpCompressor;
28
+ }
29
+
30
+ export class Outbox {
31
+ private readonly attachFlowBatch: BatchManager;
32
+ private readonly mainBatch: BatchManager;
33
+ private readonly defaultAttachFlowSoftLimitInBytes = 64 * 1024;
34
+
35
+ constructor(private readonly params: IOutboxParameters) {
36
+ const isCompressionEnabled = this.params.config.compressionOptions.minimumBatchSizeInBytes !== Number.POSITIVE_INFINITY;
37
+ // We need to allow infinite size batches if we enable compression
38
+ const hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;
39
+ const softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;
40
+
41
+ this.attachFlowBatch = new BatchManager({
42
+ hardLimit,
43
+ softLimit,
44
+ });
45
+ this.mainBatch = new BatchManager({
46
+ hardLimit
47
+ });
48
+ }
49
+
50
+ public get isEmpty(): boolean {
51
+ return this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;
52
+ }
53
+
54
+ public submit(message: BatchMessage) {
55
+ if (!this.mainBatch.push(message)) {
56
+ throw new GenericError(
57
+ "BatchTooLarge",
58
+ /* error */ undefined,
59
+ {
60
+ opSize: (message.contents?.length) ?? 0,
61
+ count: this.mainBatch.length,
62
+ limit: this.mainBatch.options.hardLimit,
63
+ });
64
+ }
65
+ }
66
+
67
+ public submitAttach(message: BatchMessage) {
68
+ if (!this.attachFlowBatch.push(message)) {
69
+ // BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged
70
+ // when queue is not empty.
71
+ // Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit
72
+ this.flushInternal(this.attachFlowBatch.popBatch());
73
+ if (!this.attachFlowBatch.push(message)) {
74
+ throw new GenericError(
75
+ "BatchTooLarge",
76
+ /* error */ undefined,
77
+ {
78
+ opSize: (message.contents?.length) ?? 0,
79
+ count: this.attachFlowBatch.length,
80
+ limit: this.attachFlowBatch.options.hardLimit,
81
+ });
82
+ }
83
+ }
84
+
85
+ // If compression is enabled, we will always successfully receive
86
+ // attach ops and compress then send them at the next JS turn, regardless
87
+ // of the overall size of the accumulated ops in the batch.
88
+ // However, it is more efficient to flush these ops faster, preferably
89
+ // after they reach a size which would benefit from compression.
90
+ if (this.attachFlowBatch.contentSizeInBytes >= this.params.config.compressionOptions.minimumBatchSizeInBytes) {
91
+ this.flushInternal(this.attachFlowBatch.popBatch());
92
+ }
93
+ }
94
+
95
+ public flush() {
96
+ this.flushInternal(this.attachFlowBatch.popBatch());
97
+ this.flushInternal(this.mainBatch.popBatch());
98
+ }
99
+
100
+ private flushInternal(rawBatch: IBatch) {
101
+ const processedBatch = this.compressBatch(rawBatch);
102
+ const clientSequenceNumber = this.sendBatch(processedBatch);
103
+
104
+ this.persistBatch(clientSequenceNumber, rawBatch.content);
105
+ }
106
+
107
+ private compressBatch(batch: IBatch): IBatch {
108
+ if (batch.content.length === 0
109
+ || this.params.config.compressionOptions === undefined
110
+ || this.params.config.compressionOptions.minimumBatchSizeInBytes > batch.contentSizeInBytes) {
111
+ // Nothing to do if the batch is empty or if compression is disabled or if we don't need to compress
112
+ return batch;
113
+ }
114
+
115
+ const compressedBatch = this.params.compressor.compressBatch(batch);
116
+ if (compressedBatch.contentSizeInBytes > this.params.config.maxBatchSizeInBytes) {
117
+ throw new GenericError(
118
+ "BatchTooLarge",
119
+ /* error */ undefined,
120
+ {
121
+ opSize: batch.contentSizeInBytes,
122
+ count: batch.content.length,
123
+ limit: this.params.config.maxBatchSizeInBytes,
124
+ compressed: true,
125
+ });
126
+ }
127
+
128
+ // If we don't reach the maximum supported size of a batch, it safe to be sent as is
129
+ return compressedBatch;
130
+ }
131
+
132
+ /**
133
+ * Sends the batch object to the container context to be sent over the wire.
134
+ *
135
+ * @param batch - batch to be sent
136
+ * @returns the client sequence number of the last batched op which was sent and
137
+ * -1 if there are no ops or the container cannot send ops.
138
+ */
139
+ private sendBatch(batch: IBatch): number {
140
+ let clientSequenceNumber: number = -1;
141
+ const length = batch.content.length;
142
+
143
+ // Did we disconnect in the middle of turn-based batch?
144
+ // If so, do nothing, as pending state manager will resubmit it correctly on reconnect.
145
+ if (length === 0 || !this.params.shouldSend()) {
146
+ return clientSequenceNumber;
147
+ }
148
+
149
+ if (this.params.containerContext.submitBatchFn === undefined) {
150
+ // Legacy path - supporting old loader versions. Can be removed only when LTS moves above
151
+ // version that has support for batches (submitBatchFn)
152
+ for (const message of batch.content) {
153
+ // Legacy path doesn't support compressed payloads and will submit uncompressed payload anyways
154
+ if (message.metadata?.compressed) {
155
+ delete message.metadata.compressed;
156
+ }
157
+
158
+ clientSequenceNumber = this.params.containerContext.submitFn(
159
+ MessageType.Operation,
160
+ message.deserializedContent,
161
+ true, // batch
162
+ message.metadata);
163
+ }
164
+
165
+ this.params.containerContext.deltaManager.flush();
166
+ } else {
167
+ // returns clientSequenceNumber of last message in a batch
168
+ clientSequenceNumber = this.params.containerContext.submitBatchFn(
169
+ batch.content.map((message) => ({ contents: message.contents, metadata: message.metadata })));
170
+ }
171
+
172
+ // Convert from clientSequenceNumber of last message in the batch to clientSequenceNumber of first message.
173
+ clientSequenceNumber -= length - 1;
174
+ assert(clientSequenceNumber >= 0, 0x3d0 /* clientSequenceNumber can't be negative */);
175
+ return clientSequenceNumber;
176
+ }
177
+
178
+ private persistBatch(initialClientSequenceNumber: number, batch: BatchMessage[]) {
179
+ let clientSequenceNumber = initialClientSequenceNumber;
180
+ // Let the PendingStateManager know that a message was submitted.
181
+ // In future, need to shift toward keeping batch as a whole!
182
+ for (const message of batch) {
183
+ this.params.pendingStateManager.onSubmitMessage(
184
+ message.deserializedContent.type,
185
+ clientSequenceNumber,
186
+ message.referenceSequenceNumber,
187
+ message.deserializedContent.contents,
188
+ message.localOpMetadata,
189
+ message.metadata,
190
+ );
191
+
192
+ clientSequenceNumber++;
193
+ }
194
+
195
+ this.params.pendingStateManager.onFlush();
196
+ }
197
+
198
+ public checkpoint() {
199
+ return {
200
+ mainBatch: this.mainBatch.checkpoint(),
201
+ attachFlowBatch: this.attachFlowBatch.checkpoint(),
202
+ };
203
+ }
204
+ }
@@ -0,0 +1,90 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
7
+ import { ContainerMessageType, ContainerRuntimeMessage } from "../containerRuntime";
8
+ import { OpDecompressor } from "./opDecompressor";
9
+ import { OpSplitter } from "./opSplitter";
10
+
11
+ export class RemoteMessageProcessor {
12
+ constructor(
13
+ private readonly opSplitter: OpSplitter,
14
+ private readonly opDecompressor: OpDecompressor,
15
+ ) { }
16
+
17
+ public get partialMessages(): ReadonlyMap<string, string[]> {
18
+ return this.opSplitter.chunks;
19
+ }
20
+
21
+ public clearPartialMessagesFor(clientId: string) {
22
+ this.opSplitter.clearPartialChunks(clientId);
23
+ }
24
+
25
+ public process(remoteMessage: ISequencedDocumentMessage): ISequencedDocumentMessage {
26
+ let message = copy(remoteMessage);
27
+
28
+ message = this.opDecompressor.processMessage(message);
29
+ unpackRuntimeMessage(message);
30
+ message = this.opSplitter.processRemoteMessage(message);
31
+
32
+ return message;
33
+ }
34
+ }
35
+
36
+ const copy = (remoteMessage: ISequencedDocumentMessage): ISequencedDocumentMessage => {
37
+ // Do shallow copy of message, as the processing flow will modify it.
38
+ // There might be multiple container instances receiving same message
39
+ // We do not need to make deep copy, as each layer will just replace message.content itself,
40
+ // but would not modify contents details
41
+ const message = { ...remoteMessage };
42
+
43
+ // back-compat: ADO #1385: eventually should become unconditional, but only for runtime messages!
44
+ // System message may have no contents, or in some cases (mostly for back-compat) they may have actual objects.
45
+ // Old ops may contain empty string (I assume noops).
46
+ if (typeof message.contents === "string" && message.contents !== "") {
47
+ message.contents = JSON.parse(message.contents);
48
+ }
49
+
50
+ return message;
51
+ };
52
+
53
+ /**
54
+ * For a given message, it moves the nested contents and type on level up.
55
+ *
56
+ */
57
+ const unpack = (message: ISequencedDocumentMessage) => {
58
+ const innerContents = message.contents as ContainerRuntimeMessage;
59
+ message.type = innerContents.type;
60
+ message.contents = innerContents.contents;
61
+ };
62
+
63
+ /**
64
+ * Unpacks runtime messages.
65
+ *
66
+ * @remarks This API makes no promises regarding backward-compatibility. This is internal API.
67
+ * @param message - message (as it observed in storage / service)
68
+ * @returns unpacked runtime message
69
+ *
70
+ * @internal
71
+ */
72
+ export function unpackRuntimeMessage(message: ISequencedDocumentMessage): boolean {
73
+ if (message.type !== MessageType.Operation) {
74
+ // Legacy format, but it's already "unpacked",
75
+ // i.e. message.type is actually ContainerMessageType.
76
+ // Or it's non-runtime message.
77
+ // Nothing to do in such case.
78
+ return false;
79
+ }
80
+
81
+ // legacy op format?
82
+ if (message.contents.address !== undefined && message.contents.type === undefined) {
83
+ message.type = ContainerMessageType.FluidDataStoreOp;
84
+ } else {
85
+ // new format
86
+ unpack(message);
87
+ }
88
+
89
+ return true;
90
+ }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/container-runtime";
9
- export const pkgVersion = "2.0.0-internal.2.1.1";
9
+ export const pkgVersion = "2.0.0-internal.2.2.0";
@@ -8,7 +8,7 @@ import { IDocumentStorageService } from "@fluidframework/driver-definitions";
8
8
  import { readAndParse } from "@fluidframework/driver-utils";
9
9
  import { ISequencedDocumentMessage, ISnapshotTree, SummaryType } from "@fluidframework/protocol-definitions";
10
10
  import { channelsTreeName, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
11
- import { gcTreeKey } from "./garbageCollection";
11
+ import { gcTreeKey } from "./garbageCollectionConstants";
12
12
 
13
13
  type OmitAttributesVersions<T> = Omit<T, "snapshotFormatVersion" | "summaryFormatVersion">;
14
14
  interface IFluidDataStoreAttributes0 {
@@ -1,36 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IBatchMessage } from "@fluidframework/container-definitions";
6
- import { ContainerRuntimeMessage } from "./containerRuntime";
7
- /**
8
- * Message type used by BatchManager
9
- */
10
- export declare type BatchMessage = IBatchMessage & {
11
- localOpMetadata: unknown;
12
- deserializedContent: ContainerRuntimeMessage;
13
- referenceSequenceNumber: number;
14
- };
15
- /**
16
- * Helper class that manages partial batch & rollback.
17
- */
18
- export declare class BatchManager {
19
- private readonly hardLimit;
20
- readonly softLimit?: number | undefined;
21
- private pendingBatch;
22
- private batchContentSize;
23
- get length(): number;
24
- get limit(): number;
25
- constructor(hardLimit: number, softLimit?: number | undefined);
26
- push(message: BatchMessage): boolean;
27
- get empty(): boolean;
28
- popBatch(): BatchMessage[];
29
- /**
30
- * Capture the pending state at this point
31
- */
32
- checkpoint(): {
33
- rollback: (process: (message: BatchMessage) => void) => void;
34
- };
35
- }
36
- //# sourceMappingURL=batchManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchManager.d.ts","sourceRoot":"","sources":["../src/batchManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;GAEG;AACH,oBAAY,YAAY,GAAG,aAAa,GAAG;IACvC,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,uBAAuB,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAY;IAQjB,OAAO,CAAC,QAAQ,CAAC,SAAS;aACV,SAAS,CAAC;IAR9B,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,gBAAgB,CAAK;IAE7B,IAAW,MAAM,WAAuC;IACxD,IAAW,KAAK,WAA6B;gBAGxB,SAAS,EAAE,MAAM,EAClB,SAAS,CAAC,oBAAQ;IAG/B,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IA2B3C,IAAW,KAAK,YAA6C;IAEtD,QAAQ;IAOf;;OAEG;IACI,UAAU;sCAGqB,YAAY,KAAK,IAAI;;CAY9D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchManager.js","sourceRoot":"","sources":["../src/batchManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAcH;;GAEG;AACH,MAAa,YAAY;IAOrB,YACqB,SAAiB,EAClB,SAAkB;QADjB,cAAS,GA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CAAC;QAC1B,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;OAEG;IACI,UAAU;QACb,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;QAC5C,OAAO;YACH,QAAQ,EAAE,CAAC,OAAwC,EAAE,EAAE;gBACnD,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,UAAU,GAAG;oBACpD,CAAC,EAAE,CAAC;oBACJ,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;oBACrC,IAAI,CAAC,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;oBACjD,OAAO,CAAC,OAAO,CAAC,CAAC;iBACpB;gBAED,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC;YAC1C,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AAlED,oCAkEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IBatchMessage } from \"@fluidframework/container-definitions\";\nimport { ContainerRuntimeMessage } from \"./containerRuntime\";\n\n/**\n * Message type used by BatchManager\n */\nexport type BatchMessage = IBatchMessage & {\n localOpMetadata: unknown;\n deserializedContent: ContainerRuntimeMessage;\n referenceSequenceNumber: number;\n};\n\n/**\n * Helper class that manages partial batch & rollback.\n */\nexport class BatchManager {\n private pendingBatch: BatchMessage[] = [];\n private batchContentSize = 0;\n\n public get length() { return this.pendingBatch.length; }\n public get limit() { return this.hardLimit; }\n\n constructor(\n private readonly hardLimit: number,\n public readonly softLimit?: number,\n ) { }\n\n public push(message: BatchMessage): boolean {\n const contentSize = this.batchContentSize + message.contents.length;\n const opCount = this.pendingBatch.length;\n\n // Attempt to estimate batch size, aka socket message size.\n // Each op has pretty large envelope, estimating to be 200 bytes.\n // Also content will be strigified, and that adds a lot of overhead due to a lot of escape characters.\n // Not taking it into account, as compression work should help there - compressed payload will be\n // initially stored as base64, and that requires only 2 extra escape characters.\n const socketMessageSize = contentSize + 200 * opCount;\n\n // If we were provided soft limit, check for exceeding it.\n // But only if we have any ops, as the intention here is to flush existing ops (on exceeding this limit)\n // and start over. That's not an option if we have no ops.\n if (this.softLimit !== undefined && this.length > 0 && socketMessageSize >= this.softLimit) {\n return false;\n }\n\n if (socketMessageSize >= this.limit) {\n return false;\n }\n\n this.batchContentSize = contentSize;\n this.pendingBatch.push(message);\n return true;\n }\n\n public get empty() { return this.pendingBatch.length === 0; }\n\n public popBatch() {\n const batch = this.pendingBatch;\n this.pendingBatch = [];\n this.batchContentSize = 0;\n return batch;\n }\n\n /**\n * Capture the pending state at this point\n */\n public checkpoint() {\n const startPoint = this.pendingBatch.length;\n return {\n rollback: (process: (message: BatchMessage) => void) => {\n for (let i = this.pendingBatch.length; i > startPoint;) {\n i--;\n const message = this.pendingBatch[i];\n this.batchContentSize -= message.contents.length;\n process(message);\n }\n\n this.pendingBatch.length = startPoint;\n },\n };\n }\n}\n"]}
@@ -1,36 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { IBatchMessage } from "@fluidframework/container-definitions";
6
- import { ContainerRuntimeMessage } from "./containerRuntime";
7
- /**
8
- * Message type used by BatchManager
9
- */
10
- export declare type BatchMessage = IBatchMessage & {
11
- localOpMetadata: unknown;
12
- deserializedContent: ContainerRuntimeMessage;
13
- referenceSequenceNumber: number;
14
- };
15
- /**
16
- * Helper class that manages partial batch & rollback.
17
- */
18
- export declare class BatchManager {
19
- private readonly hardLimit;
20
- readonly softLimit?: number | undefined;
21
- private pendingBatch;
22
- private batchContentSize;
23
- get length(): number;
24
- get limit(): number;
25
- constructor(hardLimit: number, softLimit?: number | undefined);
26
- push(message: BatchMessage): boolean;
27
- get empty(): boolean;
28
- popBatch(): BatchMessage[];
29
- /**
30
- * Capture the pending state at this point
31
- */
32
- checkpoint(): {
33
- rollback: (process: (message: BatchMessage) => void) => void;
34
- };
35
- }
36
- //# sourceMappingURL=batchManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchManager.d.ts","sourceRoot":"","sources":["../src/batchManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;GAEG;AACH,oBAAY,YAAY,GAAG,aAAa,GAAG;IACvC,eAAe,EAAE,OAAO,CAAC;IACzB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,uBAAuB,EAAE,MAAM,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,qBAAa,YAAY;IAQjB,OAAO,CAAC,QAAQ,CAAC,SAAS;aACV,SAAS,CAAC;IAR9B,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,gBAAgB,CAAK;IAE7B,IAAW,MAAM,WAAuC;IACxD,IAAW,KAAK,WAA6B;gBAGxB,SAAS,EAAE,MAAM,EAClB,SAAS,CAAC,oBAAQ;IAG/B,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;IA2B3C,IAAW,KAAK,YAA6C;IAEtD,QAAQ;IAOf;;OAEG;IACI,UAAU;sCAGqB,YAAY,KAAK,IAAI;;CAY9D"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchManager.js","sourceRoot":"","sources":["../src/batchManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH;;GAEG;AACH,MAAM,OAAO,YAAY;IAOrB,YACqB,SAAiB,EAClB,SAAkB;QADjB,cAAS,GAAT,SAAS,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAS;QAR9B,iBAAY,GAAmB,EAAE,CAAC;QAClC,qBAAgB,GAAG,CAAC,CAAC;IAQzB,CAAC;IANL,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,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AK,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,GAAG,UAAU,GAAG;oBACpD,CAAC,EAAE,CAAC;oBACJ,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;oBACrC,IAAI,CAAC,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;oBACjD,OAAO,CAAC,OAAO,CAAC,CAAC;iBACpB;gBAED,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC;YAC1C,CAAC;SACJ,CAAC;IACN,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IBatchMessage } from \"@fluidframework/container-definitions\";\nimport { ContainerRuntimeMessage } from \"./containerRuntime\";\n\n/**\n * Message type used by BatchManager\n */\nexport type BatchMessage = IBatchMessage & {\n localOpMetadata: unknown;\n deserializedContent: ContainerRuntimeMessage;\n referenceSequenceNumber: number;\n};\n\n/**\n * Helper class that manages partial batch & rollback.\n */\nexport class BatchManager {\n private pendingBatch: BatchMessage[] = [];\n private batchContentSize = 0;\n\n public get length() { return this.pendingBatch.length; }\n public get limit() { return this.hardLimit; }\n\n constructor(\n private readonly hardLimit: number,\n public readonly softLimit?: number,\n ) { }\n\n public push(message: BatchMessage): boolean {\n const contentSize = this.batchContentSize + message.contents.length;\n const opCount = this.pendingBatch.length;\n\n // Attempt to estimate batch size, aka socket message size.\n // Each op has pretty large envelope, estimating to be 200 bytes.\n // Also content will be strigified, and that adds a lot of overhead due to a lot of escape characters.\n // Not taking it into account, as compression work should help there - compressed payload will be\n // initially stored as base64, and that requires only 2 extra escape characters.\n const socketMessageSize = contentSize + 200 * opCount;\n\n // If we were provided soft limit, check for exceeding it.\n // But only if we have any ops, as the intention here is to flush existing ops (on exceeding this limit)\n // and start over. That's not an option if we have no ops.\n if (this.softLimit !== undefined && this.length > 0 && socketMessageSize >= this.softLimit) {\n return false;\n }\n\n if (socketMessageSize >= this.limit) {\n return false;\n }\n\n this.batchContentSize = contentSize;\n this.pendingBatch.push(message);\n return true;\n }\n\n public get empty() { return this.pendingBatch.length === 0; }\n\n public popBatch() {\n const batch = this.pendingBatch;\n this.pendingBatch = [];\n this.batchContentSize = 0;\n return batch;\n }\n\n /**\n * Capture the pending state at this point\n */\n public checkpoint() {\n const startPoint = this.pendingBatch.length;\n return {\n rollback: (process: (message: BatchMessage) => void) => {\n for (let i = this.pendingBatch.length; i > startPoint;) {\n i--;\n const message = this.pendingBatch[i];\n this.batchContentSize -= message.contents.length;\n process(message);\n }\n\n this.pendingBatch.length = startPoint;\n },\n };\n }\n}\n"]}