Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] tools-v2: add bs check server #2463

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion tools-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ A tool for CurveFS & CurveBs.
- [create dir](#create-dir)
- [check](#check-1)
- [check copyset](#check-copyset-1)
- [check server](#check-server)
- [snapshot](#snapshot)
- [snapshot copyset](#snapshot-copyset)
- [Comparison of old and new commands](#comparison-of-old-and-new-commands)
Expand Down Expand Up @@ -1335,6 +1336,28 @@ Output:
+------------+-----------+--------+--------+--------+---------+
```

#### check server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complement the comparison of old and new tools

Comparison of old and new commands

curve bs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


check copysets health in server

Usage:

```shell
curve bs check server --serverid 1
curve bs check server --ip 127.0.0.1 --port 8200
```

Output:

```shell
+--------+-----------+-------+------------------+
| SERVER | IP | TOTAL | UNHEALTHYCOPYSET |
+--------+-----------+-------+------------------+
| 1 | 127.0.0.1 | 100 | 0(0%) |
+--------+-----------+-------+------------------+
```


### snapshot

#### snapshot copyset
Expand Down Expand Up @@ -1405,6 +1428,7 @@ Output:
| curve_ops_tool check-copyset | curve bs check copyset |
| curve_ops_tool client-status | curve bs status client |
| curve_ops_tool check-operator | curve bs check operator |
| curve_ops_tool check-server | curve bs check server |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete line 1444, and please don't delete the blank line at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

| curve_ops_tool snapshot-clone-status | curve bs status snapshotserver |
| curve_ops_tool transfer-leader | curve bs update leader |
| curve_ops_tool do-snapshot | curve bs snapshot copyset |
Expand All @@ -1417,7 +1441,6 @@ Output:
| curve_ops_tool check-consistency | |
| curve_ops_tool do-snapshot-all | |
| curve_ops_tool check-chunkserver | |
| curve_ops_tool check-server | |
| curve_ops_tool list-may-broken-vol | |
| curve_ops_tool set-copyset-availflag | |
| curve_ops_tool rapid-leader-schedule | |
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 @@ -444,6 +444,9 @@ var (
ErrBsListChunkServer = func() *CmdError {
return NewInternalCmdError(54, "list chunkserver fail, err: %s")
}
ErrBsGetChunkServerInfos = func() *CmdError {
return NewInternalCmdError(55, "get chunkserver infos fail, err: %s")
}

// http error
ErrHttpUnreadableResult = func() *CmdError {
Expand Down
2 changes: 2 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/copyset"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/operator"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/server"
"github.com/spf13/cobra"
)

Expand All @@ -39,6 +40,7 @@ func (checkCmd *CheckCommand) AddSubCommands() {
checkCmd.Cmd.AddCommand(
copyset.NewCopysetCommand(),
operator.NewOperatorCommand(),
server.NewServerCommand(),
)
}

Expand Down
142 changes: 142 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/check/server/get_chunk_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: CurveCli
* Created Date: 2023-05-07
* Author: pengpengSir
*/
package server

import (
"context"

cmderror "github.com/opencurve/curve/tools-v2/internal/error"
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
"github.com/opencurve/curve/tools-v2/pkg/config"
"github.com/opencurve/curve/tools-v2/pkg/output"
"github.com/opencurve/curve/tools-v2/proto/proto/topology"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)

type GetChunkServerInfosRpc struct {
Info *basecmd.Rpc
Request *topology.ListChunkServerRequest
topologyClient topology.TopologyServiceClient
}

type GetChunkInfosCommand struct {
basecmd.FinalCurveCmd
Rpc *GetChunkServerInfosRpc
Response *topology.ListChunkServerResponse
}

var _ basecmd.FinalCurveCmdFunc = (*GetChunkInfosCommand)(nil)

func NewChunkInfosCommand() *cobra.Command {
return NewGetChunkServerInfosCommand().Cmd
}

func NewGetChunkServerInfosCommand() *GetChunkInfosCommand {
gCmd := &GetChunkInfosCommand{
FinalCurveCmd: basecmd.FinalCurveCmd{},
}
basecmd.NewFinalCurveCli(&gCmd.FinalCurveCmd, gCmd)
return gCmd
}

func (gcRpc *GetChunkServerInfosRpc) NewRpcClient(cc grpc.ClientConnInterface) {
gcRpc.topologyClient = topology.NewTopologyServiceClient(cc)
}

func (gcRpc *GetChunkServerInfosRpc) Stub_Func(ctx context.Context) (interface{}, error) {
return gcRpc.topologyClient.ListChunkServer(ctx, gcRpc.Request)
}

func (gCmd *GetChunkInfosCommand) AddFlags() {
config.AddBsMdsFlagOption(gCmd.Cmd)
config.AddRpcRetryTimesFlag(gCmd.Cmd)
config.AddRpcTimeoutFlag(gCmd.Cmd)
config.AddBsServerIdOptionFlag(gCmd.Cmd)
config.AddBsIpOptionFlag(gCmd.Cmd)
config.AddBsPortOptionFlag(gCmd.Cmd)
}

func (gCmd *GetChunkInfosCommand) Init(cmd *cobra.Command, args []string) error {
timeout := config.GetFlagDuration(gCmd.Cmd, config.RPCTIMEOUT)
retrytimes := config.GetFlagInt32(gCmd.Cmd, config.RPCRETRYTIMES)
mdsAddrs, _ := config.GetBsMdsAddrSlice(gCmd.Cmd)
ip := config.GetFlagString(gCmd.Cmd, config.CURVEBS_IP)
port := config.GetFlagUint32(gCmd.Cmd, config.CURVEBS_PORT)
serverid := config.GetFlagUint32(gCmd.Cmd, config.CURVEBS_SERVER_ID)

if ip != "" {
rpc := &GetChunkServerInfosRpc{
Request: &topology.ListChunkServerRequest{
Ip: &ip,
Port: &port,
},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"),
}
gCmd.Rpc = rpc
} else {
rpc := &GetChunkServerInfosRpc{
Request: &topology.ListChunkServerRequest{
ServerID: &serverid,
},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"),
}
gCmd.Rpc = rpc
}
Comment on lines +87 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ip != "" {
rpc := &GetChunkServerInfosRpc{
Request: &topology.ListChunkServerRequest{
Ip: &ip,
Port: &port,
},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"),
}
gCmd.Rpc = rpc
} else {
rpc := &GetChunkServerInfosRpc{
Request: &topology.ListChunkServerRequest{
ServerID: &serverid,
},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"),
}
gCmd.Rpc = rpc
}
gCmd.Rpc = &GetChunkServerInfosRpc{
Request: &topology.ListChunkServerRequest{},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "ListChunkServer"),
}
if ip != "" {
gCmd.Rpc.Request.Ip = &ip
gCmd.Rpc.Request.Port = &port
} else {
gCmd.Rpc.Request.ServerID = &serverid
}

return nil
}

func (gCmd *GetChunkInfosCommand) Print(cmd *cobra.Command, args []string) error {
return output.FinalCmdOutput(&gCmd.FinalCurveCmd, gCmd)
}

func (gCmd *GetChunkInfosCommand) ResultPlainOutput() error {
return output.FinalCmdOutputPlain(&gCmd.FinalCurveCmd)
}

func (gCmd *GetChunkInfosCommand) RunCommand(cmd *cobra.Command, args []string) error {
result, err := basecmd.GetRpcResponse(gCmd.Rpc.Info, gCmd.Rpc)
if err.TypeCode() != cmderror.CODE_SUCCESS {
return err.ToError()
}
gCmd.Response = result.(*topology.ListChunkServerResponse)
return nil
}

func GetChunkserverInfos(caller *cobra.Command) ([]*topology.ChunkServerInfo, *cmderror.CmdError) {
gCmd := NewGetChunkServerInfosCommand()
config.AlignFlagsValue(caller, gCmd.Cmd, []string{
config.CURVEBS_MDSADDR, config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_SERVER_ID, config.CURVEBS_IP, config.CURVEBS_PORT,
})

gCmd.Cmd.SilenceErrors = true
gCmd.Cmd.SilenceUsage = true
gCmd.Cmd.SetArgs([]string{"--format", config.FORMAT_NOOUT})
err := gCmd.Cmd.Execute()
if err != nil {
retErr := cmderror.ErrBsGetChunkServerInfos()
retErr.Format(err.Error())
return nil, retErr
}

return gCmd.Response.ChunkServerInfos, cmderror.Success()
}
143 changes: 143 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/check/server/get_copyset_ids.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
/*
* Copyright (c) 2023 NetEase Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Project: CurveCli
* Created Date: 2023-05-07
* Author: pengpengSir
*/
package server

import (
"context"
"fmt"

cmderror "github.com/opencurve/curve/tools-v2/internal/error"
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
"github.com/opencurve/curve/tools-v2/pkg/config"
"github.com/opencurve/curve/tools-v2/pkg/output"
"github.com/opencurve/curve/tools-v2/proto/proto/topology"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)

type GetChunkServerCopysetsRpc struct {
Info *basecmd.Rpc
Request *topology.GetCopySetsInChunkServerRequest
topologyClient topology.TopologyServiceClient
}

type CopysetidsCommand struct {
basecmd.FinalCurveCmd
Rpc *GetChunkServerCopysetsRpc
Response *topology.GetCopySetsInChunkServerResponse
}

var _ basecmd.FinalCurveCmdFunc = (*CopysetidsCommand)(nil)

func NewCopysetCommand() *cobra.Command {
return NewCopysetidsCommand().Cmd
}

func NewCopysetidsCommand() *CopysetidsCommand {
cCmd := &CopysetidsCommand{
FinalCurveCmd: basecmd.FinalCurveCmd{},
}
basecmd.NewFinalCurveCli(&cCmd.FinalCurveCmd, cCmd)
return cCmd
}

func (tRpc *GetChunkServerCopysetsRpc) NewRpcClient(cc grpc.ClientConnInterface) {
tRpc.topologyClient = topology.NewTopologyServiceClient(cc)
}

func (tRpc *GetChunkServerCopysetsRpc) Stub_Func(ctx context.Context) (interface{}, error) {
return tRpc.topologyClient.GetCopySetsInChunkServer(ctx, tRpc.Request)
}

func (cCmd *CopysetidsCommand) AddFlags() {
config.AddBsMdsFlagOption(cCmd.Cmd)
config.AddRpcRetryTimesFlag(cCmd.Cmd)
config.AddRpcTimeoutFlag(cCmd.Cmd)
config.AddBsChunkServerIDOptionFlag(cCmd.Cmd)
config.AddBsIpOptionFlag(cCmd.Cmd)
config.AddBsPortOptionFlag(cCmd.Cmd)
}

func (cCmd *CopysetidsCommand) Init(cmd *cobra.Command, args []string) error {
timeout := config.GetFlagDuration(cCmd.Cmd, config.RPCTIMEOUT)
retrytimes := config.GetFlagInt32(cCmd.Cmd, config.RPCRETRYTIMES)
mdsAddrs, _ := config.GetBsMdsAddrSlice(cCmd.Cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not check the error


chunkserverId := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_CHUNKSERVER_ID)
hostip := config.GetBsFlagString(cCmd.Cmd, config.CURVEBS_IP)
port := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_PORT)

rpc := &GetChunkServerCopysetsRpc{
Request: &topology.GetCopySetsInChunkServerRequest{
ChunkServerID: &chunkserverId,
HostIp: &hostip,
Port: &port,
},
Info: basecmd.NewRpc(mdsAddrs, timeout, retrytimes, "GetCopysetInChunkServer"),
}
cCmd.Rpc = rpc
return nil
}

func (cCmd *CopysetidsCommand) Print(cmd *cobra.Command, args []string) error {
return output.FinalCmdOutput(&cCmd.FinalCurveCmd, cCmd)
}

func (cCmd *CopysetidsCommand) ResultPlainOutput() error {
return output.FinalCmdOutputPlain(&cCmd.FinalCurveCmd)
}

func (cCmd *CopysetidsCommand) RunCommand(cmd *cobra.Command, args []string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can set Cmd.Error = err, to let client use this error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

result, err := basecmd.GetRpcResponse(cCmd.Rpc.Info, cCmd.Rpc)

if err.TypeCode() != cmderror.CODE_SUCCESS {
fmt.Print(err.Message)
return err.ToError()
}

cCmd.Response = result.(*topology.GetCopySetsInChunkServerResponse)
return nil
}

func GetCopysetids(caller *cobra.Command) (*map[uint32]uint32, *cmderror.CmdError) {
cCmd := NewCopysetidsCommand()
config.AlignFlagsValue(caller, cCmd.Cmd, []string{
config.CURVEBS_MDSADDR, config.RPCRETRYTIMES, config.RPCTIMEOUT, config.CURVEBS_CHUNKSERVER_ID,
config.CURVEBS_IP, config.CURVEBS_PORT,
})
cCmd.Cmd.SilenceErrors = true
cCmd.Cmd.SilenceUsage = true
cCmd.Cmd.SetArgs([]string{"--format", config.FORMAT_NOOUT})
err := cCmd.Cmd.Execute()
if err != nil {
retErr := cmderror.ErrBsGetCopysetStatus()
retErr.Format(err.Error())
return nil, retErr
}

copysetID2PoolId := make(map[uint32]uint32)
for _, copysetInfo := range cCmd.Response.GetCopysetInfos() {
copysetID2PoolId[copysetInfo.GetCopysetId()] = copysetInfo.GetLogicalPoolId()
}

return &copysetID2PoolId, cmderror.Success()
}
Loading