From 0bba2bd1ba9d34f431d8dcf03608fbf5d39e1f9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 16 Nov 2022 16:25:19 +0100 Subject: [PATCH] sealing: Use FinalizeSector in snap abort for cleanup --- storage/pipeline/states_failed.go | 14 ++++-------- storage/sealer/manager.go | 34 +++++++++++++++++++++++----- storage/sealer/storiface/filetype.go | 2 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/storage/pipeline/states_failed.go b/storage/pipeline/states_failed.go index c7f85a7fa..26b8b2d53 100644 --- a/storage/pipeline/states_failed.go +++ b/storage/pipeline/states_failed.go @@ -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{}) } diff --git a/storage/sealer/manager.go b/storage/sealer/manager.go index b0f506539..30ed9ca65 100644 --- a/storage/sealer/manager.go +++ b/storage/sealer/manager.go @@ -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 diff --git a/storage/sealer/storiface/filetype.go b/storage/sealer/storiface/filetype.go index 4660dd2a7..ec3c5450c 100644 --- a/storage/sealer/storiface/filetype.go +++ b/storage/sealer/storiface/filetype.go @@ -83,7 +83,7 @@ func (t SectorFileType) String() string { case FTUpdateCache: return "update-cache" default: - return fmt.Sprintf("", t) + return fmt.Sprintf("", t, (t & ((1 << FileTypes) - 1)).Strings()) } }