@fluidframework/container-runtime 2.0.0-internal.6.3.3 → 2.0.0-internal.6.4.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 (188) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/blobManager.d.ts +3 -2
  3. package/dist/blobManager.d.ts.map +1 -1
  4. package/dist/blobManager.js +29 -25
  5. package/dist/blobManager.js.map +1 -1
  6. package/dist/containerRuntime.d.ts +14 -69
  7. package/dist/containerRuntime.d.ts.map +1 -1
  8. package/dist/containerRuntime.js +155 -184
  9. package/dist/containerRuntime.js.map +1 -1
  10. package/dist/dataStoreContext.d.ts.map +1 -1
  11. package/dist/dataStoreContext.js +3 -1
  12. package/dist/dataStoreContext.js.map +1 -1
  13. package/dist/dataStores.d.ts +1 -1
  14. package/dist/dataStores.js +3 -3
  15. package/dist/dataStores.js.map +1 -1
  16. package/dist/gc/garbageCollection.d.ts +6 -3
  17. package/dist/gc/garbageCollection.d.ts.map +1 -1
  18. package/dist/gc/garbageCollection.js +6 -3
  19. package/dist/gc/garbageCollection.js.map +1 -1
  20. package/dist/gc/gcDefinitions.d.ts +13 -2
  21. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  22. package/dist/gc/gcDefinitions.js +14 -15
  23. package/dist/gc/gcDefinitions.js.map +1 -1
  24. package/dist/gc/gcHelpers.d.ts +0 -9
  25. package/dist/gc/gcHelpers.d.ts.map +1 -1
  26. package/dist/gc/gcHelpers.js +1 -13
  27. package/dist/gc/gcHelpers.js.map +1 -1
  28. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  29. package/dist/gc/gcTelemetry.js +1 -4
  30. package/dist/gc/gcTelemetry.js.map +1 -1
  31. package/dist/gc/index.d.ts +2 -2
  32. package/dist/gc/index.d.ts.map +1 -1
  33. package/dist/gc/index.js +3 -4
  34. package/dist/gc/index.js.map +1 -1
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +3 -2
  38. package/dist/index.js.map +1 -1
  39. package/dist/messageTypes.d.ts +134 -0
  40. package/dist/messageTypes.d.ts.map +1 -0
  41. package/dist/messageTypes.js +29 -0
  42. package/dist/messageTypes.js.map +1 -0
  43. package/dist/opLifecycle/definitions.d.ts +2 -1
  44. package/dist/opLifecycle/definitions.d.ts.map +1 -1
  45. package/dist/opLifecycle/definitions.js.map +1 -1
  46. package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
  47. package/dist/opLifecycle/opDecompressor.js +0 -4
  48. package/dist/opLifecycle/opDecompressor.js.map +1 -1
  49. package/dist/opLifecycle/opGroupingManager.d.ts.map +1 -1
  50. package/dist/opLifecycle/opGroupingManager.js +4 -2
  51. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  52. package/dist/opLifecycle/opSplitter.js +3 -3
  53. package/dist/opLifecycle/opSplitter.js.map +1 -1
  54. package/dist/opLifecycle/remoteMessageProcessor.d.ts +17 -3
  55. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  56. package/dist/opLifecycle/remoteMessageProcessor.js +38 -25
  57. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  58. package/dist/packageVersion.d.ts +1 -1
  59. package/dist/packageVersion.js +1 -1
  60. package/dist/packageVersion.js.map +1 -1
  61. package/dist/pendingStateManager.d.ts +2 -2
  62. package/dist/pendingStateManager.d.ts.map +1 -1
  63. package/dist/pendingStateManager.js +13 -6
  64. package/dist/pendingStateManager.js.map +1 -1
  65. package/dist/summary/runningSummarizer.d.ts +1 -1
  66. package/dist/summary/runningSummarizer.d.ts.map +1 -1
  67. package/dist/summary/runningSummarizer.js +4 -2
  68. package/dist/summary/runningSummarizer.js.map +1 -1
  69. package/dist/summary/summarizer.d.ts +2 -2
  70. package/dist/summary/summarizer.js +2 -2
  71. package/dist/summary/summarizer.js.map +1 -1
  72. package/dist/summary/summarizerNode/summarizerNode.d.ts +1 -1
  73. package/dist/summary/summarizerNode/summarizerNode.js +1 -1
  74. package/dist/summary/summarizerNode/summarizerNode.js.map +1 -1
  75. package/dist/summary/summarizerTypes.d.ts +2 -1
  76. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  77. package/dist/summary/summarizerTypes.js.map +1 -1
  78. package/dist/summary/summaryFormat.d.ts +3 -0
  79. package/dist/summary/summaryFormat.d.ts.map +1 -1
  80. package/dist/summary/summaryFormat.js +3 -0
  81. package/dist/summary/summaryFormat.js.map +1 -1
  82. package/lib/blobManager.d.ts +3 -2
  83. package/lib/blobManager.d.ts.map +1 -1
  84. package/lib/blobManager.js +30 -26
  85. package/lib/blobManager.js.map +1 -1
  86. package/lib/containerRuntime.d.ts +14 -69
  87. package/lib/containerRuntime.d.ts.map +1 -1
  88. package/lib/containerRuntime.js +121 -150
  89. package/lib/containerRuntime.js.map +1 -1
  90. package/lib/dataStoreContext.d.ts.map +1 -1
  91. package/lib/dataStoreContext.js +3 -1
  92. package/lib/dataStoreContext.js.map +1 -1
  93. package/lib/dataStores.d.ts +1 -1
  94. package/lib/dataStores.js +4 -4
  95. package/lib/dataStores.js.map +1 -1
  96. package/lib/gc/garbageCollection.d.ts +6 -3
  97. package/lib/gc/garbageCollection.d.ts.map +1 -1
  98. package/lib/gc/garbageCollection.js +6 -3
  99. package/lib/gc/garbageCollection.js.map +1 -1
  100. package/lib/gc/gcDefinitions.d.ts +13 -2
  101. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  102. package/lib/gc/gcDefinitions.js +13 -14
  103. package/lib/gc/gcDefinitions.js.map +1 -1
  104. package/lib/gc/gcHelpers.d.ts +0 -9
  105. package/lib/gc/gcHelpers.d.ts.map +1 -1
  106. package/lib/gc/gcHelpers.js +0 -11
  107. package/lib/gc/gcHelpers.js.map +1 -1
  108. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  109. package/lib/gc/gcTelemetry.js +1 -4
  110. package/lib/gc/gcTelemetry.js.map +1 -1
  111. package/lib/gc/index.d.ts +2 -2
  112. package/lib/gc/index.d.ts.map +1 -1
  113. package/lib/gc/index.js +2 -2
  114. package/lib/gc/index.js.map +1 -1
  115. package/lib/index.d.ts +2 -1
  116. package/lib/index.d.ts.map +1 -1
  117. package/lib/index.js +2 -1
  118. package/lib/index.js.map +1 -1
  119. package/lib/messageTypes.d.ts +134 -0
  120. package/lib/messageTypes.d.ts.map +1 -0
  121. package/lib/messageTypes.js +26 -0
  122. package/lib/messageTypes.js.map +1 -0
  123. package/lib/opLifecycle/definitions.d.ts +2 -1
  124. package/lib/opLifecycle/definitions.d.ts.map +1 -1
  125. package/lib/opLifecycle/definitions.js.map +1 -1
  126. package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
  127. package/lib/opLifecycle/opDecompressor.js +0 -4
  128. package/lib/opLifecycle/opDecompressor.js.map +1 -1
  129. package/lib/opLifecycle/opGroupingManager.d.ts.map +1 -1
  130. package/lib/opLifecycle/opGroupingManager.js +4 -2
  131. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  132. package/lib/opLifecycle/opSplitter.js +1 -1
  133. package/lib/opLifecycle/opSplitter.js.map +1 -1
  134. package/lib/opLifecycle/remoteMessageProcessor.d.ts +17 -3
  135. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  136. package/lib/opLifecycle/remoteMessageProcessor.js +37 -24
  137. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  138. package/lib/packageVersion.d.ts +1 -1
  139. package/lib/packageVersion.js +1 -1
  140. package/lib/packageVersion.js.map +1 -1
  141. package/lib/pendingStateManager.d.ts +2 -2
  142. package/lib/pendingStateManager.d.ts.map +1 -1
  143. package/lib/pendingStateManager.js +12 -5
  144. package/lib/pendingStateManager.js.map +1 -1
  145. package/lib/summary/runningSummarizer.d.ts +1 -1
  146. package/lib/summary/runningSummarizer.d.ts.map +1 -1
  147. package/lib/summary/runningSummarizer.js +4 -2
  148. package/lib/summary/runningSummarizer.js.map +1 -1
  149. package/lib/summary/summarizer.d.ts +2 -2
  150. package/lib/summary/summarizer.js +2 -2
  151. package/lib/summary/summarizer.js.map +1 -1
  152. package/lib/summary/summarizerNode/summarizerNode.d.ts +1 -1
  153. package/lib/summary/summarizerNode/summarizerNode.js +1 -1
  154. package/lib/summary/summarizerNode/summarizerNode.js.map +1 -1
  155. package/lib/summary/summarizerTypes.d.ts +2 -1
  156. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  157. package/lib/summary/summarizerTypes.js.map +1 -1
  158. package/lib/summary/summaryFormat.d.ts +3 -0
  159. package/lib/summary/summaryFormat.d.ts.map +1 -1
  160. package/lib/summary/summaryFormat.js +3 -0
  161. package/lib/summary/summaryFormat.js.map +1 -1
  162. package/package.json +16 -16
  163. package/src/blobManager.ts +38 -28
  164. package/src/containerRuntime.ts +181 -245
  165. package/src/dataStoreContext.ts +3 -1
  166. package/src/dataStores.ts +4 -4
  167. package/src/gc/garbageCollection.md +53 -5
  168. package/src/gc/garbageCollection.ts +6 -3
  169. package/src/gc/gcDefinitions.ts +13 -14
  170. package/src/gc/gcEarlyAdoption.md +145 -0
  171. package/src/gc/gcHelpers.ts +0 -12
  172. package/src/gc/gcTelemetry.ts +1 -4
  173. package/src/gc/index.ts +2 -3
  174. package/src/index.ts +7 -4
  175. package/src/messageTypes.ts +225 -0
  176. package/src/opLifecycle/README.md +40 -40
  177. package/src/opLifecycle/definitions.ts +2 -1
  178. package/src/opLifecycle/opDecompressor.ts +0 -8
  179. package/src/opLifecycle/opGroupingManager.ts +7 -6
  180. package/src/opLifecycle/opSplitter.ts +2 -2
  181. package/src/opLifecycle/remoteMessageProcessor.ts +54 -33
  182. package/src/packageVersion.ts +1 -1
  183. package/src/pendingStateManager.ts +23 -6
  184. package/src/summary/runningSummarizer.ts +4 -2
  185. package/src/summary/summarizer.ts +2 -2
  186. package/src/summary/summarizerNode/summarizerNode.ts +1 -1
  187. package/src/summary/summarizerTypes.ts +2 -1
  188. package/src/summary/summaryFormat.ts +3 -0
@@ -25,32 +25,12 @@ import { BindBatchTracker } from "./batchTracker";
25
25
  import { ScheduleManager } from "./scheduleManager";
26
26
  import { OpCompressor, OpDecompressor, Outbox, OpSplitter, RemoteMessageProcessor, OpGroupingManager, getLongStack, } from "./opLifecycle";
27
27
  import { DeltaManagerSummarizerProxy } from "./deltaManagerSummarizerProxy";
28
- export var ContainerMessageType;
29
- (function (ContainerMessageType) {
30
- // An op to be delivered to store
31
- ContainerMessageType["FluidDataStoreOp"] = "component";
32
- // Creates a new store
33
- ContainerMessageType["Attach"] = "attach";
34
- // Chunked operation.
35
- ContainerMessageType["ChunkedOp"] = "chunkedOp";
36
- // Signifies that a blob has been attached and should not be garbage collected by storage
37
- ContainerMessageType["BlobAttach"] = "blobAttach";
38
- // Ties our new clientId to our old one on reconnect
39
- ContainerMessageType["Rejoin"] = "rejoin";
40
- // Sets the alias of a root data store
41
- ContainerMessageType["Alias"] = "alias";
42
- /**
43
- * An op containing an IdRange of Ids allocated using the runtime's IdCompressor since
44
- * the last allocation op was sent.
45
- * See the [IdCompressor README](./id-compressor/README.md) for more details.
46
- */
47
- ContainerMessageType["IdAllocation"] = "idAllocation";
48
- })(ContainerMessageType || (ContainerMessageType = {}));
28
+ import { ContainerMessageType, } from "./messageTypes";
49
29
  /**
50
30
  * Utility to implement compat behaviors given an unknown message type
51
31
  * The parameters are typed to support compile-time enforcement of handling all known types/behaviors
52
32
  *
53
- * @param _unknownContainerRuntimeMessageType - Typed as never, to ensure all known types have been
33
+ * @param _unknownContainerRuntimeMessageType - Typed as something unexpected, to ensure all known types have been
54
34
  * handled before calling this function (e.g. in a switch statement).
55
35
  * @param compatBehavior - Typed redundantly with CompatModeBehavior to ensure handling is added when updating that type
56
36
  */
@@ -58,6 +38,12 @@ function compatBehaviorAllowsMessageType(_unknownContainerRuntimeMessageType, co
58
38
  // undefined defaults to same behavior as "FailToProcess"
59
39
  return compatBehavior === "Ignore";
60
40
  }
41
+ function prepareLocalContainerRuntimeIdAllocationMessageForTransit(message) {
42
+ // Remove the stashedState from the op if it's a stashed op
43
+ if ("stashedState" in message.contents) {
44
+ delete message.contents.stashedState;
45
+ }
46
+ }
61
47
  export const DefaultSummaryConfiguration = {
62
48
  state: "enabled",
63
49
  minIdleTime: 0,
@@ -127,7 +113,7 @@ export const defaultPendingOpsRetryDelayMs = 1000;
127
113
  */
128
114
  const defaultCloseSummarizerDelayMs = 5000; // 5 seconds
129
115
  /**
130
- * @deprecated - use ContainerRuntimeMessage instead
116
+ * @deprecated - use ContainerRuntimeMessageType instead
131
117
  */
132
118
  export var RuntimeMessage;
133
119
  (function (RuntimeMessage) {
@@ -495,26 +481,6 @@ export class ContainerRuntime extends TypedEventEmitter {
495
481
  this.summaryManager.start();
496
482
  }
497
483
  }
498
- this.deltaManager.on("readonly", (readonly) => {
499
- // we accumulate ops while being in read-only state.
500
- // once user gets write permissions and we have active connection, flush all pending ops.
501
- // Note that the inner (non-proxy) delta manager is needed here to get the readonly information.
502
- assert(readonly === this.innerDeltaManager.readOnlyInfo.readonly, 0x124 /* "inconsistent readonly property/event state" */);
503
- // We need to be very careful with when we (re)send pending ops, to ensure that we only send ops
504
- // when we either never send an op, or attempted to send it but we know for sure it was not
505
- // sequenced by server and will never be sequenced (i.e. was lost)
506
- // For loss of connection, we wait for our own "join" op and use it a a barrier to know all the
507
- // ops that made it from previous connection, before switching clientId and raising "connected" event
508
- // But with read-only permissions, if we transition between read-only and r/w states while on same
509
- // connection, then we have no good signal to tell us when it's safe to send ops we accumulated while
510
- // being in read-only state.
511
- // For that reason, we support getting to read-only state only when disconnected. This ensures that we
512
- // can rely on same safety mechanism and resend ops only when we establish new connection.
513
- // This is applicable for read-only permissions (event is raised before connection is properly registered),
514
- // but it's an extra requirement for Container.forceReadonly() API
515
- assert(!readonly || !this.connected, 0x125 /* "Unsafe to transition to read-only state!" */);
516
- this.replayPendingStates();
517
- });
518
484
  // logging hardware telemetry
519
485
  logger.sendTelemetryEvent({
520
486
  eventName: "DeviceSpec",
@@ -690,10 +656,9 @@ export class ContainerRuntime extends TypedEventEmitter {
690
656
  enableGroupedBatching,
691
657
  }, containerScope, logger, existing, blobManagerSnapshot, context.storage, idCompressor, requestHandler, undefined, // summaryConfiguration
692
658
  initializeEntryPoint);
693
- await runtime.blobManager.processStashedChanges();
694
- // It's possible to have ops with a reference sequence number of 0. Op sequence numbers start
695
- // at 1, so we won't see a replayed saved op with a sequence number of 0.
696
- await runtime.pendingStateManager.applyStashedOpsAt(0);
659
+ // Apply stashed ops with a reference sequence number equal to the sequence number of the snapshot,
660
+ // or zero. This must be done before Container replays saved ops.
661
+ await runtime.pendingStateManager.applyStashedOpsAt(runtimeSequenceNumber ?? 0);
697
662
  // Initialize the base state of the runtime before it's returned.
698
663
  await runtime.initializeBaseState();
699
664
  return runtime;
@@ -1024,23 +989,24 @@ export class ContainerRuntime extends TypedEventEmitter {
1024
989
  * Parse an op's type and actual content from given serialized content
1025
990
  * ! Note: this format needs to be in-line with what is set in the "ContainerRuntime.submit(...)" method
1026
991
  */
1027
- parseOpContent(serializedContent) {
1028
- assert(serializedContent !== undefined, 0x6d5 /* content must be defined */);
1029
- const { type, contents, compatDetails } = JSON.parse(serializedContent);
1030
- assert(type !== undefined, 0x6d6 /* incorrect op content format */);
1031
- return { type, contents, compatDetails };
1032
- }
1033
- async applyStashedOp(op) {
992
+ // TODO: markfields: confirm Local- versus Outbound- ContainerRuntimeMessage typing
993
+ parseLocalOpContent(serializedContents) {
994
+ assert(serializedContents !== undefined, 0x6d5 /* content must be defined */);
995
+ const message = JSON.parse(serializedContents);
996
+ assert(message.type !== undefined, 0x6d6 /* incorrect op content format */);
997
+ return message;
998
+ }
999
+ async applyStashedOp(serializedOpContent) {
1034
1000
  // Need to parse from string for back-compat
1035
- const { type, contents, compatDetails } = this.parseOpContent(op);
1036
- switch (type) {
1001
+ const opContents = this.parseLocalOpContent(serializedOpContent);
1002
+ switch (opContents.type) {
1037
1003
  case ContainerMessageType.FluidDataStoreOp:
1038
- return this.dataStores.applyStashedOp(contents);
1004
+ return this.dataStores.applyStashedOp(opContents.contents);
1039
1005
  case ContainerMessageType.Attach:
1040
- return this.dataStores.applyStashedAttachOp(contents);
1006
+ return this.dataStores.applyStashedAttachOp(opContents.contents);
1041
1007
  case ContainerMessageType.IdAllocation:
1042
1008
  assert(this.idCompressor !== undefined, 0x67b /* IdCompressor should be defined if enabled */);
1043
- return this.applyStashedIdAllocationOp(contents);
1009
+ return this.applyStashedIdAllocationOp(opContents.contents);
1044
1010
  case ContainerMessageType.Alias:
1045
1011
  case ContainerMessageType.BlobAttach:
1046
1012
  return;
@@ -1052,11 +1018,11 @@ export class ContainerRuntime extends TypedEventEmitter {
1052
1018
  // This should be extremely rare for stashed ops.
1053
1019
  // It would require a newer runtime stashing ops and then an older one applying them,
1054
1020
  // e.g. if an app rolled back its container version
1055
- const compatBehavior = compatDetails?.behavior;
1056
- if (!compatBehaviorAllowsMessageType(type, compatBehavior)) {
1021
+ const compatBehavior = opContents.compatDetails?.behavior;
1022
+ if (!compatBehaviorAllowsMessageType(opContents.type, compatBehavior)) {
1057
1023
  const error = DataProcessingError.create("Stashed runtime message of unknown type", "applyStashedOp", undefined /* sequencedMessage */, {
1058
1024
  messageDetails: JSON.stringify({
1059
- type,
1025
+ type: opContents.type,
1060
1026
  compatBehavior,
1061
1027
  }),
1062
1028
  });
@@ -1075,6 +1041,23 @@ export class ContainerRuntime extends TypedEventEmitter {
1075
1041
  // Don't propagate "disconnected" event because we didn't propagate the previous "connected" event
1076
1042
  return;
1077
1043
  }
1044
+ // If there are stashed blobs in the pending state, we need to delay
1045
+ // propagation of the "connected" event until we have uploaded them to
1046
+ // ensure we don't submit ops referencing a blob that has not been uploaded
1047
+ const connecting = connected && !this._connected;
1048
+ if (connecting && this.blobManager.hasPendingStashedBlobs()) {
1049
+ assert(!this.delayConnectClientId, 0x791 /* Connect event delay must be canceled before subsequent connect event */);
1050
+ assert(!!clientId, 0x792 /* Must have clientId when connecting */);
1051
+ this.delayConnectClientId = clientId;
1052
+ this.blobManager.processStashedChanges().then(() => {
1053
+ // make sure we didn't reconnect before the promise resolved
1054
+ if (this.delayConnectClientId === clientId && !this.disposed) {
1055
+ this.delayConnectClientId = undefined;
1056
+ this.setConnectionStateCore(connected, clientId);
1057
+ }
1058
+ }, (error) => this.closeFn(error));
1059
+ return;
1060
+ }
1078
1061
  this.setConnectionStateCore(connected, clientId);
1079
1062
  }
1080
1063
  setConnectionStateCore(connected, clientId) {
@@ -1127,18 +1110,33 @@ export class ContainerRuntime extends TypedEventEmitter {
1127
1110
  // or something different, like a system message.
1128
1111
  const modernRuntimeMessage = messageArg.type === MessageType.Operation;
1129
1112
  // Do shallow copy of message, as the processing flow will modify it.
1113
+ // There might be multiple container instances receiving the same message.
1114
+ // We do not need to make a deep copy. Each layer will just replace message.contents itself,
1115
+ // but will not modify the contents object (likely it will replace it on the message).
1130
1116
  const messageCopy = { ...messageArg };
1131
1117
  for (const message of this.remoteMessageProcessor.process(messageCopy)) {
1132
- this.processCore(message, local, modernRuntimeMessage);
1118
+ if (modernRuntimeMessage) {
1119
+ this.processCore({
1120
+ // Cast it since we expect it to be this based on modernRuntimeMessage computation above.
1121
+ // There is nothing really ensuring that anytime original message.type is Operation that
1122
+ // the result messages will be so. In the end modern bool being true only directs to
1123
+ // throw error if ultimately unrecognized without compat details saying otherwise.
1124
+ message: message,
1125
+ local,
1126
+ modernRuntimeMessage,
1127
+ });
1128
+ }
1129
+ else {
1130
+ // Unrecognized message will be ignored.
1131
+ this.processCore({ message, local, modernRuntimeMessage });
1132
+ }
1133
1133
  }
1134
1134
  }
1135
1135
  /**
1136
1136
  * Direct the message to the correct subsystem for processing, and implement other side effects
1137
- * @param message - The unpacked message. Likely a ContainerRuntimeMessage, but could also be a system op
1138
- * @param local - Did this client send the op?
1139
- * @param modernRuntimeMessage - Does this appear like a current ContainerRuntimeMessage?
1140
1137
  */
1141
- processCore(message, local, modernRuntimeMessage) {
1138
+ processCore(messageWithContext) {
1139
+ const { message, local } = messageWithContext;
1142
1140
  // Surround the actual processing of the operation with messages to the schedule manager indicating
1143
1141
  // the beginning and end. This allows it to emit appropriate events and/or pause the processing of new
1144
1142
  // messages once a batch has been fully processed.
@@ -1146,16 +1144,18 @@ export class ContainerRuntime extends TypedEventEmitter {
1146
1144
  this._processedClientSequenceNumber = message.clientSequenceNumber;
1147
1145
  try {
1148
1146
  let localOpMetadata;
1149
- if (local && modernRuntimeMessage && message.type !== ContainerMessageType.ChunkedOp) {
1150
- localOpMetadata = this.pendingStateManager.processPendingLocalMessage(message);
1147
+ if (local &&
1148
+ messageWithContext.modernRuntimeMessage &&
1149
+ message.type !== ContainerMessageType.ChunkedOp) {
1150
+ localOpMetadata = this.pendingStateManager.processPendingLocalMessage(messageWithContext.message);
1151
1151
  }
1152
1152
  // If there are no more pending messages after processing a local message,
1153
1153
  // the document is no longer dirty.
1154
1154
  if (!this.hasPendingMessages()) {
1155
1155
  this.updateDocumentDirtyState(false);
1156
1156
  }
1157
- this.validateAndProcessRuntimeMessage(message, localOpMetadata, local, modernRuntimeMessage);
1158
- this.emit("op", message, modernRuntimeMessage);
1157
+ this.validateAndProcessRuntimeMessage(messageWithContext, localOpMetadata);
1158
+ this.emit("op", message, messageWithContext.modernRuntimeMessage);
1159
1159
  this.scheduleManager.afterOpProcessing(undefined, message);
1160
1160
  if (local) {
1161
1161
  // If we have processed a local op, this means that the container is
@@ -1170,29 +1170,29 @@ export class ContainerRuntime extends TypedEventEmitter {
1170
1170
  }
1171
1171
  }
1172
1172
  /**
1173
- * Assuming the given message is also a ContainerRuntimeMessage,
1173
+ * Assuming the given message is also a TypedContainerRuntimeMessage,
1174
1174
  * checks its type and dispatches the message to the appropriate handler in the runtime.
1175
- * Throws a DataProcessingError if the message doesn't conform to the ContainerRuntimeMessage type.
1175
+ * Throws a DataProcessingError if the message looks like but doesn't conform to a known TypedContainerRuntimeMessage type.
1176
1176
  */
1177
- validateAndProcessRuntimeMessage(message, localOpMetadata, local, expectRuntimeMessageType) {
1178
- // Optimistically extract ContainerRuntimeMessage-specific props from the message
1179
- const { type: maybeContainerMessageType, compatDetails } = message;
1180
- switch (maybeContainerMessageType) {
1177
+ validateAndProcessRuntimeMessage(messageWithContext, localOpMetadata) {
1178
+ // TODO: destructure message and modernRuntimeMessage once using typescript 5.2.2+
1179
+ const { local } = messageWithContext;
1180
+ switch (messageWithContext.message.type) {
1181
1181
  case ContainerMessageType.Attach:
1182
- this.dataStores.processAttachMessage(message, local);
1182
+ this.dataStores.processAttachMessage(messageWithContext.message, local);
1183
1183
  break;
1184
1184
  case ContainerMessageType.Alias:
1185
- this.dataStores.processAliasMessage(message, localOpMetadata, local);
1185
+ this.dataStores.processAliasMessage(messageWithContext.message, localOpMetadata, local);
1186
1186
  break;
1187
1187
  case ContainerMessageType.FluidDataStoreOp:
1188
- this.dataStores.processFluidDataStoreOp(message, local, localOpMetadata);
1188
+ this.dataStores.processFluidDataStoreOp(messageWithContext.message, local, localOpMetadata);
1189
1189
  break;
1190
1190
  case ContainerMessageType.BlobAttach:
1191
- this.blobManager.processBlobAttachOp(message, local);
1191
+ this.blobManager.processBlobAttachOp(messageWithContext.message, local);
1192
1192
  break;
1193
1193
  case ContainerMessageType.IdAllocation:
1194
1194
  assert(this.idCompressor !== undefined, 0x67c /* IdCompressor should be defined if enabled */);
1195
- this.idCompressor.finalizeCreationRange(message.contents);
1195
+ this.idCompressor.finalizeCreationRange(messageWithContext.message.contents);
1196
1196
  break;
1197
1197
  case ContainerMessageType.ChunkedOp:
1198
1198
  case ContainerMessageType.Rejoin:
@@ -1200,11 +1200,12 @@ export class ContainerRuntime extends TypedEventEmitter {
1200
1200
  default: {
1201
1201
  // If we didn't necessarily expect a runtime message type, then no worries - just return
1202
1202
  // e.g. this case applies to system ops, or legacy ops that would have fallen into the above cases anyway.
1203
- if (!expectRuntimeMessageType) {
1203
+ if (!messageWithContext.modernRuntimeMessage) {
1204
1204
  return;
1205
1205
  }
1206
- const compatBehavior = compatDetails?.behavior;
1207
- if (!compatBehaviorAllowsMessageType(maybeContainerMessageType, compatBehavior)) {
1206
+ const compatBehavior = messageWithContext.message.compatDetails?.behavior;
1207
+ if (!compatBehaviorAllowsMessageType(messageWithContext.message.type, compatBehavior)) {
1208
+ const { message } = messageWithContext;
1208
1209
  const error = DataProcessingError.create(
1209
1210
  // Former assert 0x3ce
1210
1211
  "Runtime message of unknown type", "OpProcessing", message, {
@@ -1346,8 +1347,8 @@ export class ContainerRuntime extends TypedEventEmitter {
1346
1347
  /**
1347
1348
  * Returns the aliased data store's entryPoint, given the alias.
1348
1349
  * @param alias - The alias for the data store.
1349
- * @returns - The data store's entry point (IFluidHandle) if it exists and is aliased. Returns undefined if no
1350
- * data store has been assigned the given alias.
1350
+ * @returns The data store's entry point ({@link @fluidframework/core-interfaces#IFluidHandle}) if it exists and is aliased.
1351
+ * Returns undefined if no data store has been assigned the given alias.
1351
1352
  */
1352
1353
  async getAliasedDataStoreEntryPoint(alias) {
1353
1354
  await this.dataStores.waitIfPendingAlias(alias);
@@ -1586,7 +1587,7 @@ export class ContainerRuntime extends TypedEventEmitter {
1586
1587
  /**
1587
1588
  * After GC has run and identified nodes that are sweep ready, this is called to delete the sweep ready nodes.
1588
1589
  * @param sweepReadyRoutes - The routes of nodes that are sweep ready and should be deleted.
1589
- * @returns - The routes of nodes that were deleted.
1590
+ * @returns The routes of nodes that were deleted.
1590
1591
  */
1591
1592
  deleteSweepReadyNodes(sweepReadyRoutes) {
1592
1593
  const { dataStoreRoutes, blobManagerRoutes } = this.getDataStoreAndBlobManagerRoutes(sweepReadyRoutes);
@@ -1648,7 +1649,7 @@ export class ContainerRuntime extends TypedEventEmitter {
1648
1649
  /**
1649
1650
  * From a given list of routes, separate and return routes that belong to blob manager and data stores.
1650
1651
  * @param routes - A list of routes that can belong to data stores or blob manager.
1651
- * @returns - Two route lists - One that contains routes for blob manager and another one that contains routes
1652
+ * @returns Two route lists - One that contains routes for blob manager and another one that contains routes
1652
1653
  * for data stores.
1653
1654
  */
1654
1655
  getDataStoreAndBlobManagerRoutes(routes) {
@@ -1700,16 +1701,13 @@ export class ContainerRuntime extends TypedEventEmitter {
1700
1701
  },
1701
1702
  });
1702
1703
  assert(this.outbox.isEmpty, 0x3d1 /* Can't trigger summary in the middle of a batch */);
1704
+ // We close the summarizer and download a new snapshot and reload the container
1703
1705
  let latestSnapshotVersionId;
1704
- if (refreshLatestAck) {
1705
- const latestSnapshotInfo = await this.refreshLatestSummaryAckFromServer(createChildLogger({
1706
+ if (refreshLatestAck === true) {
1707
+ return this.prefetchLatestSummaryThenClose(createChildLogger({
1706
1708
  logger: summaryNumberLogger,
1707
1709
  properties: { all: { safeSummary: true } },
1708
1710
  }));
1709
- const latestSnapshotRefSeq = latestSnapshotInfo.latestSnapshotRefSeq;
1710
- latestSnapshotVersionId = latestSnapshotInfo.latestSnapshotVersionId;
1711
- // We might need to catch up to the latest summary's reference sequence number before pausing.
1712
- await this.waitForDeltaManagerToCatchup(latestSnapshotRefSeq, summaryNumberLogger);
1713
1711
  }
1714
1712
  // If there are pending (unacked ops), the summary will not be eventual consistent and it may even be
1715
1713
  // incorrect. So, wait for the container to be saved with a timeout. If the container is not saved
@@ -2233,34 +2231,31 @@ export class ContainerRuntime extends TypedEventEmitter {
2233
2231
  }
2234
2232
  reSubmit(message) {
2235
2233
  // Need to parse from string for back-compat
2236
- const containerRuntimeMessage = this.parseOpContent(message.content);
2234
+ const containerRuntimeMessage = this.parseLocalOpContent(message.content);
2237
2235
  this.reSubmitCore(containerRuntimeMessage, message.localOpMetadata, message.opMetadata);
2238
2236
  }
2239
2237
  /**
2240
2238
  * Finds the right store and asks it to resubmit the message. This typically happens when we
2241
2239
  * reconnect and there are pending messages.
2242
- * @param message - The original ContainerRuntimeMessage.
2240
+ * @param message - The original LocalContainerRuntimeMessage.
2243
2241
  * @param localOpMetadata - The local metadata associated with the original message.
2244
2242
  */
2245
2243
  reSubmitCore(message, localOpMetadata, opMetadata) {
2246
- const contents = message.contents;
2247
2244
  switch (message.type) {
2248
2245
  case ContainerMessageType.FluidDataStoreOp:
2249
2246
  // For Operations, call resubmitDataStoreOp which will find the right store
2250
2247
  // and trigger resubmission on it.
2251
- this.dataStores.resubmitDataStoreOp(contents, localOpMetadata);
2248
+ this.dataStores.resubmitDataStoreOp(message.contents, localOpMetadata);
2252
2249
  break;
2253
2250
  case ContainerMessageType.Attach:
2254
2251
  case ContainerMessageType.Alias:
2255
2252
  this.submit(message, localOpMetadata);
2256
2253
  break;
2257
- case ContainerMessageType.IdAllocation:
2258
- // Remove the stashedState from the op if it's a stashed op
2259
- if (contents.stashedState !== undefined) {
2260
- delete contents.stashedState;
2261
- }
2254
+ case ContainerMessageType.IdAllocation: {
2255
+ prepareLocalContainerRuntimeIdAllocationMessageForTransit(message);
2262
2256
  this.submit(message, localOpMetadata);
2263
2257
  break;
2258
+ }
2264
2259
  case ContainerMessageType.ChunkedOp:
2265
2260
  throw new Error(`chunkedOp not expected here`);
2266
2261
  case ContainerMessageType.BlobAttach:
@@ -2294,7 +2289,7 @@ export class ContainerRuntime extends TypedEventEmitter {
2294
2289
  }
2295
2290
  rollback(content, localOpMetadata) {
2296
2291
  // Need to parse from string for back-compat
2297
- const { type, contents } = this.parseOpContent(content);
2292
+ const { type, contents } = this.parseLocalOpContent(content);
2298
2293
  switch (type) {
2299
2294
  case ContainerMessageType.FluidDataStoreOp:
2300
2295
  // For operations, call rollbackDataStoreOp which will find the right store
@@ -2306,17 +2301,6 @@ export class ContainerRuntime extends TypedEventEmitter {
2306
2301
  throw new Error(`Can't rollback ${type}`);
2307
2302
  }
2308
2303
  }
2309
- async waitForDeltaManagerToCatchup(latestSnapshotRefSeq, summaryLogger) {
2310
- if (latestSnapshotRefSeq > this.deltaManager.lastSequenceNumber) {
2311
- // We need to catch up to the latest summary's reference sequence number before proceeding.
2312
- await PerformanceEvent.timedExecAsync(summaryLogger, {
2313
- eventName: "WaitingForSeq",
2314
- lastSequenceNumber: this.deltaManager.lastSequenceNumber,
2315
- targetSequenceNumber: latestSnapshotRefSeq,
2316
- lastKnownSeqNumber: this.deltaManager.lastKnownSeqNumber,
2317
- }, async () => waitForSeq(this.deltaManager, latestSnapshotRefSeq), { start: true, end: true, cancel: "error" });
2318
- }
2319
- }
2320
2304
  /** Implementation of ISummarizerInternalsProvider.refreshLatestSummaryAck */
2321
2305
  async refreshLatestSummaryAck(options) {
2322
2306
  const { proposalHandle, ackHandle, summaryRefSeq, summaryLogger } = options;
@@ -2362,18 +2346,25 @@ export class ContainerRuntime extends TypedEventEmitter {
2362
2346
  await this.garbageCollector.refreshLatestSummary(result);
2363
2347
  }
2364
2348
  /**
2365
- * Fetches the latest snapshot from storage and uses it to refresh SummarizerNode's
2366
- * internal state as it should be considered the latest summary ack.
2349
+ * Fetches the latest snapshot from storage to refresh the cache as a performance optimization and closes the
2350
+ * summarizer to reload from new state.
2367
2351
  * @param summaryLogger - logger to use when fetching snapshot from storage
2368
- * @returns downloaded snapshot's reference sequence number
2352
+ * @returns a generic summarization error
2369
2353
  */
2370
- async refreshLatestSummaryAckFromServer(summaryLogger) {
2354
+ async prefetchLatestSummaryThenClose(summaryLogger) {
2371
2355
  const readAndParseBlob = async (id) => readAndParse(this.storage, id);
2372
- const { versionId, latestSnapshotRefSeq } = await this.fetchSnapshotFromStorage(summaryLogger, {
2356
+ // This is a performance optimization as the same parent is likely to be elected again, and would use its
2357
+ // cache to fetch the snapshot instead of the network.
2358
+ await this.fetchSnapshotFromStorage(summaryLogger, {
2373
2359
  eventName: "RefreshLatestSummaryFromServerFetch",
2374
2360
  }, readAndParseBlob, null);
2375
2361
  await this.closeStaleSummarizer("RefreshLatestSummaryFromServerFetch");
2376
- return { latestSnapshotRefSeq, latestSnapshotVersionId: versionId };
2362
+ return {
2363
+ stage: "base",
2364
+ error: "summary state stale - Unsupported option 'refreshLatestAck'",
2365
+ referenceSequenceNumber: this.deltaManager.lastSequenceNumber,
2366
+ minimumSequenceNumber: this.deltaManager.minimumSequenceNumber,
2367
+ };
2377
2368
  }
2378
2369
  async closeStaleSummarizer(codePath) {
2379
2370
  this.mc.logger.sendTelemetryEvent({
@@ -2396,7 +2387,7 @@ export class ContainerRuntime extends TypedEventEmitter {
2396
2387
  return PerformanceEvent.timedExecAsync(logger, event, async (perfEvent) => {
2397
2388
  const stats = {};
2398
2389
  const trace = Trace.start();
2399
- const versions = await this.storage.getVersions(versionId, 1, "refreshLatestSummaryAckFromServer", versionId === null ? FetchSource.noCache : undefined);
2390
+ const versions = await this.storage.getVersions(versionId, 1, "prefetchLatestSummaryBeforeClose", versionId === null ? FetchSource.noCache : undefined);
2400
2391
  assert(!!versions && !!versions[0], 0x137 /* "Failed to get version from storage" */);
2401
2392
  stats.getVersionDuration = trace.trace().duration;
2402
2393
  const maybeSnapshot = await this.storage.getSnapshotTree(versions[0]);
@@ -2424,15 +2415,17 @@ export class ContainerRuntime extends TypedEventEmitter {
2424
2415
  if (this._orderSequentiallyCalls !== 0) {
2425
2416
  throw new UsageError("can't get state during orderSequentially");
2426
2417
  }
2427
- const pendingAttachmentBlobs = await this.blobManager.getPendingBlobs(waitBlobsToAttach);
2428
- const pending = this.pendingStateManager.getLocalState();
2429
- if (!pendingAttachmentBlobs && !this.hasPendingMessages()) {
2430
- return; // no pending state to save
2431
- }
2432
2418
  // Flush pending batch.
2433
2419
  // getPendingLocalState() is only exposed through Container.closeAndGetPendingLocalState(), so it's safe
2434
2420
  // to close current batch.
2435
2421
  this.flush();
2422
+ const pendingAttachmentBlobs = waitBlobsToAttach
2423
+ ? await this.blobManager.attachAndGetPendingBlobs()
2424
+ : undefined;
2425
+ const pending = this.pendingStateManager.getLocalState();
2426
+ if (!pendingAttachmentBlobs && !this.hasPendingMessages()) {
2427
+ return; // no pending state to save
2428
+ }
2436
2429
  const pendingState = {
2437
2430
  pending,
2438
2431
  pendingAttachmentBlobs,
@@ -2514,26 +2507,4 @@ export class ContainerRuntime extends TypedEventEmitter {
2514
2507
  return killSwitch !== true && this.runtimeOptions.enableGroupedBatching;
2515
2508
  }
2516
2509
  }
2517
- /**
2518
- * Wait for a specific sequence number. Promise should resolve when we reach that number,
2519
- * or reject if closed.
2520
- */
2521
- const waitForSeq = async (deltaManager, targetSeq) => new Promise((resolve, reject) => {
2522
- // TODO: remove cast to any when actual event is determined
2523
- deltaManager.on("closed", reject);
2524
- deltaManager.on("disposed", reject);
2525
- // If we already reached target sequence number, simply resolve the promise.
2526
- if (deltaManager.lastSequenceNumber >= targetSeq) {
2527
- resolve();
2528
- }
2529
- else {
2530
- const handleOp = (message) => {
2531
- if (message.sequenceNumber >= targetSeq) {
2532
- resolve();
2533
- deltaManager.off("op", handleOp);
2534
- }
2535
- };
2536
- deltaManager.on("op", handleOp);
2537
- }
2538
- });
2539
2510
  //# sourceMappingURL=containerRuntime.js.map