range-export: write files to lotus repo path

This commit is contained in:
Hector Sanjuan 2023-02-14 19:10:22 +01:00
parent be1614a042
commit a2475bca94
2 changed files with 6 additions and 4 deletions

View File

@ -1150,7 +1150,7 @@ var ChainExportCmd = &cli.Command{
var ChainExportRangeCmd = &cli.Command{ var ChainExportRangeCmd = &cli.Command{
Name: "export-range", Name: "export-range",
Usage: "export chain to a car file", Usage: "export chain to a car file",
ArgsUsage: "[outputPath]", ArgsUsage: "",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "head", Name: "head",

View File

@ -42,6 +42,7 @@ import (
"github.com/filecoin-project/lotus/lib/oldpath" "github.com/filecoin-project/lotus/lib/oldpath"
"github.com/filecoin-project/lotus/lib/oldpath/oldresolver" "github.com/filecoin-project/lotus/lib/oldpath/oldresolver"
"github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/repo"
) )
var log = logging.Logger("fullnode") var log = logging.Logger("fullnode")
@ -93,6 +94,8 @@ type ChainAPI struct {
// BaseBlockstore is the underlying blockstore // BaseBlockstore is the underlying blockstore
BaseBlockstore dtypes.BaseBlockstore BaseBlockstore dtypes.BaseBlockstore
Repo repo.LockedRepo
} }
func (m *ChainModule) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) { func (m *ChainModule) ChainNotify(ctx context.Context) (<-chan []*api.HeadChange, error) {
@ -606,8 +609,7 @@ func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types
return xerrors.Errorf("Height of head-tipset (%d) must be greater or equal to the height of the tail-tipset (%d)", headTs.Height(), tailTs.Height()) return xerrors.Errorf("Height of head-tipset (%d) must be greater or equal to the height of the tail-tipset (%d)", headTs.Height(), tailTs.Height())
} }
fileName := fmt.Sprintf("./snapshot_%d_%d_%d.car", tailTs.Height(), headTs.Height(), time.Now().Unix()) fileName := filepath.Join(a.Repo.Path(), fmt.Sprintf("snapshot_%d_%d_%d.car", tailTs.Height(), headTs.Height(), time.Now().Unix()))
absFileName, err := filepath.Abs(fileName)
if err != nil { if err != nil {
return err return err
} }
@ -617,7 +619,7 @@ func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types
return err return err
} }
log.Infow("Exporting chain range", "path", absFileName) log.Infow("Exporting chain range", "path", fileName)
// buffer writes to the chain export file. // buffer writes to the chain export file.
bw := bufio.NewWriterSize(f, cfg.WriteBufferSize) bw := bufio.NewWriterSize(f, cfg.WriteBufferSize)