Skip to content

Commit

Permalink
flush pinning improvements
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
  • Loading branch information
whyrusleeping committed Feb 8, 2016
1 parent 1feea8b commit d2e0d73
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
7 changes: 5 additions & 2 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,11 @@ func (n *IpfsNode) loadFilesRoot() error {
return err
}

err = n.Pinning.Pin(n.Context(), nnd, true)
if err != nil {
if err := n.Pinning.Pin(n.Context(), nnd, true); err != nil {
return err
}

if err := n.Pinning.Flush(); err != nil {
return err
}

Expand Down
22 changes: 21 additions & 1 deletion mfs/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ func DirLookup(d *Directory, pth string) (FSNode, error) {

func FlushPath(r *Root, pth string) error {
parts := path.SplitList(strings.Trim(pth, "/"))
if len(parts) == 1 && parts[0] == "" {
parts = nil
}

d, ok := r.GetValue().(*Directory)
if !ok {
Expand All @@ -214,12 +217,24 @@ func FlushPath(r *Root, pth string) error {
}

r.repub.Update(k)
r.repub.WaitPub()

return nil
}

func flushPathRec(d *Directory, parts []string) (*dag.Node, error) {
if len(parts) == 0 {
return d.GetNode()
nd, err := d.GetNode()
if err != nil {
return nil, err
}

_, err = d.dserv.Add(nd)
if err != nil {
return nil, err
}

return nd, nil
}

d.Lock()
Expand All @@ -243,6 +258,11 @@ func flushPathRec(d *Directory, parts []string) (*dag.Node, error) {
return nil, err
}

_, err = d.dserv.Add(newnode)
if err != nil {
return nil, err
}

d.node = newnode
return newnode, nil
case *File:
Expand Down
19 changes: 15 additions & 4 deletions mfs/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type Republisher struct {
TimeoutShort time.Duration
Publish chan struct{}
pubfunc PubFunc
pubnowch chan struct{}
pubnowch chan chan struct{}

ctx context.Context
cancel func()
Expand All @@ -190,7 +190,7 @@ func NewRepublisher(ctx context.Context, pf PubFunc, tshort, tlong time.Duration
TimeoutLong: tlong,
Publish: make(chan struct{}, 1),
pubfunc: pf,
pubnowch: make(chan struct{}),
pubnowch: make(chan chan struct{}),
ctx: ctx,
cancel: cancel,
}
Expand All @@ -204,11 +204,17 @@ func (p *Republisher) setVal(k key.Key) {

func (p *Republisher) pubNow() {
select {
case p.pubnowch <- struct{}{}:
case p.pubnowch <- nil:
default:
}
}

func (p *Republisher) WaitPub() {
wait := make(chan struct{})
p.pubnowch <- wait
<-wait
}

func (p *Republisher) Close() error {
err := p.publish(p.ctx)
p.cancel()
Expand All @@ -235,6 +241,8 @@ func (np *Republisher) Run() {
longer := time.After(np.TimeoutLong)

wait:
var pubnowresp chan struct{}

select {
case <-np.ctx.Done():
return
Expand All @@ -243,10 +251,13 @@ func (np *Republisher) Run() {
goto wait
case <-quick:
case <-longer:
case <-np.pubnowch:
case pubnowresp = <-np.pubnowch:
}

err := np.publish(np.ctx)
if pubnowresp != nil {
pubnowresp <- struct{}{}
}
if err != nil {
log.Error("republishRoot error: %s", err)
}
Expand Down
10 changes: 7 additions & 3 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,13 @@ test_files_api() {
test_cmp root_hash_exp root_hash
'

test_expect_success "root hash is pinned" '
ipfs pin ls
return 1
test_expect_success "flush root succeeds" '
ipfs files flush /
'

test_expect_success "root hash is pinned after flush" '
ipfs pin ls > pins &&
grep $EXP_ROOT_HASH pins || (cat pins && exit 1)
'

# test mv
Expand Down

0 comments on commit d2e0d73

Please sign in to comment.