@fluidframework/container-runtime 2.0.0-internal.4.2.1 → 2.0.0-internal.4.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 (183) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/blobManager.d.ts.map +1 -1
  3. package/dist/blobManager.js +3 -2
  4. package/dist/blobManager.js.map +1 -1
  5. package/dist/connectionTelemetry.d.ts.map +1 -1
  6. package/dist/connectionTelemetry.js +1 -0
  7. package/dist/connectionTelemetry.js.map +1 -1
  8. package/dist/containerRuntime.d.ts.map +1 -1
  9. package/dist/containerRuntime.js +20 -11
  10. package/dist/containerRuntime.js.map +1 -1
  11. package/dist/dataStoreContext.d.ts.map +1 -1
  12. package/dist/dataStoreContext.js +1 -2
  13. package/dist/dataStoreContext.js.map +1 -1
  14. package/dist/dataStores.d.ts +5 -5
  15. package/dist/dataStores.d.ts.map +1 -1
  16. package/dist/dataStores.js +3 -6
  17. package/dist/dataStores.js.map +1 -1
  18. package/dist/gc/garbageCollection.d.ts +56 -70
  19. package/dist/gc/garbageCollection.d.ts.map +1 -1
  20. package/dist/gc/garbageCollection.js +227 -408
  21. package/dist/gc/garbageCollection.js.map +1 -1
  22. package/dist/gc/gcConfigs.d.ts.map +1 -1
  23. package/dist/gc/gcConfigs.js +8 -10
  24. package/dist/gc/gcConfigs.js.map +1 -1
  25. package/dist/gc/gcDefinitions.d.ts +2 -0
  26. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  27. package/dist/gc/gcDefinitions.js.map +1 -1
  28. package/dist/gc/gcHelpers.d.ts +11 -11
  29. package/dist/gc/gcHelpers.d.ts.map +1 -1
  30. package/dist/gc/gcHelpers.js +18 -22
  31. package/dist/gc/gcHelpers.js.map +1 -1
  32. package/dist/gc/gcSummaryStateTracker.d.ts +6 -2
  33. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  34. package/dist/gc/gcSummaryStateTracker.js +16 -6
  35. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  36. package/dist/gc/gcTelemetry.d.ts +91 -0
  37. package/dist/gc/gcTelemetry.d.ts.map +1 -0
  38. package/dist/gc/gcTelemetry.js +282 -0
  39. package/dist/gc/gcTelemetry.js.map +1 -0
  40. package/dist/gc/index.d.ts +2 -2
  41. package/dist/gc/index.d.ts.map +1 -1
  42. package/dist/gc/index.js +5 -6
  43. package/dist/gc/index.js.map +1 -1
  44. package/dist/opLifecycle/opGroupingManager.js +1 -1
  45. package/dist/opLifecycle/opGroupingManager.js.map +1 -1
  46. package/dist/opLifecycle/outbox.js +1 -1
  47. package/dist/opLifecycle/outbox.js.map +1 -1
  48. package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  49. package/dist/opLifecycle/remoteMessageProcessor.js +25 -22
  50. package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
  51. package/dist/packageVersion.d.ts +1 -1
  52. package/dist/packageVersion.js +1 -1
  53. package/dist/packageVersion.js.map +1 -1
  54. package/dist/pendingStateManager.d.ts +1 -1
  55. package/dist/pendingStateManager.d.ts.map +1 -1
  56. package/dist/pendingStateManager.js.map +1 -1
  57. package/dist/scheduleManager.js +15 -4
  58. package/dist/scheduleManager.js.map +1 -1
  59. package/dist/summary/orderedClientElection.d.ts.map +1 -1
  60. package/dist/summary/orderedClientElection.js +14 -17
  61. package/dist/summary/orderedClientElection.js.map +1 -1
  62. package/dist/summary/summarizer.d.ts +2 -0
  63. package/dist/summary/summarizer.d.ts.map +1 -1
  64. package/dist/summary/summarizer.js +9 -4
  65. package/dist/summary/summarizer.js.map +1 -1
  66. package/dist/summary/summarizerHeuristics.d.ts +8 -9
  67. package/dist/summary/summarizerHeuristics.d.ts.map +1 -1
  68. package/dist/summary/summarizerHeuristics.js +15 -16
  69. package/dist/summary/summarizerHeuristics.js.map +1 -1
  70. package/dist/summary/summarizerTypes.d.ts +2 -0
  71. package/dist/summary/summarizerTypes.d.ts.map +1 -1
  72. package/dist/summary/summarizerTypes.js.map +1 -1
  73. package/dist/summary/summaryGenerator.d.ts.map +1 -1
  74. package/dist/summary/summaryGenerator.js +4 -3
  75. package/dist/summary/summaryGenerator.js.map +1 -1
  76. package/lib/blobManager.d.ts.map +1 -1
  77. package/lib/blobManager.js +3 -2
  78. package/lib/blobManager.js.map +1 -1
  79. package/lib/connectionTelemetry.d.ts.map +1 -1
  80. package/lib/connectionTelemetry.js +1 -0
  81. package/lib/connectionTelemetry.js.map +1 -1
  82. package/lib/containerRuntime.d.ts.map +1 -1
  83. package/lib/containerRuntime.js +20 -11
  84. package/lib/containerRuntime.js.map +1 -1
  85. package/lib/dataStoreContext.d.ts.map +1 -1
  86. package/lib/dataStoreContext.js +1 -2
  87. package/lib/dataStoreContext.js.map +1 -1
  88. package/lib/dataStores.d.ts +5 -5
  89. package/lib/dataStores.d.ts.map +1 -1
  90. package/lib/dataStores.js +3 -6
  91. package/lib/dataStores.js.map +1 -1
  92. package/lib/gc/garbageCollection.d.ts +56 -70
  93. package/lib/gc/garbageCollection.d.ts.map +1 -1
  94. package/lib/gc/garbageCollection.js +231 -412
  95. package/lib/gc/garbageCollection.js.map +1 -1
  96. package/lib/gc/gcConfigs.d.ts.map +1 -1
  97. package/lib/gc/gcConfigs.js +8 -10
  98. package/lib/gc/gcConfigs.js.map +1 -1
  99. package/lib/gc/gcDefinitions.d.ts +2 -0
  100. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  101. package/lib/gc/gcDefinitions.js.map +1 -1
  102. package/lib/gc/gcHelpers.d.ts +11 -11
  103. package/lib/gc/gcHelpers.d.ts.map +1 -1
  104. package/lib/gc/gcHelpers.js +16 -20
  105. package/lib/gc/gcHelpers.js.map +1 -1
  106. package/lib/gc/gcSummaryStateTracker.d.ts +6 -2
  107. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  108. package/lib/gc/gcSummaryStateTracker.js +16 -6
  109. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  110. package/lib/gc/gcTelemetry.d.ts +91 -0
  111. package/lib/gc/gcTelemetry.d.ts.map +1 -0
  112. package/lib/gc/gcTelemetry.js +277 -0
  113. package/lib/gc/gcTelemetry.js.map +1 -0
  114. package/lib/gc/index.d.ts +2 -2
  115. package/lib/gc/index.d.ts.map +1 -1
  116. package/lib/gc/index.js +2 -2
  117. package/lib/gc/index.js.map +1 -1
  118. package/lib/opLifecycle/opGroupingManager.js +1 -1
  119. package/lib/opLifecycle/opGroupingManager.js.map +1 -1
  120. package/lib/opLifecycle/outbox.js +1 -1
  121. package/lib/opLifecycle/outbox.js.map +1 -1
  122. package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
  123. package/lib/opLifecycle/remoteMessageProcessor.js +25 -22
  124. package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
  125. package/lib/packageVersion.d.ts +1 -1
  126. package/lib/packageVersion.js +1 -1
  127. package/lib/packageVersion.js.map +1 -1
  128. package/lib/pendingStateManager.d.ts +1 -1
  129. package/lib/pendingStateManager.d.ts.map +1 -1
  130. package/lib/pendingStateManager.js.map +1 -1
  131. package/lib/scheduleManager.js +15 -4
  132. package/lib/scheduleManager.js.map +1 -1
  133. package/lib/summary/orderedClientElection.d.ts.map +1 -1
  134. package/lib/summary/orderedClientElection.js +14 -17
  135. package/lib/summary/orderedClientElection.js.map +1 -1
  136. package/lib/summary/summarizer.d.ts +2 -0
  137. package/lib/summary/summarizer.d.ts.map +1 -1
  138. package/lib/summary/summarizer.js +9 -4
  139. package/lib/summary/summarizer.js.map +1 -1
  140. package/lib/summary/summarizerHeuristics.d.ts +8 -9
  141. package/lib/summary/summarizerHeuristics.d.ts.map +1 -1
  142. package/lib/summary/summarizerHeuristics.js +15 -16
  143. package/lib/summary/summarizerHeuristics.js.map +1 -1
  144. package/lib/summary/summarizerTypes.d.ts +2 -0
  145. package/lib/summary/summarizerTypes.d.ts.map +1 -1
  146. package/lib/summary/summarizerTypes.js.map +1 -1
  147. package/lib/summary/summaryGenerator.d.ts.map +1 -1
  148. package/lib/summary/summaryGenerator.js +4 -3
  149. package/lib/summary/summaryGenerator.js.map +1 -1
  150. package/package.json +15 -16
  151. package/src/blobManager.ts +3 -2
  152. package/src/connectionTelemetry.ts +1 -0
  153. package/src/containerRuntime.ts +22 -15
  154. package/src/dataStoreContext.ts +1 -2
  155. package/src/dataStores.ts +4 -7
  156. package/src/gc/garbageCollection.ts +316 -561
  157. package/src/gc/gcConfigs.ts +12 -11
  158. package/src/gc/gcDefinitions.ts +2 -0
  159. package/src/gc/gcHelpers.ts +21 -40
  160. package/src/gc/gcSummaryStateTracker.ts +19 -7
  161. package/src/gc/gcTelemetry.ts +408 -0
  162. package/src/gc/index.ts +2 -6
  163. package/src/opLifecycle/README.md +13 -0
  164. package/src/opLifecycle/opGroupingManager.ts +1 -1
  165. package/src/opLifecycle/outbox.ts +2 -2
  166. package/src/opLifecycle/remoteMessageProcessor.ts +37 -28
  167. package/src/packageVersion.ts +1 -1
  168. package/src/pendingStateManager.ts +1 -4
  169. package/src/scheduleManager.ts +19 -7
  170. package/src/summary/orderedClientElection.ts +14 -17
  171. package/src/summary/summarizer.ts +17 -5
  172. package/src/summary/summarizerHeuristics.ts +15 -16
  173. package/src/summary/summarizerTypes.ts +2 -0
  174. package/src/summary/summaryGenerator.ts +5 -4
  175. package/dist/gc/gcSweepReadyUsageDetection.d.ts +0 -53
  176. package/dist/gc/gcSweepReadyUsageDetection.d.ts.map +0 -1
  177. package/dist/gc/gcSweepReadyUsageDetection.js +0 -130
  178. package/dist/gc/gcSweepReadyUsageDetection.js.map +0 -1
  179. package/lib/gc/gcSweepReadyUsageDetection.d.ts +0 -53
  180. package/lib/gc/gcSweepReadyUsageDetection.d.ts.map +0 -1
  181. package/lib/gc/gcSweepReadyUsageDetection.js +0 -125
  182. package/lib/gc/gcSweepReadyUsageDetection.js.map +0 -1
  183. package/src/gc/gcSweepReadyUsageDetection.ts +0 -145
@@ -0,0 +1,277 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ var __rest = (this && this.__rest) || function (s, e) {
6
+ var t = {};
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
8
+ t[p] = s[p];
9
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
10
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
12
+ t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ };
16
+ import { packagePathToTelemetryProperty } from "@fluidframework/runtime-utils";
17
+ import { generateStack } from "@fluidframework/telemetry-utils";
18
+ import { disableSweepLogKey, GCNodeType, UnreferencedState, disableTombstoneKey, throwOnTombstoneUsageKey, throwOnTombstoneLoadKey, runSweepKey, } from "./gcDefinitions";
19
+ import { tagAsCodeArtifact } from "./gcHelpers";
20
+ /**
21
+ * Encapsulates the logic that tracks the various telemetry logged by the Garbage Collector. There are 4 types of
22
+ * telemetry logged:
23
+ * 1. inactiveObject telemetry - When an inactive node is used - A node that has been unreferenced for inactiveTimeoutMs.
24
+ * 2. sweepReadyObject telemetry - When a sweep ready node is used - A node that has been unreferenced for sweepTimeoutMs.
25
+ * 3. Tombstone telemetry - When a tombstoned node is used - A node that that has been marked as tombstone.
26
+ * 4. Sweep / deleted telemetry - When a node is detected as sweep ready in the sweep phase.
27
+ * 5. Unknown outbound reference telemetry - When a node is referenced but GC is not explicitly notified of it.
28
+ */
29
+ export class GCTelemetryTracker {
30
+ constructor(mc, configs, isSummarizerClient, gcTombstoneEnforcementAllowed, createContainerMetadata, getNodeType, getNodeStateTracker, getNodePackagePath) {
31
+ this.mc = mc;
32
+ this.configs = configs;
33
+ this.isSummarizerClient = isSummarizerClient;
34
+ this.gcTombstoneEnforcementAllowed = gcTombstoneEnforcementAllowed;
35
+ this.createContainerMetadata = createContainerMetadata;
36
+ this.getNodeType = getNodeType;
37
+ this.getNodeStateTracker = getNodeStateTracker;
38
+ this.getNodePackagePath = getNodePackagePath;
39
+ // Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one
40
+ // per event per node.
41
+ this.loggedUnreferencedEvents = new Set();
42
+ // Queue for unreferenced events that should be logged the next time GC runs.
43
+ this.pendingEventsQueue = [];
44
+ }
45
+ /**
46
+ * Returns whether an event should be logged for a node that isn't active anymore. Some scenarios where we won't log:
47
+ * 1. When a DDS is changed or loaded. The corresponding data store's event will be logged instead.
48
+ * 2. An event is logged only once per container instance per event per node.
49
+ */
50
+ shouldLogNonActiveEvent(nodeId, nodeType, usageType, nodeStateTracker, uniqueEventId) {
51
+ if (nodeStateTracker.state === UnreferencedState.Active) {
52
+ return false;
53
+ }
54
+ // For sub data store (DDS) nodes, if they are changed or loaded, its data store will also be changed or loaded,
55
+ // so skip logging to make the telemetry less noisy.
56
+ if (nodeType === GCNodeType.SubDataStore && usageType !== "Revived") {
57
+ return false;
58
+ }
59
+ if (nodeType === GCNodeType.Other) {
60
+ return false;
61
+ }
62
+ if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
63
+ return false;
64
+ }
65
+ return true;
66
+ }
67
+ /**
68
+ * Called when a node is used. If the node is not active, log an event indicating object is used when its not active.
69
+ */
70
+ nodeUsed(nodeUsageProps) {
71
+ // If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip
72
+ // logging as nothing interesting would have happened worth logging.
73
+ // If the node is not unreferenced, skip logging.
74
+ const nodeStateTracker = this.getNodeStateTracker(nodeUsageProps.id);
75
+ if (!nodeStateTracker || nodeUsageProps.currentReferenceTimestampMs === undefined) {
76
+ return;
77
+ }
78
+ // We log these events once per event per node. A unique id is generated by joining node state (inactive / sweep ready),
79
+ // node's id and usage (loaded / changed / revived).
80
+ const uniqueEventId = `${nodeStateTracker.state}-${nodeUsageProps.id}-${nodeUsageProps.usageType}`;
81
+ const nodeType = this.getNodeType(nodeUsageProps.id);
82
+ if (!this.shouldLogNonActiveEvent(nodeUsageProps.id, nodeType, nodeUsageProps.usageType, nodeStateTracker, uniqueEventId)) {
83
+ return;
84
+ }
85
+ // Add the unique event id so that we don't generate a log for this event again in this session..
86
+ this.loggedUnreferencedEvents.add(uniqueEventId);
87
+ const state = nodeStateTracker.state;
88
+ const { usageType, currentReferenceTimestampMs, packagePath, id, fromId } = nodeUsageProps, propsToLog = __rest(nodeUsageProps, ["usageType", "currentReferenceTimestampMs", "packagePath", "id", "fromId"]);
89
+ const eventProps = Object.assign(Object.assign({ id: tagAsCodeArtifact(id), type: nodeType, unrefTime: nodeStateTracker.unreferencedTimestampMs, age: nodeUsageProps.currentReferenceTimestampMs -
90
+ nodeStateTracker.unreferencedTimestampMs, timeout: state === UnreferencedState.Inactive
91
+ ? this.configs.inactiveTimeoutMs
92
+ : this.configs.sweepTimeoutMs, fromId: fromId ? tagAsCodeArtifact(fromId) : undefined }, propsToLog), this.createContainerMetadata);
93
+ // This will log the following events:
94
+ // GC_Tombstone_DataStore_Revived, GC_Tombstone_SubDataStore_Revived, GC_Tombstone_Blob_Revived
95
+ if (nodeUsageProps.usageType === "Revived" && nodeUsageProps.isTombstoned) {
96
+ sendGCUnexpectedUsageEvent(this.mc, {
97
+ eventName: `GC_Tombstone_${nodeType}_Revived`,
98
+ category: "generic",
99
+ url: tagAsCodeArtifact(id),
100
+ gcTombstoneEnforcementAllowed: this.gcTombstoneEnforcementAllowed,
101
+ }, undefined /* packagePath */);
102
+ }
103
+ // For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.
104
+ // For non-summarizer client, log the event now since GC won't run on it. This may result in false positives
105
+ // but it's a good signal nonetheless and we can consume it with a grain of salt.
106
+ // Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.
107
+ // SweepReady errors are usages of Objects that will be deleted by GC Sweep!
108
+ if (this.isSummarizerClient) {
109
+ this.pendingEventsQueue.push(Object.assign(Object.assign({}, eventProps), { usageType: nodeUsageProps.usageType, state }));
110
+ }
111
+ else {
112
+ // For non-summarizer clients, only log "Loaded" type events since these objects may not be loaded in the
113
+ // summarizer clients if they are based off of user actions (such as scrolling to content for these objects)
114
+ // Events generated:
115
+ // InactiveObject_Loaded, SweepReadyObject_Loaded
116
+ if (nodeUsageProps.usageType === "Loaded") {
117
+ const { id: taggedId, fromId: taggedFromId } = eventProps, otherProps = __rest(eventProps, ["id", "fromId"]);
118
+ const event = {
119
+ eventName: `${state}Object_${nodeUsageProps.usageType}`,
120
+ pkg: packagePathToTelemetryProperty(nodeUsageProps.packagePath),
121
+ stack: generateStack(),
122
+ id: taggedId,
123
+ fromId: taggedFromId,
124
+ details: JSON.stringify(Object.assign({}, otherProps)),
125
+ };
126
+ // Do not log the inactive object x events as error events as they are not the best signal for
127
+ // detecting something wrong with GC either from the partner or from the runtime itself.
128
+ if (state === UnreferencedState.Inactive) {
129
+ this.mc.logger.sendTelemetryEvent(event);
130
+ }
131
+ else {
132
+ this.mc.logger.sendErrorEvent(event);
133
+ }
134
+ }
135
+ }
136
+ }
137
+ /**
138
+ * Log all new references or outbound routes in the current graph that haven't been explicitly notified to GC.
139
+ * The principle is that every new reference or outbound route must be notified to GC via the
140
+ * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.
141
+ *
142
+ * In more simple terms:
143
+ * Missing Explicit References = Current References - Previous References - Explicitly Added References;
144
+ *
145
+ * @param currentGCData - The GC data (reference graph) from the current GC run.
146
+ * @param previousGCData - The GC data (reference graph) from the previous GC run.
147
+ * @param explicitReferences - New references added explicity between the previous and the current run.
148
+ */
149
+ logIfMissingExplicitReferences(currentGCData, previousGCData, explicitReferences, logger) {
150
+ var _a, _b;
151
+ for (const [nodeId, currentOutboundRoutes] of Object.entries(currentGCData.gcNodes)) {
152
+ const previousRoutes = (_a = previousGCData.gcNodes[nodeId]) !== null && _a !== void 0 ? _a : [];
153
+ const explicitRoutes = (_b = explicitReferences.get(nodeId)) !== null && _b !== void 0 ? _b : [];
154
+ /**
155
+ * 1. For routes in the current GC data, routes that were not present in previous GC data and did not have
156
+ * explicit references should be added to missing explicit routes list.
157
+ * 2. Only include data store and blob routes since GC only works for these two.
158
+ * Note: Due to a bug with de-duped blobs, only adding data store routes for now.
159
+ * 3. Ignore DDS routes to their parent datastores since those were added implicitly. So, there won't be
160
+ * explicit routes to them.
161
+ */
162
+ const missingExplicitRoutes = [];
163
+ for (const route of currentOutboundRoutes) {
164
+ const nodeType = this.getNodeType(route);
165
+ if ((nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) &&
166
+ !nodeId.startsWith(route) &&
167
+ !previousRoutes.includes(route) &&
168
+ !explicitRoutes.includes(route)) {
169
+ missingExplicitRoutes.push(route);
170
+ }
171
+ }
172
+ if (missingExplicitRoutes.length > 0) {
173
+ logger.sendErrorEvent({
174
+ eventName: "gcUnknownOutboundReferences",
175
+ id: tagAsCodeArtifact(nodeId),
176
+ routes: tagAsCodeArtifact(JSON.stringify(missingExplicitRoutes)),
177
+ });
178
+ }
179
+ }
180
+ }
181
+ /**
182
+ * Log events that are pending in pendingEventsQueue. This is called after GC runs in the summarizer client
183
+ * so that the state of an unreferenced node is updated.
184
+ */
185
+ async logPendingEvents(logger) {
186
+ // Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at
187
+ // summary time they are then logged.
188
+ // Events generated:
189
+ // InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived
190
+ // SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived
191
+ for (const eventProps of this.pendingEventsQueue) {
192
+ const { usageType, state, id, fromId } = eventProps, propsToLog = __rest(eventProps, ["usageType", "state", "id", "fromId"]);
193
+ /**
194
+ * Revived event is logged only if the node is active. If the node is not active, the reference to it was
195
+ * from another unreferenced node and this scenario is not interesting to log.
196
+ * Loaded and Changed events are logged only if the node is not active. If the node is active, it was
197
+ * revived and a Revived event will be logged for it.
198
+ */
199
+ const nodeStateTracker = this.getNodeStateTracker(eventProps.id.value);
200
+ const active = nodeStateTracker === undefined ||
201
+ nodeStateTracker.state === UnreferencedState.Active;
202
+ if ((usageType === "Revived") === active) {
203
+ const pkg = await this.getNodePackagePath(eventProps.id.value);
204
+ const fromPkg = eventProps.fromId
205
+ ? await this.getNodePackagePath(eventProps.fromId.value)
206
+ : undefined;
207
+ const event = {
208
+ eventName: `${state}Object_${usageType}`,
209
+ details: JSON.stringify(Object.assign({}, propsToLog)),
210
+ id,
211
+ fromId,
212
+ pkg: pkg ? tagAsCodeArtifact(pkg.join("/")) : undefined,
213
+ fromPkg: fromPkg ? tagAsCodeArtifact(fromPkg.join("/")) : undefined,
214
+ };
215
+ if (state === UnreferencedState.Inactive) {
216
+ logger.sendTelemetryEvent(event);
217
+ }
218
+ else {
219
+ logger.sendErrorEvent(event);
220
+ }
221
+ }
222
+ }
223
+ this.pendingEventsQueue = [];
224
+ }
225
+ /**
226
+ * For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,
227
+ * this will give us a view into how much deleted content a container has.
228
+ */
229
+ logSweepEvents(logger, currentReferenceTimestampMs, unreferencedNodesState, completedGCRuns, lastSummaryTime) {
230
+ if (this.mc.config.getBoolean(disableSweepLogKey) === true ||
231
+ this.configs.sweepTimeoutMs === undefined) {
232
+ return;
233
+ }
234
+ const deletedNodeIds = [];
235
+ for (const [nodeId, nodeStateTracker] of unreferencedNodesState) {
236
+ if (nodeStateTracker.state !== UnreferencedState.SweepReady) {
237
+ return;
238
+ }
239
+ const nodeType = this.getNodeType(nodeId);
240
+ if (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {
241
+ return;
242
+ }
243
+ // Log deleted event for each node only once to reduce noise in telemetry.
244
+ const uniqueEventId = `Deleted-${nodeId}`;
245
+ if (this.loggedUnreferencedEvents.has(uniqueEventId)) {
246
+ return;
247
+ }
248
+ this.loggedUnreferencedEvents.add(uniqueEventId);
249
+ deletedNodeIds.push(nodeId);
250
+ }
251
+ if (deletedNodeIds.length > 0) {
252
+ logger.sendTelemetryEvent({
253
+ eventName: "GC_SweepReadyObjects_Delete",
254
+ details: JSON.stringify(Object.assign({ timeout: this.configs.sweepTimeoutMs, completedGCRuns,
255
+ lastSummaryTime }, this.createContainerMetadata)),
256
+ id: tagAsCodeArtifact(JSON.stringify(deletedNodeIds)),
257
+ });
258
+ }
259
+ }
260
+ }
261
+ /**
262
+ * Consolidates info / logic for logging when we encounter unexpected usage of GC'd objects. For example, when a
263
+ * tombstoned or deleted object is loaded.
264
+ */
265
+ export function sendGCUnexpectedUsageEvent(mc, event, packagePath, error) {
266
+ event.pkg = packagePathToTelemetryProperty(packagePath);
267
+ event.tombstoneFlags = JSON.stringify({
268
+ DisableTombstone: mc.config.getBoolean(disableTombstoneKey),
269
+ ThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),
270
+ ThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),
271
+ });
272
+ event.sweepFlags = JSON.stringify({
273
+ EnableSweepFlag: mc.config.getBoolean(runSweepKey),
274
+ });
275
+ mc.logger.sendTelemetryEvent(event, error);
276
+ }
277
+ //# sourceMappingURL=gcTelemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gcTelemetry.js","sourceRoot":"","sources":["../../src/gc/gcTelemetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;AAIH,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAEnF,OAAO,EACN,kBAAkB,EAClB,UAAU,EACV,iBAAiB,EAEjB,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAsChD;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IAO9B,YACkB,EAAqB,EACrB,OAGhB,EACgB,kBAA2B,EAC3B,6BAAsC,EACtC,uBAAiD,EACj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ACxC,OAAO,EAAE,IAAI,CAAC,SAAS,iBACtB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,EACpC,eAAe;oBACf,eAAe,IACZ,IAAI,CAAC,uBAAuB,EAC9B;gBACF,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;aACrD,CAAC,CAAC;SACH;IACF,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACzC,EAAqB,EACrB,KAGC,EACD,WAA0C,EAC1C,KAAe;IAEf,KAAK,CAAC,GAAG,GAAG,8BAA8B,CAAC,WAAW,CAAC,CAAC;IACxD,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC;QACrC,gBAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,mBAAmB,CAAC;QAC3D,qBAAqB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC;QACrE,oBAAoB,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,uBAAuB,CAAC;KACnE,CAAC,CAAC;IACH,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC;QACjC,eAAe,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC;KAClD,CAAC,CAAC;IAEH,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryGenericEvent, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { IGarbageCollectionData } from \"@fluidframework/runtime-definitions\";\nimport { packagePathToTelemetryProperty } from \"@fluidframework/runtime-utils\";\nimport { generateStack, MonitoringContext } from \"@fluidframework/telemetry-utils\";\nimport { ICreateContainerMetadata } from \"../summary\";\nimport {\n\tdisableSweepLogKey,\n\tGCNodeType,\n\tUnreferencedState,\n\tIGarbageCollectorConfigs,\n\tdisableTombstoneKey,\n\tthrowOnTombstoneUsageKey,\n\tthrowOnTombstoneLoadKey,\n\trunSweepKey,\n} from \"./gcDefinitions\";\nimport { UnreferencedStateTracker } from \"./gcUnreferencedStateTracker\";\nimport { tagAsCodeArtifact } from \"./gcHelpers\";\n\ntype NodeUsageType = \"Changed\" | \"Loaded\" | \"Revived\";\n\n/** Properties that are common to IUnreferencedEventProps and INodeUsageProps */\ninterface ICommonProps {\n\tusageType: NodeUsageType;\n\tcompletedGCRuns: number;\n\tisTombstoned: boolean;\n\tlastSummaryTime?: number;\n\tviaHandle?: boolean;\n}\n\n/** The event that is logged when unreferenced node is used after a certain time. */\ninterface IUnreferencedEventProps extends ICreateContainerMetadata, ICommonProps {\n\tstate: UnreferencedState;\n\tid: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n\ttype: GCNodeType;\n\tunrefTime: number;\n\tage: number;\n\ttimeout?: number;\n\tfromId?: {\n\t\tvalue: string;\n\t\ttag: string;\n\t};\n}\n\n/** Properties passed to nodeUsed function when a node is used. */\ninterface INodeUsageProps extends ICommonProps {\n\tid: string;\n\tcurrentReferenceTimestampMs: number | undefined;\n\tpackagePath: readonly string[] | undefined;\n\tfromId?: string;\n}\n\n/**\n * Encapsulates the logic that tracks the various telemetry logged by the Garbage Collector. There are 4 types of\n * telemetry logged:\n * 1. inactiveObject telemetry - When an inactive node is used - A node that has been unreferenced for inactiveTimeoutMs.\n * 2. sweepReadyObject telemetry - When a sweep ready node is used - A node that has been unreferenced for sweepTimeoutMs.\n * 3. Tombstone telemetry - When a tombstoned node is used - A node that that has been marked as tombstone.\n * 4. Sweep / deleted telemetry - When a node is detected as sweep ready in the sweep phase.\n * 5. Unknown outbound reference telemetry - When a node is referenced but GC is not explicitly notified of it.\n */\nexport class GCTelemetryTracker {\n\t// Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one\n\t// per event per node.\n\tprivate readonly loggedUnreferencedEvents: Set<string> = new Set();\n\t// Queue for unreferenced events that should be logged the next time GC runs.\n\tprivate pendingEventsQueue: IUnreferencedEventProps[] = [];\n\n\tconstructor(\n\t\tprivate readonly mc: MonitoringContext,\n\t\tprivate readonly configs: Pick<\n\t\t\tIGarbageCollectorConfigs,\n\t\t\t\"inactiveTimeoutMs\" | \"sweepTimeoutMs\"\n\t\t>,\n\t\tprivate readonly isSummarizerClient: boolean,\n\t\tprivate readonly gcTombstoneEnforcementAllowed: boolean,\n\t\tprivate readonly createContainerMetadata: ICreateContainerMetadata,\n\t\tprivate readonly getNodeType: (nodeId: string) => GCNodeType,\n\t\tprivate readonly getNodeStateTracker: (\n\t\t\tnodeId: string,\n\t\t) => UnreferencedStateTracker | undefined,\n\t\tprivate readonly getNodePackagePath: (\n\t\t\tnodePath: string,\n\t\t) => Promise<readonly string[] | undefined>,\n\t) {}\n\n\t/**\n\t * Returns whether an event should be logged for a node that isn't active anymore. Some scenarios where we won't log:\n\t * 1. When a DDS is changed or loaded. The corresponding data store's event will be logged instead.\n\t * 2. An event is logged only once per container instance per event per node.\n\t */\n\tprivate shouldLogNonActiveEvent(\n\t\tnodeId: string,\n\t\tnodeType: GCNodeType,\n\t\tusageType: NodeUsageType,\n\t\tnodeStateTracker: UnreferencedStateTracker,\n\t\tuniqueEventId: string,\n\t) {\n\t\tif (nodeStateTracker.state === UnreferencedState.Active) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// For sub data store (DDS) nodes, if they are changed or loaded, its data store will also be changed or loaded,\n\t\t// so skip logging to make the telemetry less noisy.\n\t\tif (nodeType === GCNodeType.SubDataStore && usageType !== \"Revived\") {\n\t\t\treturn false;\n\t\t}\n\t\tif (nodeType === GCNodeType.Other) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (this.loggedUnreferencedEvents.has(uniqueEventId)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Called when a node is used. If the node is not active, log an event indicating object is used when its not active.\n\t */\n\tpublic nodeUsed(nodeUsageProps: INodeUsageProps) {\n\t\t// If there is no reference timestamp to work with, no ops have been processed after creation. If so, skip\n\t\t// logging as nothing interesting would have happened worth logging.\n\t\t// If the node is not unreferenced, skip logging.\n\t\tconst nodeStateTracker = this.getNodeStateTracker(nodeUsageProps.id);\n\t\tif (!nodeStateTracker || nodeUsageProps.currentReferenceTimestampMs === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We log these events once per event per node. A unique id is generated by joining node state (inactive / sweep ready),\n\t\t// node's id and usage (loaded / changed / revived).\n\t\tconst uniqueEventId = `${nodeStateTracker.state}-${nodeUsageProps.id}-${nodeUsageProps.usageType}`;\n\t\tconst nodeType = this.getNodeType(nodeUsageProps.id);\n\t\tif (\n\t\t\t!this.shouldLogNonActiveEvent(\n\t\t\t\tnodeUsageProps.id,\n\t\t\t\tnodeType,\n\t\t\t\tnodeUsageProps.usageType,\n\t\t\t\tnodeStateTracker,\n\t\t\t\tuniqueEventId,\n\t\t\t)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Add the unique event id so that we don't generate a log for this event again in this session..\n\t\tthis.loggedUnreferencedEvents.add(uniqueEventId);\n\n\t\tconst state = nodeStateTracker.state;\n\t\tconst { usageType, currentReferenceTimestampMs, packagePath, id, fromId, ...propsToLog } =\n\t\t\tnodeUsageProps;\n\t\tconst eventProps: Omit<IUnreferencedEventProps, \"state\" | \"usageType\"> = {\n\t\t\tid: tagAsCodeArtifact(id),\n\t\t\ttype: nodeType,\n\t\t\tunrefTime: nodeStateTracker.unreferencedTimestampMs,\n\t\t\tage:\n\t\t\t\tnodeUsageProps.currentReferenceTimestampMs -\n\t\t\t\tnodeStateTracker.unreferencedTimestampMs,\n\t\t\ttimeout:\n\t\t\t\tstate === UnreferencedState.Inactive\n\t\t\t\t\t? this.configs.inactiveTimeoutMs\n\t\t\t\t\t: this.configs.sweepTimeoutMs,\n\t\t\tfromId: fromId ? tagAsCodeArtifact(fromId) : undefined,\n\t\t\t...propsToLog,\n\t\t\t...this.createContainerMetadata,\n\t\t};\n\n\t\t// This will log the following events:\n\t\t// GC_Tombstone_DataStore_Revived, GC_Tombstone_SubDataStore_Revived, GC_Tombstone_Blob_Revived\n\t\tif (nodeUsageProps.usageType === \"Revived\" && nodeUsageProps.isTombstoned) {\n\t\t\tsendGCUnexpectedUsageEvent(\n\t\t\t\tthis.mc,\n\t\t\t\t{\n\t\t\t\t\teventName: `GC_Tombstone_${nodeType}_Revived`,\n\t\t\t\t\tcategory: \"generic\",\n\t\t\t\t\turl: tagAsCodeArtifact(id),\n\t\t\t\t\tgcTombstoneEnforcementAllowed: this.gcTombstoneEnforcementAllowed,\n\t\t\t\t},\n\t\t\t\tundefined /* packagePath */,\n\t\t\t);\n\t\t}\n\n\t\t// For summarizer client, queue the event so it is logged the next time GC runs if the event is still valid.\n\t\t// For non-summarizer client, log the event now since GC won't run on it. This may result in false positives\n\t\t// but it's a good signal nonetheless and we can consume it with a grain of salt.\n\t\t// Inactive errors are usages of Objects that are unreferenced for at least a period of 7 days.\n\t\t// SweepReady errors are usages of Objects that will be deleted by GC Sweep!\n\t\tif (this.isSummarizerClient) {\n\t\t\tthis.pendingEventsQueue.push({\n\t\t\t\t...eventProps,\n\t\t\t\tusageType: nodeUsageProps.usageType,\n\t\t\t\tstate,\n\t\t\t});\n\t\t} else {\n\t\t\t// For non-summarizer clients, only log \"Loaded\" type events since these objects may not be loaded in the\n\t\t\t// summarizer clients if they are based off of user actions (such as scrolling to content for these objects)\n\t\t\t// Events generated:\n\t\t\t// InactiveObject_Loaded, SweepReadyObject_Loaded\n\t\t\tif (nodeUsageProps.usageType === \"Loaded\") {\n\t\t\t\tconst { id: taggedId, fromId: taggedFromId, ...otherProps } = eventProps;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${nodeUsageProps.usageType}`,\n\t\t\t\t\tpkg: packagePathToTelemetryProperty(nodeUsageProps.packagePath),\n\t\t\t\t\tstack: generateStack(),\n\t\t\t\t\tid: taggedId,\n\t\t\t\t\tfromId: taggedFromId,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\t...otherProps,\n\t\t\t\t\t}),\n\t\t\t\t};\n\n\t\t\t\t// Do not log the inactive object x events as error events as they are not the best signal for\n\t\t\t\t// detecting something wrong with GC either from the partner or from the runtime itself.\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tthis.mc.logger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tthis.mc.logger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Log all new references or outbound routes in the current graph that haven't been explicitly notified to GC.\n\t * The principle is that every new reference or outbound route must be notified to GC via the\n\t * addedOutboundReference method. It it hasn't, its a bug and we want to identify these scenarios.\n\t *\n\t * In more simple terms:\n\t * Missing Explicit References = Current References - Previous References - Explicitly Added References;\n\t *\n\t * @param currentGCData - The GC data (reference graph) from the current GC run.\n\t * @param previousGCData - The GC data (reference graph) from the previous GC run.\n\t * @param explicitReferences - New references added explicity between the previous and the current run.\n\t */\n\tpublic logIfMissingExplicitReferences(\n\t\tcurrentGCData: IGarbageCollectionData,\n\t\tpreviousGCData: IGarbageCollectionData,\n\t\texplicitReferences: Map<string, string[]>,\n\t\tlogger: ITelemetryLogger,\n\t) {\n\t\tfor (const [nodeId, currentOutboundRoutes] of Object.entries(currentGCData.gcNodes)) {\n\t\t\tconst previousRoutes = previousGCData.gcNodes[nodeId] ?? [];\n\t\t\tconst explicitRoutes = explicitReferences.get(nodeId) ?? [];\n\n\t\t\t/**\n\t\t\t * 1. For routes in the current GC data, routes that were not present in previous GC data and did not have\n\t\t\t * explicit references should be added to missing explicit routes list.\n\t\t\t * 2. Only include data store and blob routes since GC only works for these two.\n\t\t\t * Note: Due to a bug with de-duped blobs, only adding data store routes for now.\n\t\t\t * 3. Ignore DDS routes to their parent datastores since those were added implicitly. So, there won't be\n\t\t\t * explicit routes to them.\n\t\t\t */\n\t\t\tconst missingExplicitRoutes: string[] = [];\n\t\t\tfor (const route of currentOutboundRoutes) {\n\t\t\t\tconst nodeType = this.getNodeType(route);\n\t\t\t\tif (\n\t\t\t\t\t(nodeType === GCNodeType.DataStore || nodeType === GCNodeType.Blob) &&\n\t\t\t\t\t!nodeId.startsWith(route) &&\n\t\t\t\t\t!previousRoutes.includes(route) &&\n\t\t\t\t\t!explicitRoutes.includes(route)\n\t\t\t\t) {\n\t\t\t\t\tmissingExplicitRoutes.push(route);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (missingExplicitRoutes.length > 0) {\n\t\t\t\tlogger.sendErrorEvent({\n\t\t\t\t\teventName: \"gcUnknownOutboundReferences\",\n\t\t\t\t\tid: tagAsCodeArtifact(nodeId),\n\t\t\t\t\troutes: tagAsCodeArtifact(JSON.stringify(missingExplicitRoutes)),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Log events that are pending in pendingEventsQueue. This is called after GC runs in the summarizer client\n\t * so that the state of an unreferenced node is updated.\n\t */\n\tpublic async logPendingEvents(logger: ITelemetryLogger) {\n\t\t// Events sent come only from the summarizer client. In between summaries, events are pushed to a queue and at\n\t\t// summary time they are then logged.\n\t\t// Events generated:\n\t\t// InactiveObject_Loaded, InactiveObject_Changed, InactiveObject_Revived\n\t\t// SweepReadyObject_Loaded, SweepReadyObject_Changed, SweepReadyObject_Revived\n\t\tfor (const eventProps of this.pendingEventsQueue) {\n\t\t\tconst { usageType, state, id, fromId, ...propsToLog } = eventProps;\n\t\t\t/**\n\t\t\t * Revived event is logged only if the node is active. If the node is not active, the reference to it was\n\t\t\t * from another unreferenced node and this scenario is not interesting to log.\n\t\t\t * Loaded and Changed events are logged only if the node is not active. If the node is active, it was\n\t\t\t * revived and a Revived event will be logged for it.\n\t\t\t */\n\t\t\tconst nodeStateTracker = this.getNodeStateTracker(eventProps.id.value);\n\t\t\tconst active =\n\t\t\t\tnodeStateTracker === undefined ||\n\t\t\t\tnodeStateTracker.state === UnreferencedState.Active;\n\t\t\tif ((usageType === \"Revived\") === active) {\n\t\t\t\tconst pkg = await this.getNodePackagePath(eventProps.id.value);\n\t\t\t\tconst fromPkg = eventProps.fromId\n\t\t\t\t\t? await this.getNodePackagePath(eventProps.fromId.value)\n\t\t\t\t\t: undefined;\n\t\t\t\tconst event = {\n\t\t\t\t\teventName: `${state}Object_${usageType}`,\n\t\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\t\t...propsToLog,\n\t\t\t\t\t}),\n\t\t\t\t\tid,\n\t\t\t\t\tfromId,\n\t\t\t\t\tpkg: pkg ? tagAsCodeArtifact(pkg.join(\"/\")) : undefined,\n\t\t\t\t\tfromPkg: fromPkg ? tagAsCodeArtifact(fromPkg.join(\"/\")) : undefined,\n\t\t\t\t};\n\n\t\t\t\tif (state === UnreferencedState.Inactive) {\n\t\t\t\t\tlogger.sendTelemetryEvent(event);\n\t\t\t\t} else {\n\t\t\t\t\tlogger.sendErrorEvent(event);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.pendingEventsQueue = [];\n\t}\n\n\t/**\n\t * For nodes that are ready to sweep, log an event for now. Until we start running sweep which deletes objects,\n\t * this will give us a view into how much deleted content a container has.\n\t */\n\tpublic logSweepEvents(\n\t\tlogger: ITelemetryLogger,\n\t\tcurrentReferenceTimestampMs: number,\n\t\tunreferencedNodesState: Map<string, UnreferencedStateTracker>,\n\t\tcompletedGCRuns: number,\n\t\tlastSummaryTime?: number,\n\t) {\n\t\tif (\n\t\t\tthis.mc.config.getBoolean(disableSweepLogKey) === true ||\n\t\t\tthis.configs.sweepTimeoutMs === undefined\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst deletedNodeIds: string[] = [];\n\t\tfor (const [nodeId, nodeStateTracker] of unreferencedNodesState) {\n\t\t\tif (nodeStateTracker.state !== UnreferencedState.SweepReady) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst nodeType = this.getNodeType(nodeId);\n\t\t\tif (nodeType !== GCNodeType.DataStore && nodeType !== GCNodeType.Blob) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Log deleted event for each node only once to reduce noise in telemetry.\n\t\t\tconst uniqueEventId = `Deleted-${nodeId}`;\n\t\t\tif (this.loggedUnreferencedEvents.has(uniqueEventId)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tthis.loggedUnreferencedEvents.add(uniqueEventId);\n\t\t\tdeletedNodeIds.push(nodeId);\n\t\t}\n\n\t\tif (deletedNodeIds.length > 0) {\n\t\t\tlogger.sendTelemetryEvent({\n\t\t\t\teventName: \"GC_SweepReadyObjects_Delete\",\n\t\t\t\tdetails: JSON.stringify({\n\t\t\t\t\ttimeout: this.configs.sweepTimeoutMs,\n\t\t\t\t\tcompletedGCRuns,\n\t\t\t\t\tlastSummaryTime,\n\t\t\t\t\t...this.createContainerMetadata,\n\t\t\t\t}),\n\t\t\t\tid: tagAsCodeArtifact(JSON.stringify(deletedNodeIds)),\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Consolidates info / logic for logging when we encounter unexpected usage of GC'd objects. For example, when a\n * tombstoned or deleted object is loaded.\n */\nexport function sendGCUnexpectedUsageEvent(\n\tmc: MonitoringContext,\n\tevent: ITelemetryGenericEvent & {\n\t\tcategory: \"error\" | \"generic\";\n\t\tgcTombstoneEnforcementAllowed: boolean | undefined;\n\t},\n\tpackagePath: readonly string[] | undefined,\n\terror?: unknown,\n) {\n\tevent.pkg = packagePathToTelemetryProperty(packagePath);\n\tevent.tombstoneFlags = JSON.stringify({\n\t\tDisableTombstone: mc.config.getBoolean(disableTombstoneKey),\n\t\tThrowOnTombstoneUsage: mc.config.getBoolean(throwOnTombstoneUsageKey),\n\t\tThrowOnTombstoneLoad: mc.config.getBoolean(throwOnTombstoneLoadKey),\n\t});\n\tevent.sweepFlags = JSON.stringify({\n\t\tEnableSweepFlag: mc.config.getBoolean(runSweepKey),\n\t});\n\n\tmc.logger.sendTelemetryEvent(event, error);\n}\n"]}
package/lib/gc/index.d.ts CHANGED
@@ -4,10 +4,10 @@
4
4
  */
5
5
  export { GarbageCollector } from "./garbageCollection";
6
6
  export { currentGCVersion, defaultInactiveTimeoutMs, defaultSessionExpiryDurationMs, disableSweepLogKey, GCNodeType, gcTestModeKey, gcTombstoneGenerationOptionName, gcSweepGenerationOptionName, GCFeatureMatrix, GCVersion, gcVersionUpgradeToV3Key, IGarbageCollectionRuntime, IGarbageCollector, IGarbageCollectorConfigs, IGarbageCollectorCreateParams, IGCMetadata, IGCResult, IGCRuntimeOptions, IGCStats, oneDayMs, runGCKey, runSessionExpiryKey, runSweepKey, stableGCVersion, sweepAttachmentBlobsKey, sweepDatastoresKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey, UnreferencedState, } from "./gcDefinitions";
7
- export { cloneGCData, concatGarbageCollectionStates, getGCDataFromSnapshot, sendGCUnexpectedUsageEvent, shouldAllowGcTombstoneEnforcement, shouldAllowGcSweep, trimLeadingAndTrailingSlashes, unpackChildNodesGCDetails, } from "./gcHelpers";
7
+ export { cloneGCData, concatGarbageCollectionStates, getGCDataFromSnapshot, shouldAllowGcTombstoneEnforcement, shouldAllowGcSweep, trimLeadingAndTrailingSlashes, unpackChildNodesGCDetails, tagAsCodeArtifact, } from "./gcHelpers";
8
8
  export { runGarbageCollection } from "./gcReferenceGraphAlgorithm";
9
9
  export { IGarbageCollectionNodeData, IGarbageCollectionSnapshotData, IGarbageCollectionState, IGarbageCollectionSummaryDetailsLegacy, } from "./gcSummaryDefinitions";
10
10
  export { gcStateBlobKey, GCSummaryStateTracker, IGCSummaryTrackingData, } from "./gcSummaryStateTracker";
11
- export { skipClosureForXDaysKey, closuresMapLocalStorageKey, SweepReadyUsageDetectionHandler, } from "./gcSweepReadyUsageDetection";
11
+ export { GCTelemetryTracker, sendGCUnexpectedUsageEvent } from "./gcTelemetry";
12
12
  export { UnreferencedStateTracker } from "./gcUnreferencedStateTracker";
13
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gc/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,+BAA+B,EAC/B,2BAA2B,EAC3B,eAAe,EACf,SAAS,EACT,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,6BAA6B,EAC7B,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,EAC1B,iCAAiC,EACjC,kBAAkB,EAClB,6BAA6B,EAC7B,yBAAyB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,EACvB,sCAAsC,GACtC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/gc/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,+BAA+B,EAC/B,2BAA2B,EAC3B,eAAe,EACf,SAAS,EACT,uBAAuB,EACvB,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,EACxB,6BAA6B,EAC7B,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,6BAA6B,EAC7B,qBAAqB,EACrB,iCAAiC,EACjC,kBAAkB,EAClB,6BAA6B,EAC7B,yBAAyB,EACzB,iBAAiB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,EACvB,sCAAsC,GACtC,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACN,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC"}
package/lib/gc/index.js CHANGED
@@ -4,9 +4,9 @@
4
4
  */
5
5
  export { GarbageCollector } from "./garbageCollection";
6
6
  export { currentGCVersion, defaultInactiveTimeoutMs, defaultSessionExpiryDurationMs, disableSweepLogKey, GCNodeType, gcTestModeKey, gcTombstoneGenerationOptionName, gcSweepGenerationOptionName, gcVersionUpgradeToV3Key, oneDayMs, runGCKey, runSessionExpiryKey, runSweepKey, stableGCVersion, sweepAttachmentBlobsKey, sweepDatastoresKey, throwOnTombstoneLoadKey, throwOnTombstoneUsageKey, UnreferencedState, } from "./gcDefinitions";
7
- export { cloneGCData, concatGarbageCollectionStates, getGCDataFromSnapshot, sendGCUnexpectedUsageEvent, shouldAllowGcTombstoneEnforcement, shouldAllowGcSweep, trimLeadingAndTrailingSlashes, unpackChildNodesGCDetails, } from "./gcHelpers";
7
+ export { cloneGCData, concatGarbageCollectionStates, getGCDataFromSnapshot, shouldAllowGcTombstoneEnforcement, shouldAllowGcSweep, trimLeadingAndTrailingSlashes, unpackChildNodesGCDetails, tagAsCodeArtifact, } from "./gcHelpers";
8
8
  export { runGarbageCollection } from "./gcReferenceGraphAlgorithm";
9
9
  export { gcStateBlobKey, GCSummaryStateTracker, } from "./gcSummaryStateTracker";
10
- export { skipClosureForXDaysKey, closuresMapLocalStorageKey, SweepReadyUsageDetectionHandler, } from "./gcSweepReadyUsageDetection";
10
+ export { GCTelemetryTracker, sendGCUnexpectedUsageEvent } from "./gcTelemetry";
11
11
  export { UnreferencedStateTracker } from "./gcUnreferencedStateTracker";
12
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gc/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,+BAA+B,EAC/B,2BAA2B,EAG3B,uBAAuB,EASvB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,EAC1B,iCAAiC,EACjC,kBAAkB,EAClB,6BAA6B,EAC7B,yBAAyB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAOnE,OAAO,EACN,cAAc,EACd,qBAAqB,GAErB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACN,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { GarbageCollector } from \"./garbageCollection\";\nexport {\n\tcurrentGCVersion,\n\tdefaultInactiveTimeoutMs,\n\tdefaultSessionExpiryDurationMs,\n\tdisableSweepLogKey,\n\tGCNodeType,\n\tgcTestModeKey,\n\tgcTombstoneGenerationOptionName,\n\tgcSweepGenerationOptionName,\n\tGCFeatureMatrix,\n\tGCVersion,\n\tgcVersionUpgradeToV3Key,\n\tIGarbageCollectionRuntime,\n\tIGarbageCollector,\n\tIGarbageCollectorConfigs,\n\tIGarbageCollectorCreateParams,\n\tIGCMetadata,\n\tIGCResult,\n\tIGCRuntimeOptions,\n\tIGCStats,\n\toneDayMs,\n\trunGCKey,\n\trunSessionExpiryKey,\n\trunSweepKey,\n\tstableGCVersion,\n\tsweepAttachmentBlobsKey,\n\tsweepDatastoresKey,\n\tthrowOnTombstoneLoadKey,\n\tthrowOnTombstoneUsageKey,\n\tUnreferencedState,\n} from \"./gcDefinitions\";\nexport {\n\tcloneGCData,\n\tconcatGarbageCollectionStates,\n\tgetGCDataFromSnapshot,\n\tsendGCUnexpectedUsageEvent,\n\tshouldAllowGcTombstoneEnforcement,\n\tshouldAllowGcSweep,\n\ttrimLeadingAndTrailingSlashes,\n\tunpackChildNodesGCDetails,\n} from \"./gcHelpers\";\nexport { runGarbageCollection } from \"./gcReferenceGraphAlgorithm\";\nexport {\n\tIGarbageCollectionNodeData,\n\tIGarbageCollectionSnapshotData,\n\tIGarbageCollectionState,\n\tIGarbageCollectionSummaryDetailsLegacy,\n} from \"./gcSummaryDefinitions\";\nexport {\n\tgcStateBlobKey,\n\tGCSummaryStateTracker,\n\tIGCSummaryTrackingData,\n} from \"./gcSummaryStateTracker\";\nexport {\n\tskipClosureForXDaysKey,\n\tclosuresMapLocalStorageKey,\n\tSweepReadyUsageDetectionHandler,\n} from \"./gcSweepReadyUsageDetection\";\nexport { UnreferencedStateTracker } from \"./gcUnreferencedStateTracker\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/gc/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,8BAA8B,EAC9B,kBAAkB,EAClB,UAAU,EACV,aAAa,EACb,+BAA+B,EAC/B,2BAA2B,EAG3B,uBAAuB,EASvB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,WAAW,EACX,6BAA6B,EAC7B,qBAAqB,EACrB,iCAAiC,EACjC,kBAAkB,EAClB,6BAA6B,EAC7B,yBAAyB,EACzB,iBAAiB,GACjB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAOnE,OAAO,EACN,cAAc,EACd,qBAAqB,GAErB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { GarbageCollector } from \"./garbageCollection\";\nexport {\n\tcurrentGCVersion,\n\tdefaultInactiveTimeoutMs,\n\tdefaultSessionExpiryDurationMs,\n\tdisableSweepLogKey,\n\tGCNodeType,\n\tgcTestModeKey,\n\tgcTombstoneGenerationOptionName,\n\tgcSweepGenerationOptionName,\n\tGCFeatureMatrix,\n\tGCVersion,\n\tgcVersionUpgradeToV3Key,\n\tIGarbageCollectionRuntime,\n\tIGarbageCollector,\n\tIGarbageCollectorConfigs,\n\tIGarbageCollectorCreateParams,\n\tIGCMetadata,\n\tIGCResult,\n\tIGCRuntimeOptions,\n\tIGCStats,\n\toneDayMs,\n\trunGCKey,\n\trunSessionExpiryKey,\n\trunSweepKey,\n\tstableGCVersion,\n\tsweepAttachmentBlobsKey,\n\tsweepDatastoresKey,\n\tthrowOnTombstoneLoadKey,\n\tthrowOnTombstoneUsageKey,\n\tUnreferencedState,\n} from \"./gcDefinitions\";\nexport {\n\tcloneGCData,\n\tconcatGarbageCollectionStates,\n\tgetGCDataFromSnapshot,\n\tshouldAllowGcTombstoneEnforcement,\n\tshouldAllowGcSweep,\n\ttrimLeadingAndTrailingSlashes,\n\tunpackChildNodesGCDetails,\n\ttagAsCodeArtifact,\n} from \"./gcHelpers\";\nexport { runGarbageCollection } from \"./gcReferenceGraphAlgorithm\";\nexport {\n\tIGarbageCollectionNodeData,\n\tIGarbageCollectionSnapshotData,\n\tIGarbageCollectionState,\n\tIGarbageCollectionSummaryDetailsLegacy,\n} from \"./gcSummaryDefinitions\";\nexport {\n\tgcStateBlobKey,\n\tGCSummaryStateTracker,\n\tIGCSummaryTrackingData,\n} from \"./gcSummaryStateTracker\";\nexport { GCTelemetryTracker, sendGCUnexpectedUsageEvent } from \"./gcTelemetry\";\nexport { UnreferencedStateTracker } from \"./gcUnreferencedStateTracker\";\n"]}
@@ -23,7 +23,6 @@ export class OpGroupingManager {
23
23
  assert(keys.length === 0 || keys[0] === "batch", 0x5de /* unexpected op metadata */);
24
24
  }
25
25
  }
26
- // Need deserializedContent for back-compat
27
26
  const deserializedContent = {
28
27
  type: OpGroupingManager.groupedBatchOp,
29
28
  contents: batch.content.map((message) => ({
@@ -37,6 +36,7 @@ export class OpGroupingManager {
37
36
  localOpMetadata: undefined,
38
37
  metadata: undefined,
39
38
  referenceSequenceNumber: batch.content[0].referenceSequenceNumber,
39
+ // Need deserializedContent for back-compat
40
40
  deserializedContent: deserializedContent,
41
41
  contents: JSON.stringify(deserializedContent),
42
42
  },
@@ -1 +1 @@
1
- {"version":3,"file":"opGroupingManager.js","sourceRoot":"","sources":["../../src/opLifecycle/opGroupingManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAA2B,MAAM,IAAI,CAAC;AASnE,MAAM,OAAO,iBAAiB;IAG7B,YAA6B,sBAA+B;QAA/B,2BAAsB,GAAtB,sBAAsB,CAAS;IAAG,CAAC;IAEzD,UAAU,CAAC,KAAa;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE;YAC7D,OAAO,KAAK,CAAC;SACb;QAED,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;YACpC,yEAAyE;YACzE,IAAI,OAAO,CAAC,mBAAmB,CAAC,IAAI,KAAK,oBAAoB,CAAC,UAAU,EAAE;gBACzE,OAAO,KAAK,CAAC;aACb;YACD,IAAI,OAAO,CAAC,QAAQ,EAAE;gBACrB,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAC3C,MAAM,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,oCAAoC,CAAC,CAAC;gBACpE,MAAM,CACL,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,OAAO,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AU,CAAC,QAAQ,EAC7B,WAAW,EAAE,UAAU,CAAC,WAAW,IAClC,CAAC,CAAC;IACL,CAAC;;AA/DM,gCAAc,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ContainerMessageType, ContainerRuntimeMessage } from \"..\";\nimport { IBatch } from \"./definitions\";\n\ninterface IGroupedMessage {\n\tcontents?: unknown;\n\tmetadata?: Record<string, unknown>;\n\tcompression?: string;\n}\n\nexport class OpGroupingManager {\n\tstatic groupedBatchOp = \"groupedBatch\";\n\n\tconstructor(private readonly groupedBatchingEnabled: boolean) {}\n\n\tpublic groupBatch(batch: IBatch): IBatch {\n\t\tif (batch.content.length < 2 || !this.groupedBatchingEnabled) {\n\t\t\treturn batch;\n\t\t}\n\n\t\tfor (const message of batch.content) {\n\t\t\t// Blob attaches cannot be grouped (grouped batching would hide metadata)\n\t\t\tif (message.deserializedContent.type === ContainerMessageType.BlobAttach) {\n\t\t\t\treturn batch;\n\t\t\t}\n\t\t\tif (message.metadata) {\n\t\t\t\tconst keys = Object.keys(message.metadata);\n\t\t\t\tassert(keys.length < 2, 0x5dd /* cannot group ops with metadata */);\n\t\t\t\tassert(\n\t\t\t\t\tkeys.length === 0 || keys[0] === \"batch\",\n\t\t\t\t\t0x5de /* unexpected op metadata */,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Need deserializedContent for back-compat\n\t\tconst deserializedContent = {\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: batch.content.map<IGroupedMessage>((message) => ({\n\t\t\t\tcontents: message.contents === undefined ? undefined : JSON.parse(message.contents),\n\t\t\t\tmetadata: message.metadata,\n\t\t\t\tcompression: message.compression,\n\t\t\t})),\n\t\t};\n\n\t\tconst groupedBatch: IBatch = {\n\t\t\t...batch,\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\tlocalOpMetadata: undefined,\n\t\t\t\t\tmetadata: undefined,\n\t\t\t\t\treferenceSequenceNumber: batch.content[0].referenceSequenceNumber,\n\t\t\t\t\tdeserializedContent: deserializedContent as ContainerRuntimeMessage,\n\t\t\t\t\tcontents: JSON.stringify(deserializedContent),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t\treturn groupedBatch;\n\t}\n\n\tpublic ungroupOp(op: ISequencedDocumentMessage): ISequencedDocumentMessage[] {\n\t\tif (op.contents?.type !== OpGroupingManager.groupedBatchOp) {\n\t\t\treturn [op];\n\t\t}\n\n\t\tconst messages = op.contents.contents as IGroupedMessage[];\n\t\tlet fakeCsn = 1;\n\t\treturn messages.map((subMessage) => ({\n\t\t\t...op,\n\t\t\tclientSequenceNumber: fakeCsn++,\n\t\t\tcontents: subMessage.contents,\n\t\t\tmetadata: subMessage.metadata,\n\t\t\tcompression: subMessage.compression,\n\t\t}));\n\t}\n}\n"]}
1
+ {"version":3,"file":"opGroupingManager.js","sourceRoot":"","sources":["../../src/opLifecycle/opGroupingManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,oBAAoB,EAA2B,MAAM,IAAI,CAAC;AASnE,MAAM,OAAO,iBAAiB;IAG7B,YAA6B,sBAA+B;QAA/B,2BAAsB,GAAtB,sBAAsB,CAAS;IAAG,CAAC;IAEzD,UAAU,CAAC,KAAa;QAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE;YAC7D,OAAO,KAAK,CAAC;SACb;QAED,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;YACpC,yEAAyE;YACzE,IAAI,OAAO,CAAC,mBAAmB,CAAC,IAAI,KAAK,oBAAoB,CAAC,UAAU,EAAE;g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c,EAAE;YAC3D,OAAO,CAAC,EAAE,CAAC,CAAC;SACZ;QAED,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,QAA6B,CAAC;QAC3D,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,iCAChC,EAAE,KACL,oBAAoB,EAAE,OAAO,EAAE,EAC/B,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAC7B,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAC7B,WAAW,EAAE,UAAU,CAAC,WAAW,IAClC,CAAC,CAAC;IACL,CAAC;;AA/DM,gCAAc,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ContainerMessageType, ContainerRuntimeMessage } from \"..\";\nimport { IBatch } from \"./definitions\";\n\ninterface IGroupedMessage {\n\tcontents?: unknown;\n\tmetadata?: Record<string, unknown>;\n\tcompression?: string;\n}\n\nexport class OpGroupingManager {\n\tstatic groupedBatchOp = \"groupedBatch\";\n\n\tconstructor(private readonly groupedBatchingEnabled: boolean) {}\n\n\tpublic groupBatch(batch: IBatch): IBatch {\n\t\tif (batch.content.length < 2 || !this.groupedBatchingEnabled) {\n\t\t\treturn batch;\n\t\t}\n\n\t\tfor (const message of batch.content) {\n\t\t\t// Blob attaches cannot be grouped (grouped batching would hide metadata)\n\t\t\tif (message.deserializedContent.type === ContainerMessageType.BlobAttach) {\n\t\t\t\treturn batch;\n\t\t\t}\n\t\t\tif (message.metadata) {\n\t\t\t\tconst keys = Object.keys(message.metadata);\n\t\t\t\tassert(keys.length < 2, 0x5dd /* cannot group ops with metadata */);\n\t\t\t\tassert(\n\t\t\t\t\tkeys.length === 0 || keys[0] === \"batch\",\n\t\t\t\t\t0x5de /* unexpected op metadata */,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst deserializedContent = {\n\t\t\ttype: OpGroupingManager.groupedBatchOp,\n\t\t\tcontents: batch.content.map<IGroupedMessage>((message) => ({\n\t\t\t\tcontents: message.contents === undefined ? undefined : JSON.parse(message.contents),\n\t\t\t\tmetadata: message.metadata,\n\t\t\t\tcompression: message.compression,\n\t\t\t})),\n\t\t};\n\n\t\tconst groupedBatch: IBatch = {\n\t\t\t...batch,\n\t\t\tcontent: [\n\t\t\t\t{\n\t\t\t\t\tlocalOpMetadata: undefined,\n\t\t\t\t\tmetadata: undefined,\n\t\t\t\t\treferenceSequenceNumber: batch.content[0].referenceSequenceNumber,\n\t\t\t\t\t// Need deserializedContent for back-compat\n\t\t\t\t\tdeserializedContent: deserializedContent as ContainerRuntimeMessage,\n\t\t\t\t\tcontents: JSON.stringify(deserializedContent),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t\treturn groupedBatch;\n\t}\n\n\tpublic ungroupOp(op: ISequencedDocumentMessage): ISequencedDocumentMessage[] {\n\t\tif (op.contents?.type !== OpGroupingManager.groupedBatchOp) {\n\t\t\treturn [op];\n\t\t}\n\n\t\tconst messages = op.contents.contents as IGroupedMessage[];\n\t\tlet fakeCsn = 1;\n\t\treturn messages.map((subMessage) => ({\n\t\t\t...op,\n\t\t\tclientSequenceNumber: fakeCsn++,\n\t\t\tcontents: subMessage.contents,\n\t\t\tmetadata: subMessage.metadata,\n\t\t\tcompression: subMessage.compression,\n\t\t}));\n\t}\n}\n"]}
@@ -134,7 +134,7 @@ export class Outbox {
134
134
  // Nothing to do if the batch is empty or if compression is disabled or not supported, or if we don't need to compress
135
135
  return this.params.groupingManager.groupBatch(batch);
136
136
  }
137
- const compressedBatch = this.params.groupingManager.groupBatch(this.params.compressor.compressBatch(batch));
137
+ const compressedBatch = this.params.compressor.compressBatch(this.params.groupingManager.groupBatch(batch));
138
138
  if (this.params.splitter.isBatchChunkingEnabled) {
139
139
  return compressedBatch.contentSizeInBytes <= this.params.splitter.chunkSizeInBytes
140
140
  ? compressedBatch
@@ -1 +1 @@
1
- {"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EACN,WAAW,EACX,yBAAyB,GAEzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACN,YAAY,EAEZ,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,gBAAgB,CAAC;AAyBxB,SAAS,YAAY,CAAC,MAAmB;IACxC,uFAAuF;IACvF,IAAI;QACH,MAAM,uBAAuB,GAAI,KAAa,CAAC,eAAe,CAAC;QAC9D,KAAa,CAAC,eAAe,GAAG,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;QACvB,KAAa,CAAC,eAAe,GAAG,uBAAuB,CAAC;QACzD,OAAO,MAAM,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACf,OAAO,MAAM,EAAE,CAAC;KAChB;AACF,CAAC;AAED,MAAM,OAAO,MAAM;IAelB,YAA6B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAXrC,sCAAiC,GAAG,GAAG,GAAG,IAAI,CAAC;QAEhE;;;;;WAKG;QACc,6BAAwB,GAAG,CAAC,CAAC;QACtC,0BAAqB,GAAG,CAAC,CAAC;QAGjC,IAAI,CAAC,EAAE,GAAG,yBAAyB,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACjF,MAAM,oBAAoB,GACzB,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,uBAAuB;YA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reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IContainerContext } from \"@fluidframework/container-definitions\";\nimport { GenericError, UsageError } from \"@fluidframework/container-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tChildLogger,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n} from \"@fluidframework/telemetry-utils\";\nimport { ICompressionRuntimeOptions } from \"../containerRuntime\";\nimport { PendingStateManager } from \"../pendingStateManager\";\nimport {\n\tBatchManager,\n\tBatchSequenceNumbers,\n\testimateSocketSize,\n\tsequenceNumbersMatch,\n} from \"./batchManager\";\nimport { BatchMessage, IBatch } from \"./definitions\";\nimport { OpCompressor } from \"./opCompressor\";\nimport { OpGroupingManager } from \"./opGroupingManager\";\nimport { OpSplitter } from \"./opSplitter\";\n\nexport interface IOutboxConfig {\n\treadonly compressionOptions: ICompressionRuntimeOptions;\n\t// The maximum size of a batch that we can send over the wire.\n\treadonly maxBatchSizeInBytes: number;\n\treadonly disablePartialFlush: boolean;\n}\n\nexport interface IOutboxParameters {\n\treadonly shouldSend: () => boolean;\n\treadonly pendingStateManager: PendingStateManager;\n\treadonly containerContext: IContainerContext;\n\treadonly config: IOutboxConfig;\n\treadonly compressor: OpCompressor;\n\treadonly splitter: OpSplitter;\n\treadonly logger: ITelemetryLogger;\n\treadonly groupingManager: OpGroupingManager;\n\treadonly getCurrentSequenceNumbers: () => BatchSequenceNumbers;\n}\n\nfunction getLongStack(action: () => Error): Error {\n\t// Increase the stack trace limit temporarily, so as to debug better in case it occurs.\n\ttry {\n\t\tconst originalStackTraceLimit = (Error as any).stackTraceLimit;\n\t\t(Error as any).stackTraceLimit = 50;\n\t\tconst result = action();\n\t\t(Error as any).stackTraceLimit = originalStackTraceLimit;\n\t\treturn result;\n\t} catch (error) {\n\t\treturn action();\n\t}\n}\n\nexport class Outbox {\n\tprivate readonly mc: MonitoringContext;\n\tprivate readonly attachFlowBatch: BatchManager;\n\tprivate readonly mainBatch: BatchManager;\n\tprivate readonly defaultAttachFlowSoftLimitInBytes = 320 * 1024;\n\n\t/**\n\t * Track the number of ops which were detected to have a mismatched\n\t * reference sequence number, in order to self-throttle the telemetry events.\n\t *\n\t * This should be removed as part of ADO:2322\n\t */\n\tprivate readonly maxMismatchedOpsToReport = 3;\n\tprivate mismatchedOpsReported = 0;\n\n\tconstructor(private readonly params: IOutboxParameters) {\n\t\tthis.mc = loggerToMonitoringContext(ChildLogger.create(params.logger, \"Outbox\"));\n\t\tconst isCompressionEnabled =\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes !==\n\t\t\tNumber.POSITIVE_INFINITY;\n\t\t// We need to allow infinite size batches if we enable compression\n\t\tconst hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;\n\t\tconst softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;\n\n\t\tthis.attachFlowBatch = new BatchManager({ hardLimit, softLimit });\n\t\tthis.mainBatch = new BatchManager({ hardLimit });\n\t}\n\n\tpublic get isEmpty(): boolean {\n\t\treturn this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;\n\t}\n\n\t/**\n\t * If we detect that the reference sequence number of the incoming message does not match\n\t * what was already in the batch managers, this means that batching has been interrupted so\n\t * we will flush the accumulated messages to account for that and create a new batch with the new\n\t * message as the first message.\n\t */\n\tprivate maybeFlushPartialBatch() {\n\t\tconst mainBatchSeqNums = this.mainBatch.sequenceNumbers;\n\t\tconst attachFlowBatchSeqNums = this.attachFlowBatch.sequenceNumbers;\n\t\tassert(\n\t\t\tthis.params.config.disablePartialFlush ||\n\t\t\t\tsequenceNumbersMatch(mainBatchSeqNums, attachFlowBatchSeqNums),\n\t\t\t0x58d /* Reference sequence numbers from both batches must be in sync */,\n\t\t);\n\n\t\tconst currentSequenceNumbers = this.params.getCurrentSequenceNumbers();\n\n\t\tif (\n\t\t\tsequenceNumbersMatch(mainBatchSeqNums, currentSequenceNumbers) &&\n\t\t\tsequenceNumbersMatch(attachFlowBatchSeqNums, currentSequenceNumbers)\n\t\t) {\n\t\t\t// The reference sequence numbers are stable, there is nothing to do\n\t\t\treturn;\n\t\t}\n\n\t\tif (++this.mismatchedOpsReported <= this.maxMismatchedOpsToReport) {\n\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\tcategory: this.params.config.disablePartialFlush ? \"error\" : \"generic\",\n\t\t\t\t\teventName: \"ReferenceSequenceNumberMismatch\",\n\t\t\t\t\tmainReferenceSequenceNumber: mainBatchSeqNums.referenceSequenceNumber,\n\t\t\t\t\tmainClientSequenceNumber: mainBatchSeqNums.clientSequenceNumber,\n\t\t\t\t\tattachReferenceSequenceNumber: attachFlowBatchSeqNums.referenceSequenceNumber,\n\t\t\t\t\tattachClientSequenceNumber: attachFlowBatchSeqNums.clientSequenceNumber,\n\t\t\t\t\tcurrentReferenceSequenceNumber: currentSequenceNumbers.referenceSequenceNumber,\n\t\t\t\t\tcurrentClientSequenceNumber: currentSequenceNumbers.clientSequenceNumber,\n\t\t\t\t},\n\t\t\t\tgetLongStack(() => new UsageError(\"Submission of an out of order message\")),\n\t\t\t);\n\t\t}\n\n\t\tif (!this.params.config.disablePartialFlush) {\n\t\t\tthis.flush();\n\t\t}\n\t}\n\n\tpublic submit(message: BatchMessage) {\n\t\tthis.maybeFlushPartialBatch();\n\n\t\tif (\n\t\t\t!this.mainBatch.push(\n\t\t\t\tmessage,\n\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\topSize: message.contents?.length ?? 0,\n\t\t\t\tbatchSize: this.mainBatch.contentSizeInBytes,\n\t\t\t\tcount: this.mainBatch.length,\n\t\t\t\tlimit: this.mainBatch.options.hardLimit,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic submitAttach(message: BatchMessage) {\n\t\tthis.maybeFlushPartialBatch();\n\n\t\tif (\n\t\t\t!this.attachFlowBatch.push(\n\t\t\t\tmessage,\n\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t)\n\t\t) {\n\t\t\t// BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged\n\t\t\t// when queue is not empty.\n\t\t\t// Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit\n\t\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\t\tif (\n\t\t\t\t!this.attachFlowBatch.push(\n\t\t\t\t\tmessage,\n\t\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\t\topSize: message.contents?.length ?? 0,\n\t\t\t\t\tbatchSize: this.attachFlowBatch.contentSizeInBytes,\n\t\t\t\t\tcount: this.attachFlowBatch.length,\n\t\t\t\t\tlimit: this.attachFlowBatch.options.hardLimit,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// If compression is enabled, we will always successfully receive\n\t\t// attach ops and compress then send them at the next JS turn, regardless\n\t\t// of the overall size of the accumulated ops in the batch.\n\t\t// However, it is more efficient to flush these ops faster, preferably\n\t\t// after they reach a size which would benefit from compression.\n\t\tif (\n\t\t\tthis.attachFlowBatch.contentSizeInBytes >=\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes\n\t\t) {\n\t\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\t}\n\t}\n\n\tpublic flush() {\n\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\tthis.flushInternal(this.mainBatch.popBatch());\n\t}\n\n\tprivate flushInternal(rawBatch: IBatch) {\n\t\tconst processedBatch = this.compressBatch(rawBatch);\n\t\tthis.sendBatch(processedBatch);\n\n\t\tthis.persistBatch(rawBatch.content);\n\t}\n\n\tprivate compressBatch(batch: IBatch): IBatch {\n\t\tif (\n\t\t\tbatch.content.length === 0 ||\n\t\t\tthis.params.config.compressionOptions === undefined ||\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes >\n\t\t\t\tbatch.contentSizeInBytes ||\n\t\t\tthis.params.containerContext.submitBatchFn === undefined\n\t\t) {\n\t\t\t// Nothing to do if the batch is empty or if compression is disabled or not supported, or if we don't need to compress\n\t\t\treturn this.params.groupingManager.groupBatch(batch);\n\t\t}\n\n\t\tconst compressedBatch = this.params.groupingManager.groupBatch(\n\t\t\tthis.params.compressor.compressBatch(batch),\n\t\t);\n\n\t\tif (this.params.splitter.isBatchChunkingEnabled) {\n\t\t\treturn compressedBatch.contentSizeInBytes <= this.params.splitter.chunkSizeInBytes\n\t\t\t\t? compressedBatch\n\t\t\t\t: this.params.splitter.splitFirstBatchMessage(compressedBatch);\n\t\t}\n\n\t\tif (compressedBatch.contentSizeInBytes >= this.params.config.maxBatchSizeInBytes) {\n\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\tbatchSize: batch.contentSizeInBytes,\n\t\t\t\tcompressedBatchSize: compressedBatch.contentSizeInBytes,\n\t\t\t\tcount: compressedBatch.content.length,\n\t\t\t\tlimit: this.params.config.maxBatchSizeInBytes,\n\t\t\t\tchunkingEnabled: this.params.splitter.isBatchChunkingEnabled,\n\t\t\t\tcompressionOptions: JSON.stringify(this.params.config.compressionOptions),\n\t\t\t\tsocketSize: estimateSocketSize(batch),\n\t\t\t});\n\t\t}\n\n\t\treturn compressedBatch;\n\t}\n\n\t/**\n\t * Sends the batch object to the container context to be sent over the wire.\n\t *\n\t * @param batch - batch to be sent\n\t */\n\tprivate sendBatch(batch: IBatch) {\n\t\tconst length = batch.content.length;\n\n\t\t// Did we disconnect in the middle of turn-based batch?\n\t\t// If so, do nothing, as pending state manager will resubmit it correctly on reconnect.\n\t\tif (length === 0 || !this.params.shouldSend()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst socketSize = estimateSocketSize(batch);\n\t\tif (socketSize >= this.params.config.maxBatchSizeInBytes) {\n\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"LargeBatch\",\n\t\t\t\tlength: batch.content.length,\n\t\t\t\tsizeInBytes: batch.contentSizeInBytes,\n\t\t\t\tsocketSize,\n\t\t\t});\n\t\t}\n\n\t\tif (this.params.containerContext.submitBatchFn === undefined) {\n\t\t\t// Legacy path - supporting old loader versions. Can be removed only when LTS moves above\n\t\t\t// version that has support for batches (submitBatchFn)\n\t\t\tassert(\n\t\t\t\tbatch.content[0].compression === undefined,\n\t\t\t\t0x5a6 /* Compression should not have happened if the loader does not support it */,\n\t\t\t);\n\n\t\t\tfor (const message of batch.content) {\n\t\t\t\tthis.params.containerContext.submitFn(\n\t\t\t\t\tMessageType.Operation,\n\t\t\t\t\tmessage.deserializedContent,\n\t\t\t\t\ttrue, // batch\n\t\t\t\t\tmessage.metadata,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.params.containerContext.deltaManager.flush();\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tbatch.referenceSequenceNumber !== undefined,\n\t\t\t\t0x58e /* Batch must not be empty */,\n\t\t\t);\n\t\t\tthis.params.containerContext.submitBatchFn(\n\t\t\t\tbatch.content.map((message) => ({\n\t\t\t\t\tcontents: message.contents,\n\t\t\t\t\tmetadata: message.metadata,\n\t\t\t\t\tcompression: message.compression,\n\t\t\t\t\treferenceSequenceNumber: message.referenceSequenceNumber,\n\t\t\t\t})),\n\t\t\t\tbatch.referenceSequenceNumber,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate persistBatch(batch: BatchMessage[]) {\n\t\t// Let the PendingStateManager know that a message was submitted.\n\t\t// In future, need to shift toward keeping batch as a whole!\n\t\tfor (const message of batch) {\n\t\t\tthis.params.pendingStateManager.onSubmitMessage(\n\t\t\t\tmessage.deserializedContent.type,\n\t\t\t\tmessage.referenceSequenceNumber,\n\t\t\t\tmessage.deserializedContent.contents,\n\t\t\t\tmessage.localOpMetadata,\n\t\t\t\tmessage.metadata,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic checkpoint() {\n\t\treturn {\n\t\t\tmainBatch: this.mainBatch.checkpoint(),\n\t\t\tattachFlowBatch: this.attachFlowBatch.checkpoint(),\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"outbox.js","sourceRoot":"","sources":["../../src/opLifecycle/outbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EACN,WAAW,EACX,yBAAyB,GAEzB,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EACN,YAAY,EAEZ,kBAAkB,EAClB,oBAAoB,GACpB,MAAM,gBAAgB,CAAC;AAyBxB,SAAS,YAAY,CAAC,MAAmB;IACxC,uFAAuF;IACvF,IAAI;QACH,MAAM,uBAAuB,GAAI,KAAa,CAAC,eAAe,CAAC;QAC9D,KAAa,CAAC,eAAe,GAAG,EAAE,CAAC;QACpC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC;QACvB,KAAa,CAAC,eAAe,GAAG,uBAAuB,CAAC;QACzD,OAAO,MAAM,CAAC;KACd;IAAC,OAAO,KAAK,EAAE;QACf,OAAO,MAAM,EAAE,CAAC;KAChB;AACF,CAAC;AAED,MAAM,OAAO,MAAM;IAelB,YAA6B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;QAXrC,sCAAiC,GAAG,GAAG,GAAG,IAAI,CAAC;QAEhE;;;;;WAKG;QACc,6BAAwB,GAAG,CAAC,CAAC;QACtC,0BAAqB,GAAG,CAAC,CAAC;QAGjC,IAAI,CAAC,EAAE,GAAG,yBAAyB,CAAC,WAAW,CAAC,MAAM,CAAC,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AU,EAAE;YACtC,eAAe,EAAE,IAAI,CAAC,eAAe,CAAC,UAAU,EAAE;SAClD,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { IContainerContext } from \"@fluidframework/container-definitions\";\nimport { GenericError, UsageError } from \"@fluidframework/container-utils\";\nimport { MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\tChildLogger,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n} from \"@fluidframework/telemetry-utils\";\nimport { ICompressionRuntimeOptions } from \"../containerRuntime\";\nimport { PendingStateManager } from \"../pendingStateManager\";\nimport {\n\tBatchManager,\n\tBatchSequenceNumbers,\n\testimateSocketSize,\n\tsequenceNumbersMatch,\n} from \"./batchManager\";\nimport { BatchMessage, IBatch } from \"./definitions\";\nimport { OpCompressor } from \"./opCompressor\";\nimport { OpGroupingManager } from \"./opGroupingManager\";\nimport { OpSplitter } from \"./opSplitter\";\n\nexport interface IOutboxConfig {\n\treadonly compressionOptions: ICompressionRuntimeOptions;\n\t// The maximum size of a batch that we can send over the wire.\n\treadonly maxBatchSizeInBytes: number;\n\treadonly disablePartialFlush: boolean;\n}\n\nexport interface IOutboxParameters {\n\treadonly shouldSend: () => boolean;\n\treadonly pendingStateManager: PendingStateManager;\n\treadonly containerContext: IContainerContext;\n\treadonly config: IOutboxConfig;\n\treadonly compressor: OpCompressor;\n\treadonly splitter: OpSplitter;\n\treadonly logger: ITelemetryLogger;\n\treadonly groupingManager: OpGroupingManager;\n\treadonly getCurrentSequenceNumbers: () => BatchSequenceNumbers;\n}\n\nfunction getLongStack(action: () => Error): Error {\n\t// Increase the stack trace limit temporarily, so as to debug better in case it occurs.\n\ttry {\n\t\tconst originalStackTraceLimit = (Error as any).stackTraceLimit;\n\t\t(Error as any).stackTraceLimit = 50;\n\t\tconst result = action();\n\t\t(Error as any).stackTraceLimit = originalStackTraceLimit;\n\t\treturn result;\n\t} catch (error) {\n\t\treturn action();\n\t}\n}\n\nexport class Outbox {\n\tprivate readonly mc: MonitoringContext;\n\tprivate readonly attachFlowBatch: BatchManager;\n\tprivate readonly mainBatch: BatchManager;\n\tprivate readonly defaultAttachFlowSoftLimitInBytes = 320 * 1024;\n\n\t/**\n\t * Track the number of ops which were detected to have a mismatched\n\t * reference sequence number, in order to self-throttle the telemetry events.\n\t *\n\t * This should be removed as part of ADO:2322\n\t */\n\tprivate readonly maxMismatchedOpsToReport = 3;\n\tprivate mismatchedOpsReported = 0;\n\n\tconstructor(private readonly params: IOutboxParameters) {\n\t\tthis.mc = loggerToMonitoringContext(ChildLogger.create(params.logger, \"Outbox\"));\n\t\tconst isCompressionEnabled =\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes !==\n\t\t\tNumber.POSITIVE_INFINITY;\n\t\t// We need to allow infinite size batches if we enable compression\n\t\tconst hardLimit = isCompressionEnabled ? Infinity : this.params.config.maxBatchSizeInBytes;\n\t\tconst softLimit = isCompressionEnabled ? Infinity : this.defaultAttachFlowSoftLimitInBytes;\n\n\t\tthis.attachFlowBatch = new BatchManager({ hardLimit, softLimit });\n\t\tthis.mainBatch = new BatchManager({ hardLimit });\n\t}\n\n\tpublic get isEmpty(): boolean {\n\t\treturn this.attachFlowBatch.length === 0 && this.mainBatch.length === 0;\n\t}\n\n\t/**\n\t * If we detect that the reference sequence number of the incoming message does not match\n\t * what was already in the batch managers, this means that batching has been interrupted so\n\t * we will flush the accumulated messages to account for that and create a new batch with the new\n\t * message as the first message.\n\t */\n\tprivate maybeFlushPartialBatch() {\n\t\tconst mainBatchSeqNums = this.mainBatch.sequenceNumbers;\n\t\tconst attachFlowBatchSeqNums = this.attachFlowBatch.sequenceNumbers;\n\t\tassert(\n\t\t\tthis.params.config.disablePartialFlush ||\n\t\t\t\tsequenceNumbersMatch(mainBatchSeqNums, attachFlowBatchSeqNums),\n\t\t\t0x58d /* Reference sequence numbers from both batches must be in sync */,\n\t\t);\n\n\t\tconst currentSequenceNumbers = this.params.getCurrentSequenceNumbers();\n\n\t\tif (\n\t\t\tsequenceNumbersMatch(mainBatchSeqNums, currentSequenceNumbers) &&\n\t\t\tsequenceNumbersMatch(attachFlowBatchSeqNums, currentSequenceNumbers)\n\t\t) {\n\t\t\t// The reference sequence numbers are stable, there is nothing to do\n\t\t\treturn;\n\t\t}\n\n\t\tif (++this.mismatchedOpsReported <= this.maxMismatchedOpsToReport) {\n\t\t\tthis.mc.logger.sendTelemetryEvent(\n\t\t\t\t{\n\t\t\t\t\tcategory: this.params.config.disablePartialFlush ? \"error\" : \"generic\",\n\t\t\t\t\teventName: \"ReferenceSequenceNumberMismatch\",\n\t\t\t\t\tmainReferenceSequenceNumber: mainBatchSeqNums.referenceSequenceNumber,\n\t\t\t\t\tmainClientSequenceNumber: mainBatchSeqNums.clientSequenceNumber,\n\t\t\t\t\tattachReferenceSequenceNumber: attachFlowBatchSeqNums.referenceSequenceNumber,\n\t\t\t\t\tattachClientSequenceNumber: attachFlowBatchSeqNums.clientSequenceNumber,\n\t\t\t\t\tcurrentReferenceSequenceNumber: currentSequenceNumbers.referenceSequenceNumber,\n\t\t\t\t\tcurrentClientSequenceNumber: currentSequenceNumbers.clientSequenceNumber,\n\t\t\t\t},\n\t\t\t\tgetLongStack(() => new UsageError(\"Submission of an out of order message\")),\n\t\t\t);\n\t\t}\n\n\t\tif (!this.params.config.disablePartialFlush) {\n\t\t\tthis.flush();\n\t\t}\n\t}\n\n\tpublic submit(message: BatchMessage) {\n\t\tthis.maybeFlushPartialBatch();\n\n\t\tif (\n\t\t\t!this.mainBatch.push(\n\t\t\t\tmessage,\n\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t)\n\t\t) {\n\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\topSize: message.contents?.length ?? 0,\n\t\t\t\tbatchSize: this.mainBatch.contentSizeInBytes,\n\t\t\t\tcount: this.mainBatch.length,\n\t\t\t\tlimit: this.mainBatch.options.hardLimit,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic submitAttach(message: BatchMessage) {\n\t\tthis.maybeFlushPartialBatch();\n\n\t\tif (\n\t\t\t!this.attachFlowBatch.push(\n\t\t\t\tmessage,\n\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t)\n\t\t) {\n\t\t\t// BatchManager has two limits - soft limit & hard limit. Soft limit is only engaged\n\t\t\t// when queue is not empty.\n\t\t\t// Flush queue & retry. Failure on retry would mean - single message is bigger than hard limit\n\t\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\t\tif (\n\t\t\t\t!this.attachFlowBatch.push(\n\t\t\t\t\tmessage,\n\t\t\t\t\tthis.params.getCurrentSequenceNumbers().clientSequenceNumber,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\t\topSize: message.contents?.length ?? 0,\n\t\t\t\t\tbatchSize: this.attachFlowBatch.contentSizeInBytes,\n\t\t\t\t\tcount: this.attachFlowBatch.length,\n\t\t\t\t\tlimit: this.attachFlowBatch.options.hardLimit,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// If compression is enabled, we will always successfully receive\n\t\t// attach ops and compress then send them at the next JS turn, regardless\n\t\t// of the overall size of the accumulated ops in the batch.\n\t\t// However, it is more efficient to flush these ops faster, preferably\n\t\t// after they reach a size which would benefit from compression.\n\t\tif (\n\t\t\tthis.attachFlowBatch.contentSizeInBytes >=\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes\n\t\t) {\n\t\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\t}\n\t}\n\n\tpublic flush() {\n\t\tthis.flushInternal(this.attachFlowBatch.popBatch());\n\t\tthis.flushInternal(this.mainBatch.popBatch());\n\t}\n\n\tprivate flushInternal(rawBatch: IBatch) {\n\t\tconst processedBatch = this.compressBatch(rawBatch);\n\t\tthis.sendBatch(processedBatch);\n\n\t\tthis.persistBatch(rawBatch.content);\n\t}\n\n\tprivate compressBatch(batch: IBatch): IBatch {\n\t\tif (\n\t\t\tbatch.content.length === 0 ||\n\t\t\tthis.params.config.compressionOptions === undefined ||\n\t\t\tthis.params.config.compressionOptions.minimumBatchSizeInBytes >\n\t\t\t\tbatch.contentSizeInBytes ||\n\t\t\tthis.params.containerContext.submitBatchFn === undefined\n\t\t) {\n\t\t\t// Nothing to do if the batch is empty or if compression is disabled or not supported, or if we don't need to compress\n\t\t\treturn this.params.groupingManager.groupBatch(batch);\n\t\t}\n\n\t\tconst compressedBatch = this.params.compressor.compressBatch(\n\t\t\tthis.params.groupingManager.groupBatch(batch),\n\t\t);\n\n\t\tif (this.params.splitter.isBatchChunkingEnabled) {\n\t\t\treturn compressedBatch.contentSizeInBytes <= this.params.splitter.chunkSizeInBytes\n\t\t\t\t? compressedBatch\n\t\t\t\t: this.params.splitter.splitFirstBatchMessage(compressedBatch);\n\t\t}\n\n\t\tif (compressedBatch.contentSizeInBytes >= this.params.config.maxBatchSizeInBytes) {\n\t\t\tthrow new GenericError(\"BatchTooLarge\", /* error */ undefined, {\n\t\t\t\tbatchSize: batch.contentSizeInBytes,\n\t\t\t\tcompressedBatchSize: compressedBatch.contentSizeInBytes,\n\t\t\t\tcount: compressedBatch.content.length,\n\t\t\t\tlimit: this.params.config.maxBatchSizeInBytes,\n\t\t\t\tchunkingEnabled: this.params.splitter.isBatchChunkingEnabled,\n\t\t\t\tcompressionOptions: JSON.stringify(this.params.config.compressionOptions),\n\t\t\t\tsocketSize: estimateSocketSize(batch),\n\t\t\t});\n\t\t}\n\n\t\treturn compressedBatch;\n\t}\n\n\t/**\n\t * Sends the batch object to the container context to be sent over the wire.\n\t *\n\t * @param batch - batch to be sent\n\t */\n\tprivate sendBatch(batch: IBatch) {\n\t\tconst length = batch.content.length;\n\n\t\t// Did we disconnect in the middle of turn-based batch?\n\t\t// If so, do nothing, as pending state manager will resubmit it correctly on reconnect.\n\t\tif (length === 0 || !this.params.shouldSend()) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst socketSize = estimateSocketSize(batch);\n\t\tif (socketSize >= this.params.config.maxBatchSizeInBytes) {\n\t\t\tthis.mc.logger.sendPerformanceEvent({\n\t\t\t\teventName: \"LargeBatch\",\n\t\t\t\tlength: batch.content.length,\n\t\t\t\tsizeInBytes: batch.contentSizeInBytes,\n\t\t\t\tsocketSize,\n\t\t\t});\n\t\t}\n\n\t\tif (this.params.containerContext.submitBatchFn === undefined) {\n\t\t\t// Legacy path - supporting old loader versions. Can be removed only when LTS moves above\n\t\t\t// version that has support for batches (submitBatchFn)\n\t\t\tassert(\n\t\t\t\tbatch.content[0].compression === undefined,\n\t\t\t\t0x5a6 /* Compression should not have happened if the loader does not support it */,\n\t\t\t);\n\n\t\t\tfor (const message of batch.content) {\n\t\t\t\tthis.params.containerContext.submitFn(\n\t\t\t\t\tMessageType.Operation,\n\t\t\t\t\tmessage.deserializedContent,\n\t\t\t\t\ttrue, // batch\n\t\t\t\t\tmessage.metadata,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.params.containerContext.deltaManager.flush();\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tbatch.referenceSequenceNumber !== undefined,\n\t\t\t\t0x58e /* Batch must not be empty */,\n\t\t\t);\n\t\t\tthis.params.containerContext.submitBatchFn(\n\t\t\t\tbatch.content.map((message) => ({\n\t\t\t\t\tcontents: message.contents,\n\t\t\t\t\tmetadata: message.metadata,\n\t\t\t\t\tcompression: message.compression,\n\t\t\t\t\treferenceSequenceNumber: message.referenceSequenceNumber,\n\t\t\t\t})),\n\t\t\t\tbatch.referenceSequenceNumber,\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate persistBatch(batch: BatchMessage[]) {\n\t\t// Let the PendingStateManager know that a message was submitted.\n\t\t// In future, need to shift toward keeping batch as a whole!\n\t\tfor (const message of batch) {\n\t\t\tthis.params.pendingStateManager.onSubmitMessage(\n\t\t\t\tmessage.deserializedContent.type,\n\t\t\t\tmessage.referenceSequenceNumber,\n\t\t\t\tmessage.deserializedContent.contents,\n\t\t\t\tmessage.localOpMetadata,\n\t\t\t\tmessage.metadata,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic checkpoint() {\n\t\treturn {\n\t\t\tmainBatch: this.mainBatch.checkpoint(),\n\t\t\tattachFlowBatch: this.attachFlowBatch.checkpoint(),\n\t\t};\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"remoteMessageProcessor.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,sBAAsB;IAEjC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAFjB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,iBAAiB,EAAE,iBAAiB;IAGtD,IAAW,eAAe,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAE1D;IAEM,uBAAuB,CAAC,QAAQ,EAAE,MAAM;IAIxC,OAAO,CAAC,aAAa,EAAE,yBAAyB,GAAG,yBAAyB,EAAE;CAuCrF;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkBhF"}
1
+ {"version":3,"file":"remoteMessageProcessor.d.ts","sourceRoot":"","sources":["../../src/opLifecycle/remoteMessageProcessor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAE9F,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,sBAAsB;IAEjC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,iBAAiB;gBAFjB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,iBAAiB,EAAE,iBAAiB;IAGtD,IAAW,eAAe,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAE1D;IAEM,uBAAuB,CAAC,QAAQ,EAAE,MAAM;IAIxC,OAAO,CAAC,aAAa,EAAE,yBAAyB,GAAG,yBAAyB,EAAE;CAgDrF;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkBhF"}
@@ -18,31 +18,34 @@ export class RemoteMessageProcessor {
18
18
  }
19
19
  process(remoteMessage) {
20
20
  const result = [];
21
- // Ungroup before processing chunks
22
- for (let ungroupedMessage of this.opGroupingManager.ungroupOp(copy(remoteMessage))) {
23
- ungroupedMessage = this.opDecompressor.processMessage(ungroupedMessage).message;
24
- unpackRuntimeMessage(ungroupedMessage);
25
- const chunkProcessingResult = this.opSplitter.processRemoteMessage(ungroupedMessage);
26
- ungroupedMessage = chunkProcessingResult.message;
27
- if (chunkProcessingResult.state !== "Processed") {
28
- // If the message is not chunked or if the splitter is still rebuilding the original message,
29
- // there is no need to continue processing
30
- result.push(ungroupedMessage);
31
- continue;
32
- }
33
- // Ungroup the chunked message before decompressing
34
- for (let ungroupedMessageAfterChunking of this.opGroupingManager.ungroupOp(ungroupedMessage)) {
35
- const decompressionAfterChunking = this.opDecompressor.processMessage(ungroupedMessageAfterChunking);
36
- ungroupedMessageAfterChunking = decompressionAfterChunking.message;
37
- if (decompressionAfterChunking.state === "Skipped") {
38
- // After chunking, if the original message was not compressed,
21
+ // Ungroup before and after decompression for back-compat (cleanup tracked by AB#4371)
22
+ for (const ungroupedMessage of this.opGroupingManager.ungroupOp(copy(remoteMessage))) {
23
+ const message = this.opDecompressor.processMessage(ungroupedMessage).message;
24
+ for (let ungroupedMessage2 of this.opGroupingManager.ungroupOp(message)) {
25
+ unpackRuntimeMessage(ungroupedMessage2);
26
+ const chunkProcessingResult = this.opSplitter.processRemoteMessage(ungroupedMessage2);
27
+ ungroupedMessage2 = chunkProcessingResult.message;
28
+ if (chunkProcessingResult.state !== "Processed") {
29
+ // If the message is not chunked or if the splitter is still rebuilding the original message,
39
30
  // there is no need to continue processing
40
- result.push(ungroupedMessageAfterChunking);
31
+ result.push(ungroupedMessage2);
41
32
  continue;
42
33
  }
43
- // The message needs to be unpacked after chunking + decompression
44
- unpack(ungroupedMessageAfterChunking);
45
- result.push(ungroupedMessageAfterChunking);
34
+ // Ungroup before and after decompression for back-compat (cleanup tracked by AB#4371)
35
+ for (const ungroupedMessageAfterChunking of this.opGroupingManager.ungroupOp(ungroupedMessage2)) {
36
+ const decompressionAfterChunking = this.opDecompressor.processMessage(ungroupedMessageAfterChunking);
37
+ for (const ungroupedMessageAfterChunking2 of this.opGroupingManager.ungroupOp(decompressionAfterChunking.message)) {
38
+ if (decompressionAfterChunking.state === "Skipped") {
39
+ // After chunking, if the original message was not compressed,
40
+ // there is no need to continue processing
41
+ result.push(ungroupedMessageAfterChunking2);
42
+ continue;
43
+ }
44
+ // The message needs to be unpacked after chunking + decompression
45
+ unpack(ungroupedMessageAfterChunking2);
46
+ result.push(ungroupedMessageAfterChunking2);
47
+ }
48
+ }
46
49
  }
47
50
  }
48
51
  return result;