Merge pull request #788 from jbenet/feat/pin-faster

teach pinning how to use GetBlocks
This commit is contained in:
Jeromy Johnson 2015-02-18 10:52:27 -08:00
commit fb4145141c
2 changed files with 22 additions and 3 deletions

View File

@ -7,7 +7,9 @@ import (
"errors"
"fmt"
"sync"
"time"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore"
nsds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/namespace"
"github.com/jbenet/go-ipfs/blocks/set"
@ -170,8 +172,9 @@ func (p *pinner) pinIndirectRecurse(node *mdag.Node) error {
}
func (p *pinner) pinLinks(node *mdag.Node) error {
for _, l := range node.Links {
subnode, err := l.GetNode(p.dserv)
ctx, _ := context.WithTimeout(context.Background(), time.Second*60)
for _, ng := range p.dserv.GetDAG(ctx, node) {
subnode, err := ng.Get()
if err != nil {
// TODO: Maybe just log and continue?
return err

View File

@ -34,6 +34,10 @@ func TestPinnerBasic(t *testing.T) {
p := NewPinner(dstore, dserv)
a, ak := randNode()
_, err = dserv.Add(a)
if err != nil {
t.Fatal(err)
}
// Pin A{}
err = p.Pin(a, false)
@ -45,18 +49,30 @@ func TestPinnerBasic(t *testing.T) {
t.Fatal("Failed to find key")
}
// create new node c, to be indirectly pinned through b
c, ck := randNode()
_, err = dserv.Add(c)
if err != nil {
t.Fatal(err)
}
// Create new node b, to be parent to a and c
b, _ := randNode()
err = b.AddNodeLink("child", a)
if err != nil {
t.Fatal(err)
}
c, ck := randNode()
err = b.AddNodeLink("otherchild", c)
if err != nil {
t.Fatal(err)
}
_, err = dserv.Add(b)
if err != nil {
t.Fatal(err)
}
// recursively pin B{A,C}
err = p.Pin(b, true)
if err != nil {