@fluidframework/runtime-utils 2.0.0-dev.2.3.0.115467 → 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 (122) hide show
  1. package/.eslintrc.js +5 -7
  2. package/.mocharc.js +2 -2
  3. package/api-extractor.json +2 -2
  4. package/dist/dataStoreHandleContextUtils.d.ts.map +1 -1
  5. package/dist/dataStoreHandleContextUtils.js +3 -1
  6. package/dist/dataStoreHandleContextUtils.js.map +1 -1
  7. package/dist/dataStoreHelpers.d.ts +3 -1
  8. package/dist/dataStoreHelpers.d.ts.map +1 -1
  9. package/dist/dataStoreHelpers.js +27 -8
  10. package/dist/dataStoreHelpers.js.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +4 -4
  14. package/dist/index.js.map +1 -1
  15. package/dist/objectstoragepartition.d.ts.map +1 -1
  16. package/dist/objectstoragepartition.js.map +1 -1
  17. package/dist/objectstorageutils.d.ts.map +1 -1
  18. package/dist/objectstorageutils.js.map +1 -1
  19. package/dist/packageVersion.d.ts +1 -1
  20. package/dist/packageVersion.js +1 -1
  21. package/dist/packageVersion.js.map +1 -1
  22. package/dist/requestParser.d.ts.map +1 -1
  23. package/dist/requestParser.js.map +1 -1
  24. package/dist/runtimeFactoryHelper.d.ts +1 -1
  25. package/dist/runtimeFactoryHelper.d.ts.map +1 -1
  26. package/dist/runtimeFactoryHelper.js +7 -6
  27. package/dist/runtimeFactoryHelper.js.map +1 -1
  28. package/dist/summaryUtils.d.ts +33 -1
  29. package/dist/summaryUtils.d.ts.map +1 -1
  30. package/dist/summaryUtils.js +86 -3
  31. package/dist/summaryUtils.js.map +1 -1
  32. package/dist/unpackUsedRoutes.d.ts +11 -0
  33. package/dist/unpackUsedRoutes.d.ts.map +1 -0
  34. package/dist/unpackUsedRoutes.js +33 -0
  35. package/dist/unpackUsedRoutes.js.map +1 -0
  36. package/dist/utils.d.ts.map +1 -1
  37. package/dist/utils.js.map +1 -1
  38. package/lib/dataStoreHandleContextUtils.d.ts.map +1 -1
  39. package/lib/dataStoreHandleContextUtils.js +3 -1
  40. package/lib/dataStoreHandleContextUtils.js.map +1 -1
  41. package/lib/dataStoreHelpers.d.ts +3 -1
  42. package/lib/dataStoreHelpers.d.ts.map +1 -1
  43. package/lib/dataStoreHelpers.js +27 -8
  44. package/lib/dataStoreHelpers.js.map +1 -1
  45. package/lib/index.d.ts +2 -2
  46. package/lib/index.d.ts.map +1 -1
  47. package/lib/index.js +2 -2
  48. package/lib/index.js.map +1 -1
  49. package/lib/objectstoragepartition.d.ts.map +1 -1
  50. package/lib/objectstoragepartition.js.map +1 -1
  51. package/lib/objectstorageutils.d.ts.map +1 -1
  52. package/lib/objectstorageutils.js.map +1 -1
  53. package/lib/packageVersion.d.ts +1 -1
  54. package/lib/packageVersion.js +1 -1
  55. package/lib/packageVersion.js.map +1 -1
  56. package/lib/requestParser.d.ts.map +1 -1
  57. package/lib/requestParser.js.map +1 -1
  58. package/lib/runtimeFactoryHelper.d.ts +1 -1
  59. package/lib/runtimeFactoryHelper.d.ts.map +1 -1
  60. package/lib/runtimeFactoryHelper.js +7 -6
  61. package/lib/runtimeFactoryHelper.js.map +1 -1
  62. package/lib/summaryUtils.d.ts +33 -1
  63. package/lib/summaryUtils.d.ts.map +1 -1
  64. package/lib/summaryUtils.js +84 -2
  65. package/lib/summaryUtils.js.map +1 -1
  66. package/lib/unpackUsedRoutes.d.ts +11 -0
  67. package/lib/unpackUsedRoutes.d.ts.map +1 -0
  68. package/lib/unpackUsedRoutes.js +29 -0
  69. package/lib/unpackUsedRoutes.js.map +1 -0
  70. package/lib/utils.d.ts.map +1 -1
  71. package/lib/utils.js.map +1 -1
  72. package/package.json +54 -55
  73. package/prettier.config.cjs +1 -1
  74. package/src/dataStoreHandleContextUtils.ts +23 -16
  75. package/src/dataStoreHelpers.ts +104 -82
  76. package/src/index.ts +3 -9
  77. package/src/objectstoragepartition.ts +13 -13
  78. package/src/objectstorageutils.ts +31 -28
  79. package/src/packageVersion.ts +1 -1
  80. package/src/requestParser.ts +80 -82
  81. package/src/runtimeFactoryHelper.ts +24 -22
  82. package/src/summaryUtils.ts +393 -291
  83. package/src/unpackUsedRoutes.ts +30 -0
  84. package/src/utils.ts +6 -6
  85. package/tsconfig.esnext.json +6 -6
  86. package/tsconfig.json +8 -12
  87. package/dist/summarizerNode/index.d.ts +0 -8
  88. package/dist/summarizerNode/index.d.ts.map +0 -1
  89. package/dist/summarizerNode/index.js +0 -12
  90. package/dist/summarizerNode/index.js.map +0 -1
  91. package/dist/summarizerNode/summarizerNode.d.ts +0 -140
  92. package/dist/summarizerNode/summarizerNode.d.ts.map +0 -1
  93. package/dist/summarizerNode/summarizerNode.js +0 -439
  94. package/dist/summarizerNode/summarizerNode.js.map +0 -1
  95. package/dist/summarizerNode/summarizerNodeUtils.d.ts +0 -128
  96. package/dist/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  97. package/dist/summarizerNode/summarizerNodeUtils.js +0 -132
  98. package/dist/summarizerNode/summarizerNodeUtils.js.map +0 -1
  99. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +0 -131
  100. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  101. package/dist/summarizerNode/summarizerNodeWithGc.js +0 -275
  102. package/dist/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  103. package/lib/summarizerNode/index.d.ts +0 -8
  104. package/lib/summarizerNode/index.d.ts.map +0 -1
  105. package/lib/summarizerNode/index.js +0 -7
  106. package/lib/summarizerNode/index.js.map +0 -1
  107. package/lib/summarizerNode/summarizerNode.d.ts +0 -140
  108. package/lib/summarizerNode/summarizerNode.d.ts.map +0 -1
  109. package/lib/summarizerNode/summarizerNode.js +0 -434
  110. package/lib/summarizerNode/summarizerNode.js.map +0 -1
  111. package/lib/summarizerNode/summarizerNodeUtils.d.ts +0 -128
  112. package/lib/summarizerNode/summarizerNodeUtils.d.ts.map +0 -1
  113. package/lib/summarizerNode/summarizerNodeUtils.js +0 -125
  114. package/lib/summarizerNode/summarizerNodeUtils.js.map +0 -1
  115. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +0 -131
  116. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +0 -1
  117. package/lib/summarizerNode/summarizerNodeWithGc.js +0 -270
  118. package/lib/summarizerNode/summarizerNodeWithGc.js.map +0 -1
  119. package/src/summarizerNode/index.ts +0 -8
  120. package/src/summarizerNode/summarizerNode.ts +0 -593
  121. package/src/summarizerNode/summarizerNodeUtils.ts +0 -216
  122. package/src/summarizerNode/summarizerNodeWithGc.ts +0 -432
@@ -1,216 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
- import {
8
- ISnapshotTree,
9
- ISummaryTree,
10
- SummaryObject,
11
- } from "@fluidframework/protocol-definitions";
12
- import { channelsTreeName, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
13
- import { ReadAndParseBlob } from "../utils";
14
-
15
- /**
16
- * Return value of refreshSummaryAck function. There can be three different scenarios based on the passed params:
17
- *
18
- * 1. The latest summary was not udpated.
19
- *
20
- * 2. The latest summary was updated and the summary corresponding to the params was tracked by this client.
21
- *
22
- * 3. The latest summary was updated but the summary corresponding to the params was not tracked. In this case, the
23
- * latest summary is updated based on the downloaded snapshot which is also returned.
24
- */
25
- export type RefreshSummaryResult = {
26
- latestSummaryUpdated: false;
27
- } | {
28
- latestSummaryUpdated: true;
29
- wasSummaryTracked: true;
30
- } | {
31
- latestSummaryUpdated: true;
32
- wasSummaryTracked: false;
33
- snapshot: ISnapshotTree;
34
- };
35
-
36
- export interface ISummarizerNodeRootContract {
37
- startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger): void;
38
- completeSummary(proposalHandle: string): void;
39
- clearSummary(): void;
40
- refreshLatestSummary(
41
- proposalHandle: string | undefined,
42
- summaryRefSeq: number,
43
- getSnapshot: () => Promise<ISnapshotTree>,
44
- readAndParseBlob: ReadAndParseBlob,
45
- correlatedSummaryLogger: ITelemetryLogger,
46
- ): Promise<RefreshSummaryResult>;
47
- }
48
-
49
- /** Path for nodes in a tree with escaped special characters */
50
- export class EscapedPath {
51
- private constructor(public readonly path: string) { }
52
- public static create(path: string): EscapedPath {
53
- return new EscapedPath(encodeURIComponent(path));
54
- }
55
- public static createAndConcat(pathParts: string[]): EscapedPath {
56
- let ret = EscapedPath.create(pathParts[0] ?? "");
57
- for (let i = 1; i < pathParts.length; i++) {
58
- ret = ret.concat(EscapedPath.create(pathParts[i]));
59
- }
60
- return ret;
61
- }
62
- public toString(): string {
63
- return this.path;
64
- }
65
- public concat(path: EscapedPath): EscapedPath {
66
- return new EscapedPath(`${this.path}/${path.path}`);
67
- }
68
- }
69
-
70
- /** Information about a summary relevant to a specific node in the tree */
71
- export class SummaryNode {
72
- /** Creates an instance that is valid for the root with specific basePath and localPath */
73
- public static createForRoot(referenceSequenceNumber: number): SummaryNode {
74
- return new SummaryNode({
75
- referenceSequenceNumber,
76
- basePath: undefined,
77
- localPath: EscapedPath.create(""), // root hard-coded to ""
78
- });
79
- }
80
-
81
- /** Summary reference sequence number, i.e. last sequence number seen when it was created */
82
- public get referenceSequenceNumber(): number {
83
- return this.summary.referenceSequenceNumber;
84
- }
85
- /** Full path to parent node, or undefined if this is the root */
86
- public get basePath(): EscapedPath | undefined {
87
- return this.summary.basePath;
88
- }
89
- /** Relative path to this node from its parent node */
90
- public get localPath(): EscapedPath {
91
- return this.summary.localPath;
92
- }
93
- /** Relative path from this node to its node innermost base summary */
94
- public get additionalPath(): EscapedPath | undefined {
95
- return this.summary.additionalPath;
96
- }
97
- public set additionalPath(additionalPath: EscapedPath | undefined) {
98
- this.summary.additionalPath = additionalPath;
99
- }
100
- constructor(private readonly summary: {
101
- readonly referenceSequenceNumber: number;
102
- readonly basePath: EscapedPath | undefined;
103
- readonly localPath: EscapedPath;
104
- additionalPath?: EscapedPath;
105
- }) { }
106
-
107
- /** Gets the full path to this node, to be used when sending a handle */
108
- public get fullPath(): EscapedPath {
109
- return this.basePath?.concat(this.localPath) ?? this.localPath;
110
- }
111
-
112
- /**
113
- * Gets the full path to this node's innermost base summary.
114
- * The children nodes can use this as their basePath to determine their path.
115
- */
116
- public get fullPathForChildren(): EscapedPath {
117
- return this.additionalPath !== undefined
118
- ? this.fullPath.concat(this.additionalPath)
119
- : this.fullPath;
120
- }
121
-
122
- /**
123
- * Creates a new node within the same summary for a child of this node.
124
- * @param id - id of the child node
125
- */
126
- public createForChild(id: string): SummaryNode {
127
- return new SummaryNode({
128
- referenceSequenceNumber: this.referenceSequenceNumber,
129
- basePath: this.fullPathForChildren,
130
- localPath: EscapedPath.create(id),
131
- });
132
- }
133
- }
134
-
135
- /**
136
- * Parameter to help encode summary with conditional behavior.
137
- * When fromSummary is true, it will contain the SummaryNode of
138
- * its previous summary, which it can use to point to with a handle.
139
- * When fromSummary is false, it will use an actual summary tree
140
- * as its base summary in case the first summary is a differential summary.
141
- */
142
- export type EncodeSummaryParam = {
143
- fromSummary: true;
144
- summaryNode: SummaryNode;
145
- } | {
146
- fromSummary: false;
147
- initialSummary: ISummaryTreeWithStats;
148
- };
149
-
150
- /**
151
- * Information about the initial summary tree found from an attach op.
152
- */
153
- export interface IInitialSummary {
154
- sequenceNumber: number;
155
- id: string;
156
- summary: ISummaryTreeWithStats | undefined;
157
- }
158
-
159
- /**
160
- * Represents the details needed to create a child summarizer node.
161
- */
162
- export interface ICreateChildDetails {
163
- /** Summary from attach op if known */
164
- initialSummary: IInitialSummary | undefined;
165
- /** Latest summary from server node data */
166
- latestSummary: SummaryNode | undefined;
167
- /** Sequence number of latest known change to the node */
168
- changeSequenceNumber: number;
169
- }
170
-
171
- export interface ISubtreeInfo<T extends ISnapshotTree | SummaryObject> {
172
- /** Tree to use to find children subtrees */
173
- childrenTree: T;
174
- /** Additional path part where children are isolated */
175
- childrenPathPart: string | undefined;
176
- }
177
-
178
- /**
179
- * Checks if the summary contains .channels subtree where the children subtrees
180
- * would be located if exists.
181
- * @param baseSummary - summary to check
182
- */
183
- export function parseSummaryForSubtrees(baseSummary: ISnapshotTree): ISubtreeInfo<ISnapshotTree> {
184
- // New versions of snapshots have child nodes isolated in .channels subtree
185
- const channelsSubtree = baseSummary.trees[channelsTreeName];
186
- if (channelsSubtree !== undefined) {
187
- return {
188
- childrenTree: channelsSubtree,
189
- childrenPathPart: channelsTreeName,
190
- };
191
- }
192
- return {
193
- childrenTree: baseSummary,
194
- childrenPathPart: undefined,
195
- };
196
- }
197
-
198
- /**
199
- * Checks if the summary contains .channels subtree where the children subtrees
200
- * would be located if exists.
201
- * @param baseSummary - summary to check
202
- */
203
- export function parseSummaryTreeForSubtrees(summary: ISummaryTree): ISubtreeInfo<SummaryObject> {
204
- // New versions of snapshots have child nodes isolated in .channels subtree
205
- const channelsSubtree = summary.tree[channelsTreeName];
206
- if (channelsSubtree !== undefined) {
207
- return {
208
- childrenTree: channelsSubtree,
209
- childrenPathPart: channelsTreeName,
210
- };
211
- }
212
- return {
213
- childrenTree: summary,
214
- childrenPathPart: undefined,
215
- };
216
- }
@@ -1,432 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
- import { assert, LazyPromise } from "@fluidframework/common-utils";
8
- import { cloneGCData } from "@fluidframework/garbage-collector";
9
- import { ISnapshotTree } from "@fluidframework/protocol-definitions";
10
- import {
11
- CreateChildSummarizerNodeParam,
12
- gcBlobKey,
13
- IGarbageCollectionData,
14
- IGarbageCollectionDetailsBase,
15
- ISummarizeInternalResult,
16
- ISummarizeResult,
17
- ISummarizerNodeConfigWithGC,
18
- ISummarizerNodeWithGC,
19
- SummarizeInternalFn,
20
- ITelemetryContext,
21
- } from "@fluidframework/runtime-definitions";
22
- import { ReadAndParseBlob } from "../utils";
23
- import { SummarizerNode } from "./summarizerNode";
24
- import {
25
- EscapedPath,
26
- ICreateChildDetails,
27
- IInitialSummary,
28
- ISummarizerNodeRootContract,
29
- SummaryNode,
30
- } from "./summarizerNodeUtils";
31
-
32
- export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {}
33
-
34
- // Extend SummaryNode to add used routes tracking to it.
35
- class SummaryNodeWithGC extends SummaryNode {
36
- constructor(
37
- public readonly serializedUsedRoutes: string,
38
- summary: {
39
- readonly referenceSequenceNumber: number;
40
- readonly basePath: EscapedPath | undefined;
41
- readonly localPath: EscapedPath;
42
- additionalPath?: EscapedPath;
43
- },
44
- ) {
45
- super(summary);
46
- }
47
- }
48
-
49
- /**
50
- * Extends the functionality of SummarizerNode to manage this node's garbage collection data:
51
- *
52
- * - Adds a new API `getGCData` to return GC data of this node.
53
- *
54
- * - Caches the result of `getGCData` to be used if nothing changes between summaries.
55
- *
56
- * - Manages the used routes of this node. These are used to identify if this node is referenced in the document
57
- * and to determine if the node's used state changed since last summary.
58
- *
59
- * - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls
60
- * directly into summarizeInternal method.
61
- */
62
- export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {
63
- // Tracks the work-in-progress used routes during summary.
64
- private wipSerializedUsedRoutes: string | undefined;
65
-
66
- // This is the last known used routes of this node as seen by the server as part of a summary.
67
- private referenceUsedRoutes: string[] | undefined;
68
-
69
- // The base GC details of this node used to initialize the GC state.
70
- private readonly baseGCDetailsP: LazyPromise<IGarbageCollectionDetailsBase>;
71
-
72
- // Keeps track of whether we have loaded the base details to ensure that we on;y do it once.
73
- private baseGCDetailsLoaded: boolean = false;
74
-
75
- private gcData: IGarbageCollectionData | undefined;
76
-
77
- // Set used routes to have self route by default. This makes the node referenced by default. This is done to ensure
78
- // that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is
79
- // removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.
80
- private usedRoutes: string[] = [""];
81
-
82
- // True if GC is disabled for this node. If so, do not track GC specific state for a summary.
83
- private readonly gcDisabled: boolean;
84
-
85
- /**
86
- * Do not call constructor directly.
87
- * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
88
- */
89
- public constructor(
90
- logger: ITelemetryLogger,
91
- private readonly summarizeFn: (
92
- fullTree: boolean,
93
- trackState: boolean,
94
- telemetryContext?: ITelemetryContext,
95
- ) => Promise<ISummarizeInternalResult>,
96
- config: ISummarizerNodeConfigWithGC,
97
- changeSequenceNumber: number,
98
- /** Undefined means created without summary */
99
- latestSummary?: SummaryNode,
100
- initialSummary?: IInitialSummary,
101
- wipSummaryLogger?: ITelemetryLogger,
102
- private readonly getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
103
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
104
- ) {
105
- super(
106
- logger,
107
- async (fullTree: boolean, _trackState: boolean, telemetryContext?: ITelemetryContext) =>
108
- summarizeFn(fullTree, true /* trackState */, telemetryContext),
109
- config,
110
- changeSequenceNumber,
111
- latestSummary,
112
- initialSummary,
113
- wipSummaryLogger,
114
- );
115
-
116
- this.gcDisabled = config.gcDisabled === true;
117
-
118
- this.baseGCDetailsP = new LazyPromise(async () => {
119
- return (await getBaseGCDetailsFn?.()) ?? { usedRoutes: [] };
120
- });
121
- }
122
-
123
- /**
124
- * Loads state from this node's initial GC summary details. This contains the following data from the last summary
125
- * seen by the server for this client:
126
- * - usedRoutes: This is used to figure out if the used state of this node changed since last summary.
127
- * - gcData: The garbage collection data of this node that is required for running GC.
128
- */
129
- private async loadBaseGCDetails() {
130
- const baseGCDetails = await this.baseGCDetailsP;
131
-
132
- // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we only update
133
- // the state from the base details only once.
134
- if (this.baseGCDetailsLoaded) {
135
- return;
136
- }
137
- this.baseGCDetailsLoaded = true;
138
-
139
- // If the GC details has GC data, initialize our GC data from it.
140
- if (baseGCDetails.gcData !== undefined) {
141
- this.gcData = cloneGCData(baseGCDetails.gcData);
142
- }
143
- // Sort the used routes because we compare them with the current used routes to check if they changed between
144
- // summaries. Both are sorted so that the order of elements is the same.
145
- this.referenceUsedRoutes = baseGCDetails.usedRoutes?.sort();
146
- }
147
-
148
- public async summarize(
149
- fullTree: boolean,
150
- trackState: boolean = true,
151
- telemetryContext?: ITelemetryContext,
152
- ): Promise<ISummarizeResult> {
153
- // If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this
154
- // summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.
155
- if (!this.gcDisabled && this.isTrackingInProgress()) {
156
- assert(this.wipSerializedUsedRoutes !== undefined,
157
- 0x1b1 /* "wip used routes should be set if tracking a summary" */);
158
- }
159
-
160
- // If trackState is true, get summary from base summarizer node which tracks summary state.
161
- // If trackState is false, get summary from summarizeInternal.
162
- return trackState
163
- ? super.summarize(fullTree, true /* trackState */, telemetryContext)
164
- : this.summarizeFn(fullTree, trackState, telemetryContext);
165
- }
166
-
167
- /**
168
- * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from
169
- * the previous summary. Else, it gets new GC data from the underlying Fluid object.
170
- * @param fullGC - true to bypass optimizations and force full generation of GC data.
171
- */
172
- public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {
173
- assert(!this.gcDisabled, 0x1b2 /* "Getting GC data should not be called when GC is disabled!" */);
174
- assert(this.getGCDataFn !== undefined, 0x1b3 /* "GC data cannot be retrieved without getGCDataFn" */);
175
-
176
- // Load GC details from the initial summary, if not already loaded. If this is the first time this function is
177
- // called and the node's data has not changed since last summary, the GC data in initial details is returned.
178
- await this.loadBaseGCDetails();
179
-
180
- // If there is no new data since last summary and we have GC data from the previous run, return it. We may not
181
- // have data from previous GC run for clients with older summary format before GC was added. They won't have
182
- // GC details in their initial summary.
183
- if (!fullGC && !this.hasDataChanged() && this.gcData !== undefined) {
184
- return cloneGCData(this.gcData);
185
- }
186
-
187
- const gcData = await this.getGCDataFn(fullGC);
188
- this.gcData = cloneGCData(gcData);
189
- return gcData;
190
- }
191
-
192
- /**
193
- * Called during the start of a summary. Updates the work-in-progress used routes.
194
- */
195
- public startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger) {
196
- // If GC is disabled, skip setting wip used routes since we should not track GC state.
197
- if (!this.gcDisabled) {
198
- assert(
199
- this.wipSerializedUsedRoutes === undefined,
200
- 0x1b4 /* "We should not already be tracking used routes when to track a new summary" */);
201
- }
202
- super.startSummary(referenceSequenceNumber, summaryLogger);
203
- }
204
-
205
- /**
206
- * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending
207
- * summary queue. We track this until we get an ack from the server for this summary.
208
- */
209
- protected completeSummaryCore(
210
- proposalHandle: string,
211
- parentPath: EscapedPath | undefined,
212
- parentSkipRecursion: boolean,
213
- ) {
214
- let wipSerializedUsedRoutes: string | undefined;
215
- // If GC is disabled, don't set wip used routes.
216
- if (!this.gcDisabled) {
217
- wipSerializedUsedRoutes = this.wipSerializedUsedRoutes;
218
- assert(wipSerializedUsedRoutes !== undefined, 0x1b5 /* "We should have been tracking used routes" */);
219
- }
220
-
221
- super.completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion);
222
-
223
- // If GC is disabled, skip setting pending summary with GC state.
224
- if (!this.gcDisabled) {
225
- const summaryNode = this.pendingSummaries.get(proposalHandle);
226
- if (summaryNode !== undefined) {
227
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
228
- const summaryNodeWithGC = new SummaryNodeWithGC(wipSerializedUsedRoutes!, summaryNode);
229
- this.pendingSummaries.set(proposalHandle, summaryNodeWithGC);
230
- }
231
- }
232
- }
233
-
234
- /**
235
- * Clears the work-in-progress state.
236
- */
237
- public clearSummary() {
238
- this.wipSerializedUsedRoutes = undefined;
239
- super.clearSummary();
240
- }
241
-
242
- /**
243
- * Called when we get an ack from the server for a summary we sent. Update the reference state of this node
244
- * from the state in the pending summary queue.
245
- */
246
- protected refreshLatestSummaryFromPending(
247
- proposalHandle: string,
248
- referenceSequenceNumber: number,
249
- ): void {
250
- // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
251
- if (!this.gcDisabled) {
252
- const summaryNode = this.pendingSummaries.get(proposalHandle) as SummaryNodeWithGC;
253
- if (summaryNode?.serializedUsedRoutes !== undefined) {
254
- this.referenceUsedRoutes = JSON.parse(summaryNode.serializedUsedRoutes);
255
- }
256
- }
257
-
258
- return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
259
- }
260
-
261
- /**
262
- * Called when we need to upload the reference state from the given summary. Read the GC blob and get the state
263
- * to upload from it.
264
- */
265
- protected async refreshLatestSummaryFromSnapshot(
266
- referenceSequenceNumber: number,
267
- snapshotTree: ISnapshotTree,
268
- basePath: EscapedPath | undefined,
269
- localPath: EscapedPath,
270
- correlatedSummaryLogger: ITelemetryLogger,
271
- readAndParseBlob: ReadAndParseBlob,
272
- ): Promise<void> {
273
- // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
274
- if (!this.gcDisabled) {
275
- const gcDetailsBlob = snapshotTree.blobs[gcBlobKey];
276
- if (gcDetailsBlob !== undefined) {
277
- const gcDetails = await readAndParseBlob<IGarbageCollectionDetailsBase>(gcDetailsBlob);
278
-
279
- // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
280
- if (this.referenceSequenceNumber >= referenceSequenceNumber) {
281
- return;
282
- }
283
-
284
- this.referenceUsedRoutes = gcDetails.usedRoutes;
285
- }
286
- }
287
-
288
- return super.refreshLatestSummaryFromSnapshot(
289
- referenceSequenceNumber,
290
- snapshotTree,
291
- basePath,
292
- localPath,
293
- correlatedSummaryLogger,
294
- readAndParseBlob,
295
- );
296
- }
297
-
298
- /**
299
- * Override the createChild method to return an instance of SummarizerNodeWithGC.
300
- */
301
- public createChild(
302
- /** Summarize function */
303
- summarizeInternalFn: SummarizeInternalFn,
304
- /** Initial id or path part of this node */
305
- id: string,
306
- /**
307
- * Information needed to create the node.
308
- * If it is from a base summary, it will assert that a summary has been seen.
309
- * Attach information if it is created from an attach op.
310
- */
311
- createParam: CreateChildSummarizerNodeParam,
312
- config: ISummarizerNodeConfigWithGC = {},
313
- getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
314
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
315
- ): ISummarizerNodeWithGC {
316
- assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
317
-
318
- const createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);
319
- const child = new SummarizerNodeWithGC(
320
- this.defaultLogger,
321
- summarizeInternalFn,
322
- {
323
- ...config,
324
- // Propagate our gcDisabled state to the child if its not explicity specified in child's config.
325
- gcDisabled: config.gcDisabled ?? this.gcDisabled,
326
- },
327
- createDetails.changeSequenceNumber,
328
- createDetails.latestSummary,
329
- createDetails.initialSummary,
330
- this.wipSummaryLogger,
331
- getGCDataFn,
332
- getBaseGCDetailsFn,
333
- );
334
-
335
- // There may be additional state that has to be updated in this child. For example, if a summary is being
336
- // tracked, the child's summary tracking state needs to be updated too.
337
- this.maybeUpdateChildState(child);
338
-
339
- this.children.set(id, child);
340
- return child;
341
- }
342
-
343
- /**
344
- * Deletes the child node with the given id.
345
- */
346
- public deleteChild(id: string): void {
347
- this.children.delete(id);
348
- }
349
-
350
- /**
351
- * Override the getChild method to return an instance of SummarizerNodeWithGC.
352
- */
353
- public getChild(id: string): ISummarizerNodeWithGC | undefined {
354
- return this.children.get(id) as SummarizerNodeWithGC;
355
- }
356
-
357
- public isReferenced(): boolean {
358
- return this.usedRoutes.includes("") || this.usedRoutes.includes("/");
359
- }
360
-
361
- public updateUsedRoutes(usedRoutes: string[]) {
362
- // Sort the given routes before updating. This will ensure that the routes compared in hasUsedStateChanged()
363
- // are in the same order.
364
- this.usedRoutes = usedRoutes.sort();
365
-
366
- // If GC is not disabled and we are tracking a summary, update the work-in-progress used routes so that it can
367
- // be tracked for this summary.
368
- if (!this.gcDisabled && this.isTrackingInProgress()) {
369
- this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);
370
- }
371
- }
372
-
373
- /**
374
- * Override the hasChanged method. If this node data or its used state changed, the node is considered changed.
375
- */
376
- protected hasChanged(): boolean {
377
- return this.hasDataChanged() || this.hasUsedStateChanged();
378
- }
379
-
380
- /**
381
- * This tells whether the data in this node has changed or not.
382
- */
383
- private hasDataChanged(): boolean {
384
- return super.hasChanged();
385
- }
386
-
387
- /**
388
- * This tells whether the used state of this node has changed since last successful summary. If the used routes
389
- * of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes
390
- * was previously used and became unused (or vice versa), its used state has changed.
391
- */
392
- private hasUsedStateChanged(): boolean {
393
- // If GC is disabled, we are not tracking used state, return false.
394
- if (this.gcDisabled) {
395
- return false;
396
- }
397
-
398
- return this.referenceUsedRoutes === undefined ||
399
- JSON.stringify(this.usedRoutes) !== JSON.stringify(this.referenceUsedRoutes);
400
- }
401
- }
402
-
403
- /**
404
- * Creates a root summarizer node with GC functionality built-in.
405
- * @param logger - Logger to use within SummarizerNode
406
- * @param summarizeInternalFn - Function to generate summary
407
- * @param changeSequenceNumber - Sequence number of latest change to new node/subtree
408
- * @param referenceSequenceNumber - Reference sequence number of last acked summary,
409
- * or undefined if not loaded from summary
410
- * @param config - Configure behavior of summarizer node
411
- * @param getGCDataFn - Function to get the GC data of this node
412
- * @param baseGCDetailsP - Function to get the initial GC details of this node
413
- */
414
- export const createRootSummarizerNodeWithGC = (
415
- logger: ITelemetryLogger,
416
- summarizeInternalFn: SummarizeInternalFn,
417
- changeSequenceNumber: number,
418
- referenceSequenceNumber: number | undefined,
419
- config: ISummarizerNodeConfigWithGC = {},
420
- getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,
421
- getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,
422
- ): IRootSummarizerNodeWithGC => new SummarizerNodeWithGC(
423
- logger,
424
- summarizeInternalFn,
425
- config,
426
- changeSequenceNumber,
427
- referenceSequenceNumber === undefined ? undefined : SummaryNode.createForRoot(referenceSequenceNumber),
428
- undefined /* initialSummary */,
429
- undefined /* wipSummaryLogger */,
430
- getGCDataFn,
431
- getBaseGCDetailsFn,
432
- );