提交 f0addb43 作者: Steven Allen

pin: don't walk all pinned blocks when removing a non-existent pin

We do this _just_ to make the error nicer but it's really slow. Additionally, we
do it while holding the pin lock, blocking all other pin operations.

fixes #6295

License: MIT
Signed-off-by: 's avatarSteven Allen <steven@stebalien.com>
上级 fdbd501f
...@@ -263,32 +263,24 @@ func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error { ...@@ -263,32 +263,24 @@ func (p *pinner) Pin(ctx context.Context, node ipld.Node, recurse bool) error {
} }
// ErrNotPinned is returned when trying to unpin items which are not pinned. // ErrNotPinned is returned when trying to unpin items which are not pinned.
var ErrNotPinned = fmt.Errorf("not pinned") var ErrNotPinned = fmt.Errorf("not pinned or pinned indirectly")
// Unpin a given key // Unpin a given key
func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error { func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error {
p.lock.Lock() p.lock.Lock()
defer p.lock.Unlock() defer p.lock.Unlock()
reason, pinned, err := p.isPinnedWithType(c, Any) if p.recursePin.Has(c) {
if err != nil { if !recursive {
return err return fmt.Errorf("%s is pinned recursively", c)
}
if !pinned {
return ErrNotPinned
}
switch reason {
case "recursive":
if recursive {
p.recursePin.Remove(c)
return nil
} }
return fmt.Errorf("%s is pinned recursively", c) p.recursePin.Remove(c)
case "direct": return nil
}
if p.directPin.Has(c) {
p.directPin.Remove(c) p.directPin.Remove(c)
return nil return nil
default:
return fmt.Errorf("%s is pinned indirectly under %s", c, reason)
} }
return ErrNotPinned
} }
func (p *pinner) isInternalPin(c cid.Cid) bool { func (p *pinner) isInternalPin(c cid.Cid) bool {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论