@fluidframework/runtime-utils 2.0.0-dev.3.1.0.125672 → 2.0.0-dev.4.2.0.153917
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +68 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/summaryUtils.d.ts +33 -1
- package/dist/summaryUtils.d.ts.map +1 -1
- package/dist/summaryUtils.js +83 -1
- package/dist/summaryUtils.js.map +1 -1
- package/dist/unpackUsedRoutes.d.ts +11 -0
- package/dist/unpackUsedRoutes.d.ts.map +1 -0
- package/dist/unpackUsedRoutes.js +33 -0
- package/dist/unpackUsedRoutes.js.map +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/summaryUtils.d.ts +33 -1
- package/lib/summaryUtils.d.ts.map +1 -1
- package/lib/summaryUtils.js +81 -0
- package/lib/summaryUtils.js.map +1 -1
- package/lib/unpackUsedRoutes.d.ts +11 -0
- package/lib/unpackUsedRoutes.d.ts.map +1 -0
- package/lib/unpackUsedRoutes.js +29 -0
- package/lib/unpackUsedRoutes.js.map +1 -0
- package/package.json +53 -55
- package/src/index.ts +2 -8
- package/src/packageVersion.ts +1 -1
- package/src/summaryUtils.ts +94 -0
- package/src/unpackUsedRoutes.ts +30 -0
- package/dist/summarizerNode/index.d.ts +0 -8
- package/dist/summarizerNode/index.d.ts.map +0 -1
- package/dist/summarizerNode/index.js +0 -12
- package/dist/summarizerNode/index.js.map +0 -1
- package/dist/summarizerNode/summarizerNode.d.ts +0 -140
- package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNode.js +0 -448
- package/dist/summarizerNode/summarizerNode.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -128
- package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeUtils.js +0 -132
- package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -135
- package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/dist/summarizerNode/summarizerNodeWithGc.js +0 -361
- package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/lib/summarizerNode/index.d.ts +0 -8
- package/lib/summarizerNode/index.d.ts.map +0 -1
- package/lib/summarizerNode/index.js +0 -7
- package/lib/summarizerNode/index.js.map +0 -1
- package/lib/summarizerNode/summarizerNode.d.ts +0 -140
- package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNode.js +0 -443
- package/lib/summarizerNode/summarizerNode.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -128
- package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeUtils.js +0 -125
- package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -135
- package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
- package/lib/summarizerNode/summarizerNodeWithGc.js +0 -356
- package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
- package/src/summarizerNode/index.ts +0 -8
- package/src/summarizerNode/summarizerNode.ts +0 -631
- package/src/summarizerNode/summarizerNodeUtils.ts +0 -219
- package/src/summarizerNode/summarizerNodeWithGc.ts +0 -556
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { channelsTreeName } from "@fluidframework/runtime-definitions";
|
|
6
|
-
/** Path for nodes in a tree with escaped special characters */
|
|
7
|
-
export class EscapedPath {
|
|
8
|
-
constructor(path) {
|
|
9
|
-
this.path = path;
|
|
10
|
-
}
|
|
11
|
-
static create(path) {
|
|
12
|
-
return new EscapedPath(encodeURIComponent(path));
|
|
13
|
-
}
|
|
14
|
-
static createAndConcat(pathParts) {
|
|
15
|
-
var _a;
|
|
16
|
-
let ret = EscapedPath.create((_a = pathParts[0]) !== null && _a !== void 0 ? _a : "");
|
|
17
|
-
for (let i = 1; i < pathParts.length; i++) {
|
|
18
|
-
ret = ret.concat(EscapedPath.create(pathParts[i]));
|
|
19
|
-
}
|
|
20
|
-
return ret;
|
|
21
|
-
}
|
|
22
|
-
toString() {
|
|
23
|
-
return this.path;
|
|
24
|
-
}
|
|
25
|
-
concat(path) {
|
|
26
|
-
return new EscapedPath(`${this.path}/${path.path}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/** Information about a summary relevant to a specific node in the tree */
|
|
30
|
-
export class SummaryNode {
|
|
31
|
-
constructor(summary) {
|
|
32
|
-
this.summary = summary;
|
|
33
|
-
}
|
|
34
|
-
/** Creates an instance that is valid for the root with specific basePath and localPath */
|
|
35
|
-
static createForRoot(referenceSequenceNumber) {
|
|
36
|
-
return new SummaryNode({
|
|
37
|
-
referenceSequenceNumber,
|
|
38
|
-
basePath: undefined,
|
|
39
|
-
localPath: EscapedPath.create(""), // root hard-coded to ""
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
/** Summary reference sequence number, i.e. last sequence number seen when it was created */
|
|
43
|
-
get referenceSequenceNumber() {
|
|
44
|
-
return this.summary.referenceSequenceNumber;
|
|
45
|
-
}
|
|
46
|
-
/** Full path to parent node, or undefined if this is the root */
|
|
47
|
-
get basePath() {
|
|
48
|
-
return this.summary.basePath;
|
|
49
|
-
}
|
|
50
|
-
/** Relative path to this node from its parent node */
|
|
51
|
-
get localPath() {
|
|
52
|
-
return this.summary.localPath;
|
|
53
|
-
}
|
|
54
|
-
/** Relative path from this node to its node innermost base summary */
|
|
55
|
-
get additionalPath() {
|
|
56
|
-
return this.summary.additionalPath;
|
|
57
|
-
}
|
|
58
|
-
set additionalPath(additionalPath) {
|
|
59
|
-
this.summary.additionalPath = additionalPath;
|
|
60
|
-
}
|
|
61
|
-
/** Gets the full path to this node, to be used when sending a handle */
|
|
62
|
-
get fullPath() {
|
|
63
|
-
var _a, _b;
|
|
64
|
-
return (_b = (_a = this.basePath) === null || _a === void 0 ? void 0 : _a.concat(this.localPath)) !== null && _b !== void 0 ? _b : this.localPath;
|
|
65
|
-
}
|
|
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() {
|
|
71
|
-
return this.additionalPath !== undefined
|
|
72
|
-
? this.fullPath.concat(this.additionalPath)
|
|
73
|
-
: this.fullPath;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Creates a new node within the same summary for a child of this node.
|
|
77
|
-
* @param id - id of the child node
|
|
78
|
-
*/
|
|
79
|
-
createForChild(id) {
|
|
80
|
-
return new SummaryNode({
|
|
81
|
-
referenceSequenceNumber: this.referenceSequenceNumber,
|
|
82
|
-
basePath: this.fullPathForChildren,
|
|
83
|
-
localPath: EscapedPath.create(id),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Checks if the summary contains .channels subtree where the children subtrees
|
|
89
|
-
* would be located if exists.
|
|
90
|
-
* @param baseSummary - summary to check
|
|
91
|
-
*/
|
|
92
|
-
export function parseSummaryForSubtrees(baseSummary) {
|
|
93
|
-
// New versions of snapshots have child nodes isolated in .channels subtree
|
|
94
|
-
const channelsSubtree = baseSummary.trees[channelsTreeName];
|
|
95
|
-
if (channelsSubtree !== undefined) {
|
|
96
|
-
return {
|
|
97
|
-
childrenTree: channelsSubtree,
|
|
98
|
-
childrenPathPart: channelsTreeName,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
return {
|
|
102
|
-
childrenTree: baseSummary,
|
|
103
|
-
childrenPathPart: undefined,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Checks if the summary contains .channels subtree where the children subtrees
|
|
108
|
-
* would be located if exists.
|
|
109
|
-
* @param baseSummary - summary to check
|
|
110
|
-
*/
|
|
111
|
-
export function parseSummaryTreeForSubtrees(summary) {
|
|
112
|
-
// New versions of snapshots have child nodes isolated in .channels subtree
|
|
113
|
-
const channelsSubtree = summary.tree[channelsTreeName];
|
|
114
|
-
if (channelsSubtree !== undefined) {
|
|
115
|
-
return {
|
|
116
|
-
childrenTree: channelsSubtree,
|
|
117
|
-
childrenPathPart: channelsTreeName,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
childrenTree: summary,
|
|
122
|
-
childrenPathPart: undefined,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=summarizerNodeUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"summarizerNodeUtils.js","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNodeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,gBAAgB,EAAyB,MAAM,qCAAqC,CAAC;AAwC9F,+DAA+D;AAC/D,MAAM,OAAO,WAAW;IACvB,YAAoC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAC7C,MAAM,CAAC,MAAM,CAAC,IAAY;QAChC,OAAO,IAAI,WAAW,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;IACM,MAAM,CAAC,eAAe,CAAC,SAA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Ae,KAAK,SAAS,EAAE;QAClC,OAAO;YACN,YAAY,EAAE,eAAe;YAC7B,gBAAgB,EAAE,gBAAgB;SAClC,CAAC;KACF;IACD,OAAO;QACN,YAAY,EAAE,OAAO;QACrB,gBAAgB,EAAE,SAAS;KAC3B,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { ISnapshotTree, ISummaryTree, SummaryObject } from \"@fluidframework/protocol-definitions\";\nimport { channelsTreeName, ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport { ReadAndParseBlob } from \"../utils\";\n\n/**\n * Return value of refreshSummaryAck function. There can be three different scenarios based on the passed params:\n *\n * 1. The latest summary was not udpated.\n *\n * 2. The latest summary was updated and the summary corresponding to the params was tracked by this client.\n *\n * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this case, the\n * latest summary is updated based on the downloaded snapshot which is also returned.\n */\nexport type RefreshSummaryResult =\n\t| {\n\t\t\tlatestSummaryUpdated: false;\n\t }\n\t| {\n\t\t\tlatestSummaryUpdated: true;\n\t\t\twasSummaryTracked: true;\n\t }\n\t| {\n\t\t\tlatestSummaryUpdated: true;\n\t\t\twasSummaryTracked: false;\n\t\t\tsnapshot: ISnapshotTree;\n\t };\n\nexport interface ISummarizerNodeRootContract {\n\tstartSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger): void;\n\tcompleteSummary(proposalHandle: string): void;\n\tclearSummary(): void;\n\trefreshLatestSummary(\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}\n\n/** Path for nodes in a tree with escaped special characters */\nexport class EscapedPath {\n\tprivate constructor(public readonly path: string) {}\n\tpublic static create(path: string): EscapedPath {\n\t\treturn new EscapedPath(encodeURIComponent(path));\n\t}\n\tpublic static createAndConcat(pathParts: string[]): EscapedPath {\n\t\tlet ret = EscapedPath.create(pathParts[0] ?? \"\");\n\t\tfor (let i = 1; i < pathParts.length; i++) {\n\t\t\tret = ret.concat(EscapedPath.create(pathParts[i]));\n\t\t}\n\t\treturn ret;\n\t}\n\tpublic toString(): string {\n\t\treturn this.path;\n\t}\n\tpublic concat(path: EscapedPath): EscapedPath {\n\t\treturn new EscapedPath(`${this.path}/${path.path}`);\n\t}\n}\n\n/** Information about a summary relevant to a specific node in the tree */\nexport class SummaryNode {\n\t/** Creates an instance that is valid for the root with specific basePath and localPath */\n\tpublic static createForRoot(referenceSequenceNumber: number): SummaryNode {\n\t\treturn new SummaryNode({\n\t\t\treferenceSequenceNumber,\n\t\t\tbasePath: undefined,\n\t\t\tlocalPath: EscapedPath.create(\"\"), // root hard-coded to \"\"\n\t\t});\n\t}\n\n\t/** Summary reference sequence number, i.e. last sequence number seen when it was created */\n\tpublic get referenceSequenceNumber(): number {\n\t\treturn this.summary.referenceSequenceNumber;\n\t}\n\t/** Full path to parent node, or undefined if this is the root */\n\tpublic get basePath(): EscapedPath | undefined {\n\t\treturn this.summary.basePath;\n\t}\n\t/** Relative path to this node from its parent node */\n\tpublic get localPath(): EscapedPath {\n\t\treturn this.summary.localPath;\n\t}\n\t/** Relative path from this node to its node innermost base summary */\n\tpublic get additionalPath(): EscapedPath | undefined {\n\t\treturn this.summary.additionalPath;\n\t}\n\tpublic set additionalPath(additionalPath: EscapedPath | undefined) {\n\t\tthis.summary.additionalPath = additionalPath;\n\t}\n\tconstructor(\n\t\tprivate readonly summary: {\n\t\t\treadonly referenceSequenceNumber: number;\n\t\t\treadonly basePath: EscapedPath | undefined;\n\t\t\treadonly localPath: EscapedPath;\n\t\t\tadditionalPath?: EscapedPath;\n\t\t},\n\t) {}\n\n\t/** Gets the full path to this node, to be used when sending a handle */\n\tpublic get fullPath(): EscapedPath {\n\t\treturn this.basePath?.concat(this.localPath) ?? this.localPath;\n\t}\n\n\t/**\n\t * Gets the full path to this node's innermost base summary.\n\t * The children nodes can use this as their basePath to determine their path.\n\t */\n\tpublic get fullPathForChildren(): EscapedPath {\n\t\treturn this.additionalPath !== undefined\n\t\t\t? this.fullPath.concat(this.additionalPath)\n\t\t\t: this.fullPath;\n\t}\n\n\t/**\n\t * Creates a new node within the same summary for a child of this node.\n\t * @param id - id of the child node\n\t */\n\tpublic createForChild(id: string): SummaryNode {\n\t\treturn new SummaryNode({\n\t\t\treferenceSequenceNumber: this.referenceSequenceNumber,\n\t\t\tbasePath: this.fullPathForChildren,\n\t\t\tlocalPath: EscapedPath.create(id),\n\t\t});\n\t}\n}\n\n/**\n * Parameter to help encode summary with conditional behavior.\n * When fromSummary is true, it will contain the SummaryNode of\n * its previous summary, which it can use to point to with a handle.\n * When fromSummary is false, it will use an actual summary tree\n * as its base summary in case the first summary is a differential summary.\n */\nexport type EncodeSummaryParam =\n\t| {\n\t\t\tfromSummary: true;\n\t\t\tsummaryNode: SummaryNode;\n\t }\n\t| {\n\t\t\tfromSummary: false;\n\t\t\tinitialSummary: ISummaryTreeWithStats;\n\t };\n\n/**\n * Information about the initial summary tree found from an attach op.\n */\nexport interface IInitialSummary {\n\tsequenceNumber: number;\n\tid: string;\n\tsummary: ISummaryTreeWithStats | undefined;\n}\n\n/**\n * Represents the details needed to create a child summarizer node.\n */\nexport interface ICreateChildDetails {\n\t/** Summary from attach op if known */\n\tinitialSummary: IInitialSummary | undefined;\n\t/** Latest summary from server node data */\n\tlatestSummary: SummaryNode | undefined;\n\t/** Sequence number of latest known change to the node */\n\tchangeSequenceNumber: number;\n}\n\nexport interface ISubtreeInfo<T extends ISnapshotTree | SummaryObject> {\n\t/** Tree to use to find children subtrees */\n\tchildrenTree: T;\n\t/** Additional path part where children are isolated */\n\tchildrenPathPart: string | undefined;\n}\n\n/**\n * Checks if the summary contains .channels subtree where the children subtrees\n * would be located if exists.\n * @param baseSummary - summary to check\n */\nexport function parseSummaryForSubtrees(baseSummary: ISnapshotTree): ISubtreeInfo<ISnapshotTree> {\n\t// New versions of snapshots have child nodes isolated in .channels subtree\n\tconst channelsSubtree = baseSummary.trees[channelsTreeName];\n\tif (channelsSubtree !== undefined) {\n\t\treturn {\n\t\t\tchildrenTree: channelsSubtree,\n\t\t\tchildrenPathPart: channelsTreeName,\n\t\t};\n\t}\n\treturn {\n\t\tchildrenTree: baseSummary,\n\t\tchildrenPathPart: undefined,\n\t};\n}\n\n/**\n * Checks if the summary contains .channels subtree where the children subtrees\n * would be located if exists.\n * @param baseSummary - summary to check\n */\nexport function parseSummaryTreeForSubtrees(summary: ISummaryTree): ISubtreeInfo<SummaryObject> {\n\t// New versions of snapshots have child nodes isolated in .channels subtree\n\tconst channelsSubtree = summary.tree[channelsTreeName];\n\tif (channelsSubtree !== undefined) {\n\t\treturn {\n\t\t\tchildrenTree: channelsSubtree,\n\t\t\tchildrenPathPart: channelsTreeName,\n\t\t};\n\t}\n\treturn {\n\t\tchildrenTree: summary,\n\t\tchildrenPathPart: undefined,\n\t};\n}\n"]}
|
|
@@ -1,135 +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 } from "@fluidframework/protocol-definitions";
|
|
7
|
-
import { CreateChildSummarizerNodeParam, IGarbageCollectionData, IGarbageCollectionDetailsBase, ISummarizeInternalResult, ISummarizeResult, ISummarizerNodeConfigWithGC, ISummarizerNodeWithGC, SummarizeInternalFn, ITelemetryContext } from "@fluidframework/runtime-definitions";
|
|
8
|
-
import { ReadAndParseBlob } from "../utils";
|
|
9
|
-
import { SummarizerNode } from "./summarizerNode";
|
|
10
|
-
import { EscapedPath, IInitialSummary, ISummarizerNodeRootContract, SummaryNode } from "./summarizerNodeUtils";
|
|
11
|
-
export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Extends the functionality of SummarizerNode to manage this node's garbage collection data:
|
|
15
|
-
*
|
|
16
|
-
* - Adds a new API `getGCData` to return GC data of this node.
|
|
17
|
-
*
|
|
18
|
-
* - Caches the result of `getGCData` to be used if nothing changes between summaries.
|
|
19
|
-
*
|
|
20
|
-
* - Manages the used routes of this node. These are used to identify if this node is referenced in the document
|
|
21
|
-
* and to determine if the node's used state changed since last summary.
|
|
22
|
-
*
|
|
23
|
-
* - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls
|
|
24
|
-
* directly into summarizeInternal method.
|
|
25
|
-
*/
|
|
26
|
-
export declare class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {
|
|
27
|
-
private readonly summarizeFn;
|
|
28
|
-
private readonly getGCDataFn?;
|
|
29
|
-
private wipSerializedUsedRoutes;
|
|
30
|
-
private referenceUsedRoutes;
|
|
31
|
-
private readonly baseGCDetailsP;
|
|
32
|
-
private baseGCDetailsLoaded;
|
|
33
|
-
private gcData;
|
|
34
|
-
private usedRoutes;
|
|
35
|
-
private readonly gcDisabled;
|
|
36
|
-
/**
|
|
37
|
-
* Do not call constructor directly.
|
|
38
|
-
* Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
|
|
39
|
-
*/
|
|
40
|
-
constructor(logger: ITelemetryLogger, summarizeFn: (fullTree: boolean, trackState: boolean, telemetryContext?: ITelemetryContext) => Promise<ISummarizeInternalResult>, config: ISummarizerNodeConfigWithGC, changeSequenceNumber: number,
|
|
41
|
-
/** Undefined means created without summary */
|
|
42
|
-
latestSummary?: SummaryNode, initialSummary?: IInitialSummary, wipSummaryLogger?: ITelemetryLogger, getGCDataFn?: ((fullGC?: boolean | undefined) => Promise<IGarbageCollectionData>) | undefined, getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>);
|
|
43
|
-
/**
|
|
44
|
-
* Loads state from this node's initial GC summary details. This contains the following data from the last summary
|
|
45
|
-
* seen by the server for this client:
|
|
46
|
-
* - usedRoutes: This is used to figure out if the used state of this node changed since last summary.
|
|
47
|
-
* - gcData: The garbage collection data of this node that is required for running GC.
|
|
48
|
-
*/
|
|
49
|
-
private loadBaseGCDetails;
|
|
50
|
-
summarize(fullTree: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummarizeResult>;
|
|
51
|
-
/**
|
|
52
|
-
* Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
|
|
53
|
-
* the previous summary. Else, it gets new GC data from the underlying Fluid object.
|
|
54
|
-
* @param fullGC - true to bypass optimizations and force full generation of GC data.
|
|
55
|
-
*/
|
|
56
|
-
getGCData(fullGC?: boolean): Promise<IGarbageCollectionData>;
|
|
57
|
-
/**
|
|
58
|
-
* Called during the start of a summary. Updates the work-in-progress used routes.
|
|
59
|
-
*/
|
|
60
|
-
startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger): void;
|
|
61
|
-
/**
|
|
62
|
-
* Called after summary has been uploaded to the server. Add the work-in-progress state to the pending
|
|
63
|
-
* summary queue. We track this until we get an ack from the server for this summary.
|
|
64
|
-
*/
|
|
65
|
-
protected completeSummaryCore(proposalHandle: string, parentPath: EscapedPath | undefined, parentSkipRecursion: boolean): void;
|
|
66
|
-
/**
|
|
67
|
-
* Clears the work-in-progress state.
|
|
68
|
-
*/
|
|
69
|
-
clearSummary(): void;
|
|
70
|
-
/**
|
|
71
|
-
* Called when we get an ack from the server for a summary we sent. Update the reference state of this node
|
|
72
|
-
* from the state in the pending summary queue.
|
|
73
|
-
*/
|
|
74
|
-
protected refreshLatestSummaryFromPending(proposalHandle: string, referenceSequenceNumber: number): void;
|
|
75
|
-
/**
|
|
76
|
-
* Called when we need to upload the reference state from the given summary.
|
|
77
|
-
*/
|
|
78
|
-
protected refreshLatestSummaryFromSnapshot(referenceSequenceNumber: number, snapshotTree: ISnapshotTree, basePath: EscapedPath | undefined, localPath: EscapedPath, correlatedSummaryLogger: ITelemetryLogger, readAndParseBlob: ReadAndParseBlob): Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Updates GC state from the given snapshot if GC is enabled and the snapshot is newer than the one this node
|
|
81
|
-
* is tracking.
|
|
82
|
-
*/
|
|
83
|
-
private refreshGCStateFromSnapshot;
|
|
84
|
-
/**
|
|
85
|
-
* Override the createChild method to return an instance of SummarizerNodeWithGC.
|
|
86
|
-
*/
|
|
87
|
-
createChild(
|
|
88
|
-
/** Summarize function */
|
|
89
|
-
summarizeInternalFn: SummarizeInternalFn,
|
|
90
|
-
/** Initial id or path part of this node */
|
|
91
|
-
id: string,
|
|
92
|
-
/**
|
|
93
|
-
* Information needed to create the node.
|
|
94
|
-
* If it is from a base summary, it will assert that a summary has been seen.
|
|
95
|
-
* Attach information if it is created from an attach op.
|
|
96
|
-
*/
|
|
97
|
-
createParam: CreateChildSummarizerNodeParam, config?: ISummarizerNodeConfigWithGC, getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>, getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>): ISummarizerNodeWithGC;
|
|
98
|
-
/**
|
|
99
|
-
* Deletes the child node with the given id.
|
|
100
|
-
*/
|
|
101
|
-
deleteChild(id: string): void;
|
|
102
|
-
/**
|
|
103
|
-
* Override the getChild method to return an instance of SummarizerNodeWithGC.
|
|
104
|
-
*/
|
|
105
|
-
getChild(id: string): ISummarizerNodeWithGC | undefined;
|
|
106
|
-
isReferenced(): boolean;
|
|
107
|
-
updateUsedRoutes(usedRoutes: string[]): void;
|
|
108
|
-
/**
|
|
109
|
-
* Override the hasChanged method. If this node data or its used state changed, the node is considered changed.
|
|
110
|
-
*/
|
|
111
|
-
protected hasChanged(): boolean;
|
|
112
|
-
/**
|
|
113
|
-
* This tells whether the data in this node has changed or not.
|
|
114
|
-
*/
|
|
115
|
-
private hasDataChanged;
|
|
116
|
-
/**
|
|
117
|
-
* This tells whether the used state of this node has changed since last successful summary. If the used routes
|
|
118
|
-
* of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes
|
|
119
|
-
* was previously used and became unused (or vice versa), its used state has changed.
|
|
120
|
-
*/
|
|
121
|
-
private hasUsedStateChanged;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Creates a root summarizer node with GC functionality built-in.
|
|
125
|
-
* @param logger - Logger to use within SummarizerNode
|
|
126
|
-
* @param summarizeInternalFn - Function to generate summary
|
|
127
|
-
* @param changeSequenceNumber - Sequence number of latest change to new node/subtree
|
|
128
|
-
* @param referenceSequenceNumber - Reference sequence number of last acked summary,
|
|
129
|
-
* or undefined if not loaded from summary
|
|
130
|
-
* @param config - Configure behavior of summarizer node
|
|
131
|
-
* @param getGCDataFn - Function to get the GC data of this node
|
|
132
|
-
* @param baseGCDetailsP - Function to get the initial GC details of this node
|
|
133
|
-
*/
|
|
134
|
-
export declare const createRootSummarizerNodeWithGC: (logger: ITelemetryLogger, summarizeInternalFn: SummarizeInternalFn, changeSequenceNumber: number, referenceSequenceNumber: number | undefined, config?: ISummarizerNodeConfigWithGC, getGCDataFn?: ((fullGC?: boolean | undefined) => Promise<IGarbageCollectionData>) | undefined, getBaseGCDetailsFn?: (() => Promise<IGarbageCollectionDetailsBase>) | undefined) => IRootSummarizerNodeWithGC;
|
|
135
|
-
//# sourceMappingURL=summarizerNodeWithGc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"summarizerNodeWithGc.d.ts","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNodeWithGc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAQtE,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EACN,8BAA8B,EAE9B,sBAAsB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;IACI,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACI,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IAIvD,YAAY,IAAI,OAAO;IAIvB,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE;IAY5C;;OAEG;IACH,SAAS,CAAC,UAAU,IAAI,OAAO;IAI/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;CAW3B;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,8BAA8B,WAClC,gBAAgB,uBACH,mBAAmB,wBAClB,MAAM,2BACH,MAAM,GAAG,SAAS,WACnC,2BAA2B,mDACC,QAAQ,sBAAsB,CAAC,2CACxC,QAAQ,6BAA6B,CAAC,kBAC/D,yBAaD,CAAC"}
|
|
@@ -1,356 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { assert, LazyPromise } from "@fluidframework/common-utils";
|
|
6
|
-
import { cloneGCData, getGCDataFromSnapshot, runGarbageCollection, unpackChildNodesGCDetails, } from "@fluidframework/garbage-collector";
|
|
7
|
-
import { gcTreeKey, } from "@fluidframework/runtime-definitions";
|
|
8
|
-
import { SummarizerNode } from "./summarizerNode";
|
|
9
|
-
import { parseSummaryForSubtrees, SummaryNode, } from "./summarizerNodeUtils";
|
|
10
|
-
// Extend SummaryNode to add used routes tracking to it.
|
|
11
|
-
class SummaryNodeWithGC extends SummaryNode {
|
|
12
|
-
constructor(serializedUsedRoutes, summary) {
|
|
13
|
-
super(summary);
|
|
14
|
-
this.serializedUsedRoutes = serializedUsedRoutes;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Extends the functionality of SummarizerNode to manage this node's garbage collection data:
|
|
19
|
-
*
|
|
20
|
-
* - Adds a new API `getGCData` to return GC data of this node.
|
|
21
|
-
*
|
|
22
|
-
* - Caches the result of `getGCData` to be used if nothing changes between summaries.
|
|
23
|
-
*
|
|
24
|
-
* - Manages the used routes of this node. These are used to identify if this node is referenced in the document
|
|
25
|
-
* and to determine if the node's used state changed since last summary.
|
|
26
|
-
*
|
|
27
|
-
* - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls
|
|
28
|
-
* directly into summarizeInternal method.
|
|
29
|
-
*/
|
|
30
|
-
export class SummarizerNodeWithGC extends SummarizerNode {
|
|
31
|
-
/**
|
|
32
|
-
* Do not call constructor directly.
|
|
33
|
-
* Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
|
|
34
|
-
*/
|
|
35
|
-
constructor(logger, summarizeFn, config, changeSequenceNumber,
|
|
36
|
-
/** Undefined means created without summary */
|
|
37
|
-
latestSummary, initialSummary, wipSummaryLogger, getGCDataFn, getBaseGCDetailsFn) {
|
|
38
|
-
super(logger, async (fullTree, _trackState, telemetryContext) => summarizeFn(fullTree, true /* trackState */, telemetryContext), config, changeSequenceNumber, latestSummary, initialSummary, wipSummaryLogger);
|
|
39
|
-
this.summarizeFn = summarizeFn;
|
|
40
|
-
this.getGCDataFn = getGCDataFn;
|
|
41
|
-
// Keeps track of whether we have loaded the base details to ensure that we on;y do it once.
|
|
42
|
-
this.baseGCDetailsLoaded = false;
|
|
43
|
-
// Set used routes to have self route by default. This makes the node referenced by default. This is done to ensure
|
|
44
|
-
// that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is
|
|
45
|
-
// removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.
|
|
46
|
-
this.usedRoutes = [""];
|
|
47
|
-
this.gcDisabled = config.gcDisabled === true;
|
|
48
|
-
this.baseGCDetailsP = new LazyPromise(async () => {
|
|
49
|
-
var _a;
|
|
50
|
-
return (_a = (await (getBaseGCDetailsFn === null || getBaseGCDetailsFn === void 0 ? void 0 : getBaseGCDetailsFn()))) !== null && _a !== void 0 ? _a : { usedRoutes: [] };
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Loads state from this node's initial GC summary details. This contains the following data from the last summary
|
|
55
|
-
* seen by the server for this client:
|
|
56
|
-
* - usedRoutes: This is used to figure out if the used state of this node changed since last summary.
|
|
57
|
-
* - gcData: The garbage collection data of this node that is required for running GC.
|
|
58
|
-
*/
|
|
59
|
-
async loadBaseGCDetails() {
|
|
60
|
-
if (this.baseGCDetailsLoaded) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const baseGCDetails = await this.baseGCDetailsP;
|
|
64
|
-
// Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we update
|
|
65
|
-
// the state from the base details only once.
|
|
66
|
-
if (this.baseGCDetailsLoaded) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
this.baseGCDetailsLoaded = true;
|
|
70
|
-
// Update GC data, used routes and reference used routes. The used routes are sorted because they are compared
|
|
71
|
-
// across GC runs to check if they changed. Sorting ensures that the elements are in the same order.
|
|
72
|
-
// If the GC details has GC data, initialize our GC data from it.
|
|
73
|
-
if (baseGCDetails.gcData !== undefined) {
|
|
74
|
-
this.gcData = cloneGCData(baseGCDetails.gcData);
|
|
75
|
-
}
|
|
76
|
-
if (baseGCDetails.usedRoutes !== undefined) {
|
|
77
|
-
this.usedRoutes = Array.from(baseGCDetails.usedRoutes).sort();
|
|
78
|
-
this.referenceUsedRoutes = Array.from(baseGCDetails.usedRoutes).sort();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
async summarize(fullTree, trackState = true, telemetryContext) {
|
|
82
|
-
// If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this
|
|
83
|
-
// summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.
|
|
84
|
-
if (!this.gcDisabled && this.isTrackingInProgress()) {
|
|
85
|
-
assert(this.wipSerializedUsedRoutes !== undefined, 0x1b1 /* "wip used routes should be set if tracking a summary" */);
|
|
86
|
-
}
|
|
87
|
-
// If trackState is true, get summary from base summarizer node which tracks summary state.
|
|
88
|
-
// If trackState is false, get summary from summarizeInternal.
|
|
89
|
-
return trackState
|
|
90
|
-
? super.summarize(fullTree, true /* trackState */, telemetryContext)
|
|
91
|
-
: this.summarizeFn(fullTree, trackState, telemetryContext);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
|
|
95
|
-
* the previous summary. Else, it gets new GC data from the underlying Fluid object.
|
|
96
|
-
* @param fullGC - true to bypass optimizations and force full generation of GC data.
|
|
97
|
-
*/
|
|
98
|
-
async getGCData(fullGC = false) {
|
|
99
|
-
assert(!this.gcDisabled, 0x1b2 /* "Getting GC data should not be called when GC is disabled!" */);
|
|
100
|
-
assert(this.getGCDataFn !== undefined, 0x1b3 /* "GC data cannot be retrieved without getGCDataFn" */);
|
|
101
|
-
// Load GC details from the initial summary, if not already loaded. If this is the first time this function is
|
|
102
|
-
// called and the node's data has not changed since last summary, the GC data in initial details is returned.
|
|
103
|
-
await this.loadBaseGCDetails();
|
|
104
|
-
// If there is no new data since last summary and we have GC data from the previous run, return it. The previous
|
|
105
|
-
// GC data may not be available if loaded from a snapshot with either GC disabled or before GC was added.
|
|
106
|
-
// Note - canReuseHandle is checked to be consistent with summarize - generate GC data for nodes for which
|
|
107
|
-
// summary must be generated.
|
|
108
|
-
if (this.canReuseHandle && !fullGC && !this.hasDataChanged() && this.gcData !== undefined) {
|
|
109
|
-
return cloneGCData(this.gcData);
|
|
110
|
-
}
|
|
111
|
-
const gcData = await this.getGCDataFn(fullGC);
|
|
112
|
-
this.gcData = cloneGCData(gcData);
|
|
113
|
-
return gcData;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Called during the start of a summary. Updates the work-in-progress used routes.
|
|
117
|
-
*/
|
|
118
|
-
startSummary(referenceSequenceNumber, summaryLogger) {
|
|
119
|
-
// If GC is disabled, skip setting wip used routes since we should not track GC state.
|
|
120
|
-
if (!this.gcDisabled) {
|
|
121
|
-
assert(this.wipSerializedUsedRoutes === undefined, 0x1b4 /* "We should not already be tracking used routes when to track a new summary" */);
|
|
122
|
-
}
|
|
123
|
-
super.startSummary(referenceSequenceNumber, summaryLogger);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Called after summary has been uploaded to the server. Add the work-in-progress state to the pending
|
|
127
|
-
* summary queue. We track this until we get an ack from the server for this summary.
|
|
128
|
-
*/
|
|
129
|
-
completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion) {
|
|
130
|
-
let wipSerializedUsedRoutes;
|
|
131
|
-
// If GC is disabled, don't set wip used routes.
|
|
132
|
-
if (!this.gcDisabled) {
|
|
133
|
-
wipSerializedUsedRoutes = this.wipSerializedUsedRoutes;
|
|
134
|
-
assert(wipSerializedUsedRoutes !== undefined, 0x1b5 /* "We should have been tracking used routes" */);
|
|
135
|
-
}
|
|
136
|
-
super.completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion);
|
|
137
|
-
// If GC is disabled, skip setting pending summary with GC state.
|
|
138
|
-
if (!this.gcDisabled) {
|
|
139
|
-
const summaryNode = this.pendingSummaries.get(proposalHandle);
|
|
140
|
-
if (summaryNode !== undefined) {
|
|
141
|
-
const summaryNodeWithGC = new SummaryNodeWithGC(
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
143
|
-
wipSerializedUsedRoutes, summaryNode);
|
|
144
|
-
this.pendingSummaries.set(proposalHandle, summaryNodeWithGC);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Clears the work-in-progress state.
|
|
150
|
-
*/
|
|
151
|
-
clearSummary() {
|
|
152
|
-
this.wipSerializedUsedRoutes = undefined;
|
|
153
|
-
super.clearSummary();
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Called when we get an ack from the server for a summary we sent. Update the reference state of this node
|
|
157
|
-
* from the state in the pending summary queue.
|
|
158
|
-
*/
|
|
159
|
-
refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber) {
|
|
160
|
-
// If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
|
|
161
|
-
if (!this.gcDisabled) {
|
|
162
|
-
const summaryNode = this.pendingSummaries.get(proposalHandle);
|
|
163
|
-
if ((summaryNode === null || summaryNode === void 0 ? void 0 : summaryNode.serializedUsedRoutes) !== undefined) {
|
|
164
|
-
this.referenceUsedRoutes = JSON.parse(summaryNode.serializedUsedRoutes);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Called when we need to upload the reference state from the given summary.
|
|
171
|
-
*/
|
|
172
|
-
async refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob) {
|
|
173
|
-
await this.refreshGCStateFromSnapshot(referenceSequenceNumber, snapshotTree, readAndParseBlob);
|
|
174
|
-
return super.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Updates GC state from the given snapshot if GC is enabled and the snapshot is newer than the one this node
|
|
178
|
-
* is tracking.
|
|
179
|
-
*/
|
|
180
|
-
async refreshGCStateFromSnapshot(referenceSequenceNumber, snapshotTree, readAndParseBlob) {
|
|
181
|
-
// If GC is disabled or we have seen a newer summary, skip updating GC state.
|
|
182
|
-
if (this.gcDisabled || this.referenceSequenceNumber >= referenceSequenceNumber) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
// Load the base GC details before proceeding because if that happens later it can overwrite the GC details
|
|
186
|
-
// written by the following code.
|
|
187
|
-
await this.loadBaseGCDetails();
|
|
188
|
-
// Possible re-entrancy. We may already have processed this while loading base GC details.
|
|
189
|
-
if (this.referenceSequenceNumber >= referenceSequenceNumber) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* GC data is written at root of the snapshot tree under "gc" sub-tree. This data needs to be propagated to
|
|
194
|
-
* all the nodes in the container.
|
|
195
|
-
* The root summarizer node reads the GC data from the "gc" sub-tree, runs GC on it to get used routes in
|
|
196
|
-
* the container and updates its GC data and referenced used routes. It then gets the GC data and used
|
|
197
|
-
* routes of all its children and adds it to their snapshot tree.
|
|
198
|
-
* All the other nodes gets the GC data and used routes from their snapshot tree and updates their state.
|
|
199
|
-
* They get the GC data and used routes of their children and add it to their snapshot tree and so on.
|
|
200
|
-
*
|
|
201
|
-
* Note that if the snapshot does not have GC tree, GC data will be set to undefined and used routes will be
|
|
202
|
-
* set to self-route (meaning referenced) for all nodes. This is important because the GC data needs to be
|
|
203
|
-
* regenerated in the next summary.
|
|
204
|
-
*/
|
|
205
|
-
let gcDetails;
|
|
206
|
-
const gcSnapshotTree = snapshotTree.trees[gcTreeKey];
|
|
207
|
-
if (gcSnapshotTree !== undefined) {
|
|
208
|
-
// If there is a GC tree in the snapshot, this is the root summarizer node. Read GC data from the tree
|
|
209
|
-
// process it as explained above.
|
|
210
|
-
const gcSnapshotData = await getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);
|
|
211
|
-
const gcNodes = {};
|
|
212
|
-
for (const [nodeId, nodeData] of Object.entries(gcSnapshotData.gcState.gcNodes)) {
|
|
213
|
-
gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
|
|
214
|
-
}
|
|
215
|
-
// Run GC on the nodes in the snapshot to get the used routes for each node in the container.
|
|
216
|
-
const usedRoutes = runGarbageCollection(gcNodes, ["/"]).referencedNodeIds;
|
|
217
|
-
gcDetails = { gcData: { gcNodes }, usedRoutes };
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
// If there is a GC blob in the snapshot, it's a non-root summarizer nodes - The root summarizer node
|
|
221
|
-
// writes GC blob in the snapshot of child nodes. Get GC data and used routes from the blob.
|
|
222
|
-
const gcDetailsBlob = snapshotTree.blobs[gcTreeKey];
|
|
223
|
-
if (gcDetailsBlob !== undefined) {
|
|
224
|
-
gcDetails = JSON.parse(gcDetailsBlob);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// Update this node to the same GC state it was when the ack corresponding to this summary was processed.
|
|
228
|
-
this.gcData = (gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.gcData) !== undefined ? cloneGCData(gcDetails.gcData) : undefined;
|
|
229
|
-
this.referenceUsedRoutes =
|
|
230
|
-
(gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.usedRoutes) !== undefined ? Array.from(gcDetails.usedRoutes) : undefined;
|
|
231
|
-
// If there are no used routes in the GC details, set it to have self route which will make the node
|
|
232
|
-
// referenced. This scenario can only happen if the snapshot is from a client where GC was not run or
|
|
233
|
-
// disabled. In both the cases, the node should be referenced.
|
|
234
|
-
this.usedRoutes =
|
|
235
|
-
(gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.usedRoutes) !== undefined ? Array.from(gcDetails.usedRoutes) : [""];
|
|
236
|
-
if (gcDetails === undefined) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
// Generate the GC data and used routes of children GC nodes and add it to their snapshot tree.
|
|
240
|
-
const gcDetailsMap = unpackChildNodesGCDetails(gcDetails);
|
|
241
|
-
const { childrenTree } = parseSummaryForSubtrees(snapshotTree);
|
|
242
|
-
gcDetailsMap.forEach((childGCDetails, childId) => {
|
|
243
|
-
if (childrenTree.trees[childId] !== undefined) {
|
|
244
|
-
childrenTree.trees[childId].blobs[gcTreeKey] = JSON.stringify(childGCDetails);
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Override the createChild method to return an instance of SummarizerNodeWithGC.
|
|
250
|
-
*/
|
|
251
|
-
createChild(
|
|
252
|
-
/** Summarize function */
|
|
253
|
-
summarizeInternalFn,
|
|
254
|
-
/** Initial id or path part of this node */
|
|
255
|
-
id,
|
|
256
|
-
/**
|
|
257
|
-
* Information needed to create the node.
|
|
258
|
-
* If it is from a base summary, it will assert that a summary has been seen.
|
|
259
|
-
* Attach information if it is created from an attach op.
|
|
260
|
-
*/
|
|
261
|
-
createParam, config = {}, getGCDataFn, getBaseGCDetailsFn) {
|
|
262
|
-
var _a;
|
|
263
|
-
assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
|
|
264
|
-
/**
|
|
265
|
-
* Update the child node's base GC details from this node's current GC details instead of updating from the base
|
|
266
|
-
* GC details of this node. This will handle scenarios where the GC details was updated during refresh from
|
|
267
|
-
* snapshot and the child node wasn't created then. If a child is created after that, its GC details should be
|
|
268
|
-
* the one from the downloaded snapshot and not the base GC details.
|
|
269
|
-
*/
|
|
270
|
-
const getChildBaseGCDetailsP = new LazyPromise(async () => {
|
|
271
|
-
var _a;
|
|
272
|
-
// Ensure that the base GC details is loaded because a child can be created before GC runs which is when
|
|
273
|
-
// base GC details is usually loaded.
|
|
274
|
-
await this.loadBaseGCDetails();
|
|
275
|
-
const childBaseGCDetails = unpackChildNodesGCDetails({
|
|
276
|
-
gcData: this.gcData,
|
|
277
|
-
usedRoutes: this.usedRoutes,
|
|
278
|
-
});
|
|
279
|
-
return (_a = childBaseGCDetails.get(id)) !== null && _a !== void 0 ? _a : {};
|
|
280
|
-
});
|
|
281
|
-
const createDetails = this.getCreateDetailsForChild(id, createParam);
|
|
282
|
-
const child = new SummarizerNodeWithGC(this.defaultLogger, summarizeInternalFn, Object.assign(Object.assign({}, config), {
|
|
283
|
-
// Propagate our gcDisabled state to the child if its not explicity specified in child's config.
|
|
284
|
-
gcDisabled: (_a = config.gcDisabled) !== null && _a !== void 0 ? _a : this.gcDisabled }), createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, getGCDataFn, async () => getChildBaseGCDetailsP);
|
|
285
|
-
// There may be additional state that has to be updated in this child. For example, if a summary is being
|
|
286
|
-
// tracked, the child's summary tracking state needs to be updated too.
|
|
287
|
-
this.maybeUpdateChildState(child);
|
|
288
|
-
this.children.set(id, child);
|
|
289
|
-
return child;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Deletes the child node with the given id.
|
|
293
|
-
*/
|
|
294
|
-
deleteChild(id) {
|
|
295
|
-
this.children.delete(id);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Override the getChild method to return an instance of SummarizerNodeWithGC.
|
|
299
|
-
*/
|
|
300
|
-
getChild(id) {
|
|
301
|
-
return this.children.get(id);
|
|
302
|
-
}
|
|
303
|
-
isReferenced() {
|
|
304
|
-
return this.usedRoutes.includes("") || this.usedRoutes.includes("/");
|
|
305
|
-
}
|
|
306
|
-
updateUsedRoutes(usedRoutes) {
|
|
307
|
-
// Sort the given routes before updating. This will ensure that the routes compared in hasUsedStateChanged()
|
|
308
|
-
// are in the same order.
|
|
309
|
-
this.usedRoutes = usedRoutes.sort();
|
|
310
|
-
// If GC is not disabled and we are tracking a summary, update the work-in-progress used routes so that it can
|
|
311
|
-
// be tracked for this summary.
|
|
312
|
-
if (!this.gcDisabled && this.isTrackingInProgress()) {
|
|
313
|
-
this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Override the hasChanged method. If this node data or its used state changed, the node is considered changed.
|
|
318
|
-
*/
|
|
319
|
-
hasChanged() {
|
|
320
|
-
return this.hasDataChanged() || this.hasUsedStateChanged();
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* This tells whether the data in this node has changed or not.
|
|
324
|
-
*/
|
|
325
|
-
hasDataChanged() {
|
|
326
|
-
return super.hasChanged();
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* This tells whether the used state of this node has changed since last successful summary. If the used routes
|
|
330
|
-
* of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes
|
|
331
|
-
* was previously used and became unused (or vice versa), its used state has changed.
|
|
332
|
-
*/
|
|
333
|
-
hasUsedStateChanged() {
|
|
334
|
-
// If GC is disabled, we are not tracking used state, return false.
|
|
335
|
-
if (this.gcDisabled) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
return (this.referenceUsedRoutes === undefined ||
|
|
339
|
-
JSON.stringify(this.usedRoutes) !== JSON.stringify(this.referenceUsedRoutes));
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Creates a root summarizer node with GC functionality built-in.
|
|
344
|
-
* @param logger - Logger to use within SummarizerNode
|
|
345
|
-
* @param summarizeInternalFn - Function to generate summary
|
|
346
|
-
* @param changeSequenceNumber - Sequence number of latest change to new node/subtree
|
|
347
|
-
* @param referenceSequenceNumber - Reference sequence number of last acked summary,
|
|
348
|
-
* or undefined if not loaded from summary
|
|
349
|
-
* @param config - Configure behavior of summarizer node
|
|
350
|
-
* @param getGCDataFn - Function to get the GC data of this node
|
|
351
|
-
* @param baseGCDetailsP - Function to get the initial GC details of this node
|
|
352
|
-
*/
|
|
353
|
-
export const createRootSummarizerNodeWithGC = (logger, summarizeInternalFn, changeSequenceNumber, referenceSequenceNumber, config = {}, getGCDataFn, getBaseGCDetailsFn) => new SummarizerNodeWithGC(logger, summarizeInternalFn, config, changeSequenceNumber, referenceSequenceNumber === undefined
|
|
354
|
-
? undefined
|
|
355
|
-
: SummaryNode.createForRoot(referenceSequenceNumber), undefined /* initialSummary */, undefined /* wipSummaryLogger */, getGCDataFn, getBaseGCDetailsFn);
|
|
356
|
-
//# sourceMappingURL=summarizerNodeWithGc.js.map
|