Unverified 提交 64744521 作者: Steven Allen 提交者: GitHub

Merge pull request #6281 from ipfs/fix/6279

gc: cancel context
...@@ -84,8 +84,6 @@ func BestEffortRoots(filesRoot *mfs.Root) ([]cid.Cid, error) { ...@@ -84,8 +84,6 @@ func BestEffortRoots(filesRoot *mfs.Root) ([]cid.Cid, error) {
} }
func GarbageCollect(n *core.IpfsNode, ctx context.Context) error { func GarbageCollect(n *core.IpfsNode, ctx context.Context) error {
ctx, cancel := context.WithCancel(ctx)
defer cancel() // in case error occurs during operation
roots, err := BestEffortRoots(n.FilesRoot) roots, err := BestEffortRoots(n.FilesRoot)
if err != nil { if err != nil {
return err return err
......
...@@ -39,6 +39,7 @@ type Result struct { ...@@ -39,6 +39,7 @@ type Result struct {
// The routine then iterates over every block in the blockstore and // The routine then iterates over every block in the blockstore and
// deletes any block that is not found in the marked set. // deletes any block that is not found in the marked set.
func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn pin.Pinner, bestEffortRoots []cid.Cid) <-chan Result { func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn pin.Pinner, bestEffortRoots []cid.Cid) <-chan Result {
ctx, cancel := context.WithCancel(ctx)
elock := log.EventBegin(ctx, "GC.lockWait") elock := log.EventBegin(ctx, "GC.lockWait")
unlocker := bs.GCLock() unlocker := bs.GCLock()
...@@ -52,6 +53,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn ...@@ -52,6 +53,7 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, dstor dstore.Datastore, pn
output := make(chan Result, 128) output := make(chan Result, 128)
go func() { go func() {
defer cancel()
defer close(output) defer close(output)
defer unlocker.Unlock() defer unlocker.Unlock()
defer elock.Done() defer elock.Done()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论