From f671654bdd782d82a2dc0392ab54dbc74feeefac Mon Sep 17 00:00:00 2001 From: Phi Date: Fri, 12 May 2023 16:35:00 +0200 Subject: [PATCH 1/4] Make redeclare cmd work - Fix an issue where `lotus-miner storage redeclare --all` required an argument - Actually implement the logic to redeclare a single sectors in a single storage path --- cmd/lotus-miner/storage.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index 89353497d..761f070f0 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -235,14 +235,19 @@ var storageRedeclareCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - if cctx.NArg() != 1 { - return lcli.IncorrectNumArgs(cctx) + // check if no argument and no --id or --all flag is provided + if cctx.NArg() == 0 && !cctx.IsSet("id") && !cctx.Bool("all") { + return xerrors.Errorf("You must specify a storage path, or --id, or --all") } if cctx.IsSet("id") && cctx.Bool("all") { return xerrors.Errorf("--id and --all can't be passed at the same time") } + if cctx.Bool("all") && cctx.NArg() > 0 { + return xerrors.Errorf("No additional arguments are expected when --all is set") + } + if cctx.IsSet("id") { id := storiface.ID(cctx.String("id")) return minerApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) @@ -252,7 +257,24 @@ var storageRedeclareCmd = &cli.Command{ return minerApi.StorageRedeclareLocal(ctx, nil, cctx.Bool("drop-missing")) } - return xerrors.Errorf("either --all or --id must be specified") + // As no --id or --all flag is set, we can assume the argument is a path. + path := cctx.Args().First() + metaFilePath := filepath.Join(path, "sectorstore.json") + + var meta storiface.LocalStorageMeta + metaFile, err := os.Open(metaFilePath) + if err != nil { + return xerrors.Errorf("Failed to open meta file: %w", err) + } + defer metaFile.Close() + + err = json.NewDecoder(metaFile).Decode(&meta) + if err != nil { + return xerrors.Errorf("Failed to decode meta file: %w", err) + } + + id := meta.ID + return minerApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) }, } From a29e8226c77a8d867c463920484924439979c869 Mon Sep 17 00:00:00 2001 From: Phi Date: Mon, 15 May 2023 11:51:43 +0200 Subject: [PATCH 2/4] Set drop-missing to true Set drop-missing to true --- cmd/lotus-miner/storage.go | 11 ++++++++--- documentation/en/cli-lotus-miner.md | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/lotus-miner/storage.go b/cmd/lotus-miner/storage.go index 761f070f0..fdd5b5696 100644 --- a/cmd/lotus-miner/storage.go +++ b/cmd/lotus-miner/storage.go @@ -225,6 +225,7 @@ var storageRedeclareCmd = &cli.Command{ &cli.BoolFlag{ Name: "drop-missing", Usage: "Drop index entries with missing files", + Value: true, }, }, Action: func(cctx *cli.Context) error { @@ -264,13 +265,17 @@ var storageRedeclareCmd = &cli.Command{ var meta storiface.LocalStorageMeta metaFile, err := os.Open(metaFilePath) if err != nil { - return xerrors.Errorf("Failed to open meta file: %w", err) + return xerrors.Errorf("Failed to open file: %w", err) } - defer metaFile.Close() + defer func() { + if closeErr := metaFile.Close(); closeErr != nil { + log.Error("Failed to close the file: %v", closeErr) + } + }() err = json.NewDecoder(metaFile).Decode(&meta) if err != nil { - return xerrors.Errorf("Failed to decode meta file: %w", err) + return xerrors.Errorf("Failed to decode file: %w", err) } id := meta.ID diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index 7c646a3b4..1446a36a9 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1285,7 +1285,7 @@ USAGE: OPTIONS: --all redeclare all storage paths (default: false) - --drop-missing Drop index entries with missing files (default: false) + --drop-missing Drop index entries with missing files (default: true) --id value storage path ID ``` From b08dbde2dad9b7f4fb8a1eb25dd578bea8144a8a Mon Sep 17 00:00:00 2001 From: Phi Date: Thu, 18 May 2023 18:04:10 +0200 Subject: [PATCH 3/4] Update redeclare cmd on Lotus-Workers Update redeclare cmd on Lotus-Workers --- cmd/lotus-worker/storage.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-worker/storage.go b/cmd/lotus-worker/storage.go index 9e4bf1c9b..8da35c944 100644 --- a/cmd/lotus-worker/storage.go +++ b/cmd/lotus-worker/storage.go @@ -178,6 +178,7 @@ var storageRedeclareCmd = &cli.Command{ &cli.BoolFlag{ Name: "drop-missing", Usage: "Drop index entries with missing files", + Value: true, }, }, Action: func(cctx *cli.Context) error { @@ -188,10 +189,19 @@ var storageRedeclareCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) + // check if no argument and no --id or --all flag is provided + if cctx.NArg() == 0 && !cctx.IsSet("id") && !cctx.Bool("all") { + return xerrors.Errorf("You must specify a storage path, or --id, or --all") + } + if cctx.IsSet("id") && cctx.Bool("all") { return xerrors.Errorf("--id and --all can't be passed at the same time") } + if cctx.Bool("all") && cctx.NArg() > 0 { + return xerrors.Errorf("No additional arguments are expected when --all is set") + } + if cctx.IsSet("id") { id := storiface.ID(cctx.String("id")) return nodeApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) @@ -201,6 +211,27 @@ var storageRedeclareCmd = &cli.Command{ return nodeApi.StorageRedeclareLocal(ctx, nil, cctx.Bool("drop-missing")) } - return xerrors.Errorf("either --all or --id must be specified") + // As no --id or --all flag is set, we can assume the argument is a path. + path := cctx.Args().First() + metaFilePath := filepath.Join(path, "sectorstore.json") + + var meta storiface.LocalStorageMeta + metaFile, err := os.Open(metaFilePath) + if err != nil { + return xerrors.Errorf("Failed to open file: %w", err) + } + defer func() { + if closeErr := metaFile.Close(); closeErr != nil { + log.Error("Failed to close the file: %v", closeErr) + } + }() + + err = json.NewDecoder(metaFile).Decode(&meta) + if err != nil { + return xerrors.Errorf("Failed to decode file: %w", err) + } + + id := meta.ID + return nodeApi.StorageRedeclareLocal(ctx, &id, cctx.Bool("drop-missing")) }, } From e65de697f03be3eccf1d56a65b567095e3fcd2fc Mon Sep 17 00:00:00 2001 From: Phi Date: Thu, 18 May 2023 18:27:53 +0200 Subject: [PATCH 4/4] make docsgen-cli make docsgen-cli --- documentation/en/cli-lotus-worker.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/en/cli-lotus-worker.md b/documentation/en/cli-lotus-worker.md index cb3d34729..3ccfadaf6 100644 --- a/documentation/en/cli-lotus-worker.md +++ b/documentation/en/cli-lotus-worker.md @@ -148,7 +148,7 @@ USAGE: OPTIONS: --all redeclare all storage paths (default: false) - --drop-missing Drop index entries with missing files (default: false) + --drop-missing Drop index entries with missing files (default: true) --id value storage path ID ```