@fluidframework/container-runtime 2.0.0-dev.4.4.0.161322 → 2.0.0-dev.4.4.0.161652

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.
@@ -429,6 +429,14 @@ export class GarbageCollector implements IGarbageCollector {
429
429
  }
430
430
  }
431
431
 
432
+ /**
433
+ * Returns a the GC details generated from the base summary. This is used to initialize the GC state of the nodes
434
+ * in the container.
435
+ */
436
+ public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
437
+ return this.baseGCDetailsP;
438
+ }
439
+
432
440
  /**
433
441
  * Runs garbage collection and updates the reference / used state of the nodes in the container.
434
442
  * @returns stats of the GC run or undefined if GC did not run.
@@ -482,53 +490,157 @@ export class GarbageCollector implements IGarbageCollector {
482
490
  logger,
483
491
  { eventName: "GarbageCollection" },
484
492
  async (event) => {
485
- await this.runPreGCSteps();
486
-
487
- // Get the runtime's GC data and run GC on the reference graph in it.
488
- const gcData = await this.runtime.getGCData(fullGC);
489
- const gcResult = runGarbageCollection(gcData.gcNodes, ["/"]);
490
-
491
- const gcStats = await this.runPostGCSteps(
492
- gcData,
493
- gcResult,
494
- logger,
495
- currentReferenceTimestampMs,
496
- );
493
+ /** Pre-GC steps */
494
+ // Ensure that state has been initialized from the base snapshot data.
495
+ await this.initializeGCStateFromBaseSnapshotP;
496
+ // Let the runtime update its pending state before GC runs.
497
+ await this.runtime.updateStateBeforeGC();
498
+
499
+ /** GC step */
500
+ const gcStats = await this.runGC(fullGC, currentReferenceTimestampMs, logger);
497
501
  event.end({ ...gcStats, timestamp: currentReferenceTimestampMs });
502
+
503
+ /** Post-GC steps */
504
+ // Log pending unreferenced events such as a node being used after inactive. This is done after GC runs and
505
+ // updates its state so that we don't send false positives based on intermediate state. For example, we may get
506
+ // reference to an unreferenced node from another unreferenced node which means the node wasn't revived.
507
+ await this.telemetryTracker.logPendingEvents(logger);
508
+ this.newReferencesSinceLastRun.clear();
498
509
  this.completedRuns++;
510
+
499
511
  return gcStats;
500
512
  },
501
513
  { end: true, cancel: "error" },
502
514
  );
503
515
  }
504
516
 
505
- private async runPreGCSteps() {
506
- // Ensure that state has been initialized from the base snapshot data.
507
- await this.initializeGCStateFromBaseSnapshotP;
508
- // Let the runtime update its pending state before GC runs.
509
- await this.runtime.updateStateBeforeGC();
510
- }
511
-
512
- private async runPostGCSteps(
513
- gcData: IGarbageCollectionData,
514
- gcResult: IGCResult,
515
- logger: ITelemetryLogger,
517
+ /**
518
+ * Runs garbage collection. It does the following:
519
+ * 1. It generates / analyzes the runtime's reference graph.
520
+ * 2. Generates stats for the GC run based on previous / current GC state.
521
+ * 3. Runs Mark phase.
522
+ * 4. Runs Sweep phase.
523
+ */
524
+ private async runGC(
525
+ fullGC: boolean,
516
526
  currentReferenceTimestampMs: number,
527
+ logger: ITelemetryLogger,
517
528
  ): Promise<IGCStats> {
518
- // Generate statistics from the current run. This is done before updating the current state because it
519
- // generates some of its data based on previous state of the system.
529
+ // 1. Generate / analyze the runtime's reference graph.
530
+ // Get the reference graph (gcData) and run GC algorithm to get referenced / unreferenced nodes.
531
+ const gcData = await this.runtime.getGCData(fullGC);
532
+ const gcResult = runGarbageCollection(gcData.gcNodes, ["/"]);
533
+ // Get all referenced nodes - References in this run + references between the previous and current runs.
534
+ const allReferencedNodeIds =
535
+ this.findAllNodesReferencedBetweenGCs(gcData, this.gcDataFromLastRun, logger) ??
536
+ gcResult.referencedNodeIds;
537
+
538
+ // 2. Generate stats based on the previous / current GC state.
539
+ // Must happen before running Mark / Sweep phase because previous GC state will be updated in these stages.
520
540
  const gcStats = this.generateStats(gcResult);
521
541
 
522
- // Update the current mark state and update the runtime of all used routes or ids that used as per the GC run.
523
- const sweepReadyNodes = this.updateMarkPhase(
524
- gcData,
542
+ // 3. Run the Mark phase.
543
+ // It will mark nodes as referenced / unreferenced and return a list of node ids that are ready to be swept.
544
+ const sweepReadyNodeIds = this.runMarkPhase(
545
+ gcResult,
546
+ allReferencedNodeIds,
547
+ currentReferenceTimestampMs,
548
+ );
549
+
550
+ // 4. Run the Sweep phase.
551
+ // It will delete sweep ready nodes and return a list of deleted node ids.
552
+ const deletedNodeIds = this.runSweepPhase(
525
553
  gcResult,
554
+ sweepReadyNodeIds,
526
555
  currentReferenceTimestampMs,
527
556
  logger,
528
557
  );
558
+
559
+ this.gcDataFromLastRun = cloneGCData(
560
+ gcData,
561
+ (id: string) => deletedNodeIds.includes(id) /* filter out deleted nodes */,
562
+ );
563
+ return gcStats;
564
+ }
565
+
566
+ /**
567
+ * Runs the GC Mark phase. It does the following:
568
+ * 1. Marks all referenced nodes in this run by clearing tracking for them.
569
+ * 2. Marks unreferenced nodes in this run by starting tracking for them.
570
+ * 3. Calls the runtime to update nodes that were marked referenced.
571
+ *
572
+ * @param gcResult - The result of the GC run on the gcData.
573
+ * @param allReferencedNodeIds - Nodes referenced in this GC run + referenced between previous and current GC run.
574
+ * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp.
575
+ * @returns - A list of sweep ready nodes, i.e., nodes that ready to be deleted.
576
+ */
577
+ private runMarkPhase(
578
+ gcResult: IGCResult,
579
+ allReferencedNodeIds: string[],
580
+ currentReferenceTimestampMs: number,
581
+ ): string[] {
582
+ // 1. Marks all referenced nodes by clearing their unreferenced tracker, if any.
583
+ for (const nodeId of allReferencedNodeIds) {
584
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
585
+ if (nodeStateTracker !== undefined) {
586
+ // Stop tracking so as to clear out any running timers.
587
+ nodeStateTracker.stopTracking();
588
+ // Delete the node as we don't need to track it any more.
589
+ this.unreferencedNodesState.delete(nodeId);
590
+ }
591
+ }
592
+
593
+ // 2. Mark unreferenced nodes in this run by starting unreferenced tracking for them.
594
+ const sweepReadyNodeIds: string[] = [];
595
+ for (const nodeId of gcResult.deletedNodeIds) {
596
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
597
+ if (nodeStateTracker === undefined) {
598
+ this.unreferencedNodesState.set(
599
+ nodeId,
600
+ new UnreferencedStateTracker(
601
+ currentReferenceTimestampMs,
602
+ this.configs.inactiveTimeoutMs,
603
+ currentReferenceTimestampMs,
604
+ this.configs.sweepTimeoutMs,
605
+ ),
606
+ );
607
+ } else {
608
+ // If a node was already unreferenced, update its tracking information. Since the current reference time
609
+ // is from the ops seen, this will ensure that we keep updating unreferenced state as time moves forward.
610
+ nodeStateTracker.updateTracking(currentReferenceTimestampMs);
611
+
612
+ // If a node is sweep ready, store it so it can be returned.
613
+ if (nodeStateTracker.state === UnreferencedState.SweepReady) {
614
+ sweepReadyNodeIds.push(nodeId);
615
+ }
616
+ }
617
+ }
618
+
619
+ // 3. Call the runtime to update referenced nodes in this run.
529
620
  this.runtime.updateUsedRoutes(gcResult.referencedNodeIds);
530
621
 
531
- // Log events for objects that are ready to be deleted by sweep.
622
+ return sweepReadyNodeIds;
623
+ }
624
+
625
+ /**
626
+ * Runs the GC Sweep phase. It does the following:
627
+ * 1. Calls the runtime to delete nodes that are sweep ready.
628
+ * 2. Clears tracking for deleted nodes.
629
+ *
630
+ * @param gcResult - The result of the GC run on the gcData.
631
+ * @param sweepReadyNodes - List of nodes that are sweep ready.
632
+ * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp.
633
+ * @param logger - The logger to be used to log any telemetry.
634
+ * @returns - A list of nodes that have been deleted.
635
+ */
636
+ private runSweepPhase(
637
+ gcResult: IGCResult,
638
+ sweepReadyNodes: string[],
639
+ currentReferenceTimestampMs: number,
640
+ logger: ITelemetryLogger,
641
+ ): string[] {
642
+ // Log events for objects that are ready to be deleted by sweep. This will give us data on sweep when
643
+ // its not enabled.
532
644
  this.telemetryTracker.logSweepEvents(
533
645
  logger,
534
646
  currentReferenceTimestampMs,
@@ -537,30 +649,136 @@ export class GarbageCollector implements IGarbageCollector {
537
649
  this.getLastSummaryTimestampMs(),
538
650
  );
539
651
 
540
- let updatedGCData: IGarbageCollectionData = gcData;
541
-
542
- if (this.configs.shouldRunSweep) {
543
- updatedGCData = this.runSweepPhase(sweepReadyNodes, gcData);
544
- } else if (this.configs.testMode) {
545
- // If we are running in GC test mode, delete objects for unused routes. This enables testing scenarios
546
- // involving access to deleted data.
652
+ /**
653
+ * Currently, there are 3 modes for sweep:
654
+ * Test mode - Unreferenced nodes are immediately deleted without waiting for them to be sweep ready.
655
+ * Tombstone mode - Sweep ready modes are marked as tombstones instead of being deleted.
656
+ * Sweep mode - Sweep ready modes are deleted.
657
+ *
658
+ * These modes serve as staging for applications that want to enable sweep by providing an incremental
659
+ * way to test and validate sweep works as expected.
660
+ */
661
+ if (this.configs.testMode) {
662
+ // If we are running in GC test mode, unreferenced nodes (gcResult.deletedNodeIds) are deleted.
547
663
  this.runtime.updateUnusedRoutes(gcResult.deletedNodeIds);
548
- } else if (this.configs.tombstoneMode) {
664
+ return [];
665
+ }
666
+
667
+ if (this.configs.tombstoneMode) {
549
668
  this.tombstones = sweepReadyNodes;
550
669
  // If we are running in GC tombstone mode, update tombstoned routes. This enables testing scenarios
551
670
  // involving access to "deleted" data without actually deleting the data from summaries.
552
- // Note: we will not tombstone in test mode.
553
671
  this.runtime.updateTombstonedRoutes(this.tombstones);
672
+ return [];
554
673
  }
555
674
 
556
- this.gcDataFromLastRun = cloneGCData(updatedGCData);
675
+ if (!this.configs.shouldRunSweep) {
676
+ return [];
677
+ }
557
678
 
558
- // Log pending unreferenced events such as a node being used after inactive. This is done after GC runs and
559
- // updates its state so that we don't send false positives based on intermediate state. For example, we may get
560
- // reference to an unreferenced node from another unreferenced node which means the node wasn't revived.
561
- await this.telemetryTracker.logPendingEvents(logger);
679
+ // 1. Call the runtime to delete sweep ready nodes. The runtime returns a list of nodes it deleted.
680
+ // TODO: GC:Validation - validate that removed routes are not double delete and that the child routes of
681
+ // removed routes are deleted as well.
682
+ const deletedNodeIds = this.runtime.deleteSweepReadyNodes(sweepReadyNodes);
562
683
 
563
- return gcStats;
684
+ // 2. Clear unreferenced state tracking for deleted nodes.
685
+ for (const nodeId of deletedNodeIds) {
686
+ const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
687
+ // TODO: GC:Validation - assert that the nodeStateTracker is defined
688
+ if (nodeStateTracker !== undefined) {
689
+ // Stop tracking so as to clear out any running timers.
690
+ nodeStateTracker.stopTracking();
691
+ // Delete the node as we don't need to track it any more.
692
+ this.unreferencedNodesState.delete(nodeId);
693
+ }
694
+ // TODO: GC:Validation - assert that the deleted node is not a duplicate
695
+ this.deletedNodes.add(nodeId);
696
+ }
697
+ return deletedNodeIds;
698
+ }
699
+
700
+ /**
701
+ * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in
702
+ * time. There can be nodes that were referenced in between two runs and their unreferenced state needs to be
703
+ * updated. For example, in the following scenarios not updating the unreferenced timestamp can lead to deletion of
704
+ * these objects while there can be in-memory referenced to it:
705
+ * 1. A node transitions from `unreferenced -> referenced -> unreferenced` between two runs. When the reference is
706
+ * added, the object may have been accessed and in-memory reference to it added.
707
+ * 2. A reference is added from one unreferenced node to one or more unreferenced nodes. Even though the node[s] were
708
+ * unreferenced, they could have been accessed and in-memory reference to them added.
709
+ *
710
+ * This function identifies nodes that were referenced since the last run.
711
+ * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.
712
+ *
713
+ * @returns - a list of all nodes referenced from the last local summary until now.
714
+ */
715
+ private findAllNodesReferencedBetweenGCs(
716
+ currentGCData: IGarbageCollectionData,
717
+ previousGCData: IGarbageCollectionData | undefined,
718
+ logger: ITelemetryLogger,
719
+ ): string[] | undefined {
720
+ // If we haven't run GC before there is nothing to do.
721
+ // No previousGCData, means nothing is unreferenced, and there are no reference state trackers to clear
722
+ if (previousGCData === undefined) {
723
+ return undefined;
724
+ }
725
+
726
+ /**
727
+ * If there are references that were not explicitly notified to GC, log an error because this should never happen.
728
+ * If it does, this may result in the unreferenced timestamps of these nodes not updated when they were referenced.
729
+ */
730
+ this.telemetryTracker.logIfMissingExplicitReferences(
731
+ currentGCData,
732
+ previousGCData,
733
+ this.newReferencesSinceLastRun,
734
+ logger,
735
+ );
736
+
737
+ // No references were added since the last run so we don't have to update reference states of any unreferenced
738
+ // nodes. There is no in between state at this point.
739
+ if (this.newReferencesSinceLastRun.size === 0) {
740
+ return undefined;
741
+ }
742
+
743
+ /**
744
+ * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and
745
+ * edges that have been added since then. To do this, combine the GC data from the last run and the current
746
+ * run, and then add the references since last run.
747
+ *
748
+ * Note on why we need to combine the data from previous run, current run and all references in between -
749
+ * 1. We need data from last run because some of its references may have been deleted since then. If those
750
+ * references added new outbound references before they were deleted, we need to detect them.
751
+ *
752
+ * 2. We need new outbound references since last run because some of them may have been deleted later. If those
753
+ * references added new outbound references before they were deleted, we need to detect them.
754
+ *
755
+ * 3. We need data from the current run because currently we may not detect when DDSes are referenced:
756
+ * - We don't require DDSes handles to be stored in a referenced DDS.
757
+ * - A new data store may have "root" DDSes already created and we don't detect them today.
758
+ */
759
+ const gcDataSuperSet = concatGarbageCollectionData(previousGCData, currentGCData);
760
+ const newOutboundRoutesSinceLastRun: string[] = [];
761
+ this.newReferencesSinceLastRun.forEach((outboundRoutes: string[], sourceNodeId: string) => {
762
+ if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {
763
+ gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;
764
+ } else {
765
+ gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);
766
+ }
767
+ newOutboundRoutesSinceLastRun.push(...outboundRoutes);
768
+ });
769
+
770
+ /**
771
+ * Run GC on the above reference graph starting with root and all new outbound routes. This will generate a
772
+ * list of all nodes that could have been referenced since the last run. If any of these nodes are unreferenced,
773
+ * unreferenced, stop tracking them and remove from unreferenced list.
774
+ * Note that some of these nodes may be unreferenced now and if so, the current run will mark them as
775
+ * unreferenced and add unreferenced state.
776
+ */
777
+ const gcResult = runGarbageCollection(gcDataSuperSet.gcNodes, [
778
+ "/",
779
+ ...newOutboundRoutesSinceLastRun,
780
+ ]);
781
+ return gcResult.referencedNodeIds;
564
782
  }
565
783
 
566
784
  /**
@@ -609,14 +827,6 @@ export class GarbageCollector implements IGarbageCollector {
609
827
  };
610
828
  }
611
829
 
612
- /**
613
- * Returns a the GC details generated from the base summary. This is used to initialize the GC state of the nodes
614
- * in the container.
615
- */
616
- public async getBaseGCDetails(): Promise<IGarbageCollectionDetailsBase> {
617
- return this.baseGCDetailsP;
618
- }
619
-
620
830
  /**
621
831
  * Called to refresh the latest summary state. This happens when either a pending summary is acked or a snapshot
622
832
  * is downloaded and should be used to update the state.
@@ -727,203 +937,6 @@ export class GarbageCollector implements IGarbageCollector {
727
937
  this.sessionExpiryTimer = undefined;
728
938
  }
729
939
 
730
- /**
731
- * Updates the state of the system as per the current GC run. It does the following:
732
- * 1. Sets up the current GC state as per the gcData.
733
- * 2. Starts tracking for nodes that have become unreferenced in this run.
734
- * 3. Clears tracking for nodes that were unreferenced but became referenced in this run.
735
- * @param gcData - The data representing the reference graph on which GC is run.
736
- * @param gcResult - The result of the GC run on the gcData.
737
- * @param currentReferenceTimestampMs - The timestamp to be used for unreferenced nodes' timestamp.
738
- * @returns - A list of sweep ready nodes. (Nodes ready to be deleted)
739
- */
740
- private updateMarkPhase(
741
- gcData: IGarbageCollectionData,
742
- gcResult: IGCResult,
743
- currentReferenceTimestampMs: number,
744
- logger: ITelemetryLogger,
745
- ) {
746
- // Get references from the current GC run + references between previous and current run and then update each
747
- // node's state
748
- const allNodesReferencedBetweenGCs =
749
- this.findAllNodesReferencedBetweenGCs(gcData, this.gcDataFromLastRun, logger) ??
750
- gcResult.referencedNodeIds;
751
- this.newReferencesSinceLastRun.clear();
752
-
753
- // Iterate through the referenced nodes and stop tracking if they were unreferenced before.
754
- for (const nodeId of allNodesReferencedBetweenGCs) {
755
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
756
- if (nodeStateTracker !== undefined) {
757
- // Stop tracking so as to clear out any running timers.
758
- nodeStateTracker.stopTracking();
759
- // Delete the node as we don't need to track it any more.
760
- this.unreferencedNodesState.delete(nodeId);
761
- }
762
- }
763
-
764
- /**
765
- * If a node became unreferenced in this run, start tracking it.
766
- * If a node was already unreferenced, update its tracking information. Since the current reference time is
767
- * from the ops seen, this will ensure that we keep updating the unreferenced state as time moves forward.
768
- *
769
- * If a node is sweep ready, store and then return it.
770
- */
771
- const sweepReadyNodes: string[] = [];
772
- for (const nodeId of gcResult.deletedNodeIds) {
773
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
774
- if (nodeStateTracker === undefined) {
775
- this.unreferencedNodesState.set(
776
- nodeId,
777
- new UnreferencedStateTracker(
778
- currentReferenceTimestampMs,
779
- this.configs.inactiveTimeoutMs,
780
- currentReferenceTimestampMs,
781
- this.configs.sweepTimeoutMs,
782
- ),
783
- );
784
- } else {
785
- nodeStateTracker.updateTracking(currentReferenceTimestampMs);
786
- if (nodeStateTracker.state === UnreferencedState.SweepReady) {
787
- sweepReadyNodes.push(nodeId);
788
- }
789
- }
790
- }
791
-
792
- return sweepReadyNodes;
793
- }
794
-
795
- /**
796
- * Deletes nodes from both the runtime and garbage collection
797
- * @param sweepReadyNodes - nodes that are ready to be deleted
798
- */
799
- private runSweepPhase(sweepReadyNodes: string[], gcData: IGarbageCollectionData) {
800
- // TODO: GC:Validation - validate that removed routes are not double deleted
801
- // TODO: GC:Validation - validate that the child routes of removed routes are deleted as well
802
- const sweptRoutes = this.runtime.deleteSweepReadyNodes(sweepReadyNodes);
803
- const updatedGCData = this.deleteSweptRoutes(sweptRoutes, gcData);
804
-
805
- for (const nodeId of sweptRoutes) {
806
- const nodeStateTracker = this.unreferencedNodesState.get(nodeId);
807
- // TODO: GC:Validation - assert that the nodeStateTracker is defined
808
- if (nodeStateTracker !== undefined) {
809
- // Stop tracking so as to clear out any running timers.
810
- nodeStateTracker.stopTracking();
811
- // Delete the node as we don't need to track it any more.
812
- this.unreferencedNodesState.delete(nodeId);
813
- }
814
- // TODO: GC:Validation - assert that the deleted node is not a duplicate
815
- this.deletedNodes.add(nodeId);
816
- }
817
-
818
- return updatedGCData;
819
- }
820
-
821
- /**
822
- * @returns IGarbageCollectionData after deleting the sweptRoutes from the gcData
823
- */
824
- private deleteSweptRoutes(
825
- sweptRoutes: string[],
826
- gcData: IGarbageCollectionData,
827
- ): IGarbageCollectionData {
828
- const sweptRoutesSet = new Set<string>(sweptRoutes);
829
- const gcNodes: { [id: string]: string[] } = {};
830
- for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {
831
- if (!sweptRoutesSet.has(id)) {
832
- gcNodes[id] = Array.from(outboundRoutes);
833
- }
834
- }
835
-
836
- // TODO: GC:Validation - assert that the nodeId is in gcData
837
-
838
- return {
839
- gcNodes,
840
- };
841
- }
842
-
843
- /**
844
- * Since GC runs periodically, the GC data that is generated only tells us the state of the world at that point in
845
- * time. There can be nodes that were referenced in between two runs and their unreferenced state needs to be
846
- * updated. For example, in the following scenarios not updating the unreferenced timestamp can lead to deletion of
847
- * these objects while there can be in-memory referenced to it:
848
- * 1. A node transitions from `unreferenced -> referenced -> unreferenced` between two runs. When the reference is
849
- * added, the object may have been accessed and in-memory reference to it added.
850
- * 2. A reference is added from one unreferenced node to one or more unreferenced nodes. Even though the node[s] were
851
- * unreferenced, they could have been accessed and in-memory reference to them added.
852
- *
853
- * This function identifies nodes that were referenced since the last run.
854
- * If these nodes are currently unreferenced, they will be assigned new unreferenced state by the current run.
855
- *
856
- * @returns - a list of all nodes referenced from the last local summary until now.
857
- */
858
- private findAllNodesReferencedBetweenGCs(
859
- currentGCData: IGarbageCollectionData,
860
- previousGCData: IGarbageCollectionData | undefined,
861
- logger: ITelemetryLogger,
862
- ): string[] | undefined {
863
- // If we haven't run GC before there is nothing to do.
864
- // No previousGCData, means nothing is unreferenced, and there are no reference state trackers to clear
865
- if (previousGCData === undefined) {
866
- return undefined;
867
- }
868
-
869
- /**
870
- * If there are references that were not explicitly notified to GC, log an error because this should never happen.
871
- * If it does, this may result in the unreferenced timestamps of these nodes not updated when they were referenced.
872
- */
873
- this.telemetryTracker.logIfMissingExplicitReferences(
874
- currentGCData,
875
- previousGCData,
876
- this.newReferencesSinceLastRun,
877
- logger,
878
- );
879
-
880
- // No references were added since the last run so we don't have to update reference states of any unreferenced
881
- // nodes. There is no in between state at this point.
882
- if (this.newReferencesSinceLastRun.size === 0) {
883
- return undefined;
884
- }
885
-
886
- /**
887
- * Generate a super set of the GC data that contains the nodes and edges from last run, plus any new node and
888
- * edges that have been added since then. To do this, combine the GC data from the last run and the current
889
- * run, and then add the references since last run.
890
- *
891
- * Note on why we need to combine the data from previous run, current run and all references in between -
892
- * 1. We need data from last run because some of its references may have been deleted since then. If those
893
- * references added new outbound references before they were deleted, we need to detect them.
894
- *
895
- * 2. We need new outbound references since last run because some of them may have been deleted later. If those
896
- * references added new outbound references before they were deleted, we need to detect them.
897
- *
898
- * 3. We need data from the current run because currently we may not detect when DDSes are referenced:
899
- * - We don't require DDSes handles to be stored in a referenced DDS.
900
- * - A new data store may have "root" DDSes already created and we don't detect them today.
901
- */
902
- const gcDataSuperSet = concatGarbageCollectionData(previousGCData, currentGCData);
903
- const newOutboundRoutesSinceLastRun: string[] = [];
904
- this.newReferencesSinceLastRun.forEach((outboundRoutes: string[], sourceNodeId: string) => {
905
- if (gcDataSuperSet.gcNodes[sourceNodeId] === undefined) {
906
- gcDataSuperSet.gcNodes[sourceNodeId] = outboundRoutes;
907
- } else {
908
- gcDataSuperSet.gcNodes[sourceNodeId].push(...outboundRoutes);
909
- }
910
- newOutboundRoutesSinceLastRun.push(...outboundRoutes);
911
- });
912
-
913
- /**
914
- * Run GC on the above reference graph starting with root and all new outbound routes. This will generate a
915
- * list of all nodes that could have been referenced since the last run. If any of these nodes are unreferenced,
916
- * unreferenced, stop tracking them and remove from unreferenced list.
917
- * Note that some of these nodes may be unreferenced now and if so, the current run will mark them as
918
- * unreferenced and add unreferenced state.
919
- */
920
- const gcResult = runGarbageCollection(gcDataSuperSet.gcNodes, [
921
- "/",
922
- ...newOutboundRoutesSinceLastRun,
923
- ]);
924
- return gcResult.referencedNodeIds;
925
- }
926
-
927
940
  /**
928
941
  * Generates the stats of a garbage collection run from the given results of the run.
929
942
  * @param gcResult - The result of a GC run.
@@ -151,12 +151,19 @@ export function concatGarbageCollectionStates(
151
151
  /**
152
152
  * Helper function that clones the GC data.
153
153
  * @param gcData - The GC data to clone.
154
+ * @param filter - Optional function to filter out node ids not to be included in the cloned GC data. Returns
155
+ * true to filter out nodes.
154
156
  * @returns a clone of the given GC data.
155
157
  */
156
- export function cloneGCData(gcData: IGarbageCollectionData): IGarbageCollectionData {
158
+ export function cloneGCData(
159
+ gcData: IGarbageCollectionData,
160
+ filter?: (id: string) => boolean,
161
+ ): IGarbageCollectionData {
157
162
  const clonedGCNodes: { [id: string]: string[] } = {};
158
163
  for (const [id, outboundRoutes] of Object.entries(gcData.gcNodes)) {
159
- clonedGCNodes[id] = Array.from(outboundRoutes);
164
+ if (filter?.(id) !== true) {
165
+ clonedGCNodes[id] = Array.from(outboundRoutes);
166
+ }
160
167
  }
161
168
  return {
162
169
  gcNodes: clonedGCNodes,
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/container-runtime";
9
- export const pkgVersion = "2.0.0-dev.4.4.0.161322";
9
+ export const pkgVersion = "2.0.0-dev.4.4.0.161652";