Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinning fixes #4451

Merged
merged 5 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
return nil, err
}

dcid, err := nd.DAG.Add(dir)
if err != nil {
return nil, fmt.Errorf("assets: DAG.Add(dir) failed: %s", err)
}

if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
return nil, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
}
Expand All @@ -93,5 +88,5 @@ func addAssetList(nd *core.IpfsNode, l []string) (*cid.Cid, error) {
return nil, fmt.Errorf("assets: Pinning flush failed: %s", err)
}

return dcid, nil
return dir.Cid(), nil
}
2 changes: 1 addition & 1 deletion cmd/ipfs/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,5 @@ func initializeIpnsKeyspace(repoRoot string) error {
return err
}

return namesys.InitializeKeyspace(ctx, nd.DAG, nd.Namesys, nd.Pinning, nd.PrivateKey)
return namesys.InitializeKeyspace(ctx, nd.Namesys, nd.Pinning, nd.PrivateKey)
}
26 changes: 7 additions & 19 deletions core/corerepo/pinning.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ import (
uio "github.com/ipfs/go-ipfs/unixfs/io"

cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
)

func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
dagnodes := make([]node.Node, 0)
out := make([]*cid.Cid, len(paths))

r := &path.Resolver{
DAG: n.DAG,
ResolveOnce: uio.ResolveUnixfsOnce,
}

for _, fpath := range paths {
for i, fpath := range paths {
p, err := path.ParsePath(fpath)
if err != nil {
return nil, err
Expand All @@ -43,20 +42,11 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
dagnodes = append(dagnodes, dagnode)
}

var out []*cid.Cid
for _, dagnode := range dagnodes {
c := dagnode.Cid()

ctx, cancel := context.WithCancel(ctx)
defer cancel()
err := n.Pinning.Pin(ctx, dagnode, recursive)
err = n.Pinning.Pin(ctx, dagnode, recursive)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
out = append(out, c)
out[i] = dagnode.Cid()
}

err := n.Pinning.Flush()
Expand All @@ -68,14 +58,14 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
}

func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
var unpinned []*cid.Cid
unpinned := make([]*cid.Cid, len(paths))

r := &path.Resolver{
DAG: n.DAG,
ResolveOnce: uio.ResolveUnixfsOnce,
}

for _, p := range paths {
for i, p := range paths {
p, err := path.ParsePath(p)
if err != nil {
return nil, err
Expand All @@ -86,13 +76,11 @@ func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool
return nil, err
}

ctx, cancel := context.WithCancel(ctx)
defer cancel()
err = n.Pinning.Unpin(ctx, k, recursive)
if err != nil {
return nil, err
}
unpinned = append(unpinned, k)
unpinned[i] = k
}

err := n.Pinning.Flush()
Expand Down
12 changes: 4 additions & 8 deletions fuse/ipns/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import (
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
emptyDir := ft.EmptyDirNode()
nodek, err := n.DAG.Add(emptyDir)
if err != nil {
return err
}

ctx, cancel := context.WithCancel(n.Context())
defer cancel()

err = n.Pinning.Pin(ctx, emptyDir, false)
emptyDir := ft.EmptyDirNode()

err := n.Pinning.Pin(ctx, emptyDir, false)
if err != nil {
return err
}
Expand All @@ -34,5 +30,5 @@ func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {

pub := nsys.NewRoutingPublisher(n.Routing, n.Repo.Datastore())

return pub.Publish(ctx, key, path.FromCid(nodek))
return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}
11 changes: 3 additions & 8 deletions namesys/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"time"

dag "github.com/ipfs/go-ipfs/merkledag"
pb "github.com/ipfs/go-ipfs/namesys/pb"
path "github.com/ipfs/go-ipfs/path"
pin "github.com/ipfs/go-ipfs/pin"
Expand Down Expand Up @@ -321,16 +320,12 @@ func ValidateIpnsRecord(k string, val []byte) error {
// InitializeKeyspace sets the ipns record for the given key to
// point to an empty directory.
// TODO: this doesnt feel like it belongs here
func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
func InitializeKeyspace(ctx context.Context, pub Publisher, pins pin.Pinner, key ci.PrivKey) error {
emptyDir := ft.EmptyDirNode()
nodek, err := ds.Add(emptyDir)
if err != nil {
return err
}

// pin recursively because this might already be pinned
// and doing a direct pin would throw an error in that case
err = pins.Pin(ctx, emptyDir, true)
err := pins.Pin(ctx, emptyDir, true)
if err != nil {
return err
}
Expand All @@ -340,7 +335,7 @@ func InitializeKeyspace(ctx context.Context, ds dag.DAGService, pub Publisher, p
return err
}

return pub.Publish(ctx, key, path.FromCid(nodek))
return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
}

func IpnsKeysForID(id peer.ID) (name, ipns string) {
Expand Down
5 changes: 4 additions & 1 deletion pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func NewPinner(dstore ds.Datastore, serv, internal mdag.DAGService) Pinner {
func (p *pinner) Pin(ctx context.Context, node node.Node, recurse bool) error {
p.lock.Lock()
defer p.lock.Unlock()
c := node.Cid()
c, err := p.dserv.Add(node)
if err != nil {
return err
}

if recurse {
if p.recursePin.Has(c) {
Expand Down