From 9abb9923aff21ebee030cd936b520d4b1b86df92 Mon Sep 17 00:00:00 2001
From: Hector Sanjuan <code@hector.link>
Date: Thu, 21 Jun 2018 16:01:58 +0200
Subject: [PATCH] Fix/GC: Do not recursively descend all internal pins

InternalPins() is a pinset composed by:

- Recursive pins CIDs
- Direct pins CIDs
- The empty node CID
- A root CID pointing to all above (and any of the subbuckets that may have been created)

It is only set during Flush/Load operations for the pinner.

Thus recursively exploring internal pins in order to decide which CIDs are safe
from GC only re-explores the recursive DAGs and should not be necessary.

Mind that, previously, the CidSet will correctly prune any already explored branches so
it did not have pernicious effects. But now it does.

License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
---
 pin/gc/gc.go | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/pin/gc/gc.go b/pin/gc/gc.go
index b4cf72f84..7b2c87bb4 100644
--- a/pin/gc/gc.go
+++ b/pin/gc/gc.go
@@ -169,7 +169,6 @@ func DescendantsMaxDepth(ctx context.Context, getLinks dag.GetLinks, set *cid.Se
 
 	for _, recPin := range roots {
 		set.Add(recPin.Cid)
-
 		// EnumerateChildren recursively walks the dag and adds the keys to the given set
 		err := dag.EnumerateChildrenMaxDepth(
 			ctx,
@@ -231,10 +230,10 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
 		gcs.Add(k)
 	}
 
-	err = Descendants(ctx, getLinks, gcs, pn.InternalPins())
-	if err != nil {
-		errors = true
-		output <- Result{Error: err}
+	// Internal pins are direct + recursive + empty + root cid
+	// so we can treat them as direct.
+	for _, k := range pn.InternalPins() {
+		gcs.Add(k)
 	}
 
 	if errors {
-- 
GitLab