Merge pull request #11032 from filecoin-project/feat/remove-existing-chain
This commit is contained in:
commit
9624dc53f8
@ -12,6 +12,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -129,6 +130,10 @@ var DaemonCmd = &cli.Command{
|
|||||||
Name: "import-snapshot",
|
Name: "import-snapshot",
|
||||||
Usage: "import chain state from a given chain export file or url",
|
Usage: "import chain state from a given chain export file or url",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "remove-existing-chain",
|
||||||
|
Usage: "remove existing chain and splitstore data on a snapshot-import",
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "halt-after-import",
|
Name: "halt-after-import",
|
||||||
Usage: "halt the process after importing chain from file",
|
Usage: "halt the process after importing chain from file",
|
||||||
@ -286,6 +291,26 @@ var DaemonCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if cctx.Bool("remove-existing-chain") {
|
||||||
|
lr, err := repo.NewFS(cctx.String("repo"))
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error opening fs repo: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
exists, err := lr.Exists()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return xerrors.Errorf("lotus repo doesn't exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = removeExistingChain(cctx, lr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chainfile := cctx.String("import-chain")
|
chainfile := cctx.String("import-chain")
|
||||||
snapshot := cctx.String("import-snapshot")
|
snapshot := cctx.String("import-snapshot")
|
||||||
if chainfile != "" || snapshot != "" {
|
if chainfile != "" || snapshot != "" {
|
||||||
@ -756,3 +781,59 @@ func slashFilterMinedBlock(ctx context.Context, sf *slashfilter.SlashFilter, a l
|
|||||||
log.Error("unexpectedly reached end of slashFilterMinedBlock despite fault being reported!")
|
log.Error("unexpectedly reached end of slashFilterMinedBlock despite fault being reported!")
|
||||||
return nil, nil, false, nil
|
return nil, nil, false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeExistingChain(cctx *cli.Context, lr repo.Repo) error {
|
||||||
|
lockedRepo, err := lr.Lock(repo.FullNode)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error locking repo: %w", err)
|
||||||
|
}
|
||||||
|
// Ensure that lockedRepo is closed when this function exits
|
||||||
|
defer func() {
|
||||||
|
if closeErr := lockedRepo.Close(); closeErr != nil {
|
||||||
|
log.Errorf("Error closing the lockedRepo: %v", closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
cfg, err := lockedRepo.Config()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error getting config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fullNodeConfig, ok := cfg.(*config.FullNode)
|
||||||
|
if !ok {
|
||||||
|
return xerrors.Errorf("wrong config type: %T", cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fullNodeConfig.Chainstore.EnableSplitstore {
|
||||||
|
log.Info("removing splitstore directory...")
|
||||||
|
err = deleteSplitstoreDir(lockedRepo)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error removing splitstore directory: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the base repo path
|
||||||
|
repoPath := lockedRepo.Path()
|
||||||
|
|
||||||
|
// Construct the path to the chain directory
|
||||||
|
chainPath := filepath.Join(repoPath, "datastore", "chain")
|
||||||
|
|
||||||
|
log.Info("removing chain directory:", chainPath)
|
||||||
|
|
||||||
|
err = os.RemoveAll(chainPath)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error removing chain directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Info("chain and splitstore data have been removed")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteSplitstoreDir(lr repo.LockedRepo) error {
|
||||||
|
path, err := lr.SplitstorePath()
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("error getting splitstore path: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.RemoveAll(path)
|
||||||
|
}
|
||||||
|
@ -65,6 +65,7 @@ OPTIONS:
|
|||||||
--bootstrap (default: true)
|
--bootstrap (default: true)
|
||||||
--import-chain value on first run, load chain from given file or url and validate
|
--import-chain value on first run, load chain from given file or url and validate
|
||||||
--import-snapshot value import chain state from a given chain export file or url
|
--import-snapshot value import chain state from a given chain export file or url
|
||||||
|
--remove-existing-chain remove existing chain and splitstore data on a snapshot-import (default: false)
|
||||||
--halt-after-import halt the process after importing chain from file (default: false)
|
--halt-after-import halt the process after importing chain from file (default: false)
|
||||||
--lite start lotus in lite mode (default: false)
|
--lite start lotus in lite mode (default: false)
|
||||||
--pprof value specify name of file for writing cpu profile to
|
--pprof value specify name of file for writing cpu profile to
|
||||||
|
Loading…
Reference in New Issue
Block a user