2020-03-23 12:29:24 +00:00
|
|
|
package main
|
2020-03-23 14:56:22 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-23 17:26:26 +00:00
|
|
|
"encoding/hex"
|
2020-07-27 11:23:43 +00:00
|
|
|
"encoding/json"
|
2020-03-23 14:56:22 +00:00
|
|
|
"fmt"
|
2022-05-24 13:47:49 +00:00
|
|
|
"io"
|
|
|
|
"net/http"
|
2020-07-21 18:07:49 +00:00
|
|
|
"os"
|
2020-03-23 14:56:22 +00:00
|
|
|
"sort"
|
2020-05-01 12:06:19 +00:00
|
|
|
"strings"
|
2020-07-21 18:07:49 +00:00
|
|
|
"text/tabwriter"
|
|
|
|
"time"
|
2020-05-01 12:06:19 +00:00
|
|
|
|
2022-05-24 13:07:53 +00:00
|
|
|
"github.com/dustin/go-humanize"
|
2020-05-01 12:06:19 +00:00
|
|
|
"github.com/fatih/color"
|
2020-10-18 10:35:44 +00:00
|
|
|
"github.com/google/uuid"
|
2022-05-24 13:07:53 +00:00
|
|
|
"github.com/mitchellh/go-homedir"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-09-23 17:26:26 +00:00
|
|
|
"golang.org/x/xerrors"
|
2020-03-23 14:56:22 +00:00
|
|
|
|
2022-05-24 13:07:53 +00:00
|
|
|
"github.com/filecoin-project/go-padreader"
|
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-05-01 12:06:19 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-03-23 14:56:22 +00:00
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/httpreader"
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
2020-03-23 14:56:22 +00:00
|
|
|
)
|
|
|
|
|
2020-07-21 18:07:49 +00:00
|
|
|
var sealingCmd = &cli.Command{
|
|
|
|
Name: "sealing",
|
|
|
|
Usage: "interact with sealing pipeline",
|
2020-03-23 14:56:22 +00:00
|
|
|
Subcommands: []*cli.Command{
|
2020-07-21 18:07:49 +00:00
|
|
|
sealingJobsCmd,
|
2022-03-26 20:16:12 +00:00
|
|
|
workersCmd(true),
|
2020-07-27 11:23:43 +00:00
|
|
|
sealingSchedDiagCmd,
|
2020-11-11 16:39:12 +00:00
|
|
|
sealingAbortCmd,
|
2022-05-24 13:07:53 +00:00
|
|
|
sealingDataCidCmd,
|
2020-03-23 14:56:22 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
func workersCmd(sealing bool) *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "workers",
|
|
|
|
Usage: "list workers",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "color",
|
|
|
|
Usage: "use color in display output",
|
|
|
|
DefaultText: "depends on output being a TTY",
|
|
|
|
},
|
2021-07-07 16:12:17 +00:00
|
|
|
},
|
2022-03-26 20:16:12 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
|
|
|
if cctx.IsSet("color") {
|
|
|
|
color.NoColor = !cctx.Bool("color")
|
2020-03-23 14:56:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2022-03-26 20:16:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-10-18 11:03:17 +00:00
|
|
|
}
|
2022-03-26 20:16:12 +00:00
|
|
|
defer closer()
|
2020-10-18 11:03:17 +00:00
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
2021-09-09 21:41:59 +00:00
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
stats, err := minerApi.WorkerStats(ctx)
|
2022-03-26 20:16:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-08-17 12:07:32 +00:00
|
|
|
}
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
type sortableStat struct {
|
|
|
|
id uuid.UUID
|
|
|
|
storiface.WorkerStats
|
2021-09-09 21:41:59 +00:00
|
|
|
}
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
st := make([]sortableStat, 0, len(stats))
|
|
|
|
for id, stat := range stats {
|
|
|
|
if len(stat.Tasks) > 0 {
|
|
|
|
if (stat.Tasks[0].WorkerType() != sealtasks.WorkerSealing) == sealing {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
st = append(st, sortableStat{id, stat})
|
2021-09-01 01:59:25 +00:00
|
|
|
}
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
sort.Slice(st, func(i, j int) bool {
|
|
|
|
return st[i].id.String() < st[j].id.String()
|
|
|
|
})
|
|
|
|
|
2022-05-25 12:44:11 +00:00
|
|
|
/*
|
|
|
|
Example output:
|
|
|
|
|
|
|
|
Worker c4d65451-07f8-4230-98ad-4f33dea2a8cc, host myhostname
|
|
|
|
TASK: PC1(1/4) AP(15/15) GET(3)
|
|
|
|
CPU: [|||||||| ] 16/128 core(s) in use
|
|
|
|
RAM: [|||||||| ] 12% 125.8 GiB/1008 GiB
|
|
|
|
VMEM: [|||||||| ] 12% 125.8 GiB/1008 GiB
|
|
|
|
GPU: [ ] 0% 0.00/1 gpu(s) in use
|
|
|
|
GPU: NVIDIA GeForce RTX 3090, not used
|
|
|
|
*/
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
for _, stat := range st {
|
2022-05-25 12:44:11 +00:00
|
|
|
// Worker uuid + name
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
var disabled string
|
|
|
|
if !stat.Enabled {
|
|
|
|
disabled = color.RedString(" (disabled)")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Worker %s, host %s%s\n", stat.id, color.MagentaString(stat.Info.Hostname), disabled)
|
|
|
|
|
2022-05-25 12:44:11 +00:00
|
|
|
// Task counts
|
|
|
|
tc := make([][]string, 0, len(stat.TaskCounts))
|
|
|
|
|
|
|
|
for st, c := range stat.TaskCounts {
|
|
|
|
if c == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
stt, err := sealtasks.SttFromString(st)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
str := fmt.Sprint(c)
|
|
|
|
if max := stat.Info.Resources.ResourceSpec(stt.RegisteredSealProof, stt.TaskType).MaxConcurrent; max > 0 {
|
|
|
|
switch {
|
|
|
|
case c < max:
|
|
|
|
str = color.GreenString(str)
|
|
|
|
case c >= max:
|
|
|
|
str = color.YellowString(str)
|
|
|
|
}
|
|
|
|
str = fmt.Sprintf("%s/%d", str, max)
|
|
|
|
} else {
|
|
|
|
str = color.CyanString(str)
|
|
|
|
}
|
|
|
|
str = fmt.Sprintf("%s(%s)", color.BlueString(stt.Short()), str)
|
|
|
|
|
|
|
|
tc = append(tc, []string{string(stt.TaskType), str})
|
|
|
|
}
|
|
|
|
sort.Slice(tc, func(i, j int) bool {
|
|
|
|
return sealtasks.TaskType(tc[i][0]).Less(sealtasks.TaskType(tc[j][0]))
|
|
|
|
})
|
|
|
|
var taskStr string
|
|
|
|
for _, t := range tc {
|
|
|
|
taskStr = t[1] + " "
|
|
|
|
}
|
|
|
|
if taskStr != "" {
|
|
|
|
fmt.Printf("\tTASK: %s\n", taskStr)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CPU use
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
fmt.Printf("\tCPU: [%s] %d/%d core(s) in use\n",
|
2022-06-02 14:53:58 +00:00
|
|
|
lcli.BarString(float64(stat.Info.Resources.CPUs), 0, float64(stat.CpuUse)), stat.CpuUse, stat.Info.Resources.CPUs)
|
2022-03-26 20:16:12 +00:00
|
|
|
|
2022-05-25 12:44:11 +00:00
|
|
|
// RAM use
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
ramTotal := stat.Info.Resources.MemPhysical
|
|
|
|
ramTasks := stat.MemUsedMin
|
|
|
|
ramUsed := stat.Info.Resources.MemUsed
|
|
|
|
var ramReserved uint64 = 0
|
|
|
|
if ramUsed > ramTasks {
|
|
|
|
ramReserved = ramUsed - ramTasks
|
|
|
|
}
|
2022-06-02 14:53:58 +00:00
|
|
|
ramBar := lcli.BarString(float64(ramTotal), float64(ramReserved), float64(ramTasks))
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
fmt.Printf("\tRAM: [%s] %d%% %s/%s\n", ramBar,
|
|
|
|
(ramTasks+ramReserved)*100/stat.Info.Resources.MemPhysical,
|
|
|
|
types.SizeStr(types.NewInt(ramTasks+ramUsed)),
|
|
|
|
types.SizeStr(types.NewInt(stat.Info.Resources.MemPhysical)))
|
|
|
|
|
2022-05-25 12:44:11 +00:00
|
|
|
// VMEM use (ram+swap)
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
vmemTotal := stat.Info.Resources.MemPhysical + stat.Info.Resources.MemSwap
|
|
|
|
vmemTasks := stat.MemUsedMax
|
|
|
|
vmemUsed := stat.Info.Resources.MemUsed + stat.Info.Resources.MemSwapUsed
|
|
|
|
var vmemReserved uint64 = 0
|
|
|
|
if vmemUsed > vmemTasks {
|
|
|
|
vmemReserved = vmemUsed - vmemTasks
|
|
|
|
}
|
2022-06-02 14:53:58 +00:00
|
|
|
vmemBar := lcli.BarString(float64(vmemTotal), float64(vmemReserved), float64(vmemTasks))
|
2022-03-26 20:16:12 +00:00
|
|
|
|
|
|
|
fmt.Printf("\tVMEM: [%s] %d%% %s/%s\n", vmemBar,
|
|
|
|
(vmemTasks+vmemReserved)*100/vmemTotal,
|
|
|
|
types.SizeStr(types.NewInt(vmemTasks+vmemReserved)),
|
|
|
|
types.SizeStr(types.NewInt(vmemTotal)))
|
|
|
|
|
2022-05-25 12:44:11 +00:00
|
|
|
// GPU use
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
if len(stat.Info.Resources.GPUs) > 0 {
|
2022-06-02 14:53:58 +00:00
|
|
|
gpuBar := lcli.BarString(float64(len(stat.Info.Resources.GPUs)), 0, stat.GpuUsed)
|
2022-03-26 20:16:12 +00:00
|
|
|
fmt.Printf("\tGPU: [%s] %.f%% %.2f/%d gpu(s) in use\n", color.GreenString(gpuBar),
|
|
|
|
stat.GpuUsed*100/float64(len(stat.Info.Resources.GPUs)),
|
|
|
|
stat.GpuUsed, len(stat.Info.Resources.GPUs))
|
|
|
|
}
|
2022-05-25 12:44:11 +00:00
|
|
|
|
|
|
|
gpuUse := "not "
|
|
|
|
gpuCol := color.FgBlue
|
|
|
|
if stat.GpuUsed > 0 {
|
|
|
|
gpuCol = color.FgGreen
|
|
|
|
gpuUse = ""
|
|
|
|
}
|
2022-03-26 20:16:12 +00:00
|
|
|
for _, gpu := range stat.Info.Resources.GPUs {
|
|
|
|
fmt.Printf("\tGPU: %s\n", color.New(gpuCol).Sprintf("%s, %sused", gpu, gpuUse))
|
|
|
|
}
|
2020-03-23 14:56:22 +00:00
|
|
|
}
|
|
|
|
|
2022-03-26 20:16:12 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-03-23 22:43:38 +00:00
|
|
|
}
|
2020-07-21 18:07:49 +00:00
|
|
|
|
|
|
|
var sealingJobsCmd = &cli.Command{
|
|
|
|
Name: "jobs",
|
2020-11-11 16:39:12 +00:00
|
|
|
Usage: "list running jobs",
|
2020-07-21 18:07:49 +00:00
|
|
|
Flags: []cli.Flag{
|
2021-07-07 16:12:17 +00:00
|
|
|
&cli.BoolFlag{
|
2021-07-08 08:44:13 +00:00
|
|
|
Name: "color",
|
2021-07-13 10:19:55 +00:00
|
|
|
Usage: "use color in display output",
|
2021-07-08 08:44:13 +00:00
|
|
|
DefaultText: "depends on output being a TTY",
|
2021-07-07 16:12:17 +00:00
|
|
|
},
|
2020-11-11 15:48:04 +00:00
|
|
|
&cli.BoolFlag{
|
2020-11-11 16:39:31 +00:00
|
|
|
Name: "show-ret-done",
|
2020-11-11 15:48:04 +00:00
|
|
|
Usage: "show returned but not consumed calls",
|
|
|
|
},
|
2020-07-21 18:07:49 +00:00
|
|
|
},
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2021-07-13 10:19:55 +00:00
|
|
|
if cctx.IsSet("color") {
|
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
}
|
2020-07-21 18:07:49 +00:00
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-07-21 18:07:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
jobs, err := minerApi.WorkerJobs(ctx)
|
2020-07-21 18:07:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker jobs: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
type line struct {
|
|
|
|
storiface.WorkerJob
|
2020-10-18 10:35:44 +00:00
|
|
|
wid uuid.UUID
|
2020-07-21 18:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lines := make([]line, 0)
|
|
|
|
|
|
|
|
for wid, jobs := range jobs {
|
|
|
|
for _, job := range jobs {
|
|
|
|
lines = append(lines, line{
|
|
|
|
WorkerJob: job,
|
|
|
|
wid: wid,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// oldest first
|
|
|
|
sort.Slice(lines, func(i, j int) bool {
|
2020-08-27 21:14:33 +00:00
|
|
|
if lines[i].RunWait != lines[j].RunWait {
|
2020-08-28 16:26:17 +00:00
|
|
|
return lines[i].RunWait < lines[j].RunWait
|
2020-08-27 21:14:33 +00:00
|
|
|
}
|
2020-09-24 09:55:11 +00:00
|
|
|
if lines[i].Start.Equal(lines[j].Start) {
|
|
|
|
return lines[i].ID.ID.String() < lines[j].ID.ID.String()
|
|
|
|
}
|
2020-07-21 18:07:49 +00:00
|
|
|
return lines[i].Start.Before(lines[j].Start)
|
|
|
|
})
|
|
|
|
|
2020-10-18 10:35:44 +00:00
|
|
|
workerHostnames := map[uuid.UUID]string{}
|
2020-07-21 18:07:49 +00:00
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
wst, err := minerApi.WorkerStats(ctx)
|
2020-07-21 18:07:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker stats: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for wid, st := range wst {
|
2020-10-18 10:35:44 +00:00
|
|
|
workerHostnames[wid] = st.Info.Hostname
|
2020-07-21 18:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
2020-08-27 21:14:33 +00:00
|
|
|
_, _ = fmt.Fprintf(tw, "ID\tSector\tWorker\tHostname\tTask\tState\tTime\n")
|
2020-07-21 18:07:49 +00:00
|
|
|
|
|
|
|
for _, l := range lines {
|
2020-08-28 16:26:17 +00:00
|
|
|
state := "running"
|
2020-11-09 22:13:29 +00:00
|
|
|
switch {
|
2021-10-15 19:26:35 +00:00
|
|
|
case l.RunWait > 1:
|
2020-08-28 16:26:17 +00:00
|
|
|
state = fmt.Sprintf("assigned(%d)", l.RunWait-1)
|
2021-10-15 19:26:35 +00:00
|
|
|
case l.RunWait == storiface.RWPrepared:
|
|
|
|
state = "prepared"
|
2020-11-09 22:38:20 +00:00
|
|
|
case l.RunWait == storiface.RWRetDone:
|
2020-11-11 15:48:04 +00:00
|
|
|
if !cctx.Bool("show-ret-done") {
|
|
|
|
continue
|
|
|
|
}
|
2020-11-09 22:38:20 +00:00
|
|
|
state = "ret-done"
|
|
|
|
case l.RunWait == storiface.RWReturned:
|
2020-11-09 22:13:29 +00:00
|
|
|
state = "returned"
|
2020-11-09 22:38:20 +00:00
|
|
|
case l.RunWait == storiface.RWRetWait:
|
2020-09-23 17:26:26 +00:00
|
|
|
state = "ret-wait"
|
|
|
|
}
|
|
|
|
dur := "n/a"
|
|
|
|
if !l.Start.IsZero() {
|
|
|
|
dur = time.Now().Sub(l.Start).Truncate(time.Millisecond * 100).String()
|
|
|
|
}
|
|
|
|
|
2020-11-09 22:09:04 +00:00
|
|
|
hostname, ok := workerHostnames[l.wid]
|
|
|
|
if !ok {
|
|
|
|
hostname = l.Hostname
|
|
|
|
}
|
|
|
|
|
2020-10-18 11:03:17 +00:00
|
|
|
_, _ = fmt.Fprintf(tw, "%s\t%d\t%s\t%s\t%s\t%s\t%s\n",
|
2020-11-11 16:39:12 +00:00
|
|
|
hex.EncodeToString(l.ID.ID[:4]),
|
2020-10-18 11:03:17 +00:00
|
|
|
l.Sector.Number,
|
2020-11-11 16:39:12 +00:00
|
|
|
hex.EncodeToString(l.wid[:4]),
|
2020-11-09 22:09:04 +00:00
|
|
|
hostname,
|
2020-10-18 11:03:17 +00:00
|
|
|
l.Task.Short(),
|
|
|
|
state,
|
|
|
|
dur)
|
2020-07-21 18:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tw.Flush()
|
|
|
|
},
|
|
|
|
}
|
2020-07-27 11:23:43 +00:00
|
|
|
|
|
|
|
var sealingSchedDiagCmd = &cli.Command{
|
|
|
|
Name: "sched-diag",
|
|
|
|
Usage: "Dump internal scheduler state",
|
2020-10-30 10:07:35 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "force-sched",
|
|
|
|
},
|
|
|
|
},
|
2020-07-27 11:23:43 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:51:18 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-07-27 11:23:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
st, err := minerApi.SealingSchedDiag(ctx, cctx.Bool("force-sched"))
|
2020-07-27 11:23:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
j, err := json.MarshalIndent(&st, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(string(j))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2020-11-11 16:39:12 +00:00
|
|
|
|
|
|
|
var sealingAbortCmd = &cli.Command{
|
2020-11-11 16:39:31 +00:00
|
|
|
Name: "abort",
|
|
|
|
Usage: "Abort a running job",
|
2020-11-12 07:04:55 +00:00
|
|
|
ArgsUsage: "[callid]",
|
2022-08-01 17:49:47 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
2022-08-02 09:47:30 +00:00
|
|
|
Name: "sched",
|
|
|
|
Usage: "Specifies that the argument is UUID of the request to be removed from scheduler",
|
2022-08-01 17:49:47 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-11 16:39:12 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() != 1 {
|
2020-11-11 16:39:12 +00:00
|
|
|
return xerrors.Errorf("expected 1 argument")
|
|
|
|
}
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2020-11-11 16:39:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2022-08-02 09:47:30 +00:00
|
|
|
if cctx.Bool("sched") {
|
2022-09-14 18:51:18 +00:00
|
|
|
err = minerApi.SealingRemoveRequest(ctx, uuid.Must(uuid.Parse(cctx.Args().First())))
|
2022-08-01 17:49:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("Failed to removed the request with UUID %s: %w", cctx.Args().First(), err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
jobs, err := minerApi.WorkerJobs(ctx)
|
2020-11-11 16:39:12 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker jobs: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var job *storiface.WorkerJob
|
|
|
|
outer:
|
|
|
|
for _, workerJobs := range jobs {
|
|
|
|
for _, j := range workerJobs {
|
|
|
|
if strings.HasPrefix(j.ID.ID.String(), cctx.Args().First()) {
|
2020-11-11 16:39:31 +00:00
|
|
|
j := j
|
2020-11-11 16:39:12 +00:00
|
|
|
job = &j
|
|
|
|
break outer
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if job == nil {
|
|
|
|
return xerrors.Errorf("job with specified id prefix not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("aborting job %s, task %s, sector %d, running on host %s\n", job.ID.String(), job.Task.Short(), job.Sector.Number, job.Hostname)
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
return minerApi.SealingAbort(ctx, job.ID)
|
2020-11-11 16:39:12 +00:00
|
|
|
},
|
|
|
|
}
|
2022-05-24 13:07:53 +00:00
|
|
|
|
|
|
|
var sealingDataCidCmd = &cli.Command{
|
|
|
|
Name: "data-cid",
|
|
|
|
Usage: "Compute data CID using workers",
|
2022-05-24 13:47:49 +00:00
|
|
|
ArgsUsage: "[file/url] <padded piece size>",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.Uint64Flag{
|
|
|
|
Name: "file-size",
|
|
|
|
Usage: "real file size",
|
|
|
|
},
|
|
|
|
},
|
2022-05-24 13:07:53 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() < 1 || cctx.NArg() > 2 {
|
2022-05-24 13:07:53 +00:00
|
|
|
return xerrors.Errorf("expected 1 or 2 arguments")
|
|
|
|
}
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2022-05-24 13:07:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2022-05-24 13:47:49 +00:00
|
|
|
var r io.Reader
|
|
|
|
sz := cctx.Uint64("file-size")
|
2022-05-24 13:07:53 +00:00
|
|
|
|
2022-05-24 13:47:49 +00:00
|
|
|
if strings.HasPrefix(cctx.Args().First(), "http://") || strings.HasPrefix(cctx.Args().First(), "https://") {
|
|
|
|
r = &httpreader.HttpReader{
|
|
|
|
URL: cctx.Args().First(),
|
|
|
|
}
|
2022-05-24 13:07:53 +00:00
|
|
|
|
2022-05-24 13:47:49 +00:00
|
|
|
if !cctx.IsSet("file-size") {
|
|
|
|
resp, err := http.Head(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("http head: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.ContentLength < 0 {
|
|
|
|
return xerrors.Errorf("head response didn't contain content length; specify --file-size")
|
|
|
|
}
|
|
|
|
sz = uint64(resp.ContentLength)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p, err := homedir.Expand(cctx.Args().First())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("expanding path: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.OpenFile(p, os.O_RDONLY, 0)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("opening source file: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !cctx.IsSet("file-size") {
|
|
|
|
st, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("stat: %w", err)
|
|
|
|
}
|
|
|
|
sz = uint64(st.Size())
|
|
|
|
}
|
|
|
|
|
|
|
|
r = f
|
2022-05-24 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var psize abi.PaddedPieceSize
|
2022-09-14 18:33:29 +00:00
|
|
|
if cctx.NArg() == 2 {
|
2022-05-24 13:07:53 +00:00
|
|
|
rps, err := humanize.ParseBytes(cctx.Args().Get(1))
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("parsing piece size: %w", err)
|
|
|
|
}
|
|
|
|
psize = abi.PaddedPieceSize(rps)
|
|
|
|
if err := psize.Validate(); err != nil {
|
|
|
|
return xerrors.Errorf("checking piece size: %w", err)
|
|
|
|
}
|
2022-05-24 13:47:49 +00:00
|
|
|
if sz > uint64(psize.Unpadded()) {
|
2022-05-24 13:07:53 +00:00
|
|
|
return xerrors.Errorf("file larger than the piece")
|
|
|
|
}
|
|
|
|
} else {
|
2022-05-24 13:59:11 +00:00
|
|
|
psize = padreader.PaddedSize(sz).Padded()
|
2022-05-24 13:07:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-14 18:51:18 +00:00
|
|
|
pc, err := minerApi.ComputeDataCid(ctx, psize.Unpadded(), r)
|
2022-05-24 13:07:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("computing data CID: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(pc.PieceCID, " ", pc.Size)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|