From 40bfdfb779694f57dcfa12f59e934affe6f05c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 8 Oct 2024 22:53:24 +0200 Subject: [PATCH] storage: Block acquire when PoSt reads are ongoing --- lib/paths/local.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/paths/local.go b/lib/paths/local.go index 6b8944983..47cbabd93 100644 --- a/lib/paths/local.go +++ b/lib/paths/local.go @@ -65,6 +65,8 @@ type Local struct { paths map[storiface.ID]*path localLk sync.RWMutex + + postLk atomic.Int32 } type sectorFile struct { @@ -598,6 +600,14 @@ func DoubleCallWrap(f func()) func() { } func (st *Local) AcquireSector(ctx context.Context, sid storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, pathType storiface.PathType, op storiface.AcquireMode, opts ...storiface.AcquireOption) (storiface.SectorPaths, storiface.SectorPaths, error) { + for st.postLk.Load() > 0 { + time.Sleep(100 * time.Millisecond) + } + + return st.acquireSector(ctx, sid, existing, allocate, pathType, op, opts...) +} + +func (st *Local) acquireSector(ctx context.Context, sid storiface.SectorRef, existing storiface.SectorFileType, allocate storiface.SectorFileType, pathType storiface.PathType, op storiface.AcquireMode, opts ...storiface.AcquireOption) (storiface.SectorPaths, storiface.SectorPaths, error) { if existing|allocate != existing^allocate { return storiface.SectorPaths{}, storiface.SectorPaths{}, xerrors.New("can't both find and allocate a sector") } @@ -946,6 +956,9 @@ func (st *Local) FsStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, er } func (st *Local) GenerateSingleVanillaProof(ctx context.Context, minerID abi.ActorID, si storiface.PostSectorChallenge, ppt abi.RegisteredPoStProof) ([]byte, error) { + st.postLk.Add(1) + defer st.postLk.Add(-1) + sr := storiface.SectorRef{ ID: abi.SectorID{ Miner: minerID, @@ -957,14 +970,14 @@ func (st *Local) GenerateSingleVanillaProof(ctx context.Context, minerID abi.Act var cache, sealed, cacheID, sealedID string if si.Update { - src, si, err := st.AcquireSector(ctx, sr, storiface.FTUpdate|storiface.FTUpdateCache, storiface.FTNone, storiface.PathStorage, storiface.AcquireMove) + src, si, err := st.acquireSector(ctx, sr, storiface.FTUpdate|storiface.FTUpdateCache, storiface.FTNone, storiface.PathStorage, storiface.AcquireMove) if err != nil { return nil, xerrors.Errorf("acquire sector: %w", err) } cache, sealed = src.UpdateCache, src.Update cacheID, sealedID = si.UpdateCache, si.Update } else { - src, si, err := st.AcquireSector(ctx, sr, storiface.FTSealed|storiface.FTCache, storiface.FTNone, storiface.PathStorage, storiface.AcquireMove) + src, si, err := st.acquireSector(ctx, sr, storiface.FTSealed|storiface.FTCache, storiface.FTNone, storiface.PathStorage, storiface.AcquireMove) if err != nil { return nil, xerrors.Errorf("acquire sector: %w", err) }