recovery

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RecoverCmd = &cli.Command{
	Name:      "recover",
	Usage:     "Recovery sector tools",
	ArgsUsage: "[sectorNum1 sectorNum2 ...]",
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:     "sectors-recovery-metadata",
			Aliases:  []string{"metadata"},
			Usage:    "specify the metadata file for the sectors recovery (Exported json file)",
			Required: true,
		},
		&cli.UintFlag{
			Name:  "parallel",
			Usage: "Number of parallel P1",
			Value: 1,
		},
		&cli.StringFlag{
			Name:  "sealing-result",
			Value: "~/sector",
			Usage: "Recover sector result path",
		},
		&cli.StringFlag{
			Name:  "sealing-temp",
			Value: "~/temp",
			Usage: "Temporarily generated during sector file",
		},
	},
	Action: func(cctx *cli.Context) error {
		log.Info("Start sealer recovery!")

		ctx := cliutil.DaemonContext(cctx)
		ctx, cancel := context.WithCancel(ctx)
		defer cancel()

		if cctx.Args().Len() < 1 {
			return fmt.Errorf("at least one sector must be specified")
		}

		cmdSectors := make([]uint64, 0)
		for _, sn := range cctx.Args().Slice() {
			sectorNum, err := strconv.ParseUint(sn, 10, 64)
			if err != nil {
				return fmt.Errorf("could not parse sector number: %w", err)
			}
			cmdSectors = append(cmdSectors, sectorNum)
		}

		pssb := cctx.String("sectors-recovery-metadata")
		if pssb == "" {
			return xerrors.Errorf("Undefined sectors recovery metadata")
		}

		log.Infof("Importing sectors recovery metadata for %s", pssb)

		rp, err := migrateRecoverMeta(ctx, pssb)
		if err != nil {
			return xerrors.Errorf("migrating sectors metadata: %w", err)
		}

		skipSectors := make([]uint64, 0)
		runSectors := make([]uint64, 0)
		sectorInfos := make(export.SectorInfos, 0)
		for _, sn := range cmdSectors {
			run := false
			for _, sectorInfo := range rp.SectorInfos {
				if sn == uint64(sectorInfo.SectorNumber) {
					run = true
					sectorInfos = append(sectorInfos, sectorInfo)
					runSectors = append(runSectors, sn)
				}
			}
			if !run {
				skipSectors = append(skipSectors, sn)
			}
		}
		if len(runSectors) > 0 {
			log.Infof("Sector %v to be recovered, %d in total!", runSectors, len(runSectors))
		}
		if len(skipSectors) > 0 {
			log.Warnf("Skip sector %v, %d in total, because sector information was not found in the metadata file!", skipSectors, len(skipSectors))
		}

		rp.SectorInfos = sectorInfos

		if err = RecoverSealedFile(ctx, rp, cctx.Uint("parallel"), cctx.String("sealing-result"), cctx.String("sealing-temp")); err != nil {
			return err
		}
		log.Info("Complete recovery sealed!")
		return nil
	},
}

Functions

func MoveStorage

func MoveStorage(ctx context.Context, sector storage.SectorRef, tempDir string, sealingResult string) error

func RecoverSealedFile

func RecoverSealedFile(ctx context.Context, rp export.RecoveryParams, parallel uint, sealingResult string, sealingTemp string) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL