From 89493fe2b86853773f841861bf148b4b7548bf66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 25 Nov 2020 18:55:58 +0100 Subject: [PATCH] storagefsm: newDealSector review --- extern/storage-sealing/sealing.go | 52 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index a34c4582c..25397ecfb 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -306,11 +306,16 @@ func (m *Sealing) getSectorAndPadding(ctx context.Context, size abi.UnpaddedPiec ssize: ssize, } case errTooManySealing: - log.Infow("") m.unsealedInfoMap.lk.Unlock() - time.Sleep(2 * time.Second) - m.unsealedInfoMap.lk.Lock() + select { + case <-time.After(2 * time.Second): + case <-ctx.Done(): + m.unsealedInfoMap.lk.Lock() + return 0, nil, xerrors.Errorf("getting sector for piece: %w", ctx.Err()) + } + + m.unsealedInfoMap.lk.Lock() continue default: return 0, nil, xerrors.Errorf("creating new sector: %w", err) @@ -339,37 +344,34 @@ func (m *Sealing) newDealSector(ctx context.Context) (abi.SectorNumber, abi.Sect } } - if cfg.MaxWaitDealsSectors > 0 { + if cfg.MaxWaitDealsSectors > 0 && uint64(len(m.unsealedInfoMap.infos)) >= cfg.MaxWaitDealsSectors { // Too many sectors are sealing in parallel. Start sealing one, and retry // allocating the piece to a sector (we're dropping the lock here, so in // case other goroutines are also trying to create a sector, we retry in // getSectorAndPadding instead of here - otherwise if we have lots of // parallel deals in progress, we can start creating a ton of sectors // with just a single deal in them) - if uint64(len(m.unsealedInfoMap.infos)) >= cfg.MaxWaitDealsSectors { + var mostStored abi.PaddedPieceSize = math.MaxUint64 + var best abi.SectorNumber = math.MaxUint64 - var mostStored abi.PaddedPieceSize = math.MaxUint64 - var best abi.SectorNumber = math.MaxUint64 - - for sn, info := range m.unsealedInfoMap.infos { - if info.stored+1 > mostStored+1 { // 18446744073709551615 + 1 = 0 - best = sn - } + for sn, info := range m.unsealedInfoMap.infos { + if info.stored+1 > mostStored+1 { // 18446744073709551615 + 1 = 0 + best = sn } - - if best != math.MaxUint64 { - m.unsealedInfoMap.lk.Unlock() - err := m.StartPacking(best) - m.unsealedInfoMap.lk.Lock() - - if err != nil { - log.Errorf("newDealSector StartPacking error: %+v", err) - // let's pretend this is fine - } - } - - return 0, 0, errTooManySealing // will wait a bit and retry } + + if best != math.MaxUint64 { + m.unsealedInfoMap.lk.Unlock() + err := m.StartPacking(best) + m.unsealedInfoMap.lk.Lock() + + if err != nil { + log.Errorf("newDealSector StartPacking error: %+v", err) + // let's pretend this is fine + } + } + + return 0, 0, errTooManySealing // will wait a bit and retry } spt, err := m.currentSealProof(ctx)