sealing: Use FinalizeSector in snap abort for cleanup

This commit is contained in:
Łukasz Magiera 2022-11-16 16:25:19 +01:00
parent 7512f82a8d
commit 0bba2bd1ba
3 changed files with 33 additions and 17 deletions

View File

@ -17,6 +17,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
)
var MinRetryTime = 1 * time.Minute
@ -430,19 +431,12 @@ func (m *Sealing) handleAbortUpgrade(ctx statemachine.Context, sector SectorInfo
return xerrors.Errorf("removing CC update files from sector storage")
}
cfg, err := m.getConfig()
if err != nil {
return xerrors.Errorf("getting sealing config: %w", err)
}
// This removes the unsealed file from all storage
// TODO: Pass full sector range
if err := m.sealer.ReleaseUnsealed(ctx.Context(), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(sector.CCPieces, true, cfg.AlwaysKeepUnsealedCopy)); err != nil {
// This removes the unsealed file from all storage, and makes sure sealed/unsealed files only exist in long-term-storage
// note: we're not keeping anything unsealed because we're reverting to CC
if err := m.sealer.FinalizeSector(ctx.Context(), m.minerSector(sector.SectorType, sector.SectorNumber), []storiface.Range{}); err != nil {
log.Error(err)
}
// TODO: Remove sealed/cache copies
return ctx.Send(SectorRevertUpgradeToProving{})
}

View File

@ -621,6 +621,15 @@ func (m *Manager) FinalizeSector(ctx context.Context, sector storiface.SectorRef
return xerrors.Errorf("acquiring sector lock: %w", err)
}
/*
We want to:
* Trim cache
* (partially) free unsealed data
* Move stuff to long-term storage
*/
// first check if the unsealed file exists anywhere; If it doesn't ignore it
unsealed := storiface.FTUnsealed
{
@ -631,21 +640,34 @@ func (m *Manager) FinalizeSector(ctx context.Context, sector storiface.SectorRef
if len(unsealedStores) == 0 { // Is some edge-cases unsealed sector may not exist already, that's fine
unsealed = storiface.FTNone
} else {
// remove redundant copies if there are any
if err := m.storage.RemoveCopies(ctx, sector.ID, storiface.FTUnsealed); err != nil {
return xerrors.Errorf("remove copies (unsealed): %w", err)
}
}
}
// Make sure that the sealed file is still in sealing storage; In case it already
// isn't, we want to do finalize in long-term storage
pathType := storiface.PathStorage
// remove redundant copies if there are any
if err := m.storage.RemoveCopies(ctx, sector.ID, storiface.FTSealed); err != nil {
return xerrors.Errorf("remove copies (sealed): %w", err)
}
if err := m.storage.RemoveCopies(ctx, sector.ID, storiface.FTCache); err != nil {
return xerrors.Errorf("remove copies (cache): %w", err)
}
// Make sure that the cache files are still in sealing storage; In case not,
// we want to do finalize in long-term storage
cachePathType := storiface.PathStorage
{
sealedStores, err := m.index.StorageFindSector(ctx, sector.ID, storiface.FTSealed, 0, false)
sealedStores, err := m.index.StorageFindSector(ctx, sector.ID, storiface.FTCache, 0, false)
if err != nil {
return xerrors.Errorf("finding sealed sector: %w", err)
}
for _, store := range sealedStores {
if store.CanSeal {
pathType = storiface.PathSealing
cachePathType = storiface.PathSealing
break
}
}
@ -656,7 +678,7 @@ func (m *Manager) FinalizeSector(ctx context.Context, sector storiface.SectorRef
selector := newExistingSelector(m.index, sector.ID, storiface.FTCache, false)
err := m.sched.Schedule(ctx, sector, sealtasks.TTFinalize, selector,
m.schedFetch(sector, storiface.FTCache|unsealed, pathType, storiface.AcquireMove),
m.schedFetch(sector, storiface.FTCache|unsealed, cachePathType, storiface.AcquireMove),
func(ctx context.Context, w Worker) error {
_, err := m.waitSimpleCall(ctx)(w.FinalizeSector(ctx, sector, keepUnsealed))
return err

View File

@ -83,7 +83,7 @@ func (t SectorFileType) String() string {
case FTUpdateCache:
return "update-cache"
default:
return fmt.Sprintf("<unknown %d>", t)
return fmt.Sprintf("<unknown %d %v>", t, (t & ((1 << FileTypes) - 1)).Strings())
}
}