From 547bf93f4a1e7329e0dd16f251a497898cacb3b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 8 Jun 2020 18:57:56 +0200 Subject: [PATCH] roprov: Use TryLock --- roprov.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/roprov.go b/roprov.go index ad63526c9..7a288bb39 100644 --- a/roprov.go +++ b/roprov.go @@ -22,9 +22,15 @@ func (l *readonlyProvider) AcquireSector(ctx context.Context, id abi.SectorID, e } ctx, cancel := context.WithCancel(ctx) - if err := l.index.StorageLock(ctx, id, existing, stores.FTNone); err != nil { + + // use TryLock to avoid blocking + locked, err := l.index.StorageTryLock(ctx, id, existing, stores.FTNone) + if err != nil { return stores.SectorPaths{}, nil, xerrors.Errorf("acquiring sector lock: %w", err) } + if !locked { + return stores.SectorPaths{}, nil, xerrors.Errorf("failed to acquire sector lock") + } p, _, err := l.stor.AcquireSector(ctx, id, l.spt, existing, allocate, sealing, stores.AcquireMove)