@fluidframework/container-runtime 2.4.0 → 2.5.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 (95) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/api-report/container-runtime.legacy.alpha.api.md +3 -1
  3. package/container-runtime.test-files.tar +0 -0
  4. package/dist/blobManager/blobManager.d.ts +3 -3
  5. package/dist/blobManager/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager/blobManager.js +1 -1
  7. package/dist/blobManager/blobManager.js.map +1 -1
  8. package/dist/channelCollection.d.ts +20 -5
  9. package/dist/channelCollection.d.ts.map +1 -1
  10. package/dist/channelCollection.js +183 -119
  11. package/dist/channelCollection.js.map +1 -1
  12. package/dist/containerRuntime.d.ts +12 -4
  13. package/dist/containerRuntime.d.ts.map +1 -1
  14. package/dist/containerRuntime.js +155 -66
  15. package/dist/containerRuntime.js.map +1 -1
  16. package/dist/dataStoreContext.d.ts +15 -3
  17. package/dist/dataStoreContext.d.ts.map +1 -1
  18. package/dist/dataStoreContext.js +48 -19
  19. package/dist/dataStoreContext.js.map +1 -1
  20. package/dist/gc/garbageCollection.d.ts +5 -6
  21. package/dist/gc/garbageCollection.d.ts.map +1 -1
  22. package/dist/gc/garbageCollection.js +23 -22
  23. package/dist/gc/garbageCollection.js.map +1 -1
  24. package/dist/gc/gcDefinitions.d.ts +2 -2
  25. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  26. package/dist/gc/gcDefinitions.js.map +1 -1
  27. package/dist/opLifecycle/outbox.d.ts +3 -0
  28. package/dist/opLifecycle/outbox.d.ts.map +1 -1
  29. package/dist/opLifecycle/outbox.js +9 -0
  30. package/dist/opLifecycle/outbox.js.map +1 -1
  31. package/dist/opLifecycle/remoteMessageProcessor.d.ts +1 -0
  32. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  33. package/dist/opLifecycle/remoteMessageProcessor.js +2 -0
  34. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  35. package/dist/opProperties.js +1 -1
  36. package/dist/opProperties.js.map +1 -1
  37. package/dist/packageVersion.d.ts +1 -1
  38. package/dist/packageVersion.js +1 -1
  39. package/dist/packageVersion.js.map +1 -1
  40. package/dist/summary/documentSchema.d.ts +11 -0
  41. package/dist/summary/documentSchema.d.ts.map +1 -1
  42. package/dist/summary/documentSchema.js +45 -30
  43. package/dist/summary/documentSchema.js.map +1 -1
  44. package/lib/blobManager/blobManager.d.ts +3 -3
  45. package/lib/blobManager/blobManager.d.ts.map +1 -1
  46. package/lib/blobManager/blobManager.js +1 -1
  47. package/lib/blobManager/blobManager.js.map +1 -1
  48. package/lib/channelCollection.d.ts +20 -5
  49. package/lib/channelCollection.d.ts.map +1 -1
  50. package/lib/channelCollection.js +183 -119
  51. package/lib/channelCollection.js.map +1 -1
  52. package/lib/containerRuntime.d.ts +12 -4
  53. package/lib/containerRuntime.d.ts.map +1 -1
  54. package/lib/containerRuntime.js +155 -66
  55. package/lib/containerRuntime.js.map +1 -1
  56. package/lib/dataStoreContext.d.ts +15 -3
  57. package/lib/dataStoreContext.d.ts.map +1 -1
  58. package/lib/dataStoreContext.js +48 -19
  59. package/lib/dataStoreContext.js.map +1 -1
  60. package/lib/gc/garbageCollection.d.ts +5 -6
  61. package/lib/gc/garbageCollection.d.ts.map +1 -1
  62. package/lib/gc/garbageCollection.js +23 -22
  63. package/lib/gc/garbageCollection.js.map +1 -1
  64. package/lib/gc/gcDefinitions.d.ts +2 -2
  65. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  66. package/lib/gc/gcDefinitions.js.map +1 -1
  67. package/lib/opLifecycle/outbox.d.ts +3 -0
  68. package/lib/opLifecycle/outbox.d.ts.map +1 -1
  69. package/lib/opLifecycle/outbox.js +9 -0
  70. package/lib/opLifecycle/outbox.js.map +1 -1
  71. package/lib/opLifecycle/remoteMessageProcessor.d.ts +1 -0
  72. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  73. package/lib/opLifecycle/remoteMessageProcessor.js +2 -0
  74. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  75. package/lib/opProperties.js +1 -1
  76. package/lib/opProperties.js.map +1 -1
  77. package/lib/packageVersion.d.ts +1 -1
  78. package/lib/packageVersion.js +1 -1
  79. package/lib/packageVersion.js.map +1 -1
  80. package/lib/summary/documentSchema.d.ts +11 -0
  81. package/lib/summary/documentSchema.d.ts.map +1 -1
  82. package/lib/summary/documentSchema.js +45 -30
  83. package/lib/summary/documentSchema.js.map +1 -1
  84. package/package.json +24 -24
  85. package/src/blobManager/blobManager.ts +2 -2
  86. package/src/channelCollection.ts +227 -160
  87. package/src/containerRuntime.ts +197 -80
  88. package/src/dataStoreContext.ts +66 -23
  89. package/src/gc/garbageCollection.ts +32 -32
  90. package/src/gc/gcDefinitions.ts +3 -3
  91. package/src/opLifecycle/outbox.ts +12 -0
  92. package/src/opLifecycle/remoteMessageProcessor.ts +3 -0
  93. package/src/opProperties.ts +1 -1
  94. package/src/packageVersion.ts +1 -1
  95. package/src/summary/documentSchema.ts +58 -39
@@ -256,87 +256,93 @@ class ChannelCollection {
256
256
  makeVisibleAndAttachGraph() {
257
257
  this.parentContext.makeLocallyVisible();
258
258
  }
259
- processAttachMessage(message, local) {
260
- const attachMessage = message.contents;
261
- // We need to process the GC Data for both local and remote attach messages
262
- const foundGCData = (0, internal_5.processAttachMessageGCData)(attachMessage.snapshot, (nodeId, toPath) => {
263
- // nodeId is the relative path under the node being attached. Always starts with "/", but no trailing "/" after an id
264
- const fromPath = `/${attachMessage.id}${nodeId === "/" ? "" : nodeId}`;
265
- this.parentContext.addedGCOutboundRoute(fromPath, toPath, message.timestamp);
266
- });
267
- // Only log once per container to avoid noise/cost.
268
- // Allows longitudinal tracking of various state (e.g. foundGCData), and some sampled details
269
- if (this.shouldSendAttachLog) {
270
- this.shouldSendAttachLog = false;
271
- this.mc.logger.sendTelemetryEvent({
272
- eventName: "dataStoreAttachMessage_sampled",
273
- ...(0, internal_6.tagCodeArtifacts)({ id: attachMessage.id, pkg: attachMessage.type }),
274
- details: {
275
- local,
276
- snapshot: !!attachMessage.snapshot,
277
- foundGCData,
278
- },
279
- ...(0, internal_6.extractSafePropertiesFromMessage)(message),
280
- });
281
- }
282
- // The local object has already been attached
283
- if (local) {
284
- (0, internal_1.assert)(this.pendingAttach.has(attachMessage.id), 0x15e /* "Local object does not have matching attach message id" */);
285
- this.contexts.get(attachMessage.id)?.setAttachState(container_definitions_1.AttachState.Attached);
286
- this.pendingAttach.delete(attachMessage.id);
287
- return;
288
- }
289
- // If a non-local operation then go and create the object, otherwise mark it as officially attached.
290
- if (this.alreadyProcessed(attachMessage.id)) {
291
- // TODO: dataStoreId may require a different tag from PackageData #7488
292
- const error = new internal_6.DataCorruptionError(
293
- // pre-0.58 error message: duplicateDataStoreCreatedWithExistingId
294
- "Duplicate DataStore created with existing id", {
295
- ...(0, internal_6.extractSafePropertiesFromMessage)(message),
296
- ...(0, internal_6.tagCodeArtifacts)({ dataStoreId: attachMessage.id }),
259
+ processAttachMessages(messageCollection) {
260
+ const { envelope, messagesContent, local } = messageCollection;
261
+ for (const { contents } of messagesContent) {
262
+ const attachMessage = contents;
263
+ // We need to process the GC Data for both local and remote attach messages
264
+ const foundGCData = (0, internal_5.processAttachMessageGCData)(attachMessage.snapshot, (nodeId, toPath) => {
265
+ // nodeId is the relative path under the node being attached. Always starts with "/", but no trailing "/" after an id
266
+ const fromPath = `/${attachMessage.id}${nodeId === "/" ? "" : nodeId}`;
267
+ this.parentContext.addedGCOutboundRoute(fromPath, toPath, envelope.timestamp);
297
268
  });
298
- throw error;
299
- }
300
- const flatAttachBlobs = new Map();
301
- let snapshot;
302
- if (attachMessage.snapshot) {
303
- snapshot = (0, internal_3.buildSnapshotTree)(attachMessage.snapshot.entries, flatAttachBlobs);
304
- if ((0, internal_3.isInstanceOfISnapshot)(this.baseSnapshot)) {
305
- snapshot = { ...this.baseSnapshot, snapshotTree: snapshot };
269
+ // Only log once per container to avoid noise/cost.
270
+ // Allows longitudinal tracking of various state (e.g. foundGCData), and some sampled details
271
+ if (this.shouldSendAttachLog) {
272
+ this.shouldSendAttachLog = false;
273
+ this.mc.logger.sendTelemetryEvent({
274
+ eventName: "dataStoreAttachMessage_sampled",
275
+ ...(0, internal_6.tagCodeArtifacts)({ id: attachMessage.id, pkg: attachMessage.type }),
276
+ details: {
277
+ local,
278
+ snapshot: !!attachMessage.snapshot,
279
+ foundGCData,
280
+ },
281
+ ...(0, internal_6.extractSafePropertiesFromMessage)(envelope),
282
+ });
306
283
  }
307
- }
308
- // Include the type of attach message which is the pkg of the store to be
309
- // used by RemoteFluidDataStoreContext in case it is not in the snapshot.
310
- const pkg = [attachMessage.type];
311
- const remoteFluidDataStoreContext = new dataStoreContext_js_1.RemoteFluidDataStoreContext({
312
- id: attachMessage.id,
313
- snapshot,
314
- parentContext: this.wrapContextForInnerChannel(attachMessage.id),
315
- storage: new storageServiceWithAttachBlobs_js_1.StorageServiceWithAttachBlobs(this.parentContext.storage, flatAttachBlobs),
316
- scope: this.parentContext.scope,
317
- loadingGroupId: attachMessage.snapshot?.groupId,
318
- createSummarizerNodeFn: this.parentContext.getCreateChildSummarizerNodeFn(attachMessage.id, {
319
- type: internal_4.CreateSummarizerNodeSource.FromAttach,
320
- sequenceNumber: message.sequenceNumber,
321
- snapshot: attachMessage.snapshot ?? {
322
- entries: [(0, dataStoreContext_js_1.createAttributesBlob)(pkg, true /* isRootDataStore */)],
323
- },
324
- }),
325
- pkg,
326
- });
327
- this.contexts.addBoundOrRemoted(remoteFluidDataStoreContext);
328
- }
329
- processAliasMessage(message, localOpMetadata, local) {
330
- const aliasMessage = message.contents;
331
- if (!(0, dataStore_js_1.isDataStoreAliasMessage)(aliasMessage)) {
332
- throw new internal_6.DataCorruptionError("malformedDataStoreAliasMessage", {
333
- ...(0, internal_6.extractSafePropertiesFromMessage)(message),
284
+ // The local object has already been attached
285
+ if (local) {
286
+ (0, internal_1.assert)(this.pendingAttach.has(attachMessage.id), 0x15e /* "Local object does not have matching attach message id" */);
287
+ this.contexts.get(attachMessage.id)?.setAttachState(container_definitions_1.AttachState.Attached);
288
+ this.pendingAttach.delete(attachMessage.id);
289
+ continue;
290
+ }
291
+ // If a non-local operation then go and create the object, otherwise mark it as officially attached.
292
+ if (this.alreadyProcessed(attachMessage.id)) {
293
+ // TODO: dataStoreId may require a different tag from PackageData #7488
294
+ const error = new internal_6.DataCorruptionError(
295
+ // pre-0.58 error message: duplicateDataStoreCreatedWithExistingId
296
+ "Duplicate DataStore created with existing id", {
297
+ ...(0, internal_6.extractSafePropertiesFromMessage)(envelope),
298
+ ...(0, internal_6.tagCodeArtifacts)({ dataStoreId: attachMessage.id }),
299
+ });
300
+ throw error;
301
+ }
302
+ const flatAttachBlobs = new Map();
303
+ let snapshot;
304
+ if (attachMessage.snapshot) {
305
+ snapshot = (0, internal_3.buildSnapshotTree)(attachMessage.snapshot.entries, flatAttachBlobs);
306
+ if ((0, internal_3.isInstanceOfISnapshot)(this.baseSnapshot)) {
307
+ snapshot = { ...this.baseSnapshot, snapshotTree: snapshot };
308
+ }
309
+ }
310
+ // Include the type of attach message which is the pkg of the store to be
311
+ // used by RemoteFluidDataStoreContext in case it is not in the snapshot.
312
+ const pkg = [attachMessage.type];
313
+ const remoteFluidDataStoreContext = new dataStoreContext_js_1.RemoteFluidDataStoreContext({
314
+ id: attachMessage.id,
315
+ snapshot,
316
+ parentContext: this.wrapContextForInnerChannel(attachMessage.id),
317
+ storage: new storageServiceWithAttachBlobs_js_1.StorageServiceWithAttachBlobs(this.parentContext.storage, flatAttachBlobs),
318
+ scope: this.parentContext.scope,
319
+ loadingGroupId: attachMessage.snapshot?.groupId,
320
+ createSummarizerNodeFn: this.parentContext.getCreateChildSummarizerNodeFn(attachMessage.id, {
321
+ type: internal_4.CreateSummarizerNodeSource.FromAttach,
322
+ sequenceNumber: envelope.sequenceNumber,
323
+ snapshot: attachMessage.snapshot ?? {
324
+ entries: [(0, dataStoreContext_js_1.createAttributesBlob)(pkg, true /* isRootDataStore */)],
325
+ },
326
+ }),
327
+ pkg,
334
328
  });
329
+ this.contexts.addBoundOrRemoted(remoteFluidDataStoreContext);
335
330
  }
336
- const resolve = localOpMetadata;
337
- const aliasResult = this.processAliasMessageCore(aliasMessage.internalId, aliasMessage.alias, message.timestamp);
338
- if (local) {
339
- resolve(aliasResult);
331
+ }
332
+ processAliasMessages(messageCollection) {
333
+ const { envelope, messagesContent, local } = messageCollection;
334
+ for (const { contents, localOpMetadata } of messagesContent) {
335
+ const aliasMessage = contents;
336
+ if (!(0, dataStore_js_1.isDataStoreAliasMessage)(aliasMessage)) {
337
+ throw new internal_6.DataCorruptionError("malformedDataStoreAliasMessage", {
338
+ ...(0, internal_6.extractSafePropertiesFromMessage)(envelope),
339
+ });
340
+ }
341
+ const resolve = localOpMetadata;
342
+ const aliasResult = this.processAliasMessageCore(aliasMessage.internalId, aliasMessage.alias, envelope.timestamp);
343
+ if (local) {
344
+ resolve(aliasResult);
345
+ }
340
346
  }
341
347
  }
342
348
  processAliasMessageCore(internalId, alias, messageTimestampMs) {
@@ -583,58 +589,116 @@ class ChannelCollection {
583
589
  this.pendingAttach.set(message.id, message);
584
590
  }
585
591
  }
586
- process(message, local, localMessageMetadata) {
587
- switch (message.type) {
592
+ /**
593
+ * Process messages for this channel collection. The messages here are contiguous messages in a batch.
594
+ * @param messageCollection - The collection of messages to process.
595
+ */
596
+ processMessages(messageCollection) {
597
+ switch (messageCollection.envelope.type) {
598
+ case messageTypes_js_1.ContainerMessageType.FluidDataStoreOp:
599
+ this.processChannelMessages(messageCollection);
600
+ break;
588
601
  case messageTypes_js_1.ContainerMessageType.Attach:
589
- this.processAttachMessage(message, local);
590
- return;
602
+ this.processAttachMessages(messageCollection);
603
+ break;
591
604
  case messageTypes_js_1.ContainerMessageType.Alias:
592
- this.processAliasMessage(message, localMessageMetadata, local);
593
- return;
594
- case messageTypes_js_1.ContainerMessageType.FluidDataStoreOp: {
595
- const envelope = message.contents;
596
- const innerContents = envelope.contents;
597
- const transformed = {
598
- ...message,
599
- type: innerContents.type,
600
- contents: innerContents.content,
601
- };
602
- this.processChannelOp(envelope.address, transformed, local, localMessageMetadata);
603
- // Notify GC of any outbound references that were added by this op.
604
- detectOutboundReferences(envelope.address, transformed.contents, (fromPath, toPath) => this.parentContext.addedGCOutboundRoute(fromPath, toPath, message.timestamp));
605
+ this.processAliasMessages(messageCollection);
605
606
  break;
606
- }
607
607
  default:
608
608
  (0, internal_1.assert)(false, 0x8e9 /* unreached */);
609
609
  }
610
610
  }
611
- processChannelOp(address, message, local, localMessageMetadata) {
612
- const context = this.contexts.get(address);
613
- // If the data store has been deleted, log an error and ignore this message. This helps prevent document
614
- // corruption in case a deleted data store accidentally submitted an op.
615
- if (this.checkAndLogIfDeleted(address, context, "Changed", "processFluidDataStoreOp")) {
616
- return;
617
- }
618
- if (context === undefined) {
619
- // Former assert 0x162
620
- throw internal_6.DataProcessingError.create("No context for op", "processFluidDataStoreOp", message, {
611
+ /**
612
+ * This is still here for back-compat purposes because channel collection implements
613
+ * IFluidDataStoreChannel. Once it is removed from the interface, this method can be removed.
614
+ * Container runtime calls `processMessages` instead.
615
+ */
616
+ process(message, local, localOpMetadata) {
617
+ this.processMessages({
618
+ envelope: message,
619
+ messagesContent: [
620
+ {
621
+ contents: message.contents,
622
+ localOpMetadata,
623
+ clientSequenceNumber: message.clientSequenceNumber,
624
+ },
625
+ ],
626
+ local,
627
+ });
628
+ }
629
+ /**
630
+ * Process channel messages. The messages here are contiguous channel type messages in a batch. Bunch
631
+ * of contiguous messages for a data store should be sent to it together.
632
+ * @param messageCollection - The collection of messages to process.
633
+ */
634
+ processChannelMessages(messageCollection) {
635
+ const { messagesContent, local } = messageCollection;
636
+ let currentMessageState;
637
+ let currentMessagesContent = [];
638
+ // Helper that sends the current bunch of messages to the data store. It validates that the data stores exists.
639
+ const sendBunchedMessages = () => {
640
+ // Current message state will be undefined for the first message in the list.
641
+ if (currentMessageState === undefined) {
642
+ return;
643
+ }
644
+ const currentContext = this.contexts.get(currentMessageState.address);
645
+ (0, internal_1.assert)(!!currentContext, 0xa66 /* Context not found */);
646
+ currentContext.processMessages({
647
+ envelope: { ...messageCollection.envelope, type: currentMessageState.type },
648
+ messagesContent: currentMessagesContent,
621
649
  local,
622
- messageDetails: JSON.stringify({
623
- type: message.type,
624
- contentType: typeof message.contents,
625
- }),
626
- ...(0, internal_6.tagCodeArtifacts)({ address }),
627
650
  });
651
+ currentMessagesContent = [];
652
+ };
653
+ /**
654
+ * Bunch contiguous messages for the same data store and send them together.
655
+ * This is an optimization mainly for DDSes, where it can process a bunch of ops together. DDSes
656
+ * like merge tree or shared tree can process ops more efficiently when they are bunched together.
657
+ */
658
+ for (const { contents, ...restOfMessagesContent } of messagesContent) {
659
+ const contentsEnvelope = contents;
660
+ const address = contentsEnvelope.address;
661
+ const context = this.contexts.get(address);
662
+ // If the data store has been deleted, log an error and ignore this message. This helps prevent document
663
+ // corruption in case a deleted data store accidentally submitted an op.
664
+ if (this.checkAndLogIfDeleted(address, context, "Changed", "processFluidDataStoreOp")) {
665
+ continue;
666
+ }
667
+ if (context === undefined) {
668
+ // Former assert 0x162
669
+ throw internal_6.DataProcessingError.create("No context for op", "processFluidDataStoreOp", messageCollection.envelope, {
670
+ local,
671
+ messageDetails: JSON.stringify({
672
+ type: messageCollection.envelope.type,
673
+ contentType: typeof contents,
674
+ }),
675
+ ...(0, internal_6.tagCodeArtifacts)({ address }),
676
+ });
677
+ }
678
+ const { type: contextType, content: contextContents } = contentsEnvelope.contents;
679
+ // If the address or type of the message changes while processing the message, send the current bunch.
680
+ if (currentMessageState?.address !== address ||
681
+ currentMessageState?.type !== contextType) {
682
+ sendBunchedMessages();
683
+ }
684
+ currentMessagesContent.push({
685
+ contents: contextContents,
686
+ ...restOfMessagesContent,
687
+ });
688
+ currentMessageState = { address, type: contextType };
689
+ // Notify that a GC node for the data store changed. This is used to detect if a deleted data store is
690
+ // being used.
691
+ this.gcNodeUpdated({
692
+ node: { type: "DataStore", path: `/${address}` },
693
+ reason: "Changed",
694
+ timestampMs: messageCollection.envelope.timestamp,
695
+ packagePath: context.isLoaded ? context.packagePath : undefined,
696
+ });
697
+ detectOutboundReferences(address, contextContents, (fromPath, toPath) => this.parentContext.addedGCOutboundRoute(fromPath, toPath, messageCollection.envelope.timestamp));
628
698
  }
629
- context.process(message, local, localMessageMetadata);
630
- // Notify that a GC node for the data store changed. This is used to detect if a deleted data store is
631
- // being used.
632
- this.gcNodeUpdated({
633
- node: { type: "DataStore", path: `/${address}` },
634
- reason: "Changed",
635
- timestampMs: message.timestamp,
636
- packagePath: context.isLoaded ? context.packagePath : undefined,
637
- });
699
+ // Process the last bunch of messages, if any. Note that there may not be any messages in case all of them are
700
+ // ignored because the data store is deleted.
701
+ sendBunchedMessages();
638
702
  }
639
703
  async getDataStore(id, requestHeaderData, originalRequest) {
640
704
  const headerData = { ...containerRuntime_js_1.defaultRuntimeHeaderData, ...requestHeaderData };