From fa596eee5bae1f2c67a61cef18bb8849fd395d91 Mon Sep 17 00:00:00 2001 From: Shrenuj Bansal Date: Wed, 23 Nov 2022 15:22:14 -0500 Subject: [PATCH] Move unsealed sector from sealing to long term storage after Unseal --- itests/sector_unseal_test.go | 52 ++++++++++++++++++++++++++++++++++++ storage/sealer/manager.go | 15 +++++++++++ 2 files changed, 67 insertions(+) diff --git a/itests/sector_unseal_test.go b/itests/sector_unseal_test.go index d3847f590..735548486 100644 --- a/itests/sector_unseal_test.go +++ b/itests/sector_unseal_test.go @@ -2,6 +2,7 @@ package itests import ( "context" + "fmt" "testing" "time" @@ -66,6 +67,53 @@ func TestUnsealPiece(t *testing.T) { require.NoError(t, err) require.Len(t, wpaths, 1) + // check which sectors files are present on the miner/worker storage paths + checkSectors := func(miners, workers storiface.SectorFileType) { + paths, err := miner.StorageList(ctx) + require.NoError(t, err) + require.Len(t, paths, 3) // genesis, miner, worker + + // first loop for debugging + for id, decls := range paths { + pinfo, err := miner.StorageInfo(ctx, id) + require.NoError(t, err) + + switch { + case id == wpaths[0].ID: // worker path + fmt.Println("Worker Decls ", len(decls), decls) + case !pinfo.CanStore && !pinfo.CanSeal: // genesis path + fmt.Println("Genesis Decls ", len(decls), decls) + default: // miner path + fmt.Println("Miner Decls ", len(decls), decls) + } + } + + for id, decls := range paths { + pinfo, err := miner.StorageInfo(ctx, id) + require.NoError(t, err) + + switch { + case id == wpaths[0].ID: // worker path + if workers != storiface.FTNone { + require.Len(t, decls, 1) + require.EqualValues(t, workers.Strings(), decls[0].SectorFileType.Strings()) + } else { + require.Len(t, decls, 0) + } + case !pinfo.CanStore && !pinfo.CanSeal: // genesis path + require.Len(t, decls, kit.DefaultPresealsPerBootstrapMiner) + default: // miner path + if miners != storiface.FTNone { + require.Len(t, decls, 1) + require.EqualValues(t, miners.Strings(), decls[0].SectorFileType.Strings()) + } else { + require.Len(t, decls, 0) + } + } + } + } + checkSectors(storiface.FTNone, storiface.FTNone) + // get a sector for upgrading miner.PledgeSectors(ctx, 1, 0, nil) sl, err := miner.SectorsListNonGenesis(ctx) @@ -74,6 +122,8 @@ func TestUnsealPiece(t *testing.T) { sector := sl[0] + checkSectors(storiface.FTCache|storiface.FTSealed, storiface.FTNone) + sinfo, err := miner.SectorsStatus(ctx, sector, false) require.NoError(t, err) @@ -87,4 +137,6 @@ func TestUnsealPiece(t *testing.T) { err = miner.SectorsUnsealPiece(ctx, sectorRef, 0, 0, sinfo.Ticket.Value, sinfo.CommD) require.NoError(t, err) + + checkSectors(storiface.FTCache|storiface.FTSealed|storiface.FTUnsealed, storiface.FTNone) } diff --git a/storage/sealer/manager.go b/storage/sealer/manager.go index cb1db5866..2c6f8d172 100644 --- a/storage/sealer/manager.go +++ b/storage/sealer/manager.go @@ -353,6 +353,21 @@ func (m *Manager) SectorsUnsealPiece(ctx context.Context, sector storiface.Secto return xerrors.Errorf("worker UnsealPiece call: %s", err) } + // get a selector for moving unsealed sector into long-term storage + fetchSel := newMoveSelector(m.index, sector.ID, storiface.FTUnsealed, storiface.PathStorage, !m.disallowRemoteFinalize) + + // move unsealed sector to long-term storage + // Possible TODO: Add an option to not keep the unsealed sector in long term storage? + err = m.sched.Schedule(ctx, sector, sealtasks.TTFetch, fetchSel, + m.schedFetch(sector, storiface.FTUnsealed, storiface.PathStorage, storiface.AcquireMove), + func(ctx context.Context, w Worker) error { + _, err := m.waitSimpleCall(ctx)(w.MoveStorage(ctx, sector, storiface.FTUnsealed)) + return err + }) + if err != nil { + return xerrors.Errorf("moving unsealed sector to long term storage: %w", err) + } + return nil }