Skip to content

Commit

Permalink
Merge pull request #8438 from filecoin-project/fix/release-unseal-sna…
Browse files Browse the repository at this point in the history
…p-abort

fix: sealing: Release unsealed sector files after snapdeals abort
  • Loading branch information
magik6k authored Apr 5, 2022
2 parents e1ef1b7 + 68f3e44 commit 0fa74a7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
18 changes: 17 additions & 1 deletion extern/sector-storage/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions extern/storage-sealing/states_failed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}

Expand Down
9 changes: 0 additions & 9 deletions extern/storage-sealing/states_proving.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion extern/storage-sealing/states_replica_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
}

Expand Down
2 changes: 1 addition & 1 deletion extern/storage-sealing/states_sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
}

Expand Down
4 changes: 2 additions & 2 deletions extern/storage-sealing/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0fa74a7

Please sign in to comment.