@fluidframework/container-runtime 2.0.0-internal.3.4.2 → 2.0.0-internal.4.0.1
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/dist/containerRuntime.d.ts +1 -5
- package/dist/containerRuntime.d.ts.map +1 -1
- package/dist/containerRuntime.js +12 -16
- package/dist/containerRuntime.js.map +1 -1
- package/dist/gc/garbageCollection.d.ts +2 -1
- package/dist/gc/garbageCollection.d.ts.map +1 -1
- package/dist/gc/garbageCollection.js.map +1 -1
- package/dist/gc/gcDefinitions.d.ts +2 -3
- package/dist/gc/gcDefinitions.d.ts.map +1 -1
- package/dist/gc/gcDefinitions.js.map +1 -1
- package/dist/gc/gcSummaryStateTracker.d.ts +2 -1
- package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/dist/gc/gcSummaryStateTracker.js.map +1 -1
- package/dist/gc/index.d.ts +1 -2
- package/dist/gc/index.d.ts.map +1 -1
- package/dist/gc/index.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.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 +2 -8
- package/dist/pendingStateManager.d.ts.map +1 -1
- package/dist/pendingStateManager.js +6 -12
- package/dist/pendingStateManager.js.map +1 -1
- package/dist/summary/index.d.ts +2 -2
- package/dist/summary/index.d.ts.map +1 -1
- package/dist/summary/index.js +4 -5
- package/dist/summary/index.js.map +1 -1
- package/dist/summary/summarizer.d.ts +2 -5
- package/dist/summary/summarizer.d.ts.map +1 -1
- package/dist/summary/summarizer.js +8 -13
- package/dist/summary/summarizer.js.map +1 -1
- package/dist/summary/summarizerNode/index.d.ts +8 -0
- package/dist/summary/summarizerNode/index.d.ts.map +1 -0
- package/dist/summary/summarizerNode/index.js +12 -0
- package/dist/summary/summarizerNode/index.js.map +1 -0
- package/dist/summary/summarizerNode/summarizerNode.d.ts +149 -0
- package/dist/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
- package/dist/summary/summarizerNode/summarizerNode.js +520 -0
- package/dist/summary/summarizerNode/summarizerNode.js.map +1 -0
- package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
- package/dist/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
- package/dist/summary/summarizerNode/summarizerNodeUtils.js +132 -0
- package/dist/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
- package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
- package/dist/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js +420 -0
- package/dist/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
- package/dist/summary/summarizerTypes.d.ts +5 -17
- package/dist/summary/summarizerTypes.d.ts.map +1 -1
- package/dist/summary/summarizerTypes.js +0 -5
- package/dist/summary/summarizerTypes.js.map +1 -1
- package/lib/containerRuntime.d.ts +1 -5
- package/lib/containerRuntime.d.ts.map +1 -1
- package/lib/containerRuntime.js +13 -17
- package/lib/containerRuntime.js.map +1 -1
- package/lib/gc/garbageCollection.d.ts +2 -1
- package/lib/gc/garbageCollection.d.ts.map +1 -1
- package/lib/gc/garbageCollection.js +1 -1
- package/lib/gc/garbageCollection.js.map +1 -1
- package/lib/gc/gcDefinitions.d.ts +2 -3
- package/lib/gc/gcDefinitions.d.ts.map +1 -1
- package/lib/gc/gcDefinitions.js.map +1 -1
- package/lib/gc/gcSummaryStateTracker.d.ts +2 -1
- package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
- package/lib/gc/gcSummaryStateTracker.js +1 -1
- package/lib/gc/gcSummaryStateTracker.js.map +1 -1
- package/lib/gc/index.d.ts +1 -2
- package/lib/gc/index.d.ts.map +1 -1
- package/lib/gc/index.js.map +1 -1
- package/lib/index.d.ts +1 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.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 +2 -8
- package/lib/pendingStateManager.d.ts.map +1 -1
- package/lib/pendingStateManager.js +6 -12
- package/lib/pendingStateManager.js.map +1 -1
- package/lib/summary/index.d.ts +2 -2
- package/lib/summary/index.d.ts.map +1 -1
- package/lib/summary/index.js +1 -2
- package/lib/summary/index.js.map +1 -1
- package/lib/summary/summarizer.d.ts +2 -5
- package/lib/summary/summarizer.d.ts.map +1 -1
- package/lib/summary/summarizer.js +8 -13
- package/lib/summary/summarizer.js.map +1 -1
- package/lib/summary/summarizerNode/index.d.ts +8 -0
- package/lib/summary/summarizerNode/index.d.ts.map +1 -0
- package/lib/summary/summarizerNode/index.js +7 -0
- package/lib/summary/summarizerNode/index.js.map +1 -0
- package/lib/summary/summarizerNode/summarizerNode.d.ts +149 -0
- package/lib/summary/summarizerNode/summarizerNode.d.ts.map +1 -0
- package/lib/summary/summarizerNode/summarizerNode.js +515 -0
- package/lib/summary/summarizerNode/summarizerNode.js.map +1 -0
- package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts +125 -0
- package/lib/summary/summarizerNode/summarizerNodeUtils.d.ts.map +1 -0
- package/lib/summary/summarizerNode/summarizerNodeUtils.js +125 -0
- package/lib/summary/summarizerNode/summarizerNodeUtils.js.map +1 -0
- package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts +22 -0
- package/lib/summary/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -0
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js +416 -0
- package/lib/summary/summarizerNode/summarizerNodeWithGc.js.map +1 -0
- package/lib/summary/summarizerTypes.d.ts +5 -17
- package/lib/summary/summarizerTypes.d.ts.map +1 -1
- package/lib/summary/summarizerTypes.js +1 -4
- package/lib/summary/summarizerTypes.js.map +1 -1
- package/package.json +52 -15
- package/src/containerRuntime.ts +19 -19
- package/src/gc/garbageCollection.ts +2 -6
- package/src/gc/gcDefinitions.ts +6 -4
- package/src/gc/gcSummaryStateTracker.ts +2 -7
- package/src/gc/index.ts +1 -1
- package/src/index.ts +0 -7
- package/src/packageVersion.ts +1 -1
- package/src/pendingStateManager.ts +8 -20
- package/src/summary/index.ts +8 -2
- package/src/summary/summarizer.ts +7 -21
- package/src/summary/summarizerNode/index.ts +12 -0
- package/src/summary/summarizerNode/summarizerNode.ts +744 -0
- package/src/summary/summarizerNode/summarizerNodeUtils.ts +214 -0
- package/src/summary/summarizerNode/summarizerNodeWithGc.ts +631 -0
- package/src/summary/summarizerTypes.ts +6 -22
- package/dist/summary/summarizerHandle.d.ts +0 -12
- package/dist/summary/summarizerHandle.d.ts.map +0 -1
- package/dist/summary/summarizerHandle.js +0 -22
- package/dist/summary/summarizerHandle.js.map +0 -1
- package/lib/summary/summarizerHandle.d.ts +0 -12
- package/lib/summary/summarizerHandle.d.ts.map +0 -1
- package/lib/summary/summarizerHandle.js +0 -18
- package/lib/summary/summarizerHandle.js.map +0 -1
- package/src/summary/summarizerHandle.ts +0 -23
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createRootSummarizerNode = exports.SummarizerNode = void 0;
|
|
8
|
+
const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
|
|
9
|
+
const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
|
|
10
|
+
const common_utils_1 = require("@fluidframework/common-utils");
|
|
11
|
+
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
12
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
13
|
+
const summarizerNodeUtils_1 = require("./summarizerNodeUtils");
|
|
14
|
+
/**
|
|
15
|
+
* Encapsulates the summarizing work and state of an individual tree node in the
|
|
16
|
+
* summary tree. It tracks changes and allows for optimizations when unchanged, or
|
|
17
|
+
* can allow for fallback summaries to be generated when an error is encountered.
|
|
18
|
+
* Usage is for the root node to call startSummary first to begin tracking a WIP
|
|
19
|
+
* (work in progress) summary. Then all nodes will call summarize to summaries their
|
|
20
|
+
* individual parts. Once completed and uploaded to storage, the root node will call
|
|
21
|
+
* completeSummary or clearSummary to clear the WIP summary tracking state if something
|
|
22
|
+
* went wrong. The SummarizerNodes will track all pending summaries that have been
|
|
23
|
+
* recorded by the completeSummary call. When one of them is acked, the root node should
|
|
24
|
+
* call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline
|
|
25
|
+
* latest successful summary.
|
|
26
|
+
*/
|
|
27
|
+
class SummarizerNode {
|
|
28
|
+
/**
|
|
29
|
+
* Do not call constructor directly.
|
|
30
|
+
* Use createRootSummarizerNode to create root node, or createChild to create child nodes.
|
|
31
|
+
*/
|
|
32
|
+
constructor(baseLogger, summarizeInternalFn, config, _changeSequenceNumber,
|
|
33
|
+
/** Undefined means created without summary */
|
|
34
|
+
_latestSummary, initialSummary, wipSummaryLogger,
|
|
35
|
+
/** A unique id of this node to be logged when sending telemetry. */
|
|
36
|
+
telemetryNodeId) {
|
|
37
|
+
var _a;
|
|
38
|
+
this.summarizeInternalFn = summarizeInternalFn;
|
|
39
|
+
this._changeSequenceNumber = _changeSequenceNumber;
|
|
40
|
+
this._latestSummary = _latestSummary;
|
|
41
|
+
this.initialSummary = initialSummary;
|
|
42
|
+
this.wipSummaryLogger = wipSummaryLogger;
|
|
43
|
+
this.telemetryNodeId = telemetryNodeId;
|
|
44
|
+
this.children = new Map();
|
|
45
|
+
this.pendingSummaries = new Map();
|
|
46
|
+
this.wipSkipRecursion = false;
|
|
47
|
+
this.canReuseHandle = (_a = config.canReuseHandle) !== null && _a !== void 0 ? _a : true;
|
|
48
|
+
// All logs posted by the summarizer node should include the telemetryNodeId.
|
|
49
|
+
this.logger = telemetry_utils_1.ChildLogger.create(baseLogger, undefined /* namespace */, {
|
|
50
|
+
all: {
|
|
51
|
+
id: {
|
|
52
|
+
tag: telemetry_utils_1.TelemetryDataTag.CodeArtifact,
|
|
53
|
+
value: this.telemetryNodeId,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The reference sequence number of the most recent acked summary.
|
|
60
|
+
* Returns 0 if there is not yet an acked summary.
|
|
61
|
+
*/
|
|
62
|
+
get referenceSequenceNumber() {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
return (_b = (_a = this._latestSummary) === null || _a === void 0 ? void 0 : _a.referenceSequenceNumber) !== null && _b !== void 0 ? _b : 0;
|
|
65
|
+
}
|
|
66
|
+
startSummary(referenceSequenceNumber, summaryLogger) {
|
|
67
|
+
(0, common_utils_1.assert)(this.wipSummaryLogger === undefined, 0x19f /* "wipSummaryLogger should not be set yet in startSummary" */);
|
|
68
|
+
(0, common_utils_1.assert)(this.wipReferenceSequenceNumber === undefined, 0x1a0 /* "Already tracking a summary" */);
|
|
69
|
+
this.wipSummaryLogger = summaryLogger;
|
|
70
|
+
for (const child of this.children.values()) {
|
|
71
|
+
child.startSummary(referenceSequenceNumber, this.wipSummaryLogger);
|
|
72
|
+
}
|
|
73
|
+
this.wipReferenceSequenceNumber = referenceSequenceNumber;
|
|
74
|
+
}
|
|
75
|
+
async summarize(fullTree, trackState = true, telemetryContext) {
|
|
76
|
+
(0, common_utils_1.assert)(this.isSummaryInProgress(), 0x1a1 /* "summarize should not be called when not tracking the summary" */);
|
|
77
|
+
(0, common_utils_1.assert)(this.wipSummaryLogger !== undefined, 0x1a2 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
|
|
78
|
+
// Try to reuse the tree if unchanged
|
|
79
|
+
if (this.canReuseHandle && !fullTree && !this.hasChanged()) {
|
|
80
|
+
const latestSummary = this._latestSummary;
|
|
81
|
+
if (latestSummary !== undefined) {
|
|
82
|
+
this.wipLocalPaths = {
|
|
83
|
+
localPath: latestSummary.localPath,
|
|
84
|
+
additionalPath: latestSummary.additionalPath,
|
|
85
|
+
};
|
|
86
|
+
this.wipSkipRecursion = true;
|
|
87
|
+
const stats = (0, runtime_utils_1.mergeStats)();
|
|
88
|
+
stats.handleNodeCount++;
|
|
89
|
+
return {
|
|
90
|
+
summary: {
|
|
91
|
+
type: protocol_definitions_1.SummaryType.Handle,
|
|
92
|
+
handle: latestSummary.fullPath.path,
|
|
93
|
+
handleType: protocol_definitions_1.SummaryType.Tree,
|
|
94
|
+
},
|
|
95
|
+
stats,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const result = await this.summarizeInternalFn(fullTree, true, telemetryContext);
|
|
100
|
+
this.wipLocalPaths = { localPath: summarizerNodeUtils_1.EscapedPath.create(result.id) };
|
|
101
|
+
if (result.pathPartsForChildren !== undefined) {
|
|
102
|
+
this.wipLocalPaths.additionalPath = summarizerNodeUtils_1.EscapedPath.createAndConcat(result.pathPartsForChildren);
|
|
103
|
+
}
|
|
104
|
+
return { summary: result.summary, stats: result.stats };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Complete the WIP summary for the given proposalHandle
|
|
108
|
+
*/
|
|
109
|
+
completeSummary(proposalHandle) {
|
|
110
|
+
this.completeSummaryCore(proposalHandle, undefined, false);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Recursive implementation for completeSummary, with additional internal-only parameters
|
|
114
|
+
*/
|
|
115
|
+
completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion) {
|
|
116
|
+
(0, common_utils_1.assert)(this.wipSummaryLogger !== undefined, 0x1a3 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
|
|
117
|
+
(0, common_utils_1.assert)(this.wipReferenceSequenceNumber !== undefined, 0x1a4 /* "Not tracking a summary" */);
|
|
118
|
+
let localPathsToUse = this.wipLocalPaths;
|
|
119
|
+
if (parentSkipRecursion) {
|
|
120
|
+
const latestSummary = this._latestSummary;
|
|
121
|
+
if (latestSummary !== undefined) {
|
|
122
|
+
// This case the parent node created a failure summary or was reused.
|
|
123
|
+
// This node and all children should only try to reference their path
|
|
124
|
+
// by its last known good state in the actual summary tree.
|
|
125
|
+
// If parent fails or is reused, the child summarize is not called so
|
|
126
|
+
// it did not get a chance to change its paths.
|
|
127
|
+
// In this case, essentially only propagate the new summary ref seq num.
|
|
128
|
+
localPathsToUse = {
|
|
129
|
+
localPath: latestSummary.localPath,
|
|
130
|
+
additionalPath: latestSummary.additionalPath,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// This case the child is added after the latest non-failure summary.
|
|
135
|
+
// This node and all children should consider themselves as still not
|
|
136
|
+
// having a successful summary yet.
|
|
137
|
+
// We cannot "reuse" this node if unchanged since that summary, because
|
|
138
|
+
// handles will be unable to point to that node. It never made it to the
|
|
139
|
+
// tree itself, and only exists as an attach op in the _outstandingOps.
|
|
140
|
+
this.clearSummary();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The absence of wip local path indicates that summarize was not called for this node. This can happen if:
|
|
146
|
+
* 1. A child node was created after summarize was already called on the parent. For example, a data store
|
|
147
|
+
* is realized (loaded) after summarize was called on it creating summarizer nodes for its DDSes. In this case,
|
|
148
|
+
* parentSkipRecursion will be true and the if block above would handle it.
|
|
149
|
+
* 2. A new node was created but summarize was never called on it. This can mean that the summary that is
|
|
150
|
+
* generated may not have the data from this node. We should not continue, log and throw an error. This
|
|
151
|
+
* will help us identify these cases and take appropriate action.
|
|
152
|
+
*/
|
|
153
|
+
if (localPathsToUse === undefined) {
|
|
154
|
+
this.throwUnexpectedError({
|
|
155
|
+
eventName: "NodeNotSummarized",
|
|
156
|
+
proposalHandle,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const summary = new summarizerNodeUtils_1.SummaryNode(Object.assign(Object.assign({}, localPathsToUse), { referenceSequenceNumber: this.wipReferenceSequenceNumber, basePath: parentPath }));
|
|
160
|
+
const fullPathForChildren = summary.fullPathForChildren;
|
|
161
|
+
for (const child of this.children.values()) {
|
|
162
|
+
child.completeSummaryCore(proposalHandle, fullPathForChildren, this.wipSkipRecursion || parentSkipRecursion);
|
|
163
|
+
}
|
|
164
|
+
// Note that this overwrites existing pending summary with
|
|
165
|
+
// the same proposalHandle. If proposalHandle is something like
|
|
166
|
+
// a hash or unique identifier, this should be fine. If storage
|
|
167
|
+
// can return the same proposalHandle for a different summary,
|
|
168
|
+
// this should still be okay, because we should be proposing the
|
|
169
|
+
// newer one later which would have to overwrite the previous one.
|
|
170
|
+
this.pendingSummaries.set(proposalHandle, summary);
|
|
171
|
+
this.clearSummary();
|
|
172
|
+
}
|
|
173
|
+
clearSummary() {
|
|
174
|
+
this.wipReferenceSequenceNumber = undefined;
|
|
175
|
+
this.wipLocalPaths = undefined;
|
|
176
|
+
this.wipSkipRecursion = false;
|
|
177
|
+
this.wipSummaryLogger = undefined;
|
|
178
|
+
for (const child of this.children.values()) {
|
|
179
|
+
child.clearSummary();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,
|
|
184
|
+
* it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary),
|
|
185
|
+
* we skip the update. Otherwise, we fetch the latest snapshot and update latest summary based off of that.
|
|
186
|
+
*
|
|
187
|
+
* @returns A RefreshSummaryResult type which returns information based on the following three scenarios:
|
|
188
|
+
*
|
|
189
|
+
* 1. The latest summary was not updated.
|
|
190
|
+
*
|
|
191
|
+
* 2. The latest summary was updated and the summary corresponding to the params was being tracked.
|
|
192
|
+
*
|
|
193
|
+
* 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this
|
|
194
|
+
* case, the latest summary is updated based on the downloaded snapshot which is also returned.
|
|
195
|
+
*/
|
|
196
|
+
async refreshLatestSummary(proposalHandle, summaryRefSeq, fetchLatestSnapshot, readAndParseBlob, correlatedSummaryLogger) {
|
|
197
|
+
const eventProps = {
|
|
198
|
+
proposalHandle,
|
|
199
|
+
summaryRefSeq,
|
|
200
|
+
referenceSequenceNumber: this.referenceSequenceNumber,
|
|
201
|
+
};
|
|
202
|
+
return telemetry_utils_1.PerformanceEvent.timedExecAsync(this.logger, Object.assign({ eventName: "refreshLatestSummary" }, eventProps), async (event) => {
|
|
203
|
+
var _a;
|
|
204
|
+
// Refresh latest summary should not happen while a summary is in progress. If it does, it can result
|
|
205
|
+
// in inconsistent state, so, we should not continue;
|
|
206
|
+
if (this.isSummaryInProgress()) {
|
|
207
|
+
throw new telemetry_utils_1.LoggingError("UnexpectedRefreshDuringSummarize", {
|
|
208
|
+
inProgressSummaryRefSeq: this.wipReferenceSequenceNumber,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
if (proposalHandle !== undefined) {
|
|
212
|
+
const maybeSummaryNode = this.pendingSummaries.get(proposalHandle);
|
|
213
|
+
if (maybeSummaryNode !== undefined) {
|
|
214
|
+
this.refreshLatestSummaryFromPending(proposalHandle, maybeSummaryNode.referenceSequenceNumber);
|
|
215
|
+
eventProps.wasSummaryTracked = true;
|
|
216
|
+
eventProps.latestSummaryUpdated = true;
|
|
217
|
+
event.end(eventProps);
|
|
218
|
+
return {
|
|
219
|
+
latestSummaryUpdated: true,
|
|
220
|
+
wasSummaryTracked: true,
|
|
221
|
+
summaryRefSeq,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const props = {
|
|
225
|
+
summaryRefSeq,
|
|
226
|
+
pendingSize: (_a = this.pendingSummaries.size) !== null && _a !== void 0 ? _a : undefined,
|
|
227
|
+
};
|
|
228
|
+
this.logger.sendTelemetryEvent({
|
|
229
|
+
eventName: "PendingSummaryNotFound",
|
|
230
|
+
proposalHandle,
|
|
231
|
+
referenceSequenceNumber: this.referenceSequenceNumber,
|
|
232
|
+
details: JSON.stringify(props),
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// If the summary for which refresh is called is older than the latest tracked summary, ignore it.
|
|
236
|
+
if (this.referenceSequenceNumber >= summaryRefSeq) {
|
|
237
|
+
eventProps.latestSummaryUpdated = false;
|
|
238
|
+
event.end(eventProps);
|
|
239
|
+
return { latestSummaryUpdated: false };
|
|
240
|
+
}
|
|
241
|
+
// Fetch the latest snapshot and refresh state from it. Note that we need to use the reference sequence number
|
|
242
|
+
// of the fetched snapshot and not the "summaryRefSeq" that was passed in.
|
|
243
|
+
const { snapshotTree, snapshotRefSeq: fetchedSnapshotRefSeq } = await fetchLatestSnapshot();
|
|
244
|
+
// Possible re-entrancy. We may have updated latest summary state while fetching the snapshot. If the fetched
|
|
245
|
+
// snapshot is older than the latest tracked summary, ignore it.
|
|
246
|
+
if (this.referenceSequenceNumber >= fetchedSnapshotRefSeq) {
|
|
247
|
+
eventProps.latestSummaryUpdated = false;
|
|
248
|
+
event.end(eventProps);
|
|
249
|
+
return { latestSummaryUpdated: false };
|
|
250
|
+
}
|
|
251
|
+
await this.refreshLatestSummaryFromSnapshot(fetchedSnapshotRefSeq, snapshotTree, undefined, summarizerNodeUtils_1.EscapedPath.create(""), correlatedSummaryLogger, readAndParseBlob);
|
|
252
|
+
eventProps.latestSummaryUpdated = true;
|
|
253
|
+
eventProps.wasSummaryTracked = false;
|
|
254
|
+
eventProps.summaryRefSeq = fetchedSnapshotRefSeq;
|
|
255
|
+
event.end(eventProps);
|
|
256
|
+
return {
|
|
257
|
+
latestSummaryUpdated: true,
|
|
258
|
+
wasSummaryTracked: false,
|
|
259
|
+
snapshotTree,
|
|
260
|
+
summaryRefSeq: fetchedSnapshotRefSeq,
|
|
261
|
+
};
|
|
262
|
+
}, { start: true, end: true, cancel: "error" });
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Called when we get an ack from the server for a summary we've just sent. Updates the reference state of this node
|
|
266
|
+
* from the state in the pending summary queue.
|
|
267
|
+
* @param proposalHandle - Handle for the current proposal.
|
|
268
|
+
* @param referenceSequenceNumber - reference sequence number of sent summary.
|
|
269
|
+
*/
|
|
270
|
+
refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber) {
|
|
271
|
+
const summaryNode = this.pendingSummaries.get(proposalHandle);
|
|
272
|
+
if (summaryNode === undefined) {
|
|
273
|
+
// This should only happen if parent skipped recursion AND no prior summary existed.
|
|
274
|
+
(0, common_utils_1.assert)(this._latestSummary === undefined, 0x1a6 /* "Not found pending summary, but this node has previously completed a summary" */);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
(0, common_utils_1.assert)(referenceSequenceNumber === summaryNode.referenceSequenceNumber, 0x1a7 /* Pending summary reference sequence number should be consistent */);
|
|
279
|
+
// Clear earlier pending summaries
|
|
280
|
+
this.pendingSummaries.delete(proposalHandle);
|
|
281
|
+
}
|
|
282
|
+
this.refreshLatestSummaryCore(referenceSequenceNumber);
|
|
283
|
+
this._latestSummary = summaryNode;
|
|
284
|
+
// Propagate update to all child nodes
|
|
285
|
+
for (const child of this.children.values()) {
|
|
286
|
+
child.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
async refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob) {
|
|
290
|
+
// Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
|
|
291
|
+
if (this.referenceSequenceNumber >= referenceSequenceNumber) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.refreshLatestSummaryCore(referenceSequenceNumber);
|
|
295
|
+
this._latestSummary = new summarizerNodeUtils_1.SummaryNode({
|
|
296
|
+
referenceSequenceNumber,
|
|
297
|
+
basePath,
|
|
298
|
+
localPath,
|
|
299
|
+
});
|
|
300
|
+
const pathParts = [];
|
|
301
|
+
const { childrenTree, childrenPathPart } = (0, summarizerNodeUtils_1.parseSummaryForSubtrees)(snapshotTree);
|
|
302
|
+
if (childrenPathPart !== undefined) {
|
|
303
|
+
pathParts.push(childrenPathPart);
|
|
304
|
+
}
|
|
305
|
+
if (pathParts.length > 0) {
|
|
306
|
+
this._latestSummary.additionalPath = summarizerNodeUtils_1.EscapedPath.createAndConcat(pathParts);
|
|
307
|
+
}
|
|
308
|
+
// Propagate update to all child nodes
|
|
309
|
+
const pathForChildren = this._latestSummary.fullPathForChildren;
|
|
310
|
+
await Promise.all(Array.from(this.children)
|
|
311
|
+
.filter(([id]) => {
|
|
312
|
+
// Assuming subtrees missing from snapshot are newer than the snapshot,
|
|
313
|
+
// but might be nice to assert this using earliest seq for node.
|
|
314
|
+
return childrenTree.trees[id] !== undefined;
|
|
315
|
+
})
|
|
316
|
+
.map(async ([id, child]) => {
|
|
317
|
+
return child.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, childrenTree.trees[id], pathForChildren, summarizerNodeUtils_1.EscapedPath.create(id), correlatedSummaryLogger, readAndParseBlob);
|
|
318
|
+
}));
|
|
319
|
+
}
|
|
320
|
+
refreshLatestSummaryCore(referenceSequenceNumber) {
|
|
321
|
+
for (const [key, value] of this.pendingSummaries) {
|
|
322
|
+
if (value.referenceSequenceNumber < referenceSequenceNumber) {
|
|
323
|
+
this.pendingSummaries.delete(key);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
updateBaseSummaryState(snapshot) {
|
|
328
|
+
// Check base summary to see if it has any additional path parts
|
|
329
|
+
// separating child SummarizerNodes. Checks for .channels subtrees.
|
|
330
|
+
const { childrenPathPart } = (0, summarizerNodeUtils_1.parseSummaryForSubtrees)(snapshot);
|
|
331
|
+
if (childrenPathPart !== undefined && this._latestSummary !== undefined) {
|
|
332
|
+
this._latestSummary.additionalPath = summarizerNodeUtils_1.EscapedPath.create(childrenPathPart);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
recordChange(op) {
|
|
336
|
+
this.invalidate(op.sequenceNumber);
|
|
337
|
+
}
|
|
338
|
+
invalidate(sequenceNumber) {
|
|
339
|
+
if (sequenceNumber > this._changeSequenceNumber) {
|
|
340
|
+
this._changeSequenceNumber = sequenceNumber;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* True if a change has been recorded with sequence number exceeding
|
|
345
|
+
* the latest successfully acked summary reference sequence number.
|
|
346
|
+
* False implies that the previous summary can be reused.
|
|
347
|
+
*/
|
|
348
|
+
hasChanged() {
|
|
349
|
+
return this._changeSequenceNumber > this.referenceSequenceNumber;
|
|
350
|
+
}
|
|
351
|
+
get latestSummary() {
|
|
352
|
+
return this._latestSummary;
|
|
353
|
+
}
|
|
354
|
+
createChild(
|
|
355
|
+
/** Summarize function */
|
|
356
|
+
summarizeInternalFn,
|
|
357
|
+
/** Initial id or path part of this node */
|
|
358
|
+
id,
|
|
359
|
+
/**
|
|
360
|
+
* Information needed to create the node.
|
|
361
|
+
* If it is from a base summary, it will assert that a summary has been seen.
|
|
362
|
+
* Attach information if it is created from an attach op.
|
|
363
|
+
*/
|
|
364
|
+
createParam, config = {}) {
|
|
365
|
+
(0, common_utils_1.assert)(!this.children.has(id), 0x1ab /* "Create SummarizerNode child already exists" */);
|
|
366
|
+
const createDetails = this.getCreateDetailsForChild(id, createParam);
|
|
367
|
+
const child = new SummarizerNode(this.logger, summarizeInternalFn, config, createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, createDetails.telemetryNodeId);
|
|
368
|
+
// There may be additional state that has to be updated in this child. For example, if a summary is being
|
|
369
|
+
// tracked, the child's summary tracking state needs to be updated too. Same goes for pendingSummaries we might
|
|
370
|
+
// have outstanding on the parent in case we realize nodes in between Summary Op and Summary Ack.
|
|
371
|
+
this.maybeUpdateChildState(child, id);
|
|
372
|
+
this.children.set(id, child);
|
|
373
|
+
return child;
|
|
374
|
+
}
|
|
375
|
+
getChild(id) {
|
|
376
|
+
return this.children.get(id);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Returns the details needed to create a child node.
|
|
380
|
+
* @param id - Initial id or path part of the child node.
|
|
381
|
+
* @param createParam - Information needed to create the node.
|
|
382
|
+
* @returns the details needed to create the child node.
|
|
383
|
+
*/
|
|
384
|
+
getCreateDetailsForChild(id, createParam) {
|
|
385
|
+
var _a, _b;
|
|
386
|
+
let initialSummary;
|
|
387
|
+
let latestSummary;
|
|
388
|
+
let changeSequenceNumber;
|
|
389
|
+
const parentLatestSummary = this._latestSummary;
|
|
390
|
+
switch (createParam.type) {
|
|
391
|
+
case runtime_definitions_1.CreateSummarizerNodeSource.FromAttach: {
|
|
392
|
+
if (parentLatestSummary !== undefined &&
|
|
393
|
+
createParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber) {
|
|
394
|
+
// Prioritize latest summary if it was after this node was attached.
|
|
395
|
+
latestSummary = parentLatestSummary.createForChild(id);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
const summary = (0, runtime_utils_1.convertToSummaryTree)(createParam.snapshot);
|
|
399
|
+
initialSummary = {
|
|
400
|
+
sequenceNumber: createParam.sequenceNumber,
|
|
401
|
+
id,
|
|
402
|
+
summary,
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
changeSequenceNumber = createParam.sequenceNumber;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
case runtime_definitions_1.CreateSummarizerNodeSource.FromSummary: {
|
|
409
|
+
if (this.initialSummary === undefined) {
|
|
410
|
+
(0, common_utils_1.assert)(!!parentLatestSummary, 0x1ac /* "Cannot create child from summary if parent does not have latest summary" */);
|
|
411
|
+
}
|
|
412
|
+
// fallthrough to local
|
|
413
|
+
}
|
|
414
|
+
case runtime_definitions_1.CreateSummarizerNodeSource.Local: {
|
|
415
|
+
const parentInitialSummary = this.initialSummary;
|
|
416
|
+
if (parentInitialSummary !== undefined) {
|
|
417
|
+
let childSummary;
|
|
418
|
+
if (parentInitialSummary.summary !== undefined) {
|
|
419
|
+
const { childrenTree } = (0, summarizerNodeUtils_1.parseSummaryTreeForSubtrees)(parentInitialSummary.summary.summary);
|
|
420
|
+
(0, common_utils_1.assert)(childrenTree.type === protocol_definitions_1.SummaryType.Tree, 0x1d6 /* "Parent summary object is not a tree" */);
|
|
421
|
+
childSummary = childrenTree.tree[id];
|
|
422
|
+
}
|
|
423
|
+
if (createParam.type === runtime_definitions_1.CreateSummarizerNodeSource.FromSummary) {
|
|
424
|
+
// Locally created would not have differential subtree.
|
|
425
|
+
(0, common_utils_1.assert)(!!childSummary, 0x1ad /* "Missing child summary tree" */);
|
|
426
|
+
}
|
|
427
|
+
let childSummaryWithStats;
|
|
428
|
+
if (childSummary !== undefined) {
|
|
429
|
+
(0, common_utils_1.assert)(childSummary.type === protocol_definitions_1.SummaryType.Tree, 0x1ae /* "Child summary object is not a tree" */);
|
|
430
|
+
childSummaryWithStats = {
|
|
431
|
+
summary: childSummary,
|
|
432
|
+
stats: (0, runtime_utils_1.calculateStats)(childSummary),
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
initialSummary = {
|
|
436
|
+
sequenceNumber: parentInitialSummary.sequenceNumber,
|
|
437
|
+
id,
|
|
438
|
+
summary: childSummaryWithStats,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
latestSummary = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.createForChild(id);
|
|
442
|
+
changeSequenceNumber = (_a = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.referenceSequenceNumber) !== null && _a !== void 0 ? _a : -1;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
default: {
|
|
446
|
+
const type = createParam.type;
|
|
447
|
+
(0, common_utils_1.unreachableCase)(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
const childtelemetryNodeId = `${(_b = this.telemetryNodeId) !== null && _b !== void 0 ? _b : ""}/${id}`;
|
|
451
|
+
return {
|
|
452
|
+
initialSummary,
|
|
453
|
+
latestSummary,
|
|
454
|
+
changeSequenceNumber,
|
|
455
|
+
telemetryNodeId: childtelemetryNodeId,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Updates the state of the child if required. For example, if a summary is currently being tracked, the child's
|
|
460
|
+
* summary tracking state needs to be updated too.
|
|
461
|
+
* Also, in case a child node gets realized in between Summary Op and Summary Ack, let's initialize the child's
|
|
462
|
+
* pending summary as well.
|
|
463
|
+
* @param child - The child node whose state is to be updated.
|
|
464
|
+
* @param id - Initial id or path part of this node
|
|
465
|
+
*
|
|
466
|
+
*/
|
|
467
|
+
maybeUpdateChildState(child, id) {
|
|
468
|
+
// If a summary is in progress, this child was created after the summary started. So, we need to update the
|
|
469
|
+
// child's summary state as well.
|
|
470
|
+
if (this.isSummaryInProgress()) {
|
|
471
|
+
child.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;
|
|
472
|
+
}
|
|
473
|
+
// In case we have pending summaries on the parent, let's initialize it on the child.
|
|
474
|
+
if (child._latestSummary !== undefined) {
|
|
475
|
+
for (const [key, value] of this.pendingSummaries.entries()) {
|
|
476
|
+
const newLatestSummaryNode = new summarizerNodeUtils_1.SummaryNode({
|
|
477
|
+
referenceSequenceNumber: value.referenceSequenceNumber,
|
|
478
|
+
basePath: child._latestSummary.basePath,
|
|
479
|
+
localPath: child._latestSummary.localPath,
|
|
480
|
+
});
|
|
481
|
+
child.addPendingSummary(key, newLatestSummaryNode);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
addPendingSummary(key, summary) {
|
|
486
|
+
this.pendingSummaries.set(key, summary);
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Tells whether summary tracking is in progress. True if "startSummary" API is called before summarize.
|
|
490
|
+
*/
|
|
491
|
+
isSummaryInProgress() {
|
|
492
|
+
return this.wipReferenceSequenceNumber !== undefined;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Creates and throws an error due to unexpected conditions.
|
|
496
|
+
*/
|
|
497
|
+
throwUnexpectedError(eventProps) {
|
|
498
|
+
const error = new telemetry_utils_1.LoggingError(eventProps.eventName, Object.assign(Object.assign({}, eventProps), { referenceSequenceNumber: this.wipReferenceSequenceNumber, id: {
|
|
499
|
+
tag: telemetry_utils_1.TelemetryDataTag.CodeArtifact,
|
|
500
|
+
value: this.telemetryNodeId,
|
|
501
|
+
} }));
|
|
502
|
+
this.logger.sendErrorEvent(eventProps, error);
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
exports.SummarizerNode = SummarizerNode;
|
|
507
|
+
/**
|
|
508
|
+
* Creates a root summarizer node.
|
|
509
|
+
* @param logger - Logger to use within SummarizerNode
|
|
510
|
+
* @param summarizeInternalFn - Function to generate summary
|
|
511
|
+
* @param changeSequenceNumber - Sequence number of latest change to new node/subtree
|
|
512
|
+
* @param referenceSequenceNumber - Reference sequence number of last acked summary,
|
|
513
|
+
* or undefined if not loaded from summary
|
|
514
|
+
* @param config - Configure behavior of summarizer node
|
|
515
|
+
*/
|
|
516
|
+
const createRootSummarizerNode = (logger, summarizeInternalFn, changeSequenceNumber, referenceSequenceNumber, config = {}) => new SummarizerNode(logger, summarizeInternalFn, config, changeSequenceNumber, referenceSequenceNumber === undefined
|
|
517
|
+
? undefined
|
|
518
|
+
: summarizerNodeUtils_1.SummaryNode.createForRoot(referenceSequenceNumber), undefined /* initialSummary */, undefined /* wipSummaryLogger */, "" /* telemetryNodeId */);
|
|
519
|
+
exports.createRootSummarizerNode = createRootSummarizerNode;
|
|
520
|
+
//# sourceMappingURL=summarizerNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarizerNode.js","sourceRoot":"","sources":["../../../src/summary/summarizerNode/summarizerN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AAK,SAAS,CAAC;IACtD,CAAC;IAED;;OAEG;IACO,oBAAoB,CAAC,UAAgC;QAC9D,MAAM,KAAK,GAAG,IAAI,8BAAY,CAAC,UAAU,CAAC,SAAS,kCAC/C,UAAU,KACb,uBAAuB,EAAE,IAAI,CAAC,0BAA0B,EACxD,EAAE,EAAE;gBACH,GAAG,EAAE,kCAAgB,CAAC,YAAY;gBAClC,KAAK,EAAE,IAAI,CAAC,eAAe;aAC3B,IACA,CAAC;QACH,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC9C,MAAM,KAAK,CAAC;IACb,CAAC;CACD;AA5oBD,wCA4oBC;AAED;;;;;;;;GAQG;AACI,MAAM,wBAAwB,GAAG,CACvC,MAAwB,EACxB,mBAAwC,EACxC,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAgC,EAAE,EACZ,EAAE,CACxB,IAAI,cAAc,CACjB,MAAM,EACN,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,uBAAuB,KAAK,SAAS;IACpC,CAAC,CAAC,SAAS;IACX,CAAC,CAAC,iCAAW,CAAC,aAAa,CAAC,uBAAuB,CAAC,EACrD,SAAS,CAAC,oBAAoB,EAC9B,SAAS,CAAC,sBAAsB,EAChC,EAAE,CAAC,qBAAqB,CACxB,CAAC;AAlBU,QAAA,wBAAwB,4BAkBlC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tISummarizerNode,\n\tISummarizerNodeConfig,\n\tISummarizeResult,\n\tISummaryTreeWithStats,\n\tCreateChildSummarizerNodeParam,\n\tCreateSummarizerNodeSource,\n\tSummarizeInternalFn,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n\tISequencedDocumentMessage,\n\tSummaryType,\n\tISnapshotTree,\n\tSummaryObject,\n} from \"@fluidframework/protocol-definitions\";\nimport { ITelemetryErrorEvent, ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, unreachableCase } from \"@fluidframework/common-utils\";\nimport {\n\tconvertToSummaryTree,\n\tcalculateStats,\n\tmergeStats,\n\tReadAndParseBlob,\n} from \"@fluidframework/runtime-utils\";\nimport {\n\tChildLogger,\n\tLoggingError,\n\tPerformanceEvent,\n\tTelemetryDataTag,\n} from \"@fluidframework/telemetry-utils\";\nimport {\n\tEscapedPath,\n\tICreateChildDetails,\n\tIFetchSnapshotResult,\n\tIInitialSummary,\n\tISummarizerNodeRootContract,\n\tparseSummaryForSubtrees,\n\tparseSummaryTreeForSubtrees,\n\tRefreshSummaryResult,\n\tSummaryNode,\n} from \"./summarizerNodeUtils\";\n\nexport interface IRootSummarizerNode extends ISummarizerNode, ISummarizerNodeRootContract {}\n\n/**\n * Encapsulates the summarizing work and state of an individual tree node in the\n * summary tree. It tracks changes and allows for optimizations when unchanged, or\n * can allow for fallback summaries to be generated when an error is encountered.\n * Usage is for the root node to call startSummary first to begin tracking a WIP\n * (work in progress) summary. Then all nodes will call summarize to summaries their\n * individual parts. Once completed and uploaded to storage, the root node will call\n * completeSummary or clearSummary to clear the WIP summary tracking state if something\n * went wrong. The SummarizerNodes will track all pending summaries that have been\n * recorded by the completeSummary call. When one of them is acked, the root node should\n * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline\n * latest successful summary.\n */\nexport class SummarizerNode implements IRootSummarizerNode {\n\t/**\n\t * The reference sequence number of the most recent acked summary.\n\t * Returns 0 if there is not yet an acked summary.\n\t */\n\tpublic get referenceSequenceNumber() {\n\t\treturn this._latestSummary?.referenceSequenceNumber ?? 0;\n\t}\n\n\tprotected readonly children = new Map<string, SummarizerNode>();\n\tprotected readonly pendingSummaries = new Map<string, SummaryNode>();\n\tprotected wipReferenceSequenceNumber: number | undefined;\n\tprivate wipLocalPaths: { localPath: EscapedPath; additionalPath?: EscapedPath } | undefined;\n\tprivate wipSkipRecursion = false;\n\n\tprotected readonly logger: ITelemetryLogger;\n\n\t/**\n\t * Do not call constructor directly.\n\t * Use createRootSummarizerNode to create root node, or createChild to create child nodes.\n\t */\n\tpublic constructor(\n\t\tbaseLogger: ITelemetryLogger,\n\t\tprivate readonly summarizeInternalFn: SummarizeInternalFn,\n\t\tconfig: ISummarizerNodeConfig,\n\t\tprivate _changeSequenceNumber: number,\n\t\t/** Undefined means created without summary */\n\t\tprivate _latestSummary?: SummaryNode,\n\t\tprivate readonly initialSummary?: IInitialSummary,\n\t\tprotected wipSummaryLogger?: ITelemetryLogger,\n\t\t/** A unique id of this node to be logged when sending telemetry. */\n\t\tprotected telemetryNodeId?: string,\n\t) {\n\t\tthis.canReuseHandle = config.canReuseHandle ?? true;\n\t\t// All logs posted by the summarizer node should include the telemetryNodeId.\n\t\tthis.logger = ChildLogger.create(baseLogger, undefined /* namespace */, {\n\t\t\tall: {\n\t\t\t\tid: {\n\t\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\t\tvalue: this.telemetryNodeId,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t}\n\n\tpublic startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger) {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger === undefined,\n\t\t\t0x19f /* \"wipSummaryLogger should not be set yet in startSummary\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.wipReferenceSequenceNumber === undefined,\n\t\t\t0x1a0 /* \"Already tracking a summary\" */,\n\t\t);\n\n\t\tthis.wipSummaryLogger = summaryLogger;\n\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.startSummary(referenceSequenceNumber, this.wipSummaryLogger);\n\t\t}\n\t\tthis.wipReferenceSequenceNumber = referenceSequenceNumber;\n\t}\n\n\tpublic async summarize(\n\t\tfullTree: boolean,\n\t\ttrackState: boolean = true,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummarizeResult> {\n\t\tassert(\n\t\t\tthis.isSummaryInProgress(),\n\t\t\t0x1a1 /* \"summarize should not be called when not tracking the summary\" */,\n\t\t);\n\t\tassert(\n\t\t\tthis.wipSummaryLogger !== undefined,\n\t\t\t0x1a2 /* \"wipSummaryLogger should have been set in startSummary or ctor\" */,\n\t\t);\n\n\t\t// Try to reuse the tree if unchanged\n\t\tif (this.canReuseHandle && !fullTree && !this.hasChanged()) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\tthis.wipLocalPaths = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t\tthis.wipSkipRecursion = true;\n\t\t\t\tconst stats = mergeStats();\n\t\t\t\tstats.handleNodeCount++;\n\t\t\t\treturn {\n\t\t\t\t\tsummary: {\n\t\t\t\t\t\ttype: SummaryType.Handle,\n\t\t\t\t\t\thandle: latestSummary.fullPath.path,\n\t\t\t\t\t\thandleType: SummaryType.Tree,\n\t\t\t\t\t},\n\t\t\t\t\tstats,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\tconst result = await this.summarizeInternalFn(fullTree, true, telemetryContext);\n\t\tthis.wipLocalPaths = { localPath: EscapedPath.create(result.id) };\n\t\tif (result.pathPartsForChildren !== undefined) {\n\t\t\tthis.wipLocalPaths.additionalPath = EscapedPath.createAndConcat(\n\t\t\t\tresult.pathPartsForChildren,\n\t\t\t);\n\t\t}\n\t\treturn { summary: result.summary, stats: result.stats };\n\t}\n\n\t/**\n\t * Complete the WIP summary for the given proposalHandle\n\t */\n\tpublic completeSummary(proposalHandle: string) {\n\t\tthis.completeSummaryCore(proposalHandle, undefined, false);\n\t}\n\n\t/**\n\t * Recursive implementation for completeSummary, with additional internal-only parameters\n\t */\n\tprotected completeSummaryCore(\n\t\tproposalHandle: string,\n\t\tparentPath: EscapedPath | undefined,\n\t\tparentSkipRecursion: boolean,\n\t) {\n\t\tassert(\n\t\t\tthis.wipSummaryLogger !== undefined,\n\t\t\t0x1a3 /* \"wipSummaryLogger should have been set in startSummary or ctor\" */,\n\t\t);\n\t\tassert(this.wipReferenceSequenceNumber !== undefined, 0x1a4 /* \"Not tracking a summary\" */);\n\t\tlet localPathsToUse = this.wipLocalPaths;\n\n\t\tif (parentSkipRecursion) {\n\t\t\tconst latestSummary = this._latestSummary;\n\t\t\tif (latestSummary !== undefined) {\n\t\t\t\t// This case the parent node created a failure summary or was reused.\n\t\t\t\t// This node and all children should only try to reference their path\n\t\t\t\t// by its last known good state in the actual summary tree.\n\t\t\t\t// If parent fails or is reused, the child summarize is not called so\n\t\t\t\t// it did not get a chance to change its paths.\n\t\t\t\t// In this case, essentially only propagate the new summary ref seq num.\n\t\t\t\tlocalPathsToUse = {\n\t\t\t\t\tlocalPath: latestSummary.localPath,\n\t\t\t\t\tadditionalPath: latestSummary.additionalPath,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// This case the child is added after the latest non-failure summary.\n\t\t\t\t// This node and all children should consider themselves as still not\n\t\t\t\t// having a successful summary yet.\n\t\t\t\t// We cannot \"reuse\" this node if unchanged since that summary, because\n\t\t\t\t// handles will be unable to point to that node. It never made it to the\n\t\t\t\t// tree itself, and only exists as an attach op in the _outstandingOps.\n\t\t\t\tthis.clearSummary();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The absence of wip local path indicates that summarize was not called for this node. This can happen if:\n\t\t * 1. A child node was created after summarize was already called on the parent. For example, a data store\n\t\t * is realized (loaded) after summarize was called on it creating summarizer nodes for its DDSes. In this case,\n\t\t * parentSkipRecursion will be true and the if block above would handle it.\n\t\t * 2. A new node was created but summarize was never called on it. This can mean that the summary that is\n\t\t * generated may not have the data from this node. We should not continue, log and throw an error. This\n\t\t * will help us identify these cases and take appropriate action.\n\t\t */\n\t\tif (localPathsToUse === undefined) {\n\t\t\tthis.throwUnexpectedError({\n\t\t\t\teventName: \"NodeNotSummarized\",\n\t\t\t\tproposalHandle,\n\t\t\t});\n\t\t}\n\n\t\tconst summary = new SummaryNode({\n\t\t\t...localPathsToUse,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\tbasePath: parentPath,\n\t\t});\n\t\tconst fullPathForChildren = summary.fullPathForChildren;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.completeSummaryCore(\n\t\t\t\tproposalHandle,\n\t\t\t\tfullPathForChildren,\n\t\t\t\tthis.wipSkipRecursion || parentSkipRecursion,\n\t\t\t);\n\t\t}\n\t\t// Note that this overwrites existing pending summary with\n\t\t// the same proposalHandle. If proposalHandle is something like\n\t\t// a hash or unique identifier, this should be fine. If storage\n\t\t// can return the same proposalHandle for a different summary,\n\t\t// this should still be okay, because we should be proposing the\n\t\t// newer one later which would have to overwrite the previous one.\n\t\tthis.pendingSummaries.set(proposalHandle, summary);\n\t\tthis.clearSummary();\n\t}\n\n\tpublic clearSummary() {\n\t\tthis.wipReferenceSequenceNumber = undefined;\n\t\tthis.wipLocalPaths = undefined;\n\t\tthis.wipSkipRecursion = false;\n\t\tthis.wipSummaryLogger = undefined;\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.clearSummary();\n\t\t}\n\t}\n\n\t/**\n\t * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,\n\t * it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary),\n\t * we skip the update. Otherwise, we fetch the latest snapshot and update latest summary based off of that.\n\t *\n\t * @returns A RefreshSummaryResult type which returns information based on the following three scenarios:\n\t *\n\t * 1. The latest summary was not updated.\n\t *\n\t * 2. The latest summary was updated and the summary corresponding to the params was being tracked.\n\t *\n\t * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this\n\t * case, the latest summary is updated based on the downloaded snapshot which is also returned.\n\t */\n\tpublic async refreshLatestSummary(\n\t\tproposalHandle: string | undefined,\n\t\tsummaryRefSeq: number,\n\t\tfetchLatestSnapshot: () => Promise<IFetchSnapshotResult>,\n\t\treadAndParseBlob: ReadAndParseBlob,\n\t\tcorrelatedSummaryLogger: ITelemetryLogger,\n\t): Promise<RefreshSummaryResult> {\n\t\tconst eventProps: {\n\t\t\tproposalHandle: string | undefined;\n\t\t\tsummaryRefSeq: number;\n\t\t\treferenceSequenceNumber: number;\n\t\t\tlatestSummaryUpdated?: boolean;\n\t\t\twasSummaryTracked?: boolean;\n\t\t} = {\n\t\t\tproposalHandle,\n\t\t\tsummaryRefSeq,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t};\n\t\treturn PerformanceEvent.timedExecAsync(\n\t\t\tthis.logger,\n\t\t\t{\n\t\t\t\teventName: \"refreshLatestSummary\",\n\t\t\t\t...eventProps,\n\t\t\t},\n\t\t\tasync (event) => {\n\t\t\t\t// Refresh latest summary should not happen while a summary is in progress. If it does, it can result\n\t\t\t\t// in inconsistent state, so, we should not continue;\n\t\t\t\tif (this.isSummaryInProgress()) {\n\t\t\t\t\tthrow new LoggingError(\"UnexpectedRefreshDuringSummarize\", {\n\t\t\t\t\t\tinProgressSummaryRefSeq: this.wipReferenceSequenceNumber,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\tif (proposalHandle !== undefined) {\n\t\t\t\t\tconst maybeSummaryNode = this.pendingSummaries.get(proposalHandle);\n\n\t\t\t\t\tif (maybeSummaryNode !== undefined) {\n\t\t\t\t\t\tthis.refreshLatestSummaryFromPending(\n\t\t\t\t\t\t\tproposalHandle,\n\t\t\t\t\t\t\tmaybeSummaryNode.referenceSequenceNumber,\n\t\t\t\t\t\t);\n\t\t\t\t\t\teventProps.wasSummaryTracked = true;\n\t\t\t\t\t\teventProps.latestSummaryUpdated = true;\n\t\t\t\t\t\tevent.end(eventProps);\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tlatestSummaryUpdated: true,\n\t\t\t\t\t\t\twasSummaryTracked: true,\n\t\t\t\t\t\t\tsummaryRefSeq,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\tconst props = {\n\t\t\t\t\t\tsummaryRefSeq,\n\t\t\t\t\t\tpendingSize: this.pendingSummaries.size ?? undefined,\n\t\t\t\t\t};\n\t\t\t\t\tthis.logger.sendTelemetryEvent({\n\t\t\t\t\t\teventName: \"PendingSummaryNotFound\",\n\t\t\t\t\t\tproposalHandle,\n\t\t\t\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// If the summary for which refresh is called is older than the latest tracked summary, ignore it.\n\t\t\t\tif (this.referenceSequenceNumber >= summaryRefSeq) {\n\t\t\t\t\teventProps.latestSummaryUpdated = false;\n\t\t\t\t\tevent.end(eventProps);\n\t\t\t\t\treturn { latestSummaryUpdated: false };\n\t\t\t\t}\n\n\t\t\t\t// Fetch the latest snapshot and refresh state from it. Note that we need to use the reference sequence number\n\t\t\t\t// of the fetched snapshot and not the \"summaryRefSeq\" that was passed in.\n\t\t\t\tconst { snapshotTree, snapshotRefSeq: fetchedSnapshotRefSeq } =\n\t\t\t\t\tawait fetchLatestSnapshot();\n\n\t\t\t\t// Possible re-entrancy. We may have updated latest summary state while fetching the snapshot. If the fetched\n\t\t\t\t// snapshot is older than the latest tracked summary, ignore it.\n\t\t\t\tif (this.referenceSequenceNumber >= fetchedSnapshotRefSeq) {\n\t\t\t\t\teventProps.latestSummaryUpdated = false;\n\t\t\t\t\tevent.end(eventProps);\n\t\t\t\t\treturn { latestSummaryUpdated: false };\n\t\t\t\t}\n\n\t\t\t\tawait this.refreshLatestSummaryFromSnapshot(\n\t\t\t\t\tfetchedSnapshotRefSeq,\n\t\t\t\t\tsnapshotTree,\n\t\t\t\t\tundefined,\n\t\t\t\t\tEscapedPath.create(\"\"),\n\t\t\t\t\tcorrelatedSummaryLogger,\n\t\t\t\t\treadAndParseBlob,\n\t\t\t\t);\n\n\t\t\t\teventProps.latestSummaryUpdated = true;\n\t\t\t\teventProps.wasSummaryTracked = false;\n\t\t\t\teventProps.summaryRefSeq = fetchedSnapshotRefSeq;\n\t\t\t\tevent.end(eventProps);\n\t\t\t\treturn {\n\t\t\t\t\tlatestSummaryUpdated: true,\n\t\t\t\t\twasSummaryTracked: false,\n\t\t\t\t\tsnapshotTree,\n\t\t\t\t\tsummaryRefSeq: fetchedSnapshotRefSeq,\n\t\t\t\t};\n\t\t\t},\n\t\t\t{ start: true, end: true, cancel: \"error\" },\n\t\t);\n\t}\n\t/**\n\t * Called when we get an ack from the server for a summary we've just sent. Updates the reference state of this node\n\t * from the state in the pending summary queue.\n\t * @param proposalHandle - Handle for the current proposal.\n\t * @param referenceSequenceNumber - reference sequence number of sent summary.\n\t */\n\tprotected refreshLatestSummaryFromPending(\n\t\tproposalHandle: string,\n\t\treferenceSequenceNumber: number,\n\t): void {\n\t\tconst summaryNode = this.pendingSummaries.get(proposalHandle);\n\t\tif (summaryNode === undefined) {\n\t\t\t// This should only happen if parent skipped recursion AND no prior summary existed.\n\t\t\tassert(\n\t\t\t\tthis._latestSummary === undefined,\n\t\t\t\t0x1a6 /* \"Not found pending summary, but this node has previously completed a summary\" */,\n\t\t\t);\n\t\t\treturn;\n\t\t} else {\n\t\t\tassert(\n\t\t\t\treferenceSequenceNumber === summaryNode.referenceSequenceNumber,\n\t\t\t\t0x1a7 /* Pending summary reference sequence number should be consistent */,\n\t\t\t);\n\n\t\t\t// Clear earlier pending summaries\n\t\t\tthis.pendingSummaries.delete(proposalHandle);\n\t\t}\n\n\t\tthis.refreshLatestSummaryCore(referenceSequenceNumber);\n\n\t\tthis._latestSummary = summaryNode;\n\t\t// Propagate update to all child nodes\n\t\tfor (const child of this.children.values()) {\n\t\t\tchild.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);\n\t\t}\n\t}\n\n\tprotected async refreshLatestSummaryFromSnapshot(\n\t\treferenceSequenceNumber: number,\n\t\tsnapshotTree: ISnapshotTree,\n\t\tbasePath: EscapedPath | undefined,\n\t\tlocalPath: EscapedPath,\n\t\tcorrelatedSummaryLogger: ITelemetryLogger,\n\t\treadAndParseBlob: ReadAndParseBlob,\n\t): Promise<void> {\n\t\t// Possible re-entrancy. If we have already seen a summary later than this one, ignore it.\n\t\tif (this.referenceSequenceNumber >= referenceSequenceNumber) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.refreshLatestSummaryCore(referenceSequenceNumber);\n\n\t\tthis._latestSummary = new SummaryNode({\n\t\t\treferenceSequenceNumber,\n\t\t\tbasePath,\n\t\t\tlocalPath,\n\t\t});\n\n\t\tconst pathParts: string[] = [];\n\t\tconst { childrenTree, childrenPathPart } = parseSummaryForSubtrees(snapshotTree);\n\t\tif (childrenPathPart !== undefined) {\n\t\t\tpathParts.push(childrenPathPart);\n\t\t}\n\n\t\tif (pathParts.length > 0) {\n\t\t\tthis._latestSummary.additionalPath = EscapedPath.createAndConcat(pathParts);\n\t\t}\n\n\t\t// Propagate update to all child nodes\n\t\tconst pathForChildren = this._latestSummary.fullPathForChildren;\n\t\tawait Promise.all(\n\t\t\tArray.from(this.children)\n\t\t\t\t.filter(([id]) => {\n\t\t\t\t\t// Assuming subtrees missing from snapshot are newer than the snapshot,\n\t\t\t\t\t// but might be nice to assert this using earliest seq for node.\n\t\t\t\t\treturn childrenTree.trees[id] !== undefined;\n\t\t\t\t})\n\t\t\t\t.map(async ([id, child]) => {\n\t\t\t\t\treturn child.refreshLatestSummaryFromSnapshot(\n\t\t\t\t\t\treferenceSequenceNumber,\n\t\t\t\t\t\tchildrenTree.trees[id],\n\t\t\t\t\t\tpathForChildren,\n\t\t\t\t\t\tEscapedPath.create(id),\n\t\t\t\t\t\tcorrelatedSummaryLogger,\n\t\t\t\t\t\treadAndParseBlob,\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t);\n\t}\n\n\tprivate refreshLatestSummaryCore(referenceSequenceNumber: number): void {\n\t\tfor (const [key, value] of this.pendingSummaries) {\n\t\t\tif (value.referenceSequenceNumber < referenceSequenceNumber) {\n\t\t\t\tthis.pendingSummaries.delete(key);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic updateBaseSummaryState(snapshot: ISnapshotTree) {\n\t\t// Check base summary to see if it has any additional path parts\n\t\t// separating child SummarizerNodes. Checks for .channels subtrees.\n\t\tconst { childrenPathPart } = parseSummaryForSubtrees(snapshot);\n\t\tif (childrenPathPart !== undefined && this._latestSummary !== undefined) {\n\t\t\tthis._latestSummary.additionalPath = EscapedPath.create(childrenPathPart);\n\t\t}\n\t}\n\n\tpublic recordChange(op: ISequencedDocumentMessage): void {\n\t\tthis.invalidate(op.sequenceNumber);\n\t}\n\n\tpublic invalidate(sequenceNumber: number): void {\n\t\tif (sequenceNumber > this._changeSequenceNumber) {\n\t\t\tthis._changeSequenceNumber = sequenceNumber;\n\t\t}\n\t}\n\n\t/**\n\t * True if a change has been recorded with sequence number exceeding\n\t * the latest successfully acked summary reference sequence number.\n\t * False implies that the previous summary can be reused.\n\t */\n\tprotected hasChanged(): boolean {\n\t\treturn this._changeSequenceNumber > this.referenceSequenceNumber;\n\t}\n\n\tpublic get latestSummary(): Readonly<SummaryNode> | undefined {\n\t\treturn this._latestSummary;\n\t}\n\n\tprotected readonly canReuseHandle: boolean;\n\n\tpublic createChild(\n\t\t/** Summarize function */\n\t\tsummarizeInternalFn: SummarizeInternalFn,\n\t\t/** Initial id or path part of this node */\n\t\tid: string,\n\t\t/**\n\t\t * Information needed to create the node.\n\t\t * If it is from a base summary, it will assert that a summary has been seen.\n\t\t * Attach information if it is created from an attach op.\n\t\t */\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t\tconfig: ISummarizerNodeConfig = {},\n\t): ISummarizerNode {\n\t\tassert(!this.children.has(id), 0x1ab /* \"Create SummarizerNode child already exists\" */);\n\n\t\tconst createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);\n\t\tconst child = new SummarizerNode(\n\t\t\tthis.logger,\n\t\t\tsummarizeInternalFn,\n\t\t\tconfig,\n\t\t\tcreateDetails.changeSequenceNumber,\n\t\t\tcreateDetails.latestSummary,\n\t\t\tcreateDetails.initialSummary,\n\t\t\tthis.wipSummaryLogger,\n\t\t\tcreateDetails.telemetryNodeId,\n\t\t);\n\n\t\t// There may be additional state that has to be updated in this child. For example, if a summary is being\n\t\t// tracked, the child's summary tracking state needs to be updated too. Same goes for pendingSummaries we might\n\t\t// have outstanding on the parent in case we realize nodes in between Summary Op and Summary Ack.\n\t\tthis.maybeUpdateChildState(child, id);\n\n\t\tthis.children.set(id, child);\n\t\treturn child;\n\t}\n\n\tpublic getChild(id: string): ISummarizerNode | undefined {\n\t\treturn this.children.get(id);\n\t}\n\n\t/**\n\t * Returns the details needed to create a child node.\n\t * @param id - Initial id or path part of the child node.\n\t * @param createParam - Information needed to create the node.\n\t * @returns the details needed to create the child node.\n\t */\n\tprotected getCreateDetailsForChild(\n\t\tid: string,\n\t\tcreateParam: CreateChildSummarizerNodeParam,\n\t): ICreateChildDetails {\n\t\tlet initialSummary: IInitialSummary | undefined;\n\t\tlet latestSummary: SummaryNode | undefined;\n\t\tlet changeSequenceNumber: number;\n\n\t\tconst parentLatestSummary = this._latestSummary;\n\t\tswitch (createParam.type) {\n\t\t\tcase CreateSummarizerNodeSource.FromAttach: {\n\t\t\t\tif (\n\t\t\t\t\tparentLatestSummary !== undefined &&\n\t\t\t\t\tcreateParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber\n\t\t\t\t) {\n\t\t\t\t\t// Prioritize latest summary if it was after this node was attached.\n\t\t\t\t\tlatestSummary = parentLatestSummary.createForChild(id);\n\t\t\t\t} else {\n\t\t\t\t\tconst summary = convertToSummaryTree(\n\t\t\t\t\t\tcreateParam.snapshot,\n\t\t\t\t\t) as ISummaryTreeWithStats;\n\t\t\t\t\tinitialSummary = {\n\t\t\t\t\t\tsequenceNumber: createParam.sequenceNumber,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tsummary,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tchangeSequenceNumber = createParam.sequenceNumber;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase CreateSummarizerNodeSource.FromSummary: {\n\t\t\t\tif (this.initialSummary === undefined) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!!parentLatestSummary,\n\t\t\t\t\t\t0x1ac /* \"Cannot create child from summary if parent does not have latest summary\" */,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// fallthrough to local\n\t\t\t}\n\t\t\tcase CreateSummarizerNodeSource.Local: {\n\t\t\t\tconst parentInitialSummary = this.initialSummary;\n\t\t\t\tif (parentInitialSummary !== undefined) {\n\t\t\t\t\tlet childSummary: SummaryObject | undefined;\n\t\t\t\t\tif (parentInitialSummary.summary !== undefined) {\n\t\t\t\t\t\tconst { childrenTree } = parseSummaryTreeForSubtrees(\n\t\t\t\t\t\t\tparentInitialSummary.summary.summary,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tchildrenTree.type === SummaryType.Tree,\n\t\t\t\t\t\t\t0x1d6 /* \"Parent summary object is not a tree\" */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tchildSummary = childrenTree.tree[id];\n\t\t\t\t\t}\n\t\t\t\t\tif (createParam.type === CreateSummarizerNodeSource.FromSummary) {\n\t\t\t\t\t\t// Locally created would not have differential subtree.\n\t\t\t\t\t\tassert(!!childSummary, 0x1ad /* \"Missing child summary tree\" */);\n\t\t\t\t\t}\n\t\t\t\t\tlet childSummaryWithStats: ISummaryTreeWithStats | undefined;\n\t\t\t\t\tif (childSummary !== undefined) {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tchildSummary.type === SummaryType.Tree,\n\t\t\t\t\t\t\t0x1ae /* \"Child summary object is not a tree\" */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tchildSummaryWithStats = {\n\t\t\t\t\t\t\tsummary: childSummary,\n\t\t\t\t\t\t\tstats: calculateStats(childSummary),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tinitialSummary = {\n\t\t\t\t\t\tsequenceNumber: parentInitialSummary.sequenceNumber,\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tsummary: childSummaryWithStats,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tlatestSummary = parentLatestSummary?.createForChild(id);\n\t\t\t\tchangeSequenceNumber = parentLatestSummary?.referenceSequenceNumber ?? -1;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst type = (createParam as unknown as CreateChildSummarizerNodeParam).type;\n\t\t\t\tunreachableCase(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);\n\t\t\t}\n\t\t}\n\n\t\tconst childtelemetryNodeId = `${this.telemetryNodeId ?? \"\"}/${id}`;\n\n\t\treturn {\n\t\t\tinitialSummary,\n\t\t\tlatestSummary,\n\t\t\tchangeSequenceNumber,\n\t\t\ttelemetryNodeId: childtelemetryNodeId,\n\t\t};\n\t}\n\n\t/**\n\t * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's\n\t * summary tracking state needs to be updated too.\n\t * Also, in case a child node gets realized in between Summary Op and Summary Ack, let's initialize the child's\n\t * pending summary as well.\n\t * @param child - The child node whose state is to be updated.\n\t * @param id - Initial id or path part of this node\n\t *\n\t */\n\tprotected maybeUpdateChildState(child: SummarizerNode, id: string) {\n\t\t// If a summary is in progress, this child was created after the summary started. So, we need to update the\n\t\t// child's summary state as well.\n\t\tif (this.isSummaryInProgress()) {\n\t\t\tchild.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;\n\t\t}\n\t\t// In case we have pending summaries on the parent, let's initialize it on the child.\n\t\tif (child._latestSummary !== undefined) {\n\t\t\tfor (const [key, value] of this.pendingSummaries.entries()) {\n\t\t\t\tconst newLatestSummaryNode = new SummaryNode({\n\t\t\t\t\treferenceSequenceNumber: value.referenceSequenceNumber,\n\t\t\t\t\tbasePath: child._latestSummary.basePath,\n\t\t\t\t\tlocalPath: child._latestSummary.localPath,\n\t\t\t\t});\n\n\t\t\t\tchild.addPendingSummary(key, newLatestSummaryNode);\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected addPendingSummary(key: string, summary: SummaryNode) {\n\t\tthis.pendingSummaries.set(key, summary);\n\t}\n\n\t/**\n\t * Tells whether summary tracking is in progress. True if \"startSummary\" API is called before summarize.\n\t */\n\tpublic isSummaryInProgress(): boolean {\n\t\treturn this.wipReferenceSequenceNumber !== undefined;\n\t}\n\n\t/**\n\t * Creates and throws an error due to unexpected conditions.\n\t */\n\tprotected throwUnexpectedError(eventProps: ITelemetryErrorEvent): never {\n\t\tconst error = new LoggingError(eventProps.eventName, {\n\t\t\t...eventProps,\n\t\t\treferenceSequenceNumber: this.wipReferenceSequenceNumber,\n\t\t\tid: {\n\t\t\t\ttag: TelemetryDataTag.CodeArtifact,\n\t\t\t\tvalue: this.telemetryNodeId,\n\t\t\t},\n\t\t});\n\t\tthis.logger.sendErrorEvent(eventProps, error);\n\t\tthrow error;\n\t}\n}\n\n/**\n * Creates a root summarizer node.\n * @param logger - Logger to use within SummarizerNode\n * @param summarizeInternalFn - Function to generate summary\n * @param changeSequenceNumber - Sequence number of latest change to new node/subtree\n * @param referenceSequenceNumber - Reference sequence number of last acked summary,\n * or undefined if not loaded from summary\n * @param config - Configure behavior of summarizer node\n */\nexport const createRootSummarizerNode = (\n\tlogger: ITelemetryLogger,\n\tsummarizeInternalFn: SummarizeInternalFn,\n\tchangeSequenceNumber: number,\n\treferenceSequenceNumber: number | undefined,\n\tconfig: ISummarizerNodeConfig = {},\n): IRootSummarizerNode =>\n\tnew SummarizerNode(\n\t\tlogger,\n\t\tsummarizeInternalFn,\n\t\tconfig,\n\t\tchangeSequenceNumber,\n\t\treferenceSequenceNumber === undefined\n\t\t\t? undefined\n\t\t\t: SummaryNode.createForRoot(referenceSequenceNumber),\n\t\tundefined /* initialSummary */,\n\t\tundefined /* wipSummaryLogger */,\n\t\t\"\" /* telemetryNodeId */,\n\t);\n"]}
|