Commit 4e5b0e8d authored by Steven Allen's avatar 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: default avatarSteven Allen <steven@stebalien.com>
parent 8fd81260
......@@ -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.
var ErrNotPinned = fmt.Errorf("not pinned")
var ErrNotPinned = fmt.Errorf("not pinned or pinned indirectly")
// Unpin a given key
func (p *pinner) Unpin(ctx context.Context, c cid.Cid, recursive bool) error {
p.lock.Lock()
defer p.lock.Unlock()
reason, pinned, err := p.isPinnedWithType(c, Any)
if err != nil {
return err
}
if !pinned {
return ErrNotPinned
}
switch reason {
case "recursive":
if recursive {
p.recursePin.Remove(c)
return nil
if p.recursePin.Has(c) {
if !recursive {
return fmt.Errorf("%s is pinned recursively", c)
}
return fmt.Errorf("%s is pinned recursively", c)
case "direct":
p.recursePin.Remove(c)
return nil
}
if p.directPin.Has(c) {
p.directPin.Remove(c)
return nil
default:
return fmt.Errorf("%s is pinned indirectly under %s", c, reason)
}
return ErrNotPinned
}
func (p *pinner) isInternalPin(c cid.Cid) bool {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment