Skip to content

Commit

Permalink
Merge pull request #3418 from ipfs/kevina/rmblock-noblock
Browse files Browse the repository at this point in the history
"block rm": make channel large enough to avoid blocking
  • Loading branch information
whyrusleeping committed Nov 30, 2016
2 parents 66315b8 + ba383ed commit e855047
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 5 additions & 2 deletions blocks/blockstore/util/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ type RmBlocksOpts struct {
Force bool
}

func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error {
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) {
// make the channel large enough to hold any result to avoid
// blocking while holding the GCLock
out := make(chan interface{}, len(cids))
go func() {
defer close(out)

Expand All @@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
}
}
}()
return nil
return out, nil
}

func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {
Expand Down
5 changes: 2 additions & 3 deletions core/commands/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,15 @@ It takes a list of base58 encoded multihashs to remove.

cids = append(cids, c)
}
outChan := make(chan interface{})
err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{
ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{
Quiet: quiet,
Force: force,
})
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput((<-chan interface{})(outChan))
res.SetOutput(ch)
},
PostRun: func(req cmds.Request, res cmds.Response) {
if res.Error() != nil {
Expand Down

0 comments on commit e855047

Please sign in to comment.