@fluidframework/runtime-utils 2.0.0-internal.2.2.1 → 2.0.0-internal.2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/.eslintrc.js +1 -1
  2. package/dist/dataStoreHelpers.d.ts +3 -1
  3. package/dist/dataStoreHelpers.d.ts.map +1 -1
  4. package/dist/dataStoreHelpers.js +4 -1
  5. package/dist/dataStoreHelpers.js.map +1 -1
  6. package/dist/packageVersion.d.ts +1 -1
  7. package/dist/packageVersion.js +1 -1
  8. package/dist/packageVersion.js.map +1 -1
  9. package/dist/summarizerNode/summarizerNode.d.ts +1 -1
  10. package/dist/summarizerNode/summarizerNode.d.ts.map +1 -1
  11. package/dist/summarizerNode/summarizerNode.js.map +1 -1
  12. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +6 -2
  13. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  14. package/dist/summarizerNode/summarizerNodeWithGc.js +98 -22
  15. package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  16. package/lib/dataStoreHelpers.d.ts +3 -1
  17. package/lib/dataStoreHelpers.d.ts.map +1 -1
  18. package/lib/dataStoreHelpers.js +4 -1
  19. package/lib/dataStoreHelpers.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/summarizerNode/summarizerNode.d.ts +1 -1
  24. package/lib/summarizerNode/summarizerNode.d.ts.map +1 -1
  25. package/lib/summarizerNode/summarizerNode.js.map +1 -1
  26. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +6 -2
  27. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  28. package/lib/summarizerNode/summarizerNodeWithGc.js +101 -25
  29. package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  30. package/package.json +13 -13
  31. package/src/dataStoreHelpers.ts +5 -1
  32. package/src/packageVersion.ts +1 -1
  33. package/src/summarizerNode/summarizerNode.ts +1 -1
  34. package/src/summarizerNode/summarizerNodeWithGc.ts +114 -28
@@ -3,10 +3,10 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { assert, LazyPromise } from "@fluidframework/common-utils";
6
- import { cloneGCData } from "@fluidframework/garbage-collector";
7
- import { gcBlobKey, } from "@fluidframework/runtime-definitions";
6
+ import { cloneGCData, getGCDataFromSnapshot, runGarbageCollection, unpackChildNodesGCDetails } from "@fluidframework/garbage-collector";
7
+ import { gcTreeKey, } from "@fluidframework/runtime-definitions";
8
8
  import { SummarizerNode } from "./summarizerNode";
9
- import { SummaryNode, } from "./summarizerNodeUtils";
9
+ import { parseSummaryForSubtrees, SummaryNode, } from "./summarizerNodeUtils";
10
10
  // Extend SummaryNode to add used routes tracking to it.
11
11
  class SummaryNodeWithGC extends SummaryNode {
12
12
  constructor(serializedUsedRoutes, summary) {
@@ -57,21 +57,26 @@ export class SummarizerNodeWithGC extends SummarizerNode {
57
57
  * - gcData: The garbage collection data of this node that is required for running GC.
58
58
  */
59
59
  async loadBaseGCDetails() {
60
- var _a;
60
+ if (this.baseGCDetailsLoaded) {
61
+ return;
62
+ }
61
63
  const baseGCDetails = await this.baseGCDetailsP;
62
- // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we only update
64
+ // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we update
63
65
  // the state from the base details only once.
64
66
  if (this.baseGCDetailsLoaded) {
65
67
  return;
66
68
  }
67
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.
68
72
  // If the GC details has GC data, initialize our GC data from it.
69
73
  if (baseGCDetails.gcData !== undefined) {
70
74
  this.gcData = cloneGCData(baseGCDetails.gcData);
71
75
  }
72
- // Sort the used routes because we compare them with the current used routes to check if they changed between
73
- // summaries. Both are sorted so that the order of elements is the same.
74
- this.referenceUsedRoutes = (_a = baseGCDetails.usedRoutes) === null || _a === void 0 ? void 0 : _a.sort();
76
+ if (baseGCDetails.usedRoutes !== undefined) {
77
+ this.usedRoutes = Array.from(baseGCDetails.usedRoutes).sort();
78
+ this.referenceUsedRoutes = Array.from(baseGCDetails.usedRoutes).sort();
79
+ }
75
80
  }
76
81
  async summarize(fullTree, trackState = true, telemetryContext) {
77
82
  // If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this
@@ -96,10 +101,11 @@ export class SummarizerNodeWithGC extends SummarizerNode {
96
101
  // Load GC details from the initial summary, if not already loaded. If this is the first time this function is
97
102
  // called and the node's data has not changed since last summary, the GC data in initial details is returned.
98
103
  await this.loadBaseGCDetails();
99
- // If there is no new data since last summary and we have GC data from the previous run, return it. We may not
100
- // have data from previous GC run for clients with older summary format before GC was added. They won't have
101
- // GC details in their initial summary.
102
- if (!fullGC && !this.hasDataChanged() && this.gcData !== undefined) {
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) {
103
109
  return cloneGCData(this.gcData);
104
110
  }
105
111
  const gcData = await this.getGCDataFn(fullGC);
@@ -160,23 +166,79 @@ export class SummarizerNodeWithGC extends SummarizerNode {
160
166
  return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);
161
167
  }
162
168
  /**
163
- * Called when we need to upload the reference state from the given summary. Read the GC blob and get the state
164
- * to upload from it.
169
+ * Called when we need to upload the reference state from the given summary.
165
170
  */
166
171
  async refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob) {
167
- // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.
168
- if (!this.gcDisabled) {
169
- const gcDetailsBlob = snapshotTree.blobs[gcBlobKey];
172
+ await this.refreshGCStateFromSnapshot(referenceSequenceNumber, snapshotTree, readAndParseBlob);
173
+ return super.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob);
174
+ }
175
+ /**
176
+ * Updates GC state from the given snapshot if GC is enabled and the snapshot is newer than the one this node
177
+ * is tracking.
178
+ */
179
+ async refreshGCStateFromSnapshot(referenceSequenceNumber, snapshotTree, readAndParseBlob) {
180
+ // If GC is disabled or we have seen a newer summary, skip updating GC state.
181
+ if (this.gcDisabled || this.referenceSequenceNumber >= referenceSequenceNumber) {
182
+ return;
183
+ }
184
+ // Load the base GC details before proceeding because if that happens later it can overwrite the GC details
185
+ // written by the following code.
186
+ await this.loadBaseGCDetails();
187
+ // Possible re-entrancy. We may already have processed this while loading base GC details.
188
+ if (this.referenceSequenceNumber >= referenceSequenceNumber) {
189
+ return;
190
+ }
191
+ /**
192
+ * GC data is written at root of the snapshot tree under "gc" sub-tree. This data needs to be propagated to
193
+ * all the nodes in the container.
194
+ * The root summarizer node reads the GC data from the "gc" sub-tree, runs GC on it to get used routes in
195
+ * the container and updates its GC data and referenced used routes. It then gets the GC data and used
196
+ * routes of all its children and adds it to their snapshot tree.
197
+ * All the other nodes gets the GC data and used routes from their snapshot tree and updates their state.
198
+ * They get the GC data and used routes of their children and add it to their snapshot tree and so on.
199
+ *
200
+ * Note that if the snapshot does not have GC tree, GC data will be set to undefined and used routes will be
201
+ * set to self-route (meaning referenced) for all nodes. This is important because the GC data needs to be
202
+ * regenerated in the next summary.
203
+ */
204
+ let gcDetails;
205
+ const gcSnapshotTree = snapshotTree.trees[gcTreeKey];
206
+ if (gcSnapshotTree !== undefined) {
207
+ // If there is a GC tree in the snapshot, this is the root summarizer node. Read GC data from the tree
208
+ // process it as explained above.
209
+ const gcSnapshotData = await getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);
210
+ const gcNodes = {};
211
+ for (const [nodeId, nodeData] of Object.entries(gcSnapshotData.gcState.gcNodes)) {
212
+ gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
213
+ }
214
+ // Run GC on the nodes in the snapshot to get the used routes for each node in the container.
215
+ const usedRoutes = runGarbageCollection(gcNodes, ["/"]).referencedNodeIds;
216
+ gcDetails = { gcData: { gcNodes }, usedRoutes };
217
+ }
218
+ else {
219
+ // If there is a GC blob in the snapshot, it's a non-root summarizer nodes - The root summarizer node
220
+ // writes GC blob in the snapshot of child nodes. Get GC data and used routes from the blob.
221
+ const gcDetailsBlob = snapshotTree.blobs[gcTreeKey];
170
222
  if (gcDetailsBlob !== undefined) {
171
- const gcDetails = await readAndParseBlob(gcDetailsBlob);
172
- // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.
173
- if (this.referenceSequenceNumber >= referenceSequenceNumber) {
174
- return;
175
- }
176
- this.referenceUsedRoutes = gcDetails.usedRoutes;
223
+ gcDetails = JSON.parse(gcDetailsBlob);
177
224
  }
178
225
  }
179
- return super.refreshLatestSummaryFromSnapshot(referenceSequenceNumber, snapshotTree, basePath, localPath, correlatedSummaryLogger, readAndParseBlob);
226
+ // Update this node to the same GC state it was when the ack corresponding to this summary was processed.
227
+ this.gcData = (gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.gcData) !== undefined ? cloneGCData(gcDetails.gcData) : undefined;
228
+ this.referenceUsedRoutes = (gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.usedRoutes) !== undefined ? Array.from(gcDetails.usedRoutes) : undefined;
229
+ // If there are no used routes in the GC details, set it to have self route which will make the node
230
+ // referenced. This scenario can only happen if the snapshot is from a client where GC was not run or
231
+ // disabled. In both the cases, the node should be referenced.
232
+ this.usedRoutes = (gcDetails === null || gcDetails === void 0 ? void 0 : gcDetails.usedRoutes) !== undefined ? Array.from(gcDetails.usedRoutes) : [""];
233
+ if (gcDetails === undefined) {
234
+ return;
235
+ }
236
+ // Generate the GC data and used routes of children GC nodes and add it to their snapshot tree.
237
+ const gcDetailsMap = unpackChildNodesGCDetails(gcDetails);
238
+ const { childrenTree } = parseSummaryForSubtrees(snapshotTree);
239
+ gcDetailsMap.forEach((childGCDetails, childId) => {
240
+ childrenTree.trees[childId].blobs[gcTreeKey] = JSON.stringify(childGCDetails);
241
+ });
180
242
  }
181
243
  /**
182
244
  * Override the createChild method to return an instance of SummarizerNodeWithGC.
@@ -194,10 +256,24 @@ export class SummarizerNodeWithGC extends SummarizerNode {
194
256
  createParam, config = {}, getGCDataFn, getBaseGCDetailsFn) {
195
257
  var _a;
196
258
  assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
259
+ /**
260
+ * Update the child node's base GC details from this node's current GC details instead of updating from the base
261
+ * GC details of this node. This will handle scenarios where the GC details was updated during refresh from
262
+ * snapshot and the child node wasn't created then. If a child is created after that, its GC details should be
263
+ * the one from the downloaded snapshot and not the base GC details.
264
+ */
265
+ const getChildBaseGCDetailsP = new LazyPromise(async () => {
266
+ var _a;
267
+ // Ensure that the base GC details is loaded because a child can be created before GC runs which is when
268
+ // base GC details is usually loaded.
269
+ await this.loadBaseGCDetails();
270
+ const childBaseGCDetails = unpackChildNodesGCDetails({ gcData: this.gcData, usedRoutes: this.usedRoutes });
271
+ return (_a = childBaseGCDetails.get(id)) !== null && _a !== void 0 ? _a : {};
272
+ });
197
273
  const createDetails = this.getCreateDetailsForChild(id, createParam);
198
274
  const child = new SummarizerNodeWithGC(this.defaultLogger, summarizeInternalFn, Object.assign(Object.assign({}, config), {
199
275
  // Propagate our gcDisabled state to the child if its not explicity specified in child's config.
200
- gcDisabled: (_a = config.gcDisabled) !== null && _a !== void 0 ? _a : this.gcDisabled }), createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, getGCDataFn, getBaseGCDetailsFn);
276
+ gcDisabled: (_a = config.gcDisabled) !== null && _a !== void 0 ? _a : this.gcDisabled }), createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, getGCDataFn, async () => getChildBaseGCDetailsP);
201
277
  // There may be additional state that has to be updated in this child. For example, if a summary is being
202
278
  // tracked, the child's summary tracking state needs to be updated too.
203
279
  this.maybeUpdateChildState(child);
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerNodeWithGc.js","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNodeWithGc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAEhE,OAAO,EAEH,SAAS,GASZ,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAKH,WAAW,GACd,MAAM,uBAAuB,CAAC;AAI/B,wDAAwD;AACxD,MAAM,iBAAkB,SAAQ,WAAW;IACvC,YACoB,oBAA4B,EAC5C,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QARC,yBAAoB,GAApB,oBAAoB,CAAQ;IAShD,CAAC;CACJ;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IAuBpD;;;OAGG;IACH,YACI,MAAwB,EACP,WAIqB,EACtC,MAAmC,EACnC,oBAA4B;IAC5B,8CAA8C;IAC9C,aAA2B,EAC3B,cAAgC,EAChC,gBAAmC,EAClB,WAAmE,EACpF,kBAAiE;QAEjE,KAAK,CACD,MAAM,EACN,KAAK,EAAE,QAAiB,EAAE,WAAoB,EAAE,gBAAoC,EAAE,EAAE,CACpF,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,EAClE,MAAM,EACN,oBAAoB,EACpB,aAAa,EACb,cAAc,EACd,gBAAgB,CACnB,CAAC;QAvBe,gBAAW,GAAX,WAAW,CAIU;QAOrB,gBAAW,GAA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vB,mEAAmE;QACnE,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,OAAO,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,CAAC,mBAAmB,KAAK,SAAS;YACzC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IACrF,CAAC;CACJ;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC1C,MAAwB,EACxB,mBAAwC,EACxC,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAsC,EAAE,EACxC,WAAmE,EACnE,kBAAiE,EACxC,EAAE,CAAC,IAAI,oBAAoB,CACpD,MAAM,EACN,mBAAmB,EACnB,MAAM,EACN,oBAAoB,EACpB,uBAAuB,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,uBAAuB,CAAC,EACtG,SAAS,CAAC,oBAAoB,EAC9B,SAAS,CAAC,sBAAsB,EAChC,WAAW,EACX,kBAAkB,CACrB,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 { assert, LazyPromise } from \"@fluidframework/common-utils\";\nimport { cloneGCData } from \"@fluidframework/garbage-collector\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n CreateChildSummarizerNodeParam,\n gcBlobKey,\n IGarbageCollectionData,\n IGarbageCollectionDetailsBase,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeConfigWithGC,\n ISummarizerNodeWithGC,\n SummarizeInternalFn,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { ReadAndParseBlob } from \"../utils\";\nimport { SummarizerNode } from \"./summarizerNode\";\nimport {\n EscapedPath,\n ICreateChildDetails,\n IInitialSummary,\n ISummarizerNodeRootContract,\n SummaryNode,\n} from \"./summarizerNodeUtils\";\n\nexport interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {}\n\n// Extend SummaryNode to add used routes tracking to it.\nclass SummaryNodeWithGC extends SummaryNode {\n constructor(\n public readonly serializedUsedRoutes: string,\n summary: {\n readonly referenceSequenceNumber: number;\n readonly basePath: EscapedPath | undefined;\n readonly localPath: EscapedPath;\n additionalPath?: EscapedPath;\n },\n ) {\n super(summary);\n }\n}\n\n/**\n * Extends the functionality of SummarizerNode to manage this node's garbage collection data:\n *\n * - Adds a new API `getGCData` to return GC data of this node.\n *\n * - Caches the result of `getGCData` to be used if nothing changes between summaries.\n *\n * - Manages the used routes of this node. These are used to identify if this node is referenced in the document\n * and to determine if the node's used state changed since last summary.\n *\n * - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls\n * directly into summarizeInternal method.\n */\nexport class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {\n // Tracks the work-in-progress used routes during summary.\n private wipSerializedUsedRoutes: string | undefined;\n\n // This is the last known used routes of this node as seen by the server as part of a summary.\n private referenceUsedRoutes: string[] | undefined;\n\n // The base GC details of this node used to initialize the GC state.\n private readonly baseGCDetailsP: LazyPromise<IGarbageCollectionDetailsBase>;\n\n // Keeps track of whether we have loaded the base details to ensure that we on;y do it once.\n private baseGCDetailsLoaded: boolean = false;\n\n private gcData: IGarbageCollectionData | undefined;\n\n // Set used routes to have self route by default. This makes the node referenced by default. This is done to ensure\n // that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is\n // removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.\n private usedRoutes: string[] = [\"\"];\n\n // True if GC is disabled for this node. If so, do not track GC specific state for a summary.\n private readonly gcDisabled: boolean;\n\n /**\n * Do not call constructor directly.\n * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.\n */\n public constructor(\n logger: ITelemetryLogger,\n private readonly summarizeFn: (\n fullTree: boolean,\n trackState: boolean,\n telemetryContext?: ITelemetryContext,\n ) => Promise<ISummarizeInternalResult>,\n config: ISummarizerNodeConfigWithGC,\n changeSequenceNumber: number,\n /** Undefined means created without summary */\n latestSummary?: SummaryNode,\n initialSummary?: IInitialSummary,\n wipSummaryLogger?: ITelemetryLogger,\n private readonly getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n ) {\n super(\n logger,\n async (fullTree: boolean, _trackState: boolean, telemetryContext?: ITelemetryContext) =>\n summarizeFn(fullTree, true /* trackState */, telemetryContext),\n config,\n changeSequenceNumber,\n latestSummary,\n initialSummary,\n wipSummaryLogger,\n );\n\n this.gcDisabled = config.gcDisabled === true;\n\n this.baseGCDetailsP = new LazyPromise(async () => {\n return (await getBaseGCDetailsFn?.()) ?? { usedRoutes: [] };\n });\n }\n\n /**\n * Loads state from this node's initial GC summary details. This contains the following data from the last summary\n * seen by the server for this client:\n * - usedRoutes: This is used to figure out if the used state of this node changed since last summary.\n * - gcData: The garbage collection data of this node that is required for running GC.\n */\n private async loadBaseGCDetails() {\n const baseGCDetails = await this.baseGCDetailsP;\n\n // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we only update\n // the state from the base details only once.\n if (this.baseGCDetailsLoaded) {\n return;\n }\n this.baseGCDetailsLoaded = true;\n\n // If the GC details has GC data, initialize our GC data from it.\n if (baseGCDetails.gcData !== undefined) {\n this.gcData = cloneGCData(baseGCDetails.gcData);\n }\n // Sort the used routes because we compare them with the current used routes to check if they changed between\n // summaries. Both are sorted so that the order of elements is the same.\n this.referenceUsedRoutes = baseGCDetails.usedRoutes?.sort();\n }\n\n public async summarize(\n fullTree: boolean,\n trackState: boolean = true,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeResult> {\n // If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this\n // summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.\n if (!this.gcDisabled && this.isTrackingInProgress()) {\n assert(this.wipSerializedUsedRoutes !== undefined,\n 0x1b1 /* \"wip used routes should be set if tracking a summary\" */);\n }\n\n // If trackState is true, get summary from base summarizer node which tracks summary state.\n // If trackState is false, get summary from summarizeInternal.\n return trackState\n ? super.summarize(fullTree, true /* trackState */, telemetryContext)\n : this.summarizeFn(fullTree, trackState, telemetryContext);\n }\n\n /**\n * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from\n * the previous summary. Else, it gets new GC data from the underlying Fluid object.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n assert(!this.gcDisabled, 0x1b2 /* \"Getting GC data should not be called when GC is disabled!\" */);\n assert(this.getGCDataFn !== undefined, 0x1b3 /* \"GC data cannot be retrieved without getGCDataFn\" */);\n\n // Load GC details from the initial summary, if not already loaded. If this is the first time this function is\n // called and the node's data has not changed since last summary, the GC data in initial details is returned.\n await this.loadBaseGCDetails();\n\n // If there is no new data since last summary and we have GC data from the previous run, return it. We may not\n // have data from previous GC run for clients with older summary format before GC was added. They won't have\n // GC details in their initial summary.\n if (!fullGC && !this.hasDataChanged() && this.gcData !== undefined) {\n return cloneGCData(this.gcData);\n }\n\n const gcData = await this.getGCDataFn(fullGC);\n this.gcData = cloneGCData(gcData);\n return gcData;\n }\n\n /**\n * Called during the start of a summary. Updates the work-in-progress used routes.\n */\n public startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger) {\n // If GC is disabled, skip setting wip used routes since we should not track GC state.\n if (!this.gcDisabled) {\n assert(\n this.wipSerializedUsedRoutes === undefined,\n 0x1b4 /* \"We should not already be tracking used routes when to track a new summary\" */);\n }\n super.startSummary(referenceSequenceNumber, summaryLogger);\n }\n\n /**\n * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending\n * summary queue. We track this until we get an ack from the server for this summary.\n */\n protected completeSummaryCore(\n proposalHandle: string,\n parentPath: EscapedPath | undefined,\n parentSkipRecursion: boolean,\n ) {\n let wipSerializedUsedRoutes: string | undefined;\n // If GC is disabled, don't set wip used routes.\n if (!this.gcDisabled) {\n wipSerializedUsedRoutes = this.wipSerializedUsedRoutes;\n assert(wipSerializedUsedRoutes !== undefined, 0x1b5 /* \"We should have been tracking used routes\" */);\n }\n\n super.completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion);\n\n // If GC is disabled, skip setting pending summary with GC state.\n if (!this.gcDisabled) {\n const summaryNode = this.pendingSummaries.get(proposalHandle);\n if (summaryNode !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const summaryNodeWithGC = new SummaryNodeWithGC(wipSerializedUsedRoutes!, summaryNode);\n this.pendingSummaries.set(proposalHandle, summaryNodeWithGC);\n }\n }\n }\n\n /**\n * Clears the work-in-progress state.\n */\n public clearSummary() {\n this.wipSerializedUsedRoutes = undefined;\n super.clearSummary();\n }\n\n /**\n * Called when we get an ack from the server for a summary we sent. Update the reference state of this node\n * from the state in the pending summary queue.\n */\n protected refreshLatestSummaryFromPending(\n proposalHandle: string,\n referenceSequenceNumber: number,\n ): void {\n // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.\n if (!this.gcDisabled) {\n const summaryNode = this.pendingSummaries.get(proposalHandle) as SummaryNodeWithGC;\n if (summaryNode?.serializedUsedRoutes !== undefined) {\n this.referenceUsedRoutes = JSON.parse(summaryNode.serializedUsedRoutes);\n }\n }\n\n return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);\n }\n\n /**\n * Called when we need to upload the reference state from the given summary. Read the GC blob and get the state\n * to upload from it.\n */\n protected async refreshLatestSummaryFromSnapshot(\n referenceSequenceNumber: number,\n snapshotTree: ISnapshotTree,\n basePath: EscapedPath | undefined,\n localPath: EscapedPath,\n correlatedSummaryLogger: ITelemetryLogger,\n readAndParseBlob: ReadAndParseBlob,\n ): Promise<void> {\n // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.\n if (!this.gcDisabled) {\n const gcDetailsBlob = snapshotTree.blobs[gcBlobKey];\n if (gcDetailsBlob !== undefined) {\n const gcDetails = await readAndParseBlob<IGarbageCollectionDetailsBase>(gcDetailsBlob);\n\n // Possible re-entrancy. If we have already seen a summary later than this one, ignore it.\n if (this.referenceSequenceNumber >= referenceSequenceNumber) {\n return;\n }\n\n this.referenceUsedRoutes = gcDetails.usedRoutes;\n }\n }\n\n return super.refreshLatestSummaryFromSnapshot(\n referenceSequenceNumber,\n snapshotTree,\n basePath,\n localPath,\n correlatedSummaryLogger,\n readAndParseBlob,\n );\n }\n\n /**\n * Override the createChild method to return an instance of SummarizerNodeWithGC.\n */\n public createChild(\n /** Summarize function */\n summarizeInternalFn: SummarizeInternalFn,\n /** Initial id or path part of this node */\n id: string,\n /**\n * Information needed to create the node.\n * If it is from a base summary, it will assert that a summary has been seen.\n * Attach information if it is created from an attach op.\n */\n createParam: CreateChildSummarizerNodeParam,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n ): ISummarizerNodeWithGC {\n assert(!this.children.has(id), 0x1b6 /* \"Create SummarizerNode child already exists\" */);\n\n const createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);\n const child = new SummarizerNodeWithGC(\n this.defaultLogger,\n summarizeInternalFn,\n {\n ...config,\n // Propagate our gcDisabled state to the child if its not explicity specified in child's config.\n gcDisabled: config.gcDisabled ?? this.gcDisabled,\n },\n createDetails.changeSequenceNumber,\n createDetails.latestSummary,\n createDetails.initialSummary,\n this.wipSummaryLogger,\n getGCDataFn,\n getBaseGCDetailsFn,\n );\n\n // There may be additional state that has to be updated in this child. For example, if a summary is being\n // tracked, the child's summary tracking state needs to be updated too.\n this.maybeUpdateChildState(child);\n\n this.children.set(id, child);\n return child;\n }\n\n /**\n * Deletes the child node with the given id.\n */\n public deleteChild(id: string): void {\n this.children.delete(id);\n }\n\n /**\n * Override the getChild method to return an instance of SummarizerNodeWithGC.\n */\n public getChild(id: string): ISummarizerNodeWithGC | undefined {\n return this.children.get(id) as SummarizerNodeWithGC;\n }\n\n public isReferenced(): boolean {\n return this.usedRoutes.includes(\"\") || this.usedRoutes.includes(\"/\");\n }\n\n public updateUsedRoutes(usedRoutes: string[]) {\n // Sort the given routes before updating. This will ensure that the routes compared in hasUsedStateChanged()\n // are in the same order.\n this.usedRoutes = usedRoutes.sort();\n\n // If GC is not disabled and we are tracking a summary, update the work-in-progress used routes so that it can\n // be tracked for this summary.\n if (!this.gcDisabled && this.isTrackingInProgress()) {\n this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);\n }\n }\n\n /**\n * Override the hasChanged method. If this node data or its used state changed, the node is considered changed.\n */\n protected hasChanged(): boolean {\n return this.hasDataChanged() || this.hasUsedStateChanged();\n }\n\n /**\n * This tells whether the data in this node has changed or not.\n */\n private hasDataChanged(): boolean {\n return super.hasChanged();\n }\n\n /**\n * This tells whether the used state of this node has changed since last successful summary. If the used routes\n * of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes\n * was previously used and became unused (or vice versa), its used state has changed.\n */\n private hasUsedStateChanged(): boolean {\n // If GC is disabled, we are not tracking used state, return false.\n if (this.gcDisabled) {\n return false;\n }\n\n return this.referenceUsedRoutes === undefined ||\n JSON.stringify(this.usedRoutes) !== JSON.stringify(this.referenceUsedRoutes);\n }\n}\n\n/**\n * Creates a root summarizer node with GC functionality built-in.\n * @param logger - Logger to use within SummarizerNode\n * @param summarizeInternalFn - Function to generate summary\n * @param changeSequenceNumber - Sequence number of latest change to new node/subtree\n * @param referenceSequenceNumber - Reference sequence number of last acked summary,\n * or undefined if not loaded from summary\n * @param config - Configure behavior of summarizer node\n * @param getGCDataFn - Function to get the GC data of this node\n * @param baseGCDetailsP - Function to get the initial GC details of this node\n */\nexport const createRootSummarizerNodeWithGC = (\n logger: ITelemetryLogger,\n summarizeInternalFn: SummarizeInternalFn,\n changeSequenceNumber: number,\n referenceSequenceNumber: number | undefined,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n): IRootSummarizerNodeWithGC => new SummarizerNodeWithGC(\n logger,\n summarizeInternalFn,\n config,\n changeSequenceNumber,\n referenceSequenceNumber === undefined ? undefined : SummaryNode.createForRoot(referenceSequenceNumber),\n undefined /* initialSummary */,\n undefined /* wipSummaryLogger */,\n getGCDataFn,\n getBaseGCDetailsFn,\n);\n"]}
1
+ {"version":3,"file":"summarizerNodeWithGc.js","sourceRoot":"","sources":["../../src/summarizerNode/summarizerNodeWithGc.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAExI,OAAO,EAEH,SAAS,GASZ,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAKH,uBAAuB,EACvB,WAAW,GACd,MAAM,uBAAuB,CAAC;AAI/B,wDAAwD;AACxD,MAAM,iBAAkB,SAAQ,WAAW;IACvC,YACoB,oBAA4B,EAC5C,OAKC;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QARC,yBAAoB,GAApB,oBAAoB,CAAQ;IAShD,CAAC;CACJ;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,oBAAqB,SAAQ,cAAc;IAuBpD;;;OAGG;IACH,YACI,MAAwB,EACP,WAIqB,EACtC,MAAmC,EACnC,oBAA4B;IAC5B,8CAA8C;IAC9C,aAA2B,EAC3B,cAAgC,EAChC,gBAAmC,EAClB,WAAmE,EACpF,kBAAiE;QAEjE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ent":["/*!\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 { assert, LazyPromise } from \"@fluidframework/common-utils\";\nimport { cloneGCData, getGCDataFromSnapshot, runGarbageCollection, unpackChildNodesGCDetails } from \"@fluidframework/garbage-collector\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n CreateChildSummarizerNodeParam,\n gcTreeKey,\n IGarbageCollectionData,\n IGarbageCollectionDetailsBase,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeConfigWithGC,\n ISummarizerNodeWithGC,\n SummarizeInternalFn,\n ITelemetryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { ReadAndParseBlob } from \"../utils\";\nimport { SummarizerNode } from \"./summarizerNode\";\nimport {\n EscapedPath,\n ICreateChildDetails,\n IInitialSummary,\n ISummarizerNodeRootContract,\n parseSummaryForSubtrees,\n SummaryNode,\n} from \"./summarizerNodeUtils\";\n\nexport interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {}\n\n// Extend SummaryNode to add used routes tracking to it.\nclass SummaryNodeWithGC extends SummaryNode {\n constructor(\n public readonly serializedUsedRoutes: string,\n summary: {\n readonly referenceSequenceNumber: number;\n readonly basePath: EscapedPath | undefined;\n readonly localPath: EscapedPath;\n additionalPath?: EscapedPath;\n },\n ) {\n super(summary);\n }\n}\n\n/**\n * Extends the functionality of SummarizerNode to manage this node's garbage collection data:\n *\n * - Adds a new API `getGCData` to return GC data of this node.\n *\n * - Caches the result of `getGCData` to be used if nothing changes between summaries.\n *\n * - Manages the used routes of this node. These are used to identify if this node is referenced in the document\n * and to determine if the node's used state changed since last summary.\n *\n * - Adds trackState param to summarize. If trackState is false, it bypasses the SummarizerNode and calls\n * directly into summarizeInternal method.\n */\nexport class SummarizerNodeWithGC extends SummarizerNode implements IRootSummarizerNodeWithGC {\n // Tracks the work-in-progress used routes during summary.\n private wipSerializedUsedRoutes: string | undefined;\n\n // This is the last known used routes of this node as seen by the server as part of a summary.\n private referenceUsedRoutes: string[] | undefined;\n\n // The base GC details of this node used to initialize the GC state.\n private readonly baseGCDetailsP: LazyPromise<IGarbageCollectionDetailsBase>;\n\n // Keeps track of whether we have loaded the base details to ensure that we on;y do it once.\n private baseGCDetailsLoaded: boolean = false;\n\n private gcData: IGarbageCollectionData | undefined;\n\n // Set used routes to have self route by default. This makes the node referenced by default. This is done to ensure\n // that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is\n // removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.\n private usedRoutes: string[] = [\"\"];\n\n // True if GC is disabled for this node. If so, do not track GC specific state for a summary.\n private readonly gcDisabled: boolean;\n\n /**\n * Do not call constructor directly.\n * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.\n */\n public constructor(\n logger: ITelemetryLogger,\n private readonly summarizeFn: (\n fullTree: boolean,\n trackState: boolean,\n telemetryContext?: ITelemetryContext,\n ) => Promise<ISummarizeInternalResult>,\n config: ISummarizerNodeConfigWithGC,\n changeSequenceNumber: number,\n /** Undefined means created without summary */\n latestSummary?: SummaryNode,\n initialSummary?: IInitialSummary,\n wipSummaryLogger?: ITelemetryLogger,\n private readonly getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n ) {\n super(\n logger,\n async (fullTree: boolean, _trackState: boolean, telemetryContext?: ITelemetryContext) =>\n summarizeFn(fullTree, true /* trackState */, telemetryContext),\n config,\n changeSequenceNumber,\n latestSummary,\n initialSummary,\n wipSummaryLogger,\n );\n\n this.gcDisabled = config.gcDisabled === true;\n\n this.baseGCDetailsP = new LazyPromise(async () => {\n return (await getBaseGCDetailsFn?.()) ?? { usedRoutes: [] };\n });\n }\n\n /**\n * Loads state from this node's initial GC summary details. This contains the following data from the last summary\n * seen by the server for this client:\n * - usedRoutes: This is used to figure out if the used state of this node changed since last summary.\n * - gcData: The garbage collection data of this node that is required for running GC.\n */\n private async loadBaseGCDetails() {\n if (this.baseGCDetailsLoaded) {\n return;\n }\n const baseGCDetails = await this.baseGCDetailsP;\n\n // Possible race - If there were parallel calls to loadBaseGCDetails, we want to make sure that we update\n // the state from the base details only once.\n if (this.baseGCDetailsLoaded) {\n return;\n }\n this.baseGCDetailsLoaded = true;\n\n // Update GC data, used routes and reference used routes. The used routes are sorted because they are compared\n // across GC runs to check if they changed. Sorting ensures that the elements are in the same order.\n // If the GC details has GC data, initialize our GC data from it.\n if (baseGCDetails.gcData !== undefined) {\n this.gcData = cloneGCData(baseGCDetails.gcData);\n }\n if (baseGCDetails.usedRoutes !== undefined) {\n this.usedRoutes = Array.from(baseGCDetails.usedRoutes).sort();\n this.referenceUsedRoutes = Array.from(baseGCDetails.usedRoutes).sort()\n }\n }\n\n public async summarize(\n fullTree: boolean,\n trackState: boolean = true,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummarizeResult> {\n // If GC is not disabled and we are tracking a summary, GC should have run and updated the used routes for this\n // summary by calling updateUsedRoutes which sets wipSerializedUsedRoutes.\n if (!this.gcDisabled && this.isTrackingInProgress()) {\n assert(this.wipSerializedUsedRoutes !== undefined,\n 0x1b1 /* \"wip used routes should be set if tracking a summary\" */);\n }\n\n // If trackState is true, get summary from base summarizer node which tracks summary state.\n // If trackState is false, get summary from summarizeInternal.\n return trackState\n ? super.summarize(fullTree, true /* trackState */, telemetryContext)\n : this.summarizeFn(fullTree, trackState, telemetryContext);\n }\n\n /**\n * Returns the GC data of this node. If nothing has changed since last summary, it tries to reuse the data from\n * the previous summary. Else, it gets new GC data from the underlying Fluid object.\n * @param fullGC - true to bypass optimizations and force full generation of GC data.\n */\n public async getGCData(fullGC: boolean = false): Promise<IGarbageCollectionData> {\n assert(!this.gcDisabled, 0x1b2 /* \"Getting GC data should not be called when GC is disabled!\" */);\n assert(this.getGCDataFn !== undefined, 0x1b3 /* \"GC data cannot be retrieved without getGCDataFn\" */);\n\n // Load GC details from the initial summary, if not already loaded. If this is the first time this function is\n // called and the node's data has not changed since last summary, the GC data in initial details is returned.\n await this.loadBaseGCDetails();\n\n // If there is no new data since last summary and we have GC data from the previous run, return it. The previous\n // GC data may not be available if loaded from a snapshot with either GC disabled or before GC was added.\n // Note - canReuseHandle is checked to be consistent with summarize - generate GC data for nodes for which\n // summary must be generated.\n if (this.canReuseHandle && !fullGC && !this.hasDataChanged() && this.gcData !== undefined) {\n return cloneGCData(this.gcData);\n }\n\n const gcData = await this.getGCDataFn(fullGC);\n this.gcData = cloneGCData(gcData);\n return gcData;\n }\n\n /**\n * Called during the start of a summary. Updates the work-in-progress used routes.\n */\n public startSummary(referenceSequenceNumber: number, summaryLogger: ITelemetryLogger) {\n // If GC is disabled, skip setting wip used routes since we should not track GC state.\n if (!this.gcDisabled) {\n assert(\n this.wipSerializedUsedRoutes === undefined,\n 0x1b4 /* \"We should not already be tracking used routes when to track a new summary\" */);\n }\n super.startSummary(referenceSequenceNumber, summaryLogger);\n }\n\n /**\n * Called after summary has been uploaded to the server. Add the work-in-progress state to the pending\n * summary queue. We track this until we get an ack from the server for this summary.\n */\n protected completeSummaryCore(\n proposalHandle: string,\n parentPath: EscapedPath | undefined,\n parentSkipRecursion: boolean,\n ) {\n let wipSerializedUsedRoutes: string | undefined;\n // If GC is disabled, don't set wip used routes.\n if (!this.gcDisabled) {\n wipSerializedUsedRoutes = this.wipSerializedUsedRoutes;\n assert(wipSerializedUsedRoutes !== undefined, 0x1b5 /* \"We should have been tracking used routes\" */);\n }\n\n super.completeSummaryCore(proposalHandle, parentPath, parentSkipRecursion);\n\n // If GC is disabled, skip setting pending summary with GC state.\n if (!this.gcDisabled) {\n const summaryNode = this.pendingSummaries.get(proposalHandle);\n if (summaryNode !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const summaryNodeWithGC = new SummaryNodeWithGC(wipSerializedUsedRoutes!, summaryNode);\n this.pendingSummaries.set(proposalHandle, summaryNodeWithGC);\n }\n }\n }\n\n /**\n * Clears the work-in-progress state.\n */\n public clearSummary() {\n this.wipSerializedUsedRoutes = undefined;\n super.clearSummary();\n }\n\n /**\n * Called when we get an ack from the server for a summary we sent. Update the reference state of this node\n * from the state in the pending summary queue.\n */\n protected refreshLatestSummaryFromPending(\n proposalHandle: string,\n referenceSequenceNumber: number,\n ): void {\n // If GC is disabled, skip setting referenced used routes since we are not tracking GC state.\n if (!this.gcDisabled) {\n const summaryNode = this.pendingSummaries.get(proposalHandle) as SummaryNodeWithGC;\n if (summaryNode?.serializedUsedRoutes !== undefined) {\n this.referenceUsedRoutes = JSON.parse(summaryNode.serializedUsedRoutes);\n }\n }\n\n return super.refreshLatestSummaryFromPending(proposalHandle, referenceSequenceNumber);\n }\n\n /**\n * Called when we need to upload the reference state from the given summary.\n */\n protected async refreshLatestSummaryFromSnapshot(\n referenceSequenceNumber: number,\n snapshotTree: ISnapshotTree,\n basePath: EscapedPath | undefined,\n localPath: EscapedPath,\n correlatedSummaryLogger: ITelemetryLogger,\n readAndParseBlob: ReadAndParseBlob,\n ): Promise<void> {\n await this.refreshGCStateFromSnapshot(referenceSequenceNumber, snapshotTree, readAndParseBlob);\n return super.refreshLatestSummaryFromSnapshot(\n referenceSequenceNumber,\n snapshotTree,\n basePath,\n localPath,\n correlatedSummaryLogger,\n readAndParseBlob,\n );\n }\n\n /**\n * Updates GC state from the given snapshot if GC is enabled and the snapshot is newer than the one this node\n * is tracking.\n */\n private async refreshGCStateFromSnapshot(\n referenceSequenceNumber: number,\n snapshotTree: ISnapshotTree,\n readAndParseBlob: ReadAndParseBlob,\n ): Promise<void> {\n // If GC is disabled or we have seen a newer summary, skip updating GC state.\n if (this.gcDisabled || this.referenceSequenceNumber >= referenceSequenceNumber) {\n return;\n }\n\n // Load the base GC details before proceeding because if that happens later it can overwrite the GC details\n // written by the following code.\n await this.loadBaseGCDetails();\n\n // Possible re-entrancy. We may already have processed this while loading base GC details.\n if (this.referenceSequenceNumber >= referenceSequenceNumber) {\n return;\n }\n\n /**\n * GC data is written at root of the snapshot tree under \"gc\" sub-tree. This data needs to be propagated to\n * all the nodes in the container.\n * The root summarizer node reads the GC data from the \"gc\" sub-tree, runs GC on it to get used routes in\n * the container and updates its GC data and referenced used routes. It then gets the GC data and used\n * routes of all its children and adds it to their snapshot tree.\n * All the other nodes gets the GC data and used routes from their snapshot tree and updates their state.\n * They get the GC data and used routes of their children and add it to their snapshot tree and so on.\n *\n * Note that if the snapshot does not have GC tree, GC data will be set to undefined and used routes will be\n * set to self-route (meaning referenced) for all nodes. This is important because the GC data needs to be\n * regenerated in the next summary.\n */\n let gcDetails: IGarbageCollectionDetailsBase | undefined;\n const gcSnapshotTree = snapshotTree.trees[gcTreeKey];\n if (gcSnapshotTree !== undefined) {\n // If there is a GC tree in the snapshot, this is the root summarizer node. Read GC data from the tree\n // process it as explained above.\n const gcSnapshotData = await getGCDataFromSnapshot(gcSnapshotTree, readAndParseBlob);\n\n const gcNodes: { [id: string]: string[]; } = {};\n for (const [nodeId, nodeData] of Object.entries(gcSnapshotData.gcState.gcNodes)) {\n gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);\n }\n // Run GC on the nodes in the snapshot to get the used routes for each node in the container.\n const usedRoutes = runGarbageCollection(gcNodes, [\"/\"]).referencedNodeIds;\n gcDetails = { gcData: { gcNodes }, usedRoutes };\n } else {\n // If there is a GC blob in the snapshot, it's a non-root summarizer nodes - The root summarizer node\n // writes GC blob in the snapshot of child nodes. Get GC data and used routes from the blob.\n const gcDetailsBlob = snapshotTree.blobs[gcTreeKey];\n if (gcDetailsBlob !== undefined) {\n gcDetails = JSON.parse(gcDetailsBlob) as IGarbageCollectionDetailsBase;\n }\n }\n\n // Update this node to the same GC state it was when the ack corresponding to this summary was processed.\n this.gcData = gcDetails?.gcData !== undefined ? cloneGCData(gcDetails.gcData) : undefined;\n this.referenceUsedRoutes = gcDetails?.usedRoutes !== undefined ? Array.from(gcDetails.usedRoutes) : undefined;\n // If there are no used routes in the GC details, set it to have self route which will make the node\n // referenced. This scenario can only happen if the snapshot is from a client where GC was not run or\n // disabled. In both the cases, the node should be referenced.\n this.usedRoutes = gcDetails?.usedRoutes !== undefined ? Array.from(gcDetails.usedRoutes) : [\"\"];\n\n if (gcDetails === undefined) {\n return;\n }\n\n // Generate the GC data and used routes of children GC nodes and add it to their snapshot tree.\n const gcDetailsMap = unpackChildNodesGCDetails(gcDetails);\n const { childrenTree } = parseSummaryForSubtrees(snapshotTree);\n gcDetailsMap.forEach((childGCDetails: IGarbageCollectionDetailsBase, childId: string) => {\n childrenTree.trees[childId].blobs[gcTreeKey] = JSON.stringify(childGCDetails);\n });\n }\n\n /**\n * Override the createChild method to return an instance of SummarizerNodeWithGC.\n */\n public createChild(\n /** Summarize function */\n summarizeInternalFn: SummarizeInternalFn,\n /** Initial id or path part of this node */\n id: string,\n /**\n * Information needed to create the node.\n * If it is from a base summary, it will assert that a summary has been seen.\n * Attach information if it is created from an attach op.\n */\n createParam: CreateChildSummarizerNodeParam,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n ): ISummarizerNodeWithGC {\n assert(!this.children.has(id), 0x1b6 /* \"Create SummarizerNode child already exists\" */);\n\n /**\n * Update the child node's base GC details from this node's current GC details instead of updating from the base\n * GC details of this node. This will handle scenarios where the GC details was updated during refresh from\n * snapshot and the child node wasn't created then. If a child is created after that, its GC details should be\n * the one from the downloaded snapshot and not the base GC details.\n */\n const getChildBaseGCDetailsP = new LazyPromise<IGarbageCollectionDetailsBase>(async () => {\n // Ensure that the base GC details is loaded because a child can be created before GC runs which is when\n // base GC details is usually loaded.\n await this.loadBaseGCDetails();\n const childBaseGCDetails = unpackChildNodesGCDetails({ gcData: this.gcData, usedRoutes: this.usedRoutes });\n return childBaseGCDetails.get(id) ?? {};\n });\n\n const createDetails: ICreateChildDetails = this.getCreateDetailsForChild(id, createParam);\n const child = new SummarizerNodeWithGC(\n this.defaultLogger,\n summarizeInternalFn,\n {\n ...config,\n // Propagate our gcDisabled state to the child if its not explicity specified in child's config.\n gcDisabled: config.gcDisabled ?? this.gcDisabled,\n },\n createDetails.changeSequenceNumber,\n createDetails.latestSummary,\n createDetails.initialSummary,\n this.wipSummaryLogger,\n getGCDataFn,\n async () => getChildBaseGCDetailsP,\n );\n\n // There may be additional state that has to be updated in this child. For example, if a summary is being\n // tracked, the child's summary tracking state needs to be updated too.\n this.maybeUpdateChildState(child);\n\n this.children.set(id, child);\n return child;\n }\n\n /**\n * Deletes the child node with the given id.\n */\n public deleteChild(id: string): void {\n this.children.delete(id);\n }\n\n /**\n * Override the getChild method to return an instance of SummarizerNodeWithGC.\n */\n public getChild(id: string): ISummarizerNodeWithGC | undefined {\n return this.children.get(id) as SummarizerNodeWithGC;\n }\n\n public isReferenced(): boolean {\n return this.usedRoutes.includes(\"\") || this.usedRoutes.includes(\"/\");\n }\n\n public updateUsedRoutes(usedRoutes: string[]) {\n // Sort the given routes before updating. This will ensure that the routes compared in hasUsedStateChanged()\n // are in the same order.\n this.usedRoutes = usedRoutes.sort();\n\n // If GC is not disabled and we are tracking a summary, update the work-in-progress used routes so that it can\n // be tracked for this summary.\n if (!this.gcDisabled && this.isTrackingInProgress()) {\n this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);\n }\n }\n\n /**\n * Override the hasChanged method. If this node data or its used state changed, the node is considered changed.\n */\n protected hasChanged(): boolean {\n return this.hasDataChanged() || this.hasUsedStateChanged();\n }\n\n /**\n * This tells whether the data in this node has changed or not.\n */\n private hasDataChanged(): boolean {\n return super.hasChanged();\n }\n\n /**\n * This tells whether the used state of this node has changed since last successful summary. If the used routes\n * of this node changed, its used state is considered changed. Basically, if this node or any of its child nodes\n * was previously used and became unused (or vice versa), its used state has changed.\n */\n private hasUsedStateChanged(): boolean {\n // If GC is disabled, we are not tracking used state, return false.\n if (this.gcDisabled) {\n return false;\n }\n\n return this.referenceUsedRoutes === undefined ||\n JSON.stringify(this.usedRoutes) !== JSON.stringify(this.referenceUsedRoutes);\n }\n}\n\n/**\n * Creates a root summarizer node with GC functionality built-in.\n * @param logger - Logger to use within SummarizerNode\n * @param summarizeInternalFn - Function to generate summary\n * @param changeSequenceNumber - Sequence number of latest change to new node/subtree\n * @param referenceSequenceNumber - Reference sequence number of last acked summary,\n * or undefined if not loaded from summary\n * @param config - Configure behavior of summarizer node\n * @param getGCDataFn - Function to get the GC data of this node\n * @param baseGCDetailsP - Function to get the initial GC details of this node\n */\nexport const createRootSummarizerNodeWithGC = (\n logger: ITelemetryLogger,\n summarizeInternalFn: SummarizeInternalFn,\n changeSequenceNumber: number,\n referenceSequenceNumber: number | undefined,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getBaseGCDetailsFn?: () => Promise<IGarbageCollectionDetailsBase>,\n): IRootSummarizerNodeWithGC => new SummarizerNodeWithGC(\n logger,\n summarizeInternalFn,\n config,\n changeSequenceNumber,\n referenceSequenceNumber === undefined ? undefined : SummaryNode.createForRoot(referenceSequenceNumber),\n undefined /* initialSummary */,\n undefined /* wipSummaryLogger */,\n getGCDataFn,\n getBaseGCDetailsFn,\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/runtime-utils",
3
- "version": "2.0.0-internal.2.2.1",
3
+ "version": "2.0.0-internal.2.3.1",
4
4
  "description": "Collection of utility functions for Fluid Runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -64,23 +64,23 @@
64
64
  "dependencies": {
65
65
  "@fluidframework/common-definitions": "^0.20.1",
66
66
  "@fluidframework/common-utils": "^1.0.0",
67
- "@fluidframework/container-definitions": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
68
- "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
69
- "@fluidframework/core-interfaces": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
70
- "@fluidframework/datastore-definitions": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
71
- "@fluidframework/garbage-collector": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
67
+ "@fluidframework/container-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
68
+ "@fluidframework/container-runtime-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
69
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
70
+ "@fluidframework/datastore-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
71
+ "@fluidframework/garbage-collector": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
72
72
  "@fluidframework/protocol-base": "^0.1038.2000",
73
73
  "@fluidframework/protocol-definitions": "^1.1.0",
74
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
75
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0"
74
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
75
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@fluid-tools/build-cli": "^0.7.0",
79
79
  "@fluidframework/build-common": "^1.1.0",
80
80
  "@fluidframework/build-tools": "^0.7.0",
81
- "@fluidframework/eslint-config-fluid": "^1.2.0",
82
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.2.1 <2.0.0-internal.3.0.0",
83
- "@fluidframework/runtime-utils-previous": "npm:@fluidframework/runtime-utils@2.0.0-internal.2.2.0",
81
+ "@fluidframework/eslint-config-fluid": "^2.0.0",
82
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.3.1 <2.0.0-internal.3.0.0",
83
+ "@fluidframework/runtime-utils-previous": "npm:@fluidframework/runtime-utils@2.0.0-internal.2.3.0",
84
84
  "@microsoft/api-extractor": "^7.22.2",
85
85
  "@rushstack/eslint-config": "^2.5.1",
86
86
  "@types/mocha": "^9.1.1",
@@ -98,8 +98,8 @@
98
98
  "typescript": "~4.5.5"
99
99
  },
100
100
  "typeValidation": {
101
- "version": "2.0.0-internal.2.2.0",
102
- "baselineRange": "2.0.0-internal.2.2.0",
101
+ "version": "2.0.0-internal.2.3.1",
102
+ "baselineRange": "2.0.0-internal.2.3.0",
103
103
  "broken": {}
104
104
  }
105
105
  }
@@ -23,6 +23,7 @@ interface IResponseException extends Error {
23
23
  message: string;
24
24
  code: number;
25
25
  stack?: string;
26
+ underlyingResponseHeaders?: { [key: string]: any; };
26
27
  }
27
28
 
28
29
  export function exceptionToResponse(err: any): IResponse {
@@ -34,6 +35,7 @@ export function exceptionToResponse(err: any): IResponse {
34
35
  status: responseErr.code,
35
36
  value: responseErr.message,
36
37
  get stack() { return responseErr.stack; },
38
+ headers: responseErr.underlyingResponseHeaders,
37
39
  };
38
40
  }
39
41
 
@@ -57,6 +59,7 @@ export function responseToException(response: IResponse, request: IRequest): Err
57
59
  name: "Error",
58
60
  code: response.status,
59
61
  get stack() { return response.stack ?? errWithStack.stack; },
62
+ underlyingResponseHeaders: response.headers,
60
63
  };
61
64
 
62
65
  return responseErr;
@@ -86,7 +89,7 @@ export async function requestFluidObject<T = FluidObject>(
86
89
 
87
90
  export const create404Response = (request: IRequest) => createResponseError(404, "not found", request);
88
91
 
89
- export function createResponseError(status: number, value: string, request: IRequest): IResponse {
92
+ export function createResponseError(status: number, value: string, request: IRequest, headers?: { [key: string]: any }): IResponse {
90
93
  assert(status !== 200, 0x19b /* "Cannot not create response error on 200 status" */);
91
94
  // Omit query string which could contain personal data (aka "PII")
92
95
  const urlNoQuery = request.url?.split("?")[0];
@@ -99,6 +102,7 @@ export function createResponseError(status: number, value: string, request: IReq
99
102
  status,
100
103
  value: urlNoQuery === undefined ? value : `${value}: ${urlNoQuery}`,
101
104
  get stack() { return errWithStack.stack; },
105
+ headers,
102
106
  };
103
107
  }
104
108
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/runtime-utils";
9
- export const pkgVersion = "2.0.0-internal.2.2.1";
9
+ export const pkgVersion = "2.0.0-internal.2.3.1";
@@ -384,7 +384,7 @@ export class SummarizerNode implements IRootSummarizerNode {
384
384
  return this._latestSummary;
385
385
  }
386
386
 
387
- private readonly canReuseHandle: boolean;
387
+ protected readonly canReuseHandle: boolean;
388
388
 
389
389
  /**
390
390
  * Do not call constructor directly.