@fluidframework/container-runtime 2.0.0-internal.1.0.0.82693 → 2.0.0-internal.1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/.mocharc.js +12 -0
  2. package/dist/batchTracker.js +1 -1
  3. package/dist/batchTracker.js.map +1 -1
  4. package/dist/blobManager.d.ts +7 -1
  5. package/dist/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager.js +34 -17
  7. package/dist/blobManager.js.map +1 -1
  8. package/dist/containerRuntime.d.ts +3 -104
  9. package/dist/containerRuntime.d.ts.map +1 -1
  10. package/dist/containerRuntime.js +83 -395
  11. package/dist/containerRuntime.js.map +1 -1
  12. package/dist/dataStore.d.ts +1 -1
  13. package/dist/dataStore.d.ts.map +1 -1
  14. package/dist/dataStore.js +2 -3
  15. package/dist/dataStore.js.map +1 -1
  16. package/dist/dataStoreContext.d.ts +3 -5
  17. package/dist/dataStoreContext.d.ts.map +1 -1
  18. package/dist/dataStoreContext.js +13 -23
  19. package/dist/dataStoreContext.js.map +1 -1
  20. package/dist/dataStores.d.ts +1 -1
  21. package/dist/dataStores.d.ts.map +1 -1
  22. package/dist/dataStores.js +3 -8
  23. package/dist/dataStores.js.map +1 -1
  24. package/dist/garbageCollection.d.ts +37 -6
  25. package/dist/garbageCollection.d.ts.map +1 -1
  26. package/dist/garbageCollection.js +61 -65
  27. package/dist/garbageCollection.js.map +1 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -2
  31. package/dist/index.js.map +1 -1
  32. package/dist/packageVersion.d.ts +1 -1
  33. package/dist/packageVersion.d.ts.map +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/pendingStateManager.d.ts.map +1 -1
  37. package/dist/pendingStateManager.js +15 -2
  38. package/dist/pendingStateManager.js.map +1 -1
  39. package/dist/runningSummarizer.d.ts +14 -0
  40. package/dist/runningSummarizer.d.ts.map +1 -1
  41. package/dist/runningSummarizer.js +25 -0
  42. package/dist/runningSummarizer.js.map +1 -1
  43. package/dist/scheduleManager.d.ts +28 -0
  44. package/dist/scheduleManager.d.ts.map +1 -0
  45. package/dist/scheduleManager.js +235 -0
  46. package/dist/scheduleManager.js.map +1 -0
  47. package/dist/summarizer.d.ts.map +1 -1
  48. package/dist/summarizer.js +33 -3
  49. package/dist/summarizer.js.map +1 -1
  50. package/dist/summaryCollection.js +1 -1
  51. package/dist/summaryCollection.js.map +1 -1
  52. package/dist/summaryGenerator.js +1 -1
  53. package/dist/summaryGenerator.js.map +1 -1
  54. package/dist/summaryManager.d.ts.map +1 -1
  55. package/dist/summaryManager.js +20 -5
  56. package/dist/summaryManager.js.map +1 -1
  57. package/lib/batchTracker.js +1 -1
  58. package/lib/batchTracker.js.map +1 -1
  59. package/lib/blobManager.d.ts +7 -1
  60. package/lib/blobManager.d.ts.map +1 -1
  61. package/lib/blobManager.js +35 -18
  62. package/lib/blobManager.js.map +1 -1
  63. package/lib/containerRuntime.d.ts +3 -104
  64. package/lib/containerRuntime.d.ts.map +1 -1
  65. package/lib/containerRuntime.js +84 -395
  66. package/lib/containerRuntime.js.map +1 -1
  67. package/lib/dataStore.d.ts +1 -1
  68. package/lib/dataStore.d.ts.map +1 -1
  69. package/lib/dataStore.js +2 -3
  70. package/lib/dataStore.js.map +1 -1
  71. package/lib/dataStoreContext.d.ts +3 -5
  72. package/lib/dataStoreContext.d.ts.map +1 -1
  73. package/lib/dataStoreContext.js +13 -23
  74. package/lib/dataStoreContext.js.map +1 -1
  75. package/lib/dataStores.d.ts +1 -1
  76. package/lib/dataStores.d.ts.map +1 -1
  77. package/lib/dataStores.js +3 -8
  78. package/lib/dataStores.js.map +1 -1
  79. package/lib/garbageCollection.d.ts +37 -6
  80. package/lib/garbageCollection.d.ts.map +1 -1
  81. package/lib/garbageCollection.js +47 -52
  82. package/lib/garbageCollection.js.map +1 -1
  83. package/lib/index.d.ts +2 -1
  84. package/lib/index.d.ts.map +1 -1
  85. package/lib/index.js +2 -1
  86. package/lib/index.js.map +1 -1
  87. package/lib/packageVersion.d.ts +1 -1
  88. package/lib/packageVersion.d.ts.map +1 -1
  89. package/lib/packageVersion.js +1 -1
  90. package/lib/packageVersion.js.map +1 -1
  91. package/lib/pendingStateManager.d.ts.map +1 -1
  92. package/lib/pendingStateManager.js +15 -2
  93. package/lib/pendingStateManager.js.map +1 -1
  94. package/lib/runningSummarizer.d.ts +14 -0
  95. package/lib/runningSummarizer.d.ts.map +1 -1
  96. package/lib/runningSummarizer.js +25 -0
  97. package/lib/runningSummarizer.js.map +1 -1
  98. package/lib/scheduleManager.d.ts +28 -0
  99. package/lib/scheduleManager.d.ts.map +1 -0
  100. package/lib/scheduleManager.js +231 -0
  101. package/lib/scheduleManager.js.map +1 -0
  102. package/lib/summarizer.d.ts.map +1 -1
  103. package/lib/summarizer.js +35 -5
  104. package/lib/summarizer.js.map +1 -1
  105. package/lib/summaryCollection.js +1 -1
  106. package/lib/summaryCollection.js.map +1 -1
  107. package/lib/summaryGenerator.js +1 -1
  108. package/lib/summaryGenerator.js.map +1 -1
  109. package/lib/summaryManager.d.ts.map +1 -1
  110. package/lib/summaryManager.js +20 -5
  111. package/lib/summaryManager.js.map +1 -1
  112. package/package.json +32 -19
  113. package/src/batchTracker.ts +1 -1
  114. package/src/blobManager.ts +43 -17
  115. package/src/containerRuntime.ts +113 -547
  116. package/src/dataStore.ts +1 -4
  117. package/src/dataStoreContext.ts +10 -25
  118. package/src/dataStores.ts +13 -19
  119. package/src/garbageCollection.ts +64 -69
  120. package/src/index.ts +1 -2
  121. package/src/packageVersion.ts +1 -1
  122. package/src/pendingStateManager.ts +18 -2
  123. package/src/runningSummarizer.ts +33 -1
  124. package/src/scheduleManager.ts +294 -0
  125. package/src/summarizer.ts +46 -10
  126. package/src/summaryCollection.ts +1 -1
  127. package/src/summaryGenerator.ts +1 -1
  128. package/src/summaryManager.ts +20 -5
@@ -0,0 +1,231 @@
1
+ import { ChildLogger } from "@fluidframework/telemetry-utils";
2
+ import { assert, performance } from "@fluidframework/common-utils";
3
+ import { isUnpackedRuntimeMessage } from "@fluidframework/driver-utils";
4
+ import { DataCorruptionError, extractSafePropertiesFromMessage } from "@fluidframework/container-utils";
5
+ import { DeltaScheduler } from "./deltaScheduler";
6
+ import { pkgVersion } from "./packageVersion";
7
+ import { latencyThreshold } from "./connectionTelemetry";
8
+ /**
9
+ * This class has the following responsibilities:
10
+ * 1. It tracks batches as we process ops and raises "batchBegin" and "batchEnd" events.
11
+ * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)
12
+ * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch
13
+ * unless all ops of the batch are in.
14
+ */
15
+ export class ScheduleManager {
16
+ constructor(deltaManager, emitter, logger) {
17
+ this.deltaManager = deltaManager;
18
+ this.emitter = emitter;
19
+ this.logger = logger;
20
+ this.hitError = false;
21
+ this.deltaScheduler = new DeltaScheduler(this.deltaManager, ChildLogger.create(this.logger, "DeltaScheduler"));
22
+ void new ScheduleManagerCore(deltaManager, logger);
23
+ }
24
+ beforeOpProcessing(message) {
25
+ var _a;
26
+ if (this.batchClientId !== message.clientId) {
27
+ assert(this.batchClientId === undefined, 0x2a2 /* "Batch is interrupted by other client op. Should be caught by trackPending()" */);
28
+ // This could be the beginning of a new batch or an individual message.
29
+ this.emitter.emit("batchBegin", message);
30
+ this.deltaScheduler.batchBegin(message);
31
+ const batch = (_a = message === null || message === void 0 ? void 0 : message.metadata) === null || _a === void 0 ? void 0 : _a.batch;
32
+ if (batch) {
33
+ this.batchClientId = message.clientId;
34
+ }
35
+ else {
36
+ this.batchClientId = undefined;
37
+ }
38
+ }
39
+ }
40
+ afterOpProcessing(error, message) {
41
+ var _a;
42
+ // If this is no longer true, we need to revisit what we do where we set this.hitError.
43
+ assert(!this.hitError, 0x2a3 /* "container should be closed on any error" */);
44
+ if (error) {
45
+ // We assume here that loader will close container and stop processing all future ops.
46
+ // This is implicit dependency. If this flow changes, this code might no longer be correct.
47
+ this.hitError = true;
48
+ this.batchClientId = undefined;
49
+ this.emitter.emit("batchEnd", error, message);
50
+ this.deltaScheduler.batchEnd(message);
51
+ return;
52
+ }
53
+ const batch = (_a = message === null || message === void 0 ? void 0 : message.metadata) === null || _a === void 0 ? void 0 : _a.batch;
54
+ // If no batchClientId has been set then we're in an individual batch. Else, if we get
55
+ // batch end metadata, this is end of the current batch.
56
+ if (this.batchClientId === undefined || batch === false) {
57
+ this.batchClientId = undefined;
58
+ this.emitter.emit("batchEnd", undefined, message);
59
+ this.deltaScheduler.batchEnd(message);
60
+ return;
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * This class controls pausing and resuming of inbound queue to ensure that we never
66
+ * start processing ops in a batch IF we do not have all ops in the batch.
67
+ */
68
+ class ScheduleManagerCore {
69
+ constructor(deltaManager, logger) {
70
+ this.deltaManager = deltaManager;
71
+ this.logger = logger;
72
+ this.localPaused = false;
73
+ this.timePaused = 0;
74
+ this.batchCount = 0;
75
+ // Listen for delta manager sends and add batch metadata to messages
76
+ this.deltaManager.on("prepareSend", (messages) => {
77
+ if (messages.length === 0) {
78
+ return;
79
+ }
80
+ // First message will have the batch flag set to true if doing a batched send
81
+ const firstMessageMetadata = messages[0].metadata;
82
+ if (!(firstMessageMetadata === null || firstMessageMetadata === void 0 ? void 0 : firstMessageMetadata.batch)) {
83
+ return;
84
+ }
85
+ // If the batch contains only a single op, clear the batch flag.
86
+ if (messages.length === 1) {
87
+ delete firstMessageMetadata.batch;
88
+ return;
89
+ }
90
+ // Set the batch flag to false on the last message to indicate the end of the send batch
91
+ const lastMessage = messages[messages.length - 1];
92
+ lastMessage.metadata = Object.assign(Object.assign({}, lastMessage.metadata), { batch: false });
93
+ });
94
+ // Listen for updates and peek at the inbound
95
+ this.deltaManager.inbound.on("push", (message) => {
96
+ this.trackPending(message);
97
+ });
98
+ // Start with baseline - empty inbound queue.
99
+ assert(!this.localPaused, 0x293 /* "initial state" */);
100
+ const allPending = this.deltaManager.inbound.toArray();
101
+ for (const pending of allPending) {
102
+ this.trackPending(pending);
103
+ }
104
+ // We are intentionally directly listening to the "op" to inspect system ops as well.
105
+ // If we do not observe system ops, we are likely to hit 0x296 assert when system ops
106
+ // precedes start of incomplete batch.
107
+ this.deltaManager.on("op", (message) => this.afterOpProcessing(message.sequenceNumber));
108
+ }
109
+ /**
110
+ * The only public function in this class - called when we processed an op,
111
+ * to make decision if op processing should be paused or not after that.
112
+ */
113
+ afterOpProcessing(sequenceNumber) {
114
+ assert(!this.localPaused, 0x294 /* "can't have op processing paused if we are processing an op" */);
115
+ // If the inbound queue is ever empty, nothing to do!
116
+ if (this.deltaManager.inbound.length === 0) {
117
+ assert(this.pauseSequenceNumber === undefined, 0x295 /* "there should be no pending batch if we have no ops" */);
118
+ return;
119
+ }
120
+ // The queue is
121
+ // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:
122
+ // - here (processing ops until reaching start of incomplete batch)
123
+ // - in trackPending(), when queue was empty and start of batch showed up.
124
+ // 2. resumed when batch end comes in (in trackPending())
125
+ // do we have incomplete batch to worry about?
126
+ if (this.pauseSequenceNumber !== undefined) {
127
+ assert(sequenceNumber < this.pauseSequenceNumber, 0x296 /* "we should never start processing incomplete batch!" */);
128
+ // If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!
129
+ if (sequenceNumber + 1 === this.pauseSequenceNumber) {
130
+ this.pauseQueue();
131
+ }
132
+ }
133
+ }
134
+ pauseQueue() {
135
+ assert(!this.localPaused, 0x297 /* "always called from resumed state" */);
136
+ this.localPaused = true;
137
+ this.timePaused = performance.now();
138
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
139
+ this.deltaManager.inbound.pause();
140
+ }
141
+ resumeQueue(startBatch, messageEndBatch) {
142
+ const endBatch = messageEndBatch.sequenceNumber;
143
+ const duration = this.localPaused ? (performance.now() - this.timePaused) : undefined;
144
+ this.batchCount++;
145
+ if (this.batchCount % 1000 === 1) {
146
+ this.logger.sendTelemetryEvent({
147
+ eventName: "BatchStats",
148
+ sequenceNumber: endBatch,
149
+ length: endBatch - startBatch + 1,
150
+ msnDistance: endBatch - messageEndBatch.minimumSequenceNumber,
151
+ duration,
152
+ batchCount: this.batchCount,
153
+ interrupted: this.localPaused,
154
+ });
155
+ }
156
+ // Return early if no change in value
157
+ if (!this.localPaused) {
158
+ return;
159
+ }
160
+ this.localPaused = false;
161
+ // Random round number - we want to know when batch waiting paused op processing.
162
+ if (duration !== undefined && duration > latencyThreshold) {
163
+ this.logger.sendErrorEvent({
164
+ eventName: "MaxBatchWaitTimeExceeded",
165
+ duration,
166
+ sequenceNumber: endBatch,
167
+ length: endBatch - startBatch,
168
+ });
169
+ }
170
+ this.deltaManager.inbound.resume();
171
+ }
172
+ /**
173
+ * Called for each incoming op (i.e. inbound "push" notification)
174
+ */
175
+ trackPending(message) {
176
+ assert(this.deltaManager.inbound.length !== 0, 0x298 /* "we have something in the queue that generates this event" */);
177
+ assert((this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined), 0x299 /* "non-synchronized state" */);
178
+ const metadata = message.metadata;
179
+ const batchMetadata = metadata === null || metadata === void 0 ? void 0 : metadata.batch;
180
+ // Protocol messages are never part of a runtime batch of messages
181
+ if (!isUnpackedRuntimeMessage(message)) {
182
+ // Protocol messages should never show up in the middle of the batch!
183
+ assert(this.currentBatchClientId === undefined, 0x29a /* "System message in the middle of batch!" */);
184
+ assert(batchMetadata === undefined, 0x29b /* "system op in a batch?" */);
185
+ assert(!this.localPaused, 0x29c /* "we should be processing ops when there is no active batch" */);
186
+ return;
187
+ }
188
+ if (this.currentBatchClientId === undefined && batchMetadata === undefined) {
189
+ assert(!this.localPaused, 0x29d /* "we should be processing ops when there is no active batch" */);
190
+ return;
191
+ }
192
+ // If the client ID changes then we can move the pause point. If it stayed the same then we need to check.
193
+ // If batchMetadata is not undefined then if it's true we've begun a new batch - if false we've ended
194
+ // the previous one
195
+ if (this.currentBatchClientId !== undefined || batchMetadata === false) {
196
+ if (this.currentBatchClientId !== message.clientId) {
197
+ // "Batch not closed, yet message from another client!"
198
+ throw new DataCorruptionError("OpBatchIncomplete", Object.assign({ runtimeVersion: pkgVersion, batchClientId: this.currentBatchClientId }, extractSafePropertiesFromMessage(message)));
199
+ }
200
+ }
201
+ // The queue is
202
+ // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:
203
+ // - in afterOpProcessing() - processing ops until reaching start of incomplete batch
204
+ // - here (batchMetadata == false below), when queue was empty and start of batch showed up.
205
+ // 2. resumed when batch end comes in (batchMetadata === true case below)
206
+ if (batchMetadata) {
207
+ assert(this.currentBatchClientId === undefined, 0x29e /* "there can't be active batch" */);
208
+ assert(!this.localPaused, 0x29f /* "we should be processing ops when there is no active batch" */);
209
+ this.pauseSequenceNumber = message.sequenceNumber;
210
+ this.currentBatchClientId = message.clientId;
211
+ // Start of the batch
212
+ // Only pause processing if queue has no other ops!
213
+ // If there are any other ops in the queue, processing will be stopped when they are processed!
214
+ if (this.deltaManager.inbound.length === 1) {
215
+ this.pauseQueue();
216
+ }
217
+ }
218
+ else if (batchMetadata === false) {
219
+ assert(this.pauseSequenceNumber !== undefined, 0x2a0 /* "batch presence was validated above" */);
220
+ // Batch is complete, we can process it!
221
+ this.resumeQueue(this.pauseSequenceNumber, message);
222
+ this.pauseSequenceNumber = undefined;
223
+ this.currentBatchClientId = undefined;
224
+ }
225
+ else {
226
+ // Continuation of current batch. Do nothing
227
+ assert(this.currentBatchClientId !== undefined, 0x2a1 /* "logic error" */);
228
+ }
229
+ }
230
+ }
231
+ //# sourceMappingURL=scheduleManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduleManager.js","sourceRoot":"","sources":["../src/scheduleManager.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CA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AAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;YAC7C,qBAAqB;YACrB,mDAAmD;YACnD,+FAA+F;YAC/F,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACxC,IAAI,CAAC,UAAU,EAAE,CAAC;aACrB;SACJ;aAAM,IAAI,aAAa,KAAK,KAAK,EAAE;YAChC,MAAM,CAAC,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE,KAAK,CAAC,0CAA0C,CAAC,CAAC;YACjG,wCAAwC;YACxC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;YACpD,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;YACrC,IAAI,CAAC,oBAAoB,GAAG,SAAS,CAAC;SACzC;aAAM;YACH,4CAA4C;YAC5C,MAAM,CAAC,IAAI,CAAC,oBAAoB,KAAK,SAAS,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;SAC9E;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { EventEmitter } from \"events\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { assert, performance } from \"@fluidframework/common-utils\";\nimport { isUnpackedRuntimeMessage } from \"@fluidframework/driver-utils\";\nimport { DataCorruptionError, extractSafePropertiesFromMessage } from \"@fluidframework/container-utils\";\nimport { DeltaScheduler } from \"./deltaScheduler\";\nimport { pkgVersion } from \"./packageVersion\";\nimport { latencyThreshold } from \"./connectionTelemetry\";\n\ntype IRuntimeMessageMetadata = undefined | {\n batch?: boolean;\n};\n\n/**\n * This class has the following responsibilities:\n * 1. It tracks batches as we process ops and raises \"batchBegin\" and \"batchEnd\" events.\n * As part of it, it validates batch correctness (i.e. no system ops in the middle of batch)\n * 2. It creates instance of ScheduleManagerCore that ensures we never start processing ops from batch\n * unless all ops of the batch are in.\n */\nexport class ScheduleManager {\n private readonly deltaScheduler: DeltaScheduler;\n private batchClientId: string | undefined;\n private hitError = false;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly emitter: EventEmitter,\n private readonly logger: ITelemetryLogger,\n ) {\n this.deltaScheduler = new DeltaScheduler(\n this.deltaManager,\n ChildLogger.create(this.logger, \"DeltaScheduler\"),\n );\n void new ScheduleManagerCore(deltaManager, logger);\n }\n\n public beforeOpProcessing(message: ISequencedDocumentMessage) {\n if (this.batchClientId !== message.clientId) {\n assert(this.batchClientId === undefined,\n 0x2a2 /* \"Batch is interrupted by other client op. Should be caught by trackPending()\" */);\n\n // This could be the beginning of a new batch or an individual message.\n this.emitter.emit(\"batchBegin\", message);\n this.deltaScheduler.batchBegin(message);\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n if (batch) {\n this.batchClientId = message.clientId;\n } else {\n this.batchClientId = undefined;\n }\n }\n }\n\n public afterOpProcessing(error: any | undefined, message: ISequencedDocumentMessage) {\n // If this is no longer true, we need to revisit what we do where we set this.hitError.\n assert(!this.hitError, 0x2a3 /* \"container should be closed on any error\" */);\n\n if (error) {\n // We assume here that loader will close container and stop processing all future ops.\n // This is implicit dependency. If this flow changes, this code might no longer be correct.\n this.hitError = true;\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", error, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n\n const batch = (message?.metadata as IRuntimeMessageMetadata)?.batch;\n // If no batchClientId has been set then we're in an individual batch. Else, if we get\n // batch end metadata, this is end of the current batch.\n if (this.batchClientId === undefined || batch === false) {\n this.batchClientId = undefined;\n this.emitter.emit(\"batchEnd\", undefined, message);\n this.deltaScheduler.batchEnd(message);\n return;\n }\n }\n}\n\n/**\n * This class controls pausing and resuming of inbound queue to ensure that we never\n * start processing ops in a batch IF we do not have all ops in the batch.\n */\nclass ScheduleManagerCore {\n private pauseSequenceNumber: number | undefined;\n private currentBatchClientId: string | undefined;\n private localPaused = false;\n private timePaused = 0;\n private batchCount = 0;\n\n constructor(\n private readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n private readonly logger: ITelemetryLogger,\n ) {\n // Listen for delta manager sends and add batch metadata to messages\n this.deltaManager.on(\"prepareSend\", (messages: IDocumentMessage[]) => {\n if (messages.length === 0) {\n return;\n }\n\n // First message will have the batch flag set to true if doing a batched send\n const firstMessageMetadata = messages[0].metadata as IRuntimeMessageMetadata;\n if (!firstMessageMetadata?.batch) {\n return;\n }\n\n // If the batch contains only a single op, clear the batch flag.\n if (messages.length === 1) {\n delete firstMessageMetadata.batch;\n return;\n }\n\n // Set the batch flag to false on the last message to indicate the end of the send batch\n const lastMessage = messages[messages.length - 1];\n lastMessage.metadata = { ...lastMessage.metadata, batch: false };\n });\n\n // Listen for updates and peek at the inbound\n this.deltaManager.inbound.on(\n \"push\",\n (message: ISequencedDocumentMessage) => {\n this.trackPending(message);\n });\n\n // Start with baseline - empty inbound queue.\n assert(!this.localPaused, 0x293 /* \"initial state\" */);\n\n const allPending = this.deltaManager.inbound.toArray();\n for (const pending of allPending) {\n this.trackPending(pending);\n }\n\n // We are intentionally directly listening to the \"op\" to inspect system ops as well.\n // If we do not observe system ops, we are likely to hit 0x296 assert when system ops\n // precedes start of incomplete batch.\n this.deltaManager.on(\"op\", (message) => this.afterOpProcessing(message.sequenceNumber));\n }\n\n /**\n * The only public function in this class - called when we processed an op,\n * to make decision if op processing should be paused or not after that.\n */\n public afterOpProcessing(sequenceNumber: number) {\n assert(!this.localPaused, 0x294 /* \"can't have op processing paused if we are processing an op\" */);\n\n // If the inbound queue is ever empty, nothing to do!\n if (this.deltaManager.inbound.length === 0) {\n assert(this.pauseSequenceNumber === undefined,\n 0x295 /* \"there should be no pending batch if we have no ops\" */);\n return;\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - here (processing ops until reaching start of incomplete batch)\n // - in trackPending(), when queue was empty and start of batch showed up.\n // 2. resumed when batch end comes in (in trackPending())\n\n // do we have incomplete batch to worry about?\n if (this.pauseSequenceNumber !== undefined) {\n assert(sequenceNumber < this.pauseSequenceNumber,\n 0x296 /* \"we should never start processing incomplete batch!\" */);\n // If the next op is the start of incomplete batch, then we can't process it until it's fully in - pause!\n if (sequenceNumber + 1 === this.pauseSequenceNumber) {\n this.pauseQueue();\n }\n }\n }\n\n private pauseQueue() {\n assert(!this.localPaused, 0x297 /* \"always called from resumed state\" */);\n this.localPaused = true;\n this.timePaused = performance.now();\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this.deltaManager.inbound.pause();\n }\n\n private resumeQueue(startBatch: number, messageEndBatch: ISequencedDocumentMessage) {\n const endBatch = messageEndBatch.sequenceNumber;\n const duration = this.localPaused ? (performance.now() - this.timePaused) : undefined;\n\n this.batchCount++;\n if (this.batchCount % 1000 === 1) {\n this.logger.sendTelemetryEvent({\n eventName: \"BatchStats\",\n sequenceNumber: endBatch,\n length: endBatch - startBatch + 1,\n msnDistance: endBatch - messageEndBatch.minimumSequenceNumber,\n duration,\n batchCount: this.batchCount,\n interrupted: this.localPaused,\n });\n }\n\n // Return early if no change in value\n if (!this.localPaused) {\n return;\n }\n\n this.localPaused = false;\n\n // Random round number - we want to know when batch waiting paused op processing.\n if (duration !== undefined && duration > latencyThreshold) {\n this.logger.sendErrorEvent({\n eventName: \"MaxBatchWaitTimeExceeded\",\n duration,\n sequenceNumber: endBatch,\n length: endBatch - startBatch,\n });\n }\n this.deltaManager.inbound.resume();\n }\n\n /**\n * Called for each incoming op (i.e. inbound \"push\" notification)\n */\n private trackPending(message: ISequencedDocumentMessage) {\n assert(this.deltaManager.inbound.length !== 0,\n 0x298 /* \"we have something in the queue that generates this event\" */);\n\n assert((this.currentBatchClientId === undefined) === (this.pauseSequenceNumber === undefined),\n 0x299 /* \"non-synchronized state\" */);\n\n const metadata = message.metadata as IRuntimeMessageMetadata;\n const batchMetadata = metadata?.batch;\n\n // Protocol messages are never part of a runtime batch of messages\n if (!isUnpackedRuntimeMessage(message)) {\n // Protocol messages should never show up in the middle of the batch!\n assert(this.currentBatchClientId === undefined, 0x29a /* \"System message in the middle of batch!\" */);\n assert(batchMetadata === undefined, 0x29b /* \"system op in a batch?\" */);\n assert(!this.localPaused, 0x29c /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n if (this.currentBatchClientId === undefined && batchMetadata === undefined) {\n assert(!this.localPaused, 0x29d /* \"we should be processing ops when there is no active batch\" */);\n return;\n }\n\n // If the client ID changes then we can move the pause point. If it stayed the same then we need to check.\n // If batchMetadata is not undefined then if it's true we've begun a new batch - if false we've ended\n // the previous one\n if (this.currentBatchClientId !== undefined || batchMetadata === false) {\n if (this.currentBatchClientId !== message.clientId) {\n // \"Batch not closed, yet message from another client!\"\n throw new DataCorruptionError(\n \"OpBatchIncomplete\",\n {\n runtimeVersion: pkgVersion,\n batchClientId: this.currentBatchClientId,\n ...extractSafePropertiesFromMessage(message),\n });\n }\n }\n\n // The queue is\n // 1. paused only when the next message to be processed is the beginning of a batch. Done in two places:\n // - in afterOpProcessing() - processing ops until reaching start of incomplete batch\n // - here (batchMetadata == false below), when queue was empty and start of batch showed up.\n // 2. resumed when batch end comes in (batchMetadata === true case below)\n\n if (batchMetadata) {\n assert(this.currentBatchClientId === undefined, 0x29e /* \"there can't be active batch\" */);\n assert(!this.localPaused, 0x29f /* \"we should be processing ops when there is no active batch\" */);\n this.pauseSequenceNumber = message.sequenceNumber;\n this.currentBatchClientId = message.clientId;\n // Start of the batch\n // Only pause processing if queue has no other ops!\n // If there are any other ops in the queue, processing will be stopped when they are processed!\n if (this.deltaManager.inbound.length === 1) {\n this.pauseQueue();\n }\n } else if (batchMetadata === false) {\n assert(this.pauseSequenceNumber !== undefined, 0x2a0 /* \"batch presence was validated above\" */);\n // Batch is complete, we can process it!\n this.resumeQueue(this.pauseSequenceNumber, message);\n this.pauseSequenceNumber = undefined;\n this.currentBatchClientId = undefined;\n } else {\n // Continuation of current batch. Do nothing\n assert(this.currentBatchClientId !== undefined, 0x2a1 /* \"logic error\" */);\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"summarizer.d.ts","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,OAAO,EAAgB,MAAM,uCAAuC,CAAC;AAI9E,OAAO,EAAe,eAAe,EAAE,YAAY,EAAmB,MAAM,iCAAiC,CAAC;AAC9G,OAAO,EAEH,mBAAmB,EACnB,YAAY,EAEf,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EACH,WAAW,EACX,4BAA4B,EAC5B,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,mBAAmB,EAAE,MAAM,GAAG,CAAC;AAIxC,qBAAa,kBAAmB,SAAQ,YAAa,YAAW,mBAAmB,EAAE,eAAe;IAM5F,QAAQ,CAAC,MAAM,EAAE,OAAO;IAL5B,QAAQ,CAAC,SAAS,sBAAoB;IACtC,QAAQ,CAAC,QAAQ,QAAQ;gBAGrB,YAAY,EAAE,MAAM,EACX,MAAM,GAAE,OAAe;IAKpC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,qBAAiB,EAAE,MAAM,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;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,oBAAoB;IAIjC,KAAK;YAOE,OAAO;IAgDrB;;;;;OAKG;WACW,2BAA2B,CAAC,UAAU,EAAE,oBAAoB,GAAG,OAAO;IAIpF;;;;;;;;OAQG;YACW,KAAK;IA8DnB;;;;;OAKG;IACI,OAAO;IAWd,SAAgB,iBAAiB,EAAE,WAAW,CAAC,mBAAmB,CAAC,CA+CjE;IAEF,SAAgB,gBAAgB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAK/D;YAEY,iBAAiB;CAqDlC"}
package/lib/summarizer.js CHANGED
@@ -6,9 +6,9 @@ import { EventEmitter } from "events";
6
6
  import { Deferred } from "@fluidframework/common-utils";
7
7
  import { LoaderHeader } from "@fluidframework/container-definitions";
8
8
  import { UsageError } from "@fluidframework/container-utils";
9
- import { DriverHeader } from "@fluidframework/driver-definitions";
9
+ import { DriverErrorType, DriverHeader } from "@fluidframework/driver-definitions";
10
10
  import { requestFluidObject } from "@fluidframework/runtime-utils";
11
- import { ChildLogger, LoggingError, wrapErrorAndLog } from "@fluidframework/telemetry-utils";
11
+ import { ChildLogger, isFluidError, LoggingError, wrapErrorAndLog, } from "@fluidframework/telemetry-utils";
12
12
  import { summarizerClientType } from "./summarizerClientElection";
13
13
  import { SummarizerHandle } from "./summarizerHandle";
14
14
  import { RunningSummarizer } from "./runningSummarizer";
@@ -279,19 +279,49 @@ export class Summarizer extends EventEmitter {
279
279
  }
280
280
  }
281
281
  async handleSummaryAcks() {
282
- var _a;
282
+ var _a, _b, _c, _d, _e;
283
283
  let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;
284
+ let ack;
284
285
  while (this.runningSummarizer) {
285
286
  const summaryLogger = (_a = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber)) !== null && _a !== void 0 ? _a : this.logger;
286
287
  try {
287
- const ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);
288
+ // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,
289
+ // we record undefined, not previous handles.
290
+ ack = undefined;
291
+ ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);
288
292
  refSequenceNumber = ack.summaryOp.referenceSequenceNumber;
289
- await this.internalsProvider.refreshLatestSummaryAck(ack.summaryOp.contents.handle, ack.summaryAck.contents.handle, refSequenceNumber, summaryLogger);
293
+ const summaryOpHandle = ack.summaryOp.contents.handle;
294
+ const summaryAckHandle = ack.summaryAck.contents.handle;
295
+ // Make sure we block any summarizer from being executed/enqueued while
296
+ // executing the refreshLatestSummaryAck.
297
+ // https://dev.azure.com/fluidframework/internal/_workitems/edit/779
298
+ await this.runningSummarizer.lockedRefreshSummaryAckAction(async () => this.internalsProvider.refreshLatestSummaryAck(summaryOpHandle, summaryAckHandle, refSequenceNumber, summaryLogger).catch(async (error) => {
299
+ // If the error is 404, so maybe the fetched version no longer exists on server. We just
300
+ // ignore this error in that case, as that means we will have another summaryAck for the
301
+ // latest version with which we will refresh the state. However in case of single commit
302
+ // summary, we might me missing a summary ack, so in that case we are still fine as the
303
+ // code in `submitSummary` function in container runtime, will refresh the latest state
304
+ // by calling `refreshLatestSummaryAckFromServer` and we will be fine.
305
+ if (isFluidError(error)
306
+ && error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError) {
307
+ summaryLogger.sendTelemetryEvent({
308
+ eventName: "HandleSummaryAckErrorIgnored",
309
+ referenceSequenceNumber: refSequenceNumber,
310
+ proposalHandle: summaryOpHandle,
311
+ ackHandle: summaryAckHandle,
312
+ }, error);
313
+ }
314
+ else {
315
+ throw error;
316
+ }
317
+ }));
290
318
  }
291
319
  catch (error) {
292
320
  summaryLogger.sendErrorEvent({
293
321
  eventName: "HandleSummaryAckError",
294
322
  referenceSequenceNumber: refSequenceNumber,
323
+ handle: (_c = (_b = ack === null || ack === void 0 ? void 0 : ack.summaryOp) === null || _b === void 0 ? void 0 : _b.contents) === null || _c === void 0 ? void 0 : _c.handle,
324
+ ackHandle: (_e = (_d = ack === null || ack === void 0 ? void 0 : ack.summaryAck) === null || _d === void 0 ? void 0 : _d.contents) === null || _e === void 0 ? void 0 : _e.handle,
295
325
  }, error);
296
326
  }
297
327
  refSequenceNumber++;
@@ -1 +1 @@
1
- {"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAW,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAmB,YAAY,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAS9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAIhD,YACI,YAAoB,EACX,SAAkB,KAAK;QAEhC,KAAK,CAAC,YAAY,CAAC,CAAC;QAFX,WAAM,GAAN,MAAM,CAAiB;QAL3B,cAAS,GAAG,gBAAgB,CAAC;QAC7B,aAAQ,GAAG,IAAI,CAAC;IAOzB,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,KAAU,EAAE,SAAkB,KAAK,EAAE,MAAwB;QACrE,MAAM,UAAU,GAAG,CAAC,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B,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,mCAAI,IAAI,CAAC,MAAM,CAAC;YACtG,IAAI;gBACA,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;gBAC3E,iBAAiB,GAAG,GAAG,CAAC,SAAS,CAAC,uBAAuB,CAAC;gBAE1D,MAAM,IAAI,CAAC,iBAAiB,CAAC,uBAAuB,CAChD,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAC7B,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,EAC9B,iBAAiB,EACjB,aAAa,CAChB,CAAC;aACL;YAAC,OAAO,KAAK,EAAE;gBACZ,aAAa,CAAC,cAAc,CAAC;oBACzB,SAAS,EAAE,uBAAuB;oBAClC,uBAAuB,EAAE,iBAAiB;iBAC7C,EAAE,KAAK,CAAC,CAAC;aACb;YACD,iBAAiB,EAAE,CAAC;SACvB;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ILoader, LoaderHeader } from \"@fluidframework/container-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { DriverHeader } from \"@fluidframework/driver-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, IFluidErrorBase, LoggingError, wrapErrorAndLog } from \"@fluidframework/telemetry-utils\";\nimport {\n FluidObject,\n IFluidHandleContext,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport { ISummaryConfiguration } from \"./containerRuntime\";\nimport { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { SummaryCollection } from \"./summaryCollection\";\nimport { SummarizerHandle } from \"./summarizerHandle\";\nimport { RunningSummarizer } from \"./runningSummarizer\";\nimport {\n ISummarizer,\n ISummarizerInternalsProvider,\n ISummarizerRuntime,\n ISummarizingWarning,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics\";\nimport { SummarizeResultBuilder } from \"./summaryGenerator\";\nimport { IConnectableRuntime } from \".\";\n\nconst summarizingError = \"summarizingError\";\n\nexport class SummarizingWarning extends LoggingError implements ISummarizingWarning, IFluidErrorBase {\n readonly errorType = summarizingError;\n readonly canRetry = true;\n\n constructor(\n errorMessage: string,\n readonly logged: boolean = false,\n ) {\n super(errorMessage);\n }\n\n static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {\n const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);\n return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n }\n}\n\nexport const createSummarizingWarning =\n (errorMessage: string, logged: boolean) => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n */\nexport class Summarizer extends EventEmitter implements ISummarizer {\n public get IFluidLoadable() { return this; }\n public get ISummarizer() { return this; }\n\n private readonly logger: ITelemetryLogger;\n private runningSummarizer?: RunningSummarizer;\n private _disposed: boolean = false;\n private starting: boolean = false;\n\n private readonly innerHandle: IFluidHandle<this>;\n\n public get handle(): IFluidHandle<this> { return this.innerHandle; }\n private readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n constructor(\n url: string,\n /** Reference to runtime that created this object.\n * i.e. runtime with clientType === \"summarizer\"\n */\n private readonly runtime: ISummarizerRuntime,\n private readonly configurationGetter: () => ISummaryConfiguration,\n /** Represents an object that can generate summary.\n * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n */\n private readonly internalsProvider: ISummarizerInternalsProvider,\n handleContext: IFluidHandleContext,\n public readonly summaryCollection: SummaryCollection,\n private readonly runCoordinatorCreateFn:\n (runtime: IConnectableRuntime) => Promise<ICancellableSummarizerController>,\n ) {\n super();\n this.logger = ChildLogger.create(this.runtime.logger, \"Summarizer\");\n this.innerHandle = new SummarizerHandle(this, url, handleContext);\n }\n\n /**\n * Creates a Summarizer and its underlying client.\n * Note that different implementations of ILoader will handle the URL differently.\n * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's\n * starting with \"/\" as relative to the Container. The general ILoader\n * interface will expect an absolute URL and will not handle \"/\".\n * @param loader - the loader that resolves the request\n * @param url - the URL used to resolve the container\n */\n public static async create(\n loader: ILoader,\n url: string): Promise<ISummarizer> {\n const request: IRequest = {\n headers: {\n [LoaderHeader.cache]: false,\n [LoaderHeader.clientDetails]: {\n capabilities: { interactive: false },\n type: summarizerClientType,\n },\n [DriverHeader.summarizingClient]: true,\n [LoaderHeader.reconnect]: false,\n },\n url,\n };\n\n const resolvedContainer = await loader.resolve(request);\n const fluidObject =\n await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, { url: \"_summarizer\" });\n if (fluidObject.ISummarizer === undefined) {\n throw new UsageError(\"Fluid object does not implement ISummarizer\");\n }\n return fluidObject.ISummarizer;\n }\n\n public async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n try {\n return await this.runCore(onBehalfOf);\n } catch (error) {\n this.stop(\"summarizerException\");\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n } finally {\n this.close();\n }\n }\n\n /**\n * Stops the summarizer from running. This will complete\n * the run promise, and also close the container.\n * @param reason - reason code for stopping\n */\n public stop(reason: SummarizerStopReason) {\n this.stopDeferred.resolve(reason);\n }\n\n public close() {\n // This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n // unless stop() was called earlier\n this.dispose();\n this.runtime.closeFn();\n }\n\n private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(this.runtime);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n void stopP.then((reason) => {\n this.logger.sendTelemetryEvent({\n eventName: \"StoppingSummarizer\",\n onBehalfOf,\n reason,\n });\n });\n\n if (runCoordinator.cancelled) {\n return runCoordinator.waitCancelled;\n }\n\n const runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopReason = await stopP;\n\n // There are two possible approaches here:\n // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n // faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n // The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n // In general, it's more wasted resources.\n // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n // substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n // conflict with new summarizer client starting on different client.\n // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n // cons of #2 substantially.\n\n // Cleanup after running\n await runningSummarizer.waitStop(\n !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));\n\n // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n runCoordinator.stop(stopReason);\n\n return stopReason;\n }\n\n /**\n * Should we try to run a last summary for the given stop reason?\n * Currently only allows \"parentNotConnected\"\n * @param stopReason - SummarizerStopReason\n * @returns - true if the stop reason can run a last summary\n */\n public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n return stopReason === \"parentNotConnected\";\n }\n\n /**\n * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n * (in the on-demand case).\n * @param onBehalfOf - ID of the client that requested that the summarizer start\n * @param runCoordinator - cancellation token\n * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n * @returns - Promise that is fulfilled when the RunningSummarizer is ready\n */\n private async start(\n onBehalfOf: string,\n runCoordinator: ICancellableSummarizerController): Promise<RunningSummarizer> {\n if (this.runningSummarizer) {\n if (this.runningSummarizer.disposed) {\n throw new UsageError(\"Starting a disposed summarizer\");\n }\n return this.runningSummarizer;\n }\n if (this.starting) {\n throw new UsageError(\"Attempting to start a summarizer that is already starting\");\n }\n this.starting = true;\n // Initialize values and first ack (time is not exact)\n this.logger.sendTelemetryEvent({\n eventName: \"RunningSummarizer\",\n onBehalfOf,\n initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n config: JSON.stringify(this.configurationGetter()),\n });\n\n // Summarizing container ID (with clientType === \"summarizer\")\n const clientId = this.runtime.clientId;\n if (clientId === undefined) {\n throw new UsageError(\"clientId should be defined if connected.\");\n }\n\n const runningSummarizer = await RunningSummarizer.start(\n this.logger,\n this.summaryCollection.createWatcher(clientId),\n this.configurationGetter(),\n async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n new SummarizeHeuristicData(\n this.runtime.deltaManager.lastSequenceNumber,\n { /** summary attempt baseline for heuristics */\n refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n summaryTime: Date.now(),\n } as const,\n ),\n (errorMessage: string) => {\n if (!this._disposed) {\n this.logger.sendErrorEvent({ eventName: \"summarizingError\" },\n createSummarizingWarning(errorMessage, true));\n }\n },\n this.summaryCollection,\n runCoordinator /* cancellationToken */,\n (reason) => runCoordinator.stop(reason), /* stopSummarizerCallback */\n this.runtime,\n );\n this.runningSummarizer = runningSummarizer;\n this.starting = false;\n\n // Handle summary acks\n // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions\n this.handleSummaryAcks().catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"HandleSummaryAckFatalError\" }, error);\n });\n\n return runningSummarizer;\n }\n\n /**\n * Disposes of resources after running. This cleanup will\n * clear any outstanding timers and reset some of the state\n * properties.\n * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n */\n public dispose() {\n // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n this.stop(\"summarizerClientDisconnected\");\n\n this._disposed = true;\n if (this.runningSummarizer) {\n this.runningSummarizer.dispose();\n this.runningSummarizer = undefined;\n }\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n try {\n if (this._disposed || this.runningSummarizer?.disposed) {\n throw new UsageError(\"Summarizer is already disposed.\");\n }\n if (this.runtime.summarizerClientId !== undefined &&\n this.runtime.summarizerClientId !== this.runtime.clientId) {\n // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n // This is to prevent the on-demand summary and heuristic-based summary from stepping on\n // each other.\n throw new UsageError(\"On-demand summary attempted while an elected summarizer is present\");\n }\n const builder = new SummarizeResultBuilder();\n if (this.runningSummarizer) {\n // Summarizer is already running. Go ahead and start.\n return this.runningSummarizer.summarizeOnDemand(builder, ...args);\n }\n\n // Summarizer isn't running, so we need to start it, which is an async operation.\n // Manage the promise related to creating the cancellation token here.\n // The promises related to starting, summarizing,\n // and submitting are communicated to the caller through the results builder.\n const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n coordinatorCreateP.then((runCoordinator) => {\n // Successully created the cancellation token. Start the summarizer.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const startP = this.start(this.runtime.clientId!, runCoordinator);\n startP.then(async (runningSummarizer) => {\n // Successfully started the summarizer. Run it.\n runningSummarizer.summarizeOnDemand(builder, ...args);\n // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n const stopReason = await Promise.race([this.stopDeferred.promise, runCoordinator.waitCancelled]);\n await runningSummarizer.waitStop(false);\n runCoordinator.stop(stopReason);\n this.close();\n }).catch((reason) => {\n builder.fail(\"Failed to start summarizer\", reason);\n });\n }).catch((reason) => {\n builder.fail(\"Failed to create cancellation token\", reason);\n });\n\n return builder.build();\n } catch (error) {\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n }\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this._disposed || this.runningSummarizer === undefined || this.runningSummarizer.disposed) {\n throw new UsageError(\"Summarizer is not running or already disposed.\");\n }\n return this.runningSummarizer.enqueueSummarize(...args);\n };\n\n private async handleSummaryAcks() {\n let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;\n while (this.runningSummarizer) {\n const summaryLogger = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;\n try {\n const ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);\n refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n\n await this.internalsProvider.refreshLatestSummaryAck(\n ack.summaryOp.contents.handle,\n ack.summaryAck.contents.handle,\n refSequenceNumber,\n summaryLogger,\n );\n } catch (error) {\n summaryLogger.sendErrorEvent({\n eventName: \"HandleSummaryAckError\",\n referenceSequenceNumber: refSequenceNumber,\n }, error);\n }\n refSequenceNumber++;\n }\n }\n}\n"]}
1
+ {"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../src/summarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,OAAO,EAAW,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EACH,WAAW,EAEX,YAAY,EACZ,YAAY,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AAC,KAAK,IAAI,EAAE,CAClE,IAAI,CAAC,iBAAiB,CAAC,uBAAuB,CAC1C,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,CAChB,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;oBACpB,wFAAwF;oBACxF,wFAAwF;oBACxF,wFAAwF;oBACxF,uFAAuF;oBACvF,uFAAuF;oBACvF,sEAAsE;oBACtE,IAAI,YAAY,CAAC,KAAK,CAAC;2BAChB,KAAK,CAAC,SAAS,KAAK,eAAe,CAAC,+BAA+B,EAAE;wBACxE,aAAa,CAAC,kBAAkB,CAAC;4BAC7B,SAAS,EAAE,8BAA8B;4BACzC,uBAAuB,EAAE,iBAAiB;4BAC1C,cAAc,EAAE,eAAe;4BAC/B,SAAS,EAAE,gBAAgB;yBAC9B,EAAE,KAAK,CAAC,CAAC;qBACb;yBAAM;wBACH,MAAM,KAAK,CAAC;qBACf;gBACL,CAAC,CAAC,CACL,CAAC;aACL;YAAC,OAAO,KAAK,EAAE;gBACZ,aAAa,CAAC,cAAc,CAAC;oBACzB,SAAS,EAAE,uBAAuB;oBAClC,uBAAuB,EAAE,iBAAiB;oBAC1C,MAAM,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,SAAS,0CAAE,QAAQ,0CAAE,MAAM;oBACxC,SAAS,EAAE,MAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,UAAU,0CAAE,QAAQ,0CAAE,MAAM;iBAC/C,EAAE,KAAK,CAAC,CAAC;aACb;YACD,iBAAiB,EAAE,CAAC;SACvB;IACL,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { EventEmitter } from \"events\";\nimport { Deferred } from \"@fluidframework/common-utils\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ILoader, LoaderHeader } from \"@fluidframework/container-definitions\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport { DriverErrorType, DriverHeader } from \"@fluidframework/driver-definitions\";\nimport { requestFluidObject } from \"@fluidframework/runtime-utils\";\nimport {\n ChildLogger,\n IFluidErrorBase,\n isFluidError,\n LoggingError,\n wrapErrorAndLog,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n FluidObject,\n IFluidHandleContext,\n IFluidHandle,\n IRequest,\n} from \"@fluidframework/core-interfaces\";\nimport { ISummaryConfiguration } from \"./containerRuntime\";\nimport { ICancellableSummarizerController } from \"./runWhileConnectedCoordinator\";\nimport { summarizerClientType } from \"./summarizerClientElection\";\nimport { IAckedSummary, SummaryCollection } from \"./summaryCollection\";\nimport { SummarizerHandle } from \"./summarizerHandle\";\nimport { RunningSummarizer } from \"./runningSummarizer\";\nimport {\n ISummarizer,\n ISummarizerInternalsProvider,\n ISummarizerRuntime,\n ISummarizingWarning,\n SummarizerStopReason,\n} from \"./summarizerTypes\";\nimport { SummarizeHeuristicData } from \"./summarizerHeuristics\";\nimport { SummarizeResultBuilder } from \"./summaryGenerator\";\nimport { IConnectableRuntime } from \".\";\n\nconst summarizingError = \"summarizingError\";\n\nexport class SummarizingWarning extends LoggingError implements ISummarizingWarning, IFluidErrorBase {\n readonly errorType = summarizingError;\n readonly canRetry = true;\n\n constructor(\n errorMessage: string,\n readonly logged: boolean = false,\n ) {\n super(errorMessage);\n }\n\n static wrap(error: any, logged: boolean = false, logger: ITelemetryLogger) {\n const newErrorFn = (errMsg: string) => new SummarizingWarning(errMsg, logged);\n return wrapErrorAndLog<SummarizingWarning>(error, newErrorFn, logger);\n }\n}\n\nexport const createSummarizingWarning =\n (errorMessage: string, logged: boolean) => new SummarizingWarning(errorMessage, logged);\n\n/**\n * Summarizer is responsible for coordinating when to generate and send summaries.\n * It is the main entry point for summary work.\n * It is created only by summarizing container (i.e. one with clientType === \"summarizer\")\n */\nexport class Summarizer extends EventEmitter implements ISummarizer {\n public get IFluidLoadable() { return this; }\n public get ISummarizer() { return this; }\n\n private readonly logger: ITelemetryLogger;\n private runningSummarizer?: RunningSummarizer;\n private _disposed: boolean = false;\n private starting: boolean = false;\n\n private readonly innerHandle: IFluidHandle<this>;\n\n public get handle(): IFluidHandle<this> { return this.innerHandle; }\n private readonly stopDeferred = new Deferred<SummarizerStopReason>();\n\n constructor(\n url: string,\n /** Reference to runtime that created this object.\n * i.e. runtime with clientType === \"summarizer\"\n */\n private readonly runtime: ISummarizerRuntime,\n private readonly configurationGetter: () => ISummaryConfiguration,\n /** Represents an object that can generate summary.\n * In practical terms, it's same runtime (this.runtime) with clientType === \"summarizer\".\n */\n private readonly internalsProvider: ISummarizerInternalsProvider,\n handleContext: IFluidHandleContext,\n public readonly summaryCollection: SummaryCollection,\n private readonly runCoordinatorCreateFn:\n (runtime: IConnectableRuntime) => Promise<ICancellableSummarizerController>,\n ) {\n super();\n this.logger = ChildLogger.create(this.runtime.logger, \"Summarizer\");\n this.innerHandle = new SummarizerHandle(this, url, handleContext);\n }\n\n /**\n * Creates a Summarizer and its underlying client.\n * Note that different implementations of ILoader will handle the URL differently.\n * ILoader provided by a ContainerRuntime is a RelativeLoader, which will treat URL's\n * starting with \"/\" as relative to the Container. The general ILoader\n * interface will expect an absolute URL and will not handle \"/\".\n * @param loader - the loader that resolves the request\n * @param url - the URL used to resolve the container\n */\n public static async create(\n loader: ILoader,\n url: string): Promise<ISummarizer> {\n const request: IRequest = {\n headers: {\n [LoaderHeader.cache]: false,\n [LoaderHeader.clientDetails]: {\n capabilities: { interactive: false },\n type: summarizerClientType,\n },\n [DriverHeader.summarizingClient]: true,\n [LoaderHeader.reconnect]: false,\n },\n url,\n };\n\n const resolvedContainer = await loader.resolve(request);\n const fluidObject =\n await requestFluidObject<FluidObject<ISummarizer>>(resolvedContainer, { url: \"_summarizer\" });\n if (fluidObject.ISummarizer === undefined) {\n throw new UsageError(\"Fluid object does not implement ISummarizer\");\n }\n return fluidObject.ISummarizer;\n }\n\n public async run(onBehalfOf: string): Promise<SummarizerStopReason> {\n try {\n return await this.runCore(onBehalfOf);\n } catch (error) {\n this.stop(\"summarizerException\");\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n } finally {\n this.close();\n }\n }\n\n /**\n * Stops the summarizer from running. This will complete\n * the run promise, and also close the container.\n * @param reason - reason code for stopping\n */\n public stop(reason: SummarizerStopReason) {\n this.stopDeferred.resolve(reason);\n }\n\n public close() {\n // This will result in \"summarizerClientDisconnected\" stop reason recorded in telemetry,\n // unless stop() was called earlier\n this.dispose();\n this.runtime.closeFn();\n }\n\n private async runCore(onBehalfOf: string): Promise<SummarizerStopReason> {\n const runCoordinator: ICancellableSummarizerController = await this.runCoordinatorCreateFn(this.runtime);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopP = Promise.race([runCoordinator.waitCancelled, this.stopDeferred.promise]);\n void stopP.then((reason) => {\n this.logger.sendTelemetryEvent({\n eventName: \"StoppingSummarizer\",\n onBehalfOf,\n reason,\n });\n });\n\n if (runCoordinator.cancelled) {\n return runCoordinator.waitCancelled;\n }\n\n const runningSummarizer = await this.start(onBehalfOf, runCoordinator);\n\n // Wait for either external signal to cancel, or loss of connectivity.\n const stopReason = await stopP;\n\n // There are two possible approaches here:\n // 1. Propagate cancellation from this.stopDeferred to runCoordinator. This will ensure that we move to the exit\n // faster, including breaking out of the RunningSummarizer.trySummarize() faster.\n // We could create new coordinator and pass it to waitStop() -> trySummarizeOnce(\"lastSummary\") flow.\n // The con of this approach is that we might cancel active summary, and lastSummary will fail because it\n // did not wait for ack/nack from previous summary. Plus we disregard any 429 kind of info from service\n // that way (i.e. trySummarize() loop might have been waiting for 5 min because storage told us so).\n // In general, it's more wasted resources.\n // 2. We can not do it and make waitStop() do last summary only if there was no active summary. This ensures\n // that client behaves properly (from server POV) and we do not waste resources. But, it may mean we wait\n // substantially longer for trySummarize() retries to play out and thus this summary loop may run into\n // conflict with new summarizer client starting on different client.\n // As of now, #2 is implemented. It's more forward looking, as issue #7279 suggests changing design for new\n // summarizer client to not be created until current summarizer fully moves to exit, and that would reduce\n // cons of #2 substantially.\n\n // Cleanup after running\n await runningSummarizer.waitStop(\n !runCoordinator.cancelled && Summarizer.stopReasonCanRunLastSummary(stopReason));\n\n // Propagate reason and ensure that if someone is waiting for cancellation token, they are moving to exit\n runCoordinator.stop(stopReason);\n\n return stopReason;\n }\n\n /**\n * Should we try to run a last summary for the given stop reason?\n * Currently only allows \"parentNotConnected\"\n * @param stopReason - SummarizerStopReason\n * @returns - true if the stop reason can run a last summary\n */\n public static stopReasonCanRunLastSummary(stopReason: SummarizerStopReason): boolean {\n return stopReason === \"parentNotConnected\";\n }\n\n /**\n * Put the summarizer in a started state, including creating and initializing the RunningSummarizer.\n * The start request can come either from the SummaryManager (in the auto-summarize case) or from the user\n * (in the on-demand case).\n * @param onBehalfOf - ID of the client that requested that the summarizer start\n * @param runCoordinator - cancellation token\n * @param newConfig - Summary configuration to override the existing config when invoking the RunningSummarizer.\n * @returns - Promise that is fulfilled when the RunningSummarizer is ready\n */\n private async start(\n onBehalfOf: string,\n runCoordinator: ICancellableSummarizerController): Promise<RunningSummarizer> {\n if (this.runningSummarizer) {\n if (this.runningSummarizer.disposed) {\n throw new UsageError(\"Starting a disposed summarizer\");\n }\n return this.runningSummarizer;\n }\n if (this.starting) {\n throw new UsageError(\"Attempting to start a summarizer that is already starting\");\n }\n this.starting = true;\n // Initialize values and first ack (time is not exact)\n this.logger.sendTelemetryEvent({\n eventName: \"RunningSummarizer\",\n onBehalfOf,\n initSummarySeqNumber: this.runtime.deltaManager.initialSequenceNumber,\n config: JSON.stringify(this.configurationGetter()),\n });\n\n // Summarizing container ID (with clientType === \"summarizer\")\n const clientId = this.runtime.clientId;\n if (clientId === undefined) {\n throw new UsageError(\"clientId should be defined if connected.\");\n }\n\n const runningSummarizer = await RunningSummarizer.start(\n this.logger,\n this.summaryCollection.createWatcher(clientId),\n this.configurationGetter(),\n async (...args) => this.internalsProvider.submitSummary(...args), // submitSummaryCallback\n new SummarizeHeuristicData(\n this.runtime.deltaManager.lastSequenceNumber,\n { /** summary attempt baseline for heuristics */\n refSequenceNumber: this.runtime.deltaManager.initialSequenceNumber,\n summaryTime: Date.now(),\n } as const,\n ),\n (errorMessage: string) => {\n if (!this._disposed) {\n this.logger.sendErrorEvent({ eventName: \"summarizingError\" },\n createSummarizingWarning(errorMessage, true));\n }\n },\n this.summaryCollection,\n runCoordinator /* cancellationToken */,\n (reason) => runCoordinator.stop(reason), /* stopSummarizerCallback */\n this.runtime,\n );\n this.runningSummarizer = runningSummarizer;\n this.starting = false;\n\n // Handle summary acks\n // Note: no exceptions are thrown from handleSummaryAcks handler as it handles all exceptions\n this.handleSummaryAcks().catch((error) => {\n this.logger.sendErrorEvent({ eventName: \"HandleSummaryAckFatalError\" }, error);\n });\n\n return runningSummarizer;\n }\n\n /**\n * Disposes of resources after running. This cleanup will\n * clear any outstanding timers and reset some of the state\n * properties.\n * Called by ContainerRuntime when it is disposed, as well as at the end the run().\n */\n public dispose() {\n // Given that the call can come from own ContainerRuntime, ensure that we stop all the processes.\n this.stop(\"summarizerClientDisconnected\");\n\n this._disposed = true;\n if (this.runningSummarizer) {\n this.runningSummarizer.dispose();\n this.runningSummarizer = undefined;\n }\n }\n\n public readonly summarizeOnDemand: ISummarizer[\"summarizeOnDemand\"] = (...args) => {\n try {\n if (this._disposed || this.runningSummarizer?.disposed) {\n throw new UsageError(\"Summarizer is already disposed.\");\n }\n if (this.runtime.summarizerClientId !== undefined &&\n this.runtime.summarizerClientId !== this.runtime.clientId) {\n // If there is an elected summarizer, and it's not this one, don't allow on-demand summary.\n // This is to prevent the on-demand summary and heuristic-based summary from stepping on\n // each other.\n throw new UsageError(\"On-demand summary attempted while an elected summarizer is present\");\n }\n const builder = new SummarizeResultBuilder();\n if (this.runningSummarizer) {\n // Summarizer is already running. Go ahead and start.\n return this.runningSummarizer.summarizeOnDemand(builder, ...args);\n }\n\n // Summarizer isn't running, so we need to start it, which is an async operation.\n // Manage the promise related to creating the cancellation token here.\n // The promises related to starting, summarizing,\n // and submitting are communicated to the caller through the results builder.\n const coordinatorCreateP = this.runCoordinatorCreateFn(this.runtime);\n\n coordinatorCreateP.then((runCoordinator) => {\n // Successully created the cancellation token. Start the summarizer.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const startP = this.start(this.runtime.clientId!, runCoordinator);\n startP.then(async (runningSummarizer) => {\n // Successfully started the summarizer. Run it.\n runningSummarizer.summarizeOnDemand(builder, ...args);\n // Wait for a command to stop or loss of connectivity before tearing down the summarizer and client.\n const stopReason = await Promise.race([this.stopDeferred.promise, runCoordinator.waitCancelled]);\n await runningSummarizer.waitStop(false);\n runCoordinator.stop(stopReason);\n this.close();\n }).catch((reason) => {\n builder.fail(\"Failed to start summarizer\", reason);\n });\n }).catch((reason) => {\n builder.fail(\"Failed to create cancellation token\", reason);\n });\n\n return builder.build();\n } catch (error) {\n throw SummarizingWarning.wrap(error, false /* logged */, this.logger);\n }\n };\n\n public readonly enqueueSummarize: ISummarizer[\"enqueueSummarize\"] = (...args) => {\n if (this._disposed || this.runningSummarizer === undefined || this.runningSummarizer.disposed) {\n throw new UsageError(\"Summarizer is not running or already disposed.\");\n }\n return this.runningSummarizer.enqueueSummarize(...args);\n };\n\n private async handleSummaryAcks() {\n let refSequenceNumber = this.runtime.deltaManager.initialSequenceNumber;\n let ack: IAckedSummary | undefined;\n while (this.runningSummarizer) {\n const summaryLogger = this.runningSummarizer.tryGetCorrelatedLogger(refSequenceNumber) ?? this.logger;\n try {\n // Initialize ack with undefined if exception happens inside of waitSummaryAck on second iteration,\n // we record undefined, not previous handles.\n ack = undefined;\n ack = await this.summaryCollection.waitSummaryAck(refSequenceNumber);\n refSequenceNumber = ack.summaryOp.referenceSequenceNumber;\n const summaryOpHandle = ack.summaryOp.contents.handle;\n const summaryAckHandle = ack.summaryAck.contents.handle;\n // Make sure we block any summarizer from being executed/enqueued while\n // executing the refreshLatestSummaryAck.\n // https://dev.azure.com/fluidframework/internal/_workitems/edit/779\n await this.runningSummarizer.lockedRefreshSummaryAckAction(async () =>\n this.internalsProvider.refreshLatestSummaryAck(\n summaryOpHandle,\n summaryAckHandle,\n refSequenceNumber,\n summaryLogger,\n ).catch(async (error) => {\n // If the error is 404, so maybe the fetched version no longer exists on server. We just\n // ignore this error in that case, as that means we will have another summaryAck for the\n // latest version with which we will refresh the state. However in case of single commit\n // summary, we might me missing a summary ack, so in that case we are still fine as the\n // code in `submitSummary` function in container runtime, will refresh the latest state\n // by calling `refreshLatestSummaryAckFromServer` and we will be fine.\n if (isFluidError(error)\n && error.errorType === DriverErrorType.fileNotFoundOrAccessDeniedError) {\n summaryLogger.sendTelemetryEvent({\n eventName: \"HandleSummaryAckErrorIgnored\",\n referenceSequenceNumber: refSequenceNumber,\n proposalHandle: summaryOpHandle,\n ackHandle: summaryAckHandle,\n }, error);\n } else {\n throw error;\n }\n }),\n );\n } catch (error) {\n summaryLogger.sendErrorEvent({\n eventName: \"HandleSummaryAckError\",\n referenceSequenceNumber: refSequenceNumber,\n handle: ack?.summaryOp?.contents?.handle,\n ackHandle: ack?.summaryAck?.contents?.handle,\n }, error);\n }\n refSequenceNumber++;\n }\n }\n}\n"]}
@@ -252,7 +252,7 @@ export class SummaryCollection extends TypedEventEmitter {
252
252
  // from. i.e. initialSequenceNumber > summarySequenceNumber.
253
253
  // We really don't care about it for now, since it is older than
254
254
  // the one we loaded from.
255
- if (seq >= this.deltaManager.initialSequenceNumber) {
255
+ if (seq > this.deltaManager.initialSequenceNumber) {
256
256
  // Potential causes for it to be later than our initialSequenceNumber
257
257
  // are that the summaryOp was nacked then acked, double-acked, or
258
258
  // the summarySequenceNumber is incorrect.