@fluidframework/container-runtime 2.1.0-276985 → 2.1.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/CHANGELOG.md +4 -0
- package/README.md +71 -18
- package/api-extractor/api-extractor.current.json +5 -0
- package/api-extractor/api-extractor.legacy.json +1 -1
- package/api-extractor.json +1 -1
- package/api-report/container-runtime.legacy.public.api.md +9 -0
- package/container-runtime.test-files.tar +0 -0
- package/dist/blobManager/blobManager.d.ts +10 -0
- package/dist/blobManager/blobManager.d.ts.map +1 -1
- package/dist/blobManager/blobManager.js +19 -0
- package/dist/blobManager/blobManager.js.map +1 -1
- package/dist/channelCollection.d.ts +1 -1
- package/dist/channelCollection.d.ts.map +1 -1
- package/dist/channelCollection.js +40 -8
- package/dist/channelCollection.js.map +1 -1
- package/dist/containerRuntime.d.ts +14 -5
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +151 -99
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStoreContext.d.ts +4 -0
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +9 -3
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +1 -1
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js +14 -8
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +4 -2
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcHelpers.d.ts.map +1 -1
- package/dist/gc/gcHelpers.js +12 -0
- package/dist/gc/gcHelpers.js.map +1 -1
- package/dist/gc/gcTelemetry.d.ts +3 -2
- package/dist/gc/gcTelemetry.d.ts.map +1 -1
- package/dist/gc/gcTelemetry.js +6 -6
- package/dist/gc/gcTelemetry.js.map +1 -1
- package/dist/legacy.d.ts +1 -1
- package/dist/metadata.d.ts +7 -1
- package/dist/metadata.d.ts.map +1 -1
- package/dist/metadata.js +6 -0
- package/dist/metadata.js.map +1 -1
- package/dist/opLifecycle/batchManager.d.ts +8 -1
- package/dist/opLifecycle/batchManager.d.ts.map +1 -1
- package/dist/opLifecycle/batchManager.js +37 -16
- package/dist/opLifecycle/batchManager.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts +1 -1
- package/dist/opLifecycle/definitions.d.ts.map +1 -1
- package/dist/opLifecycle/definitions.js.map +1 -1
- package/dist/opLifecycle/index.d.ts +2 -2
- package/dist/opLifecycle/index.d.ts.map +1 -1
- package/dist/opLifecycle/index.js +3 -1
- package/dist/opLifecycle/index.js.map +1 -1
- package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opCompressor.js +12 -8
- package/dist/opLifecycle/opCompressor.js.map +1 -1
- package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
- package/dist/opLifecycle/opGroupingManager.js +14 -11
- package/dist/opLifecycle/opGroupingManager.js.map +1 -1
- package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
- package/dist/opLifecycle/opSplitter.js +11 -6
- package/dist/opLifecycle/opSplitter.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts +22 -6
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +43 -21
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.d.ts +10 -8
- package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.js +39 -15
- package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +37 -13
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +95 -45
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/scheduleManager.js +4 -0
- package/dist/scheduleManager.js.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/dist/summary/summarizerNode/summarizerNodeUtils.js +2 -0
- package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/dist/summary/summaryFormat.d.ts.map +1 -1
- package/dist/summary/summaryFormat.js +4 -1
- package/dist/summary/summaryFormat.js.map +1 -1
- package/internal.d.ts +1 -1
- package/legacy.d.ts +1 -1
- package/lib/blobManager/blobManager.d.ts +10 -0
- package/lib/blobManager/blobManager.d.ts.map +1 -1
- package/lib/blobManager/blobManager.js +19 -0
- package/lib/blobManager/blobManager.js.map +1 -1
- package/lib/channelCollection.d.ts +1 -1
- package/lib/channelCollection.d.ts.map +1 -1
- package/lib/channelCollection.js +40 -8
- package/lib/channelCollection.js.map +1 -1
- package/lib/containerRuntime.d.ts +14 -5
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +152 -100
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStoreContext.d.ts +4 -0
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +10 -4
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +1 -1
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +14 -8
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +4 -2
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcHelpers.d.ts.map +1 -1
- package/lib/gc/gcHelpers.js +12 -0
- package/lib/gc/gcHelpers.js.map +1 -1
- package/lib/gc/gcTelemetry.d.ts +3 -2
- package/lib/gc/gcTelemetry.d.ts.map +1 -1
- package/lib/gc/gcTelemetry.js +6 -6
- package/lib/gc/gcTelemetry.js.map +1 -1
- package/lib/legacy.d.ts +1 -1
- package/lib/metadata.d.ts +7 -1
- package/lib/metadata.d.ts.map +1 -1
- package/lib/metadata.js +4 -1
- package/lib/metadata.js.map +1 -1
- package/lib/opLifecycle/batchManager.d.ts +8 -1
- package/lib/opLifecycle/batchManager.d.ts.map +1 -1
- package/lib/opLifecycle/batchManager.js +35 -15
- package/lib/opLifecycle/batchManager.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts +1 -1
- package/lib/opLifecycle/definitions.d.ts.map +1 -1
- package/lib/opLifecycle/definitions.js.map +1 -1
- package/lib/opLifecycle/index.d.ts +2 -2
- package/lib/opLifecycle/index.d.ts.map +1 -1
- package/lib/opLifecycle/index.js +2 -2
- package/lib/opLifecycle/index.js.map +1 -1
- package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opCompressor.js +12 -8
- package/lib/opLifecycle/opCompressor.js.map +1 -1
- package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
- package/lib/opLifecycle/opGroupingManager.js +14 -11
- package/lib/opLifecycle/opGroupingManager.js.map +1 -1
- package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
- package/lib/opLifecycle/opSplitter.js +11 -6
- package/lib/opLifecycle/opSplitter.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts +22 -6
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +44 -22
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.d.ts +10 -8
- package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.js +37 -14
- package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +37 -13
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +95 -45
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/public.d.ts +1 -1
- package/lib/scheduleManager.js +4 -0
- package/lib/scheduleManager.js.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -1
- package/lib/summary/summarizerNode/summarizerNodeUtils.js +2 -0
- package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -1
- package/lib/summary/summaryFormat.d.ts.map +1 -1
- package/lib/summary/summaryFormat.js +4 -1
- package/lib/summary/summaryFormat.js.map +1 -1
- package/package.json +46 -31
- package/src/blobManager/blobManager.ts +19 -0
- package/src/channelCollection.ts +48 -11
- package/src/containerRuntime.ts +203 -133
- package/src/dataStoreContext.ts +22 -4
- package/src/gc/garbageCollection.ts +15 -10
- package/src/gc/gcDefinitions.ts +7 -2
- package/src/gc/gcHelpers.ts +18 -6
- package/src/gc/gcTelemetry.ts +20 -8
- package/src/metadata.ts +11 -1
- package/src/opLifecycle/README.md +0 -8
- package/src/opLifecycle/batchManager.ts +49 -16
- package/src/opLifecycle/definitions.ts +1 -1
- package/src/opLifecycle/index.ts +13 -2
- package/src/opLifecycle/opCompressor.ts +12 -8
- package/src/opLifecycle/opGroupingManager.ts +14 -11
- package/src/opLifecycle/opSplitter.ts +10 -6
- package/src/opLifecycle/outbox.ts +64 -26
- package/src/opLifecycle/remoteMessageProcessor.ts +56 -17
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +173 -74
- package/src/scheduleManager.ts +6 -2
- package/src/summary/README.md +81 -0
- package/src/summary/summarizerNode/summarizerNodeUtils.ts +3 -1
- package/src/summary/summaryFormat.ts +3 -1
- package/src/summary/summaryFormats.md +69 -8
- package/tsconfig.json +0 -1
- package/src/summary/images/appTree.png +0 -0
- package/src/summary/images/protocolAndAppTree.png +0 -0
- package/src/summary/images/summaryTree.png +0 -0
|
@@ -9,19 +9,20 @@ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
|
|
|
9
9
|
import { assert } from "@fluidframework/core-utils/internal";
|
|
10
10
|
import {
|
|
11
11
|
GenericError,
|
|
12
|
-
MonitoringContext,
|
|
13
12
|
UsageError,
|
|
14
|
-
|
|
13
|
+
createChildLogger,
|
|
14
|
+
type ITelemetryLoggerExt,
|
|
15
15
|
} from "@fluidframework/telemetry-utils/internal";
|
|
16
16
|
|
|
17
17
|
import { ICompressionRuntimeOptions } from "../containerRuntime.js";
|
|
18
|
-
import {
|
|
18
|
+
import { PendingMessageResubmitData, PendingStateManager } from "../pendingStateManager.js";
|
|
19
19
|
|
|
20
20
|
import {
|
|
21
21
|
BatchManager,
|
|
22
22
|
BatchSequenceNumbers,
|
|
23
23
|
estimateSocketSize,
|
|
24
24
|
sequenceNumbersMatch,
|
|
25
|
+
type BatchId,
|
|
25
26
|
} from "./batchManager.js";
|
|
26
27
|
import { BatchMessage, IBatch, IBatchCheckpoint } from "./definitions.js";
|
|
27
28
|
import { OpCompressor } from "./opCompressor.js";
|
|
@@ -48,7 +49,7 @@ export interface IOutboxParameters {
|
|
|
48
49
|
readonly logger: ITelemetryBaseLogger;
|
|
49
50
|
readonly groupingManager: OpGroupingManager;
|
|
50
51
|
readonly getCurrentSequenceNumbers: () => BatchSequenceNumbers;
|
|
51
|
-
readonly reSubmit: (message:
|
|
52
|
+
readonly reSubmit: (message: PendingMessageResubmitData) => void;
|
|
52
53
|
readonly opReentrancy: () => boolean;
|
|
53
54
|
readonly closeContainer: (error?: ICriticalContainerError) => void;
|
|
54
55
|
}
|
|
@@ -87,8 +88,15 @@ export function getLongStack<T>(action: () => T, length: number = 50): T {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
/**
|
|
92
|
+
* The Outbox collects messages submitted by the ContainerRuntime into a batch,
|
|
93
|
+
* and then flushes the batch when requested.
|
|
94
|
+
*
|
|
95
|
+
* @remarks There are actually multiple independent batches (some are for a specific message type),
|
|
96
|
+
* to support slight variation in semantics for each batch (e.g. support for rebasing or grouping).
|
|
97
|
+
*/
|
|
90
98
|
export class Outbox {
|
|
91
|
-
private readonly
|
|
99
|
+
private readonly logger: ITelemetryLoggerExt;
|
|
92
100
|
private readonly mainBatch: BatchManager;
|
|
93
101
|
private readonly blobAttachBatch: BatchManager;
|
|
94
102
|
private readonly idAllocationBatch: BatchManager;
|
|
@@ -105,7 +113,8 @@ export class Outbox {
|
|
|
105
113
|
private mismatchedOpsReported = 0;
|
|
106
114
|
|
|
107
115
|
constructor(private readonly params: IOutboxParameters) {
|
|
108
|
-
this.
|
|
116
|
+
this.logger = createChildLogger({ logger: params.logger, namespace: "Outbox" });
|
|
117
|
+
|
|
109
118
|
const isCompressionEnabled =
|
|
110
119
|
this.params.config.compressionOptions.minimumBatchSizeInBytes !==
|
|
111
120
|
Number.POSITIVE_INFINITY;
|
|
@@ -158,7 +167,7 @@ export class Outbox {
|
|
|
158
167
|
}
|
|
159
168
|
|
|
160
169
|
if (++this.mismatchedOpsReported <= this.maxMismatchedOpsToReport) {
|
|
161
|
-
this.
|
|
170
|
+
this.logger.sendTelemetryEvent(
|
|
162
171
|
{
|
|
163
172
|
category: this.params.config.disablePartialFlush ? "error" : "generic",
|
|
164
173
|
eventName: "ReferenceSequenceNumberMismatch",
|
|
@@ -225,28 +234,48 @@ export class Outbox {
|
|
|
225
234
|
}
|
|
226
235
|
}
|
|
227
236
|
|
|
228
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Flush all the batches to the ordering service.
|
|
239
|
+
* This method is expected to be called at the end of a batch.
|
|
240
|
+
* @param resubmittingBatchId - If defined, indicates this is a resubmission of a batch
|
|
241
|
+
* with the given Batch ID, which must be preserved
|
|
242
|
+
*/
|
|
243
|
+
public flush(resubmittingBatchId?: BatchId) {
|
|
229
244
|
if (this.isContextReentrant()) {
|
|
230
245
|
const error = new UsageError("Flushing is not supported inside DDS event handlers");
|
|
231
246
|
this.params.closeContainer(error);
|
|
232
247
|
throw error;
|
|
233
248
|
}
|
|
234
249
|
|
|
235
|
-
this.flushAll();
|
|
250
|
+
this.flushAll(resubmittingBatchId);
|
|
236
251
|
}
|
|
237
252
|
|
|
238
|
-
private flushAll() {
|
|
253
|
+
private flushAll(resubmittingBatchId?: BatchId) {
|
|
254
|
+
// Don't use resubmittingBatchId for idAllocationBatch.
|
|
255
|
+
// ID Allocation messages are not directly resubmitted so we don't want to reuse the batch ID.
|
|
239
256
|
this.flushInternal(this.idAllocationBatch);
|
|
240
|
-
this.flushInternal(
|
|
241
|
-
|
|
257
|
+
this.flushInternal(
|
|
258
|
+
this.blobAttachBatch,
|
|
259
|
+
true /* disableGroupedBatching */,
|
|
260
|
+
resubmittingBatchId,
|
|
261
|
+
);
|
|
262
|
+
this.flushInternal(
|
|
263
|
+
this.mainBatch,
|
|
264
|
+
false /* disableGroupedBatching */,
|
|
265
|
+
resubmittingBatchId,
|
|
266
|
+
);
|
|
242
267
|
}
|
|
243
268
|
|
|
244
|
-
private flushInternal(
|
|
269
|
+
private flushInternal(
|
|
270
|
+
batchManager: BatchManager,
|
|
271
|
+
disableGroupedBatching: boolean = false,
|
|
272
|
+
resubmittingBatchId?: BatchId,
|
|
273
|
+
) {
|
|
245
274
|
if (batchManager.empty) {
|
|
246
275
|
return;
|
|
247
276
|
}
|
|
248
277
|
|
|
249
|
-
const rawBatch = batchManager.popBatch();
|
|
278
|
+
const rawBatch = batchManager.popBatch(resubmittingBatchId);
|
|
250
279
|
const shouldGroup =
|
|
251
280
|
!disableGroupedBatching && this.params.groupingManager.shouldGroup(rawBatch);
|
|
252
281
|
if (batchManager.options.canRebase && rawBatch.hasReentrantOps === true && shouldGroup) {
|
|
@@ -267,9 +296,13 @@ export class Outbox {
|
|
|
267
296
|
shouldGroup ? this.params.groupingManager.groupBatch(rawBatch) : rawBatch,
|
|
268
297
|
);
|
|
269
298
|
clientSequenceNumber = this.sendBatch(processedBatch);
|
|
299
|
+
assert(
|
|
300
|
+
clientSequenceNumber === undefined || clientSequenceNumber >= 0,
|
|
301
|
+
0x9d2 /* unexpected negative clientSequenceNumber (empty batch should yield undefined) */,
|
|
302
|
+
);
|
|
270
303
|
}
|
|
271
304
|
|
|
272
|
-
this.params.pendingStateManager.onFlushBatch(rawBatch.
|
|
305
|
+
this.params.pendingStateManager.onFlushBatch(rawBatch.messages, clientSequenceNumber);
|
|
273
306
|
}
|
|
274
307
|
|
|
275
308
|
/**
|
|
@@ -283,7 +316,7 @@ export class Outbox {
|
|
|
283
316
|
assert(batchManager.options.canRebase, 0x9a7 /* BatchManager does not support rebase */);
|
|
284
317
|
|
|
285
318
|
this.rebasing = true;
|
|
286
|
-
for (const message of rawBatch.
|
|
319
|
+
for (const message of rawBatch.messages) {
|
|
287
320
|
this.params.reSubmit({
|
|
288
321
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
289
322
|
content: message.contents!,
|
|
@@ -293,10 +326,10 @@ export class Outbox {
|
|
|
293
326
|
}
|
|
294
327
|
|
|
295
328
|
if (this.batchRebasesToReport > 0) {
|
|
296
|
-
this.
|
|
329
|
+
this.logger.sendTelemetryEvent(
|
|
297
330
|
{
|
|
298
331
|
eventName: "BatchRebase",
|
|
299
|
-
length: rawBatch.
|
|
332
|
+
length: rawBatch.messages.length,
|
|
300
333
|
referenceSequenceNumber: rawBatch.referenceSequenceNumber,
|
|
301
334
|
},
|
|
302
335
|
new UsageError("BatchRebase"),
|
|
@@ -323,7 +356,7 @@ export class Outbox {
|
|
|
323
356
|
*/
|
|
324
357
|
private compressBatch(batch: IBatch): IBatch {
|
|
325
358
|
if (
|
|
326
|
-
batch.
|
|
359
|
+
batch.messages.length === 0 ||
|
|
327
360
|
this.params.config.compressionOptions === undefined ||
|
|
328
361
|
this.params.config.compressionOptions.minimumBatchSizeInBytes >
|
|
329
362
|
batch.contentSizeInBytes ||
|
|
@@ -345,7 +378,7 @@ export class Outbox {
|
|
|
345
378
|
throw new GenericError("BatchTooLarge", /* error */ undefined, {
|
|
346
379
|
batchSize: batch.contentSizeInBytes,
|
|
347
380
|
compressedBatchSize: compressedBatch.contentSizeInBytes,
|
|
348
|
-
count: compressedBatch.
|
|
381
|
+
count: compressedBatch.messages.length,
|
|
349
382
|
limit: this.params.config.maxBatchSizeInBytes,
|
|
350
383
|
chunkingEnabled: this.params.splitter.isBatchChunkingEnabled,
|
|
351
384
|
compressionOptions: JSON.stringify(this.params.config.compressionOptions),
|
|
@@ -363,16 +396,16 @@ export class Outbox {
|
|
|
363
396
|
* @returns the clientSequenceNumber of the start of the batch, or undefined if nothing was sent
|
|
364
397
|
*/
|
|
365
398
|
private sendBatch(batch: IBatch) {
|
|
366
|
-
const length = batch.
|
|
399
|
+
const length = batch.messages.length;
|
|
367
400
|
if (length === 0) {
|
|
368
401
|
return undefined; // Nothing submitted
|
|
369
402
|
}
|
|
370
403
|
|
|
371
404
|
const socketSize = estimateSocketSize(batch);
|
|
372
405
|
if (socketSize >= this.params.config.maxBatchSizeInBytes) {
|
|
373
|
-
this.
|
|
406
|
+
this.logger.sendPerformanceEvent({
|
|
374
407
|
eventName: "LargeBatch",
|
|
375
|
-
length: batch.
|
|
408
|
+
length: batch.messages.length,
|
|
376
409
|
sizeInBytes: batch.contentSizeInBytes,
|
|
377
410
|
socketSize,
|
|
378
411
|
});
|
|
@@ -383,7 +416,9 @@ export class Outbox {
|
|
|
383
416
|
// Legacy path - supporting old loader versions. Can be removed only when LTS moves above
|
|
384
417
|
// version that has support for batches (submitBatchFn)
|
|
385
418
|
assert(
|
|
386
|
-
|
|
419
|
+
// Non null asserting here because of the length check above
|
|
420
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
421
|
+
batch.messages[0]!.compression === undefined,
|
|
387
422
|
0x5a6 /* Compression should not have happened if the loader does not support it */,
|
|
388
423
|
);
|
|
389
424
|
|
|
@@ -391,7 +426,7 @@ export class Outbox {
|
|
|
391
426
|
} else {
|
|
392
427
|
assert(batch.referenceSequenceNumber !== undefined, 0x58e /* Batch must not be empty */);
|
|
393
428
|
clientSequenceNumber = this.params.submitBatchFn(
|
|
394
|
-
batch.
|
|
429
|
+
batch.messages.map<IBatchMessage>((message) => ({
|
|
395
430
|
contents: message.contents,
|
|
396
431
|
metadata: message.metadata,
|
|
397
432
|
compression: message.compression,
|
|
@@ -407,7 +442,10 @@ export class Outbox {
|
|
|
407
442
|
return clientSequenceNumber;
|
|
408
443
|
}
|
|
409
444
|
|
|
410
|
-
|
|
445
|
+
/**
|
|
446
|
+
* @returns A checkpoint object per batch that facilitates iterating over the batch messages when rolling back.
|
|
447
|
+
*/
|
|
448
|
+
public getBatchCheckpoints() {
|
|
411
449
|
// This variable is declared with a specific type so that we have a standard import of the IBatchCheckpoint type.
|
|
412
450
|
// When the type is inferred, the generated .d.ts uses a dynamic import which doesn't resolve.
|
|
413
451
|
const mainBatch: IBatchCheckpoint = this.mainBatch.checkpoint();
|
|
@@ -13,9 +13,9 @@ import {
|
|
|
13
13
|
ContainerMessageType,
|
|
14
14
|
type InboundContainerRuntimeMessage,
|
|
15
15
|
type InboundSequencedContainerRuntimeMessage,
|
|
16
|
-
type InboundSequencedContainerRuntimeMessageOrSystemMessage,
|
|
17
16
|
type InboundSequencedRecentlyAddedContainerRuntimeMessage,
|
|
18
17
|
} from "../messageTypes.js";
|
|
18
|
+
import { asBatchMetadata } from "../metadata.js";
|
|
19
19
|
|
|
20
20
|
import { OpDecompressor } from "./opDecompressor.js";
|
|
21
21
|
import { OpGroupingManager, isGroupedBatch } from "./opGroupingManager.js";
|
|
@@ -35,6 +35,7 @@ export class RemoteMessageProcessor {
|
|
|
35
35
|
* @remarks For chunked batches, this is the CSN of the "representative" chunk (the final chunk)
|
|
36
36
|
*/
|
|
37
37
|
private batchStartCsn: number | undefined;
|
|
38
|
+
private readonly processorBatch: InboundSequencedContainerRuntimeMessage[] = [];
|
|
38
39
|
|
|
39
40
|
constructor(
|
|
40
41
|
private readonly opSplitter: OpSplitter,
|
|
@@ -51,7 +52,7 @@ export class RemoteMessageProcessor {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
/**
|
|
54
|
-
* Ungroups and Unchunks the runtime ops
|
|
55
|
+
* Ungroups and Unchunks the runtime ops of a batch received over the wire
|
|
55
56
|
* @param remoteMessageCopy - A shallow copy of a message from another client, possibly virtualized
|
|
56
57
|
* (grouped, compressed, and/or chunked).
|
|
57
58
|
* Being a shallow copy, it's considered mutable, meaning no other Container or other parallel procedure
|
|
@@ -66,20 +67,20 @@ export class RemoteMessageProcessor {
|
|
|
66
67
|
* 3. If grouped, ungroup the message
|
|
67
68
|
* For more details, see https://github.com/microsoft/FluidFramework/blob/main/packages/runtime/container-runtime/src/opLifecycle/README.md#inbound
|
|
68
69
|
*
|
|
69
|
-
* @returns the unchunked, decompressed, ungrouped, unpacked
|
|
70
|
-
*
|
|
71
|
-
* a singleton array [remoteMessageCopy] is returned
|
|
70
|
+
* @returns all the unchunked, decompressed, ungrouped, unpacked InboundSequencedContainerRuntimeMessage from a single batch
|
|
71
|
+
* or undefined if the batch is not yet complete.
|
|
72
72
|
*/
|
|
73
|
-
public process(
|
|
73
|
+
public process(
|
|
74
|
+
remoteMessageCopy: ISequencedDocumentMessage,
|
|
75
|
+
logLegacyCase: (codePath: string) => void,
|
|
76
|
+
):
|
|
74
77
|
| {
|
|
75
|
-
messages:
|
|
78
|
+
messages: InboundSequencedContainerRuntimeMessage[];
|
|
76
79
|
batchStartCsn: number;
|
|
77
80
|
}
|
|
78
81
|
| undefined {
|
|
79
82
|
let message = remoteMessageCopy;
|
|
80
83
|
|
|
81
|
-
ensureContentsDeserialized(message);
|
|
82
|
-
|
|
83
84
|
if (isChunkedMessage(message)) {
|
|
84
85
|
const chunkProcessingResult = this.opSplitter.processChunk(message);
|
|
85
86
|
// Only continue further if current chunk is the final chunk
|
|
@@ -104,7 +105,14 @@ export class RemoteMessageProcessor {
|
|
|
104
105
|
|
|
105
106
|
if (isGroupedBatch(message)) {
|
|
106
107
|
// We should be awaiting a new batch (batchStartCsn undefined)
|
|
107
|
-
assert(
|
|
108
|
+
assert(
|
|
109
|
+
this.batchStartCsn === undefined,
|
|
110
|
+
0x9d3 /* Grouped batch interrupting another batch */,
|
|
111
|
+
);
|
|
112
|
+
assert(
|
|
113
|
+
this.processorBatch.length === 0,
|
|
114
|
+
0x9d4 /* Processor batch should be empty on grouped batch */,
|
|
115
|
+
);
|
|
108
116
|
return {
|
|
109
117
|
messages: this.opGroupingManager.ungroupOp(message).map(unpack),
|
|
110
118
|
batchStartCsn: message.clientSequenceNumber,
|
|
@@ -114,9 +122,21 @@ export class RemoteMessageProcessor {
|
|
|
114
122
|
const batchStartCsn = this.getAndUpdateBatchStartCsn(message);
|
|
115
123
|
|
|
116
124
|
// Do a final unpack of runtime messages in case the message was not grouped, compressed, or chunked
|
|
117
|
-
unpackRuntimeMessage(message);
|
|
125
|
+
unpackRuntimeMessage(message, logLegacyCase);
|
|
126
|
+
this.processorBatch.push(message as InboundSequencedContainerRuntimeMessage);
|
|
127
|
+
|
|
128
|
+
// this.batchStartCsn is undefined only if we have processed all messages in the batch.
|
|
129
|
+
// If it's still defined, we're still in the middle of a batch, so we return nothing, letting
|
|
130
|
+
// containerRuntime know that we're waiting for more messages to complete the batch.
|
|
131
|
+
if (this.batchStartCsn !== undefined) {
|
|
132
|
+
// batch not yet complete
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const messages = [...this.processorBatch];
|
|
137
|
+
this.processorBatch.length = 0;
|
|
118
138
|
return {
|
|
119
|
-
messages
|
|
139
|
+
messages,
|
|
120
140
|
batchStartCsn,
|
|
121
141
|
};
|
|
122
142
|
}
|
|
@@ -127,10 +147,10 @@ export class RemoteMessageProcessor {
|
|
|
127
147
|
* the batch tracking info (this.batchStartCsn) based on whether we're still mid-batch.
|
|
128
148
|
*/
|
|
129
149
|
private getAndUpdateBatchStartCsn(message: ISequencedDocumentMessage): number {
|
|
130
|
-
const batchMetadataFlag = (message.metadata
|
|
150
|
+
const batchMetadataFlag = asBatchMetadata(message.metadata)?.batch;
|
|
131
151
|
if (this.batchStartCsn === undefined) {
|
|
132
152
|
// We are waiting for a new batch
|
|
133
|
-
assert(batchMetadataFlag !== false,
|
|
153
|
+
assert(batchMetadataFlag !== false, 0x9d5 /* Unexpected batch end marker */);
|
|
134
154
|
|
|
135
155
|
// Start of a new multi-message batch
|
|
136
156
|
if (batchMetadataFlag === true) {
|
|
@@ -146,7 +166,7 @@ export class RemoteMessageProcessor {
|
|
|
146
166
|
// We are in the middle or end of an existing multi-message batch. Return the current batchStartCsn
|
|
147
167
|
const batchStartCsn = this.batchStartCsn;
|
|
148
168
|
|
|
149
|
-
assert(batchMetadataFlag !== true,
|
|
169
|
+
assert(batchMetadataFlag !== true, 0x9d6 /* Unexpected batch start marker */);
|
|
150
170
|
if (batchMetadataFlag === false) {
|
|
151
171
|
// Batch end? Then get ready for the next batch to start
|
|
152
172
|
this.batchStartCsn = undefined;
|
|
@@ -157,12 +177,27 @@ export class RemoteMessageProcessor {
|
|
|
157
177
|
}
|
|
158
178
|
|
|
159
179
|
/** Takes an incoming message and if the contents is a string, JSON.parse's it in place */
|
|
160
|
-
function ensureContentsDeserialized(
|
|
180
|
+
export function ensureContentsDeserialized(
|
|
181
|
+
mutableMessage: ISequencedDocumentMessage,
|
|
182
|
+
modernRuntimeMessage: boolean,
|
|
183
|
+
logLegacyCase: (codePath: string) => void,
|
|
184
|
+
): void {
|
|
161
185
|
// back-compat: ADO #1385: eventually should become unconditional, but only for runtime messages!
|
|
162
186
|
// System message may have no contents, or in some cases (mostly for back-compat) they may have actual objects.
|
|
163
187
|
// Old ops may contain empty string (I assume noops).
|
|
188
|
+
let parsedJsonContents: boolean;
|
|
164
189
|
if (typeof mutableMessage.contents === "string" && mutableMessage.contents !== "") {
|
|
165
190
|
mutableMessage.contents = JSON.parse(mutableMessage.contents);
|
|
191
|
+
parsedJsonContents = true;
|
|
192
|
+
} else {
|
|
193
|
+
parsedJsonContents = false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// We expect Modern Runtime Messages to have JSON serialized contents,
|
|
197
|
+
// and all other messages not to (system messages and legacy runtime messages without outer "op" type envelope)
|
|
198
|
+
// Let's observe if we are wrong about this to learn about these cases.
|
|
199
|
+
if (modernRuntimeMessage !== parsedJsonContents) {
|
|
200
|
+
logLegacyCase("ensureContentsDeserialized_unexpectedContentsType");
|
|
166
201
|
}
|
|
167
202
|
}
|
|
168
203
|
|
|
@@ -198,7 +233,10 @@ function unpack(message: ISequencedDocumentMessage): InboundSequencedContainerRu
|
|
|
198
233
|
*
|
|
199
234
|
* @internal
|
|
200
235
|
*/
|
|
201
|
-
export function unpackRuntimeMessage(
|
|
236
|
+
export function unpackRuntimeMessage(
|
|
237
|
+
message: ISequencedDocumentMessage,
|
|
238
|
+
logLegacyCase: (codePath: string) => void = () => {},
|
|
239
|
+
): boolean {
|
|
202
240
|
if (message.type !== MessageType.Operation) {
|
|
203
241
|
// Legacy format, but it's already "unpacked",
|
|
204
242
|
// i.e. message.type is actually ContainerMessageType.
|
|
@@ -214,6 +252,7 @@ export function unpackRuntimeMessage(message: ISequencedDocumentMessage): boolea
|
|
|
214
252
|
(message.contents as { type?: unknown }).type === undefined
|
|
215
253
|
) {
|
|
216
254
|
message.type = ContainerMessageType.FluidDataStoreOp;
|
|
255
|
+
logLegacyCase("unpackRuntimeMessage_contentsWithAddress");
|
|
217
256
|
} else {
|
|
218
257
|
// new format
|
|
219
258
|
unpack(message);
|
package/src/packageVersion.ts
CHANGED