Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sealing: Fix restartSectors race #6495

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions extern/storage-sealing/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ func planCommitting(events []statemachine.Event, state *SectorInfo) (uint64, err
}

func (m *Sealing) restartSectors(ctx context.Context) error {
defer m.startupWait.Done()

trackedSectors, err := m.ListSectors()
if err != nil {
log.Errorf("loading sector list: %+v", err)
Expand All @@ -539,6 +541,7 @@ func (m *Sealing) restartSectors(ctx context.Context) error {
}

func (m *Sealing) ForceSectorState(ctx context.Context, id abi.SectorNumber, state SectorState) error {
m.startupWait.Wait()
return m.sectors.Send(id, SectorForceState{state})
}

Expand Down
2 changes: 2 additions & 0 deletions extern/storage-sealing/garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func (m *Sealing) PledgeSector(ctx context.Context) (storage.SectorRef, error) {
m.startupWait.Wait()

m.inputLk.Lock()
defer m.inputLk.Unlock()

Expand Down
3 changes: 3 additions & 0 deletions extern/storage-sealing/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ func (m *Sealing) updateInput(ctx context.Context, sp abi.RegisteredSealProof) e
}

func (m *Sealing) tryCreateDealSector(ctx context.Context, sp abi.RegisteredSealProof) error {
m.startupWait.Wait()
if m.creating != nil {
return nil // new sector is being created right now
}
Expand Down Expand Up @@ -446,7 +447,9 @@ func (m *Sealing) createSector(ctx context.Context, cfg sealiface.Config, sp abi
}

func (m *Sealing) StartPacking(sid abi.SectorNumber) error {
m.startupWait.Wait()
log.Infow("starting to seal deal sector", "sector", sid, "trigger", "user")

return m.sectors.Send(uint64(sid), SectorStartPacking{})
}

Expand Down
7 changes: 7 additions & 0 deletions extern/storage-sealing/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type Sealing struct {
feeCfg config.MinerFeeConfig
events Events

startupWait sync.WaitGroup

maddr address.Address

sealer sectorstorage.SectorManager
Expand Down Expand Up @@ -162,6 +164,7 @@ func New(api SealingAPI, fc config.MinerFeeConfig, events Events, maddr address.
bySector: map[abi.SectorID]statSectorState{},
},
}
s.startupWait.Add(1)

s.sectors = statemachine.New(namespace.Wrap(ds, datastore.NewKey(SectorStorePrefix)), s, SectorInfo{})

Expand Down Expand Up @@ -189,10 +192,14 @@ func (m *Sealing) Stop(ctx context.Context) error {
}

func (m *Sealing) Remove(ctx context.Context, sid abi.SectorNumber) error {
m.startupWait.Wait()

return m.sectors.Send(uint64(sid), SectorRemove{})
}

func (m *Sealing) Terminate(ctx context.Context, sid abi.SectorNumber) error {
m.startupWait.Wait()

return m.sectors.Send(uint64(sid), SectorTerminate{})
}

Expand Down