@fluidframework/container-runtime 2.0.0-internal.2.3.0 → 2.0.0-internal.2.4.0

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 (81) hide show
  1. package/dist/blobManager.d.ts +4 -2
  2. package/dist/blobManager.d.ts.map +1 -1
  3. package/dist/blobManager.js +43 -10
  4. package/dist/blobManager.js.map +1 -1
  5. package/dist/containerRuntime.d.ts +15 -0
  6. package/dist/containerRuntime.d.ts.map +1 -1
  7. package/dist/containerRuntime.js +28 -13
  8. package/dist/containerRuntime.js.map +1 -1
  9. package/dist/dataStoreContext.d.ts.map +1 -1
  10. package/dist/dataStoreContext.js +5 -8
  11. package/dist/dataStoreContext.js.map +1 -1
  12. package/dist/dataStores.d.ts +3 -3
  13. package/dist/dataStores.d.ts.map +1 -1
  14. package/dist/dataStores.js +14 -14
  15. package/dist/dataStores.js.map +1 -1
  16. package/dist/garbageCollection.d.ts +15 -7
  17. package/dist/garbageCollection.d.ts.map +1 -1
  18. package/dist/garbageCollection.js +101 -40
  19. package/dist/garbageCollection.js.map +1 -1
  20. package/dist/garbageCollectionConstants.d.ts +1 -0
  21. package/dist/garbageCollectionConstants.d.ts.map +1 -1
  22. package/dist/garbageCollectionConstants.js +4 -2
  23. package/dist/garbageCollectionConstants.js.map +1 -1
  24. package/dist/garbageCollectionTombstoneUtils.d.ts +5 -4
  25. package/dist/garbageCollectionTombstoneUtils.d.ts.map +1 -1
  26. package/dist/garbageCollectionTombstoneUtils.js +8 -13
  27. package/dist/garbageCollectionTombstoneUtils.js.map +1 -1
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +3 -1
  31. package/dist/index.js.map +1 -1
  32. package/dist/packageVersion.d.ts +1 -1
  33. package/dist/packageVersion.js +1 -1
  34. package/dist/packageVersion.js.map +1 -1
  35. package/dist/summarizer.js.map +1 -1
  36. package/lib/blobManager.d.ts +4 -2
  37. package/lib/blobManager.d.ts.map +1 -1
  38. package/lib/blobManager.js +44 -11
  39. package/lib/blobManager.js.map +1 -1
  40. package/lib/containerRuntime.d.ts +15 -0
  41. package/lib/containerRuntime.d.ts.map +1 -1
  42. package/lib/containerRuntime.js +27 -12
  43. package/lib/containerRuntime.js.map +1 -1
  44. package/lib/dataStoreContext.d.ts.map +1 -1
  45. package/lib/dataStoreContext.js +5 -8
  46. package/lib/dataStoreContext.js.map +1 -1
  47. package/lib/dataStores.d.ts +3 -3
  48. package/lib/dataStores.d.ts.map +1 -1
  49. package/lib/dataStores.js +15 -15
  50. package/lib/dataStores.js.map +1 -1
  51. package/lib/garbageCollection.d.ts +15 -7
  52. package/lib/garbageCollection.d.ts.map +1 -1
  53. package/lib/garbageCollection.js +103 -42
  54. package/lib/garbageCollection.js.map +1 -1
  55. package/lib/garbageCollectionConstants.d.ts +1 -0
  56. package/lib/garbageCollectionConstants.d.ts.map +1 -1
  57. package/lib/garbageCollectionConstants.js +3 -1
  58. package/lib/garbageCollectionConstants.js.map +1 -1
  59. package/lib/garbageCollectionTombstoneUtils.d.ts +5 -4
  60. package/lib/garbageCollectionTombstoneUtils.d.ts.map +1 -1
  61. package/lib/garbageCollectionTombstoneUtils.js +9 -14
  62. package/lib/garbageCollectionTombstoneUtils.js.map +1 -1
  63. package/lib/index.d.ts +1 -1
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +1 -1
  66. package/lib/index.js.map +1 -1
  67. package/lib/packageVersion.d.ts +1 -1
  68. package/lib/packageVersion.js +1 -1
  69. package/lib/packageVersion.js.map +1 -1
  70. package/lib/summarizer.js.map +1 -1
  71. package/package.json +16 -16
  72. package/src/blobManager.ts +57 -13
  73. package/src/containerRuntime.ts +38 -9
  74. package/src/dataStoreContext.ts +13 -14
  75. package/src/dataStores.ts +25 -19
  76. package/src/garbageCollection.ts +115 -42
  77. package/src/garbageCollectionConstants.ts +3 -1
  78. package/src/garbageCollectionTombstoneUtils.ts +11 -14
  79. package/src/index.ts +2 -0
  80. package/src/packageVersion.ts +1 -1
  81. package/src/summarizer.ts +1 -1
@@ -26,6 +26,7 @@ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
26
26
  const containerRuntime_1 = require("./containerRuntime");
27
27
  const dataStores_1 = require("./dataStores");
28
28
  const garbageCollectionConstants_1 = require("./garbageCollectionConstants");
29
+ const garbageCollectionTombstoneUtils_1 = require("./garbageCollectionTombstoneUtils");
29
30
  const gcSweepReadyUsageDetection_1 = require("./gcSweepReadyUsageDetection");
30
31
  const summaryFormat_1 = require("./summaryFormat");
31
32
  /** The types of GC nodes in the GC reference graph. */
@@ -144,7 +145,10 @@ class GarbageCollector {
144
145
  // Keeps a list of references (edges in the GC graph) between GC runs. Each entry has a node id and a list of
145
146
  // outbound routes from that node.
146
147
  this.newReferencesSinceLastRun = new Map();
148
+ // A list of nodes that have been tombstoned.
147
149
  this.tombstones = [];
150
+ // A list of nodes that have been deleted during sweep phase.
151
+ this.deletedNodes = new Set();
148
152
  // Map of node ids to their unreferenced state tracker.
149
153
  this.unreferencedNodesState = new Map();
150
154
  // Keeps track of unreferenced events that are logged for a node. This is used to limit the log generation to one
@@ -213,8 +217,7 @@ class GarbageCollector {
213
217
  // flag in GC options to false.
214
218
  this.gcEnabled = this.gcOptions.gcAllowed !== false;
215
219
  // The sweep phase has to be explicitly enabled by setting the sweepAllowed flag in GC options to true.
216
- // ...unless we're using the TestOverride
217
- this.sweepEnabled = this.gcOptions.sweepAllowed === true || testOverrideSweepTimeoutMs !== undefined;
220
+ this.sweepEnabled = this.gcOptions.sweepAllowed === true;
218
221
  // Set the Session Expiry only if the flag is enabled and GC is enabled.
219
222
  if (this.mc.config.getBoolean(garbageCollectionConstants_1.runSessionExpiryKey) && this.gcEnabled) {
220
223
  this.sessionExpiryTimeoutMs = (_c = this.gcOptions.sessionExpiryTimeoutMs) !== null && _c !== void 0 ? _c : garbageCollectionConstants_1.defaultSessionExpiryDurationMs;
@@ -270,8 +273,9 @@ class GarbageCollector {
270
273
  }
271
274
  // Whether we are running in test mode. In this mode, unreferenced nodes are immediately deleted.
272
275
  this.testMode = (_h = this.mc.config.getBoolean(garbageCollectionConstants_1.gcTestModeKey)) !== null && _h !== void 0 ? _h : this.gcOptions.runGCInTestMode === true;
273
- // Whether we are running in tombstone mode. This is true by default unless disabled via feature flags.
274
- this.tombstoneMode = this.mc.config.getBoolean(garbageCollectionConstants_1.disableTombstoneKey) !== true;
276
+ // Whether we are running in tombstone mode. This is enabled by default if sweep won't run. It can be disabled
277
+ // via feature flags.
278
+ this.tombstoneMode = !this.shouldRunSweep && this.mc.config.getBoolean(garbageCollectionConstants_1.disableTombstoneKey) !== true;
275
279
  // If GC ran in the container that generated the base snapshot, it will have a GC tree.
276
280
  this.wasGCRunInLatestSummary = (baseSnapshot === null || baseSnapshot === void 0 ? void 0 : baseSnapshot.trees[runtime_definitions_1.gcTreeKey]) !== undefined;
277
281
  // Get the GC data from the base snapshot. Use LazyPromise because we only want to do this once since it
@@ -321,7 +325,9 @@ class GarbageCollector {
321
325
  }
322
326
  // If there is only one node (root node just added above), either GC is disabled or we are loading from
323
327
  // the first summary generated by detached container. In both cases, GC was not run - return undefined.
324
- return Object.keys(gcState.gcNodes).length === 1 ? undefined : { gcState, tombstones: undefined };
328
+ return Object.keys(gcState.gcNodes).length === 1
329
+ ? undefined
330
+ : { gcState, tombstones: undefined, deletedNodes: undefined };
325
331
  }
326
332
  catch (error) {
327
333
  const dpe = container_utils_1.DataProcessingError.wrapIfUnrecognized(error, "FailedToInitializeGC");
@@ -434,24 +440,31 @@ class GarbageCollector {
434
440
  return Object.assign({ gcEnabled: this.gcEnabled, sweepEnabled: this.sweepEnabled, runGC: this.shouldRunGC, runSweep: this.shouldRunSweep, testMode: this.testMode, tombstoneMode: this.tombstoneMode, sessionExpiry: this.sessionExpiryTimeoutMs, sweepTimeout: this.sweepTimeoutMs, inactiveTimeout: this.inactiveTimeoutMs, trackGCState: this.trackGCState }, this.gcOptions);
435
441
  }
436
442
  /**
437
- * Called during container initialization. Initialize the tombstone state so that object are marked as tombstones
438
- * before they are loaded or used. This is important to get accurate information of whether tombstoned object are
439
- * in use or not.
443
+ * Called during container initialization. Initialize from the tombstone state in the base snapshot. This is done
444
+ * during initialization so that deleted or tombstoned objects are marked as such before they are loaded or used.
440
445
  */
441
446
  async initializeBaseState() {
442
447
  const baseSnapshotData = await this.baseSnapshotDataP;
443
448
  /**
444
- * The base snapshot data or tombstone state will not be present if the container is loaded from:
449
+ * The base snapshot data will not be present if the container is loaded from:
445
450
  * 1. The first summary created by the detached container.
446
451
  * 2. A summary that was generated with GC disabled.
447
452
  * 3. A summary that was generated before GC even existed.
448
- * 4. A summary that was generated with tombstone feature disabled.
449
453
  */
450
- if (!this.tombstoneMode || (baseSnapshotData === null || baseSnapshotData === void 0 ? void 0 : baseSnapshotData.tombstones) === undefined) {
454
+ if (baseSnapshotData === undefined) {
451
455
  return;
452
456
  }
453
- this.tombstones = Array.from(baseSnapshotData.tombstones);
454
- this.runtime.updateTombstonedRoutes(this.tombstones);
457
+ // Initialize the deleted nodes from the snapshot. This is done irrespective of whether sweep is enabled or not
458
+ // to identify deleted nodes' usage.
459
+ if (baseSnapshotData.deletedNodes !== undefined) {
460
+ this.deletedNodes = new Set(baseSnapshotData.deletedNodes);
461
+ }
462
+ // If running in tombstone mode, initialize the tombstone state from the snapshot. Also, notify the runtime of
463
+ // tombstone routes.
464
+ if (this.tombstoneMode && baseSnapshotData.tombstones !== undefined) {
465
+ this.tombstones = Array.from(baseSnapshotData.tombstones);
466
+ this.runtime.updateTombstonedRoutes(this.tombstones);
467
+ }
455
468
  }
456
469
  /**
457
470
  * Update state from the given snapshot data. This is done during load and during refreshing state from a snapshot.
@@ -478,9 +491,30 @@ class GarbageCollector {
478
491
  }
479
492
  ;
480
493
  this.unreferencedNodesState.clear();
481
- // If tombstone mode is enabled, update tombstone information and also update all tombstoned nodes in the
482
- // container as per the state in the snapshot data.
483
- if (this.tombstoneMode) {
494
+ // If running sweep, the tombstone state represents the list of nodes that have been deleted during sweep.
495
+ // If running in tombstone mode, the tombstone state represents the list of nodes that have been marked as
496
+ // tombstones.
497
+ // If this call is because we are refreshing from a snapshot due to an ack, it is likely that the GC state
498
+ // in the snapshot is newer than this client's. And so, the deleted / tombstone nodes need to be updated.
499
+ if (this.shouldRunSweep) {
500
+ const snapshotDeletedNodes = (snapshotData === null || snapshotData === void 0 ? void 0 : snapshotData.tombstones) ? new Set(snapshotData.tombstones) : undefined;
501
+ // If the snapshot contains deleted nodes that are not yet deleted by this client, ask the runtime to
502
+ // delete them.
503
+ if (snapshotDeletedNodes !== undefined) {
504
+ const newDeletedNodes = [];
505
+ for (const nodeId of snapshotDeletedNodes) {
506
+ if (!this.deletedNodes.has(nodeId)) {
507
+ newDeletedNodes.push(nodeId);
508
+ }
509
+ }
510
+ if (newDeletedNodes.length > 0) {
511
+ // Call container runtime to delete these nodes and add deleted nodes to this.deletedNodes.
512
+ }
513
+ }
514
+ }
515
+ else if (this.tombstoneMode) {
516
+ // The snapshot may contain more or fewer tombstone nodes than this client. Update tombstone state and
517
+ // notify the runtime to update its state as well.
484
518
  this.tombstones = (snapshotData === null || snapshotData === void 0 ? void 0 : snapshotData.tombstones) ? Array.from(snapshotData.tombstones) : [];
485
519
  this.runtime.updateTombstonedRoutes(this.tombstones);
486
520
  }
@@ -505,6 +539,7 @@ class GarbageCollector {
505
539
  this.latestSummaryData = {
506
540
  serializedGCState: JSON.stringify(generateSortedGCState(snapshotData.gcState)),
507
541
  serializedTombstones: JSON.stringify(snapshotData.tombstones),
542
+ serializedDeletedNodes: JSON.stringify(snapshotData.deletedNodes),
508
543
  };
509
544
  }
510
545
  }
@@ -624,17 +659,25 @@ class GarbageCollector {
624
659
  };
625
660
  }
626
661
  const serializedGCState = JSON.stringify(generateSortedGCState(gcState));
662
+ // Serialize and write deleted nodes, if any. This is done irrespective of whether sweep is enabled or not so
663
+ // to identify deleted nodes' usage.
664
+ const serializedDeletedNodes = this.deletedNodes.size > 0
665
+ ? JSON.stringify(Array.from(this.deletedNodes).sort())
666
+ : undefined;
667
+ // If running in tombstone mode, serialize and write tombstones, if any.
627
668
  const serializedTombstones = this.tombstoneMode
628
669
  ? (this.tombstones.length > 0 ? JSON.stringify(this.tombstones.sort()) : undefined)
629
670
  : undefined;
630
671
  /**
631
- * Incremental summary of GC data - If any of the GC state or tombstone state hasn't changed since the last
632
- * summary, send summary handles for them. Otherwise, send the data in summary blobs.
672
+ * Incremental summary of GC data - If none of GC state, deleted nodes or tombstones changed since last summary,
673
+ * write summary handle instead of summary tree for GC.
674
+ * Otherwise, write the GC summary tree. In the tree, for each of these that changed, write a summary blob and
675
+ * for each of these that did not change, write a summary handle.
633
676
  */
634
677
  if (this.trackGCState) {
635
- this.pendingSummaryData = { serializedGCState, serializedTombstones };
678
+ this.pendingSummaryData = { serializedGCState, serializedTombstones, serializedDeletedNodes };
636
679
  if (trackState && !fullTree && this.latestSummaryData !== undefined) {
637
- // If neither GC state or tombstone state changed, send a summary handle for the entire GC data.
680
+ // If nothing changed since last summary, send a summary handle for the entire GC data.
638
681
  if (this.latestSummaryData.serializedGCState === serializedGCState
639
682
  && this.latestSummaryData.serializedTombstones === serializedTombstones) {
640
683
  const stats = (0, runtime_utils_1.mergeStats)();
@@ -648,24 +691,25 @@ class GarbageCollector {
648
691
  stats,
649
692
  };
650
693
  }
651
- // If either or both of GC state or tombstone state changed, build a GC summary tree.
652
- return this.buildGCSummaryTree(serializedGCState, serializedTombstones, true /* trackState */);
694
+ // If some state changed, build a GC summary tree.
695
+ return this.buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, true /* trackState */);
653
696
  }
654
697
  }
655
698
  // If not tracking GC state, build a GC summary tree without any summary handles.
656
- return this.buildGCSummaryTree(serializedGCState, serializedTombstones, false /* trackState */);
699
+ return this.buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, false /* trackState */);
657
700
  }
658
701
  /**
659
- * Builds the GC summary tree which contains GC state and tombstone state.
660
- * If trackState is false, both GC state and tombstone state are written as summary blobs.
661
- * If trackState is true, summary blob is written for GC state or tombstone state if they changed.
702
+ * Builds the GC summary tree which contains GC state, deleted nodes and tombstones.
703
+ * If trackState is false, all of GC state, deleted nodes and tombstones are written as summary blobs.
704
+ * If trackState is true, only states that changed are written. Rest are written as handles.
662
705
  * @param serializedGCState - The GC state serialized as string.
663
- * @param serializedTombstones - THe tombstone state serialized as string.
706
+ * @param serializedTombstones - The tombstone state serialized as string.
707
+ * @param serializedDeletedNodes - Deleted nodes serialized as string.
664
708
  * @param trackState - Whether we are tracking GC state across summaries.
665
709
  * @returns the GC summary tree.
666
710
  */
667
- buildGCSummaryTree(serializedGCState, serializedTombstones, trackState) {
668
- var _a, _b;
711
+ buildGCSummaryTree(serializedGCState, serializedTombstones, serializedDeletedNodes, trackState) {
712
+ var _a, _b, _c;
669
713
  const gcStateBlobKey = `${runtime_definitions_1.gcBlobPrefix}_root`;
670
714
  const builder = new runtime_utils_1.SummaryTreeBuilder();
671
715
  // If the GC state hasn't changed, write a summary handle, else write a summary blob for it.
@@ -675,16 +719,26 @@ class GarbageCollector {
675
719
  else {
676
720
  builder.addBlob(gcStateBlobKey, serializedGCState);
677
721
  }
678
- // If there is no tombstone data, return only the GC state.
679
- if (serializedTombstones === undefined) {
722
+ // If tombstones exist, write a summary handle if it hasn't changed. If it has changed, write a
723
+ // summary blob.
724
+ if (serializedTombstones !== undefined) {
725
+ if (((_b = this.latestSummaryData) === null || _b === void 0 ? void 0 : _b.serializedTombstones) === serializedTombstones && trackState) {
726
+ builder.addHandle(runtime_definitions_1.gcTombstoneBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${runtime_definitions_1.gcTombstoneBlobKey}`);
727
+ }
728
+ else {
729
+ builder.addBlob(runtime_definitions_1.gcTombstoneBlobKey, serializedTombstones);
730
+ }
731
+ }
732
+ // If there are no deleted nodes, return the summary tree.
733
+ if (serializedDeletedNodes === undefined) {
680
734
  return builder.getSummaryTree();
681
735
  }
682
- // If the tombstone state hasn't changed, write a summary handle, else write a summary blob for it.
683
- if (((_b = this.latestSummaryData) === null || _b === void 0 ? void 0 : _b.serializedTombstones) === serializedTombstones && trackState) {
684
- builder.addHandle(runtime_definitions_1.gcTombstoneBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${runtime_definitions_1.gcTombstoneBlobKey}`);
736
+ // If the deleted nodes hasn't changed, write a summary handle, else write a summary blob for it.
737
+ if (((_c = this.latestSummaryData) === null || _c === void 0 ? void 0 : _c.serializedDeletedNodes) === serializedDeletedNodes && trackState) {
738
+ builder.addHandle(runtime_definitions_1.gcDeletedBlobKey, protocol_definitions_1.SummaryType.Blob, `/${runtime_definitions_1.gcTreeKey}/${runtime_definitions_1.gcDeletedBlobKey}`);
685
739
  }
686
740
  else {
687
- builder.addBlob(runtime_definitions_1.gcTombstoneBlobKey, serializedTombstones);
741
+ builder.addBlob(runtime_definitions_1.gcDeletedBlobKey, serializedDeletedNodes);
688
742
  }
689
743
  return builder.getSummaryTree();
690
744
  }
@@ -780,7 +834,7 @@ class GarbageCollector {
780
834
  * @param toNodePath - The node to which the reference is added.
781
835
  */
782
836
  addedOutboundReference(fromNodePath, toNodePath) {
783
- var _a, _b;
837
+ var _a;
784
838
  if (!this.shouldRunGC) {
785
839
  return;
786
840
  }
@@ -800,15 +854,22 @@ class GarbageCollector {
800
854
  else if (nodeType === exports.GCNodeType.Blob) {
801
855
  eventName = "GC_Tombstone_Blob_Revived";
802
856
  }
803
- this.mc.logger.sendTelemetryEvent({
857
+ (0, garbageCollectionTombstoneUtils_1.sendGCTombstoneEvent)(this.mc, {
804
858
  eventName,
859
+ category: "generic",
805
860
  isSummarizerClient: this.isSummarizerClient,
806
861
  url: (0, garbage_collector_1.trimLeadingSlashes)(toNodePath),
807
862
  nodeType,
808
- throwOnTombstoneUsage: (_b = this.mc.config.getBoolean(garbageCollectionConstants_1.throwOnTombstoneUsageKey)) !== null && _b !== void 0 ? _b : false,
809
- });
863
+ }, undefined /* packagePath */);
810
864
  }
811
865
  }
866
+ /**
867
+ * Returns whether a node with the given path has been deleted or not. This can be used by the runtime to identify
868
+ * cases where objects are used after they are deleted and throw / log errors accordingly.
869
+ */
870
+ isNodeDeleted(nodePath) {
871
+ return this.deletedNodes.has(nodePath);
872
+ }
812
873
  dispose() {
813
874
  var _a;
814
875
  (_a = this.sessionExpiryTimer) === null || _a === void 0 ? void 0 : _a.clear();
@@ -1120,7 +1181,7 @@ class GarbageCollector {
1120
1181
  this.mc.logger.sendErrorEvent(event);
1121
1182
  }
1122
1183
  }
1123
- // If SweepReady Usage Detection is enabed, the handler may close the interactive container.
1184
+ // If SweepReady Usage Detection is enabled, the handler may close the interactive container.
1124
1185
  // Once Sweep is fully implemented, this will be removed since the objects will be gone
1125
1186
  // and errors will arise elsewhere in the runtime
1126
1187
  if (state === exports.UnreferencedState.SweepReady) {