From 68f3e4483ffe3ac7b7da8c726ea91f1865494158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 5 Apr 2022 16:45:07 -0400 Subject: [PATCH] fix: sealing: Release unsealed sector files after snapdeals abort --- extern/sector-storage/manager.go | 18 +++++++++++++++++- extern/storage-sealing/states_failed.go | 10 ++++++++++ extern/storage-sealing/states_proving.go | 9 --------- .../storage-sealing/states_replica_update.go | 2 +- extern/storage-sealing/states_sealing.go | 2 +- extern/storage-sealing/types.go | 4 ++-- 6 files changed, 31 insertions(+), 14 deletions(-) diff --git a/extern/sector-storage/manager.go b/extern/sector-storage/manager.go index 6af927786..7e1f8fb37 100644 --- a/extern/sector-storage/manager.go +++ b/extern/sector-storage/manager.go @@ -701,7 +701,23 @@ func (m *Manager) FinalizeReplicaUpdate(ctx context.Context, sector storage.Sect } func (m *Manager) ReleaseUnsealed(ctx context.Context, sector storage.SectorRef, safeToFree []storage.Range) error { - return nil + ssize, err := sector.ProofType.SectorSize() + if err != nil { + return err + } + if len(safeToFree) != 0 || safeToFree[0].Offset != 0 || safeToFree[0].Size.Padded() != abi.PaddedPieceSize(ssize) { + // todo support partial free + return nil + } + + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + if err := m.index.StorageLock(ctx, sector.ID, storiface.FTNone, storiface.FTUnsealed); err != nil { + return xerrors.Errorf("acquiring sector lock: %w", err) + } + + return m.storage.Remove(ctx, sector.ID, storiface.FTUnsealed, true, nil) } func (m *Manager) ReleaseSectorKey(ctx context.Context, sector storage.SectorRef) error { diff --git a/extern/storage-sealing/states_failed.go b/extern/storage-sealing/states_failed.go index dedba2fc6..2a6d50ccf 100644 --- a/extern/storage-sealing/states_failed.go +++ b/extern/storage-sealing/states_failed.go @@ -417,6 +417,16 @@ func (m *Sealing) handleAbortUpgrade(ctx statemachine.Context, sector SectorInfo if err := m.sealer.ReleaseReplicaUpgrade(ctx.Context(), m.minerSector(sector.SectorType, sector.SectorNumber)); err != nil { 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) + } + + if err := m.sealer.ReleaseUnsealed(ctx.Context(), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(sector.CCPieces, true, cfg.AlwaysKeepUnsealedCopy)); err != nil { + log.Error(err) + } + return ctx.Send(SectorRevertUpgradeToProving{}) } diff --git a/extern/storage-sealing/states_proving.go b/extern/storage-sealing/states_proving.go index afb5c54bf..a5e5ddf88 100644 --- a/extern/storage-sealing/states_proving.go +++ b/extern/storage-sealing/states_proving.go @@ -135,15 +135,6 @@ func (m *Sealing) handleProvingSector(ctx statemachine.Context, sector SectorInf delete(m.available, m.minerSectorID(sector.SectorNumber)) m.inputLk.Unlock() - cfg, err := m.getConfig() - if err != nil { - return xerrors.Errorf("getting sealing config: %w", err) - } - - if err := m.sealer.ReleaseUnsealed(ctx.Context(), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(true, cfg.AlwaysKeepUnsealedCopy)); err != nil { - log.Error(err) - } - // TODO: Watch termination // TODO: Auto-extend if set diff --git a/extern/storage-sealing/states_replica_update.go b/extern/storage-sealing/states_replica_update.go index 8a4f05dc4..ff6302599 100644 --- a/extern/storage-sealing/states_replica_update.go +++ b/extern/storage-sealing/states_replica_update.go @@ -222,7 +222,7 @@ func (m *Sealing) handleFinalizeReplicaUpdate(ctx statemachine.Context, sector S return xerrors.Errorf("getting sealing config: %w", err) } - if err := m.sealer.FinalizeReplicaUpdate(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(false, cfg.AlwaysKeepUnsealedCopy)); err != nil { + if err := m.sealer.FinalizeReplicaUpdate(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(sector.Pieces, false, cfg.AlwaysKeepUnsealedCopy)); err != nil { return ctx.Send(SectorFinalizeFailed{xerrors.Errorf("finalize sector: %w", err)}) } diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 058c8316a..1b2556943 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -763,7 +763,7 @@ func (m *Sealing) handleFinalizeSector(ctx statemachine.Context, sector SectorIn return xerrors.Errorf("getting sealing config: %w", err) } - if err := m.sealer.FinalizeSector(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(false, cfg.AlwaysKeepUnsealedCopy)); err != nil { + if err := m.sealer.FinalizeSector(sector.sealingCtx(ctx.Context()), m.minerSector(sector.SectorType, sector.SectorNumber), sector.keepUnsealedRanges(sector.Pieces, false, cfg.AlwaysKeepUnsealedCopy)); err != nil { return ctx.Send(SectorFinalizeFailed{xerrors.Errorf("finalize sector: %w", err)}) } diff --git a/extern/storage-sealing/types.go b/extern/storage-sealing/types.go index db53f43d3..d30d98f03 100644 --- a/extern/storage-sealing/types.go +++ b/extern/storage-sealing/types.go @@ -165,11 +165,11 @@ func (t *SectorInfo) sealingCtx(ctx context.Context) context.Context { // Returns list of offset/length tuples of sector data ranges which clients // requested to keep unsealed -func (t *SectorInfo) keepUnsealedRanges(invert, alwaysKeep bool) []storage.Range { +func (t *SectorInfo) keepUnsealedRanges(pieces []Piece, invert, alwaysKeep bool) []storage.Range { var out []storage.Range var at abi.UnpaddedPieceSize - for _, piece := range t.Pieces { + for _, piece := range pieces { psize := piece.Piece.Size.Unpadded() at += psize