@fluidframework/container-runtime 2.0.0-internal.3.0.1 → 2.0.0-internal.3.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.
- package/.eslintrc.js +19 -19
- package/.mocharc.js +2 -2
- package/api-extractor.json +2 -2
- package/dist/batchTracker.d.ts.map +1 -1
- package/dist/batchTracker.js +2 -1
- package/dist/batchTracker.js.map +1 -1
- package/dist/blobManager.d.ts +9 -2
- package/dist/blobManager.d.ts.map +1 -1
- package/dist/blobManager.js +80 -33
- package/dist/blobManager.js.map +1 -1
- package/dist/connectionTelemetry.d.ts.map +1 -1
- package/dist/connectionTelemetry.js +11 -9
- package/dist/connectionTelemetry.js.map +1 -1
- package/dist/containerHandleContext.d.ts.map +1 -1
- package/dist/containerHandleContext.js +3 -1
- package/dist/containerHandleContext.js.map +1 -1
- package/dist/containerRuntime.d.ts +10 -0
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +140 -72
- package/dist/containerRuntime.js.map +1 -1
- package/dist/dataStore.d.ts.map +1 -1
- package/dist/dataStore.js +11 -9
- package/dist/dataStore.js.map +1 -1
- package/dist/dataStoreContext.d.ts +18 -1
- package/dist/dataStoreContext.d.ts.map +1 -1
- package/dist/dataStoreContext.js +66 -15
- package/dist/dataStoreContext.js.map +1 -1
- package/dist/dataStoreContexts.d.ts.map +1 -1
- package/dist/dataStoreContexts.js +7 -3
- package/dist/dataStoreContexts.js.map +1 -1
- package/dist/dataStoreRegistry.d.ts.map +1 -1
- package/dist/dataStoreRegistry.js +3 -1
- package/dist/dataStoreRegistry.js.map +1 -1
- package/dist/dataStores.d.ts +26 -1
- package/dist/dataStores.d.ts.map +1 -1
- package/dist/dataStores.js +103 -18
- package/dist/dataStores.js.map +1 -1
- package/dist/deltaScheduler.d.ts.map +1 -1
- package/dist/deltaScheduler.js +8 -3
- package/dist/deltaScheduler.js.map +1 -1
- package/dist/garbageCollection.d.ts +34 -14
- package/dist/garbageCollection.d.ts.map +1 -1
- package/dist/garbageCollection.js +188 -93
- package/dist/garbageCollection.js.map +1 -1
- package/dist/garbageCollectionConstants.d.ts +3 -0
- package/dist/garbageCollectionConstants.d.ts.map +1 -1
- package/dist/garbageCollectionConstants.js +6 -1
- package/dist/garbageCollectionConstants.js.map +1 -1
- package/dist/garbageCollectionHelpers.d.ts +26 -0
- package/dist/garbageCollectionHelpers.d.ts.map +1 -0
- package/dist/garbageCollectionHelpers.js +45 -0
- package/dist/garbageCollectionHelpers.js.map +1 -0
- package/dist/gcSweepReadyUsageDetection.d.ts +5 -5
- package/dist/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/dist/gcSweepReadyUsageDetection.js +14 -10
- package/dist/gcSweepReadyUsageDetection.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/opLifecycle/batchManager.d.ts +5 -5
- package/dist/opLifecycle/batchManager.d.ts.map +1 -1
- package/dist/opLifecycle/batchManager.js +19 -12
- package/dist/opLifecycle/batchManager.js.map +1 -1
- package/dist/opLifecycle/definitions.d.ts.map +1 -1
- package/dist/opLifecycle/definitions.js.map +1 -1
- package/dist/opLifecycle/index.d.ts.map +1 -1
- package/dist/opLifecycle/index.js.map +1 -1
- package/dist/opLifecycle/opCompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opCompressor.js.map +1 -1
- package/dist/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/dist/opLifecycle/opDecompressor.js +5 -2
- package/dist/opLifecycle/opDecompressor.js.map +1 -1
- package/dist/opLifecycle/opSplitter.d.ts.map +1 -1
- package/dist/opLifecycle/opSplitter.js +4 -1
- package/dist/opLifecycle/opSplitter.js.map +1 -1
- package/dist/opLifecycle/outbox.d.ts.map +1 -1
- package/dist/opLifecycle/outbox.js +19 -17
- package/dist/opLifecycle/outbox.js.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/dist/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/dist/opProperties.d.ts.map +1 -1
- package/dist/opProperties.js +1 -3
- package/dist/opProperties.js.map +1 -1
- package/dist/orderedClientElection.d.ts.map +1 -1
- package/dist/orderedClientElection.js +10 -4
- package/dist/orderedClientElection.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/pendingStateManager.d.ts +7 -0
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +7 -4
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/runWhileConnectedCoordinator.d.ts.map +1 -1
- package/dist/runWhileConnectedCoordinator.js.map +1 -1
- package/dist/runningSummarizer.d.ts.map +1 -1
- package/dist/runningSummarizer.js +34 -21
- package/dist/runningSummarizer.js.map +1 -1
- package/dist/scheduleManager.d.ts.map +1 -1
- package/dist/scheduleManager.js +3 -2
- package/dist/scheduleManager.js.map +1 -1
- package/dist/serializedSnapshotStorage.d.ts +2 -2
- package/dist/serializedSnapshotStorage.d.ts.map +1 -1
- package/dist/serializedSnapshotStorage.js +5 -3
- package/dist/serializedSnapshotStorage.js.map +1 -1
- package/dist/summarizer.d.ts +2 -2
- package/dist/summarizer.d.ts.map +1 -1
- package/dist/summarizer.js +37 -17
- package/dist/summarizer.js.map +1 -1
- package/dist/summarizerClientElection.d.ts.map +1 -1
- package/dist/summarizerClientElection.js.map +1 -1
- package/dist/summarizerHandle.d.ts.map +1 -1
- package/dist/summarizerHandle.js.map +1 -1
- package/dist/summarizerHeuristics.d.ts.map +1 -1
- package/dist/summarizerHeuristics.js +6 -9
- package/dist/summarizerHeuristics.js.map +1 -1
- package/dist/summarizerTypes.d.ts +21 -21
- package/dist/summarizerTypes.d.ts.map +1 -1
- package/dist/summarizerTypes.js.map +1 -1
- package/dist/summaryCollection.d.ts.map +1 -1
- package/dist/summaryCollection.js +18 -8
- package/dist/summaryCollection.js.map +1 -1
- package/dist/summaryFormat.d.ts +22 -0
- package/dist/summaryFormat.d.ts.map +1 -1
- package/dist/summaryFormat.js +18 -10
- package/dist/summaryFormat.js.map +1 -1
- package/dist/summaryGenerator.d.ts.map +1 -1
- package/dist/summaryGenerator.js +34 -15
- package/dist/summaryGenerator.js.map +1 -1
- package/dist/summaryManager.d.ts.map +1 -1
- package/dist/summaryManager.js +21 -9
- package/dist/summaryManager.js.map +1 -1
- package/dist/throttler.d.ts +2 -2
- package/dist/throttler.d.ts.map +1 -1
- package/dist/throttler.js +4 -4
- package/dist/throttler.js.map +1 -1
- package/garbageCollection.md +15 -2
- package/lib/batchTracker.d.ts.map +1 -1
- package/lib/batchTracker.js +2 -1
- package/lib/batchTracker.js.map +1 -1
- package/lib/blobManager.d.ts +9 -2
- package/lib/blobManager.d.ts.map +1 -1
- package/lib/blobManager.js +82 -35
- package/lib/blobManager.js.map +1 -1
- package/lib/connectionTelemetry.d.ts.map +1 -1
- package/lib/connectionTelemetry.js +11 -9
- package/lib/connectionTelemetry.js.map +1 -1
- package/lib/containerHandleContext.d.ts.map +1 -1
- package/lib/containerHandleContext.js +3 -1
- package/lib/containerHandleContext.js.map +1 -1
- package/lib/containerRuntime.d.ts +10 -0
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +146 -78
- package/lib/containerRuntime.js.map +1 -1
- package/lib/dataStore.d.ts.map +1 -1
- package/lib/dataStore.js +11 -9
- package/lib/dataStore.js.map +1 -1
- package/lib/dataStoreContext.d.ts +18 -1
- package/lib/dataStoreContext.d.ts.map +1 -1
- package/lib/dataStoreContext.js +68 -17
- package/lib/dataStoreContext.js.map +1 -1
- package/lib/dataStoreContexts.d.ts.map +1 -1
- package/lib/dataStoreContexts.js +7 -3
- package/lib/dataStoreContexts.js.map +1 -1
- package/lib/dataStoreRegistry.d.ts.map +1 -1
- package/lib/dataStoreRegistry.js +3 -1
- package/lib/dataStoreRegistry.js.map +1 -1
- package/lib/dataStores.d.ts +26 -1
- package/lib/dataStores.d.ts.map +1 -1
- package/lib/dataStores.js +109 -24
- package/lib/dataStores.js.map +1 -1
- package/lib/deltaScheduler.d.ts.map +1 -1
- package/lib/deltaScheduler.js +9 -4
- package/lib/deltaScheduler.js.map +1 -1
- package/lib/garbageCollection.d.ts +34 -14
- package/lib/garbageCollection.d.ts.map +1 -1
- package/lib/garbageCollection.js +190 -95
- package/lib/garbageCollection.js.map +1 -1
- package/lib/garbageCollectionConstants.d.ts +3 -0
- package/lib/garbageCollectionConstants.d.ts.map +1 -1
- package/lib/garbageCollectionConstants.js +5 -0
- package/lib/garbageCollectionConstants.js.map +1 -1
- package/lib/garbageCollectionHelpers.d.ts +26 -0
- package/lib/garbageCollectionHelpers.d.ts.map +1 -0
- package/lib/garbageCollectionHelpers.js +40 -0
- package/lib/garbageCollectionHelpers.js.map +1 -0
- package/lib/gcSweepReadyUsageDetection.d.ts +5 -5
- package/lib/gcSweepReadyUsageDetection.d.ts.map +1 -1
- package/lib/gcSweepReadyUsageDetection.js +14 -10
- package/lib/gcSweepReadyUsageDetection.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/opLifecycle/batchManager.d.ts +5 -5
- package/lib/opLifecycle/batchManager.d.ts.map +1 -1
- package/lib/opLifecycle/batchManager.js +19 -12
- package/lib/opLifecycle/batchManager.js.map +1 -1
- package/lib/opLifecycle/definitions.d.ts.map +1 -1
- package/lib/opLifecycle/definitions.js.map +1 -1
- package/lib/opLifecycle/index.d.ts.map +1 -1
- package/lib/opLifecycle/index.js.map +1 -1
- package/lib/opLifecycle/opCompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opCompressor.js.map +1 -1
- package/lib/opLifecycle/opDecompressor.d.ts.map +1 -1
- package/lib/opLifecycle/opDecompressor.js +5 -2
- package/lib/opLifecycle/opDecompressor.js.map +1 -1
- package/lib/opLifecycle/opSplitter.d.ts.map +1 -1
- package/lib/opLifecycle/opSplitter.js +5 -2
- package/lib/opLifecycle/opSplitter.js.map +1 -1
- package/lib/opLifecycle/outbox.d.ts.map +1 -1
- package/lib/opLifecycle/outbox.js +19 -17
- package/lib/opLifecycle/outbox.js.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.d.ts.map +1 -1
- package/lib/opLifecycle/remoteMessageProcessor.js.map +1 -1
- package/lib/opProperties.d.ts.map +1 -1
- package/lib/opProperties.js +1 -3
- package/lib/opProperties.js.map +1 -1
- package/lib/orderedClientElection.d.ts.map +1 -1
- package/lib/orderedClientElection.js +10 -4
- package/lib/orderedClientElection.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/pendingStateManager.d.ts +7 -0
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +7 -4
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/runWhileConnectedCoordinator.d.ts.map +1 -1
- package/lib/runWhileConnectedCoordinator.js.map +1 -1
- package/lib/runningSummarizer.d.ts.map +1 -1
- package/lib/runningSummarizer.js +35 -22
- package/lib/runningSummarizer.js.map +1 -1
- package/lib/scheduleManager.d.ts.map +1 -1
- package/lib/scheduleManager.js +3 -2
- package/lib/scheduleManager.js.map +1 -1
- package/lib/serializedSnapshotStorage.d.ts +2 -2
- package/lib/serializedSnapshotStorage.d.ts.map +1 -1
- package/lib/serializedSnapshotStorage.js +5 -3
- package/lib/serializedSnapshotStorage.js.map +1 -1
- package/lib/summarizer.d.ts +2 -2
- package/lib/summarizer.d.ts.map +1 -1
- package/lib/summarizer.js +37 -17
- package/lib/summarizer.js.map +1 -1
- package/lib/summarizerClientElection.d.ts.map +1 -1
- package/lib/summarizerClientElection.js.map +1 -1
- package/lib/summarizerHandle.d.ts.map +1 -1
- package/lib/summarizerHandle.js.map +1 -1
- package/lib/summarizerHeuristics.d.ts.map +1 -1
- package/lib/summarizerHeuristics.js +6 -9
- package/lib/summarizerHeuristics.js.map +1 -1
- package/lib/summarizerTypes.d.ts +21 -21
- package/lib/summarizerTypes.d.ts.map +1 -1
- package/lib/summarizerTypes.js.map +1 -1
- package/lib/summaryCollection.d.ts.map +1 -1
- package/lib/summaryCollection.js +18 -8
- package/lib/summaryCollection.js.map +1 -1
- package/lib/summaryFormat.d.ts +22 -0
- package/lib/summaryFormat.d.ts.map +1 -1
- package/lib/summaryFormat.js +20 -12
- package/lib/summaryFormat.js.map +1 -1
- package/lib/summaryGenerator.d.ts.map +1 -1
- package/lib/summaryGenerator.js +34 -15
- package/lib/summaryGenerator.js.map +1 -1
- package/lib/summaryManager.d.ts.map +1 -1
- package/lib/summaryManager.js +21 -9
- package/lib/summaryManager.js.map +1 -1
- package/lib/throttler.d.ts +2 -2
- package/lib/throttler.d.ts.map +1 -1
- package/lib/throttler.js +4 -4
- package/lib/throttler.js.map +1 -1
- package/package.json +121 -149
- package/prettier.config.cjs +1 -1
- package/src/batchTracker.ts +54 -49
- package/src/blobManager.ts +793 -672
- package/src/connectionTelemetry.ts +280 -249
- package/src/containerHandleContext.ts +27 -29
- package/src/containerRuntime.ts +3168 -2940
- package/src/dataStore.ts +172 -159
- package/src/dataStoreContext.ts +1098 -996
- package/src/dataStoreContexts.ts +178 -161
- package/src/dataStoreRegistry.ts +25 -20
- package/src/dataStores.ts +884 -728
- package/src/deltaScheduler.ts +158 -150
- package/src/garbageCollection.ts +1883 -1692
- package/src/garbageCollectionConstants.ts +6 -0
- package/src/garbageCollectionHelpers.ts +61 -0
- package/src/gcSweepReadyUsageDetection.ts +89 -83
- package/src/index.ts +67 -66
- package/src/opLifecycle/README.md +152 -0
- package/src/opLifecycle/batchManager.ts +145 -141
- package/src/opLifecycle/definitions.ts +29 -29
- package/src/opLifecycle/index.ts +5 -5
- package/src/opLifecycle/opCompressor.ts +54 -53
- package/src/opLifecycle/opDecompressor.ts +100 -81
- package/src/opLifecycle/opSplitter.ts +214 -188
- package/src/opLifecycle/outbox.ts +204 -194
- package/src/opLifecycle/remoteMessageProcessor.ts +62 -62
- package/src/opProperties.ts +11 -9
- package/src/orderedClientElection.ts +489 -457
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +384 -338
- package/src/runWhileConnectedCoordinator.ts +78 -71
- package/src/runningSummarizer.ts +619 -581
- package/src/scheduleManager.ts +299 -269
- package/src/serializedSnapshotStorage.ts +126 -112
- package/src/summarizer.ts +417 -381
- package/src/summarizerClientElection.ts +107 -100
- package/src/summarizerHandle.ts +11 -9
- package/src/summarizerHeuristics.ts +183 -186
- package/src/summarizerTypes.ts +344 -330
- package/src/summaryCollection.ts +378 -349
- package/src/summaryFormat.ts +170 -126
- package/src/summaryGenerator.ts +465 -406
- package/src/summaryManager.ts +377 -348
- package/src/throttler.ts +131 -122
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
- package/dist/garbageCollectionTombstoneUtils.d.ts +0 -14
- package/dist/garbageCollectionTombstoneUtils.d.ts.map +0 -1
- package/dist/garbageCollectionTombstoneUtils.js +0 -23
- package/dist/garbageCollectionTombstoneUtils.js.map +0 -1
- package/lib/garbageCollectionTombstoneUtils.d.ts +0 -14
- package/lib/garbageCollectionTombstoneUtils.d.ts.map +0 -1
- package/lib/garbageCollectionTombstoneUtils.js +0 -19
- package/lib/garbageCollectionTombstoneUtils.js.map +0 -1
- package/src/garbageCollectionTombstoneUtils.ts +0 -28
package/src/runningSummarizer.ts
CHANGED
|
@@ -7,38 +7,33 @@ import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definition
|
|
|
7
7
|
import { assert, delay, Deferred, PromiseTimer } from "@fluidframework/common-utils";
|
|
8
8
|
import { UsageError } from "@fluidframework/container-utils";
|
|
9
9
|
import { isRuntimeMessage } from "@fluidframework/driver-utils";
|
|
10
|
-
import {
|
|
11
|
-
ISequencedDocumentMessage,
|
|
12
|
-
MessageType,
|
|
13
|
-
} from "@fluidframework/protocol-definitions";
|
|
10
|
+
import { ISequencedDocumentMessage, MessageType } from "@fluidframework/protocol-definitions";
|
|
14
11
|
import { ChildLogger } from "@fluidframework/telemetry-utils";
|
|
15
|
-
import {
|
|
16
|
-
ISummaryConfiguration,
|
|
17
|
-
} from "./containerRuntime";
|
|
12
|
+
import { ISummaryConfiguration } from "./containerRuntime";
|
|
18
13
|
import { opSize } from "./opProperties";
|
|
19
14
|
import { SummarizeHeuristicRunner } from "./summarizerHeuristics";
|
|
20
15
|
import {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
16
|
+
IEnqueueSummarizeOptions,
|
|
17
|
+
ISummarizeOptions,
|
|
18
|
+
ISummarizeHeuristicData,
|
|
19
|
+
ISummarizeHeuristicRunner,
|
|
20
|
+
IOnDemandSummarizeOptions,
|
|
21
|
+
EnqueueSummarizeResult,
|
|
22
|
+
SummarizerStopReason,
|
|
23
|
+
ISubmitSummaryOptions,
|
|
24
|
+
SubmitSummaryResult,
|
|
25
|
+
ISummaryCancellationToken,
|
|
26
|
+
ISummarizeResults,
|
|
27
|
+
ISummarizeTelemetryProperties,
|
|
28
|
+
ISummarizerRuntime,
|
|
29
|
+
ISummarizeRunnerTelemetry,
|
|
35
30
|
} from "./summarizerTypes";
|
|
36
31
|
import { IClientSummaryWatcher, SummaryCollection } from "./summaryCollection";
|
|
37
32
|
import {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
raceTimer,
|
|
34
|
+
SummarizeReason,
|
|
35
|
+
SummarizeResultBuilder,
|
|
36
|
+
SummaryGenerator,
|
|
42
37
|
} from "./summaryGenerator";
|
|
43
38
|
|
|
44
39
|
const maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes
|
|
@@ -51,560 +46,603 @@ const maxSummarizeAckWaitTime = 10 * 60 * 1000; // 10 minutes
|
|
|
51
46
|
* This object is created and controlled by Summarizer object.
|
|
52
47
|
*/
|
|
53
48
|
export class RunningSummarizer implements IDisposable {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
49
|
+
public static async start(
|
|
50
|
+
logger: ITelemetryLogger,
|
|
51
|
+
summaryWatcher: IClientSummaryWatcher,
|
|
52
|
+
configuration: ISummaryConfiguration,
|
|
53
|
+
submitSummaryCallback: (options: ISubmitSummaryOptions) => Promise<SubmitSummaryResult>,
|
|
54
|
+
heuristicData: ISummarizeHeuristicData,
|
|
55
|
+
raiseSummarizingError: (errorMessage: string) => void,
|
|
56
|
+
summaryCollection: SummaryCollection,
|
|
57
|
+
cancellationToken: ISummaryCancellationToken,
|
|
58
|
+
stopSummarizerCallback: (reason: SummarizerStopReason) => void,
|
|
59
|
+
runtime: ISummarizerRuntime,
|
|
60
|
+
): Promise<RunningSummarizer> {
|
|
61
|
+
const summarizer = new RunningSummarizer(
|
|
62
|
+
logger,
|
|
63
|
+
summaryWatcher,
|
|
64
|
+
configuration,
|
|
65
|
+
submitSummaryCallback,
|
|
66
|
+
heuristicData,
|
|
67
|
+
raiseSummarizingError,
|
|
68
|
+
summaryCollection,
|
|
69
|
+
cancellationToken,
|
|
70
|
+
stopSummarizerCallback,
|
|
71
|
+
runtime,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
await summarizer.waitStart();
|
|
75
|
+
|
|
76
|
+
// Update heuristic counts
|
|
77
|
+
// By the time we get here, there are potentially ops missing from the heuristic summary counts
|
|
78
|
+
// Examples of where this could happen:
|
|
79
|
+
// 1. Op is processed during the time that we are initiating the RunningSummarizer instance but before we
|
|
80
|
+
// listen for the op events (will get missed by the handlers in the current workflow)
|
|
81
|
+
// 2. Op was sequenced after the last time we summarized (op sequence number > summarize ref sequence number)
|
|
82
|
+
const diff =
|
|
83
|
+
runtime.deltaManager.lastSequenceNumber -
|
|
84
|
+
(heuristicData.lastSuccessfulSummary.refSequenceNumber +
|
|
85
|
+
heuristicData.numNonRuntimeOps +
|
|
86
|
+
heuristicData.numRuntimeOps);
|
|
87
|
+
heuristicData.hasMissingOpData = diff > 0;
|
|
88
|
+
|
|
89
|
+
if (heuristicData.hasMissingOpData) {
|
|
90
|
+
// Split the diff 50-50 and increment the counts appropriately
|
|
91
|
+
heuristicData.numNonRuntimeOps += Math.ceil(diff / 2);
|
|
92
|
+
heuristicData.numRuntimeOps += Math.floor(diff / 2);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Update last seq number (in case the handlers haven't processed anything yet)
|
|
96
|
+
heuristicData.lastOpSequenceNumber = runtime.deltaManager.lastSequenceNumber;
|
|
97
|
+
|
|
98
|
+
// Start heuristics
|
|
99
|
+
summarizer.heuristicRunner?.start();
|
|
100
|
+
summarizer.heuristicRunner?.run();
|
|
101
|
+
|
|
102
|
+
return summarizer;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public get disposed() {
|
|
106
|
+
return this._disposed;
|
|
107
|
+
}
|
|
108
|
+
private stopping = false;
|
|
109
|
+
private _disposed = false;
|
|
110
|
+
private summarizingLock: Promise<void> | undefined;
|
|
111
|
+
private refreshSummaryAckLock: Promise<void> | undefined;
|
|
112
|
+
private tryWhileSummarizing = false;
|
|
113
|
+
private readonly pendingAckTimer: PromiseTimer;
|
|
114
|
+
private heuristicRunner?: ISummarizeHeuristicRunner;
|
|
115
|
+
private readonly generator: SummaryGenerator;
|
|
116
|
+
private readonly logger: ITelemetryLogger;
|
|
117
|
+
private enqueuedSummary:
|
|
118
|
+
| {
|
|
119
|
+
reason: SummarizeReason;
|
|
120
|
+
afterSequenceNumber: number;
|
|
121
|
+
options: ISummarizeOptions;
|
|
122
|
+
readonly resultsBuilder: SummarizeResultBuilder;
|
|
123
|
+
}
|
|
124
|
+
| undefined;
|
|
125
|
+
private summarizeCount = 0;
|
|
126
|
+
private totalSuccessfulAttempts = 0;
|
|
127
|
+
private initialized = false;
|
|
128
|
+
|
|
129
|
+
private constructor(
|
|
130
|
+
baseLogger: ITelemetryLogger,
|
|
131
|
+
private readonly summaryWatcher: IClientSummaryWatcher,
|
|
132
|
+
private readonly configuration: ISummaryConfiguration,
|
|
133
|
+
private readonly submitSummaryCallback: (
|
|
134
|
+
options: ISubmitSummaryOptions,
|
|
135
|
+
) => Promise<SubmitSummaryResult>,
|
|
136
|
+
private readonly heuristicData: ISummarizeHeuristicData,
|
|
137
|
+
private readonly raiseSummarizingError: (errorMessage: string) => void,
|
|
138
|
+
private readonly summaryCollection: SummaryCollection,
|
|
139
|
+
private readonly cancellationToken: ISummaryCancellationToken,
|
|
140
|
+
private readonly stopSummarizerCallback: (reason: SummarizerStopReason) => void,
|
|
141
|
+
private readonly runtime: ISummarizerRuntime,
|
|
142
|
+
) {
|
|
143
|
+
const telemetryProps: ISummarizeRunnerTelemetry = {
|
|
144
|
+
summarizeCount: () => this.summarizeCount,
|
|
145
|
+
summarizerSuccessfulAttempts: () => this.totalSuccessfulAttempts,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
this.logger = ChildLogger.create(baseLogger, "Running", {
|
|
149
|
+
all: telemetryProps,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
if (configuration.state !== "disableHeuristics") {
|
|
153
|
+
assert(
|
|
154
|
+
this.configuration.state === "enabled",
|
|
155
|
+
0x2ea /* "Configuration state should be enabled" */,
|
|
156
|
+
);
|
|
157
|
+
this.heuristicRunner = new SummarizeHeuristicRunner(
|
|
158
|
+
heuristicData,
|
|
159
|
+
this.configuration,
|
|
160
|
+
(reason) => this.trySummarize(reason),
|
|
161
|
+
this.logger,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
assert(
|
|
166
|
+
this.configuration.state !== "disabled",
|
|
167
|
+
0x2eb /* "Summary not supported with configuration disabled" */,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// Cap the maximum amount of time client will wait for a summarize op ack to maxSummarizeAckWaitTime
|
|
171
|
+
// configuration.maxAckWaitTime is composed from defaults, server values, and runtime overrides
|
|
172
|
+
|
|
173
|
+
const maxAckWaitTime = Math.min(this.configuration.maxAckWaitTime, maxSummarizeAckWaitTime);
|
|
174
|
+
|
|
175
|
+
this.pendingAckTimer = new PromiseTimer(maxAckWaitTime, () => {
|
|
176
|
+
// pre-0.58 error message: summaryAckWaitTimeout
|
|
177
|
+
this.raiseSummarizingError("Pending summary ack not received in time");
|
|
178
|
+
// Note: summarizeCount (from ChildLogger definition) may be 0,
|
|
179
|
+
// since this code path is hit when RunningSummarizer first starts up,
|
|
180
|
+
// before this instance has kicked off a new summarize run.
|
|
181
|
+
this.logger.sendErrorEvent({
|
|
182
|
+
eventName: "SummaryAckWaitTimeout",
|
|
183
|
+
maxAckWaitTime,
|
|
184
|
+
referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,
|
|
185
|
+
summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,
|
|
186
|
+
timePending: Date.now() - this.heuristicData.lastAttempt.summaryTime,
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
// Set up pending ack timeout by op timestamp differences for previous summaries.
|
|
190
|
+
summaryCollection.setPendingAckTimerTimeoutCallback(maxAckWaitTime, () => {
|
|
191
|
+
if (this.pendingAckTimer.hasTimer) {
|
|
192
|
+
this.logger.sendTelemetryEvent({
|
|
193
|
+
eventName: "MissingSummaryAckFoundByOps",
|
|
194
|
+
referenceSequenceNumber: this.heuristicData.lastAttempt.refSequenceNumber,
|
|
195
|
+
summarySequenceNumber: this.heuristicData.lastAttempt.summarySequenceNumber,
|
|
196
|
+
});
|
|
197
|
+
this.pendingAckTimer.clear();
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
this.generator = new SummaryGenerator(
|
|
202
|
+
this.pendingAckTimer,
|
|
203
|
+
this.heuristicData,
|
|
204
|
+
this.submitSummaryCallback,
|
|
205
|
+
this.raiseSummarizingError,
|
|
206
|
+
() => {
|
|
207
|
+
this.totalSuccessfulAttempts++;
|
|
208
|
+
},
|
|
209
|
+
this.summaryWatcher,
|
|
210
|
+
this.logger,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
// Listen for ops
|
|
214
|
+
this.runtime.deltaManager.on("op", (op) => {
|
|
215
|
+
this.handleOp(op);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public dispose(): void {
|
|
220
|
+
this.runtime.deltaManager.off("op", (op) => {
|
|
221
|
+
this.handleOp(op);
|
|
222
|
+
});
|
|
223
|
+
this.summaryWatcher.dispose();
|
|
224
|
+
this.heuristicRunner?.dispose();
|
|
225
|
+
this.heuristicRunner = undefined;
|
|
226
|
+
this.generator.dispose();
|
|
227
|
+
this.pendingAckTimer.clear();
|
|
228
|
+
this.disposeEnqueuedSummary();
|
|
229
|
+
this._disposed = true;
|
|
230
|
+
this.stopping = true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* RunningSummarizer's logger includes the sequenced index of the current summary on each event.
|
|
235
|
+
* If some other Summarizer code wants that event on their logs they can get it here,
|
|
236
|
+
* but only if they're logging about that same summary.
|
|
237
|
+
* @param summaryOpRefSeq - RefSeq number of the summary op, to ensure the log correlation will be correct
|
|
238
|
+
*/
|
|
239
|
+
public tryGetCorrelatedLogger = (summaryOpRefSeq) =>
|
|
240
|
+
this.heuristicData.lastAttempt.refSequenceNumber === summaryOpRefSeq
|
|
241
|
+
? this.logger
|
|
242
|
+
: undefined;
|
|
243
|
+
|
|
244
|
+
/** We only want a single heuristic runner micro-task (will provide better optimized grouping of ops) */
|
|
245
|
+
private heuristicRunnerMicroTaskExists = false;
|
|
246
|
+
|
|
247
|
+
public handleOp(op: ISequencedDocumentMessage) {
|
|
248
|
+
this.heuristicData.lastOpSequenceNumber = op.sequenceNumber;
|
|
249
|
+
|
|
250
|
+
if (isRuntimeMessage(op)) {
|
|
251
|
+
this.heuristicData.numRuntimeOps++;
|
|
252
|
+
} else {
|
|
253
|
+
this.heuristicData.numNonRuntimeOps++;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
this.heuristicData.totalOpsSize += opSize(op);
|
|
257
|
+
|
|
258
|
+
// Check for enqueued on-demand summaries; Intentionally do nothing otherwise
|
|
259
|
+
if (
|
|
260
|
+
this.initialized &&
|
|
261
|
+
this.opCanTriggerSummary(op) &&
|
|
262
|
+
!this.tryRunEnqueuedSummary() &&
|
|
263
|
+
!this.heuristicRunnerMicroTaskExists
|
|
264
|
+
) {
|
|
265
|
+
this.heuristicRunnerMicroTaskExists = true;
|
|
266
|
+
Promise.resolve()
|
|
267
|
+
.then(() => {
|
|
268
|
+
this.heuristicRunner?.run();
|
|
269
|
+
})
|
|
270
|
+
.finally(() => {
|
|
271
|
+
this.heuristicRunnerMicroTaskExists = false;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Can the given op trigger a summary?
|
|
278
|
+
* # Currently always prevents summaries for Summarize and SummaryAck/Nack ops
|
|
279
|
+
* @param op - op to check
|
|
280
|
+
* @returns true if this op can trigger a summary
|
|
281
|
+
*/
|
|
282
|
+
private opCanTriggerSummary(op: ISequencedDocumentMessage): boolean {
|
|
283
|
+
switch (op.type) {
|
|
284
|
+
case MessageType.Summarize:
|
|
285
|
+
case MessageType.SummaryAck:
|
|
286
|
+
case MessageType.SummaryNack:
|
|
287
|
+
return false;
|
|
288
|
+
default:
|
|
289
|
+
return isRuntimeMessage(op) || this.nonRuntimeOpCanTriggerSummary();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private nonRuntimeOpCanTriggerSummary(): boolean {
|
|
294
|
+
const opsSinceLastAck =
|
|
295
|
+
this.heuristicData.lastOpSequenceNumber -
|
|
296
|
+
this.heuristicData.lastSuccessfulSummary.refSequenceNumber;
|
|
297
|
+
return (
|
|
298
|
+
this.configuration.state === "enabled" &&
|
|
299
|
+
(this.configuration.nonRuntimeHeuristicThreshold === undefined ||
|
|
300
|
+
this.configuration.nonRuntimeHeuristicThreshold <= opsSinceLastAck)
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public async waitStop(allowLastSummary: boolean): Promise<void> {
|
|
305
|
+
if (this.stopping) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
this.stopping = true;
|
|
310
|
+
|
|
311
|
+
this.disposeEnqueuedSummary();
|
|
312
|
+
|
|
313
|
+
// This will try to run lastSummary if needed.
|
|
314
|
+
if (allowLastSummary && this.heuristicRunner?.shouldRunLastSummary()) {
|
|
315
|
+
if (this.summarizingLock === undefined) {
|
|
316
|
+
this.trySummarizeOnce(
|
|
317
|
+
// summarizeProps
|
|
318
|
+
{ reason: "lastSummary" },
|
|
319
|
+
// ISummarizeOptions, using defaults: { refreshLatestAck: false, fullTree: false }
|
|
320
|
+
{},
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Note that trySummarizeOnce() call above returns right away, without waiting.
|
|
326
|
+
// So we need to wait for its completion, otherwise it would be destroyed right away.
|
|
327
|
+
// That said, if summary lock was taken upfront, this wait might wait on multiple retries to
|
|
328
|
+
// submit summary. We should reconsider this flow and make summarizer move to exit faster.
|
|
329
|
+
// This resolves when the current pending summary gets an ack or fails.
|
|
330
|
+
await this.summarizingLock;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private async waitStart() {
|
|
334
|
+
// Wait no longer than ack timeout for all pending
|
|
335
|
+
const waitStartResult = await raceTimer(
|
|
336
|
+
this.summaryWatcher.waitFlushed(),
|
|
337
|
+
this.pendingAckTimer.start(),
|
|
338
|
+
);
|
|
339
|
+
this.pendingAckTimer.clear();
|
|
340
|
+
|
|
341
|
+
// Remove pending ack wait timeout by op timestamp comparison, because
|
|
342
|
+
// it has race conditions with summaries submitted by this same client.
|
|
343
|
+
this.summaryCollection.unsetPendingAckTimerTimeoutCallback();
|
|
344
|
+
|
|
345
|
+
if (waitStartResult.result === "done" && waitStartResult.value !== undefined) {
|
|
346
|
+
this.heuristicData.updateWithLastSummaryAckInfo({
|
|
347
|
+
refSequenceNumber: waitStartResult.value.summaryOp.referenceSequenceNumber,
|
|
348
|
+
// This will be the Summarizer starting point so only use timestamps from client's machine.
|
|
349
|
+
summaryTime: Date.now(),
|
|
350
|
+
summarySequenceNumber: waitStartResult.value.summaryOp.sequenceNumber,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
this.initialized = true;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Blocks a new summarizer from running in case RefreshSummaryAck is being processed.
|
|
358
|
+
* Assumes that caller checked upfront for lack of concurrent action (this.refreshSummaryAckLock)
|
|
359
|
+
* before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.
|
|
360
|
+
* Note: The refreshSummaryAckLock makes sure no summarizer gets enqueued or processed
|
|
361
|
+
* until the refresh has completed. One can't rely uniquely on the summarizingLock as the
|
|
362
|
+
* refreshLatestSummaryAck also happens during the time summarizingLock !== undefined.
|
|
363
|
+
* Ex. Summarizer submits a summay + op and then waits for the Summary Ack to proceed
|
|
364
|
+
* with the refreshLatestSummaryAck and complete the summary.
|
|
365
|
+
* @param action - action to perform.
|
|
366
|
+
* @returns - result of action.
|
|
367
|
+
*/
|
|
368
|
+
public async lockedRefreshSummaryAckAction<T>(action: () => Promise<T>) {
|
|
369
|
+
assert(
|
|
370
|
+
this.refreshSummaryAckLock === undefined,
|
|
371
|
+
0x396 /* Refresh Summary Ack - Caller is responsible for checking lock */,
|
|
372
|
+
);
|
|
373
|
+
|
|
374
|
+
const refreshSummaryAckLock = new Deferred<void>();
|
|
375
|
+
this.refreshSummaryAckLock = refreshSummaryAckLock.promise;
|
|
376
|
+
|
|
377
|
+
return action().finally(() => {
|
|
378
|
+
refreshSummaryAckLock.resolve();
|
|
379
|
+
this.refreshSummaryAckLock = undefined;
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Runs single summary action that prevents any other concurrent actions.
|
|
385
|
+
* Assumes that caller checked upfront for lack of concurrent action (this.summarizingLock)
|
|
386
|
+
* before calling this API. I.e. caller is responsible for either erroring out or waiting on this promise.
|
|
387
|
+
* @param action - action to perform.
|
|
388
|
+
* @returns - result of action.
|
|
389
|
+
*/
|
|
390
|
+
private async lockedSummaryAction<T>(action: () => Promise<T>) {
|
|
391
|
+
assert(
|
|
392
|
+
this.summarizingLock === undefined,
|
|
393
|
+
0x25b /* "Caller is responsible for checking lock" */,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const summarizingLock = new Deferred<void>();
|
|
397
|
+
this.summarizingLock = summarizingLock.promise;
|
|
398
|
+
|
|
399
|
+
this.summarizeCount++;
|
|
400
|
+
// Make sure the RefreshLatestSummaryAck is not being executed.
|
|
401
|
+
await this.refreshSummaryAckLock;
|
|
402
|
+
|
|
403
|
+
return action().finally(() => {
|
|
404
|
+
summarizingLock.resolve();
|
|
405
|
+
this.summarizingLock = undefined;
|
|
406
|
+
|
|
407
|
+
const retry = this.tryWhileSummarizing;
|
|
408
|
+
this.tryWhileSummarizing = false;
|
|
409
|
+
|
|
410
|
+
// After summarizing, we should check to see if we need to summarize again.
|
|
411
|
+
// Rerun the heuristics and check for enqueued summaries.
|
|
412
|
+
if (!this.stopping && !this.tryRunEnqueuedSummary() && retry) {
|
|
413
|
+
this.heuristicRunner?.run();
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Runs single summarize attempt
|
|
420
|
+
* @param summarizeProps - props to log with each telemetry event associated with this attempt
|
|
421
|
+
* @param options - summary options
|
|
422
|
+
* @param cancellationToken - cancellation token to use to be able to cancel this summary, if needed
|
|
423
|
+
* @param resultsBuilder - optional, result builder to use.
|
|
424
|
+
* @returns ISummarizeResult - result of running a summary.
|
|
425
|
+
*/
|
|
426
|
+
private trySummarizeOnce(
|
|
427
|
+
summarizeProps: ISummarizeTelemetryProperties,
|
|
428
|
+
options: ISummarizeOptions,
|
|
429
|
+
cancellationToken = this.cancellationToken,
|
|
430
|
+
resultsBuilder = new SummarizeResultBuilder(),
|
|
431
|
+
): ISummarizeResults {
|
|
432
|
+
this.lockedSummaryAction(async () => {
|
|
433
|
+
const summarizeResult = this.generator.summarize(
|
|
434
|
+
summarizeProps,
|
|
435
|
+
options,
|
|
436
|
+
cancellationToken,
|
|
437
|
+
resultsBuilder,
|
|
438
|
+
);
|
|
439
|
+
// ensure we wait till the end of the process
|
|
440
|
+
return summarizeResult.receivedSummaryAckOrNack;
|
|
441
|
+
}).catch((error) => {
|
|
442
|
+
// SummaryGenerator.summarize() does not throw exceptions - it converts them to failed result
|
|
443
|
+
// on resultsBuilder
|
|
444
|
+
// We do not care about exceptions on receivedSummaryAckOrNack - caller should check results
|
|
445
|
+
// and take a appropriate action.
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
return resultsBuilder.build();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** Heuristics summarize attempt. */
|
|
452
|
+
private trySummarize(
|
|
453
|
+
reason: SummarizeReason,
|
|
454
|
+
cancellationToken = this.cancellationToken,
|
|
455
|
+
): void {
|
|
456
|
+
if (this.summarizingLock !== undefined) {
|
|
457
|
+
// lockedSummaryAction() will retry heuristic-based summary at the end of current attempt
|
|
458
|
+
// if it's still needed
|
|
459
|
+
this.tryWhileSummarizing = true;
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
this.lockedSummaryAction(async () => {
|
|
464
|
+
const attempts: (ISummarizeOptions & { delaySeconds?: number })[] = [
|
|
465
|
+
{ refreshLatestAck: false, fullTree: false },
|
|
466
|
+
{ refreshLatestAck: true, fullTree: false },
|
|
467
|
+
{ refreshLatestAck: true, fullTree: false, delaySeconds: 2 * 60 },
|
|
468
|
+
{ refreshLatestAck: true, fullTree: true, delaySeconds: 10 * 60 },
|
|
469
|
+
];
|
|
470
|
+
let overrideDelaySeconds: number | undefined;
|
|
471
|
+
let summaryAttempts = 0;
|
|
472
|
+
let summaryAttemptsPerPhase = 0;
|
|
473
|
+
|
|
474
|
+
let lastResult: { message: string; error: any } | undefined;
|
|
475
|
+
|
|
476
|
+
for (let summaryAttemptPhase = 0; summaryAttemptPhase < attempts.length; ) {
|
|
477
|
+
if (this.cancellationToken.cancelled) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// We only want to attempt 1 summary when reason is "lastSummary"
|
|
482
|
+
if (++summaryAttempts > 1 && reason === "lastSummary") {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
summaryAttemptsPerPhase++;
|
|
487
|
+
|
|
488
|
+
const { delaySeconds: regularDelaySeconds = 0, ...options } =
|
|
489
|
+
attempts[summaryAttemptPhase];
|
|
490
|
+
const delaySeconds = overrideDelaySeconds ?? regularDelaySeconds;
|
|
491
|
+
|
|
492
|
+
const summarizeProps: ISummarizeTelemetryProperties = {
|
|
493
|
+
reason,
|
|
494
|
+
summaryAttempts,
|
|
495
|
+
summaryAttemptsPerPhase,
|
|
496
|
+
summaryAttemptPhase: summaryAttemptPhase + 1, // make everything 1-based
|
|
497
|
+
...options,
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
if (delaySeconds > 0) {
|
|
501
|
+
this.logger.sendPerformanceEvent({
|
|
502
|
+
eventName: "SummarizeAttemptDelay",
|
|
503
|
+
duration: delaySeconds,
|
|
504
|
+
summaryNackDelay: overrideDelaySeconds !== undefined,
|
|
505
|
+
...summarizeProps,
|
|
506
|
+
});
|
|
507
|
+
await delay(delaySeconds * 1000);
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Make sure the refresh Summary Ack is not being executed.
|
|
511
|
+
await this.refreshSummaryAckLock;
|
|
512
|
+
|
|
513
|
+
// Note: no need to account for cancellationToken.waitCancelled here, as
|
|
514
|
+
// this is accounted SummaryGenerator.summarizeCore that controls receivedSummaryAckOrNack.
|
|
515
|
+
const resultSummarize = this.generator.summarize(
|
|
516
|
+
summarizeProps,
|
|
517
|
+
options,
|
|
518
|
+
cancellationToken,
|
|
519
|
+
);
|
|
520
|
+
const result = await resultSummarize.receivedSummaryAckOrNack;
|
|
521
|
+
|
|
522
|
+
if (result.success) {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
// Check for retryDelay that can come from summaryNack or upload summary flow.
|
|
526
|
+
// Retry the same step only once per retryAfter response.
|
|
527
|
+
overrideDelaySeconds = result.retryAfterSeconds;
|
|
528
|
+
if (overrideDelaySeconds === undefined || summaryAttemptsPerPhase > 1) {
|
|
529
|
+
summaryAttemptPhase++;
|
|
530
|
+
summaryAttemptsPerPhase = 0;
|
|
531
|
+
}
|
|
532
|
+
lastResult = result;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// If all attempts failed, log error (with last attempt info) and close the summarizer container
|
|
536
|
+
this.logger.sendErrorEvent(
|
|
537
|
+
{
|
|
538
|
+
eventName: "FailToSummarize",
|
|
539
|
+
reason,
|
|
540
|
+
message: lastResult?.message,
|
|
541
|
+
},
|
|
542
|
+
lastResult?.error,
|
|
543
|
+
);
|
|
544
|
+
|
|
545
|
+
this.stopSummarizerCallback("failToSummarize");
|
|
546
|
+
}).catch((error) => {
|
|
547
|
+
this.logger.sendErrorEvent({ eventName: "UnexpectedSummarizeError" }, error);
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
/** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */
|
|
552
|
+
public summarizeOnDemand(
|
|
553
|
+
resultsBuilder: SummarizeResultBuilder = new SummarizeResultBuilder(),
|
|
554
|
+
{ reason, ...options }: IOnDemandSummarizeOptions,
|
|
555
|
+
): ISummarizeResults {
|
|
556
|
+
if (this.stopping) {
|
|
557
|
+
resultsBuilder.fail("RunningSummarizer stopped or disposed", undefined);
|
|
558
|
+
return resultsBuilder.build();
|
|
559
|
+
}
|
|
560
|
+
// Check for concurrent summary attempts. If one is found,
|
|
561
|
+
// return a promise that caller can await before trying again.
|
|
562
|
+
if (this.summarizingLock !== undefined) {
|
|
563
|
+
// The heuristics are blocking concurrent summarize attempts.
|
|
564
|
+
throw new UsageError("Attempted to run an already-running summarizer on demand");
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const result = this.trySummarizeOnce(
|
|
568
|
+
{ reason: `onDemand/${reason}` },
|
|
569
|
+
options,
|
|
570
|
+
this.cancellationToken,
|
|
571
|
+
resultsBuilder,
|
|
572
|
+
);
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */
|
|
577
|
+
public enqueueSummarize({
|
|
578
|
+
reason,
|
|
579
|
+
afterSequenceNumber = 0,
|
|
580
|
+
override = false,
|
|
581
|
+
...options
|
|
582
|
+
}: IEnqueueSummarizeOptions): EnqueueSummarizeResult {
|
|
583
|
+
const onDemandReason = `enqueue;${reason}` as const;
|
|
584
|
+
let overridden = false;
|
|
585
|
+
if (this.enqueuedSummary !== undefined) {
|
|
586
|
+
if (!override) {
|
|
587
|
+
return { alreadyEnqueued: true };
|
|
588
|
+
}
|
|
589
|
+
// Override existing enqueued summarize attempt.
|
|
590
|
+
this.enqueuedSummary.resultsBuilder.fail(
|
|
591
|
+
"Aborted; overridden by another enqueue summarize attempt",
|
|
592
|
+
undefined,
|
|
593
|
+
);
|
|
594
|
+
this.enqueuedSummary = undefined;
|
|
595
|
+
overridden = true;
|
|
596
|
+
}
|
|
597
|
+
this.enqueuedSummary = {
|
|
598
|
+
reason: onDemandReason,
|
|
599
|
+
afterSequenceNumber,
|
|
600
|
+
options,
|
|
601
|
+
resultsBuilder: new SummarizeResultBuilder(),
|
|
602
|
+
};
|
|
603
|
+
const results = this.enqueuedSummary.resultsBuilder.build();
|
|
604
|
+
this.tryRunEnqueuedSummary();
|
|
605
|
+
return overridden
|
|
606
|
+
? {
|
|
607
|
+
...results,
|
|
608
|
+
alreadyEnqueued: true,
|
|
609
|
+
overridden: true,
|
|
610
|
+
}
|
|
611
|
+
: results;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private tryRunEnqueuedSummary() {
|
|
615
|
+
if (this.stopping) {
|
|
616
|
+
this.disposeEnqueuedSummary();
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
if (
|
|
620
|
+
this.enqueuedSummary === undefined ||
|
|
621
|
+
this.heuristicData.lastOpSequenceNumber < this.enqueuedSummary.afterSequenceNumber ||
|
|
622
|
+
this.summarizingLock !== undefined
|
|
623
|
+
) {
|
|
624
|
+
// If no enqueued summary is ready or a summary is already in progress, take no action.
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
const { reason, resultsBuilder, options } = this.enqueuedSummary;
|
|
628
|
+
// Set to undefined first, so that subsequent enqueue attempt while summarize will occur later.
|
|
629
|
+
this.enqueuedSummary = undefined;
|
|
630
|
+
this.trySummarizeOnce(
|
|
631
|
+
{ reason: `enqueuedSummary/${reason}` },
|
|
632
|
+
options,
|
|
633
|
+
this.cancellationToken,
|
|
634
|
+
resultsBuilder,
|
|
635
|
+
);
|
|
636
|
+
return true;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
private disposeEnqueuedSummary() {
|
|
640
|
+
if (this.enqueuedSummary !== undefined) {
|
|
641
|
+
this.enqueuedSummary.resultsBuilder.fail(
|
|
642
|
+
"RunningSummarizer stopped or disposed",
|
|
643
|
+
undefined,
|
|
644
|
+
);
|
|
645
|
+
this.enqueuedSummary = undefined;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
610
648
|
}
|