@fluidframework/runtime-utils 0.52.0 → 0.54.0-47413

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 (47) hide show
  1. package/bench/src/index.ts +1 -1
  2. package/dist/dataStoreHelpers.d.ts +0 -1
  3. package/dist/dataStoreHelpers.d.ts.map +1 -1
  4. package/dist/dataStoreHelpers.js +18 -31
  5. package/dist/dataStoreHelpers.js.map +1 -1
  6. package/dist/packageVersion.d.ts +1 -1
  7. package/dist/packageVersion.d.ts.map +1 -1
  8. package/dist/packageVersion.js +1 -1
  9. package/dist/packageVersion.js.map +1 -1
  10. package/dist/remoteObjectHandle.d.ts +0 -4
  11. package/dist/remoteObjectHandle.d.ts.map +1 -1
  12. package/dist/remoteObjectHandle.js +0 -6
  13. package/dist/remoteObjectHandle.js.map +1 -1
  14. package/dist/serializer.d.ts +2 -1
  15. package/dist/serializer.d.ts.map +1 -1
  16. package/dist/serializer.js +7 -2
  17. package/dist/serializer.js.map +1 -1
  18. package/dist/summarizerNode/summarizerNodeWithGc.d.ts +1 -13
  19. package/dist/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  20. package/dist/summarizerNode/summarizerNodeWithGc.js +3 -73
  21. package/dist/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  22. package/lib/dataStoreHelpers.d.ts +0 -1
  23. package/lib/dataStoreHelpers.d.ts.map +1 -1
  24. package/lib/dataStoreHelpers.js +17 -29
  25. package/lib/dataStoreHelpers.js.map +1 -1
  26. package/lib/packageVersion.d.ts +1 -1
  27. package/lib/packageVersion.d.ts.map +1 -1
  28. package/lib/packageVersion.js +1 -1
  29. package/lib/packageVersion.js.map +1 -1
  30. package/lib/remoteObjectHandle.d.ts +0 -4
  31. package/lib/remoteObjectHandle.d.ts.map +1 -1
  32. package/lib/remoteObjectHandle.js +0 -6
  33. package/lib/remoteObjectHandle.js.map +1 -1
  34. package/lib/serializer.d.ts +2 -1
  35. package/lib/serializer.d.ts.map +1 -1
  36. package/lib/serializer.js +7 -2
  37. package/lib/serializer.js.map +1 -1
  38. package/lib/summarizerNode/summarizerNodeWithGc.d.ts +1 -13
  39. package/lib/summarizerNode/summarizerNodeWithGc.d.ts.map +1 -1
  40. package/lib/summarizerNode/summarizerNodeWithGc.js +4 -74
  41. package/lib/summarizerNode/summarizerNodeWithGc.js.map +1 -1
  42. package/package.json +10 -9
  43. package/src/dataStoreHelpers.ts +24 -29
  44. package/src/packageVersion.ts +1 -1
  45. package/src/remoteObjectHandle.ts +0 -7
  46. package/src/serializer.ts +8 -2
  47. package/src/summarizerNode/summarizerNodeWithGc.ts +3 -92
@@ -2,12 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert, LazyPromise, Timer } from "@fluidframework/common-utils";
5
+ import { assert, LazyPromise } from "@fluidframework/common-utils";
6
6
  import { cloneGCData } from "@fluidframework/garbage-collector";
7
7
  import { gcBlobKey, } from "@fluidframework/runtime-definitions";
8
8
  import { SummarizerNode } from "./summarizerNode";
9
9
  import { SummaryNode, } from "./summarizerNodeUtils";
10
- const defaultMaxUnreferencedDurationMs = 7 * 24 * 60 * 60 * 1000; // 7 days
11
10
  // Extend SummaryNode to add used routes tracking to it.
12
11
  class SummaryNodeWithGC extends SummaryNode {
13
12
  constructor(serializedUsedRoutes, summary) {
@@ -32,7 +31,6 @@ export class SummarizerNodeWithGC extends SummarizerNode {
32
31
  constructor(logger, summarizeFn, config, changeSequenceNumber,
33
32
  /** Undefined means created without summary */
34
33
  latestSummary, initialSummary, wipSummaryLogger, getGCDataFn, getInitialGCSummaryDetailsFn) {
35
- var _a;
36
34
  super(logger, async (fullTree) => summarizeFn(fullTree, true /* trackState */), config, changeSequenceNumber, latestSummary, initialSummary, wipSummaryLogger);
37
35
  this.summarizeFn = summarizeFn;
38
36
  this.getGCDataFn = getGCDataFn;
@@ -40,20 +38,11 @@ export class SummarizerNodeWithGC extends SummarizerNode {
40
38
  // that this node is not marked as collected when running GC has been disabled. Once, the option to disable GC is
41
39
  // removed (from runGC flag in IContainerRuntimeOptions), this should be changed to be have no routes by default.
42
40
  this.usedRoutes = [""];
43
- // Tracks whether this node is inactive after being unreferenced for maxUnreferencedDurationMs.
44
- this.inactive = false;
45
- // Keeps track of whether we logged an use-after-free error. This is temporary since the error is too noisy.
46
- // To be removed once this item is completed - https://github.com/microsoft/FluidFramework/issues/7895.
47
- this.useAfterFreeErrorLogged = false;
48
41
  this.gcDisabled = config.gcDisabled === true;
49
- this.maxUnreferencedDurationMs = (_a = config.maxUnreferencedDurationMs) !== null && _a !== void 0 ? _a : defaultMaxUnreferencedDurationMs;
50
42
  this.gcDetailsInInitialSummaryP = new LazyPromise(async () => {
51
43
  const gcSummaryDetails = await (getInitialGCSummaryDetailsFn === null || getInitialGCSummaryDetailsFn === void 0 ? void 0 : getInitialGCSummaryDetailsFn());
52
44
  return gcSummaryDetails !== null && gcSummaryDetails !== void 0 ? gcSummaryDetails : { usedRoutes: [] };
53
45
  });
54
- this.unreferencedTimer = new Timer(this.maxUnreferencedDurationMs, () => {
55
- this.inactive = true;
56
- });
57
46
  }
58
47
  // Returns the GC details that may be added to this node's summary.
59
48
  getGCSummaryDetails() {
@@ -200,12 +189,12 @@ export class SummarizerNodeWithGC extends SummarizerNode {
200
189
  * Attach information if it is created from an attach op.
201
190
  */
202
191
  createParam, config = {}, getGCDataFn, getInitialGCSummaryDetailsFn) {
203
- var _a, _b;
192
+ var _a;
204
193
  assert(!this.children.has(id), 0x1b6 /* "Create SummarizerNode child already exists" */);
205
194
  const createDetails = this.getCreateDetailsForChild(id, createParam);
206
195
  const child = new SummarizerNodeWithGC(this.defaultLogger, summarizeInternalFn, Object.assign(Object.assign({}, config), {
207
196
  // Propagate our gcDisabled state to the child if its not explicity specified in child's config.
208
- gcDisabled: (_a = config.gcDisabled) !== null && _a !== void 0 ? _a : this.gcDisabled, maxUnreferencedDurationMs: (_b = config.maxUnreferencedDurationMs) !== null && _b !== void 0 ? _b : this.maxUnreferencedDurationMs }), createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, getGCDataFn, getInitialGCSummaryDetailsFn);
197
+ gcDisabled: (_a = config.gcDisabled) !== null && _a !== void 0 ? _a : this.gcDisabled }), createDetails.changeSequenceNumber, createDetails.latestSummary, createDetails.initialSummary, this.wipSummaryLogger, getGCDataFn, getInitialGCSummaryDetailsFn);
209
198
  // There may be additional state that has to be updated in this child. For example, if a summary is being
210
199
  // tracked, the child's summary tracking state needs to be updated too.
211
200
  this.maybeUpdateChildState(child);
@@ -237,72 +226,13 @@ export class SummarizerNodeWithGC extends SummarizerNode {
237
226
  this.wipSerializedUsedRoutes = JSON.stringify(this.usedRoutes);
238
227
  }
239
228
  if (this.isReferenced()) {
240
- // If this node has been unreferenced for longer than maxUnreferencedDurationMs and is being referenced,
241
- // log an error as this may mean the maxUnreferencedDurationMs is not long enough.
242
- this.logErrorIfInactive("inactiveObjectRevived", gcTimestamp);
243
- // Clear unreferenced / inactive state, if any.
244
- this.inactive = false;
245
229
  this.unreferencedTimestampMs = undefined;
246
- this.unreferencedTimer.clear();
247
- return;
248
- }
249
- // This node is unreferenced. We need to check if this node is inative or if we need to start the unreferenced
250
- // timer which would mark the node as inactive.
251
- // If there is no timestamp when GC was run, we don't have enough information to determine whether this content
252
- // should become inactive.
253
- if (gcTimestamp === undefined) {
254
230
  return;
255
231
  }
256
- // If unreferencedTimestampMs is not present, this node just became unreferenced. Update unreferencedTimestampMs
257
- // and start the unreferenced timer.
258
- // Note that it's possible this node has been unreferenced before but the unreferencedTimestampMs was not added.
259
- // For example, older versions where this concept did not exist or if gcTimestamp wasn't available. In such
260
- // cases, we track them as if the content just became unreferenced.
232
+ // If this node just became unreferenced, update its unreferencedTimestampMs.
261
233
  if (this.unreferencedTimestampMs === undefined) {
262
234
  this.unreferencedTimestampMs = gcTimestamp;
263
- this.unreferencedTimer.start();
264
- return;
265
- }
266
- // If we are here, this node was unreferenced earlier.
267
- // If it is already inactive or has an unreferenced timer running, there is no more work to be done.
268
- if (this.inactive || this.unreferencedTimer.hasTimer) {
269
- return;
270
- }
271
- // If it has been unreferenced longer than maxUnreferencedDurationMs, mark it as inactive. Otherwise, start the
272
- // unreferenced timer for the duration left for it to reach maxUnreferencedDurationMs.
273
- const currentUnreferencedDurationMs = gcTimestamp - this.unreferencedTimestampMs;
274
- if (currentUnreferencedDurationMs >= this.maxUnreferencedDurationMs) {
275
- this.inactive = true;
276
- }
277
- else {
278
- this.unreferencedTimer.start(this.maxUnreferencedDurationMs - currentUnreferencedDurationMs);
279
- }
280
- }
281
- recordChange(op) {
282
- // If the node is changed after it is inactive, log an error as this may mean use-after-delete.
283
- // Currently, we only log this error once per node per session as it's too noisy.
284
- if (!this.useAfterFreeErrorLogged && this.logErrorIfInactive("inactiveObjectChanged")) {
285
- this.useAfterFreeErrorLogged = true;
286
- }
287
- super.recordChange(op);
288
- }
289
- /**
290
- * Logs an error event if the node is inactive. This is used to identify cases where an inactive object is used.
291
- * @param eventName - The name of the event to log.
292
- * @param currentTimestampMs - The current time stamp. Used to report how long the object has been inactive.
293
- * @returns true if we logged an error, false otherwise.
294
- */
295
- logErrorIfInactive(eventName, currentTimestampMs) {
296
- if (this.inactive) {
297
- assert(this.unreferencedTimestampMs !== undefined, 0x271 /* "Node should not become inactive without setting unreferencedTimestampMs first" */);
298
- this.defaultLogger.sendErrorEvent({
299
- eventName,
300
- unreferencedDuratonMs: (currentTimestampMs !== null && currentTimestampMs !== void 0 ? currentTimestampMs : Date.now()) - this.unreferencedTimestampMs,
301
- maxUnreferencedDurationMs: this.maxUnreferencedDurationMs,
302
- });
303
- return true;
304
235
  }
305
- return false;
306
236
  }
307
237
  /**
308
238
  * Override the hasChanged method. If this node data or its used state changed, the node is considered changed.
@@ -1 +1 @@
1
- {"version":3,"file":"summarizerNodeWithGc.js","sourceRoot":"","sources":["../../src/summarizerNode/summarizerN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AAM,8BAA8B,GAAG,CAC1C,MAAwB,EACxB,mBAAkG,EAClG,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAsC,EAAE,EACxC,WAAmE,EACnE,4BAA8E,EACrD,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,4BAA4B,CAC/B,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, Timer } from \"@fluidframework/common-utils\";\nimport { cloneGCData } from \"@fluidframework/garbage-collector\";\nimport { ISequencedDocumentMessage, ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n CreateChildSummarizerNodeParam,\n gcBlobKey,\n IGarbageCollectionData,\n IGarbageCollectionSummaryDetails,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeConfigWithGC,\n ISummarizerNodeWithGC,\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\nconst defaultMaxUnreferencedDurationMs = 7 * 24 * 60 * 60 * 1000; // 7 days\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 * - Adds a new API `getGCData` to return GC data of this node.\n * - Caches the result of `getGCData` to be used if nothing changes between summaries.\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 * - 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 GC details of this node in the initial summary.\n private gcDetailsInInitialSummaryP: LazyPromise<IGarbageCollectionSummaryDetails> | undefined;\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 // If this node is marked as unreferenced, the time when it marked as such.\n private unreferencedTimestampMs: number | undefined;\n\n // The max duration for which this node can be unreferenced before it is eligible for deletion.\n private readonly maxUnreferencedDurationMs: number;\n\n // The timer that runs when the node is marked unreferenced.\n private readonly unreferencedTimer: Timer;\n\n // Tracks whether this node is inactive after being unreferenced for maxUnreferencedDurationMs.\n private inactive: boolean = false;\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 // Keeps track of whether we logged an use-after-free error. This is temporary since the error is too noisy.\n // To be removed once this item is completed - https://github.com/microsoft/FluidFramework/issues/7895.\n private useAfterFreeErrorLogged: boolean = false;\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: (fullTree: boolean, trackState: boolean) => 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 getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\n ) {\n super(\n logger,\n async (fullTree: boolean) => summarizeFn(fullTree, true /* trackState */),\n config,\n changeSequenceNumber,\n latestSummary,\n initialSummary,\n wipSummaryLogger,\n );\n\n this.gcDisabled = config.gcDisabled === true;\n this.maxUnreferencedDurationMs = config.maxUnreferencedDurationMs ?? defaultMaxUnreferencedDurationMs;\n\n this.gcDetailsInInitialSummaryP = new LazyPromise(async () => {\n const gcSummaryDetails = await getInitialGCSummaryDetailsFn?.();\n return gcSummaryDetails ?? { usedRoutes: [] };\n });\n\n this.unreferencedTimer = new Timer(this.maxUnreferencedDurationMs, () => {\n this.inactive = true;\n });\n }\n\n // Returns the GC details that may be added to this node's summary.\n public getGCSummaryDetails(): IGarbageCollectionSummaryDetails {\n return {\n gcData: this.gcData,\n usedRoutes: this.usedRoutes,\n unrefTimestamp: this.unreferencedTimestampMs,\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 loadInitialGCSummaryDetails() {\n if (this.gcDetailsInInitialSummaryP === undefined) {\n return;\n }\n\n const gcDetailsInInitialSummaryP = this.gcDetailsInInitialSummaryP;\n this.gcDetailsInInitialSummaryP = undefined;\n\n const gcDetailsInInitialSummary = await gcDetailsInInitialSummaryP;\n // If the GC details has GC data, initialize our GC data from it.\n if (gcDetailsInInitialSummary.gcData !== undefined) {\n this.gcData = cloneGCData(gcDetailsInInitialSummary.gcData);\n }\n this.referenceUsedRoutes = gcDetailsInInitialSummary.usedRoutes;\n this.unreferencedTimestampMs = gcDetailsInInitialSummary.unrefTimestamp;\n }\n\n public async summarize(fullTree: boolean, trackState: boolean = true): 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 ? super.summarize(fullTree) : this.summarizeFn(fullTree, trackState);\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.loadInitialGCSummaryDetails();\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 !== 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<IGarbageCollectionSummaryDetails>(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: (fullTree: boolean, trackState: boolean) => Promise<ISummarizeInternalResult>,\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 getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\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 maxUnreferencedDurationMs: config.maxUnreferencedDurationMs ?? this.maxUnreferencedDurationMs,\n },\n createDetails.changeSequenceNumber,\n createDetails.latestSummary,\n createDetails.initialSummary,\n this.wipSummaryLogger,\n getGCDataFn,\n getInitialGCSummaryDetailsFn,\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[], gcTimestamp?: number) {\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 if (this.isReferenced()) {\n // If this node has been unreferenced for longer than maxUnreferencedDurationMs and is being referenced,\n // log an error as this may mean the maxUnreferencedDurationMs is not long enough.\n this.logErrorIfInactive(\"inactiveObjectRevived\", gcTimestamp);\n\n // Clear unreferenced / inactive state, if any.\n this.inactive = false;\n this.unreferencedTimestampMs = undefined;\n this.unreferencedTimer.clear();\n return;\n }\n\n // This node is unreferenced. We need to check if this node is inative or if we need to start the unreferenced\n // timer which would mark the node as inactive.\n\n // If there is no timestamp when GC was run, we don't have enough information to determine whether this content\n // should become inactive.\n if (gcTimestamp === undefined) {\n return;\n }\n\n // If unreferencedTimestampMs is not present, this node just became unreferenced. Update unreferencedTimestampMs\n // and start the unreferenced timer.\n // Note that it's possible this node has been unreferenced before but the unreferencedTimestampMs was not added.\n // For example, older versions where this concept did not exist or if gcTimestamp wasn't available. In such\n // cases, we track them as if the content just became unreferenced.\n if (this.unreferencedTimestampMs === undefined) {\n this.unreferencedTimestampMs = gcTimestamp;\n this.unreferencedTimer.start();\n return;\n }\n\n // If we are here, this node was unreferenced earlier.\n\n // If it is already inactive or has an unreferenced timer running, there is no more work to be done.\n if (this.inactive || this.unreferencedTimer.hasTimer) {\n return;\n }\n\n // If it has been unreferenced longer than maxUnreferencedDurationMs, mark it as inactive. Otherwise, start the\n // unreferenced timer for the duration left for it to reach maxUnreferencedDurationMs.\n const currentUnreferencedDurationMs = gcTimestamp - this.unreferencedTimestampMs;\n if (currentUnreferencedDurationMs >= this.maxUnreferencedDurationMs) {\n this.inactive = true;\n } else {\n this.unreferencedTimer.start(this.maxUnreferencedDurationMs - currentUnreferencedDurationMs);\n }\n }\n\n public recordChange(op: ISequencedDocumentMessage): void {\n // If the node is changed after it is inactive, log an error as this may mean use-after-delete.\n // Currently, we only log this error once per node per session as it's too noisy.\n if (!this.useAfterFreeErrorLogged && this.logErrorIfInactive(\"inactiveObjectChanged\")) {\n this.useAfterFreeErrorLogged = true;\n }\n super.recordChange(op);\n }\n\n /**\n * Logs an error event if the node is inactive. This is used to identify cases where an inactive object is used.\n * @param eventName - The name of the event to log.\n * @param currentTimestampMs - The current time stamp. Used to report how long the object has been inactive.\n * @returns true if we logged an error, false otherwise.\n */\n private logErrorIfInactive(eventName: string, currentTimestampMs?: number): boolean {\n if (this.inactive) {\n assert(\n this.unreferencedTimestampMs !== undefined,\n 0x271 /* \"Node should not become inactive without setting unreferencedTimestampMs first\" */);\n this.defaultLogger.sendErrorEvent({\n eventName,\n unreferencedDuratonMs: (currentTimestampMs ?? Date.now()) - this.unreferencedTimestampMs,\n maxUnreferencedDurationMs: this.maxUnreferencedDurationMs,\n });\n return true;\n }\n return false;\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 gcDetailsInInitialSummaryP - Function to get the initial GC details of this node\n */\nexport const createRootSummarizerNodeWithGC = (\n logger: ITelemetryLogger,\n summarizeInternalFn: (fullTree: boolean, trackState: boolean) => Promise<ISummarizeInternalResult>,\n changeSequenceNumber: number,\n referenceSequenceNumber: number | undefined,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\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 getInitialGCSummaryDetailsFn,\n);\n"]}
1
+ {"version":3,"file":"summarizerNodeWithGc.js","sourceRoot":"","sources":["../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AC;IAC9B,CAAC;IAED;;;;OAIG;IACK,mBAAmB;QACvB,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,mBAAkG,EAClG,oBAA4B,EAC5B,uBAA2C,EAC3C,SAAsC,EAAE,EACxC,WAAmE,EACnE,4BAA8E,EACrD,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,4BAA4B,CAC/B,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 IGarbageCollectionSummaryDetails,\n ISummarizeInternalResult,\n ISummarizeResult,\n ISummarizerNodeConfigWithGC,\n ISummarizerNodeWithGC,\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 * - Adds a new API `getGCData` to return GC data of this node.\n * - Caches the result of `getGCData` to be used if nothing changes between summaries.\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 * - 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 GC details of this node in the initial summary.\n private gcDetailsInInitialSummaryP: LazyPromise<IGarbageCollectionSummaryDetails> | undefined;\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 // If this node is marked as unreferenced, the time when it marked as such.\n private unreferencedTimestampMs: number | undefined;\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: (fullTree: boolean, trackState: boolean) => 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 getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\n ) {\n super(\n logger,\n async (fullTree: boolean) => summarizeFn(fullTree, true /* trackState */),\n config,\n changeSequenceNumber,\n latestSummary,\n initialSummary,\n wipSummaryLogger,\n );\n\n this.gcDisabled = config.gcDisabled === true;\n\n this.gcDetailsInInitialSummaryP = new LazyPromise(async () => {\n const gcSummaryDetails = await getInitialGCSummaryDetailsFn?.();\n return gcSummaryDetails ?? { usedRoutes: [] };\n });\n }\n\n // Returns the GC details that may be added to this node's summary.\n public getGCSummaryDetails(): IGarbageCollectionSummaryDetails {\n return {\n gcData: this.gcData,\n usedRoutes: this.usedRoutes,\n unrefTimestamp: this.unreferencedTimestampMs,\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 loadInitialGCSummaryDetails() {\n if (this.gcDetailsInInitialSummaryP === undefined) {\n return;\n }\n\n const gcDetailsInInitialSummaryP = this.gcDetailsInInitialSummaryP;\n this.gcDetailsInInitialSummaryP = undefined;\n\n const gcDetailsInInitialSummary = await gcDetailsInInitialSummaryP;\n // If the GC details has GC data, initialize our GC data from it.\n if (gcDetailsInInitialSummary.gcData !== undefined) {\n this.gcData = cloneGCData(gcDetailsInInitialSummary.gcData);\n }\n this.referenceUsedRoutes = gcDetailsInInitialSummary.usedRoutes;\n this.unreferencedTimestampMs = gcDetailsInInitialSummary.unrefTimestamp;\n }\n\n public async summarize(fullTree: boolean, trackState: boolean = true): 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 ? super.summarize(fullTree) : this.summarizeFn(fullTree, trackState);\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.loadInitialGCSummaryDetails();\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 !== 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<IGarbageCollectionSummaryDetails>(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: (fullTree: boolean, trackState: boolean) => Promise<ISummarizeInternalResult>,\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 getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\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 getInitialGCSummaryDetailsFn,\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[], gcTimestamp?: number) {\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 if (this.isReferenced()) {\n this.unreferencedTimestampMs = undefined;\n return;\n }\n\n // If this node just became unreferenced, update its unreferencedTimestampMs.\n if (this.unreferencedTimestampMs === undefined) {\n this.unreferencedTimestampMs = gcTimestamp;\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 gcDetailsInInitialSummaryP - Function to get the initial GC details of this node\n */\nexport const createRootSummarizerNodeWithGC = (\n logger: ITelemetryLogger,\n summarizeInternalFn: (fullTree: boolean, trackState: boolean) => Promise<ISummarizeInternalResult>,\n changeSequenceNumber: number,\n referenceSequenceNumber: number | undefined,\n config: ISummarizerNodeConfigWithGC = {},\n getGCDataFn?: (fullGC?: boolean) => Promise<IGarbageCollectionData>,\n getInitialGCSummaryDetailsFn?: () => Promise<IGarbageCollectionSummaryDetails>,\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 getInitialGCSummaryDetailsFn,\n);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/runtime-utils",
3
- "version": "0.52.0",
3
+ "version": "0.54.0-47413",
4
4
  "description": "Collection of utility functions for Fluid Runtime",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": "https://github.com/microsoft/FluidFramework",
@@ -58,24 +58,25 @@
58
58
  "dependencies": {
59
59
  "@fluidframework/common-definitions": "^0.20.1",
60
60
  "@fluidframework/common-utils": "^0.32.1",
61
- "@fluidframework/container-definitions": "^0.42.0",
62
- "@fluidframework/container-runtime-definitions": "^0.52.0",
61
+ "@fluidframework/container-definitions": "^0.44.0-0",
62
+ "@fluidframework/container-runtime-definitions": "0.54.0-47413",
63
63
  "@fluidframework/core-interfaces": "^0.41.0",
64
- "@fluidframework/datastore-definitions": "^0.52.0",
65
- "@fluidframework/garbage-collector": "^0.52.0",
64
+ "@fluidframework/datastore-definitions": "0.54.0-47413",
65
+ "@fluidframework/garbage-collector": "0.54.0-47413",
66
66
  "@fluidframework/protocol-base": "^0.1034.0",
67
67
  "@fluidframework/protocol-definitions": "^0.1026.0",
68
- "@fluidframework/runtime-definitions": "^0.52.0"
68
+ "@fluidframework/runtime-definitions": "0.54.0-47413",
69
+ "@fluidframework/telemetry-utils": "0.54.0-47413"
69
70
  },
70
71
  "devDependencies": {
71
72
  "@fluidframework/build-common": "^0.23.0",
72
73
  "@fluidframework/eslint-config-fluid": "^0.24.0",
73
- "@fluidframework/mocha-test-setup": "^0.52.0",
74
- "@fluidframework/telemetry-utils": "^0.52.0",
74
+ "@fluidframework/mocha-test-setup": "0.54.0-47413",
75
+ "@fluidframework/telemetry-utils": "^0.53.0",
75
76
  "@microsoft/api-extractor": "^7.16.1",
76
77
  "@types/benchmark": "^2.1.0",
77
78
  "@types/mocha": "^8.2.2",
78
- "@types/node": "^12.19.0",
79
+ "@types/node": "^14.18.0",
79
80
  "@typescript-eslint/eslint-plugin": "~4.14.0",
80
81
  "@typescript-eslint/parser": "~4.14.0",
81
82
  "benchmark": "^2.1.4",
@@ -16,24 +16,13 @@ import {
16
16
  IFluidDataStoreRegistry,
17
17
  IProvideFluidDataStoreRegistry,
18
18
  } from "@fluidframework/runtime-definitions";
19
+ import { generateErrorWithStack } from "@fluidframework/telemetry-utils";
19
20
 
20
21
  interface IResponseException extends Error {
21
22
  errorFromRequestFluidObject: true;
22
23
  message: string;
23
24
  code: number;
24
- stack: string;
25
- }
26
-
27
- export function getStack() {
28
- const err = new Error();
29
- if (err.stack !== undefined) {
30
- return err.stack;
31
- }
32
- try {
33
- throw err;
34
- } catch (err2) {
35
- return (err2 as Error).stack;
36
- }
25
+ stack?: string;
37
26
  }
38
27
 
39
28
  export function exceptionToResponse(err: any): IResponse {
@@ -45,31 +34,33 @@ export function exceptionToResponse(err: any): IResponse {
45
34
  mimeType: "text/plain",
46
35
  status: responseErr.code,
47
36
  value: responseErr.message,
48
- stack: responseErr.stack ?? getStack(),
37
+ get stack() { return responseErr.stack; },
49
38
  };
50
39
  }
40
+
41
+ // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
42
+ const errWithStack = generateErrorWithStack();
43
+
51
44
  return {
52
45
  mimeType: "text/plain",
53
46
  status,
54
47
  value: `${err}`,
55
- stack: getStack(),
48
+ get stack() { return ((err?.stack) as (string|undefined)) ?? errWithStack.stack; },
56
49
  };
57
50
  }
58
51
 
59
- export function responseToException(response: IResponse, request: IRequest) {
52
+ export function responseToException(response: IResponse, request: IRequest): Error {
60
53
  const message = response.value;
61
- const err = new Error(message);
62
- const responseErr = err as any as IResponseException;
63
- responseErr.errorFromRequestFluidObject = true;
64
- responseErr.message = message;
65
- responseErr.code = response.status;
66
- if (response.stack !== undefined) {
67
- try {
68
- // not clear if all browsers allow overwriting stack
69
- responseErr.stack = response.stack;
70
- } catch (err2) {}
71
- }
72
- return err;
54
+ const errWithStack = generateErrorWithStack();
55
+ const responseErr: Error & IResponseException = {
56
+ errorFromRequestFluidObject: true,
57
+ message,
58
+ name: "Error",
59
+ code: response.status,
60
+ get stack() { return response.stack ?? errWithStack.stack; },
61
+ };
62
+
63
+ return responseErr;
73
64
  }
74
65
 
75
66
  export async function requestFluidObject<T = IFluidObject & FluidObject>(
@@ -91,11 +82,15 @@ export function createResponseError(status: number, value: string, request: IReq
91
82
  assert(status !== 200, 0x19b /* "Cannot not create response error on 200 status" */);
92
83
  // Omit query string which could contain personal data (aka "PII")
93
84
  const urlNoQuery = request.url?.split("?")[0];
85
+
86
+ // Capture error objects, not stack itself, as stack retrieval is very expensive operation, so we delay it
87
+ const errWithStack = generateErrorWithStack();
88
+
94
89
  return {
95
90
  mimeType: "text/plain",
96
91
  status,
97
92
  value: urlNoQuery === undefined ? value : `${value}: ${urlNoQuery}`,
98
- stack: getStack(),
93
+ get stack() { return errWithStack.stack; },
99
94
  };
100
95
  }
101
96
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/runtime-utils";
9
- export const pkgVersion = "0.52.0";
9
+ export const pkgVersion = "0.54.0-47413";
@@ -41,13 +41,6 @@ export class RemoteFluidObjectHandle implements IFluidHandle {
41
41
  assert(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
42
42
  }
43
43
 
44
- /**
45
- * @deprecated - This returns the absolute path.
46
- */
47
- public get path() {
48
- return this.absolutePath;
49
- }
50
-
51
44
  public async get(): Promise<any> {
52
45
  if (this.objectP === undefined) {
53
46
  const request = { url: this.absolutePath };
package/src/serializer.ts CHANGED
@@ -21,7 +21,11 @@ import { isSerializedHandle } from "./utils";
21
21
  export class FluidSerializer implements IFluidSerializer {
22
22
  private readonly root: IFluidHandleContext;
23
23
 
24
- public constructor(private readonly context: IFluidHandleContext) {
24
+ public constructor(
25
+ private readonly context: IFluidHandleContext,
26
+ // To be called whenever a handle is parsed by this serializer.
27
+ private readonly handleParsedCb: (handle: IFluidHandle) => void,
28
+ ) {
25
29
  this.root = this.context;
26
30
  while (this.root.routeContext !== undefined) {
27
31
  this.root = this.root.routeContext;
@@ -101,7 +105,9 @@ export class FluidSerializer implements IFluidSerializer {
101
105
  ? value.url
102
106
  : generateHandleContextPath(value.url, this.context);
103
107
 
104
- return new RemoteFluidObjectHandle(absolutePath, this.root);
108
+ const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);
109
+ this.handleParsedCb(parsedHandle);
110
+ return parsedHandle;
105
111
  } else {
106
112
  return value;
107
113
  }
@@ -4,9 +4,9 @@
4
4
  */
5
5
 
6
6
  import { ITelemetryLogger } from "@fluidframework/common-definitions";
7
- import { assert, LazyPromise, Timer } from "@fluidframework/common-utils";
7
+ import { assert, LazyPromise } from "@fluidframework/common-utils";
8
8
  import { cloneGCData } from "@fluidframework/garbage-collector";
9
- import { ISequencedDocumentMessage, ISnapshotTree } from "@fluidframework/protocol-definitions";
9
+ import { ISnapshotTree } from "@fluidframework/protocol-definitions";
10
10
  import {
11
11
  CreateChildSummarizerNodeParam,
12
12
  gcBlobKey,
@@ -27,8 +27,6 @@ import {
27
27
  SummaryNode,
28
28
  } from "./summarizerNodeUtils";
29
29
 
30
- const defaultMaxUnreferencedDurationMs = 7 * 24 * 60 * 60 * 1000; // 7 days
31
-
32
30
  export interface IRootSummarizerNodeWithGC extends ISummarizerNodeWithGC, ISummarizerNodeRootContract {}
33
31
 
34
32
  // Extend SummaryNode to add used routes tracking to it.
@@ -75,22 +73,9 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
75
73
  // If this node is marked as unreferenced, the time when it marked as such.
76
74
  private unreferencedTimestampMs: number | undefined;
77
75
 
78
- // The max duration for which this node can be unreferenced before it is eligible for deletion.
79
- private readonly maxUnreferencedDurationMs: number;
80
-
81
- // The timer that runs when the node is marked unreferenced.
82
- private readonly unreferencedTimer: Timer;
83
-
84
- // Tracks whether this node is inactive after being unreferenced for maxUnreferencedDurationMs.
85
- private inactive: boolean = false;
86
-
87
76
  // True if GC is disabled for this node. If so, do not track GC specific state for a summary.
88
77
  private readonly gcDisabled: boolean;
89
78
 
90
- // Keeps track of whether we logged an use-after-free error. This is temporary since the error is too noisy.
91
- // To be removed once this item is completed - https://github.com/microsoft/FluidFramework/issues/7895.
92
- private useAfterFreeErrorLogged: boolean = false;
93
-
94
79
  /**
95
80
  * Do not call constructor directly.
96
81
  * Use createRootSummarizerNodeWithGC to create root node, or createChild to create child nodes.
@@ -118,16 +103,11 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
118
103
  );
119
104
 
120
105
  this.gcDisabled = config.gcDisabled === true;
121
- this.maxUnreferencedDurationMs = config.maxUnreferencedDurationMs ?? defaultMaxUnreferencedDurationMs;
122
106
 
123
107
  this.gcDetailsInInitialSummaryP = new LazyPromise(async () => {
124
108
  const gcSummaryDetails = await getInitialGCSummaryDetailsFn?.();
125
109
  return gcSummaryDetails ?? { usedRoutes: [] };
126
110
  });
127
-
128
- this.unreferencedTimer = new Timer(this.maxUnreferencedDurationMs, () => {
129
- this.inactive = true;
130
- });
131
111
  }
132
112
 
133
113
  // Returns the GC details that may be added to this node's summary.
@@ -334,7 +314,6 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
334
314
  ...config,
335
315
  // Propagate our gcDisabled state to the child if its not explicity specified in child's config.
336
316
  gcDisabled: config.gcDisabled ?? this.gcDisabled,
337
- maxUnreferencedDurationMs: config.maxUnreferencedDurationMs ?? this.maxUnreferencedDurationMs,
338
317
  },
339
318
  createDetails.changeSequenceNumber,
340
319
  createDetails.latestSummary,
@@ -382,82 +361,14 @@ export class SummarizerNodeWithGC extends SummarizerNode implements IRootSummari
382
361
  }
383
362
 
384
363
  if (this.isReferenced()) {
385
- // If this node has been unreferenced for longer than maxUnreferencedDurationMs and is being referenced,
386
- // log an error as this may mean the maxUnreferencedDurationMs is not long enough.
387
- this.logErrorIfInactive("inactiveObjectRevived", gcTimestamp);
388
-
389
- // Clear unreferenced / inactive state, if any.
390
- this.inactive = false;
391
364
  this.unreferencedTimestampMs = undefined;
392
- this.unreferencedTimer.clear();
393
365
  return;
394
366
  }
395
367
 
396
- // This node is unreferenced. We need to check if this node is inative or if we need to start the unreferenced
397
- // timer which would mark the node as inactive.
398
-
399
- // If there is no timestamp when GC was run, we don't have enough information to determine whether this content
400
- // should become inactive.
401
- if (gcTimestamp === undefined) {
402
- return;
403
- }
404
-
405
- // If unreferencedTimestampMs is not present, this node just became unreferenced. Update unreferencedTimestampMs
406
- // and start the unreferenced timer.
407
- // Note that it's possible this node has been unreferenced before but the unreferencedTimestampMs was not added.
408
- // For example, older versions where this concept did not exist or if gcTimestamp wasn't available. In such
409
- // cases, we track them as if the content just became unreferenced.
368
+ // If this node just became unreferenced, update its unreferencedTimestampMs.
410
369
  if (this.unreferencedTimestampMs === undefined) {
411
370
  this.unreferencedTimestampMs = gcTimestamp;
412
- this.unreferencedTimer.start();
413
- return;
414
- }
415
-
416
- // If we are here, this node was unreferenced earlier.
417
-
418
- // If it is already inactive or has an unreferenced timer running, there is no more work to be done.
419
- if (this.inactive || this.unreferencedTimer.hasTimer) {
420
- return;
421
- }
422
-
423
- // If it has been unreferenced longer than maxUnreferencedDurationMs, mark it as inactive. Otherwise, start the
424
- // unreferenced timer for the duration left for it to reach maxUnreferencedDurationMs.
425
- const currentUnreferencedDurationMs = gcTimestamp - this.unreferencedTimestampMs;
426
- if (currentUnreferencedDurationMs >= this.maxUnreferencedDurationMs) {
427
- this.inactive = true;
428
- } else {
429
- this.unreferencedTimer.start(this.maxUnreferencedDurationMs - currentUnreferencedDurationMs);
430
- }
431
- }
432
-
433
- public recordChange(op: ISequencedDocumentMessage): void {
434
- // If the node is changed after it is inactive, log an error as this may mean use-after-delete.
435
- // Currently, we only log this error once per node per session as it's too noisy.
436
- if (!this.useAfterFreeErrorLogged && this.logErrorIfInactive("inactiveObjectChanged")) {
437
- this.useAfterFreeErrorLogged = true;
438
- }
439
- super.recordChange(op);
440
- }
441
-
442
- /**
443
- * Logs an error event if the node is inactive. This is used to identify cases where an inactive object is used.
444
- * @param eventName - The name of the event to log.
445
- * @param currentTimestampMs - The current time stamp. Used to report how long the object has been inactive.
446
- * @returns true if we logged an error, false otherwise.
447
- */
448
- private logErrorIfInactive(eventName: string, currentTimestampMs?: number): boolean {
449
- if (this.inactive) {
450
- assert(
451
- this.unreferencedTimestampMs !== undefined,
452
- 0x271 /* "Node should not become inactive without setting unreferencedTimestampMs first" */);
453
- this.defaultLogger.sendErrorEvent({
454
- eventName,
455
- unreferencedDuratonMs: (currentTimestampMs ?? Date.now()) - this.unreferencedTimestampMs,
456
- maxUnreferencedDurationMs: this.maxUnreferencedDurationMs,
457
- });
458
- return true;
459
371
  }
460
- return false;
461
372
  }
462
373
 
463
374
  /**