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