@fluidframework/container-runtime 0.53.0 → 0.54.2

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 (96) hide show
  1. package/dist/containerRuntime.d.ts +25 -16
  2. package/dist/containerRuntime.d.ts.map +1 -1
  3. package/dist/containerRuntime.js +126 -77
  4. package/dist/containerRuntime.js.map +1 -1
  5. package/dist/dataStoreContext.d.ts +29 -3
  6. package/dist/dataStoreContext.d.ts.map +1 -1
  7. package/dist/dataStoreContext.js +29 -4
  8. package/dist/dataStoreContext.js.map +1 -1
  9. package/dist/dataStores.d.ts +7 -3
  10. package/dist/dataStores.d.ts.map +1 -1
  11. package/dist/dataStores.js +54 -5
  12. package/dist/dataStores.js.map +1 -1
  13. package/dist/garbageCollection.d.ts +22 -2
  14. package/dist/garbageCollection.d.ts.map +1 -1
  15. package/dist/garbageCollection.js +112 -34
  16. package/dist/garbageCollection.js.map +1 -1
  17. package/dist/packageVersion.d.ts +1 -1
  18. package/dist/packageVersion.js +1 -1
  19. package/dist/packageVersion.js.map +1 -1
  20. package/dist/runningSummarizer.d.ts +3 -2
  21. package/dist/runningSummarizer.d.ts.map +1 -1
  22. package/dist/runningSummarizer.js +6 -6
  23. package/dist/runningSummarizer.js.map +1 -1
  24. package/dist/summarizer.d.ts +22 -0
  25. package/dist/summarizer.d.ts.map +1 -1
  26. package/dist/summarizer.js +135 -33
  27. package/dist/summarizer.js.map +1 -1
  28. package/dist/summarizerTypes.d.ts +1 -8
  29. package/dist/summarizerTypes.d.ts.map +1 -1
  30. package/dist/summarizerTypes.js.map +1 -1
  31. package/dist/summaryFormat.d.ts +1 -0
  32. package/dist/summaryFormat.d.ts.map +1 -1
  33. package/dist/summaryFormat.js +2 -1
  34. package/dist/summaryFormat.js.map +1 -1
  35. package/dist/summaryManager.d.ts +0 -15
  36. package/dist/summaryManager.d.ts.map +1 -1
  37. package/dist/summaryManager.js +1 -35
  38. package/dist/summaryManager.js.map +1 -1
  39. package/lib/containerRuntime.d.ts +25 -16
  40. package/lib/containerRuntime.d.ts.map +1 -1
  41. package/lib/containerRuntime.js +132 -83
  42. package/lib/containerRuntime.js.map +1 -1
  43. package/lib/dataStoreContext.d.ts +29 -3
  44. package/lib/dataStoreContext.d.ts.map +1 -1
  45. package/lib/dataStoreContext.js +29 -4
  46. package/lib/dataStoreContext.js.map +1 -1
  47. package/lib/dataStores.d.ts +7 -3
  48. package/lib/dataStores.d.ts.map +1 -1
  49. package/lib/dataStores.js +54 -5
  50. package/lib/dataStores.js.map +1 -1
  51. package/lib/garbageCollection.d.ts +22 -2
  52. package/lib/garbageCollection.d.ts.map +1 -1
  53. package/lib/garbageCollection.js +114 -36
  54. package/lib/garbageCollection.js.map +1 -1
  55. package/lib/packageVersion.d.ts +1 -1
  56. package/lib/packageVersion.js +1 -1
  57. package/lib/packageVersion.js.map +1 -1
  58. package/lib/runningSummarizer.d.ts +3 -2
  59. package/lib/runningSummarizer.d.ts.map +1 -1
  60. package/lib/runningSummarizer.js +6 -6
  61. package/lib/runningSummarizer.js.map +1 -1
  62. package/lib/summarizer.d.ts +22 -0
  63. package/lib/summarizer.d.ts.map +1 -1
  64. package/lib/summarizer.js +135 -33
  65. package/lib/summarizer.js.map +1 -1
  66. package/lib/summarizerTypes.d.ts +1 -8
  67. package/lib/summarizerTypes.d.ts.map +1 -1
  68. package/lib/summarizerTypes.js.map +1 -1
  69. package/lib/summaryFormat.d.ts +1 -0
  70. package/lib/summaryFormat.d.ts.map +1 -1
  71. package/lib/summaryFormat.js +1 -0
  72. package/lib/summaryFormat.js.map +1 -1
  73. package/lib/summaryManager.d.ts +0 -15
  74. package/lib/summaryManager.d.ts.map +1 -1
  75. package/lib/summaryManager.js +1 -34
  76. package/lib/summaryManager.js.map +1 -1
  77. package/package.json +13 -13
  78. package/src/containerRuntime.ts +177 -93
  79. package/src/dataStoreContext.ts +44 -6
  80. package/src/dataStores.ts +84 -4
  81. package/src/garbageCollection.ts +137 -46
  82. package/src/packageVersion.ts +1 -1
  83. package/src/runningSummarizer.ts +12 -10
  84. package/src/summarizer.ts +154 -38
  85. package/src/summarizerTypes.ts +2 -9
  86. package/src/summaryFormat.ts +1 -0
  87. package/src/summaryManager.ts +2 -49
  88. package/dist/localStorageFeatureGates.d.ts +0 -13
  89. package/dist/localStorageFeatureGates.d.ts.map +0 -1
  90. package/dist/localStorageFeatureGates.js +0 -31
  91. package/dist/localStorageFeatureGates.js.map +0 -1
  92. package/lib/localStorageFeatureGates.d.ts +0 -13
  93. package/lib/localStorageFeatureGates.d.ts.map +0 -1
  94. package/lib/localStorageFeatureGates.js +0 -27
  95. package/lib/localStorageFeatureGates.js.map +0 -1
  96. package/src/localStorageFeatureGates.ts +0 -27
@@ -11,7 +11,6 @@ const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
11
11
  const runtime_utils_1 = require("@fluidframework/runtime-utils");
12
12
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
13
13
  const dataStores_1 = require("./dataStores");
14
- const localStorageFeatureGates_1 = require("./localStorageFeatureGates");
15
14
  const summaryFormat_1 = require("./summaryFormat");
16
15
  /** This is the current version of garbage collection. */
17
16
  const GCVersion = 1;
@@ -20,11 +19,11 @@ exports.gcTreeKey = "gc";
20
19
  // They prefix for GC blobs in the GC tree in summary.
21
20
  exports.gcBlobPrefix = "__gc";
22
21
  // Local storage key to turn GC on / off.
23
- const runGCKey = "FluidRunGC";
22
+ const runGCKey = "Fluid.GarbageCollection.RunGC";
24
23
  // Local storage key to turn GC test mode on / off.
25
- const gcTestModeKey = "FluidGCTestMode";
24
+ const gcTestModeKey = "Fluid.GarbageCollection.GCTestMode";
26
25
  // Local storage key to turn GC sweep on / off.
27
- const runSweepKey = "FluidRunSweep";
26
+ const runSweepKey = "Fluid.GarbageCollection.RunSweep";
28
27
  const defaultDeleteTimeoutMs = 7 * 24 * 60 * 60 * 1000; // 7 days
29
28
  /**
30
29
  * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced. It also sets
@@ -58,9 +57,9 @@ class UnreferencedStateTracker {
58
57
  if (this.inactive && !this.inactiveEventsLogged.has(eventName)) {
59
58
  logger.sendErrorEvent({
60
59
  eventName,
61
- unreferencedDuratonMs: currentTimestampMs - this.unreferencedTimestampMs,
62
- deleteTimeoutMs,
63
- inactiveNodeId,
60
+ age: currentTimestampMs - this.unreferencedTimestampMs,
61
+ timeout: deleteTimeoutMs,
62
+ id: inactiveNodeId,
64
63
  });
65
64
  this.inactiveEventsLogged.add(eventName);
66
65
  }
@@ -90,9 +89,12 @@ class GarbageCollector {
90
89
  this._writeDataAtRoot = false;
91
90
  // The current GC version that this container is running.
92
91
  this.currentGCVersion = GCVersion;
92
+ // Keeps a list of references (edges in the GC graph) between GC runs. Each entry has a node id and a list of
93
+ // outbound routes from that node.
94
+ this.referencesSinceLastRun = new Map();
93
95
  // Map of node ids to their unreferenced state tracker.
94
96
  this.unreferencedNodesState = new Map();
95
- this.logger = telemetry_utils_1.ChildLogger.create(baseLogger, "GarbageCollector");
97
+ this.mc = telemetry_utils_1.loggerToMonitoringContext(telemetry_utils_1.ChildLogger.create(baseLogger, "GarbageCollector"));
96
98
  this.deleteTimeoutMs = (_a = this.gcOptions.deleteTimeoutMs) !== null && _a !== void 0 ? _a : defaultDeleteTimeoutMs;
97
99
  let prevSummaryGCVersion;
98
100
  // GC can only be enabled during creation. After that, it can never be enabled again. So, for existing
@@ -111,7 +113,7 @@ class GarbageCollector {
111
113
  // latest tracked GC version. For new documents, we will be writing the first summary with the current version.
112
114
  this.latestSummaryGCVersion = prevSummaryGCVersion !== null && prevSummaryGCVersion !== void 0 ? prevSummaryGCVersion : this.currentGCVersion;
113
115
  // Whether GC should run or not. Can override with localStorage flag.
114
- this.shouldRunGC = (_b = localStorageFeatureGates_1.getLocalStorageFeatureGate(runGCKey)) !== null && _b !== void 0 ? _b : (
116
+ this.shouldRunGC = (_b = this.mc.config.getBoolean(runGCKey)) !== null && _b !== void 0 ? _b : (
115
117
  // GC must be enabled for the document.
116
118
  this.gcEnabled
117
119
  // GC must not be disabled via GC options.
@@ -119,9 +121,9 @@ class GarbageCollector {
119
121
  // Whether GC sweep phase should run or not. If this is false, only GC mark phase is run. Can override with
120
122
  // localStorage flag.
121
123
  this.shouldRunSweep = this.shouldRunGC &&
122
- ((_c = localStorageFeatureGates_1.getLocalStorageFeatureGate(runSweepKey)) !== null && _c !== void 0 ? _c : gcOptions.runSweep === true);
124
+ ((_c = this.mc.config.getBoolean(runSweepKey)) !== null && _c !== void 0 ? _c : gcOptions.runSweep === true);
123
125
  // Whether we are running in test mode. In this mode, unreferenced nodes are immediately deleted.
124
- this.testMode = (_d = localStorageFeatureGates_1.getLocalStorageFeatureGate(gcTestModeKey)) !== null && _d !== void 0 ? _d : gcOptions.runGCInTestMode === true;
126
+ this.testMode = (_d = this.mc.config.getBoolean(gcTestModeKey)) !== null && _d !== void 0 ? _d : gcOptions.runGCInTestMode === true;
125
127
  // If `writeDataAtRoot` GC option is true, we should write the GC data into the root of the summary tree. This
126
128
  // GC option is used for testing only. It will be removed once we start writing GC data into root by default.
127
129
  this._writeDataAtRoot = this.gcOptions.writeDataAtRoot === true;
@@ -130,7 +132,7 @@ class GarbageCollector {
130
132
  const baseSummaryStateP = new common_utils_1.LazyPromise(async () => {
131
133
  var _a;
132
134
  if (baseSnapshot === undefined) {
133
- return { gcNodes: {} };
135
+ return undefined;
134
136
  }
135
137
  // For newer documents, GC data should be present in the GC tree in the root of the snapshot.
136
138
  const gcSnapshotTree = baseSnapshot.trees[exports.gcTreeKey];
@@ -141,6 +143,7 @@ class GarbageCollector {
141
143
  }
142
144
  // back-compat - Older documents will have the GC blobs in each data store's summary tree. Get them and
143
145
  // consolidate into IGarbageCollectionState format.
146
+ // Add a node for the root node that is not present in older snapshot format.
144
147
  const gcState = { gcNodes: { "/": { outboundRoutes: [] } } };
145
148
  const dataStoreSnaphotTree = dataStores_1.getSummaryForDatastores(baseSnapshot, metadata);
146
149
  common_utils_1.assert(dataStoreSnaphotTree !== undefined, 0x2a8 /* "Expected data store snapshot tree in base snapshot" */);
@@ -170,41 +173,46 @@ class GarbageCollector {
170
173
  common_utils_1.assert(gcState.gcNodes[dsRootId] !== undefined, 0x2a9 /* `GC nodes for data store ${dsId} not in GC blob` */);
171
174
  gcState.gcNodes[dsRootId].unreferencedTimestampMs = gcSummaryDetails.unrefTimestamp;
172
175
  }
173
- return gcState;
176
+ // If there is only one node (root node just added above), either GC is disabled or we are loading from the
177
+ // very first summary generated by detached container. In both cases, GC was not run - return undefined.
178
+ return Object.keys(gcState.gcNodes).length === 1 ? undefined : gcState;
174
179
  });
175
180
  // Set up the initializer which initializes the base GC state from the base snapshot. Use lazy promise because
176
181
  // we only do this once - the very first time we run GC.
177
182
  this.initializeBaseStateP = new common_utils_1.LazyPromise(async () => {
183
+ const currentTimestampMs = this.getCurrentTimestampMs();
178
184
  const baseState = await baseSummaryStateP;
185
+ if (baseState === undefined) {
186
+ return;
187
+ }
179
188
  const gcNodes = {};
180
- // Set up tracking for the nodes in the base summary state and add them to GC nodes.
181
189
  for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {
182
190
  const unreferencedTimestampMs = nodeData.unreferencedTimestampMs;
183
191
  if (unreferencedTimestampMs !== undefined) {
184
192
  // Get how long it has been since the node was unreferenced. Start a timeout for the remaining time
185
193
  // left for it to be eligible for deletion.
186
- const unreferencedDurationMs = this.getCurrentTimestampMs() - unreferencedTimestampMs;
194
+ const unreferencedDurationMs = currentTimestampMs - unreferencedTimestampMs;
187
195
  this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(unreferencedTimestampMs, this.deleteTimeoutMs - unreferencedDurationMs));
188
196
  }
189
- gcNodes[nodeId] = {
190
- outboundRoutes: Array.from(nodeData.outboundRoutes),
191
- unreferencedTimestampMs,
192
- };
197
+ gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
193
198
  }
194
- this.currentGCState = { gcNodes };
199
+ this.gcDataFromLastRun = { gcNodes };
195
200
  });
196
201
  // Get the GC details for each data store from the GC state in the base summary. This is returned in
197
202
  // getDataStoreBaseGCDetails and is used to initialize each data store's base GC details.
198
203
  this.dataStoreGCDetailsP = new common_utils_1.LazyPromise(async () => {
199
- const gcNodes = {};
200
204
  const baseState = await baseSummaryStateP;
205
+ if (baseState === undefined) {
206
+ return new Map();
207
+ }
208
+ const gcNodes = {};
201
209
  for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {
202
210
  gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
203
211
  }
204
212
  // Run GC on the nodes in the base summary to get the routes used in each node in the container.
205
213
  // This is an optimization for space (vs performance) wherein we don't need to store the used routes of
206
214
  // each node in the summary.
207
- const usedRoutes = garbage_collector_1.runGarbageCollection(gcNodes, ["/"], this.logger).referencedNodeIds;
215
+ const usedRoutes = garbage_collector_1.runGarbageCollection(gcNodes, ["/"], this.mc.logger).referencedNodeIds;
208
216
  const dataStoreGCDetailsMap = garbage_collector_1.unpackChildNodesGCDetails({ gcData: { gcNodes }, usedRoutes });
209
217
  // Currently, the data stores write the GC data. So, we need to update it's base GC details with the
210
218
  // unreferenced timestamp. Once we start writing the GC data here, we won't need to do this anymore.
@@ -247,12 +255,13 @@ class GarbageCollector {
247
255
  * @returns the number of data stores that have been marked as unreferenced.
248
256
  */
249
257
  async collectGarbage(options) {
250
- const { logger = this.logger, runSweep = this.shouldRunSweep, fullGC = this.gcOptions.runFullGC === true || this.hasGCVersionChanged, } = options;
258
+ const { logger = this.mc.logger, runSweep = this.shouldRunSweep, fullGC = this.gcOptions.runFullGC === true || this.hasGCVersionChanged, } = options;
251
259
  return telemetry_utils_1.PerformanceEvent.timedExecAsync(logger, { eventName: "GarbageCollection" }, async (event) => {
252
260
  await this.initializeBaseStateP;
253
261
  const gcStats = {};
254
262
  // Get the runtime's GC data and run GC on the reference graph in it.
255
263
  const gcData = await this.provider.getGCData(fullGC);
264
+ this.updateStateSinceLatestRun(gcData);
256
265
  const gcResult = garbage_collector_1.runGarbageCollection(gcData.gcNodes, ["/"], logger);
257
266
  const currentTimestampMs = this.getCurrentTimestampMs();
258
267
  // Update the current state of the system based on the GC run.
@@ -281,11 +290,19 @@ class GarbageCollector {
281
290
  * blobs. All the blob keys should start with `gcBlobPrefix`.
282
291
  */
283
292
  summarize() {
284
- if (!this.shouldRunGC || this.currentGCState === undefined) {
293
+ var _a;
294
+ if (!this.shouldRunGC || this.gcDataFromLastRun === undefined) {
285
295
  return;
286
296
  }
297
+ const gcState = { gcNodes: {} };
298
+ for (const [nodeId, outboundRoutes] of Object.entries(this.gcDataFromLastRun.gcNodes)) {
299
+ gcState.gcNodes[nodeId] = {
300
+ outboundRoutes,
301
+ unreferencedTimestampMs: (_a = this.unreferencedNodesState.get(nodeId)) === null || _a === void 0 ? void 0 : _a.unreferencedTimestampMs,
302
+ };
303
+ }
287
304
  const builder = new runtime_utils_1.SummaryTreeBuilder();
288
- builder.addBlob(`${exports.gcBlobPrefix}_root`, JSON.stringify(this.currentGCState));
305
+ builder.addBlob(`${exports.gcBlobPrefix}_root`, JSON.stringify(gcState));
289
306
  return builder.getSummaryTree();
290
307
  }
291
308
  /**
@@ -320,7 +337,20 @@ class GarbageCollector {
320
337
  var _a;
321
338
  // Prefix "/" if needed to make it relative to the root.
322
339
  const nodeId = id.startsWith("/") ? id : `/${id}`;
323
- (_a = this.unreferencedNodesState.get(nodeId)) === null || _a === void 0 ? void 0 : _a.logIfInactive(this.logger, "inactiveObjectChanged", this.getCurrentTimestampMs(), this.deleteTimeoutMs, nodeId);
340
+ (_a = this.unreferencedNodesState.get(nodeId)) === null || _a === void 0 ? void 0 : _a.logIfInactive(this.mc.logger, "inactiveObjectChanged", this.getCurrentTimestampMs(), this.deleteTimeoutMs, nodeId);
341
+ }
342
+ /**
343
+ * Called when an outbound reference is added to a node. This is used to identify all nodes that have been
344
+ * referenced between summaries so that their unreferenced timestamp can be reset.
345
+ *
346
+ * @param fromNodeId - The node from which the reference is added.
347
+ * @param toNodeId - The node to which the reference is added.
348
+ */
349
+ addedOutboundReference(fromNodeId, toNodeId) {
350
+ var _a;
351
+ const outboundRoutes = (_a = this.referencesSinceLastRun.get(fromNodeId)) !== null && _a !== void 0 ? _a : [];
352
+ outboundRoutes.push(toNodeId);
353
+ this.referencesSinceLastRun.set(fromNodeId, outboundRoutes);
324
354
  }
325
355
  /**
326
356
  * Update the latest summary GC version from the metadata blob in the given snapshot.
@@ -342,13 +372,10 @@ class GarbageCollector {
342
372
  * @param currentTimestampMs - The current timestamp to be used for unreferenced nodes' timestamp.
343
373
  */
344
374
  updateCurrentState(gcData, gcResult, currentTimestampMs) {
345
- this.currentGCState = { gcNodes: {} };
346
- for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {
347
- this.currentGCState.gcNodes[id] = { outboundRoutes: Array.from(outboundRoutes) };
348
- }
375
+ this.gcDataFromLastRun = garbage_collector_1.cloneGCData(gcData);
376
+ this.referencesSinceLastRun.clear();
349
377
  // Iterate through the deleted nodes and start tracking if they became unreferenced in this run.
350
378
  for (const nodeId of gcResult.deletedNodeIds) {
351
- common_utils_1.assert(this.currentGCState.gcNodes[nodeId] !== undefined, 0x2aa /* "Unexpected node when running GC" */);
352
379
  // The time when the node became unreferenced. This is added to the current GC state.
353
380
  let unreferencedTimestampMs = currentTimestampMs;
354
381
  const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
@@ -359,16 +386,67 @@ class GarbageCollector {
359
386
  // Start tracking this node as it became unreferenced in this run.
360
387
  this.unreferencedNodesState.set(nodeId, new UnreferencedStateTracker(unreferencedTimestampMs, this.deleteTimeoutMs));
361
388
  }
362
- this.currentGCState.gcNodes[nodeId].unreferencedTimestampMs = unreferencedTimestampMs;
363
389
  }
364
390
  // Iterate through the referenced nodes and stop tracking if they were unreferenced before.
365
391
  for (const nodeId of gcResult.referencedNodeIds) {
366
- common_utils_1.assert(this.currentGCState.gcNodes[nodeId] !== undefined, 0x2ab /* "Unexpected node when running GC" */);
367
392
  const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
368
393
  if (nodeStateTracker !== undefined) {
369
394
  // If this node has been unreferenced for longer than deleteTimeoutMs and is being referenced,
370
395
  // log an error as this may mean the deleteTimeoutMs is not long enough.
371
- nodeStateTracker.logIfInactive(this.logger, "inactiveObjectRevived", currentTimestampMs, this.deleteTimeoutMs, nodeId);
396
+ nodeStateTracker.logIfInactive(this.mc.logger, "inactiveObjectRevived", currentTimestampMs, this.deleteTimeoutMs, nodeId);
397
+ // Stop tracking so as to clear out any running timers.
398
+ nodeStateTracker.stopTracking();
399
+ // Delete the node as we don't need to track it any more.
400
+ this.unreferencedNodesState.delete(nodeId);
401
+ }
402
+ }
403
+ }
404
+ /**
405
+ * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in
406
+ * time. It's possible that nodes transition from `unreferenced -> referenced -> unreferenced` between two runs. The
407
+ * unreferenced timestamp of such nodes needs to be reset as they may have been accessed when they were referenced.
408
+ *
409
+ * This function identifies nodes that were referenced since last run and removes their unreferenced state, if any.
410
+ * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.
411
+ */
412
+ updateStateSinceLatestRun(currentGCData) {
413
+ // If we haven't run GC before or no references were added since the last run, there is nothing to do.
414
+ if (this.gcDataFromLastRun === undefined || this.referencesSinceLastRun.size === 0) {
415
+ return;
416
+ }
417
+ /**
418
+ * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and
419
+ * edges that have been added since then. To do this, combine the GC data from the last run and the current
420
+ * run, and then add the references since last run.
421
+ *
422
+ * Note on why we need to combine the data from previous run, current run and all references in between -
423
+ * 1. We need data from last run because some of its references may have been deleted since then. If those
424
+ * references added new outbound references before getting deleted, we need to detect them.
425
+ * 2. We need new outbound references since last run because some of them may have been deleted later. If those
426
+ * references added new outbound references before getting deleted, we need to detect them.
427
+ * 3. We need data from the current run because currently we may not detect when DDSs are referenced:
428
+ * - We don't require DDSs handles to be stored in a referenced DDS. For this, we need GC at DDS level
429
+ * which is tracked by https://github.com/microsoft/FluidFramework/issues/8470.
430
+ * - A new data store may have "root" DDSs already created and we don't detect them today.
431
+ */
432
+ const gcDataSuperSet = garbage_collector_1.concatGarbageCollectionData(this.gcDataFromLastRun, currentGCData);
433
+ this.referencesSinceLastRun.forEach((outboundRoutes, sourceNodeId) => {
434
+ if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {
435
+ gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;
436
+ }
437
+ else {
438
+ gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);
439
+ }
440
+ });
441
+ /**
442
+ * Run GC on the above reference graph to find all nodes that are referenced. For each one, if they are
443
+ * unreferenced, stop tracking them and remove from unreferenced list.
444
+ * Some of these nodes may be unreferenced now and if so, the current run will add unreferenced state for them.
445
+ */
446
+ const gcResult = garbage_collector_1.runGarbageCollection(gcDataSuperSet.gcNodes, ["/"], this.mc.logger);
447
+ for (const nodeId of gcResult.referencedNodeIds) {
448
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
449
+ if (nodeStateTracker !== undefined) {
372
450
  // Stop tracking so as to clear out any running timers.
373
451
  nodeStateTracker.stopTracking();
374
452
  // Delete the node as we don't need to track it any more.
@@ -1 +1 @@
1
- {"version":3,"file":"garbageCollection.js","sourceRoot":"","sources":["../src/garbageCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA0E;AAC1E,yEAK2C;AAE3C,6EAO6C;AAC7C,iEAIuC;AACvC,qEAAgF;AAGhF,6CAAuD;AACvD,yEAAwE;AACxE,mDAOyB;AAEzB,yDAAyD;AACzD,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB,sCAAsC;AACzB,QAAA,SAAS,GAAG,IAAI,CAAC;AAC9B,sDAAsD;AACzC,QAAA,YAAY,GAAG,MAAM,CAAC;AAEnC,yCAAyC;AACzC,MAAM,QAAQ,GAAG,YAAY,CAAC;AAC9B,mDAAmD;AACnD,MAAM,aAAa,GAAG,iBAAiB,CAAC;AACxC,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,CAC1B,IAAI,CAAC,MAAM,EACX,uBAAuB,EACvB,kBAAkB,EAClB,IAAI,CAAC,eAAe,EACpB,MAAM,CACT,CAAC;gBACF,uDAAuD;gBACvD,gBAAgB,CAAC,YAAY,EAAE,CAAC;gBAChC,yDAAyD;gBACzD,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;aAC9C;SACJ;IACL,CAAC;CACJ;AAlcD,4CAkcC;AAED;;;EAGE;AACF,KAAK,UAAU,sBAAsB,CACjC,cAA6B,EAC7B,gBAAkC;IAElC,IAAI,WAAW,GAA4B,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC3D,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;QACjD,oDAAoD;QACpD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,oBAAY,CAAC,EAAE;YAC/B,SAAS;SACZ;QAED,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,MAAM,KAAK,SAAS,EAAE;YACtB,SAAS;SACZ;QACD,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAA0B,MAAM,CAAC,CAAC;QACxE,qBAAM,CAAC,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC3E,0DAA0D;QAC1D,WAAW,GAAG,iDAA6B,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;KACrE;IACD,OAAO,WAAW,CAAC;AACvB,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 {\n concatGarbageCollectionStates,\n unpackChildNodesGCDetails,\n IGCResult,\n runGarbageCollection,\n} from \"@fluidframework/garbage-collector\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n gcBlobKey,\n IGarbageCollectionData,\n IGarbageCollectionNodeData,\n IGarbageCollectionState,\n IGarbageCollectionSummaryDetails,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ReadAndParseBlob,\n RefreshSummaryResult,\n SummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\n\nimport { IGCRuntimeOptions } from \"./containerRuntime\";\nimport { getSummaryForDatastores } from \"./dataStores\";\nimport { getLocalStorageFeatureGate } from \"./localStorageFeatureGates\";\nimport {\n getGCVersion,\n GCVersion,\n IContainerRuntimeMetadata,\n metadataBlobName,\n ReadFluidDataStoreAttributes,\n dataStoreAttributesBlobName,\n} from \"./summaryFormat\";\n\n/** This is the current version of garbage collection. */\nconst GCVersion = 1;\n\n// The key for the GC tree in summary.\nexport const gcTreeKey = \"gc\";\n// They prefix for GC blobs in the GC tree in summary.\nexport const gcBlobPrefix = \"__gc\";\n\n// Local storage key to turn GC on / off.\nconst runGCKey = \"FluidRunGC\";\n// Local storage key to turn GC test mode on / off.\nconst gcTestModeKey = \"FluidGCTestMode\";\n// Local storage key to turn GC sweep on / off.\nconst runSweepKey = \"FluidRunSweep\";\n\nconst defaultDeleteTimeoutMs = 7 * 24 * 60 * 60 * 1000; // 7 days\n\n/** The used state statistics of a node. */\nexport interface IUsedStateStats {\n totalNodeCount: number;\n unusedNodeCount: number;\n}\n\n/** The statistics of the system state after a garbage collection run. */\nexport interface IGCStats {\n totalNodes: number;\n deletedNodes: number;\n totalDataStores: number;\n deletedDataStores: number;\n}\n\n/** Defines the APIs for the runtime object to be passed to the garbage collector. */\nexport interface IGarbageCollectionRuntime {\n /** Returns the garbage collection data of the runtime. */\n getGCData(fullGC?: boolean): Promise<IGarbageCollectionData>;\n /** After GC has run, called to notify the runtime of routes that are used in it. */\n updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number): IUsedStateStats;\n}\n\n/** Defines the contract for the garbage collector. */\nexport interface IGarbageCollector {\n /** Tells whether GC should run or not. */\n readonly shouldRunGC: boolean;\n /**\n * This tracks two things:\n * 1. Whether GC is enabled - If this is 0, GC is disabled. If this is greater than 0, GC is enabled.\n * 2. If GC is enabled, the version of GC used to generate the GC data written in a summary.\n */\n readonly gcSummaryFeatureVersion: number;\n /** Tells whether the GC version has changed compared to the version in the latest summary. */\n readonly hasGCVersionChanged: boolean;\n /** Tells whether GC data should be written to the root of the summary tree. */\n readonly writeDataAtRoot: boolean;\n /** Run garbage collection and update the reference / used state of the system. */\n collectGarbage(\n options: { logger?: ITelemetryLogger, runGC?: boolean, runSweep?: boolean, fullGC?: boolean },\n ): Promise<IGCStats>;\n /** Summarizes the GC data and returns it as a summary tree. */\n summarize(): ISummaryTreeWithStats | undefined;\n /** Returns a map of each data store id to its GC details in the base summary. */\n getDataStoreBaseGCDetails(): Promise<Map<string, IGarbageCollectionSummaryDetails>>;\n /** Called when the latest summary of the system has been refreshed. */\n latestSummaryStateRefreshed(result: RefreshSummaryResult, readAndParseBlob: ReadAndParseBlob): Promise<void>;\n /** Called when a node is changed. Used to detect and log when an inactive node is changed. */\n nodeChanged(id: string): void;\n}\n\n/**\n * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced. It also sets\n * the node's state to inactive if it remains unreferenced for a given amount of time (inactiveTimeoutMs).\n */\nclass UnreferencedStateTracker {\n private inactive: boolean = false;\n // Keeps track of all inactive events that are logged. This is used to limit the log generation for each event to 1\n // so that it is not noisy.\n private readonly inactiveEventsLogged: Set<string> = new Set();\n private readonly timer: Timer | undefined;\n\n constructor(\n public readonly unreferencedTimestampMs: number,\n inactiveTimeoutMs: number,\n ) {\n // If the timeout has already expired, the node should become inactive immediately. Otherwise, start a timer of\n // inactiveTimeoutMs after which the node will become inactive.\n if (inactiveTimeoutMs <= 0) {\n this.inactive = true;\n } else {\n this.timer = new Timer(inactiveTimeoutMs, () => { this.inactive = true; });\n this.timer.start();\n }\n }\n\n /** Stop tracking this node. Reset the unreferenced timer, if any, and reset inactive state. */\n public stopTracking() {\n this.timer?.clear();\n this.inactive = false;\n }\n\n /** Logs an error with the given properties if the node is inactive. */\n public logIfInactive(\n logger: ITelemetryLogger,\n eventName: string,\n currentTimestampMs: number,\n deleteTimeoutMs: number,\n inactiveNodeId: string,\n ) {\n if (this.inactive && !this.inactiveEventsLogged.has(eventName)) {\n logger.sendErrorEvent({\n eventName,\n unreferencedDuratonMs: currentTimestampMs - this.unreferencedTimestampMs,\n deleteTimeoutMs,\n inactiveNodeId,\n });\n this.inactiveEventsLogged.add(eventName);\n }\n }\n}\n\n/**\n * The garbage collector for the container runtime. It consolidates the garbage collection functionality and maintains\n * its state across summaries.\n */\nexport class GarbageCollector implements IGarbageCollector {\n public static create(\n provider: IGarbageCollectionRuntime,\n gcOptions: IGCRuntimeOptions,\n deleteUnusedRoutes: (unusedRoutes: string[]) => void,\n getCurrentTimestampMs: () => number,\n baseSnapshot: ISnapshotTree | undefined,\n readAndParseBlob: ReadAndParseBlob,\n baseLogger: ITelemetryLogger,\n existing: boolean,\n metadata?: IContainerRuntimeMetadata,\n ): IGarbageCollector {\n return new GarbageCollector(\n provider,\n gcOptions,\n deleteUnusedRoutes,\n getCurrentTimestampMs,\n baseSnapshot,\n readAndParseBlob,\n baseLogger,\n existing,\n metadata,\n );\n }\n\n /**\n * Tells whether GC should be run based on the GC options and local storage flags.\n */\n public readonly shouldRunGC: boolean;\n\n /**\n * This tracks two things:\n * 1. Whether GC is enabled - If this is 0, GC is disabled. If this is greater than 0, GC is enabled.\n * 2. If GC is enabled, the version of GC used to generate the GC data written in a summary.\n */\n public get gcSummaryFeatureVersion(): number {\n return this.gcEnabled ? this.currentGCVersion : 0;\n }\n\n /**\n * Tells whether the GC version has changed compared to the version in the latest summary.\n */\n public get hasGCVersionChanged(): boolean {\n // The current version can differ from the latest summary version in two cases:\n // 1. The summary this client loaded with has data from a different GC version.\n // 2. This client's latest summary was updated from a snapshot that has a different GC version.\n return this.shouldRunGC && this.latestSummaryGCVersion !== this.currentGCVersion;\n }\n\n /**\n * Tracks if GC is enabled for this document. This is specified during document creation and doesn't change\n * throughout its lifetime.\n */\n private readonly gcEnabled: boolean;\n private readonly shouldRunSweep: boolean;\n private readonly testMode: boolean;\n private readonly logger: ITelemetryLogger;\n\n /**\n * Tells whether the GC data should be written to the root of the summary tree. We do this under 2 conditions:\n * 1. If `writeDataAtRoot` GC option is enabled.\n * 2. If the base summary has the GC data written at the root. This is to support forward compatibility where when\n * we start writing the GC data at root, older versions can detect that and write at root too.\n */\n private _writeDataAtRoot: boolean = false;\n public get writeDataAtRoot(): boolean {\n return this._writeDataAtRoot;\n }\n\n // The current GC version that this container is running.\n private readonly currentGCVersion = GCVersion;\n // This is the version of GC data in the latest summary being tracked.\n private latestSummaryGCVersion: GCVersion;\n\n // The current state - each node's GC data and unreferenced timestamp.\n private currentGCState: IGarbageCollectionState | undefined;\n\n // Promise when resolved initializes the base state of the nodes from the base summary state.\n private readonly initializeBaseStateP: Promise<void>;\n // The map of data store ids to their GC details in the base summary returned in getDataStoreGCDetails().\n private readonly dataStoreGCDetailsP: Promise<Map<string, IGarbageCollectionSummaryDetails>>;\n // The time after which an unreferenced node can be deleted. Currently, we only set the node's state to expired.\n private readonly deleteTimeoutMs: number;\n // Map of node ids to their unreferenced state tracker.\n private readonly unreferencedNodesState: Map<string, UnreferencedStateTracker> = new Map();\n\n protected constructor(\n private readonly provider: IGarbageCollectionRuntime,\n private readonly gcOptions: IGCRuntimeOptions,\n /** After GC has run, called to delete objects in the runtime whose routes are unused. */\n private readonly deleteUnusedRoutes: (unusedRoutes: string[]) => void,\n /** Returns the current timestamp to be assigned to nodes that become unreferenced. */\n private readonly getCurrentTimestampMs: () => number,\n baseSnapshot: ISnapshotTree | undefined,\n readAndParseBlob: ReadAndParseBlob,\n baseLogger: ITelemetryLogger,\n existing: boolean,\n metadata?: IContainerRuntimeMetadata,\n ) {\n this.logger = ChildLogger.create(baseLogger, \"GarbageCollector\");\n\n this.deleteTimeoutMs = this.gcOptions.deleteTimeoutMs ?? defaultDeleteTimeoutMs;\n\n let prevSummaryGCVersion: number | undefined;\n // GC can only be enabled during creation. After that, it can never be enabled again. So, for existing\n // documents, we get this information from the metadata blob.\n if (existing) {\n prevSummaryGCVersion = getGCVersion(metadata);\n // Existing documents which did not have metadata blob or had GC disabled have version as 0. For all\n // other exsiting documents, GC is enabled.\n this.gcEnabled = prevSummaryGCVersion > 0;\n } else {\n // For new documents, GC has to be exlicitly enabled via the gcAllowed flag in GC options.\n this.gcEnabled = gcOptions.gcAllowed === true;\n }\n // For existing document, the latest summary is the one that we loaded from. So, use its GC version as the\n // latest tracked GC version. For new documents, we will be writing the first summary with the current version.\n this.latestSummaryGCVersion = prevSummaryGCVersion ?? this.currentGCVersion;\n\n // Whether GC should run or not. Can override with localStorage flag.\n this.shouldRunGC = getLocalStorageFeatureGate(runGCKey) ?? (\n // GC must be enabled for the document.\n this.gcEnabled\n // GC must not be disabled via GC options.\n && !gcOptions.disableGC\n );\n\n // Whether GC sweep phase should run or not. If this is false, only GC mark phase is run. Can override with\n // localStorage flag.\n this.shouldRunSweep = this.shouldRunGC &&\n (getLocalStorageFeatureGate(runSweepKey) ?? gcOptions.runSweep === true);\n\n // Whether we are running in test mode. In this mode, unreferenced nodes are immediately deleted.\n this.testMode = getLocalStorageFeatureGate(gcTestModeKey) ?? gcOptions.runGCInTestMode === true;\n\n // If `writeDataAtRoot` GC option is true, we should write the GC data into the root of the summary tree. This\n // GC option is used for testing only. It will be removed once we start writing GC data into root by default.\n this._writeDataAtRoot = this.gcOptions.writeDataAtRoot === true;\n\n // Get the GC state from the GC blob in the base snapshot. Use LazyPromise because we only want to do\n // this once since it involves fetching blobs from storage which is expensive.\n const baseSummaryStateP = new LazyPromise<IGarbageCollectionState>(async () => {\n if (baseSnapshot === undefined) {\n return { gcNodes: {} };\n }\n\n // For newer documents, GC data should be present in the GC tree in the root of the snapshot.\n const gcSnapshotTree = baseSnapshot.trees[gcTreeKey];\n if (gcSnapshotTree !== undefined) {\n // forward-compat - If a newer version has written the GC tree at root, we should also do the same.\n this._writeDataAtRoot = true;\n return getGCStateFromSnapshot(gcSnapshotTree, readAndParseBlob);\n }\n\n // back-compat - Older documents will have the GC blobs in each data store's summary tree. Get them and\n // consolidate into IGarbageCollectionState format.\n const gcState: IGarbageCollectionState = { gcNodes: { \"/\": { outboundRoutes: [] } } };\n const dataStoreSnaphotTree = getSummaryForDatastores(baseSnapshot, metadata);\n assert(dataStoreSnaphotTree !== undefined,\n 0x2a8 /* \"Expected data store snapshot tree in base snapshot\" */);\n for (const [dsId, dsSnapshotTree] of Object.entries(dataStoreSnaphotTree.trees)) {\n const blobId = dsSnapshotTree.blobs[gcBlobKey];\n if (blobId === undefined) {\n continue;\n }\n\n const gcSummaryDetails = await readAndParseBlob<IGarbageCollectionSummaryDetails>(blobId);\n // If there are no nodes for this data store, skip it.\n if (gcSummaryDetails.gcData?.gcNodes === undefined) {\n continue;\n }\n\n const dsRootId = `/${dsId}`;\n // Since we used to write GC data at data store level, we won't have an entry for the root (\"/\").\n // Construct that entry by adding root data store ids to its outbound routes.\n const initialSnapshotDetails = await readAndParseBlob<ReadFluidDataStoreAttributes>(\n dsSnapshotTree.blobs[dataStoreAttributesBlobName],\n );\n if (initialSnapshotDetails.isRootDataStore) {\n gcState.gcNodes[\"/\"].outboundRoutes.push(dsRootId);\n }\n\n for (const [id, outboundRoutes] of Object.entries(gcSummaryDetails.gcData.gcNodes)) {\n // Prefix the data store id to the GC node ids to make them relative to the root from being\n // relative to the data store. Similar to how its done in DataStore::getGCData.\n const rootId = id === \"/\" ? dsRootId : `${dsRootId}${id}`;\n gcState.gcNodes[rootId] = { outboundRoutes: Array.from(outboundRoutes) };\n }\n assert(gcState.gcNodes[dsRootId] !== undefined,\n 0x2a9 /* `GC nodes for data store ${dsId} not in GC blob` */);\n gcState.gcNodes[dsRootId].unreferencedTimestampMs = gcSummaryDetails.unrefTimestamp;\n }\n return gcState;\n });\n\n // Set up the initializer which initializes the base GC state from the base snapshot. Use lazy promise because\n // we only do this once - the very first time we run GC.\n this.initializeBaseStateP = new LazyPromise<void>(async () => {\n const baseState = await baseSummaryStateP;\n\n const gcNodes: { [ id: string ]: IGarbageCollectionNodeData } = {};\n // Set up tracking for the nodes in the base summary state and add them to GC nodes.\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n const unreferencedTimestampMs = nodeData.unreferencedTimestampMs;\n if (unreferencedTimestampMs !== undefined) {\n // Get how long it has been since the node was unreferenced. Start a timeout for the remaining time\n // left for it to be eligible for deletion.\n const unreferencedDurationMs = this.getCurrentTimestampMs() - unreferencedTimestampMs;\n this.unreferencedNodesState.set(\n nodeId,\n new UnreferencedStateTracker(\n unreferencedTimestampMs,\n this.deleteTimeoutMs - unreferencedDurationMs,\n ),\n );\n }\n\n gcNodes[nodeId] = {\n outboundRoutes: Array.from(nodeData.outboundRoutes),\n unreferencedTimestampMs,\n };\n }\n this.currentGCState = { gcNodes };\n });\n\n // Get the GC details for each data store from the GC state in the base summary. This is returned in\n // getDataStoreBaseGCDetails and is used to initialize each data store's base GC details.\n this.dataStoreGCDetailsP = new LazyPromise<Map<string, IGarbageCollectionSummaryDetails>>(async () => {\n const gcNodes: { [ id: string ]: string[] } = {};\n const baseState = await baseSummaryStateP;\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);\n }\n // Run GC on the nodes in the base summary to get the routes used in each node in the container.\n // This is an optimization for space (vs performance) wherein we don't need to store the used routes of\n // each node in the summary.\n const usedRoutes = runGarbageCollection(\n gcNodes,\n [ \"/\" ],\n this.logger,\n ).referencedNodeIds;\n\n const dataStoreGCDetailsMap = unpackChildNodesGCDetails({ gcData: { gcNodes }, usedRoutes });\n // Currently, the data stores write the GC data. So, we need to update it's base GC details with the\n // unreferenced timestamp. Once we start writing the GC data here, we won't need to do this anymore.\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n if (nodeData.unreferencedTimestampMs !== undefined) {\n const dataStoreGCDetails = dataStoreGCDetailsMap.get(nodeId.slice(1));\n if (dataStoreGCDetails !== undefined) {\n dataStoreGCDetails.unrefTimestamp = nodeData.unreferencedTimestampMs;\n }\n }\n }\n return dataStoreGCDetailsMap;\n });\n }\n\n /**\n * Runs garbage collection and udpates the reference / used state of the nodes in the container.\n * @returns the number of data stores that have been marked as unreferenced.\n */\n public async collectGarbage(\n options: {\n /** Logger to use for logging GC events */\n logger?: ITelemetryLogger,\n /** True to run GC sweep phase after the mark phase */\n runSweep?: boolean,\n /** True to generate full GC data */\n fullGC?: boolean,\n },\n ): Promise<IGCStats> {\n const {\n logger = this.logger,\n runSweep = this.shouldRunSweep,\n fullGC = this.gcOptions.runFullGC === true || this.hasGCVersionChanged,\n } = options;\n\n return PerformanceEvent.timedExecAsync(logger, { eventName: \"GarbageCollection\" }, async (event) => {\n await this.initializeBaseStateP;\n\n const gcStats: {\n deletedNodes?: number,\n totalNodes?: number,\n deletedDataStores?: number,\n totalDataStores?: number,\n } = {};\n\n // Get the runtime's GC data and run GC on the reference graph in it.\n const gcData = await this.provider.getGCData(fullGC);\n const gcResult = runGarbageCollection(\n gcData.gcNodes,\n [ \"/\" ],\n logger,\n );\n\n const currentTimestampMs = this.getCurrentTimestampMs();\n // Update the current state of the system based on the GC run.\n this.updateCurrentState(gcData, gcResult, currentTimestampMs);\n\n const dataStoreUsedStateStats =\n this.provider.updateUsedRoutes(gcResult.referencedNodeIds, currentTimestampMs);\n\n if (runSweep) {\n // Placeholder for running sweep logic.\n }\n\n // Update stats to be reported in the peformance event.\n gcStats.deletedNodes = gcResult.deletedNodeIds.length;\n gcStats.totalNodes = gcResult.referencedNodeIds.length + gcResult.deletedNodeIds.length;\n gcStats.deletedDataStores = dataStoreUsedStateStats.unusedNodeCount;\n gcStats.totalDataStores = dataStoreUsedStateStats.totalNodeCount;\n\n // If we are running in GC test mode, delete objects for unused routes. This enables testing scenarios\n // involving access to deleted data.\n if (this.testMode) {\n this.deleteUnusedRoutes(gcResult.deletedNodeIds);\n }\n event.end(gcStats);\n return gcStats as IGCStats;\n },\n { end: true, cancel: \"error\" });\n }\n\n /**\n * Summarizes the GC data and returns it as a summary tree.\n * We current write the entire GC state in a single blob. This can be modified later to write multiple\n * blobs. All the blob keys should start with `gcBlobPrefix`.\n */\n public summarize(): ISummaryTreeWithStats | undefined {\n if (!this.shouldRunGC || this.currentGCState === undefined) {\n return;\n }\n\n const builder = new SummaryTreeBuilder();\n builder.addBlob(`${gcBlobPrefix}_root`, JSON.stringify(this.currentGCState));\n return builder.getSummaryTree();\n }\n\n /**\n * Returns a map of data store ids to their base GC details generated from the base summary.This is used to\n * initialize the data stores with their base GC state.\n */\n public async getDataStoreBaseGCDetails(): Promise<Map<string, IGarbageCollectionSummaryDetails>> {\n return this.dataStoreGCDetailsP;\n }\n\n /**\n * Called when the latest summary of the system has been refreshed. This will be used to update the state of the\n * latest summary tracked.\n */\n public async latestSummaryStateRefreshed(\n result: RefreshSummaryResult,\n readAndParseBlob: ReadAndParseBlob,\n ): Promise<void> {\n if (!this.shouldRunGC || !result.latestSummaryUpdated) {\n return;\n }\n\n // If the summary was tracked by this client, it was the one that generated the summary in the first place.\n // Basically, it was written in the current GC version.\n if (result.wasSummaryTracked) {\n this.latestSummaryGCVersion = this.currentGCVersion;\n return;\n }\n // If the summary was not tracked by this client, update latest GC version from the snapshot in the result as\n // that is now the latest summary.\n await this.updateSummaryGCVersionFromSnapshot(result.snapshot, readAndParseBlob);\n }\n\n /**\n * Called when a node with the given id is changed. If the node is inactive, log an error.\n */\n public nodeChanged(id: string) {\n // Prefix \"/\" if needed to make it relative to the root.\n const nodeId = id.startsWith(\"/\") ? id : `/${id}`;\n this.unreferencedNodesState.get(nodeId)?.logIfInactive(\n this.logger,\n \"inactiveObjectChanged\",\n this.getCurrentTimestampMs(),\n this.deleteTimeoutMs,\n nodeId,\n );\n }\n\n /**\n * Update the latest summary GC version from the metadata blob in the given snapshot.\n */\n private async updateSummaryGCVersionFromSnapshot(snapshot: ISnapshotTree, readAndParseBlob: ReadAndParseBlob) {\n const metadataBlobId = snapshot.blobs[metadataBlobName];\n if (metadataBlobId) {\n const metadata = await readAndParseBlob<IContainerRuntimeMetadata>(metadataBlobId);\n this.latestSummaryGCVersion = getGCVersion(metadata);\n }\n }\n\n /**\n * Updates the state of the system as per the current GC run. It does the following:\n * 1. Sets up the current GC state as per the gcData.\n * 2. Starts tracking for nodes that have become unreferenced in this run.\n * 3. Clears tracking for nodes that were unreferenced but became referenced in this run.\n * @param gcData - The data representing the reference graph on which GC is run.\n * @param gcResult - The result of the GC run on the gcData.\n * @param currentTimestampMs - The current timestamp to be used for unreferenced nodes' timestamp.\n */\n private updateCurrentState(gcData: IGarbageCollectionData, gcResult: IGCResult, currentTimestampMs: number) {\n this.currentGCState = { gcNodes: {} };\n for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {\n this.currentGCState.gcNodes[id] = { outboundRoutes: Array.from(outboundRoutes) };\n }\n\n // Iterate through the deleted nodes and start tracking if they became unreferenced in this run.\n for (const nodeId of gcResult.deletedNodeIds) {\n assert(this.currentGCState.gcNodes[nodeId] !== undefined, 0x2aa /* \"Unexpected node when running GC\" */);\n\n // The time when the node became unreferenced. This is added to the current GC state.\n let unreferencedTimestampMs: number = currentTimestampMs;\n const nodeStateTracker = this.unreferencedNodesState.get(nodeId);\n if (nodeStateTracker !== undefined) {\n unreferencedTimestampMs = nodeStateTracker.unreferencedTimestampMs;\n } else {\n // Start tracking this node as it became unreferenced in this run.\n this.unreferencedNodesState.set(\n nodeId,\n new UnreferencedStateTracker(unreferencedTimestampMs, this.deleteTimeoutMs),\n );\n }\n this.currentGCState.gcNodes[nodeId].unreferencedTimestampMs = unreferencedTimestampMs;\n }\n\n // Iterate through the referenced nodes and stop tracking if they were unreferenced before.\n for (const nodeId of gcResult.referencedNodeIds) {\n assert(this.currentGCState.gcNodes[nodeId] !== undefined, 0x2ab /* \"Unexpected node when running GC\" */);\n const nodeStateTracker = this.unreferencedNodesState.get(nodeId);\n if (nodeStateTracker !== undefined) {\n // If this node has been unreferenced for longer than deleteTimeoutMs and is being referenced,\n // log an error as this may mean the deleteTimeoutMs is not long enough.\n nodeStateTracker.logIfInactive(\n this.logger,\n \"inactiveObjectRevived\",\n currentTimestampMs,\n this.deleteTimeoutMs,\n nodeId,\n );\n // Stop tracking so as to clear out any running timers.\n nodeStateTracker.stopTracking();\n // Delete the node as we don't need to track it any more.\n this.unreferencedNodesState.delete(nodeId);\n }\n }\n }\n}\n\n/**\n * Gets the garbage collection state from the given snapshot tree. The GC state may be written into multiple blobs.\n * Merge the GC state from all such blobs and return the merged GC state.\n*/\nasync function getGCStateFromSnapshot(\n gcSnapshotTree: ISnapshotTree,\n readAndParseBlob: ReadAndParseBlob,\n): Promise<IGarbageCollectionState> {\n let rootGCState: IGarbageCollectionState = { gcNodes: {} };\n for (const key of Object.keys(gcSnapshotTree.blobs)) {\n // Skip blobs that do not stsart with the GC prefix.\n if (!key.startsWith(gcBlobPrefix)) {\n continue;\n }\n\n const blobId = gcSnapshotTree.blobs[key];\n if (blobId === undefined) {\n continue;\n }\n const gcState = await readAndParseBlob<IGarbageCollectionState>(blobId);\n assert(gcState !== undefined, 0x2ad /* \"GC blob missing from snapshot\" */);\n // Merge the GC state of this blob into the root GC state.\n rootGCState = concatGarbageCollectionStates(rootGCState, gcState);\n }\n return rootGCState;\n}\n"]}
1
+ {"version":3,"file":"garbageCollection.js","sourceRoot":"","sources":["../src/garbageCollection.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+DAA0E;AAC1E,yEAO2C;AAE3C,6EAM6C;AAC7C,iEAIuC;AACvC,qEAK0C;AAG1C,6CAAuD;AACvD,mDAOyB;AAEzB,yDAAyD;AACzD,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB,sCAAsC;AACzB,QAAA,SAAS,G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KAAK,CAAC,EAAE;QACjD,oDAAoD;QACpD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,oBAAY,CAAC,EAAE;YAC/B,SAAS;SACZ;QAED,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,MAAM,KAAK,SAAS,EAAE;YACtB,SAAS;SACZ;QACD,MAAM,OAAO,GAAG,MAAM,gBAAgB,CAA0B,MAAM,CAAC,CAAC;QACxE,qBAAM,CAAC,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC3E,0DAA0D;QAC1D,WAAW,GAAG,iDAA6B,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;KACrE;IACD,OAAO,WAAW,CAAC;AACvB,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 {\n cloneGCData,\n concatGarbageCollectionStates,\n concatGarbageCollectionData,\n IGCResult,\n runGarbageCollection,\n unpackChildNodesGCDetails,\n} from \"@fluidframework/garbage-collector\";\nimport { ISnapshotTree } from \"@fluidframework/protocol-definitions\";\nimport {\n gcBlobKey,\n IGarbageCollectionData,\n IGarbageCollectionState,\n IGarbageCollectionSummaryDetails,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ReadAndParseBlob,\n RefreshSummaryResult,\n SummaryTreeBuilder,\n} from \"@fluidframework/runtime-utils\";\nimport {\n ChildLogger,\n loggerToMonitoringContext,\n MonitoringContext,\n PerformanceEvent,\n } from \"@fluidframework/telemetry-utils\";\n\nimport { IGCRuntimeOptions } from \"./containerRuntime\";\nimport { getSummaryForDatastores } from \"./dataStores\";\nimport {\n getGCVersion,\n GCVersion,\n IContainerRuntimeMetadata,\n metadataBlobName,\n ReadFluidDataStoreAttributes,\n dataStoreAttributesBlobName,\n} from \"./summaryFormat\";\n\n/** This is the current version of garbage collection. */\nconst GCVersion = 1;\n\n// The key for the GC tree in summary.\nexport const gcTreeKey = \"gc\";\n// They prefix for GC blobs in the GC tree in summary.\nexport const gcBlobPrefix = \"__gc\";\n\n// Local storage key to turn GC on / off.\nconst runGCKey = \"Fluid.GarbageCollection.RunGC\";\n// Local storage key to turn GC test mode on / off.\nconst gcTestModeKey = \"Fluid.GarbageCollection.GCTestMode\";\n// Local storage key to turn GC sweep on / off.\nconst runSweepKey = \"Fluid.GarbageCollection.RunSweep\";\n\nconst defaultDeleteTimeoutMs = 7 * 24 * 60 * 60 * 1000; // 7 days\n\n/** The used state statistics of a node. */\nexport interface IUsedStateStats {\n totalNodeCount: number;\n unusedNodeCount: number;\n}\n\n/** The statistics of the system state after a garbage collection run. */\nexport interface IGCStats {\n totalNodes: number;\n deletedNodes: number;\n totalDataStores: number;\n deletedDataStores: number;\n}\n\n/** Defines the APIs for the runtime object to be passed to the garbage collector. */\nexport interface IGarbageCollectionRuntime {\n /** Returns the garbage collection data of the runtime. */\n getGCData(fullGC?: boolean): Promise<IGarbageCollectionData>;\n /** After GC has run, called to notify the runtime of routes that are used in it. */\n updateUsedRoutes(usedRoutes: string[], gcTimestamp?: number): IUsedStateStats;\n}\n\n/** Defines the contract for the garbage collector. */\nexport interface IGarbageCollector {\n /** Tells whether GC should run or not. */\n readonly shouldRunGC: boolean;\n /**\n * This tracks two things:\n * 1. Whether GC is enabled - If this is 0, GC is disabled. If this is greater than 0, GC is enabled.\n * 2. If GC is enabled, the version of GC used to generate the GC data written in a summary.\n */\n readonly gcSummaryFeatureVersion: number;\n /** Tells whether the GC version has changed compared to the version in the latest summary. */\n readonly hasGCVersionChanged: boolean;\n /** Tells whether GC data should be written to the root of the summary tree. */\n readonly writeDataAtRoot: boolean;\n /** Run garbage collection and update the reference / used state of the system. */\n collectGarbage(\n options: { logger?: ITelemetryLogger, runGC?: boolean, runSweep?: boolean, fullGC?: boolean },\n ): Promise<IGCStats>;\n /** Summarizes the GC data and returns it as a summary tree. */\n summarize(): ISummaryTreeWithStats | undefined;\n /** Returns a map of each data store id to its GC details in the base summary. */\n getDataStoreBaseGCDetails(): Promise<Map<string, IGarbageCollectionSummaryDetails>>;\n /** Called when the latest summary of the system has been refreshed. */\n latestSummaryStateRefreshed(result: RefreshSummaryResult, readAndParseBlob: ReadAndParseBlob): Promise<void>;\n /** Called when a node is changed. Used to detect and log when an inactive node is changed. */\n nodeChanged(id: string): void;\n /** Called when a reference is added to a node. Used to identify nodes that were referenced between summaries. */\n addedOutboundReference(fromNodeId: string, toNodeId: string): void;\n}\n\n/**\n * Helper class that tracks the state of an unreferenced node such as the time it was unreferenced. It also sets\n * the node's state to inactive if it remains unreferenced for a given amount of time (inactiveTimeoutMs).\n */\nclass UnreferencedStateTracker {\n private inactive: boolean = false;\n // Keeps track of all inactive events that are logged. This is used to limit the log generation for each event to 1\n // so that it is not noisy.\n private readonly inactiveEventsLogged: Set<string> = new Set();\n private readonly timer: Timer | undefined;\n\n constructor(\n public readonly unreferencedTimestampMs: number,\n inactiveTimeoutMs: number,\n ) {\n // If the timeout has already expired, the node should become inactive immediately. Otherwise, start a timer of\n // inactiveTimeoutMs after which the node will become inactive.\n if (inactiveTimeoutMs <= 0) {\n this.inactive = true;\n } else {\n this.timer = new Timer(inactiveTimeoutMs, () => { this.inactive = true; });\n this.timer.start();\n }\n }\n\n /** Stop tracking this node. Reset the unreferenced timer, if any, and reset inactive state. */\n public stopTracking() {\n this.timer?.clear();\n this.inactive = false;\n }\n\n /** Logs an error with the given properties if the node is inactive. */\n public logIfInactive(\n logger: ITelemetryLogger,\n eventName: string,\n currentTimestampMs: number,\n deleteTimeoutMs: number,\n inactiveNodeId: string,\n ) {\n if (this.inactive && !this.inactiveEventsLogged.has(eventName)) {\n logger.sendErrorEvent({\n eventName,\n age: currentTimestampMs - this.unreferencedTimestampMs,\n timeout: deleteTimeoutMs,\n id: inactiveNodeId,\n });\n this.inactiveEventsLogged.add(eventName);\n }\n }\n}\n\n/**\n * The garbage collector for the container runtime. It consolidates the garbage collection functionality and maintains\n * its state across summaries.\n */\nexport class GarbageCollector implements IGarbageCollector {\n public static create(\n provider: IGarbageCollectionRuntime,\n gcOptions: IGCRuntimeOptions,\n deleteUnusedRoutes: (unusedRoutes: string[]) => void,\n getCurrentTimestampMs: () => number,\n baseSnapshot: ISnapshotTree | undefined,\n readAndParseBlob: ReadAndParseBlob,\n baseLogger: ITelemetryLogger,\n existing: boolean,\n metadata?: IContainerRuntimeMetadata,\n ): IGarbageCollector {\n return new GarbageCollector(\n provider,\n gcOptions,\n deleteUnusedRoutes,\n getCurrentTimestampMs,\n baseSnapshot,\n readAndParseBlob,\n baseLogger,\n existing,\n metadata,\n );\n }\n\n /**\n * Tells whether GC should be run based on the GC options and local storage flags.\n */\n public readonly shouldRunGC: boolean;\n\n /**\n * This tracks two things:\n * 1. Whether GC is enabled - If this is 0, GC is disabled. If this is greater than 0, GC is enabled.\n * 2. If GC is enabled, the version of GC used to generate the GC data written in a summary.\n */\n public get gcSummaryFeatureVersion(): number {\n return this.gcEnabled ? this.currentGCVersion : 0;\n }\n\n /**\n * Tells whether the GC version has changed compared to the version in the latest summary.\n */\n public get hasGCVersionChanged(): boolean {\n // The current version can differ from the latest summary version in two cases:\n // 1. The summary this client loaded with has data from a different GC version.\n // 2. This client's latest summary was updated from a snapshot that has a different GC version.\n return this.shouldRunGC && this.latestSummaryGCVersion !== this.currentGCVersion;\n }\n\n /**\n * Tracks if GC is enabled for this document. This is specified during document creation and doesn't change\n * throughout its lifetime.\n */\n private readonly gcEnabled: boolean;\n private readonly shouldRunSweep: boolean;\n private readonly testMode: boolean;\n private readonly mc: MonitoringContext;\n\n /**\n * Tells whether the GC data should be written to the root of the summary tree. We do this under 2 conditions:\n * 1. If `writeDataAtRoot` GC option is enabled.\n * 2. If the base summary has the GC data written at the root. This is to support forward compatibility where when\n * we start writing the GC data at root, older versions can detect that and write at root too.\n */\n private _writeDataAtRoot: boolean = false;\n public get writeDataAtRoot(): boolean {\n return this._writeDataAtRoot;\n }\n\n // The current GC version that this container is running.\n private readonly currentGCVersion = GCVersion;\n // This is the version of GC data in the latest summary being tracked.\n private latestSummaryGCVersion: GCVersion;\n\n // Keeps track of the GC state from the last run.\n private gcDataFromLastRun: IGarbageCollectionData | undefined;\n // Keeps a list of references (edges in the GC graph) between GC runs. Each entry has a node id and a list of\n // outbound routes from that node.\n private readonly referencesSinceLastRun: Map<string, string[]> = new Map();\n\n // Promise when resolved initializes the base state of the nodes from the base summary state.\n private readonly initializeBaseStateP: Promise<void>;\n // The map of data store ids to their GC details in the base summary returned in getDataStoreGCDetails().\n private readonly dataStoreGCDetailsP: Promise<Map<string, IGarbageCollectionSummaryDetails>>;\n // The time after which an unreferenced node can be deleted. Currently, we only set the node's state to expired.\n private readonly deleteTimeoutMs: number;\n // Map of node ids to their unreferenced state tracker.\n private readonly unreferencedNodesState: Map<string, UnreferencedStateTracker> = new Map();\n\n protected constructor(\n private readonly provider: IGarbageCollectionRuntime,\n private readonly gcOptions: IGCRuntimeOptions,\n /** After GC has run, called to delete objects in the runtime whose routes are unused. */\n private readonly deleteUnusedRoutes: (unusedRoutes: string[]) => void,\n /** Returns the current timestamp to be assigned to nodes that become unreferenced. */\n private readonly getCurrentTimestampMs: () => number,\n baseSnapshot: ISnapshotTree | undefined,\n readAndParseBlob: ReadAndParseBlob,\n baseLogger: ITelemetryLogger,\n existing: boolean,\n metadata?: IContainerRuntimeMetadata,\n ) {\n this.mc = loggerToMonitoringContext(\n ChildLogger.create(baseLogger, \"GarbageCollector\"));\n\n this.deleteTimeoutMs = this.gcOptions.deleteTimeoutMs ?? defaultDeleteTimeoutMs;\n\n let prevSummaryGCVersion: number | undefined;\n // GC can only be enabled during creation. After that, it can never be enabled again. So, for existing\n // documents, we get this information from the metadata blob.\n if (existing) {\n prevSummaryGCVersion = getGCVersion(metadata);\n // Existing documents which did not have metadata blob or had GC disabled have version as 0. For all\n // other exsiting documents, GC is enabled.\n this.gcEnabled = prevSummaryGCVersion > 0;\n } else {\n // For new documents, GC has to be exlicitly enabled via the gcAllowed flag in GC options.\n this.gcEnabled = gcOptions.gcAllowed === true;\n }\n // For existing document, the latest summary is the one that we loaded from. So, use its GC version as the\n // latest tracked GC version. For new documents, we will be writing the first summary with the current version.\n this.latestSummaryGCVersion = prevSummaryGCVersion ?? this.currentGCVersion;\n\n // Whether GC should run or not. Can override with localStorage flag.\n this.shouldRunGC = this.mc.config.getBoolean(runGCKey) ?? (\n // GC must be enabled for the document.\n this.gcEnabled\n // GC must not be disabled via GC options.\n && !gcOptions.disableGC\n );\n\n // Whether GC sweep phase should run or not. If this is false, only GC mark phase is run. Can override with\n // localStorage flag.\n this.shouldRunSweep = this.shouldRunGC &&\n (this.mc.config.getBoolean(runSweepKey) ?? gcOptions.runSweep === true);\n\n // Whether we are running in test mode. In this mode, unreferenced nodes are immediately deleted.\n this.testMode = this.mc.config.getBoolean(gcTestModeKey) ?? gcOptions.runGCInTestMode === true;\n\n // If `writeDataAtRoot` GC option is true, we should write the GC data into the root of the summary tree. This\n // GC option is used for testing only. It will be removed once we start writing GC data into root by default.\n this._writeDataAtRoot = this.gcOptions.writeDataAtRoot === true;\n\n // Get the GC state from the GC blob in the base snapshot. Use LazyPromise because we only want to do\n // this once since it involves fetching blobs from storage which is expensive.\n const baseSummaryStateP = new LazyPromise<IGarbageCollectionState | undefined>(async () => {\n if (baseSnapshot === undefined) {\n return undefined;\n }\n\n // For newer documents, GC data should be present in the GC tree in the root of the snapshot.\n const gcSnapshotTree = baseSnapshot.trees[gcTreeKey];\n if (gcSnapshotTree !== undefined) {\n // forward-compat - If a newer version has written the GC tree at root, we should also do the same.\n this._writeDataAtRoot = true;\n return getGCStateFromSnapshot(gcSnapshotTree, readAndParseBlob);\n }\n\n // back-compat - Older documents will have the GC blobs in each data store's summary tree. Get them and\n // consolidate into IGarbageCollectionState format.\n // Add a node for the root node that is not present in older snapshot format.\n const gcState: IGarbageCollectionState = { gcNodes: { \"/\": { outboundRoutes: [] } } };\n const dataStoreSnaphotTree = getSummaryForDatastores(baseSnapshot, metadata);\n assert(dataStoreSnaphotTree !== undefined,\n 0x2a8 /* \"Expected data store snapshot tree in base snapshot\" */);\n for (const [dsId, dsSnapshotTree] of Object.entries(dataStoreSnaphotTree.trees)) {\n const blobId = dsSnapshotTree.blobs[gcBlobKey];\n if (blobId === undefined) {\n continue;\n }\n\n const gcSummaryDetails = await readAndParseBlob<IGarbageCollectionSummaryDetails>(blobId);\n // If there are no nodes for this data store, skip it.\n if (gcSummaryDetails.gcData?.gcNodes === undefined) {\n continue;\n }\n\n const dsRootId = `/${dsId}`;\n // Since we used to write GC data at data store level, we won't have an entry for the root (\"/\").\n // Construct that entry by adding root data store ids to its outbound routes.\n const initialSnapshotDetails = await readAndParseBlob<ReadFluidDataStoreAttributes>(\n dsSnapshotTree.blobs[dataStoreAttributesBlobName],\n );\n if (initialSnapshotDetails.isRootDataStore) {\n gcState.gcNodes[\"/\"].outboundRoutes.push(dsRootId);\n }\n\n for (const [id, outboundRoutes] of Object.entries(gcSummaryDetails.gcData.gcNodes)) {\n // Prefix the data store id to the GC node ids to make them relative to the root from being\n // relative to the data store. Similar to how its done in DataStore::getGCData.\n const rootId = id === \"/\" ? dsRootId : `${dsRootId}${id}`;\n gcState.gcNodes[rootId] = { outboundRoutes: Array.from(outboundRoutes) };\n }\n assert(gcState.gcNodes[dsRootId] !== undefined,\n 0x2a9 /* `GC nodes for data store ${dsId} not in GC blob` */);\n gcState.gcNodes[dsRootId].unreferencedTimestampMs = gcSummaryDetails.unrefTimestamp;\n }\n\n // If there is only one node (root node just added above), either GC is disabled or we are loading from the\n // very first summary generated by detached container. In both cases, GC was not run - return undefined.\n return Object.keys(gcState.gcNodes).length === 1 ? undefined : gcState;\n });\n\n // Set up the initializer which initializes the base GC state from the base snapshot. Use lazy promise because\n // we only do this once - the very first time we run GC.\n this.initializeBaseStateP = new LazyPromise<void>(async () => {\n const currentTimestampMs = this.getCurrentTimestampMs();\n const baseState = await baseSummaryStateP;\n if (baseState === undefined) {\n return;\n }\n\n const gcNodes: { [ id: string ]: string[] } = {};\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n const unreferencedTimestampMs = nodeData.unreferencedTimestampMs;\n if (unreferencedTimestampMs !== undefined) {\n // Get how long it has been since the node was unreferenced. Start a timeout for the remaining time\n // left for it to be eligible for deletion.\n const unreferencedDurationMs = currentTimestampMs - unreferencedTimestampMs;\n this.unreferencedNodesState.set(\n nodeId,\n new UnreferencedStateTracker(\n unreferencedTimestampMs,\n this.deleteTimeoutMs - unreferencedDurationMs,\n ),\n );\n }\n gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);\n }\n this.gcDataFromLastRun = { gcNodes };\n });\n\n // Get the GC details for each data store from the GC state in the base summary. This is returned in\n // getDataStoreBaseGCDetails and is used to initialize each data store's base GC details.\n this.dataStoreGCDetailsP = new LazyPromise<Map<string, IGarbageCollectionSummaryDetails>>(async () => {\n const baseState = await baseSummaryStateP;\n if (baseState === undefined) {\n return new Map();\n }\n\n const gcNodes: { [ id: string ]: string[] } = {};\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);\n }\n // Run GC on the nodes in the base summary to get the routes used in each node in the container.\n // This is an optimization for space (vs performance) wherein we don't need to store the used routes of\n // each node in the summary.\n const usedRoutes = runGarbageCollection(\n gcNodes,\n [ \"/\" ],\n this.mc.logger,\n ).referencedNodeIds;\n\n const dataStoreGCDetailsMap = unpackChildNodesGCDetails({ gcData: { gcNodes }, usedRoutes });\n // Currently, the data stores write the GC data. So, we need to update it's base GC details with the\n // unreferenced timestamp. Once we start writing the GC data here, we won't need to do this anymore.\n for (const [nodeId, nodeData] of Object.entries(baseState.gcNodes)) {\n if (nodeData.unreferencedTimestampMs !== undefined) {\n const dataStoreGCDetails = dataStoreGCDetailsMap.get(nodeId.slice(1));\n if (dataStoreGCDetails !== undefined) {\n dataStoreGCDetails.unrefTimestamp = nodeData.unreferencedTimestampMs;\n }\n }\n }\n return dataStoreGCDetailsMap;\n });\n }\n\n /**\n * Runs garbage collection and udpates the reference / used state of the nodes in the container.\n * @returns the number of data stores that have been marked as unreferenced.\n */\n public async collectGarbage(\n options: {\n /** Logger to use for logging GC events */\n logger?: ITelemetryLogger,\n /** True to run GC sweep phase after the mark phase */\n runSweep?: boolean,\n /** True to generate full GC data */\n fullGC?: boolean,\n },\n ): Promise<IGCStats> {\n const {\n logger = this.mc.logger,\n runSweep = this.shouldRunSweep,\n fullGC = this.gcOptions.runFullGC === true || this.hasGCVersionChanged,\n } = options;\n\n return PerformanceEvent.timedExecAsync(logger, { eventName: \"GarbageCollection\" }, async (event) => {\n await this.initializeBaseStateP;\n\n const gcStats: {\n deletedNodes?: number,\n totalNodes?: number,\n deletedDataStores?: number,\n totalDataStores?: number,\n } = {};\n\n // Get the runtime's GC data and run GC on the reference graph in it.\n const gcData = await this.provider.getGCData(fullGC);\n\n this.updateStateSinceLatestRun(gcData);\n\n const gcResult = runGarbageCollection(\n gcData.gcNodes,\n [ \"/\" ],\n logger,\n );\n\n const currentTimestampMs = this.getCurrentTimestampMs();\n // Update the current state of the system based on the GC run.\n this.updateCurrentState(gcData, gcResult, currentTimestampMs);\n\n const dataStoreUsedStateStats =\n this.provider.updateUsedRoutes(gcResult.referencedNodeIds, currentTimestampMs);\n\n if (runSweep) {\n // Placeholder for running sweep logic.\n }\n\n // Update stats to be reported in the peformance event.\n gcStats.deletedNodes = gcResult.deletedNodeIds.length;\n gcStats.totalNodes = gcResult.referencedNodeIds.length + gcResult.deletedNodeIds.length;\n gcStats.deletedDataStores = dataStoreUsedStateStats.unusedNodeCount;\n gcStats.totalDataStores = dataStoreUsedStateStats.totalNodeCount;\n\n // If we are running in GC test mode, delete objects for unused routes. This enables testing scenarios\n // involving access to deleted data.\n if (this.testMode) {\n this.deleteUnusedRoutes(gcResult.deletedNodeIds);\n }\n event.end(gcStats);\n return gcStats as IGCStats;\n },\n { end: true, cancel: \"error\" });\n }\n\n /**\n * Summarizes the GC data and returns it as a summary tree.\n * We current write the entire GC state in a single blob. This can be modified later to write multiple\n * blobs. All the blob keys should start with `gcBlobPrefix`.\n */\n public summarize(): ISummaryTreeWithStats | undefined {\n if (!this.shouldRunGC || this.gcDataFromLastRun === undefined) {\n return;\n }\n\n const gcState: IGarbageCollectionState = { gcNodes: {} };\n for (const [nodeId, outboundRoutes] of Object.entries(this.gcDataFromLastRun.gcNodes)) {\n gcState.gcNodes[nodeId] = {\n outboundRoutes,\n unreferencedTimestampMs: this.unreferencedNodesState.get(nodeId)?.unreferencedTimestampMs,\n };\n }\n\n const builder = new SummaryTreeBuilder();\n builder.addBlob(`${gcBlobPrefix}_root`, JSON.stringify(gcState));\n return builder.getSummaryTree();\n }\n\n /**\n * Returns a map of data store ids to their base GC details generated from the base summary.This is used to\n * initialize the data stores with their base GC state.\n */\n public async getDataStoreBaseGCDetails(): Promise<Map<string, IGarbageCollectionSummaryDetails>> {\n return this.dataStoreGCDetailsP;\n }\n\n /**\n * Called when the latest summary of the system has been refreshed. This will be used to update the state of the\n * latest summary tracked.\n */\n public async latestSummaryStateRefreshed(\n result: RefreshSummaryResult,\n readAndParseBlob: ReadAndParseBlob,\n ): Promise<void> {\n if (!this.shouldRunGC || !result.latestSummaryUpdated) {\n return;\n }\n\n // If the summary was tracked by this client, it was the one that generated the summary in the first place.\n // Basically, it was written in the current GC version.\n if (result.wasSummaryTracked) {\n this.latestSummaryGCVersion = this.currentGCVersion;\n return;\n }\n // If the summary was not tracked by this client, update latest GC version from the snapshot in the result as\n // that is now the latest summary.\n await this.updateSummaryGCVersionFromSnapshot(result.snapshot, readAndParseBlob);\n }\n\n /**\n * Called when a node with the given id is changed. If the node is inactive, log an error.\n */\n public nodeChanged(id: string) {\n // Prefix \"/\" if needed to make it relative to the root.\n const nodeId = id.startsWith(\"/\") ? id : `/${id}`;\n this.unreferencedNodesState.get(nodeId)?.logIfInactive(\n this.mc.logger,\n \"inactiveObjectChanged\",\n this.getCurrentTimestampMs(),\n this.deleteTimeoutMs,\n nodeId,\n );\n }\n\n /**\n * Called when an outbound reference is added to a node. This is used to identify all nodes that have been\n * referenced between summaries so that their unreferenced timestamp can be reset.\n *\n * @param fromNodeId - The node from which the reference is added.\n * @param toNodeId - The node to which the reference is added.\n */\n public addedOutboundReference(fromNodeId: string, toNodeId: string) {\n const outboundRoutes = this.referencesSinceLastRun.get(fromNodeId) ?? [];\n outboundRoutes.push(toNodeId);\n this.referencesSinceLastRun.set(fromNodeId, outboundRoutes);\n }\n\n /**\n * Update the latest summary GC version from the metadata blob in the given snapshot.\n */\n private async updateSummaryGCVersionFromSnapshot(snapshot: ISnapshotTree, readAndParseBlob: ReadAndParseBlob) {\n const metadataBlobId = snapshot.blobs[metadataBlobName];\n if (metadataBlobId) {\n const metadata = await readAndParseBlob<IContainerRuntimeMetadata>(metadataBlobId);\n this.latestSummaryGCVersion = getGCVersion(metadata);\n }\n }\n\n /**\n * Updates the state of the system as per the current GC run. It does the following:\n * 1. Sets up the current GC state as per the gcData.\n * 2. Starts tracking for nodes that have become unreferenced in this run.\n * 3. Clears tracking for nodes that were unreferenced but became referenced in this run.\n * @param gcData - The data representing the reference graph on which GC is run.\n * @param gcResult - The result of the GC run on the gcData.\n * @param currentTimestampMs - The current timestamp to be used for unreferenced nodes' timestamp.\n */\n private updateCurrentState(gcData: IGarbageCollectionData, gcResult: IGCResult, currentTimestampMs: number) {\n this.gcDataFromLastRun = cloneGCData(gcData);\n this.referencesSinceLastRun.clear();\n\n // Iterate through the deleted nodes and start tracking if they became unreferenced in this run.\n for (const nodeId of gcResult.deletedNodeIds) {\n // The time when the node became unreferenced. This is added to the current GC state.\n let unreferencedTimestampMs: number = currentTimestampMs;\n const nodeStateTracker = this.unreferencedNodesState.get(nodeId);\n if (nodeStateTracker !== undefined) {\n unreferencedTimestampMs = nodeStateTracker.unreferencedTimestampMs;\n } else {\n // Start tracking this node as it became unreferenced in this run.\n this.unreferencedNodesState.set(\n nodeId,\n new UnreferencedStateTracker(unreferencedTimestampMs, this.deleteTimeoutMs),\n );\n }\n }\n\n // Iterate through the referenced nodes and stop tracking if they were unreferenced before.\n for (const nodeId of gcResult.referencedNodeIds) {\n const nodeStateTracker = this.unreferencedNodesState.get(nodeId);\n if (nodeStateTracker !== undefined) {\n // If this node has been unreferenced for longer than deleteTimeoutMs and is being referenced,\n // log an error as this may mean the deleteTimeoutMs is not long enough.\n nodeStateTracker.logIfInactive(\n this.mc.logger,\n \"inactiveObjectRevived\",\n currentTimestampMs,\n this.deleteTimeoutMs,\n nodeId,\n );\n // Stop tracking so as to clear out any running timers.\n nodeStateTracker.stopTracking();\n // Delete the node as we don't need to track it any more.\n this.unreferencedNodesState.delete(nodeId);\n }\n }\n }\n\n /**\n * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in\n * time. It's possible that nodes transition from `unreferenced -> referenced -> unreferenced` between two runs. The\n * unreferenced timestamp of such nodes needs to be reset as they may have been accessed when they were referenced.\n *\n * This function identifies nodes that were referenced since last run and removes their unreferenced state, if any.\n * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.\n */\n private updateStateSinceLatestRun(currentGCData: IGarbageCollectionData) {\n // If we haven't run GC before or no references were added since the last run, there is nothing to do.\n if (this.gcDataFromLastRun === undefined || this.referencesSinceLastRun.size === 0) {\n return;\n }\n\n /**\n * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and\n * edges that have been added since then. To do this, combine the GC data from the last run and the current\n * run, and then add the references since last run.\n *\n * Note on why we need to combine the data from previous run, current run and all references in between -\n * 1. We need data from last run because some of its references may have been deleted since then. If those\n * references added new outbound references before getting deleted, we need to detect them.\n * 2. We need new outbound references since last run because some of them may have been deleted later. If those\n * references added new outbound references before getting deleted, we need to detect them.\n * 3. We need data from the current run because currently we may not detect when DDSs are referenced:\n * - We don't require DDSs handles to be stored in a referenced DDS. For this, we need GC at DDS level\n * which is tracked by https://github.com/microsoft/FluidFramework/issues/8470.\n * - A new data store may have \"root\" DDSs already created and we don't detect them today.\n */\n const gcDataSuperSet = concatGarbageCollectionData(this.gcDataFromLastRun, currentGCData);\n this.referencesSinceLastRun.forEach((outboundRoutes: string[], sourceNodeId: string) => {\n if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {\n gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;\n } else {\n gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);\n }\n });\n\n /**\n * Run GC on the above reference graph to find all nodes that are referenced. For each one, if they are\n * unreferenced, stop tracking them and remove from unreferenced list.\n * Some of these nodes may be unreferenced now and if so, the current run will add unreferenced state for them.\n */\n const gcResult = runGarbageCollection(gcDataSuperSet.gcNodes, [\"/\"], this.mc.logger);\n for (const nodeId of gcResult.referencedNodeIds) {\n const nodeStateTracker = this.unreferencedNodesState.get(nodeId);\n if (nodeStateTracker !== undefined) {\n // Stop tracking so as to clear out any running timers.\n nodeStateTracker.stopTracking();\n // Delete the node as we don't need to track it any more.\n this.unreferencedNodesState.delete(nodeId);\n }\n }\n }\n}\n\n/**\n * Gets the garbage collection state from the given snapshot tree. The GC state may be written into multiple blobs.\n * Merge the GC state from all such blobs and return the merged GC state.\n*/\nasync function getGCStateFromSnapshot(\n gcSnapshotTree: ISnapshotTree,\n readAndParseBlob: ReadAndParseBlob,\n): Promise<IGarbageCollectionState> {\n let rootGCState: IGarbageCollectionState = { gcNodes: {} };\n for (const key of Object.keys(gcSnapshotTree.blobs)) {\n // Skip blobs that do not stsart with the GC prefix.\n if (!key.startsWith(gcBlobPrefix)) {\n continue;\n }\n\n const blobId = gcSnapshotTree.blobs[key];\n if (blobId === undefined) {\n continue;\n }\n const gcState = await readAndParseBlob<IGarbageCollectionState>(blobId);\n assert(gcState !== undefined, 0x2ad /* \"GC blob missing from snapshot\" */);\n // Merge the GC state of this blob into the root GC state.\n rootGCState = concatGarbageCollectionStates(rootGCState, gcState);\n }\n return rootGCState;\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/container-runtime";
8
- export declare const pkgVersion = "0.53.0";
8
+ export declare const pkgVersion = "0.54.2";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/container-runtime";
11
- exports.pkgVersion = "0.53.0";
11
+ exports.pkgVersion = "0.54.2";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"0.53.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,mCAAmC,CAAC;AAC9C,QAAA,UAAU,GAAG,QAAQ,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/container-runtime\";\nexport const pkgVersion = \"0.54.2\";\n"]}
@@ -4,8 +4,9 @@
4
4
  */
5
5
  import { IDisposable, ITelemetryLogger } from "@fluidframework/common-definitions";
6
6
  import { ISequencedDocumentMessage, ISummaryConfiguration } from "@fluidframework/protocol-definitions";
7
- import { IEnqueueSummarizeOptions, ISummarizeHeuristicData, ISummarizerOptions, OnDemandSummarizeResult, IOnDemandSummarizeOptions, EnqueueSummarizeResult, SummarizerStopReason, ISubmitSummaryOptions, SubmitSummaryResult, ISummaryCancellationToken } from "./summarizerTypes";
7
+ import { IEnqueueSummarizeOptions, ISummarizeHeuristicData, ISummarizerOptions, IOnDemandSummarizeOptions, EnqueueSummarizeResult, SummarizerStopReason, ISubmitSummaryOptions, SubmitSummaryResult, ISummaryCancellationToken, ISummarizeResults } from "./summarizerTypes";
8
8
  import { IClientSummaryWatcher, SummaryCollection } from "./summaryCollection";
9
+ import { SummarizeResultBuilder } from "./summaryGenerator";
9
10
  /**
10
11
  * An instance of RunningSummarizer manages the heuristics for summarizing.
11
12
  * Until disposed, the instance of RunningSummarizer can assume that it is
@@ -67,7 +68,7 @@ export declare class RunningSummarizer implements IDisposable {
67
68
  /** Heuristics summarize attempt. */
68
69
  private trySummarize;
69
70
  /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */
70
- summarizeOnDemand({ reason, ...options }: IOnDemandSummarizeOptions): OnDemandSummarizeResult;
71
+ summarizeOnDemand(resultsBuilder: SummarizeResultBuilder | undefined, { reason, ...options }: IOnDemandSummarizeOptions): ISummarizeResults;
71
72
  /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */
72
73
  enqueueSummarize({ reason, afterSequenceNumber, override, ...options }: IEnqueueSummarizeOptions): EnqueueSummarizeResult;
73
74
  private tryRunEnqueuedSummary;
@@ -1 +1 @@
1
- {"version":3,"file":"runningSummarizer.d.ts","sourceRoot":"","sources":["../src/runningSummarizer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAwB,MAAM,oCAAoC,CAAC;AAEzG,OAAO,EACH,yBAAyB,EACz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,CAAS;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,eAAe,CAA4B;IACnD,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAe;IAC/C,OAAO,CAAC,eAAe,CAAC,CAA4B;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAmB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,eAAe,CAKT;IACd,OAAO,CAAC,cAAc,CAAK;IAE3B,OAAO;IA+DA,OAAO,IAAI,IAAI;IAWtB;;;;;OAKG;IACI,sBAAsB,yDAGT;IAEb,cAAc,CAAC,EAAE,EAAE,yBAAyB;IAgB5C,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,yBAAyB;IAiBtF,QAAQ,CAAC,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YA4BjD,SAAS;IAqBvB;;;;;;OAMG;YACW,mBAAmB;IAuBjC;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAwBxB,oCAAoC;IACpC,OAAO,CAAC,YAAY;IAmFpB,8DAA8D;IACvD,iBAAiB,CACpB,cAAc,oCAAuD,EACrE,EACI,MAAM,EACN,GAAG,OAAO,EACb,EAAE,yBAAyB,GAAG,iBAAiB;IAmBpD,6DAA6D;IACtD,gBAAgB,CAAC,EACpB,MAAM,EACN,mBAAuB,EACvB,QAAgB,EAChB,GAAG,OAAO,EACb,EAAE,wBAAwB,GAAG,sBAAsB;IA8BpD,OAAO,CAAC,qBAAqB;IAwB7B,OAAO,CAAC,sBAAsB;CAMjC"}
@@ -17,6 +17,7 @@ var __rest = (this && this.__rest) || function (s, e) {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.RunningSummarizer = void 0;
19
19
  const common_utils_1 = require("@fluidframework/common-utils");
20
+ const container_utils_1 = require("@fluidframework/container-utils");
20
21
  const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
21
22
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
22
23
  const summarizerHeuristics_1 = require("./summarizerHeuristics");
@@ -283,20 +284,19 @@ class RunningSummarizer {
283
284
  });
284
285
  }
285
286
  /** {@inheritdoc (ISummarizer:interface).summarizeOnDemand} */
286
- summarizeOnDemand(_a) {
287
+ summarizeOnDemand(resultsBuilder = new summaryGenerator_1.SummarizeResultBuilder(), _a) {
287
288
  var { reason } = _a, options = __rest(_a, ["reason"]);
288
289
  if (this.stopping) {
289
- const failBuilder = new summaryGenerator_1.SummarizeResultBuilder();
290
- failBuilder.fail("RunningSummarizer stopped or disposed", undefined);
291
- return failBuilder.build();
290
+ resultsBuilder.fail("RunningSummarizer stopped or disposed", undefined);
291
+ return resultsBuilder.build();
292
292
  }
293
293
  // Check for concurrent summary attempts. If one is found,
294
294
  // return a promise that caller can await before trying again.
295
295
  if (this.summarizingLock !== undefined) {
296
296
  // The heuristics are blocking concurrent summarize attempts.
297
- return { alreadyRunning: this.summarizingLock };
297
+ throw new container_utils_1.UsageError("Attempted to run an already-running summarizer on demand");
298
298
  }
299
- const result = this.trySummarizeOnce({ summarizeReason: `onDemand/${reason}` }, options, this.cancellationToken);
299
+ const result = this.trySummarizeOnce({ summarizeReason: `onDemand/${reason}` }, options, this.cancellationToken, resultsBuilder);
300
300
  return result;
301
301
  }
302
302
  /** {@inheritdoc (ISummarizer:interface).enqueueSummarize} */