Skip to content

Commit

Permalink
"block rm": make channel large enough to avoid blocking
Browse files Browse the repository at this point in the history
Make the channel for the output of RmBlocks large enough to hold any
result to avoid blocking while holding the GCLock.

License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed Nov 23, 2016
1 parent ccb46fa commit ba383ed
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 @@ -256,16 +256,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 ba383ed

Please sign in to comment.