Skip to content

Commit

Permalink
storage: Block acquire when PoSt reads are ongoing
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Oct 8, 2024
1 parent aa07266 commit 40bfdfb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/paths/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Local struct {
paths map[storiface.ID]*path

localLk sync.RWMutex

postLk atomic.Int32
}

type sectorFile struct {
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit 40bfdfb

Please sign in to comment.