Skip to content

Commit

Permalink
Checkpoint.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed Jun 20, 2016
1 parent 3868ef7 commit ed601f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
12 changes: 10 additions & 2 deletions core/corerepo/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func NewGC(n *core.IpfsNode) (*GC, error) {
func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel() // in case error occurs during operation
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning, n.FilesRoot)
rootDag, err := n.FilesRoot.GetValue().GetNode()
if err != nil {
return err
}
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning, rootDag)
if err != nil {
return err
}
Expand All @@ -93,7 +97,11 @@ func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
}

func GarbageCollectAsync(n *core.IpfsNode, ctx context.Context) (<-chan *KeyRemoved, error) {
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning, n.FilesRoot)
rootDag, err := n.FilesRoot.GetValue().GetNode()
if err != nil {
return nil, err
}
rmed, err := gc.GC(ctx, n.Blockstore, n.Pinning, rootDag)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion core/coreunix/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ func TestAddGCLive(t *testing.T) {

var gcout <-chan key.Key
gcstarted := make(chan struct{})
rootDag, err := node.FilesRoot.GetValue().GetNode()
if err != nil {
t.Fatal(err.Error())
}
go func() {
defer close(gcstarted)
gcchan, err := gc.GC(context.Background(), node.Blockstore, node.Pinning, node.FilesRoot)
gcchan, err := gc.GC(context.Background(), node.Blockstore, node.Pinning, rootDag)
if err != nil {
log.Error("GC ERROR:", err)
errs <- err
Expand Down
11 changes: 7 additions & 4 deletions merkledag/merkledag.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,18 @@ func EnumerateChildren(ctx context.Context, ds DAGService, root *Node, set key.K
// Like EnumerateChildren but will not fail if Get failes due to key
// not existing
func EnumerateChildrenBestEffort(ctx context.Context, ds DAGService, root *Node, set key.KeySet) error {
loop:
for _, lnk := range root.Links {
k := key.Key(lnk.Hash)
if !set.Has(k) {
set.Add(k)
child, err := ds.Get(ctx, k)
if err == ErrNotFound {
continue
}
if err != nil {
switch err {
case ErrNotFound:
continue loop
case nil:
break
default:
return err
}
err = EnumerateChildrenBestEffort(ctx, ds, child, set)
Expand Down
11 changes: 3 additions & 8 deletions pin/gc/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
bserv "github.com/ipfs/go-ipfs/blockservice"
offline "github.com/ipfs/go-ipfs/exchange/offline"
dag "github.com/ipfs/go-ipfs/merkledag"
mfs "github.com/ipfs/go-ipfs/mfs"
pin "github.com/ipfs/go-ipfs/pin"

logging "gx/ipfs/QmYtB7Qge8cJpXc4irsEp8zRqfnZMBeB7aTrMEkPk67DRv/go-log"
Expand All @@ -24,7 +23,7 @@ var log = logging.Logger("gc")
//
// The routine then iterates over every block in the blockstore and
// deletes any block that is not found in the marked set.
func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner, filesRoot *mfs.Root) (<-chan key.Key, error) {
func GC(ctx context.Context, bs bstore.GCBlockstore, pn pin.Pinner, filesRoot *dag.Node) (<-chan key.Key, error) {
unlocker := bs.GCLock()

bsrv := bserv.New(bs, offline.Exchange(bs))
Expand Down Expand Up @@ -89,7 +88,7 @@ func Descendants(ctx context.Context, ds dag.DAGService, set key.KeySet, roots [
return nil
}

func ColoredSet(ctx context.Context, pn pin.Pinner, ds dag.DAGService, filesRoot *mfs.Root) (key.KeySet, error) {
func ColoredSet(ctx context.Context, pn pin.Pinner, ds dag.DAGService, filesRoot *dag.Node) (key.KeySet, error) {
// KeySet currently implemented in memory, in the future, may be bloom filter or
// disk backed to conserve memory.
gcs := key.NewKeySet()
Expand All @@ -98,11 +97,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ds dag.DAGService, filesRoot
return nil, err
}

rootDag, err := filesRoot.GetValue().GetNode()
if err != nil {
return nil, err
}
err = dag.EnumerateChildrenBestEffort(ctx, ds, rootDag, gcs)
err = dag.EnumerateChildrenBestEffort(ctx, ds, filesRoot, gcs)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ed601f6

Please sign in to comment.