Skip to content

Commit

Permalink
[feat]tools-v2: add bs query volume clone-recover
Browse files Browse the repository at this point in the history
Signed-off-by: baytan0720 <baytan2@hotmail.com>
  • Loading branch information
baytan0720 authored and caoxianfei1 committed Nov 3, 2023
1 parent c431d82 commit cf3d33f
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 105 deletions.
43 changes: 31 additions & 12 deletions tools-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@ A tool for CurveFS & CurveBs.
- [warmup query](#warmup-query)
- [bs](#bs)
- [list](#list-1)
- [list logical-pool](#list-logical-pool)
- [list server](#list-server)
- [list client](#list-client)
- [list dir](#list-dir)
- [list space](#list-space)
- [list chunkserver](#list-chunkserver)
- [list scan-status](#list-scan-status)
- [list may-broken-vol](#list-may-broken-vol)
- [list snapshot](#list-snapshot)
- [list logical-pool](#list-logical-pool)
- [list server](#list-server)
- [list client](#list-client)
- [list dir](#list-dir)
- [list space](#list-space)
- [list chunkserver](#list-chunkserver)
- [list scan-status](#list-scan-status)
- [list may-broken-vol](#list-may-broken-vol)
- [list snapshot](#list-snapshot)
- [clean-recycle](#clean-recycle)
- [query](#query-1)
- [query file](#query-file)
- [query chunk](#query-chunk)
- [query segment](#query-segment)
- [query file](#query-file)
- [query chunk](#query-chunk)
- [query segment](#query-segment)
- [query scan-status](#query-scan-status)
- [query volume clone-recover](#query-volume-clone-recover)
- [status](#status-1)
- [status etcd](#status-etcd-1)
- [status mds](#status-mds-1)
Expand Down Expand Up @@ -1441,6 +1442,24 @@ Output:
+-------------+-----------+-------+-------------+--------------------+
```


##### query volume clone-recover
query volume clone and recover in curvebs cluster

Usage:
```bash
curve bs query volume clone-recover
```

Output:
```bash
+------+--------------------------------------+--------------------------------------+----------+-------+----------+--------+----------+--------+----------+---------------------+
| USER | SRC | TASK ID | TASKTYPE | FILE | FILETYPE | ISLAZY | NEXTSTEP | STATUS | PROGRESS | TIME |
+------+--------------------------------------+--------------------------------------+----------+-------+----------+--------+----------+--------+----------+---------------------+
| root | a19b5e5e-b306-488f-8e6d-d87282c869cb | d26e27a8-fcbd-4f7a-adf8-53795217cbb0 | clone | /root | file | false | end | done | 1 | 2006-01-02 15:04:05 |
+------+--------------------------------------+--------------------------------------+----------+-------+----------+--------+----------+--------+----------+---------------------+
```

#### status

##### status etcd
Expand Down
3 changes: 3 additions & 0 deletions tools-v2/internal/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ var (
ErrBsListSnaspshot = func(requestId, code, message string) *CmdError {
return NewInternalCmdError(78, fmt.Sprintf("list snapshot fail, requestId: %s, code: %s, message: %s", requestId, code, message))
}
ErrBsGetCloneRecover = func() *CmdError {
return NewInternalCmdError(73, "get clone-recover fail, err: %s")
}

// http error
ErrHttpUnreadableResult = func() *CmdError {
Expand Down
4 changes: 4 additions & 0 deletions tools-v2/internal/utils/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const (
ROW_HEALTHY_RATIO = "ratio"
ROW_UNHEALTHY_RATIO = "unhealthyRatio"
ROW_FORMAT_PERCENT = "formatPercent"
ROW_TASKTYPE = "taskType"
ROW_ISLAZY = "isLazy"
ROW_NEXTSTEP = "nextStep"
ROW_TIME = "time"

ROW_RW_STATUS = "rwStatus"
ROW_DISK_STATE = "diskState"
Expand Down
23 changes: 11 additions & 12 deletions tools-v2/internal/utils/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ type SnapshotInfos []SnapshotInfo
var SnapshotStatus = []string{"done", "in-progress", "deleting", "errorDeleting", "canceling", "error"}

type TaskInfo struct {
File string `json:"File"`
FileType int `json:"FileType"`
IsLazy bool `json:"IsLazy"`
NextStep int `json:"NextStep"`
Progress int `json:"Progress"`
Src string `json:"Src"`
TaskStatus int `json:"TaskStatus"`
TaskType int `json:"TaskType"`
Time int `json:"Time"`
UUID string `json:"UUID"`
User string `json:"User"`
File string `json:"File"`
FileType int `json:"FileType"`
IsLazy bool `json:"IsLazy"`
NextStep int `json:"NextStep"`
Progress float64 `json:"Progress"`
Src string `json:"Src"`
TaskStatus int `json:"TaskStatus"`
TaskType int `json:"TaskType"`
Time int64 `json:"Time"`
UUID string `json:"UUID"`
User string `json:"User"`
}

type TaskInfos []TaskInfo
Expand All @@ -83,4 +83,3 @@ var TaskStatus = []string{"Done", "Cloning", "Recovering", "Cleaning", "ErrorCle
var TaskType = []string{"clone", "recover"}
var FileType = []string{"file", "snapshot"}
var CloneStep = []string{"CreateCloneFile", "CreateCloneMeta", "CreateCloneChunk", "CompleteCloneMeta", "RecoverChunk", "ChangeOwner", "RenameCloneFile", "CompleteCloneFile", "End"}
var IsLazy = []string{"false", "true"}
45 changes: 8 additions & 37 deletions tools-v2/pkg/cli/command/curvebs/delete/volume/clone/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package clone
import (
"encoding/json"
"fmt"
clone_recover "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/volume/clone-recover"
"sync"
"time"

Expand Down Expand Up @@ -78,43 +79,13 @@ func (rCmd *CloneCmd) Init(cmd *cobra.Command, args []string) error {
}

func (rCmd *CloneCmd) RunCommand(cmd *cobra.Command, args []string) error {
params := map[string]any{
snapshotutil.QueryAction: snapshotutil.ActionGetCloneTaskList,
snapshotutil.QueryType: snapshotutil.TypeCloneTask,
snapshotutil.QueryUser: rCmd.user,
snapshotutil.QueryUUID: rCmd.taskID,
snapshotutil.QuerySource: rCmd.src,
snapshotutil.QueryDestination: rCmd.dest,
snapshotutil.QueryStatus: rCmd.status,
snapshotutil.QueryLimit: 100,
snapshotutil.QueryOffset: 0,
}
records := make(snapshotutil.TaskInfos, 0)
for {
subUri := snapshotutil.NewQuerySubUri(params)
metric := basecmd.NewMetric(rCmd.snapshotAddrs, subUri, rCmd.timeout)
result, err := basecmd.QueryMetric(metric)
if err.TypeCode() != cmderror.CODE_SUCCESS {
return err.ToError()
}

var payload struct {
snapshotutil.Response
TaskInfos snapshotutil.TaskInfos `json:"TaskInfos"`
TotalCount int `json:"TotalCount"`
}
if err := json.Unmarshal([]byte(result), &payload); err != nil {
return err
}
if payload.Code != snapshotutil.ResultSuccess {
return fmt.Errorf("get clone list fail, requestId: %s, code: %s, message: %s", payload.RequestId, payload.Code, payload.Message)
}
if len(payload.TaskInfos) == 0 {
break
} else {
records = append(records, payload.TaskInfos...)
params[snapshotutil.QueryOffset] = params[snapshotutil.QueryOffset].(int) + params[snapshotutil.QueryLimit].(int)
}
config.AddBsTaskTypeOptionFlag(rCmd.Cmd)
rCmd.Cmd.ParseFlags([]string{
fmt.Sprintf("--%s", config.CURVEBS_TYPE), "clone",
})
records, err := clone_recover.GetCloneOrRecoverList(rCmd.Cmd)
if err.TypeCode() != cmderror.CODE_SUCCESS {
return err.ToError()
}

wg := sync.WaitGroup{}
Expand Down
60 changes: 16 additions & 44 deletions tools-v2/pkg/cli/command/curvebs/delete/volume/recover/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
cobrautil "github.com/opencurve/curve/tools-v2/internal/utils"
snapshotutil "github.com/opencurve/curve/tools-v2/internal/utils/snapshot"
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
clone_recover "github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/volume/clone-recover"
"github.com/opencurve/curve/tools-v2/pkg/config"
"github.com/opencurve/curve/tools-v2/pkg/output"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -77,56 +78,26 @@ func (rCmd *RecoverCmd) Init(cmd *cobra.Command, args []string) error {
}

func (rCmd *RecoverCmd) RunCommand(cmd *cobra.Command, args []string) error {
params := map[string]any{
snapshotutil.QueryAction: snapshotutil.ActionGetCloneTaskList,
snapshotutil.QueryType: snapshotutil.TypeRecoverTask,
snapshotutil.QueryUser: rCmd.user,
snapshotutil.QueryUUID: rCmd.taskID,
snapshotutil.QuerySource: rCmd.src,
snapshotutil.QueryDestination: rCmd.dest,
snapshotutil.QueryStatus: rCmd.status,
snapshotutil.QueryLimit: 100,
snapshotutil.QueryOffset: 0,
}
records := make(snapshotutil.TaskInfos, 0)
for {
subUri := snapshotutil.NewQuerySubUri(params)
metric := basecmd.NewMetric(rCmd.snapshotAddrs, subUri, rCmd.timeout)
result, err := basecmd.QueryMetric(metric)
if err.TypeCode() != cmderror.CODE_SUCCESS {
return err.ToError()
}

var payload struct {
snapshotutil.Response
TaskInfos snapshotutil.TaskInfos `json:"TaskInfos"`
TotalCount int `json:"TotalCount"`
}
if err := json.Unmarshal([]byte(result), &payload); err != nil {
return err
}
if payload.Code != snapshotutil.ResultSuccess {
return fmt.Errorf("get clone list fail, requestId: %s, code: %s, message: %s", payload.RequestId, payload.Code, payload.Message)
}
if len(payload.TaskInfos) == 0 {
break
} else {
records = append(records, payload.TaskInfos...)
params[snapshotutil.QueryOffset] = params[snapshotutil.QueryOffset].(int) + params[snapshotutil.QueryLimit].(int)
}
config.AddBsTaskTypeOptionFlag(rCmd.Cmd)
rCmd.Cmd.ParseFlags([]string{
fmt.Sprintf("--%s", config.CURVEBS_TYPE), "recover",
})
records, err := clone_recover.GetCloneOrRecoverList(rCmd.Cmd)
if err.TypeCode() != cmderror.CODE_SUCCESS {
return err.ToError()
}

wg := sync.WaitGroup{}
for _, item := range records {
wg.Add(1)
go func(clone snapshotutil.TaskInfo) {
go func(recover snapshotutil.TaskInfo) {
defer wg.Done()
result := cobrautil.ROW_VALUE_SUCCESS
reason := ""
params := map[string]any{
snapshotutil.QueryAction: snapshotutil.ActionCleanCloneTask,
snapshotutil.QueryUser: clone.User,
snapshotutil.QueryUUID: clone.UUID,
snapshotutil.QueryUser: recover.User,
snapshotutil.QueryUUID: recover.UUID,
}
subUri := snapshotutil.NewQuerySubUri(params)
metric := basecmd.NewMetric(rCmd.snapshotAddrs, subUri, rCmd.timeout)
Expand All @@ -147,16 +118,17 @@ func (rCmd *RecoverCmd) RunCommand(cmd *cobra.Command, args []string) error {
}
}
rCmd.TableNew.Append(cobrautil.Map2List(map[string]string{
cobrautil.ROW_USER: clone.User,
cobrautil.ROW_SRC: clone.Src,
cobrautil.ROW_TASK_ID: clone.UUID,
cobrautil.ROW_FILE: clone.File,
cobrautil.ROW_USER: recover.User,
cobrautil.ROW_SRC: recover.Src,
cobrautil.ROW_TASK_ID: recover.UUID,
cobrautil.ROW_FILE: recover.File,
cobrautil.ROW_RESULT: result,
cobrautil.ROW_REASON: reason,
}, rCmd.Header))
}(item)
}
wg.Wait()

rCmd.Result = records
rCmd.Error = cmderror.Success()
return nil
Expand Down
2 changes: 2 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/file"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/scanstatus"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/seginfo"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/query/volume"
"github.com/spf13/cobra"
)

Expand All @@ -43,6 +44,7 @@ func (queryCmd *QueryCommand) AddSubCommands() {
seginfo.NewSeginfoCommand(),
chunk.NewChunkCommand(),
scanstatus.NewScanStatusCommand(),
volume.NewVolumeCommand(),
)
}

Expand Down
Loading

0 comments on commit cf3d33f

Please sign in to comment.