@fluidframework/container-runtime 2.0.0-internal.8.0.0 → 2.0.0-internal.8.0.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 (47) hide show
  1. package/dist/containerRuntime.d.ts.map +1 -1
  2. package/dist/containerRuntime.js +0 -3
  3. package/dist/containerRuntime.js.map +1 -1
  4. package/dist/gc/garbageCollection.d.ts +8 -12
  5. package/dist/gc/garbageCollection.d.ts.map +1 -1
  6. package/dist/gc/garbageCollection.js +71 -103
  7. package/dist/gc/garbageCollection.js.map +1 -1
  8. package/dist/gc/gcDefinitions.d.ts +0 -1
  9. package/dist/gc/gcDefinitions.d.ts.map +1 -1
  10. package/dist/gc/gcDefinitions.js.map +1 -1
  11. package/dist/gc/gcSummaryStateTracker.d.ts +1 -1
  12. package/dist/gc/gcSummaryStateTracker.d.ts.map +1 -1
  13. package/dist/gc/gcSummaryStateTracker.js +3 -0
  14. package/dist/gc/gcSummaryStateTracker.js.map +1 -1
  15. package/dist/gc/gcTelemetry.d.ts.map +1 -1
  16. package/dist/gc/gcTelemetry.js +4 -14
  17. package/dist/gc/gcTelemetry.js.map +1 -1
  18. package/dist/packageVersion.d.ts +1 -1
  19. package/dist/packageVersion.js +1 -1
  20. package/dist/packageVersion.js.map +1 -1
  21. package/lib/containerRuntime.d.ts.map +1 -1
  22. package/lib/containerRuntime.js +0 -3
  23. package/lib/containerRuntime.js.map +1 -1
  24. package/lib/gc/garbageCollection.d.ts +8 -12
  25. package/lib/gc/garbageCollection.d.ts.map +1 -1
  26. package/lib/gc/garbageCollection.js +72 -104
  27. package/lib/gc/garbageCollection.js.map +1 -1
  28. package/lib/gc/gcDefinitions.d.ts +0 -1
  29. package/lib/gc/gcDefinitions.d.ts.map +1 -1
  30. package/lib/gc/gcDefinitions.js.map +1 -1
  31. package/lib/gc/gcSummaryStateTracker.d.ts +1 -1
  32. package/lib/gc/gcSummaryStateTracker.d.ts.map +1 -1
  33. package/lib/gc/gcSummaryStateTracker.js +3 -0
  34. package/lib/gc/gcSummaryStateTracker.js.map +1 -1
  35. package/lib/gc/gcTelemetry.d.ts.map +1 -1
  36. package/lib/gc/gcTelemetry.js +4 -14
  37. package/lib/gc/gcTelemetry.js.map +1 -1
  38. package/lib/packageVersion.d.ts +1 -1
  39. package/lib/packageVersion.js +1 -1
  40. package/lib/packageVersion.js.map +1 -1
  41. package/package.json +16 -16
  42. package/src/containerRuntime.ts +0 -3
  43. package/src/gc/garbageCollection.ts +92 -119
  44. package/src/gc/gcDefinitions.ts +0 -1
  45. package/src/gc/gcSummaryStateTracker.ts +5 -1
  46. package/src/gc/gcTelemetry.ts +4 -13
  47. package/src/packageVersion.ts +1 -1
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { LazyPromise, Timer } from "@fluidframework/core-utils";
6
+ import { assert, LazyPromise, Timer } from "@fluidframework/core-utils";
7
7
  import { IRequest } from "@fluidframework/core-interfaces";
8
8
  import {
9
9
  gcTreeKey,
@@ -21,6 +21,7 @@ import {
21
21
  MonitoringContext,
22
22
  PerformanceEvent,
23
23
  } from "@fluidframework/telemetry-utils";
24
+ import { BlobManager } from "../blobManager";
24
25
  import {
25
26
  InactiveResponseHeaderKey,
26
27
  RuntimeHeaderData,
@@ -141,8 +142,6 @@ export class GarbageCollector implements IGarbageCollector {
141
142
  ) => Promise<readonly string[] | undefined>;
142
143
  /** Returns the timestamp of the last summary generated for this container. */
143
144
  private readonly getLastSummaryTimestampMs: () => number | undefined;
144
- /** Returns true if connection is active, i.e. it's "write" connection and the runtime is connected. */
145
- private readonly activeConnection: () => boolean;
146
145
 
147
146
  private readonly submitMessage: (message: ContainerRuntimeGCMessage) => void;
148
147
 
@@ -160,7 +159,6 @@ export class GarbageCollector implements IGarbageCollector {
160
159
  this.isSummarizerClient = createParams.isSummarizerClient;
161
160
  this.getNodePackagePath = createParams.getNodePackagePath;
162
161
  this.getLastSummaryTimestampMs = createParams.getLastSummaryTimestampMs;
163
- this.activeConnection = createParams.activeConnection;
164
162
  this.submitMessage = createParams.submitMessage;
165
163
 
166
164
  const baseSnapshot = createParams.baseSnapshot;
@@ -255,28 +253,18 @@ export class GarbageCollector implements IGarbageCollector {
255
253
  );
256
254
 
257
255
  /**
258
- * Set up the initializer which initializes the GC state from the data in base snapshot. This is done when
259
- * connected in write mode or when GC runs the first time. It sets up all unreferenced nodes from the base
260
- * GC state and updates their inactive or sweep-ready state.
256
+ * Set up the initializer which initializes the GC state from the data in base snapshot. It sets up GC data
257
+ * from the base GC state and starts tracking the state of unreferenced nodes.
258
+ *
259
+ * Must only be called if there is a current reference timestamp.
261
260
  */
262
261
  this.initializeGCStateFromBaseSnapshotP = new LazyPromise<void>(async () => {
263
- /**
264
- * If there is no current reference timestamp, skip initialization. We need the current timestamp to track
265
- * how long objects have been unreferenced and if they can be deleted.
266
- *
267
- * Note that the only scenario where there is no reference timestamp is when no ops have ever been processed
268
- * for this container and it is in read mode. In this scenario, there is no point in running GC anyway
269
- * because references in the container do not change without any ops, i.e., there is nothing to collect.
270
- */
271
262
  const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
272
- if (currentReferenceTimestampMs === undefined) {
273
- // Log an event so we can evaluate how often we run into this scenario.
274
- this.mc.logger.sendErrorEvent({
275
- eventName: "GarbageCollectorInitializedWithoutTimestamp",
276
- gcConfigs: JSON.stringify(this.configs),
277
- });
278
- return;
279
- }
263
+ assert(
264
+ currentReferenceTimestampMs !== undefined,
265
+ "Trying to initialize GC state without current timestamp",
266
+ );
267
+
280
268
  /**
281
269
  * The base snapshot data will not be present if the container is loaded from:
282
270
  * 1. The first summary created by the detached container.
@@ -284,11 +272,31 @@ export class GarbageCollector implements IGarbageCollector {
284
272
  * 3. A summary that was generated before GC even existed.
285
273
  */
286
274
  const baseSnapshotData = await this.baseSnapshotDataP;
287
- if (baseSnapshotData === undefined) {
275
+ this.summaryStateTracker.initializeBaseState(baseSnapshotData);
276
+
277
+ if (baseSnapshotData?.gcState === undefined) {
288
278
  return;
289
279
  }
290
- this.updateStateFromSnapshotData(baseSnapshotData, currentReferenceTimestampMs);
291
- this.summaryStateTracker.initializeBaseState(baseSnapshotData);
280
+
281
+ // Update unreferenced state tracking as per the GC state in the snapshot data and update gcDataFromLastRun
282
+ // to the GC data from the snapshot data.
283
+ const gcNodes: { [id: string]: string[] } = {};
284
+ for (const [nodeId, nodeData] of Object.entries(baseSnapshotData.gcState.gcNodes)) {
285
+ if (nodeData.unreferencedTimestampMs !== undefined) {
286
+ this.unreferencedNodesState.set(
287
+ nodeId,
288
+ new UnreferencedStateTracker(
289
+ nodeData.unreferencedTimestampMs,
290
+ this.configs.inactiveTimeoutMs,
291
+ currentReferenceTimestampMs,
292
+ this.configs.sweepTimeoutMs,
293
+ this.configs.sweepGracePeriodMs,
294
+ ),
295
+ );
296
+ }
297
+ gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
298
+ }
299
+ this.gcDataFromLastRun = { gcNodes };
292
300
  });
293
301
 
294
302
  // Get the GC details from the GC state in the base summary. This is returned in getBaseGCDetails which is
@@ -322,8 +330,10 @@ export class GarbageCollector implements IGarbageCollector {
322
330
  }
323
331
 
324
332
  /**
325
- * Called during container initialization. Initialize from the tombstone state in the base snapshot. This is done
326
- * during initialization so that deleted or tombstoned objects are marked as such before they are loaded or used.
333
+ * Called during container initialization. Initializes the tombstone and deleted nodes state from the base snapshot.
334
+ * Also, initializes the GC state including unreferenced nodes tracking if a current reference timestamp exists.
335
+ * Note that if there is any GC state in the base snapshot, then there will definitely be a reference timestamp
336
+ * to work with - The GC state would have been generated using a timestamp which is part of the snapshot.
327
337
  */
328
338
  public async initializeBaseState(): Promise<void> {
329
339
  const baseSnapshotData = await this.baseSnapshotDataP;
@@ -350,115 +360,59 @@ export class GarbageCollector implements IGarbageCollector {
350
360
  this.tombstones = Array.from(baseSnapshotData.tombstones);
351
361
  this.runtime.updateTombstonedRoutes(this.tombstones);
352
362
  }
363
+
364
+ await this.initializeOrUpdateGCState();
353
365
  }
354
366
 
355
367
  /**
356
- * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.
357
- * All current tracking is reset and updated from the data in the snapshot.
358
- * @param snapshotData - The snapshot data to update state from. If this is undefined, all GC state and tracking
359
- * is reset.
360
- * @param currentReferenceTimestampMs - The current reference timestamp for marking unreferenced nodes' unreferenced
361
- * timestamp.
368
+ * Initialize the GC state if not already initialized. If GC state is already initialized, update the unreferenced
369
+ * state tracking as per the current reference timestamp.
362
370
  */
363
- private updateStateFromSnapshotData(
364
- snapshotData: IGarbageCollectionSnapshotData | undefined,
365
- currentReferenceTimestampMs: number,
366
- ) {
367
- /**
368
- * Note: "newReferencesSinceLastRun" is not reset here. This is done because there may be references since the
369
- * snapshot that we are updating state from. For example, this client may have processed ops till seq#1000 and
370
- * its refreshing state from a summary that happened at seq#900. In this case, there may be references between
371
- * seq#901 and seq#1000 that we don't want to reset.
372
- * Unfortunately, there is no way to track the seq# of ops that add references, so we choose to not reset any
373
- * references here. This should be fine because, in the worst case, we may end up updating the unreferenced
374
- * timestamp of a node which will delay its deletion. Although not ideal, this will only happen in rare
375
- * scenarios, so it should be okay.
376
- */
377
-
378
- // Clear all existing unreferenced state tracking.
379
- for (const [, nodeStateTracker] of this.unreferencedNodesState) {
380
- nodeStateTracker.stopTracking();
381
- }
382
- this.unreferencedNodesState.clear();
383
-
384
- // If running sweep, the tombstone state represents the list of nodes that have been deleted during sweep.
385
- // If running in tombstone mode, the tombstone state represents the list of nodes that have been marked as
386
- // tombstones.
387
- // If this call is because we are refreshing from a snapshot due to an ack, it is likely that the GC state
388
- // in the snapshot is newer than this client's. And so, the deleted / tombstone nodes need to be updated.
389
- if (this.configs.shouldRunSweep) {
390
- const snapshotDeletedNodes = snapshotData?.deletedNodes
391
- ? new Set(snapshotData.deletedNodes)
392
- : undefined;
393
- // If the snapshot contains deleted nodes that are not yet deleted by this client, ask the runtime to
394
- // delete them.
395
- if (snapshotDeletedNodes !== undefined) {
396
- const newDeletedNodes: string[] = [];
397
- for (const nodeId of snapshotDeletedNodes) {
398
- if (!this.deletedNodes.has(nodeId)) {
399
- newDeletedNodes.push(nodeId);
400
- }
401
- }
402
- if (newDeletedNodes.length > 0) {
403
- // Call container runtime to delete these nodes and add deleted nodes to this.deletedNodes.
404
- }
405
- }
406
- } else if (this.configs.tombstoneMode) {
407
- // The snapshot may contain more or fewer tombstone nodes than this client. Update tombstone state and
408
- // notify the runtime to update its state as well.
409
- this.tombstones = snapshotData?.tombstones ? Array.from(snapshotData.tombstones) : [];
410
- this.runtime.updateTombstonedRoutes(this.tombstones);
371
+ private async initializeOrUpdateGCState() {
372
+ const currentReferenceTimestampMs = this.runtime.getCurrentReferenceTimestampMs();
373
+ if (currentReferenceTimestampMs === undefined) {
374
+ return;
411
375
  }
412
376
 
413
- // If there is no snapshot data, it means this snapshot was generated with GC disabled. Unset all GC state.
414
- if (snapshotData?.gcState === undefined) {
415
- this.gcDataFromLastRun = undefined;
377
+ // If the GC state hasn't been initialized yet, initialize it and return.
378
+ if (this.gcDataFromLastRun === undefined) {
379
+ await this.initializeGCStateFromBaseSnapshotP;
416
380
  return;
417
381
  }
418
382
 
419
- // Update unreferenced state tracking as per the GC state in the snapshot data and update gcDataFromLastRun
420
- // to the GC data from the snapshot data.
421
- const gcNodes: { [id: string]: string[] } = {};
422
- for (const [nodeId, nodeData] of Object.entries(snapshotData.gcState.gcNodes)) {
423
- if (nodeData.unreferencedTimestampMs !== undefined) {
424
- this.unreferencedNodesState.set(
425
- nodeId,
426
- new UnreferencedStateTracker(
427
- nodeData.unreferencedTimestampMs,
428
- this.configs.inactiveTimeoutMs,
429
- currentReferenceTimestampMs,
430
- this.configs.sweepTimeoutMs,
431
- this.configs.sweepGracePeriodMs,
432
- ),
433
- );
434
- }
435
- gcNodes[nodeId] = Array.from(nodeData.outboundRoutes);
383
+ // If the GC state has been initialized, update the tracking of unreferenced nodes as per the current
384
+ // reference timestamp.
385
+ for (const [, nodeStateTracker] of this.unreferencedNodesState) {
386
+ nodeStateTracker.updateTracking(currentReferenceTimestampMs);
436
387
  }
437
- this.gcDataFromLastRun = { gcNodes };
438
388
  }
439
389
 
440
390
  /**
441
391
  * Called when the connection state of the runtime changes, i.e., it connects or disconnects. GC subscribes to this
442
- * to initialize the base state for non-summarizer clients so that they can track inactive / sweep-ready nodes.
392
+ * to initialize or update the unreference state tracking.
443
393
  * @param connected - Whether the runtime connected / disconnected.
444
394
  * @param clientId - The clientId of this runtime.
445
395
  */
446
396
  public setConnectionState(connected: boolean, clientId?: string | undefined): void {
447
397
  /**
448
- * For all clients, initialize the base state when the container becomes active, i.e., it transitions
449
- * to "write" mode. This will ensure that the container's own join op is processed and there is a recent
450
- * reference timestamp that will be used to update the state of unreferenced nodes. Also, all trailing ops which
451
- * could affect the GC state will have been processed.
452
- *
453
- * If GC is up-to-date for the client and the summarizing client, there will be an doubling of both
454
- * InactiveObject_Loaded and SweepReady_Loaded errors, as there will be one from the sending client and one from
455
- * the receiving summarizer client.
398
+ * When the client connects (or reconnects), attempt to initialize or update the GC state. This will keep
399
+ * the unreferenced state tracking updated as per the reference timestamp at the time of connection.
456
400
  *
457
- * Ideally, this initialization should only be done for summarizer client. However, we are currently rolling out
458
- * sweep in phases and we want to track when inactive and sweep-ready objects are used in any client.
401
+ * During GC initialization and during connections in read mode, it is possible that either no ops are
402
+ * processed or only trailing ops are processed. This means that the GC state is not initialized or initialized
403
+ * with an older reference timestamp. So, doing this on every connection will keep the unreferenced state
404
+ * tracking up-to-date.
459
405
  */
460
- if (this.activeConnection() && this.configs.shouldRunGC) {
461
- this.initializeGCStateFromBaseSnapshotP.catch((error) => {});
406
+ if (connected && this.configs.shouldRunGC) {
407
+ this.initializeOrUpdateGCState().catch((error) => {
408
+ this.mc.logger.sendErrorEvent(
409
+ {
410
+ eventName: "GCInitializationOrUpdateFailed",
411
+ gcConfigs: JSON.stringify(this.configs),
412
+ },
413
+ error,
414
+ );
415
+ });
462
416
  }
463
417
  }
464
418
 
@@ -536,8 +490,11 @@ export class GarbageCollector implements IGarbageCollector {
536
490
  const gcStats = await this.runGC(fullGC, currentReferenceTimestampMs, logger);
537
491
  event.end({
538
492
  ...gcStats,
539
- timestamp: currentReferenceTimestampMs,
540
- sweep: this.configs.shouldRunSweep,
493
+ details: {
494
+ timestamp: currentReferenceTimestampMs,
495
+ sweep: this.configs.shouldRunSweep,
496
+ tombstone: this.configs.throwOnTombstoneLoad,
497
+ },
541
498
  });
542
499
 
543
500
  /** Post-GC steps */
@@ -1163,9 +1120,25 @@ export class GarbageCollector implements IGarbageCollector {
1163
1120
  deletedAttachmentBlobCount: 0,
1164
1121
  };
1165
1122
 
1123
+ // The runtime can't reliably identify the type of deleted nodes. So, get the type here. This should
1124
+ // be good enough because the only types that participate in GC today are data stores, DDSes and blobs.
1125
+ const getDeletedNodeType = (nodeId: string): GCNodeType => {
1126
+ const pathParts = nodeId.split("/");
1127
+ if (pathParts[1] === BlobManager.basePath) {
1128
+ return GCNodeType.Blob;
1129
+ }
1130
+ if (pathParts.length === 2) {
1131
+ return GCNodeType.DataStore;
1132
+ }
1133
+ if (pathParts.length === 3) {
1134
+ return GCNodeType.SubDataStore;
1135
+ }
1136
+ return GCNodeType.Other;
1137
+ };
1138
+
1166
1139
  for (const nodeId of deletedNodes) {
1167
1140
  sweepPhaseStats.deletedNodeCount++;
1168
- const nodeType = this.runtime.getNodeType(nodeId);
1141
+ const nodeType = getDeletedNodeType(nodeId);
1169
1142
  if (nodeType === GCNodeType.DataStore) {
1170
1143
  sweepPhaseStats.deletedDataStoreCount++;
1171
1144
  } else if (nodeType === GCNodeType.Blob) {
@@ -353,7 +353,6 @@ export interface IGarbageCollectorCreateParams {
353
353
  readonly getNodePackagePath: (nodePath: string) => Promise<readonly string[] | undefined>;
354
354
  readonly getLastSummaryTimestampMs: () => number | undefined;
355
355
  readonly readAndParseBlob: ReadAndParseBlob;
356
- readonly activeConnection: () => boolean;
357
356
  readonly submitMessage: (message: ContainerRuntimeGCMessage) => void;
358
357
  }
359
358
 
@@ -111,7 +111,11 @@ export class GCSummaryStateTracker {
111
111
  /**
112
112
  * Called during GC initialization. Initialize the latest summary data from the base snapshot data.
113
113
  */
114
- public initializeBaseState(baseSnapshotData: IGarbageCollectionSnapshotData) {
114
+ public initializeBaseState(baseSnapshotData: IGarbageCollectionSnapshotData | undefined) {
115
+ if (baseSnapshotData === undefined) {
116
+ return;
117
+ }
118
+
115
119
  // If tracking state across summaries, update latest summary data from the snapshot's GC data.
116
120
  this.latestSummaryData = {
117
121
  serializedGCState: baseSnapshotData.gcState
@@ -240,13 +240,9 @@ export class GCTelemetryTracker {
240
240
  gcConfigs,
241
241
  };
242
242
 
243
- // Do not log the inactive object x events as error events as they are not the best signal for
244
- // detecting something wrong with GC either from the partner or from the runtime itself.
245
- if (state === UnreferencedState.Inactive) {
246
- this.mc.logger.sendTelemetryEvent(event);
247
- } else {
248
- this.mc.logger.sendErrorEvent(event);
249
- }
243
+ // These are logged as generic events and not errors because there can be false positives. The Tombstone
244
+ // and Delete errors are separately logged and are reliable.
245
+ this.mc.logger.sendTelemetryEvent(event);
250
246
  }
251
247
  }
252
248
  }
@@ -393,12 +389,7 @@ export class GCTelemetryTracker {
393
389
  fromPkg: fromPkg?.join("/"),
394
390
  }),
395
391
  };
396
-
397
- if (state === UnreferencedState.Inactive) {
398
- logger.sendTelemetryEvent(event);
399
- } else {
400
- logger.sendErrorEvent(event);
401
- }
392
+ logger.sendTelemetryEvent(event);
402
393
  }
403
394
  }
404
395
  this.pendingEventsQueue = [];
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/container-runtime";
9
- export const pkgVersion = "2.0.0-internal.8.0.0";
9
+ export const pkgVersion = "2.0.0-internal.8.0.2";