@fluidframework/container-runtime 0.58.1000 → 0.58.2000

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 (94) hide show
  1. package/dist/batchTracker.d.ts +1 -1
  2. package/dist/batchTracker.d.ts.map +1 -1
  3. package/dist/batchTracker.js.map +1 -1
  4. package/dist/containerRuntime.d.ts.map +1 -1
  5. package/dist/containerRuntime.js +9 -4
  6. package/dist/containerRuntime.js.map +1 -1
  7. package/dist/dataStore.js.map +1 -1
  8. package/dist/dataStoreContext.d.ts +17 -14
  9. package/dist/dataStoreContext.d.ts.map +1 -1
  10. package/dist/dataStoreContext.js +41 -31
  11. package/dist/dataStoreContext.js.map +1 -1
  12. package/dist/dataStores.d.ts.map +1 -1
  13. package/dist/dataStores.js +4 -2
  14. package/dist/dataStores.js.map +1 -1
  15. package/dist/garbageCollection.d.ts +1 -1
  16. package/dist/garbageCollection.d.ts.map +1 -1
  17. package/dist/garbageCollection.js +3 -4
  18. package/dist/garbageCollection.js.map +1 -1
  19. package/dist/packageVersion.d.ts +1 -1
  20. package/dist/packageVersion.js +1 -1
  21. package/dist/packageVersion.js.map +1 -1
  22. package/dist/pendingStateManager.d.ts +15 -5
  23. package/dist/pendingStateManager.d.ts.map +1 -1
  24. package/dist/pendingStateManager.js +78 -72
  25. package/dist/pendingStateManager.js.map +1 -1
  26. package/dist/runningSummarizer.d.ts.map +1 -1
  27. package/dist/runningSummarizer.js +1 -1
  28. package/dist/runningSummarizer.js.map +1 -1
  29. package/dist/summarizerClientElection.d.ts.map +1 -1
  30. package/dist/summarizerClientElection.js +1 -0
  31. package/dist/summarizerClientElection.js.map +1 -1
  32. package/dist/summarizerTypes.d.ts +13 -1
  33. package/dist/summarizerTypes.d.ts.map +1 -1
  34. package/dist/summarizerTypes.js.map +1 -1
  35. package/dist/summaryGenerator.d.ts +3 -3
  36. package/dist/summaryGenerator.d.ts.map +1 -1
  37. package/dist/summaryGenerator.js +1 -0
  38. package/dist/summaryGenerator.js.map +1 -1
  39. package/dist/summaryManager.d.ts.map +1 -1
  40. package/dist/summaryManager.js.map +1 -1
  41. package/lib/batchTracker.d.ts +1 -1
  42. package/lib/batchTracker.d.ts.map +1 -1
  43. package/lib/batchTracker.js.map +1 -1
  44. package/lib/containerRuntime.d.ts.map +1 -1
  45. package/lib/containerRuntime.js +9 -4
  46. package/lib/containerRuntime.js.map +1 -1
  47. package/lib/dataStore.js.map +1 -1
  48. package/lib/dataStoreContext.d.ts +17 -14
  49. package/lib/dataStoreContext.d.ts.map +1 -1
  50. package/lib/dataStoreContext.js +41 -31
  51. package/lib/dataStoreContext.js.map +1 -1
  52. package/lib/dataStores.d.ts.map +1 -1
  53. package/lib/dataStores.js +4 -2
  54. package/lib/dataStores.js.map +1 -1
  55. package/lib/garbageCollection.d.ts +1 -1
  56. package/lib/garbageCollection.d.ts.map +1 -1
  57. package/lib/garbageCollection.js +1 -2
  58. package/lib/garbageCollection.js.map +1 -1
  59. package/lib/packageVersion.d.ts +1 -1
  60. package/lib/packageVersion.js +1 -1
  61. package/lib/packageVersion.js.map +1 -1
  62. package/lib/pendingStateManager.d.ts +15 -5
  63. package/lib/pendingStateManager.d.ts.map +1 -1
  64. package/lib/pendingStateManager.js +78 -72
  65. package/lib/pendingStateManager.js.map +1 -1
  66. package/lib/runningSummarizer.d.ts.map +1 -1
  67. package/lib/runningSummarizer.js +1 -1
  68. package/lib/runningSummarizer.js.map +1 -1
  69. package/lib/summarizerClientElection.d.ts.map +1 -1
  70. package/lib/summarizerClientElection.js +1 -0
  71. package/lib/summarizerClientElection.js.map +1 -1
  72. package/lib/summarizerTypes.d.ts +13 -1
  73. package/lib/summarizerTypes.d.ts.map +1 -1
  74. package/lib/summarizerTypes.js.map +1 -1
  75. package/lib/summaryGenerator.d.ts +3 -3
  76. package/lib/summaryGenerator.d.ts.map +1 -1
  77. package/lib/summaryGenerator.js +1 -0
  78. package/lib/summaryGenerator.js.map +1 -1
  79. package/lib/summaryManager.d.ts.map +1 -1
  80. package/lib/summaryManager.js.map +1 -1
  81. package/package.json +17 -13
  82. package/src/batchTracker.ts +2 -2
  83. package/src/containerRuntime.ts +5 -1
  84. package/src/dataStore.ts +1 -1
  85. package/src/dataStoreContext.ts +38 -36
  86. package/src/dataStores.ts +2 -1
  87. package/src/garbageCollection.ts +5 -6
  88. package/src/packageVersion.ts +1 -1
  89. package/src/pendingStateManager.ts +102 -86
  90. package/src/runningSummarizer.ts +5 -4
  91. package/src/summarizerClientElection.ts +1 -0
  92. package/src/summarizerTypes.ts +18 -0
  93. package/src/summaryGenerator.ts +41 -5
  94. package/src/summaryManager.ts +0 -1
@@ -23,7 +23,7 @@ const containerRuntime_1 = require("./containerRuntime");
23
23
  * It verifies that all the ops are acked, are received in the right order and batch information is correct.
24
24
  */
25
25
  class PendingStateManager {
26
- constructor(containerRuntime, applyStashedOp, initialState) {
26
+ constructor(containerRuntime, applyStashedOp, initialFlushMode, initialLocalState) {
27
27
  var _a;
28
28
  this.containerRuntime = containerRuntime;
29
29
  this.applyStashedOp = applyStashedOp;
@@ -39,16 +39,18 @@ class PendingStateManager {
39
39
  // Indicates whether we are processing a batch.
40
40
  this.isProcessingBatch = false;
41
41
  this.dispose = () => this.disposeOnce.value;
42
- this.initialStates = new double_ended_queue_1.default((_a = initialState === null || initialState === void 0 ? void 0 : initialState.pendingStates) !== null && _a !== void 0 ? _a : []);
43
- if (initialState) {
44
- if (initialState === null || initialState === void 0 ? void 0 : initialState.clientId) {
45
- this.previousClientIds.add(initialState.clientId);
42
+ this.initialStates = new double_ended_queue_1.default((_a = initialLocalState === null || initialLocalState === void 0 ? void 0 : initialLocalState.pendingStates) !== null && _a !== void 0 ? _a : []);
43
+ if (initialLocalState) {
44
+ if (initialLocalState === null || initialLocalState === void 0 ? void 0 : initialLocalState.clientId) {
45
+ this.previousClientIds.add(initialLocalState.clientId);
46
46
  }
47
47
  // get stashed op count and client sequence number of first op
48
- const messages = initialState.pendingStates
48
+ const messages = initialLocalState.pendingStates
49
49
  .filter((state) => state.type === "message");
50
50
  this.firstStashedCSN = messages[0].clientSequenceNumber;
51
51
  }
52
+ this.flushModeForNextMessage = initialFlushMode;
53
+ this.onFlushModeUpdated(initialFlushMode);
52
54
  }
53
55
  get connected() {
54
56
  return this.containerRuntime.connected;
@@ -98,48 +100,24 @@ class PendingStateManager {
98
100
  * @param flushMode - The flushMode that was updated.
99
101
  */
100
102
  onFlushModeUpdated(flushMode) {
101
- if (flushMode === runtime_definitions_1.FlushMode.Immediate) {
102
- const previousState = this.pendingStates.peekBack();
103
- // We don't have to track a previous "flush" state because FlushMode.Immediate flushes the messages. So,
104
- // just tracking this FlushMode.Immediate is enough.
105
- if ((previousState === null || previousState === void 0 ? void 0 : previousState.type) === "flush") {
106
- this.pendingStates.removeBack();
107
- }
108
- // If no messages were sent between FlushMode.TurnBased and FlushMode.Immediate,
109
- // then we do not have to track both these states.
110
- // Remove FlushMode.TurnBased from the pending queue and return.
111
- if ((previousState === null || previousState === void 0 ? void 0 : previousState.type) === "flushMode" && previousState.flushMode === runtime_definitions_1.FlushMode.TurnBased) {
112
- this.pendingStates.removeBack();
113
- return;
114
- }
115
- }
116
- const pendingFlushMode = {
117
- type: "flushMode",
118
- flushMode,
119
- };
120
- this.pendingStates.push(pendingFlushMode);
103
+ this.pendingStates.push({ type: "flushMode", flushMode });
121
104
  }
122
105
  /**
123
106
  * Called when flush() is called on the ContainerRuntime to manually flush messages.
124
107
  */
125
108
  onFlush() {
126
- // If the FlushMode is Immediate, we should not track this flush call as it is only applicable when FlushMode
127
- // is TurnBased.
109
+ // If the FlushMode is Immediate, we don't need to track an explicit flush call because every message is
110
+ // automatically flushed. So, flush is a no-op.
128
111
  if (this.containerRuntime.flushMode === runtime_definitions_1.FlushMode.Immediate) {
129
112
  return;
130
113
  }
131
- // If the previous state is not a message, we don't have to track this flush call as there is nothing to flush.
114
+ // If the previous state is not a message, flush is a no-op.
132
115
  const previousState = this.pendingStates.peekBack();
133
116
  if ((previousState === null || previousState === void 0 ? void 0 : previousState.type) !== "message") {
134
117
  return;
135
118
  }
136
- // Note that because of the checks above and the checks in onFlushModeUpdated(), we can be sure that a "flush"
137
- // state always has a "message" before and after it. So, it marks the end of a batch and the beginning of a
138
- // new one.
139
- const pendingFlush = {
140
- type: "flush",
141
- };
142
- this.pendingStates.push(pendingFlush);
119
+ // An explicit flush is interesting and is tracked only if there are messages sent in TurnBased mode.
120
+ this.pendingStates.push({ type: "flush" });
143
121
  }
144
122
  /**
145
123
  * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted
@@ -169,7 +147,7 @@ class PendingStateManager {
169
147
  * Processes a local message once it's ack'd by the server to verify that there was no data corruption and that
170
148
  * the batch information was preserved for batch messages. Also process remote messages that might have been
171
149
  * sent from a previous container.
172
- * @param message - The messsage that got ack'd and needs to be processed.
150
+ * @param message - The message that got ack'd and needs to be processed.
173
151
  */
174
152
  processMessage(message, local) {
175
153
  // Do not process chunked ops until all pieces are available.
@@ -237,7 +215,7 @@ class PendingStateManager {
237
215
  /**
238
216
  * Processes a local message once its ack'd by the server. It verifies that there was no data corruption and that
239
217
  * the batch information was preserved for batch messages.
240
- * @param message - The messsage that got ack'd and needs to be processed.
218
+ * @param message - The message that got ack'd and needs to be processed.
241
219
  */
242
220
  processPendingLocalMessage(message) {
243
221
  // Pre-processing part - This may be the start of a batch.
@@ -256,9 +234,7 @@ class PendingStateManager {
256
234
  }
257
235
  this.pendingMessagesCount--;
258
236
  // Post-processing part - If we are processing a batch then this could be the last message in the batch.
259
- if (this.isProcessingBatch) {
260
- this.maybeProcessBatchEnd(message);
261
- }
237
+ this.maybeProcessBatchEnd(message);
262
238
  return pendingState.localOpMetadata;
263
239
  }
264
240
  /**
@@ -266,37 +242,70 @@ class PendingStateManager {
266
242
  * @param message - The message that is being processed.
267
243
  */
268
244
  maybeProcessBatchBegin(message) {
269
- const pendingState = this.peekNextPendingState();
270
- if (pendingState.type !== "flush" && pendingState.type !== "flushMode") {
245
+ // Tracks the last FlushMode that was set before this message was sent.
246
+ let pendingFlushMode;
247
+ // Tracks whether a flush was called before this message was sent.
248
+ let pendingFlush = false;
249
+ /**
250
+ * We are checking if the next message is the start of a batch. It can happen in the following scenarios:
251
+ * 1. The FlushMode was set to TurnBased before this message was sent.
252
+ * 2. The FlushMode was already TurnBased and a flush was called before this message was sent. This essentially
253
+ * means that the flush marked the end of a previous batch and beginning of a new batch.
254
+ *
255
+ * Keep reading pending states from the queue until we encounter a message. It's possible that the FlushMode was
256
+ * updated a bunch of times without sending any messages.
257
+ */
258
+ let nextPendingState = this.peekNextPendingState();
259
+ while (nextPendingState.type !== "message") {
260
+ if (nextPendingState.type === "flushMode") {
261
+ pendingFlushMode = nextPendingState.flushMode;
262
+ }
263
+ if (nextPendingState.type === "flush") {
264
+ pendingFlush = true;
265
+ }
266
+ this.pendingStates.shift();
267
+ nextPendingState = this.peekNextPendingState();
268
+ }
269
+ if (pendingFlushMode !== undefined) {
270
+ this.flushModeForNextMessage = pendingFlushMode;
271
+ }
272
+ // If the FlushMode was set to Immediate before this message was sent, this message won't be a batch message
273
+ // because in Immediate mode, every message is flushed individually.
274
+ if (pendingFlushMode === runtime_definitions_1.FlushMode.Immediate) {
271
275
  return;
272
276
  }
273
- // If the pending state is of type "flushMode", it must be Manual since Automatic flush mode is processed
274
- // after a message is processed and not before.
275
- if (pendingState.type === "flushMode") {
276
- common_utils_1.assert(pendingState.flushMode === runtime_definitions_1.FlushMode.TurnBased, 0x16a /* "Flush mode should be manual when processing batch begin" */);
277
+ /**
278
+ * This message is the first in a batch if before it was sent either the FlushMode was set to TurnBased or there
279
+ * was an explicit flush call. Note that a flush call is tracked only in TurnBased mode and it indicates the end
280
+ * of one batch and beginning of another.
281
+ */
282
+ if (pendingFlushMode === runtime_definitions_1.FlushMode.TurnBased || pendingFlush) {
283
+ // We should not already be processing a batch and there should be no pending batch begin message.
284
+ common_utils_1.assert(!this.isProcessingBatch && this.pendingBatchBeginMessage === undefined, 0x16b /* "The pending batch state indicates we are already processing a batch" */);
285
+ // Set the pending batch state indicating we have started processing a batch.
286
+ this.pendingBatchBeginMessage = message;
287
+ this.isProcessingBatch = true;
277
288
  }
278
- // We should not already be processing a batch and there should be no pending batch begin message.
279
- common_utils_1.assert(!this.isProcessingBatch && this.pendingBatchBeginMessage === undefined, 0x16b /* "The pending batch state indicates we are already processing a batch" */);
280
- // Set the pending batch state indicating we have started processing a batch.
281
- this.pendingBatchBeginMessage = message;
282
- this.isProcessingBatch = true;
283
- // Remove this pending state from the queue as we have processed it.
284
- this.pendingStates.shift();
285
289
  }
290
+ /**
291
+ * This message could be the last message in batch. If so, clear batch state since the batch is complete.
292
+ * @param message - The message that is being processed.
293
+ */
286
294
  maybeProcessBatchEnd(message) {
287
295
  var _a, _b;
288
- const nextPendingState = this.peekNextPendingState();
289
- if (nextPendingState.type !== "flush" && nextPendingState.type !== "flushMode") {
296
+ if (!this.isProcessingBatch) {
290
297
  return;
291
298
  }
292
- // If the next pending state is of type "flushMode", it must be Immediate and if so, we need to remove it from
293
- // the queue.
294
- // Note that we do not remove the type "flush" from the queue because it indicates the end of one batch and the
295
- // beginning of a new one. So, it will removed when the next batch begin is processed.
296
- if (nextPendingState.type === "flushMode") {
297
- common_utils_1.assert(nextPendingState.flushMode === runtime_definitions_1.FlushMode.Immediate, 0x16c /* "Flush mode is set to TurnBased in the middle of processing a batch" */);
298
- this.pendingStates.shift();
299
+ const nextPendingState = this.peekNextPendingState();
300
+ if (nextPendingState.type === "message") {
301
+ return;
299
302
  }
303
+ /**
304
+ * We are in the middle of processing a batch. The batch ends when we see an explicit flush. We should never see
305
+ * a FlushMode before flush. This is true because we track batches only when FlushMode is TurnBased and in this
306
+ * mode, a batch ends either by calling flush or by changing the mode to Immediate which also triggers a flush.
307
+ */
308
+ common_utils_1.assert(nextPendingState.type !== "flushMode", 0x2bd /* "We should not see a pending FlushMode until we see a flush when processing a batch" */);
300
309
  // There should be a pending batch begin message.
301
310
  common_utils_1.assert(this.pendingBatchBeginMessage !== undefined, 0x16d /* "There is no pending batch begin message" */);
302
311
  // Get the batch begin metadata from the first message in the batch.
@@ -342,6 +351,9 @@ class PendingStateManager {
342
351
  this.pendingMessagesCount = 0;
343
352
  // Save the current FlushMode so that we can revert it back after replaying the states.
344
353
  const savedFlushMode = this.containerRuntime.flushMode;
354
+ // Set the flush mode for the next message. This step is important because the flush mode may have been changed
355
+ // after the next pending message was sent.
356
+ this.containerRuntime.setFlushMode(this.flushModeForNextMessage);
345
357
  // Process exactly `pendingStatesCount` items in the queue as it represents the number of states that were
346
358
  // pending when we connected. This is important because the `reSubmitFn` might add more items in the queue
347
359
  // which must not be replayed.
@@ -350,19 +362,13 @@ class PendingStateManager {
350
362
  const pendingState = this.pendingStates.shift();
351
363
  switch (pendingState.type) {
352
364
  case "message":
353
- {
354
- this.containerRuntime.reSubmitFn(pendingState.messageType, pendingState.content, pendingState.localOpMetadata, pendingState.opMetadata);
355
- }
365
+ this.containerRuntime.reSubmitFn(pendingState.messageType, pendingState.content, pendingState.localOpMetadata, pendingState.opMetadata);
356
366
  break;
357
367
  case "flushMode":
358
- {
359
- this.containerRuntime.setFlushMode(pendingState.flushMode);
360
- }
368
+ this.containerRuntime.setFlushMode(pendingState.flushMode);
361
369
  break;
362
370
  case "flush":
363
- {
364
- this.containerRuntime.flush();
365
- }
371
+ this.containerRuntime.flush();
366
372
  break;
367
373
  default:
368
374
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,+DAA4D;AAC5D,qEAAsE;AAItE,6EAAgE;AAChE,4EAAuC;AACvC,yDAA8F;AA8C9F;;;;;;;;GAQG;AACH,MAAa,mBAAmB;IA8C5B,YACqB,gBAAkC,EAClC,cAAmD,EACpE,YAA4C;;QAF3B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,mBAAc,GAAd,cAAc,CAAq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CAAC;CACJ;AA/aD,kDA+aC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable } from \"@fluidframework/common-definitions\";\nimport { assert, Lazy } from \"@fluidframework/common-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport {\n ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport { FlushMode } from \"@fluidframework/runtime-definitions\";\nimport Deque from \"double-ended-queue\";\nimport { ContainerRuntime, ContainerMessageType, isRuntimeMessage } from \"./containerRuntime\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n */\nexport interface IPendingMessage {\n type: \"message\";\n messageType: ContainerMessageType;\n clientSequenceNumber: number;\n referenceSequenceNumber: number;\n content: any;\n localOpMetadata: unknown;\n opMetadata: Record<string, unknown> | undefined;\n}\n\n/**\n * This represents a FlushMode update and is added to the pending queue when `setFlushMode` is called on the\n * ContainerRuntime and the FlushMode changes.\n */\nexport interface IPendingFlushMode {\n type: \"flushMode\";\n flushMode: FlushMode;\n}\n\n/**\n * This represents a manual flush and is added to the pending queue when `flush` is called on the ContainerRuntime to\n * flush any pending messages. This is applicable only when the FlushMode is Manual.\n */\nexport interface IPendingFlush {\n type: \"flush\";\n}\n\nexport type IPendingState = IPendingMessage | IPendingFlushMode | IPendingFlush;\n\nexport interface IPendingLocalState {\n /**\n * client ID we most recently connected with, or undefined if we never connected\n */\n clientId?: string;\n /**\n * list of pending states, including ops and batch information\n */\n pendingStates: IPendingState[];\n}\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes setting the FlushMode, manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n private readonly pendingStates = new Deque<IPendingState>();\n private readonly initialStates: Deque<IPendingState>;\n private readonly previousClientIds = new Set<string>();\n private readonly firstStashedCSN: number = -1;\n private readonly disposeOnce = new Lazy<void>(() => {\n this.initialStates.clear();\n this.pendingStates.clear();\n });\n\n // Maintains the count of messages that are currently unacked.\n private pendingMessagesCount: number = 0;\n\n // Indicates whether we are processing a batch.\n private isProcessingBatch: boolean = false;\n\n // This stores the first message in the batch that we are processing. This is used to verify that we get\n // the correct batch metadata.\n private pendingBatchBeginMessage: ISequencedDocumentMessage | undefined;\n\n private clientId: string | undefined;\n\n private get connected(): boolean {\n return this.containerRuntime.connected;\n }\n\n /**\n * Called to check if there are any pending messages in the pending state queue.\n * @returns A boolean indicating whether there are messages or not.\n */\n public hasPendingMessages(): boolean {\n return this.pendingMessagesCount !== 0;\n }\n\n public getLocalState(): IPendingLocalState | undefined {\n if (this.hasPendingMessages()) {\n return {\n clientId: this.clientId,\n pendingStates: this.pendingStates.toArray().map(\n // delete localOpMetadata since it may not be serializable\n // and will be regenerated by applyStashedOp()\n (state) => state.type === \"message\" ? {...state, localOpMetadata: undefined } : state),\n };\n }\n }\n\n constructor(\n private readonly containerRuntime: ContainerRuntime,\n private readonly applyStashedOp: (type, content) => Promise<unknown>,\n initialState: IPendingLocalState | undefined,\n ) {\n this.initialStates = new Deque<IPendingState>(initialState?.pendingStates ?? []);\n\n if (initialState) {\n if (initialState?.clientId) {\n this.previousClientIds.add(initialState.clientId);\n }\n // get stashed op count and client sequence number of first op\n const messages = initialState.pendingStates\n .filter((state) => state.type === \"message\") as IPendingMessage[];\n this.firstStashedCSN = messages[0].clientSequenceNumber;\n }\n }\n\n public get disposed() { return this.disposeOnce.evaluated; }\n public readonly dispose = () => this.disposeOnce.value;\n\n /**\n * Called when a message is submitted locally. Adds the message and the associated details to the pending state\n * queue.\n * @param type - The container message type.\n * @param clientSequenceNumber - The clientSequenceNumber associated with the message.\n * @param content - The message content.\n * @param localOpMetadata - The local metadata associated with the message.\n */\n public onSubmitMessage(\n type: ContainerMessageType,\n clientSequenceNumber: number,\n referenceSequenceNumber: number,\n content: any,\n localOpMetadata: unknown,\n opMetadata: Record<string, unknown> | undefined,\n ) {\n const pendingMessage: IPendingMessage = {\n type: \"message\",\n messageType: type,\n clientSequenceNumber,\n referenceSequenceNumber,\n content,\n localOpMetadata,\n opMetadata,\n };\n\n this.pendingStates.push(pendingMessage);\n\n this.pendingMessagesCount++;\n }\n\n /**\n * Called when the FlushMode is updated. Adds the FlushMode to the pending state queue.\n * @param flushMode - The flushMode that was updated.\n */\n public onFlushModeUpdated(flushMode: FlushMode) {\n if (flushMode === FlushMode.Immediate) {\n const previousState = this.pendingStates.peekBack();\n\n // We don't have to track a previous \"flush\" state because FlushMode.Immediate flushes the messages. So,\n // just tracking this FlushMode.Immediate is enough.\n if (previousState?.type === \"flush\") {\n this.pendingStates.removeBack();\n }\n\n // If no messages were sent between FlushMode.TurnBased and FlushMode.Immediate,\n // then we do not have to track both these states.\n // Remove FlushMode.TurnBased from the pending queue and return.\n if (previousState?.type === \"flushMode\" && previousState.flushMode === FlushMode.TurnBased) {\n this.pendingStates.removeBack();\n return;\n }\n }\n\n const pendingFlushMode: IPendingFlushMode = {\n type: \"flushMode\",\n flushMode,\n };\n this.pendingStates.push(pendingFlushMode);\n }\n\n /**\n * Called when flush() is called on the ContainerRuntime to manually flush messages.\n */\n public onFlush() {\n // If the FlushMode is Immediate, we should not track this flush call as it is only applicable when FlushMode\n // is TurnBased.\n if (this.containerRuntime.flushMode === FlushMode.Immediate) {\n return;\n }\n\n // If the previous state is not a message, we don't have to track this flush call as there is nothing to flush.\n const previousState = this.pendingStates.peekBack();\n if (previousState?.type !== \"message\") {\n return;\n }\n\n // Note that because of the checks above and the checks in onFlushModeUpdated(), we can be sure that a \"flush\"\n // state always has a \"message\" before and after it. So, it marks the end of a batch and the beginning of a\n // new one.\n const pendingFlush: IPendingFlush = {\n type: \"flush\",\n };\n this.pendingStates.push(pendingFlush);\n }\n\n /**\n * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n */\n public async applyStashedOpsAt(seqNum: number) {\n // apply stashed ops at sequence number\n while (!this.initialStates.isEmpty()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nextState = this.initialStates.peekFront()!;\n if (nextState.type === \"message\") {\n if (nextState.referenceSequenceNumber > seqNum) {\n break; // nothing left to do at this sequence number\n } else if (nextState.referenceSequenceNumber > 0 && nextState.referenceSequenceNumber < seqNum) {\n throw new Error(\"loaded from snapshot too recent to apply stashed ops\");\n }\n\n // applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n const localOpMetadata = await this.applyStashedOp(nextState.messageType, nextState.content);\n nextState.localOpMetadata = localOpMetadata;\n }\n\n // then we push onto pendingStates which will cause PendingStateManager to resubmit when we connect\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.pendingStates.push(this.initialStates.shift()!);\n }\n }\n\n /**\n * Processes a local message once it's ack'd by the server to verify that there was no data corruption and that\n * the batch information was preserved for batch messages. Also process remote messages that might have been\n * sent from a previous container.\n * @param message - The messsage that got ack'd and needs to be processed.\n */\n public processMessage(message: ISequencedDocumentMessage, local: boolean) {\n // Do not process chunked ops until all pieces are available.\n if (message.type === ContainerMessageType.ChunkedOp) {\n return { localAck: false, localOpMetadata: undefined };\n }\n\n if (local) {\n return { localAck: false, localOpMetadata: this.processPendingLocalMessage(message) };\n } else {\n return this.processRemoteMessage(message);\n }\n }\n\n /**\n * Listens for ACKs of stashed ops\n */\n private processRemoteMessage(message: ISequencedDocumentMessage) {\n if (!isRuntimeMessage(message)) {\n return { localAck: false, localOpMetadata: undefined };\n }\n\n // this message was a pending op that was actually sent successfully\n const isOriginalClientId = message.clientId === Array.from(this.previousClientIds)[0] &&\n message.clientSequenceNumber >= this.firstStashedCSN;\n // this message is a pending or stashed op that was resubmitted\n const isNewClientId = Array.from(this.previousClientIds).indexOf(message.clientId) > 0;\n\n // if this is an ack for a stashed op, dequeue one message.\n // we should have seen its ref seq num by now and the DDS should be ready for it to be ACKed\n if (isOriginalClientId || isNewClientId) {\n assert(this.clientId === undefined, 0x28b /* \"multiple clients connected with stashed ops\" */);\n while (!this.pendingStates.isEmpty()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nextState = this.pendingStates.shift()!;\n // if it's not a message just drop it and keep looking\n if (nextState.type === \"message\") {\n this.assertOpMatch(nextState, message, isOriginalClientId);\n return { localAck: true, localOpMetadata: nextState.localOpMetadata };\n }\n }\n }\n\n if (message.type === ContainerMessageType.Rejoin && this.previousClientIds.has(message.contents?.clientId)) {\n this.previousClientIds.add(message.clientId);\n }\n\n return { localAck: false, localOpMetadata: undefined };\n }\n\n private assertOpMatch(state: IPendingMessage, message: ISequencedDocumentMessage, isOriginalClientId: boolean) {\n assert(message.type === state.messageType, 0x28c /* \"different message type\" */);\n assert(message.clientSequenceNumber === state.clientSequenceNumber || !isOriginalClientId,\n 0x28d /* \"client sequence number doesn't match\" */);\n switch(message.type) {\n case ContainerMessageType.Attach:\n assert(message.contents.id === state.content.id, 0x28e /* \"datastore ID doesn't match\" */);\n break;\n case ContainerMessageType.FluidDataStoreOp:\n assert(message.contents.address === state.content.address, 0x28f /* \"address doesn't match\" */);\n break;\n case ContainerMessageType.BlobAttach:\n // todo: assert we have blob storage, assert blob IDs match, remove blob from blob storage since it made\n // it through successfully\n break;\n case ContainerMessageType.Rejoin:\n default:\n throw new Error(`${message.type} not expected`);\n }\n }\n\n /**\n * Processes a local message once its ack'd by the server. It verifies that there was no data corruption and that\n * the batch information was preserved for batch messages.\n * @param message - The messsage that got ack'd and needs to be processed.\n */\n private processPendingLocalMessage(message: ISequencedDocumentMessage): unknown {\n // Pre-processing part - This may be the start of a batch.\n this.maybeProcessBatchBegin(message);\n\n // Get the next state from the pending queue and verify that it is of type \"message\".\n const pendingState = this.peekNextPendingState();\n assert(pendingState.type === \"message\", 0x169 /* \"No pending message found for this remote message\" */);\n this.pendingStates.shift();\n\n // Processing part - Verify that there has been no data corruption.\n // The clientSequenceNumber of the incoming message must match that of the pending message.\n if (pendingState.clientSequenceNumber !== message.clientSequenceNumber) {\n // Close the container because this could indicate data corruption.\n const error = DataProcessingError.create(\n \"pending local message clientSequenceNumber mismatch\",\n \"unexpectedAckReceived\",\n message,\n { expectedClientSequenceNumber: pendingState.clientSequenceNumber },\n );\n\n this.containerRuntime.closeFn(error);\n return;\n }\n\n this.pendingMessagesCount--;\n\n // Post-processing part - If we are processing a batch then this could be the last message in the batch.\n if (this.isProcessingBatch) {\n this.maybeProcessBatchEnd(message);\n }\n\n return pendingState.localOpMetadata;\n }\n\n /**\n * This message could be the first message in batch. If so, set batch state marking the beginning of a batch.\n * @param message - The message that is being processed.\n */\n private maybeProcessBatchBegin(message: ISequencedDocumentMessage) {\n const pendingState = this.peekNextPendingState();\n if (pendingState.type !== \"flush\" && pendingState.type !== \"flushMode\") {\n return;\n }\n\n // If the pending state is of type \"flushMode\", it must be Manual since Automatic flush mode is processed\n // after a message is processed and not before.\n if (pendingState.type === \"flushMode\") {\n assert(pendingState.flushMode === FlushMode.TurnBased,\n 0x16a /* \"Flush mode should be manual when processing batch begin\" */);\n }\n\n // We should not already be processing a batch and there should be no pending batch begin message.\n assert(!this.isProcessingBatch && this.pendingBatchBeginMessage === undefined,\n 0x16b /* \"The pending batch state indicates we are already processing a batch\" */);\n\n // Set the pending batch state indicating we have started processing a batch.\n this.pendingBatchBeginMessage = message;\n this.isProcessingBatch = true;\n\n // Remove this pending state from the queue as we have processed it.\n this.pendingStates.shift();\n }\n\n private maybeProcessBatchEnd(message: ISequencedDocumentMessage) {\n const nextPendingState = this.peekNextPendingState();\n if (nextPendingState.type !== \"flush\" && nextPendingState.type !== \"flushMode\") {\n return;\n }\n\n // If the next pending state is of type \"flushMode\", it must be Immediate and if so, we need to remove it from\n // the queue.\n // Note that we do not remove the type \"flush\" from the queue because it indicates the end of one batch and the\n // beginning of a new one. So, it will removed when the next batch begin is processed.\n if (nextPendingState.type === \"flushMode\") {\n assert(nextPendingState.flushMode === FlushMode.Immediate,\n 0x16c /* \"Flush mode is set to TurnBased in the middle of processing a batch\" */);\n this.pendingStates.shift();\n }\n\n // There should be a pending batch begin message.\n assert(this.pendingBatchBeginMessage !== undefined, 0x16d /* \"There is no pending batch begin message\" */);\n\n // Get the batch begin metadata from the first message in the batch.\n const batchBeginMetadata = this.pendingBatchBeginMessage.metadata?.batch;\n\n // There could be just a single message in the batch. If so, it should not have any batch metadata. If there\n // are multiple messages in the batch, verify that we got the correct batch begin and end metadata.\n if (this.pendingBatchBeginMessage === message) {\n assert(batchBeginMetadata === undefined,\n 0x16e /* \"Batch with single message should not have batch metadata\" */);\n } else {\n // Get the batch metadata from the last message in the batch.\n const batchEndMetadata = message.metadata?.batch;\n assert(batchBeginMetadata === true, 0x16f /* \"Did not receive batch begin metadata\" */);\n assert(batchEndMetadata === false, 0x170 /* \"Did not receive batch end metadata\" */);\n }\n\n // Clear the pending batch state now that we have processed the entire batch.\n this.pendingBatchBeginMessage = undefined;\n this.isProcessingBatch = false;\n }\n\n /**\n * Returns the next pending state from the pending state queue.\n */\n private peekNextPendingState(): IPendingState {\n const nextPendingState = this.pendingStates.peekFront();\n assert(!!nextPendingState, 0x171 /* \"No pending state found for the remote message\" */);\n return nextPendingState;\n }\n\n /**\n * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n * states in its queue. This includes setting the FlushMode and triggering resubmission of unacked ops.\n */\n public replayPendingStates() {\n assert(this.connected, 0x172 /* \"The connection state is not consistent with the runtime\" */);\n\n // This assert suggests we are about to send same ops twice, which will result in data loss.\n assert(this.clientId !== this.containerRuntime.clientId,\n 0x173 /* \"replayPendingStates called twice for same clientId!\" */);\n this.clientId = this.containerRuntime.clientId;\n\n assert(this.initialStates.isEmpty(), 0x174 /* \"initial states should be empty before replaying pending\" */);\n\n let pendingStatesCount = this.pendingStates.length;\n if (pendingStatesCount === 0) {\n return;\n }\n\n // Reset the pending message count because all these messages will be removed from the queue.\n this.pendingMessagesCount = 0;\n\n // Save the current FlushMode so that we can revert it back after replaying the states.\n const savedFlushMode = this.containerRuntime.flushMode;\n\n // Process exactly `pendingStatesCount` items in the queue as it represents the number of states that were\n // pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n // which must not be replayed.\n while (pendingStatesCount > 0) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingState = this.pendingStates.shift()!;\n switch (pendingState.type) {\n case \"message\":\n {\n this.containerRuntime.reSubmitFn(\n pendingState.messageType,\n pendingState.content,\n pendingState.localOpMetadata,\n pendingState.opMetadata);\n }\n break;\n case \"flushMode\":\n {\n this.containerRuntime.setFlushMode(pendingState.flushMode);\n }\n break;\n case \"flush\":\n {\n this.containerRuntime.flush();\n }\n break;\n default:\n break;\n }\n pendingStatesCount--;\n }\n\n // Revert the FlushMode.\n this.containerRuntime.setFlushMode(savedFlushMode);\n }\n}\n"]}
1
+ {"version":3,"file":"pendingStateManager.js","sourceRoot":"","sources":["../src/pendingStateManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAGH,+DAA4D;AAC5D,qEAAsE;AAItE,6EAAgE;AAChE,4EAAuC;AACvC,yDAA8F;AA8C9F;;;;;;;;GAQG;AACH,MAAa,mBAAmB;IAqD5B,YACqB,gBAAkC,EAClC,cAAmD,EACpE,gBAA2B,EAC3B,iBAAiD;;QAHhC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,mBAAc,GAAd,cAAc,CAAqC;QAtDvD,kBAAa,GAAG,IAAI,4BAAK,EAAiB,CAAC;QAE3C,sBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;QACtC,oBAAe,GAAW,CAAC,CAAC,CAAC;QAC7B,gBAAW,GAAG,IAAI,mBAAI,CAAO,GAAG,EAAE;YAC/C,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,C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CAAC,uBAAuB,CAAC,CAAC;QAEjE,0GAA0G;QAC1G,0GAA0G;QAC1G,8BAA8B;QAC9B,OAAO,kBAAkB,GAAG,CAAC,EAAE;YAC3B,oEAAoE;YACpE,MAAM,YAAY,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,EAAG,CAAC;YACjD,QAAQ,YAAY,CAAC,IAAI,EAAE;gBACvB,KAAK,SAAS;oBACV,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAC5B,YAAY,CAAC,WAAW,EACxB,YAAY,CAAC,OAAO,EACpB,YAAY,CAAC,eAAe,EAC5B,YAAY,CAAC,UAAU,CAAC,CAAC;oBAC7B,MAAM;gBACV,KAAK,WAAW;oBACZ,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;oBAC3D,MAAM;gBACV,KAAK,OAAO;oBACR,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;oBAC9B,MAAM;gBACV;oBACI,MAAM;aACb;YACD,kBAAkB,EAAE,CAAC;SACxB;QAED,wBAAwB;QACxB,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IACvD,CAAC;CACJ;AA/bD,kDA+bC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable } from \"@fluidframework/common-definitions\";\nimport { assert, Lazy } from \"@fluidframework/common-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport {\n ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport { FlushMode } from \"@fluidframework/runtime-definitions\";\nimport Deque from \"double-ended-queue\";\nimport { ContainerRuntime, ContainerMessageType, isRuntimeMessage } from \"./containerRuntime\";\n\n/**\n * This represents a message that has been submitted and is added to the pending queue when `submit` is called on the\n * ContainerRuntime. This message has either not been ack'd by the server or has not been submitted to the server yet.\n */\nexport interface IPendingMessage {\n type: \"message\";\n messageType: ContainerMessageType;\n clientSequenceNumber: number;\n referenceSequenceNumber: number;\n content: any;\n localOpMetadata: unknown;\n opMetadata: Record<string, unknown> | undefined;\n}\n\n/**\n * This represents a FlushMode update and is added to the pending queue when `setFlushMode` is called on the\n * ContainerRuntime and the FlushMode changes.\n */\nexport interface IPendingFlushMode {\n type: \"flushMode\";\n flushMode: FlushMode;\n}\n\n/**\n * This represents an explicit flush call and is added to the pending queue when flush is called on the ContainerRuntime\n * to flush pending messages.\n */\nexport interface IPendingFlush {\n type: \"flush\";\n}\n\nexport type IPendingState = IPendingMessage | IPendingFlushMode | IPendingFlush;\n\nexport interface IPendingLocalState {\n /**\n * client ID we most recently connected with, or undefined if we never connected\n */\n clientId?: string;\n /**\n * list of pending states, including ops and batch information\n */\n pendingStates: IPendingState[];\n}\n\n/**\n * PendingStateManager is responsible for maintaining the messages that have not been sent or have not yet been\n * acknowledged by the server. It also maintains the batch information for both automatically and manually flushed\n * batches along with the messages.\n * When the Container reconnects, it replays the pending states, which includes setting the FlushMode, manual flushing\n * of messages and triggering resubmission of unacked ops.\n *\n * It verifies that all the ops are acked, are received in the right order and batch information is correct.\n */\nexport class PendingStateManager implements IDisposable {\n private readonly pendingStates = new Deque<IPendingState>();\n private readonly initialStates: Deque<IPendingState>;\n private readonly previousClientIds = new Set<string>();\n private readonly firstStashedCSN: number = -1;\n private readonly disposeOnce = new Lazy<void>(() => {\n this.initialStates.clear();\n this.pendingStates.clear();\n });\n\n // Maintains the count of messages that are currently unacked.\n private pendingMessagesCount: number = 0;\n\n // Indicates whether we are processing a batch.\n private isProcessingBatch: boolean = false;\n\n // This stores the first message in the batch that we are processing. This is used to verify that we get\n // the correct batch metadata.\n private pendingBatchBeginMessage: ISequencedDocumentMessage | undefined;\n\n /**\n * This tracks the flush mode for the next message in the pending state queue. When replaying messages, we need to\n * first set the flush mode to this value and then send ops. It is important to do this info because the flush\n * mode could have been updated.\n */\n private flushModeForNextMessage: FlushMode;\n\n private clientId: string | undefined;\n\n private get connected(): boolean {\n return this.containerRuntime.connected;\n }\n\n /**\n * Called to check if there are any pending messages in the pending state queue.\n * @returns A boolean indicating whether there are messages or not.\n */\n public hasPendingMessages(): boolean {\n return this.pendingMessagesCount !== 0;\n }\n\n public getLocalState(): IPendingLocalState | undefined {\n if (this.hasPendingMessages()) {\n return {\n clientId: this.clientId,\n pendingStates: this.pendingStates.toArray().map(\n // delete localOpMetadata since it may not be serializable\n // and will be regenerated by applyStashedOp()\n (state) => state.type === \"message\" ? {...state, localOpMetadata: undefined } : state),\n };\n }\n }\n\n constructor(\n private readonly containerRuntime: ContainerRuntime,\n private readonly applyStashedOp: (type, content) => Promise<unknown>,\n initialFlushMode: FlushMode,\n initialLocalState: IPendingLocalState | undefined,\n ) {\n this.initialStates = new Deque<IPendingState>(initialLocalState?.pendingStates ?? []);\n\n if (initialLocalState) {\n if (initialLocalState?.clientId) {\n this.previousClientIds.add(initialLocalState.clientId);\n }\n // get stashed op count and client sequence number of first op\n const messages = initialLocalState.pendingStates\n .filter((state) => state.type === \"message\") as IPendingMessage[];\n this.firstStashedCSN = messages[0].clientSequenceNumber;\n }\n\n this.flushModeForNextMessage = initialFlushMode;\n this.onFlushModeUpdated(initialFlushMode);\n }\n\n public get disposed() { return this.disposeOnce.evaluated; }\n public readonly dispose = () => this.disposeOnce.value;\n\n /**\n * Called when a message is submitted locally. Adds the message and the associated details to the pending state\n * queue.\n * @param type - The container message type.\n * @param clientSequenceNumber - The clientSequenceNumber associated with the message.\n * @param content - The message content.\n * @param localOpMetadata - The local metadata associated with the message.\n */\n public onSubmitMessage(\n type: ContainerMessageType,\n clientSequenceNumber: number,\n referenceSequenceNumber: number,\n content: any,\n localOpMetadata: unknown,\n opMetadata: Record<string, unknown> | undefined,\n ) {\n const pendingMessage: IPendingMessage = {\n type: \"message\",\n messageType: type,\n clientSequenceNumber,\n referenceSequenceNumber,\n content,\n localOpMetadata,\n opMetadata,\n };\n\n this.pendingStates.push(pendingMessage);\n\n this.pendingMessagesCount++;\n }\n\n /**\n * Called when the FlushMode is updated. Adds the FlushMode to the pending state queue.\n * @param flushMode - The flushMode that was updated.\n */\n public onFlushModeUpdated(flushMode: FlushMode) {\n this.pendingStates.push({ type: \"flushMode\", flushMode });\n }\n\n /**\n * Called when flush() is called on the ContainerRuntime to manually flush messages.\n */\n public onFlush() {\n // If the FlushMode is Immediate, we don't need to track an explicit flush call because every message is\n // automatically flushed. So, flush is a no-op.\n if (this.containerRuntime.flushMode === FlushMode.Immediate) {\n return;\n }\n\n // If the previous state is not a message, flush is a no-op.\n const previousState = this.pendingStates.peekBack();\n if (previousState?.type !== \"message\") {\n return;\n }\n\n // An explicit flush is interesting and is tracked only if there are messages sent in TurnBased mode.\n this.pendingStates.push({ type: \"flush\" });\n }\n\n /**\n * Applies stashed ops at their reference sequence number so they are ready to be ACKed or resubmitted\n */\n public async applyStashedOpsAt(seqNum: number) {\n // apply stashed ops at sequence number\n while (!this.initialStates.isEmpty()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nextState = this.initialStates.peekFront()!;\n if (nextState.type === \"message\") {\n if (nextState.referenceSequenceNumber > seqNum) {\n break; // nothing left to do at this sequence number\n } else if (nextState.referenceSequenceNumber > 0 && nextState.referenceSequenceNumber < seqNum) {\n throw new Error(\"loaded from snapshot too recent to apply stashed ops\");\n }\n\n // applyStashedOp will cause the DDS to behave as if it has sent the op but not actually send it\n const localOpMetadata = await this.applyStashedOp(nextState.messageType, nextState.content);\n nextState.localOpMetadata = localOpMetadata;\n }\n\n // then we push onto pendingStates which will cause PendingStateManager to resubmit when we connect\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.pendingStates.push(this.initialStates.shift()!);\n }\n }\n\n /**\n * Processes a local message once it's ack'd by the server to verify that there was no data corruption and that\n * the batch information was preserved for batch messages. Also process remote messages that might have been\n * sent from a previous container.\n * @param message - The message that got ack'd and needs to be processed.\n */\n public processMessage(message: ISequencedDocumentMessage, local: boolean) {\n // Do not process chunked ops until all pieces are available.\n if (message.type === ContainerMessageType.ChunkedOp) {\n return { localAck: false, localOpMetadata: undefined };\n }\n\n if (local) {\n return { localAck: false, localOpMetadata: this.processPendingLocalMessage(message) };\n } else {\n return this.processRemoteMessage(message);\n }\n }\n\n /**\n * Listens for ACKs of stashed ops\n */\n private processRemoteMessage(message: ISequencedDocumentMessage) {\n if (!isRuntimeMessage(message)) {\n return { localAck: false, localOpMetadata: undefined };\n }\n\n // this message was a pending op that was actually sent successfully\n const isOriginalClientId = message.clientId === Array.from(this.previousClientIds)[0] &&\n message.clientSequenceNumber >= this.firstStashedCSN;\n // this message is a pending or stashed op that was resubmitted\n const isNewClientId = Array.from(this.previousClientIds).indexOf(message.clientId) > 0;\n\n // if this is an ack for a stashed op, dequeue one message.\n // we should have seen its ref seq num by now and the DDS should be ready for it to be ACKed\n if (isOriginalClientId || isNewClientId) {\n assert(this.clientId === undefined, 0x28b /* \"multiple clients connected with stashed ops\" */);\n while (!this.pendingStates.isEmpty()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const nextState = this.pendingStates.shift()!;\n // if it's not a message just drop it and keep looking\n if (nextState.type === \"message\") {\n this.assertOpMatch(nextState, message, isOriginalClientId);\n return { localAck: true, localOpMetadata: nextState.localOpMetadata };\n }\n }\n }\n\n if (message.type === ContainerMessageType.Rejoin && this.previousClientIds.has(message.contents?.clientId)) {\n this.previousClientIds.add(message.clientId);\n }\n\n return { localAck: false, localOpMetadata: undefined };\n }\n\n private assertOpMatch(state: IPendingMessage, message: ISequencedDocumentMessage, isOriginalClientId: boolean) {\n assert(message.type === state.messageType, 0x28c /* \"different message type\" */);\n assert(message.clientSequenceNumber === state.clientSequenceNumber || !isOriginalClientId,\n 0x28d /* \"client sequence number doesn't match\" */);\n switch(message.type) {\n case ContainerMessageType.Attach:\n assert(message.contents.id === state.content.id, 0x28e /* \"datastore ID doesn't match\" */);\n break;\n case ContainerMessageType.FluidDataStoreOp:\n assert(message.contents.address === state.content.address, 0x28f /* \"address doesn't match\" */);\n break;\n case ContainerMessageType.BlobAttach:\n // todo: assert we have blob storage, assert blob IDs match, remove blob from blob storage since it made\n // it through successfully\n break;\n case ContainerMessageType.Rejoin:\n default:\n throw new Error(`${message.type} not expected`);\n }\n }\n\n /**\n * Processes a local message once its ack'd by the server. It verifies that there was no data corruption and that\n * the batch information was preserved for batch messages.\n * @param message - The message that got ack'd and needs to be processed.\n */\n private processPendingLocalMessage(message: ISequencedDocumentMessage): unknown {\n // Pre-processing part - This may be the start of a batch.\n this.maybeProcessBatchBegin(message);\n\n // Get the next state from the pending queue and verify that it is of type \"message\".\n const pendingState = this.peekNextPendingState();\n assert(pendingState.type === \"message\", 0x169 /* \"No pending message found for this remote message\" */);\n this.pendingStates.shift();\n\n // Processing part - Verify that there has been no data corruption.\n // The clientSequenceNumber of the incoming message must match that of the pending message.\n if (pendingState.clientSequenceNumber !== message.clientSequenceNumber) {\n // Close the container because this could indicate data corruption.\n const error = DataProcessingError.create(\n \"pending local message clientSequenceNumber mismatch\",\n \"unexpectedAckReceived\",\n message,\n { expectedClientSequenceNumber: pendingState.clientSequenceNumber },\n );\n\n this.containerRuntime.closeFn(error);\n return;\n }\n\n this.pendingMessagesCount--;\n\n // Post-processing part - If we are processing a batch then this could be the last message in the batch.\n this.maybeProcessBatchEnd(message);\n\n return pendingState.localOpMetadata;\n }\n\n /**\n * This message could be the first message in batch. If so, set batch state marking the beginning of a batch.\n * @param message - The message that is being processed.\n */\n private maybeProcessBatchBegin(message: ISequencedDocumentMessage) {\n // Tracks the last FlushMode that was set before this message was sent.\n let pendingFlushMode: FlushMode | undefined;\n // Tracks whether a flush was called before this message was sent.\n let pendingFlush: boolean = false;\n\n /**\n * We are checking if the next message is the start of a batch. It can happen in the following scenarios:\n * 1. The FlushMode was set to TurnBased before this message was sent.\n * 2. The FlushMode was already TurnBased and a flush was called before this message was sent. This essentially\n * means that the flush marked the end of a previous batch and beginning of a new batch.\n *\n * Keep reading pending states from the queue until we encounter a message. It's possible that the FlushMode was\n * updated a bunch of times without sending any messages.\n */\n let nextPendingState = this.peekNextPendingState();\n while (nextPendingState.type !== \"message\") {\n if (nextPendingState.type === \"flushMode\") {\n pendingFlushMode = nextPendingState.flushMode;\n }\n if (nextPendingState.type === \"flush\") {\n pendingFlush = true;\n }\n this.pendingStates.shift();\n nextPendingState = this.peekNextPendingState();\n }\n\n if (pendingFlushMode !== undefined) {\n this.flushModeForNextMessage = pendingFlushMode;\n }\n\n // If the FlushMode was set to Immediate before this message was sent, this message won't be a batch message\n // because in Immediate mode, every message is flushed individually.\n if (pendingFlushMode === FlushMode.Immediate) {\n return;\n }\n\n /**\n * This message is the first in a batch if before it was sent either the FlushMode was set to TurnBased or there\n * was an explicit flush call. Note that a flush call is tracked only in TurnBased mode and it indicates the end\n * of one batch and beginning of another.\n */\n if (pendingFlushMode === FlushMode.TurnBased || pendingFlush) {\n // We should not already be processing a batch and there should be no pending batch begin message.\n assert(!this.isProcessingBatch && this.pendingBatchBeginMessage === undefined,\n 0x16b /* \"The pending batch state indicates we are already processing a batch\" */);\n\n // Set the pending batch state indicating we have started processing a batch.\n this.pendingBatchBeginMessage = message;\n this.isProcessingBatch = true;\n }\n }\n\n /**\n * This message could be the last message in batch. If so, clear batch state since the batch is complete.\n * @param message - The message that is being processed.\n */\n private maybeProcessBatchEnd(message: ISequencedDocumentMessage) {\n if (!this.isProcessingBatch) {\n return;\n }\n\n const nextPendingState = this.peekNextPendingState();\n if (nextPendingState.type === \"message\") {\n return;\n }\n\n /**\n * We are in the middle of processing a batch. The batch ends when we see an explicit flush. We should never see\n * a FlushMode before flush. This is true because we track batches only when FlushMode is TurnBased and in this\n * mode, a batch ends either by calling flush or by changing the mode to Immediate which also triggers a flush.\n */\n assert(\n nextPendingState.type !== \"flushMode\",\n 0x2bd /* \"We should not see a pending FlushMode until we see a flush when processing a batch\" */,\n );\n\n // There should be a pending batch begin message.\n assert(this.pendingBatchBeginMessage !== undefined, 0x16d /* \"There is no pending batch begin message\" */);\n\n // Get the batch begin metadata from the first message in the batch.\n const batchBeginMetadata = this.pendingBatchBeginMessage.metadata?.batch;\n\n // There could be just a single message in the batch. If so, it should not have any batch metadata. If there\n // are multiple messages in the batch, verify that we got the correct batch begin and end metadata.\n if (this.pendingBatchBeginMessage === message) {\n assert(batchBeginMetadata === undefined,\n 0x16e /* \"Batch with single message should not have batch metadata\" */);\n } else {\n // Get the batch metadata from the last message in the batch.\n const batchEndMetadata = message.metadata?.batch;\n assert(batchBeginMetadata === true, 0x16f /* \"Did not receive batch begin metadata\" */);\n assert(batchEndMetadata === false, 0x170 /* \"Did not receive batch end metadata\" */);\n }\n\n // Clear the pending batch state now that we have processed the entire batch.\n this.pendingBatchBeginMessage = undefined;\n this.isProcessingBatch = false;\n }\n\n /**\n * Returns the next pending state from the pending state queue.\n */\n private peekNextPendingState(): IPendingState {\n const nextPendingState = this.pendingStates.peekFront();\n assert(!!nextPendingState, 0x171 /* \"No pending state found for the remote message\" */);\n return nextPendingState;\n }\n\n /**\n * Called when the Container's connection state changes. If the Container gets connected, it replays all the pending\n * states in its queue. This includes setting the FlushMode and triggering resubmission of unacked ops.\n */\n public replayPendingStates() {\n assert(this.connected, 0x172 /* \"The connection state is not consistent with the runtime\" */);\n\n // This assert suggests we are about to send same ops twice, which will result in data loss.\n assert(this.clientId !== this.containerRuntime.clientId,\n 0x173 /* \"replayPendingStates called twice for same clientId!\" */);\n this.clientId = this.containerRuntime.clientId;\n\n assert(this.initialStates.isEmpty(), 0x174 /* \"initial states should be empty before replaying pending\" */);\n\n let pendingStatesCount = this.pendingStates.length;\n if (pendingStatesCount === 0) {\n return;\n }\n\n // Reset the pending message count because all these messages will be removed from the queue.\n this.pendingMessagesCount = 0;\n\n // Save the current FlushMode so that we can revert it back after replaying the states.\n const savedFlushMode = this.containerRuntime.flushMode;\n\n // Set the flush mode for the next message. This step is important because the flush mode may have been changed\n // after the next pending message was sent.\n this.containerRuntime.setFlushMode(this.flushModeForNextMessage);\n\n // Process exactly `pendingStatesCount` items in the queue as it represents the number of states that were\n // pending when we connected. This is important because the `reSubmitFn` might add more items in the queue\n // which must not be replayed.\n while (pendingStatesCount > 0) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const pendingState = this.pendingStates.shift()!;\n switch (pendingState.type) {\n case \"message\":\n this.containerRuntime.reSubmitFn(\n pendingState.messageType,\n pendingState.content,\n pendingState.localOpMetadata,\n pendingState.opMetadata);\n break;\n case \"flushMode\":\n this.containerRuntime.setFlushMode(pendingState.flushMode);\n break;\n case \"flush\":\n this.containerRuntime.flush();\n break;\n default:\n break;\n }\n pendingStatesCount--;\n }\n\n // Revert the FlushMode.\n this.containerRuntime.setFlushMode(savedFlushMode);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"runningSummarizer.d.ts","sourceRoot":"","sources":["../src/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAwB,MAAM,oCAAoC,CAAC;AAGzG,OAAO,EACH,yBAAyB,EACzB,qBAAqB,EAExB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EACH,wBAAwB,EAExB,uBAAuB,EAEvB,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAGH,sBAAsB,EAEzB,MAAM,oBAAoB,CAAC;AAI5B;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IAqD7C,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IACtC,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAA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AC,EAAE,EAAE,yBAAyB;IAe5C,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,yBAAyB;IAYtF,QAAQ,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YA4BjD,SAAS;IAqBvB;;;;;;OAMG;YACW,mBAAmB;IAuBjC;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAwBxB,oCAAoC;IACpC,OAAO,CAAC,YAAY;IAmFpB,8DAA8D;IACvD,iBAAiB,CACpB,cAAc,oCAAuD,EACrE,EACI,MAAM,EACN,GAAG,OAAO,EACb,EAAE,yBAAyB,GAAG,iBAAiB;IAmBpD,6DAA6D;IACtD,gBAAgB,CAAC,EACpB,MAAM,EACN,mBAAuB,EACvB,QAAgB,EAChB,GAAG,OAAO,EACb,EAAE,wBAAwB,GAAG,sBAAsB;IA8BpD,OAAO,CAAC,qBAAqB;IAwB7B,OAAO,CAAC,sBAAsB;CAMjC"}
@@ -67,6 +67,7 @@ class RunningSummarizer {
67
67
  // configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides
68
68
  const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);
69
69
  this.pendingAckTimer = new common_utils_1.PromiseTimer(maxAckWaitTime, () => {
70
+ // pre-0.58 error message: summaryAckWaitTimeout
70
71
  this.raiseSummarizingError("Pending summary ack not received in time");
71
72
  // Note: summarizeCount (from ChildLogger definition) may be 0,
72
73
  // since this code path is hit when RunningSummarizer first starts up,
@@ -261,7 +262,6 @@ class RunningSummarizer {
261
262
  const resultSummarize = this.generator.summarize(summarizeProps, options, cancellationToken);
262
263
  const result = await resultSummarize.receivedSummaryAckOrNack;
263
264
  if (result.success) {
264
- this.totalSuccessfulAttempts++;
265
265
  return;
266
266
  }
267
267
  // Check for retryDelay that can come from summaryNack or upload summary flow.
@@ -1 +1 @@
1
- {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AAC;QAC5D,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7B,OAAO,UAAU,CAAC,CAAC,iCACZ,OAAO,KACV,eAAe,EAAE,IAAI,EACrB,UAAU,EAAE,IAAI,IAClB,CAAC,CAAC,OAAO,CAAC;IAChB,CAAC;IAEO,qBAAqB;QACzB,IAAI,IAAI,CAAC,QAAQ,EAAE;YACf,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;SAChB;QACD,IACI,IAAI,CAAC,eAAe,KAAK,SAAS;eAC/B,IAAI,CAAC,aAAa,CAAC,oBAAoB,GAAG,IAAI,CAAC,eAAe,CAAC,mBAAmB;eAClF,IAAI,CAAC,eAAe,KAAK,SAAS,EACvC;YACE,uFAAuF;YACvF,OAAO,KAAK,CAAC;SAChB;QACD,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,eAAe,CAAC;QACjE,+FAA+F;QAC/F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;QACjC,IAAI,CAAC,gBAAgB,CACjB,EAAE,eAAe,EAAE,mBAAmB,MAAM,EAAE,EAAE,EAChD,OAAO,EACP,IAAI,CAAC,iBAAiB,EACtB,cAAc,CAAC,CAAC;QACpB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEO,sBAAsB;QAC1B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;YAC7F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;SACpC;IACL,CAAC;CACJ;AA1cD,8CA0cC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, delay, Deferred, PromiseTimer } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n ISequencedDocumentMessage,\n ISummaryConfiguration,\n MessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics\";\nimport {\n IEnqueueSummarizeOptions,\n ISummarizeOptions,\n ISummarizeHeuristicData,\n ISummarizeHeuristicRunner,\n ISummarizerOptions,\n IOnDemandSummarizeOptions,\n EnqueueSummarizeResult,\n SummarizerStopReason,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n ISummaryCancellationToken,\n ISummarizeResults,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher, SummaryCollection } from \"./summaryCollection\";\nimport {\n raceTimer,\n SummarizeReason,\n SummarizeResultBuilder,\n SummaryGenerator,\n} from \"./summaryGenerator\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer implements IDisposable {\n public static async start(\n logger: ITelemetryLogger,\n summaryWatcher: IClientSummaryWatcher,\n configuration: ISummaryConfiguration,\n submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n heuristicData: ISummarizeHeuristicData,\n raiseSummarizingError: (errorMessage: string) => void,\n summaryCollection: SummaryCollection,\n cancellationToken: ISummaryCancellationToken,\n stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n options?: Readonly<Partial<ISummarizerOptions>>,\n ): Promise<RunningSummarizer> {\n const summarizer = new RunningSummarizer(\n logger,\n summaryWatcher,\n configuration,\n submitSummaryCallback,\n heuristicData,\n raiseSummarizingError,\n summaryCollection,\n cancellationToken,\n stopSummarizerCallback,\n options);\n\n await summarizer.waitStart();\n\n // Run the heuristics after starting\n summarizer.heuristicRunner?.run();\n return summarizer;\n }\n\n public get disposed() { return this._disposed; }\n\n private stopping = false;\n private _disposed = false;\n private summarizingLock: Promise<void> | undefined;\n private tryWhileSummarizing = false;\n private readonly pendingAckTimer: PromiseTimer;\n private heuristicRunner?: ISummarizeHeuristicRunner;\n private readonly generator: SummaryGenerator;\n private readonly logger: ITelemetryLogger;\n private enqueuedSummary: {\n reason: SummarizeReason;\n afterSequenceNumber: number;\n options: ISummarizeOptions;\n readonly resultsBuilder: SummarizeResultBuilder;\n } | undefined;\n private summarizeCount = 0;\n private totalSuccessfulAttempts = 0;\n\n private constructor(\n baseLogger: ITelemetryLogger,\n private readonly summaryWatcher: IClientSummaryWatcher,\n private readonly configuration: ISummaryConfiguration,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly summaryCollection: SummaryCollection,\n private readonly cancellationToken: ISummaryCancellationToken,\n private readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n { disableHeuristics = false }: Readonly<Partial<ISummarizerOptions>> = {},\n ) {\n this.logger = ChildLogger.create(\n baseLogger, \"Running\",\n {\n all: {\n summarizeCount: () => this.summarizeCount,\n summarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n },\n },\n );\n\n if (!disableHeuristics) {\n this.heuristicRunner = new SummarizeHeuristicRunner(\n heuristicData,\n configuration,\n (reason) => this.trySummarize(reason));\n }\n\n // Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n // configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);\n\n this.pendingAckTimer = new PromiseTimer(\n maxAckWaitTime,\n () => {\n this.raiseSummarizingError(\"Pending summary ack not received in time\");\n // Note: summarizeCount (from ChildLogger definition) may be 0,\n // since this code path is hit when RunningSummarizer first starts up,\n // before this instance has kicked off a new summarize run.\n this.logger.sendErrorEvent({\n eventName: \"SummaryAckWaitTimeout\",\n maxAckWaitTime,\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n timePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n });\n });\n // Set up pending ack timeout by op timestamp differences for previous summaries.\n summaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n if (this.pendingAckTimer.hasTimer) {\n this.logger.sendTelemetryEvent({\n eventName: \"MissingSummaryAckFoundByOps\",\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n });\n this.pendingAckTimer.clear();\n }\n });\n\n this.generator = new SummaryGenerator(\n this.pendingAckTimer,\n this.heuristicData,\n this.submitSummaryCallback,\n this.raiseSummarizingError,\n () => { this.totalSuccessfulAttempts++; },\n this.summaryWatcher,\n this.logger,\n );\n }\n\n public dispose(): void {\n this.summaryWatcher.dispose();\n this.heuristicRunner?.dispose();\n this.heuristicRunner = undefined;\n this.generator.dispose();\n this.pendingAckTimer.clear();\n this.disposeEnqueuedSummary();\n this._disposed = true;\n this.stopping = true;\n }\n\n /**\n * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n * If some other Summarizer code wants that event on their logs they can get it here,\n * but only if they're logging about that same summary.\n * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n */\n public tryGetCorrelatedLogger = (summaryOpRefSeq) =>\n this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n ? this.logger\n : undefined;\n\n public handleSystemOp(op: ISequencedDocumentMessage) {\n switch (op.type) {\n case MessageType.ClientLeave:\n case MessageType.ClientJoin:\n case MessageType.Propose: {\n // Synchronously handle quorum ops like regular ops\n this.handleOp(undefined, op);\n return;\n }\n default: {\n return;\n }\n }\n }\n\n public handleOp(error: any, { sequenceNumber, type, clientId, contents }: ISequencedDocumentMessage) {\n if (error !== undefined) {\n return;\n }\n this.heuristicData.lastOpSequenceNumber = sequenceNumber;\n\n // Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n if (!this.tryRunEnqueuedSummary()) {\n this.heuristicRunner?.run();\n }\n }\n\n public async waitStop(allowLastSummary: boolean): Promise<void> {\n if (this.stopping) {\n return;\n }\n\n this.stopping = true;\n\n this.disposeEnqueuedSummary();\n\n // This will try to run lastSummary if needed.\n if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {\n if (this.summarizingLock === undefined) {\n this.trySummarizeOnce(\n // summarizeProps\n { summarizeReason: \"lastSummary\" },\n // ISummarizeOptions, using defaults: { refreshLatestAck: false, fullTree: false }\n {});\n }\n }\n\n // Note that trySummarizeOnce() call above returns right away, without waiting.\n // So we need to wait for its completion, otherwise it would be destroyed right away.\n // That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n // submit summary. We should reconsider this flow and make summarizer move to exit faster.\n // This resolves when the current pending summary gets an ack or fails.\n await this.summarizingLock;\n }\n\n private async waitStart() {\n // Wait no longer than ack timeout for all pending\n const waitStartResult = await raceTimer(\n this.summaryWatcher.waitFlushed(),\n this.pendingAckTimer.start(),\n );\n this.pendingAckTimer.clear();\n\n // Remove pending ack wait timeout by op timestamp comparison, because\n // it has race conditions with summaries submitted by this same client.\n this.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n if (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n this.heuristicData.initialize({\n refSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n summaryTime: waitStartResult.value.summaryOp.timestamp,\n summarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n });\n }\n }\n\n /**\n * Runs single summary action that prevents any other concurrent actions.\n * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * @param action - action to perform.\n * @returns - result of action.\n */\n private async lockedSummaryAction<T>(action: () => Promise<T>) {\n assert (this.summarizingLock === undefined, 0x25b /* \"Caller is responsible for checking lock\" */);\n\n const summarizingLock = new Deferred<void>();\n this.summarizingLock = summarizingLock.promise;\n\n this.summarizeCount++;\n\n return action().finally(() => {\n summarizingLock.resolve();\n this.summarizingLock = undefined;\n\n const retry = this.tryWhileSummarizing;\n this.tryWhileSummarizing = false;\n\n // After summarizing, we should check to see if we need to summarize again.\n // Rerun the heuristics and check for enqueued summaries.\n if (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n this.heuristicRunner?.run();\n }\n });\n }\n\n /**\n * Runs single summarize attempt\n * @param summarizeProps - props to log with each telemetry event associated with this attempt\n * @param options - summary options\n * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n * @param resultsBuilder - optional, result builder to use.\n * @returns ISummarizeResult - result of running a summary.\n */\n private trySummarizeOnce(\n summarizeProps: ITelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken = this.cancellationToken,\n resultsBuilder = new SummarizeResultBuilder()): ISummarizeResults\n {\n this.lockedSummaryAction(async () => {\n const summarizeResult = this.generator.summarize(\n summarizeProps,\n options,\n cancellationToken,\n resultsBuilder);\n // ensure we wait till the end of the process\n return summarizeResult.receivedSummaryAckOrNack;\n }).catch((error) => {\n // SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n // on resultsBuilder\n // We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n // and take a appropriate action.\n });\n\n return resultsBuilder.build();\n }\n\n /** Heuristics summarize attempt. */\n private trySummarize(\n summarizeReason: SummarizeReason,\n cancellationToken = this.cancellationToken): void\n {\n if (this.summarizingLock !== undefined) {\n // lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n // if it's still needed\n this.tryWhileSummarizing = true;\n return;\n }\n\n this.lockedSummaryAction(async () => {\n const attempts: (ISummarizeOptions & { delaySeconds?: number })[] = [\n { refreshLatestAck: false, fullTree: false },\n { refreshLatestAck: true, fullTree: false },\n { refreshLatestAck: true, fullTree: false, delaySeconds: 2 * 60 },\n { refreshLatestAck: true, fullTree: true, delaySeconds: 10 * 60 },\n ];\n let overrideDelaySeconds: number | undefined;\n let summaryAttempts = 0;\n let summaryAttemptsPerPhase = 0;\n\n let lastResult: { message: string; error: any; } | undefined;\n\n for (let summaryAttemptPhase = 0; summaryAttemptPhase < attempts.length;) {\n if (this.cancellationToken.cancelled) {\n return;\n }\n\n summaryAttempts++;\n summaryAttemptsPerPhase++;\n\n const { delaySeconds: regularDelaySeconds = 0, ...options } = attempts[summaryAttemptPhase];\n const delaySeconds = overrideDelaySeconds ?? regularDelaySeconds;\n\n const summarizeProps: ITelemetryProperties = {\n summarizeReason,\n summaryAttempts,\n summaryAttemptsPerPhase,\n summaryAttemptPhase: summaryAttemptPhase + 1, // make everything 1-based\n ...options,\n };\n\n if (delaySeconds > 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeAttemptDelay\",\n duration: delaySeconds,\n reason: overrideDelaySeconds !== undefined ? \"nack with retryAfter\" : undefined,\n ...summarizeProps,\n });\n await delay(delaySeconds * 1000);\n }\n // Note: no need to account for cancellationToken.waitCancelled here, as\n // this is accounted SummaryGenerator.summarizeCore that controls receivedSummaryAckOrNack.\n const resultSummarize = this.generator.summarize(summarizeProps, options, cancellationToken);\n const result = await resultSummarize.receivedSummaryAckOrNack;\n\n if (result.success) {\n this.totalSuccessfulAttempts++;\n return;\n }\n // Check for retryDelay that can come from summaryNack or upload summary flow.\n // Retry the same step only once per retryAfter response.\n overrideDelaySeconds = result.retryAfterSeconds;\n if (overrideDelaySeconds === undefined || summaryAttemptsPerPhase > 1) {\n summaryAttemptPhase++;\n summaryAttemptsPerPhase = 0;\n }\n lastResult = result;\n }\n\n // If all attempts failed, log error (with last attempt info) and close the summarizer container\n this.logger.sendErrorEvent({\n eventName: \"FailToSummarize\",\n summarizeReason,\n message: lastResult?.message,\n }, lastResult?.error);\n\n this.stopSummarizerCallback(\"failToSummarize\");\n }).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"UnexpectedSummarizeError\" }, error);\n });\n }\n\n /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */\n public summarizeOnDemand(\n resultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n {\n reason,\n ...options\n }: IOnDemandSummarizeOptions): ISummarizeResults {\n if (this.stopping) {\n resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n return resultsBuilder.build();\n }\n // Check for concurrent summary attempts. If one is found,\n // return a promise that caller can await before trying again.\n if (this.summarizingLock !== undefined) {\n // The heuristics are blocking concurrent summarize attempts.\n throw new UsageError(\"Attempted to run an already-running summarizer on demand\");\n }\n const result = this.trySummarizeOnce(\n { summarizeReason: `onDemand/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return result;\n }\n\n /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */\n public enqueueSummarize({\n reason,\n afterSequenceNumber = 0,\n override = false,\n ...options\n }: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n const onDemandReason = `enqueue;${reason}` as const;\n let overridden = false;\n if (this.enqueuedSummary !== undefined) {\n if (!override) {\n return { alreadyEnqueued: true };\n }\n // Override existing enqueued summarize attempt.\n this.enqueuedSummary.resultsBuilder.fail(\n \"Aborted; overridden by another enqueue summarize attempt\",\n undefined,\n );\n this.enqueuedSummary = undefined;\n overridden = true;\n }\n this.enqueuedSummary = {\n reason: onDemandReason,\n afterSequenceNumber,\n options,\n resultsBuilder: new SummarizeResultBuilder(),\n };\n const results = this.enqueuedSummary.resultsBuilder.build();\n this.tryRunEnqueuedSummary();\n return overridden ? {\n ...results,\n alreadyEnqueued: true,\n overridden: true,\n } : results;\n }\n\n private tryRunEnqueuedSummary() {\n if (this.stopping) {\n this.disposeEnqueuedSummary();\n return false;\n }\n if (\n this.enqueuedSummary === undefined\n || this.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber\n || this.summarizingLock !== undefined\n ) {\n // If no enqueued summary is ready or a summary is already in progress, take no action.\n return false;\n }\n const { reason, resultsBuilder, options } = this.enqueuedSummary;\n // Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n this.enqueuedSummary = undefined;\n this.trySummarizeOnce(\n { summarizeReason: `enqueuedSummary/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return true;\n }\n\n private disposeEnqueuedSummary() {\n if (this.enqueuedSummary !== undefined) {\n this.enqueuedSummary.resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n this.enqueuedSummary = undefined;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"runningSummarizer.js","sourceRoot":"","sources":["../src/runningSummarizer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;AAGH,+DAAqF;AACrF,qEAA6D;AAC7D,+EAI8C;AAC9C,qEAA8D;AAC9D,iEAAkE;AAiBlE,yDAK4B;AAE5B,MAAM,uBAAuB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAE7D;;;;;;GAMG;AACH,MAAa,iBAAiB;IAmD1B,YACI,UAA4B,EACX,cAAqC,EACrC,aAAoC,EACpC,qBAAuF,EACvF,aAAsC,EACtC,qBAAqD,EACrD,iBAAoC,EACpC,iBAA4C,EAC5C,sBAA8D,EAC/E,EAAE,iBAAiB,GAAG,KAAK,KAA4C,EAAE;QARxD,mBAAc,GAAd,cAAc,CAAuB;QACrC,kBAAa,GAAb,aAAa,CAAuB;QACpC,0BAAqB,GAArB,qBAAqB,CAAkE;QACvF,kBAAa,GAAb,aAAa,CAAyB;QACtC,0BAAqB,GAArB,qBAAqB,CAAgC;QACrD,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,sBAAiB,GAAjB,iBAAiB,CAA2B;QAC5C,2BAAsB,GAAtB,sBAAsB,CAAwC;QA1B3E,aAAQ,GAAG,KAAK,CAAC;QACjB,cAAS,GAAG,KAAK,CAA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,eAAe,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;YAC7F,IAAI,CAAC,eAAe,GAAG,SAAS,CAAC;SACpC;IACL,CAAC;CACJ;AA1cD,8CA0cC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IDisposable, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, delay, Deferred, PromiseTimer } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n ISequencedDocumentMessage,\n ISummaryConfiguration,\n MessageType,\n} from \"@fluidframework/protocol-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { SummarizeHeuristicRunner } from \"./summarizerHeuristics\";\nimport {\n IEnqueueSummarizeOptions,\n ISummarizeOptions,\n ISummarizeHeuristicData,\n ISummarizeHeuristicRunner,\n ISummarizerOptions,\n IOnDemandSummarizeOptions,\n EnqueueSummarizeResult,\n SummarizerStopReason,\n ISubmitSummaryOptions,\n SubmitSummaryResult,\n ISummaryCancellationToken,\n ISummarizeResults,\n ISummarizeTelemetryProperties,\n} from \"./summarizerTypes\";\nimport { IClientSummaryWatcher, SummaryCollection } from \"./summaryCollection\";\nimport {\n raceTimer,\n SummarizeReason,\n SummarizeResultBuilder,\n SummaryGenerator,\n} from \"./summaryGenerator\";\n\nconst maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes\n\n/**\n * An instance of RunningSummarizer manages the heuristics for summarizing.\n * Until disposed, the instance of RunningSummarizer can assume that it is\n * in a state of running, meaning it is connected and initialized. It keeps\n * track of summaries that it is generating as they are broadcast and acked/nacked.\n * This object is created and controlled by Summarizer object.\n */\nexport class RunningSummarizer implements IDisposable {\n public static async start(\n logger: ITelemetryLogger,\n summaryWatcher: IClientSummaryWatcher,\n configuration: ISummaryConfiguration,\n submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n heuristicData: ISummarizeHeuristicData,\n raiseSummarizingError: (errorMessage: string) => void,\n summaryCollection: SummaryCollection,\n cancellationToken: ISummaryCancellationToken,\n stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n options?: Readonly<Partial<ISummarizerOptions>>,\n ): Promise<RunningSummarizer> {\n const summarizer = new RunningSummarizer(\n logger,\n summaryWatcher,\n configuration,\n submitSummaryCallback,\n heuristicData,\n raiseSummarizingError,\n summaryCollection,\n cancellationToken,\n stopSummarizerCallback,\n options);\n\n await summarizer.waitStart();\n\n // Run the heuristics after starting\n summarizer.heuristicRunner?.run();\n return summarizer;\n }\n\n public get disposed() { return this._disposed; }\n\n private stopping = false;\n private _disposed = false;\n private summarizingLock: Promise<void> | undefined;\n private tryWhileSummarizing = false;\n private readonly pendingAckTimer: PromiseTimer;\n private heuristicRunner?: ISummarizeHeuristicRunner;\n private readonly generator: SummaryGenerator;\n private readonly logger: ITelemetryLogger;\n private enqueuedSummary: {\n reason: SummarizeReason;\n afterSequenceNumber: number;\n options: ISummarizeOptions;\n readonly resultsBuilder: SummarizeResultBuilder;\n } | undefined;\n private summarizeCount = 0;\n private totalSuccessfulAttempts = 0;\n\n private constructor(\n baseLogger: ITelemetryLogger,\n private readonly summaryWatcher: IClientSummaryWatcher,\n private readonly configuration: ISummaryConfiguration,\n private readonly submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,\n private readonly heuristicData: ISummarizeHeuristicData,\n private readonly raiseSummarizingError: (errorMessage: string) => void,\n private readonly summaryCollection: SummaryCollection,\n private readonly cancellationToken: ISummaryCancellationToken,\n private readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,\n { disableHeuristics = false }: Readonly<Partial<ISummarizerOptions>> = {},\n ) {\n this.logger = ChildLogger.create(\n baseLogger, \"Running\",\n {\n all: {\n summarizeCount: () => this.summarizeCount,\n summarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,\n },\n },\n );\n\n if (!disableHeuristics) {\n this.heuristicRunner = new SummarizeHeuristicRunner(\n heuristicData,\n configuration,\n (reason) => this.trySummarize(reason));\n }\n\n // Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime\n // configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides\n const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);\n\n this.pendingAckTimer = new PromiseTimer(\n maxAckWaitTime,\n () => {\n // pre-0.58 error message: summaryAckWaitTimeout\n this.raiseSummarizingError(\"Pending summary ack not received in time\");\n // Note: summarizeCount (from ChildLogger definition) may be 0,\n // since this code path is hit when RunningSummarizer first starts up,\n // before this instance has kicked off a new summarize run.\n this.logger.sendErrorEvent({\n eventName: \"SummaryAckWaitTimeout\",\n maxAckWaitTime,\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n timePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,\n });\n });\n // Set up pending ack timeout by op timestamp differences for previous summaries.\n summaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {\n if (this.pendingAckTimer.hasTimer) {\n this.logger.sendTelemetryEvent({\n eventName: \"MissingSummaryAckFoundByOps\",\n referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,\n summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,\n });\n this.pendingAckTimer.clear();\n }\n });\n\n this.generator = new SummaryGenerator(\n this.pendingAckTimer,\n this.heuristicData,\n this.submitSummaryCallback,\n this.raiseSummarizingError,\n () => { this.totalSuccessfulAttempts++; },\n this.summaryWatcher,\n this.logger,\n );\n }\n\n public dispose(): void {\n this.summaryWatcher.dispose();\n this.heuristicRunner?.dispose();\n this.heuristicRunner = undefined;\n this.generator.dispose();\n this.pendingAckTimer.clear();\n this.disposeEnqueuedSummary();\n this._disposed = true;\n this.stopping = true;\n }\n\n /**\n * RunningSummarizer's logger includes the sequenced index of the current summary on each event.\n * If some other Summarizer code wants that event on their logs they can get it here,\n * but only if they're logging about that same summary.\n * @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct\n */\n public tryGetCorrelatedLogger = (summaryOpRefSeq) =>\n this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq\n ? this.logger\n : undefined;\n\n public handleSystemOp(op: ISequencedDocumentMessage) {\n switch (op.type) {\n case MessageType.ClientLeave:\n case MessageType.ClientJoin:\n case MessageType.Propose: {\n // Synchronously handle quorum ops like regular ops\n this.handleOp(undefined, op);\n return;\n }\n default: {\n return;\n }\n }\n }\n\n public handleOp(error: any, { sequenceNumber, type, clientId, contents }: ISequencedDocumentMessage) {\n if (error !== undefined) {\n return;\n }\n this.heuristicData.lastOpSequenceNumber = sequenceNumber;\n\n // Check for enqueued on-demand summaries; Intentionally do nothing otherwise\n if (!this.tryRunEnqueuedSummary()) {\n this.heuristicRunner?.run();\n }\n }\n\n public async waitStop(allowLastSummary: boolean): Promise<void> {\n if (this.stopping) {\n return;\n }\n\n this.stopping = true;\n\n this.disposeEnqueuedSummary();\n\n // This will try to run lastSummary if needed.\n if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {\n if (this.summarizingLock === undefined) {\n this.trySummarizeOnce(\n // summarizeProps\n { summarizeReason: \"lastSummary\" },\n // ISummarizeOptions, using defaults: { refreshLatestAck: false, fullTree: false }\n {});\n }\n }\n\n // Note that trySummarizeOnce() call above returns right away, without waiting.\n // So we need to wait for its completion, otherwise it would be destroyed right away.\n // That said, if summary lock was taken upfront, this wait might wait on multiple retries to\n // submit summary. We should reconsider this flow and make summarizer move to exit faster.\n // This resolves when the current pending summary gets an ack or fails.\n await this.summarizingLock;\n }\n\n private async waitStart() {\n // Wait no longer than ack timeout for all pending\n const waitStartResult = await raceTimer(\n this.summaryWatcher.waitFlushed(),\n this.pendingAckTimer.start(),\n );\n this.pendingAckTimer.clear();\n\n // Remove pending ack wait timeout by op timestamp comparison, because\n // it has race conditions with summaries submitted by this same client.\n this.summaryCollection.unsetPendingAckTimerTimeoutCallback();\n\n if (waitStartResult.result === \"done\" && waitStartResult.value !== undefined) {\n this.heuristicData.initialize({\n refSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,\n summaryTime: waitStartResult.value.summaryOp.timestamp,\n summarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,\n });\n }\n }\n\n /**\n * Runs single summary action that prevents any other concurrent actions.\n * Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)\n * before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.\n * @param action - action to perform.\n * @returns - result of action.\n */\n private async lockedSummaryAction<T>(action: () => Promise<T>) {\n assert (this.summarizingLock === undefined, 0x25b /* \"Caller is responsible for checking lock\" */);\n\n const summarizingLock = new Deferred<void>();\n this.summarizingLock = summarizingLock.promise;\n\n this.summarizeCount++;\n\n return action().finally(() => {\n summarizingLock.resolve();\n this.summarizingLock = undefined;\n\n const retry = this.tryWhileSummarizing;\n this.tryWhileSummarizing = false;\n\n // After summarizing, we should check to see if we need to summarize again.\n // Rerun the heuristics and check for enqueued summaries.\n if (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {\n this.heuristicRunner?.run();\n }\n });\n }\n\n /**\n * Runs single summarize attempt\n * @param summarizeProps - props to log with each telemetry event associated with this attempt\n * @param options - summary options\n * @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed\n * @param resultsBuilder - optional, result builder to use.\n * @returns ISummarizeResult - result of running a summary.\n */\n private trySummarizeOnce(\n summarizeProps: ISummarizeTelemetryProperties,\n options: ISummarizeOptions,\n cancellationToken = this.cancellationToken,\n resultsBuilder = new SummarizeResultBuilder()): ISummarizeResults\n {\n this.lockedSummaryAction(async () => {\n const summarizeResult = this.generator.summarize(\n summarizeProps,\n options,\n cancellationToken,\n resultsBuilder);\n // ensure we wait till the end of the process\n return summarizeResult.receivedSummaryAckOrNack;\n }).catch((error) => {\n // SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result\n // on resultsBuilder\n // We do not care about exceptions on receivedSummaryAckOrNack - caller should check results\n // and take a appropriate action.\n });\n\n return resultsBuilder.build();\n }\n\n /** Heuristics summarize attempt. */\n private trySummarize(\n summarizeReason: SummarizeReason,\n cancellationToken = this.cancellationToken): void\n {\n if (this.summarizingLock !== undefined) {\n // lockedSummaryAction() will retry heuristic-based summary at the end of current attempt\n // if it's still needed\n this.tryWhileSummarizing = true;\n return;\n }\n\n this.lockedSummaryAction(async () => {\n const attempts: (ISummarizeOptions & { delaySeconds?: number })[] = [\n { refreshLatestAck: false, fullTree: false },\n { refreshLatestAck: true, fullTree: false },\n { refreshLatestAck: true, fullTree: false, delaySeconds: 2 * 60 },\n { refreshLatestAck: true, fullTree: true, delaySeconds: 10 * 60 },\n ];\n let overrideDelaySeconds: number | undefined;\n let summaryAttempts = 0;\n let summaryAttemptsPerPhase = 0;\n\n let lastResult: { message: string; error: any; } | undefined;\n\n for (let summaryAttemptPhase = 0; summaryAttemptPhase < attempts.length;) {\n if (this.cancellationToken.cancelled) {\n return;\n }\n\n summaryAttempts++;\n summaryAttemptsPerPhase++;\n\n const { delaySeconds: regularDelaySeconds = 0, ...options } = attempts[summaryAttemptPhase];\n const delaySeconds = overrideDelaySeconds ?? regularDelaySeconds;\n\n const summarizeProps: ISummarizeTelemetryProperties = {\n summarizeReason,\n summaryAttempts,\n summaryAttemptsPerPhase,\n summaryAttemptPhase: summaryAttemptPhase + 1, // make everything 1-based\n ...options,\n };\n\n if (delaySeconds > 0) {\n this.logger.sendPerformanceEvent({\n eventName: \"SummarizeAttemptDelay\",\n duration: delaySeconds,\n reason: overrideDelaySeconds !== undefined ? \"nack with retryAfter\" : undefined,\n ...summarizeProps,\n });\n await delay(delaySeconds * 1000);\n }\n // Note: no need to account for cancellationToken.waitCancelled here, as\n // this is accounted SummaryGenerator.summarizeCore that controls receivedSummaryAckOrNack.\n const resultSummarize = this.generator.summarize(summarizeProps, options, cancellationToken);\n const result = await resultSummarize.receivedSummaryAckOrNack;\n\n if (result.success) {\n return;\n }\n // Check for retryDelay that can come from summaryNack or upload summary flow.\n // Retry the same step only once per retryAfter response.\n overrideDelaySeconds = result.retryAfterSeconds;\n if (overrideDelaySeconds === undefined || summaryAttemptsPerPhase > 1) {\n summaryAttemptPhase++;\n summaryAttemptsPerPhase = 0;\n }\n lastResult = result;\n }\n\n // If all attempts failed, log error (with last attempt info) and close the summarizer container\n this.logger.sendErrorEvent({\n eventName: \"FailToSummarize\",\n summarizeReason,\n message: lastResult?.message,\n }, lastResult?.error);\n\n this.stopSummarizerCallback(\"failToSummarize\");\n }).catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"UnexpectedSummarizeError\" }, error);\n });\n }\n\n /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */\n public summarizeOnDemand(\n resultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),\n {\n reason,\n ...options\n }: IOnDemandSummarizeOptions): ISummarizeResults {\n if (this.stopping) {\n resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n return resultsBuilder.build();\n }\n // Check for concurrent summary attempts. If one is found,\n // return a promise that caller can await before trying again.\n if (this.summarizingLock !== undefined) {\n // The heuristics are blocking concurrent summarize attempts.\n throw new UsageError(\"Attempted to run an already-running summarizer on demand\");\n }\n const result = this.trySummarizeOnce(\n { summarizeReason: `onDemand/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return result;\n }\n\n /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */\n public enqueueSummarize({\n reason,\n afterSequenceNumber = 0,\n override = false,\n ...options\n }: IEnqueueSummarizeOptions): EnqueueSummarizeResult {\n const onDemandReason = `enqueue;${reason}` as const;\n let overridden = false;\n if (this.enqueuedSummary !== undefined) {\n if (!override) {\n return { alreadyEnqueued: true };\n }\n // Override existing enqueued summarize attempt.\n this.enqueuedSummary.resultsBuilder.fail(\n \"Aborted; overridden by another enqueue summarize attempt\",\n undefined,\n );\n this.enqueuedSummary = undefined;\n overridden = true;\n }\n this.enqueuedSummary = {\n reason: onDemandReason,\n afterSequenceNumber,\n options,\n resultsBuilder: new SummarizeResultBuilder(),\n };\n const results = this.enqueuedSummary.resultsBuilder.build();\n this.tryRunEnqueuedSummary();\n return overridden ? {\n ...results,\n alreadyEnqueued: true,\n overridden: true,\n } : results;\n }\n\n private tryRunEnqueuedSummary() {\n if (this.stopping) {\n this.disposeEnqueuedSummary();\n return false;\n }\n if (\n this.enqueuedSummary === undefined\n || this.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber\n || this.summarizingLock !== undefined\n ) {\n // If no enqueued summary is ready or a summary is already in progress, take no action.\n return false;\n }\n const { reason, resultsBuilder, options } = this.enqueuedSummary;\n // Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.\n this.enqueuedSummary = undefined;\n this.trySummarizeOnce(\n { summarizeReason: `enqueuedSummary/${reason}` },\n options,\n this.cancellationToken,\n resultsBuilder);\n return true;\n }\n\n private disposeEnqueuedSummary() {\n if (this.enqueuedSummary !== undefined) {\n this.enqueuedSummary.resultsBuilder.fail(\"RunningSummarizer stopped or disposed\", undefined);\n this.enqueuedSummary = undefined;\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerClientElection.d.ts","sourceRoot":"","sources":["../src/summarizerClientElection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAe,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtG,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAEjE,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electionSequenceNumber,
56
56
  nextElectedClientId: (_b = this.clientElection.peekNextElectedClient()) === null || _b === void 0 ? void 0 : _b.clientId,
57
+ electionEnabled: this.electionEnabled,
57
58
  });
58
59
  this.lastReportedSeq = sequenceNumber;
59
60
  }