@fluidframework/runtime-utils 2.0.0-dev.3.1.0.125672 → 2.0.0-dev.4.1.0.148229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +4 -4
  4. package/dist/index.js.map +1 -1
  5. package/dist/packageVersion.d.ts +1 -1
  6. package/dist/packageVersion.js +1 -1
  7. package/dist/packageVersion.js.map +1 -1
  8. package/dist/summaryUtils.d.ts +33 -1
  9. package/dist/summaryUtils.d.ts.map +1 -1
  10. package/dist/summaryUtils.js +83 -1
  11. package/dist/summaryUtils.js.map +1 -1
  12. package/dist/unpackUsedRoutes.d.ts +11 -0
  13. package/dist/unpackUsedRoutes.d.ts.map +1 -0
  14. package/dist/unpackUsedRoutes.js +33 -0
  15. package/dist/unpackUsedRoutes.js.map +1 -0
  16. package/lib/index.d.ts +2 -2
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +2 -2
  19. package/lib/index.js.map +1 -1
  20. package/lib/packageVersion.d.ts +1 -1
  21. package/lib/packageVersion.js +1 -1
  22. package/lib/packageVersion.js.map +1 -1
  23. package/lib/summaryUtils.d.ts +33 -1
  24. package/lib/summaryUtils.d.ts.map +1 -1
  25. package/lib/summaryUtils.js +81 -0
  26. package/lib/summaryUtils.js.map +1 -1
  27. package/lib/unpackUsedRoutes.d.ts +11 -0
  28. package/lib/unpackUsedRoutes.d.ts.map +1 -0
  29. package/lib/unpackUsedRoutes.js +29 -0
  30. package/lib/unpackUsedRoutes.js.map +1 -0
  31. package/package.json +53 -55
  32. package/src/index.ts +2 -8
  33. package/src/packageVersion.ts +1 -1
  34. package/src/summaryUtils.ts +94 -0
  35. package/src/unpackUsedRoutes.ts +30 -0
  36. package/dist/summarizerNode/index.d.ts +0 -8
  37. package/dist/summarizerNode/index.d.ts.map +0 -1
  38. package/dist/summarizerNode/index.js +0 -12
  39. package/dist/summarizerNode/index.js.map +0 -1
  40. package/dist/summarizerNode/summarizerNode.d.ts +0 -140
  41. package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
  42. package/dist/summarizerNode/summarizerNode.js +0 -448
  43. package/dist/summarizerNode/summarizerNode.js.map +0 -1
  44. package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -128
  45. package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  46. package/dist/summarizerNode/summarizerNodeUtils.js +0 -132
  47. package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
  48. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -135
  49. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  50. package/dist/summarizerNode/summarizerNodeWithGc.js +0 -361
  51. package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  52. package/lib/summarizerNode/index.d.ts +0 -8
  53. package/lib/summarizerNode/index.d.ts.map +0 -1
  54. package/lib/summarizerNode/index.js +0 -7
  55. package/lib/summarizerNode/index.js.map +0 -1
  56. package/lib/summarizerNode/summarizerNode.d.ts +0 -140
  57. package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
  58. package/lib/summarizerNode/summarizerNode.js +0 -443
  59. package/lib/summarizerNode/summarizerNode.js.map +0 -1
  60. package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -128
  61. package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  62. package/lib/summarizerNode/summarizerNodeUtils.js +0 -125
  63. package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
  64. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -135
  65. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  66. package/lib/summarizerNode/summarizerNodeWithGc.js +0 -356
  67. package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  68. package/src/summarizerNode/index.ts +0 -8
  69. package/src/summarizerNode/summarizerNode.ts +0 -631
  70. package/src/summarizerNode/summarizerNodeUtils.ts +0 -219
  71. package/src/summarizerNode/summarizerNodeWithGc.ts +0 -556
@@ -1,443 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { CreateSummarizerNodeSource, } from "@fluidframework/runtime-definitions";
6
- import { SummaryType, } from "@fluidframework/protocol-definitions";
7
- import { assert, unreachableCase } from "@fluidframework/common-utils";
8
- import { mergeStats, convertToSummaryTree, calculateStats } from "../summaryUtils";
9
- import { EscapedPath, parseSummaryForSubtrees, parseSummaryTreeForSubtrees, SummaryNode, } from "./summarizerNodeUtils";
10
- /**
11
- * Encapsulates the summarizing work and state of an individual tree node in the
12
- * summary tree. It tracks changes and allows for optimizations when unchanged, or
13
- * can allow for fallback summaries to be generated when an error is encountered.
14
- * Usage is for the root node to call startSummary first to begin tracking a WIP
15
- * (work in progress) summary. Then all nodes will call summarize to summaries their
16
- * individual parts. Once completed and uploaded to storage, the root node will call
17
- * completeSummary or clearSummary to clear the WIP summary tracking state if something
18
- * went wrong. The SummarizerNodes will track all pending summaries that have been
19
- * recorded by the completeSummary call. When one of them is acked, the root node should
20
- * call refreshLatestSummary to inform the tree of SummarizerNodes of the new baseline
21
- * latest successful summary.
22
- */
23
- export class SummarizerNode {
24
- /**
25
- * Do not call constructor directly.
26
- * Use createRootSummarizerNode to create root node, or createChild to create child nodes.
27
- */
28
- constructor(defaultLogger, summarizeInternalFn, config, _changeSequenceNumber,
29
- /** Undefined means created without summary */
30
- _latestSummary, initialSummary, wipSummaryLogger) {
31
- var _a;
32
- this.defaultLogger = defaultLogger;
33
- this.summarizeInternalFn = summarizeInternalFn;
34
- this._changeSequenceNumber = _changeSequenceNumber;
35
- this._latestSummary = _latestSummary;
36
- this.initialSummary = initialSummary;
37
- this.wipSummaryLogger = wipSummaryLogger;
38
- this.children = new Map();
39
- this.pendingSummaries = new Map();
40
- this.wipSkipRecursion = false;
41
- this.canReuseHandle = (_a = config.canReuseHandle) !== null && _a !== void 0 ? _a : true;
42
- }
43
- /**
44
- * The reference sequence number of the most recent acked summary.
45
- * Returns 0 if there is not yet an acked summary.
46
- */
47
- get referenceSequenceNumber() {
48
- var _a, _b;
49
- return (_b = (_a = this._latestSummary) === null || _a === void 0 ? void 0 : _a.referenceSequenceNumber) !== null && _b !== void 0 ? _b : 0;
50
- }
51
- startSummary(referenceSequenceNumber, summaryLogger) {
52
- assert(this.wipSummaryLogger === undefined, 0x19f /* "wipSummaryLogger should not be set yet in startSummary" */);
53
- assert(this.wipReferenceSequenceNumber === undefined, 0x1a0 /* "Already tracking a summary" */);
54
- this.wipSummaryLogger = summaryLogger;
55
- for (const child of this.children.values()) {
56
- child.startSummary(referenceSequenceNumber, this.wipSummaryLogger);
57
- }
58
- this.wipReferenceSequenceNumber = referenceSequenceNumber;
59
- }
60
- async summarize(fullTree, trackState = true, telemetryContext) {
61
- assert(this.isTrackingInProgress(), 0x1a1 /* "summarize should not be called when not tracking the summary" */);
62
- assert(this.wipSummaryLogger !== undefined, 0x1a2 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
63
- // Try to reuse the tree if unchanged
64
- if (this.canReuseHandle && !fullTree && !this.hasChanged()) {
65
- const latestSummary = this._latestSummary;
66
- if (latestSummary !== undefined) {
67
- this.wipLocalPaths = {
68
- localPath: latestSummary.localPath,
69
- additionalPath: latestSummary.additionalPath,
70
- };
71
- this.wipSkipRecursion = true;
72
- const stats = mergeStats();
73
- stats.handleNodeCount++;
74
- return {
75
- summary: {
76
- type: SummaryType.Handle,
77
- handle: latestSummary.fullPath.path,
78
- handleType: SummaryType.Tree,
79
- },
80
- stats,
81
- };
82
- }
83
- }
84
- const result = await this.summarizeInternalFn(fullTree, true, telemetryContext);
85
- this.wipLocalPaths = { localPath: EscapedPath.create(result.id) };
86
- if (result.pathPartsForChildren !== undefined) {
87
- this.wipLocalPaths.additionalPath = EscapedPath.createAndConcat(result.pathPartsForChildren);
88
- }
89
- return { summary: result.summary, stats: result.stats };
90
- }
91
- /**
92
- * Complete the WIP summary for the given proposalHandle
93
- */
94
- completeSummary(proposalHandle) {
95
- this.completeSummaryCore(proposalHandle, undefined, false);
96
- }
97
- /**
98
- * Recursive implementation for completeSummary, with additional internal-only parameters
99
- */
100
- completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion) {
101
- assert(this.wipSummaryLogger !== undefined, 0x1a3 /* "wipSummaryLogger should have been set in startSummary or ctor" */);
102
- assert(this.wipReferenceSequenceNumber !== undefined, 0x1a4 /* "Not tracking a summary" */);
103
- let localPathsToUse = this.wipLocalPaths;
104
- if (parentSkipRecursion) {
105
- const latestSummary = this._latestSummary;
106
- if (latestSummary !== undefined) {
107
- // This case the parent node created a failure summary or was reused.
108
- // This node and all children should only try to reference their path
109
- // by its last known good state in the actual summary tree.
110
- // If parent fails or is reused, the child summarize is not called so
111
- // it did not get a chance to change its paths.
112
- // In this case, essentially only propagate the new summary ref seq num.
113
- localPathsToUse = {
114
- localPath: latestSummary.localPath,
115
- additionalPath: latestSummary.additionalPath,
116
- };
117
- }
118
- else {
119
- // This case the child is added after the latest non-failure summary.
120
- // This node and all children should consider themselves as still not
121
- // having a successful summary yet.
122
- // We cannot "reuse" this node if unchanged since that summary, because
123
- // handles will be unable to point to that node. It never made it to the
124
- // tree itself, and only exists as an attach op in the _outstandingOps.
125
- this.clearSummary();
126
- return;
127
- }
128
- }
129
- // This should come from wipLocalPaths in normal cases, or from the latestSummary
130
- // if parentIsFailure or parentIsReused is true.
131
- // If there is no latestSummary, clearSummary and return before reaching this code.
132
- assert(!!localPathsToUse, 0x1a5 /* "Tracked summary local paths not set" */);
133
- const summary = new SummaryNode(Object.assign(Object.assign({}, localPathsToUse), { referenceSequenceNumber: this.wipReferenceSequenceNumber, basePath: parentPath }));
134
- const fullPathForChildren = summary.fullPathForChildren;
135
- for (const child of this.children.values()) {
136
- child.completeSummaryCore(proposalHandle, fullPathForChildren, this.wipSkipRecursion || parentSkipRecursion);
137
- }
138
- // Note that this overwrites existing pending summary with
139
- // the same proposalHandle. If proposalHandle is something like
140
- // a hash or unique identifier, this should be fine. If storage
141
- // can return the same proposalHandle for a different summary,
142
- // this should still be okay, because we should be proposing the
143
- // newer one later which would have to overwrite the previous one.
144
- this.pendingSummaries.set(proposalHandle, summary);
145
- this.clearSummary();
146
- }
147
- clearSummary() {
148
- this.wipReferenceSequenceNumber = undefined;
149
- this.wipLocalPaths = undefined;
150
- this.wipSkipRecursion = false;
151
- this.wipSummaryLogger = undefined;
152
- for (const child of this.children.values()) {
153
- child.clearSummary();
154
- }
155
- }
156
- /**
157
- * Refreshes the latest summary tracked by this node. If we have a pending summary for the given proposal handle,
158
- * it becomes the latest summary. If the current summary is already ahead (e.g., loaded from a service summary),
159
- * we skip the update. Otherwise, we get the snapshot by calling `getSnapshot` and update latest
160
- * summary based off of that.
161
- *
162
- * @returns A RefreshSummaryResult type which returns information based on the following three scenarios:
163
- *
164
- * 1. The latest summary was not udpated.
165
- *
166
- * 2. The latest summary was updated and the summary corresponding to the params was being tracked.
167
- *
168
- * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this
169
- * case, the latest summary is updated based on the downloaded snapshot which is also returned.
170
- */
171
- async refreshLatestSummary(proposalHandle, summaryRefSeq, getSnapshot, readAndParseBlob, correlatedSummaryLogger) {
172
- var _a;
173
- this.defaultLogger.sendTelemetryEvent({
174
- eventName: "refreshLatestSummary_start",
175
- proposalHandle,
176
- referenceSequenceNumber: this.referenceSequenceNumber,
177
- summaryRefSeq,
178
- });
179
- if (proposalHandle !== undefined) {
180
- const maybeSummaryNode = this.pendingSummaries.get(proposalHandle);
181
- if (maybeSummaryNode !== undefined) {
182
- this.refreshLatestSummaryFromPending(proposalHandle, maybeSummaryNode.referenceSequenceNumber);
183
- return { latestSummaryUpdated: true, wasSummaryTracked: true };
184
- }
185
- const props = {
186
- summaryRefSeq,
187
- pendingSize: (_a = this.pendingSummaries.size) !== null && _a !== void 0 ? _a : undefined,
188
- };
189
- this.defaultLogger.sendTelemetryEvent({
190
- eventName: "PendingSummaryNotFound",
191
- proposalHandle,
192
- referenceSequenceNumber: this.referenceSequenceNumber,
193
- details: JSON.stringify(props),
194
- });
195
- }
196
- // If we have seen a summary same or later as the current one, ignore it.
197
- if (this.referenceSequenceNumber >= summaryRefSeq) {
198
- return { latestSummaryUpdated: false };
199
- }
200
- const snapshotTree = await getSnapshot();
201
- await this.refreshLatestSummaryFromSnapshot(summaryRefSeq, snapshotTree, undefined, EscapedPath.create(""), correlatedSummaryLogger, readAndParseBlob);
202
- return { latestSummaryUpdated: true, wasSummaryTracked: false, snapshot: snapshotTree };
203
- }
204
- /**
205
- * Called when we get an ack from the server for a summary we've just sent. Updates the reference state of this node
206
- * from the state in the pending summary queue.
207
- * @param proposalHandle - Handle for the current proposal.
208
- * @param referenceSequenceNumber - reference sequence number of sent summary.
209
- */
210
- refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber) {
211
- const summaryNode = this.pendingSummaries.get(proposalHandle);
212
- if (summaryNode === undefined) {
213
- // This should only happen if parent skipped recursion AND no prior summary existed.
214
- assert(this._latestSummary === undefined, 0x1a6 /* "Not found pending summary, but this node has previously completed a summary" */);
215
- return;
216
- }
217
- else {
218
- assert(referenceSequenceNumber === summaryNode.referenceSequenceNumber, 0x1a7 /* Pending summary reference sequence number should be consistent */);
219
- // Clear earlier pending summaries
220
- this.pendingSummaries.delete(proposalHandle);
221
- }
222
- this.refreshLatestSummaryCore(referenceSequenceNumber);
223
- this._latestSummary = summaryNode;
224
- // Propagate update to all child nodes
225
- for (const child of this.children.values()) {
226
- child.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
227
- }
228
- }
229
- async refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob) {
230
- // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
231
- if (this.referenceSequenceNumber >= referenceSequenceNumber) {
232
- return;
233
- }
234
- this.refreshLatestSummaryCore(referenceSequenceNumber);
235
- this._latestSummary = new SummaryNode({
236
- referenceSequenceNumber,
237
- basePath,
238
- localPath,
239
- });
240
- const pathParts = [];
241
- const { childrenTree, childrenPathPart } = parseSummaryForSubtrees(snapshotTree);
242
- if (childrenPathPart !== undefined) {
243
- pathParts.push(childrenPathPart);
244
- }
245
- if (pathParts.length > 0) {
246
- this._latestSummary.additionalPath = EscapedPath.createAndConcat(pathParts);
247
- }
248
- // Propagate update to all child nodes
249
- const pathForChildren = this._latestSummary.fullPathForChildren;
250
- await Promise.all(Array.from(this.children)
251
- .filter(([id]) => {
252
- // Assuming subtrees missing from snapshot are newer than the snapshot,
253
- // but might be nice to assert this using earliest seq for node.
254
- return childrenTree.trees[id] !== undefined;
255
- })
256
- .map(async ([id, child]) => {
257
- return child.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, childrenTree.trees[id], pathForChildren, EscapedPath.create(id), correlatedSummaryLogger, readAndParseBlob);
258
- }));
259
- }
260
- refreshLatestSummaryCore(referenceSequenceNumber) {
261
- for (const [key, value] of this.pendingSummaries) {
262
- if (value.referenceSequenceNumber < referenceSequenceNumber) {
263
- this.pendingSummaries.delete(key);
264
- }
265
- }
266
- }
267
- updateBaseSummaryState(snapshot) {
268
- // Check base summary to see if it has any additional path parts
269
- // separating child SummarizerNodes. Checks for .channels subtrees.
270
- const { childrenPathPart } = parseSummaryForSubtrees(snapshot);
271
- if (childrenPathPart !== undefined && this._latestSummary !== undefined) {
272
- this._latestSummary.additionalPath = EscapedPath.create(childrenPathPart);
273
- }
274
- }
275
- recordChange(op) {
276
- this.invalidate(op.sequenceNumber);
277
- }
278
- invalidate(sequenceNumber) {
279
- if (sequenceNumber > this._changeSequenceNumber) {
280
- this._changeSequenceNumber = sequenceNumber;
281
- }
282
- }
283
- /**
284
- * True if a change has been recorded with sequence number exceeding
285
- * the latest successfully acked summary reference sequence number.
286
- * False implies that the previous summary can be reused.
287
- */
288
- hasChanged() {
289
- return this._changeSequenceNumber > this.referenceSequenceNumber;
290
- }
291
- get latestSummary() {
292
- return this._latestSummary;
293
- }
294
- createChild(
295
- /** Summarize function */
296
- summarizeInternalFn,
297
- /** Initial id or path part of this node */
298
- id,
299
- /**
300
- * Information needed to create the node.
301
- * If it is from a base summary, it will assert that a summary has been seen.
302
- * Attach information if it is created from an attach op.
303
- */
304
- createParam, config = {}) {
305
- assert(!this.children.has(id), 0x1ab /* "Create SummarizerNode child already exists" */);
306
- const createDetails = this.getCreateDetailsForChild(id, createParam);
307
- const child = new SummarizerNode(this.defaultLogger, summarizeInternalFn, config, createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger);
308
- // There may be additional state that has to be updated in this child. For example, if a summary is being
309
- // tracked, the child's summary tracking state needs to be updated too. Same goes for pendingSummaries we might
310
- // have outstanding on the parent in case we realize nodes in between Summary Op and Summary Ack.
311
- this.maybeUpdateChildState(child);
312
- this.children.set(id, child);
313
- return child;
314
- }
315
- getChild(id) {
316
- return this.children.get(id);
317
- }
318
- /**
319
- * Returns the details needed to create a child node.
320
- * @param id - Initial id or path part of the child node.
321
- * @param createParam - Information needed to create the node.
322
- * @returns the details needed to create the child node.
323
- */
324
- getCreateDetailsForChild(id, createParam) {
325
- var _a;
326
- let initialSummary;
327
- let latestSummary;
328
- let changeSequenceNumber;
329
- const parentLatestSummary = this._latestSummary;
330
- switch (createParam.type) {
331
- case CreateSummarizerNodeSource.FromAttach: {
332
- if (parentLatestSummary !== undefined &&
333
- createParam.sequenceNumber <= parentLatestSummary.referenceSequenceNumber) {
334
- // Prioritize latest summary if it was after this node was attached.
335
- latestSummary = parentLatestSummary.createForChild(id);
336
- }
337
- else {
338
- const summary = convertToSummaryTree(createParam.snapshot);
339
- initialSummary = {
340
- sequenceNumber: createParam.sequenceNumber,
341
- id,
342
- summary,
343
- };
344
- }
345
- changeSequenceNumber = createParam.sequenceNumber;
346
- break;
347
- }
348
- case CreateSummarizerNodeSource.FromSummary: {
349
- if (this.initialSummary === undefined) {
350
- assert(!!parentLatestSummary, 0x1ac /* "Cannot create child from summary if parent does not have latest summary" */);
351
- }
352
- // fallthrough to local
353
- }
354
- case CreateSummarizerNodeSource.Local: {
355
- const parentInitialSummary = this.initialSummary;
356
- if (parentInitialSummary !== undefined) {
357
- let childSummary;
358
- if (parentInitialSummary.summary !== undefined) {
359
- const { childrenTree } = parseSummaryTreeForSubtrees(parentInitialSummary.summary.summary);
360
- assert(childrenTree.type === SummaryType.Tree, 0x1d6 /* "Parent summary object is not a tree" */);
361
- childSummary = childrenTree.tree[id];
362
- }
363
- if (createParam.type === CreateSummarizerNodeSource.FromSummary) {
364
- // Locally created would not have differential subtree.
365
- assert(!!childSummary, 0x1ad /* "Missing child summary tree" */);
366
- }
367
- let childSummaryWithStats;
368
- if (childSummary !== undefined) {
369
- assert(childSummary.type === SummaryType.Tree, 0x1ae /* "Child summary object is not a tree" */);
370
- childSummaryWithStats = {
371
- summary: childSummary,
372
- stats: calculateStats(childSummary),
373
- };
374
- }
375
- initialSummary = {
376
- sequenceNumber: parentInitialSummary.sequenceNumber,
377
- id,
378
- summary: childSummaryWithStats,
379
- };
380
- }
381
- latestSummary = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.createForChild(id);
382
- changeSequenceNumber = (_a = parentLatestSummary === null || parentLatestSummary === void 0 ? void 0 : parentLatestSummary.referenceSequenceNumber) !== null && _a !== void 0 ? _a : -1;
383
- break;
384
- }
385
- default: {
386
- const type = createParam.type;
387
- unreachableCase(createParam, `Unexpected CreateSummarizerNodeSource: ${type}`);
388
- }
389
- }
390
- return {
391
- initialSummary,
392
- latestSummary,
393
- changeSequenceNumber,
394
- };
395
- }
396
- /**
397
- * Updates the state of the child if required. For example, if a summary is currently being tracked, the child's
398
- * summary tracking state needs to be updated too.
399
- * Also, in case a child node gets realized in between Summary Op and Summary Ack, let's initialize the child's
400
- * pending summary as well.
401
- * @param child - The child node whose state is to be updated.
402
- */
403
- maybeUpdateChildState(child) {
404
- // If we are tracking a summary, this child was created after the tracking started. So, we need to update the
405
- // child's tracking state as well.
406
- if (this.isTrackingInProgress()) {
407
- child.wipReferenceSequenceNumber = this.wipReferenceSequenceNumber;
408
- }
409
- // In case we have pending summaries on the parent, let's initialize it on the child.
410
- if (child._latestSummary !== undefined) {
411
- for (const [key, value] of this.pendingSummaries.entries()) {
412
- const newLatestSummaryNode = new SummaryNode({
413
- referenceSequenceNumber: value.referenceSequenceNumber,
414
- basePath: child._latestSummary.basePath,
415
- localPath: child._latestSummary.localPath,
416
- });
417
- child.addPendingSummary(key, newLatestSummaryNode);
418
- }
419
- }
420
- }
421
- addPendingSummary(key, summary) {
422
- this.pendingSummaries.set(key, summary);
423
- }
424
- /**
425
- * Tells whether summary tracking is in progress. True if "startSummary" API is called before summarize.
426
- */
427
- isTrackingInProgress() {
428
- return this.wipReferenceSequenceNumber !== undefined;
429
- }
430
- }
431
- /**
432
- * Creates a root summarizer node.
433
- * @param logger - Logger to use within SummarizerNode
434
- * @param summarizeInternalFn - Function to generate summary
435
- * @param changeSequenceNumber - Sequence number of latest change to new node/subtree
436
- * @param referenceSequenceNumber - Reference sequence number of last acked summary,
437
- * or undefined if not loaded from summary
438
- * @param config - Configure behavior of summarizer node
439
- */
440
- export const createRootSummarizerNode = (logger, summarizeInternalFn, changeSequenceNumber, referenceSequenceNumber, config = {}) => new SummarizerNode(logger, summarizeInternalFn, config, changeSequenceNumber, referenceSequenceNumber === undefined
441
- ? undefined
442
- : SummaryNode.createForRoot(referenceSequenceNumber));
443
- //# sourceMappingURL=summarizerNode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarizerNode.js","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAMN,0BAA0B,GAG1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEN,WAAW,GAGX,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAE,MAAM,EAA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,kCAAkC;QAClC,IAAI,IAAI,CAAC,oBAAoB,EAAE,EAAE;YAChC,KAAK,CAAC,0BAA0B,GAAG,IAAI,CAAC,0BAA0B,CAAC;SACnE;QACD,qFAAqF;QACrF,IAAI,KAAK,CAAC,cAAc,KAAK,SAAS,EAAE;YACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE;gBAC3D,MAAM,oBAAoB,GAAG,IAAI,WAAW,CAAC;oBAC5C,uBAAuB,EAAE,KAAK,CAAC,uBAAuB;oBACtD,QAAQ,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ;oBACvC,SAAS,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS;iBACzC,CAAC,CAAC;gBAEH,KAAK,CAAC,iBAAiB,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;aACnD;SACD;IACF,CAAC;IAES,iBAAiB,CAAC,GAAW,EAAE,OAAoB;QAC5D,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACD;;OAEG;IACO,oBAAoB;QAC7B,OAAO,IAAI,CAAC,0BAA0B,KAAK,SAAS,CAAC;IACtD,CAAC;CACD;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,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,WAAW,CAAC,aAAa,CAAC,uBAAuB,CAAC,CACrD,CAAC","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 { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, unreachableCase } from \"@fluidframework/common-utils\";\nimport { mergeStats, convertToSummaryTree, calculateStats } from \"../summaryUtils\";\nimport { ReadAndParseBlob } from \"../utils\";\nimport {\n\tEscapedPath,\n\tICreateChildDetails,\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\tprivate wipReferenceSequenceNumber: number | undefined;\n\tprivate wipLocalPaths: { localPath: EscapedPath; additionalPath?: EscapedPath } | undefined;\n\tprivate wipSkipRecursion = false;\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.isTrackingInProgress(),\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// This should come from wipLocalPaths in normal cases, or from the latestSummary\n\t\t// if parentIsFailure or parentIsReused is true.\n\t\t// If there is no latestSummary, clearSummary and return before reaching this code.\n\t\tassert(!!localPathsToUse, 0x1a5 /* \"Tracked summary local paths not set\" */);\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 get the snapshot by calling `getSnapshot` and update latest\n\t * 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 udpated.\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\tgetSnapshot: () => Promise<ISnapshotTree>,\n\t\treadAndParseBlob: ReadAndParseBlob,\n\t\tcorrelatedSummaryLogger: ITelemetryLogger,\n\t): Promise<RefreshSummaryResult> {\n\t\tthis.defaultLogger.sendTelemetryEvent({\n\t\t\teventName: \"refreshLatestSummary_start\",\n\t\t\tproposalHandle,\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\tsummaryRefSeq,\n\t\t});\n\n\t\tif (proposalHandle !== undefined) {\n\t\t\tconst maybeSummaryNode = this.pendingSummaries.get(proposalHandle);\n\n\t\t\tif (maybeSummaryNode !== undefined) {\n\t\t\t\tthis.refreshLatestSummaryFromPending(\n\t\t\t\t\tproposalHandle,\n\t\t\t\t\tmaybeSummaryNode.referenceSequenceNumber,\n\t\t\t\t);\n\t\t\t\treturn { latestSummaryUpdated: true, wasSummaryTracked: true };\n\t\t\t}\n\n\t\t\tconst props = {\n\t\t\t\tsummaryRefSeq,\n\t\t\t\tpendingSize: this.pendingSummaries.size ?? undefined,\n\t\t\t};\n\t\t\tthis.defaultLogger.sendTelemetryEvent({\n\t\t\t\teventName: \"PendingSummaryNotFound\",\n\t\t\t\tproposalHandle,\n\t\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\t\tdetails: JSON.stringify(props),\n\t\t\t});\n\t\t}\n\n\t\t// If we have seen a summary same or later as the current one, ignore it.\n\t\tif (this.referenceSequenceNumber >= summaryRefSeq) {\n\t\t\treturn { latestSummaryUpdated: false };\n\t\t}\n\n\t\tconst snapshotTree = await getSnapshot();\n\t\tawait this.refreshLatestSummaryFromSnapshot(\n\t\t\tsummaryRefSeq,\n\t\t\tsnapshotTree,\n\t\t\tundefined,\n\t\t\tEscapedPath.create(\"\"),\n\t\t\tcorrelatedSummaryLogger,\n\t\t\treadAndParseBlob,\n\t\t);\n\t\treturn { latestSummaryUpdated: true, wasSummaryTracked: false, snapshot: snapshotTree };\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\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\tprotected readonly defaultLogger: 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) {\n\t\tthis.canReuseHandle = config.canReuseHandle ?? true;\n\t}\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.defaultLogger,\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);\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);\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\treturn {\n\t\t\tinitialSummary,\n\t\t\tlatestSummary,\n\t\t\tchangeSequenceNumber,\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 */\n\tprotected maybeUpdateChildState(child: SummarizerNode) {\n\t\t// If we are tracking a summary, this child was created after the tracking started. So, we need to update the\n\t\t// child's tracking state as well.\n\t\tif (this.isTrackingInProgress()) {\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\t/**\n\t * Tells whether summary tracking is in progress. True if \"startSummary\" API is called before summarize.\n\t */\n\tprotected isTrackingInProgress(): boolean {\n\t\treturn this.wipReferenceSequenceNumber !== undefined;\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);\n"]}
@@ -1,128 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
- import { ISnapshotTree, ISummaryTree, SummaryObject } from "@fluidframework/protocol-definitions";
7
- import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
- import { ReadAndParseBlob } from "../utils";
9
- /**
10
- * Return value of refreshSummaryAck function. There can be three different scenarios based on the passed params:
11
- *
12
- * 1. The latest summary was not udpated.
13
- *
14
- * 2. The latest summary was updated and the summary corresponding to the params was tracked by this client.
15
- *
16
- * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this case, the
17
- * latest summary is updated based on the downloaded snapshot which is also returned.
18
- */
19
- export declare type RefreshSummaryResult = {
20
- latestSummaryUpdated: false;
21
- } | {
22
- latestSummaryUpdated: true;
23
- wasSummaryTracked: true;
24
- } | {
25
- latestSummaryUpdated: true;
26
- wasSummaryTracked: false;
27
- snapshot: ISnapshotTree;
28
- };
29
- export interface ISummarizerNodeRootContract {
30
- startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger): void;
31
- completeSummary(proposalHandle: string): void;
32
- clearSummary(): void;
33
- refreshLatestSummary(proposalHandle: string | undefined, summaryRefSeq: number, getSnapshot: () => Promise<ISnapshotTree>, readAndParseBlob: ReadAndParseBlob, correlatedSummaryLogger: ITelemetryLogger): Promise<RefreshSummaryResult>;
34
- }
35
- /** Path for nodes in a tree with escaped special characters */
36
- export declare class EscapedPath {
37
- readonly path: string;
38
- private constructor();
39
- static create(path: string): EscapedPath;
40
- static createAndConcat(pathParts: string[]): EscapedPath;
41
- toString(): string;
42
- concat(path: EscapedPath): EscapedPath;
43
- }
44
- /** Information about a summary relevant to a specific node in the tree */
45
- export declare class SummaryNode {
46
- private readonly summary;
47
- /** Creates an instance that is valid for the root with specific basePath and localPath */
48
- static createForRoot(referenceSequenceNumber: number): SummaryNode;
49
- /** Summary reference sequence number, i.e. last sequence number seen when it was created */
50
- get referenceSequenceNumber(): number;
51
- /** Full path to parent node, or undefined if this is the root */
52
- get basePath(): EscapedPath | undefined;
53
- /** Relative path to this node from its parent node */
54
- get localPath(): EscapedPath;
55
- /** Relative path from this node to its node innermost base summary */
56
- get additionalPath(): EscapedPath | undefined;
57
- set additionalPath(additionalPath: EscapedPath | undefined);
58
- constructor(summary: {
59
- readonly referenceSequenceNumber: number;
60
- readonly basePath: EscapedPath | undefined;
61
- readonly localPath: EscapedPath;
62
- additionalPath?: EscapedPath;
63
- });
64
- /** Gets the full path to this node, to be used when sending a handle */
65
- get fullPath(): EscapedPath;
66
- /**
67
- * Gets the full path to this node's innermost base summary.
68
- * The children nodes can use this as their basePath to determine their path.
69
- */
70
- get fullPathForChildren(): EscapedPath;
71
- /**
72
- * Creates a new node within the same summary for a child of this node.
73
- * @param id - id of the child node
74
- */
75
- createForChild(id: string): SummaryNode;
76
- }
77
- /**
78
- * Parameter to help encode summary with conditional behavior.
79
- * When fromSummary is true, it will contain the SummaryNode of
80
- * its previous summary, which it can use to point to with a handle.
81
- * When fromSummary is false, it will use an actual summary tree
82
- * as its base summary in case the first summary is a differential summary.
83
- */
84
- export declare type EncodeSummaryParam = {
85
- fromSummary: true;
86
- summaryNode: SummaryNode;
87
- } | {
88
- fromSummary: false;
89
- initialSummary: ISummaryTreeWithStats;
90
- };
91
- /**
92
- * Information about the initial summary tree found from an attach op.
93
- */
94
- export interface IInitialSummary {
95
- sequenceNumber: number;
96
- id: string;
97
- summary: ISummaryTreeWithStats | undefined;
98
- }
99
- /**
100
- * Represents the details needed to create a child summarizer node.
101
- */
102
- export interface ICreateChildDetails {
103
- /** Summary from attach op if known */
104
- initialSummary: IInitialSummary | undefined;
105
- /** Latest summary from server node data */
106
- latestSummary: SummaryNode | undefined;
107
- /** Sequence number of latest known change to the node */
108
- changeSequenceNumber: number;
109
- }
110
- export interface ISubtreeInfo<T extends ISnapshotTree | SummaryObject> {
111
- /** Tree to use to find children subtrees */
112
- childrenTree: T;
113
- /** Additional path part where children are isolated */
114
- childrenPathPart: string | undefined;
115
- }
116
- /**
117
- * Checks if the summary contains .channels subtree where the children subtrees
118
- * would be located if exists.
119
- * @param baseSummary - summary to check
120
- */
121
- export declare function parseSummaryForSubtrees(baseSummary: ISnapshotTree): ISubtreeInfo<ISnapshotTree>;
122
- /**
123
- * Checks if the summary contains .channels subtree where the children subtrees
124
- * would be located if exists.
125
- * @param baseSummary - summary to check
126
- */
127
- export declare function parseSummaryTreeForSubtrees(summary: ISummaryTree): ISubtreeInfo<SummaryObject>;
128
- //# sourceMappingURL=summarizerNodeUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"summarizerNodeUtils.d.ts","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNodeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAClG,OAAO,EAAoB,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C;;;;;;;;;GASG;AACH,oBAAY,oBAAoB,GAC7B;IACA,oBAAoB,EAAE,KAAK,CAAC;CAC3B,GACD;IACA,oBAAoB,EAAE,IAAI,CAAC;IAC3B,iBAAiB,EAAE,IAAI,CAAC;CACvB,GACD;IACA,oBAAoB,EAAE,IAAI,CAAC;IAC3B,iBAAiB,EAAE,KAAK,CAAC;IACzB,QAAQ,EAAE,aAAa,CAAC;CACvB,CAAC;AAEL,MAAM,WAAW,2BAA2B;IAC3C,YAAY,CAAC,uBAAuB,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACrF,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9C,YAAY,IAAI,IAAI,CAAC;IACrB,oBAAoB,CACnB,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EACzC,gBAAgB,EAAE,gBAAgB,EAClC,uBAAuB,E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