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

finish issue #2355 #2462

Closed
wants to merge 2 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
227 changes: 110 additions & 117 deletions tools-v2/internal/utils/row.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,121 +20,114 @@
* Author: chengyi (Cyber-SiKu)
*/

package cobrautil
package cobrautil

const (
ROW_ADDR = "addr"
ROW_ALLOC = "alloc"
ROW_ALLOC_SIZE = "allocatedSize"
ROW_BLOCKSIZE = "blocksize"
ROW_CAPACITY = "capacity"
ROW_CHILD_LIST = "childList"
ROW_CHILD_TYPE = "childType"
ROW_CHUNK = "chunk"
ROW_CHUNK_SIZE = "chunkSize"
ROW_COPYSET = "copyset"
ROW_COPYSET_ID = "copysetId"
ROW_COPYSET_KEY = "copysetKey"
ROW_CREATE_TIME = "createTime"
ROW_CREATED = "created"
ROW_CTIME = "ctime"
ROW_DUMMY_ADDR = "dummyAddr"
ROW_END = "end"
ROW_EPOCH = "epoch"
ROW_EXPLAIN = "explain"
ROW_EXTERNAL_ADDR = "externalAddr"
ROW_FILE_NAME = "fileName"
ROW_FILE_SIZE = "fileSize"
ROW_FILE_TYPE = "fileType"
ROW_FS_ID = "fsId"
ROW_FS_NAME = "fsName"
ROW_FS_TYPE = "fsType"
ROW_GROUP = "group"
ROW_HOSTNAME = "hostname"
ROW_ID = "id"
ROW_INODE_ID = "inodeId"
ROW_INTERNAL_ADDR = "internalAddr"
ROW_IP = "ip"
ROW_KEY = "key"
ROW_LEADER = "leader"
ROW_LEADER_PEER = "leaderPeer"
ROW_LEFT = "left"
ROW_LENGTH = "length"
ROW_LOCATION = "location"
ROW_LOG_GAP = "logGap"
ROW_LOGICALPOOL = "logicalpool"
ROW_METASERVER = "metaserver"
ROW_METASERVER_ADDR = "metaserverAddr"
ROW_MOUNT_NUM = "mountNum"
ROW_MOUNTPOINT = "mountpoint"
ROW_NAME = "name"
ROW_NLINK = "nlink"
ROW_NUM = "num"
ROW_ONLINE_STATE = "onlineState"
ROW_OPERATION = "operation"
ROW_OPNAME = "opname"
ROW_ORIGINAL_PATH = "originalPath"
ROW_OWNER = "owner"
ROW_PARENT = "parent"
ROW_PARENT_ID = "parentId"
ROW_PARTITION_ID = "partitionId"
ROW_PEER = "peer"
ROW_PEER_ADDR = "peerAddr"
ROW_PEER_ID = "peerId"
ROW_PEER_NUMBER = "peerNumber"
ROW_PHYPOOL = "phyPool"
ROW_POOL = "pool"
ROW_POOL_ID = "poolId"
ROW_PORT = "port"
ROW_READONLY = "readonly"
ROW_REASON = "reason"
ROW_RECYCLABLE = "recyclable"
ROW_RECYCLE = "recycle"
ROW_RESULT = "result"
ROW_SCAN = "scan"
ROW_SEGMENT = "segment"
ROW_SEGMENT_SIZE = "segmentSize"
ROW_SEQ = "seq"
ROW_SERVER = "server"
ROW_SIZE = "size"
ROW_START = "start"
ROW_STATE = "state"
ROW_STATUS = "status"
ROW_STRIPE = "stripe"
ROW_SUM_IN_DIR = "sumInDir"
ROW_TERM = "term"
ROW_THROTTLE = "throttle"
ROW_TOTAL = "total"
ROW_TYPE = "type"
ROW_USED = "used"
ROW_VERSION = "version"
ROW_ZONE = "zone"

// s3
ROW_S3CHUNKINFO_CHUNKID = "s3ChunkId"
ROW_S3CHUNKINFO_LENGTH = "s3Length"
ROW_S3CHUNKINFO_OFFSET = "s3Offset"
ROW_S3CHUNKINFO_SIZE = "s3Size"

// vale
ROW_VALUE_ADD = "add"
ROW_VALUE_DEL = "del"
ROW_VALUE_DNE = "DNE"
ROW_VALUE_FAILED = "failed"
ROW_VALUE_LOGICAL = "logical"
ROW_VALUE_NO_VALUE = "-"
ROW_VALUE_NULL = "null"
ROW_VALUE_OFFLINE = "offline"
ROW_VALUE_PHYSICAL = "physical"
ROW_VALUE_SUCCESS = "success"
ROW_VALUE_UNKNOWN = "unknown"
)

// topology type
const (
TYPE_POOL = "pool"
TYPE_SERVER = "server"
TYPE_ZONE = "zone"
TYPE_PHYPOOL = "physicalpool"
TYPE_LGPOOL = "logicalpool"
)
const (
ROW_ADDR = "addr"
ROW_ALLOC = "alloc"
ROW_ALLOC_SIZE = "allocatedSize"
ROW_BLOCKSIZE = "blocksize"
ROW_CAPACITY = "capacity"
ROW_CHILD_LIST = "childList"
ROW_CHILD_TYPE = "childType"
ROW_CHUNK = "chunk"
ROW_COPYSET_ID = "copysetId"
ROW_COPYSET_KEY = "copysetKey"
ROW_CREATE_TIME = "createTime"
ROW_CTIME = "ctime"
ROW_DUMMY_ADDR = "dummyAddr"
ROW_END = "end"
ROW_EPOCH = "epoch"
ROW_EXPLAIN = "explain"
ROW_EXTERNAL_ADDR = "externalAddr"
ROW_FILE_SIZE = "fileSize"
ROW_FILE_TYPE = "fileType"
ROW_FILE_NAME = "fileName"
ROW_FS_ID = "fsId"
ROW_FS_NAME = "fsName"
ROW_FS_TYPE = "fsType"
ROW_HOSTNAME = "hostname"
ROW_ID = "id"
ROW_INODE_ID = "inodeId"
ROW_INTERNAL_ADDR = "internalAddr"
ROW_KEY = "key"
ROW_LEADER_PEER = "leaderPeer"
ROW_LEFT = "left"
ROW_LENGTH = "length"
ROW_LOG_GAP = "logGap"
ROW_METASERVER = "metaserver"
ROW_METASERVER_ADDR = "metaserverAddr"
ROW_MOUNT_NUM = "mountNum"
ROW_MOUNTPOINT = "mountpoint"
ROW_NAME = "name"
ROW_NLINK = "nlink"
ROW_NUM = "num"
ROW_ONLINE_STATE = "onlineState"
ROW_OPERATION = "operation"
ROW_ORIGINAL_PATH = "originalPath"
ROW_OWNER = "owner"
ROW_PARENT = "parent"
ROW_PARENT_ID = "parentId"
ROW_PARTITION_ID = "partitionId"
ROW_PEER_ADDR = "peerAddr"
ROW_PEER_ID = "peerId"
ROW_PEER_NUMBER = "peerNumber"
ROW_PHYPOOL = "phyPool"
ROW_POOL = "pool"
ROW_POOL_ID = "poolId"
ROW_READONLY = "readonly"
ROW_RECYCLE = "recycle"
ROW_RESULT = "result"
ROW_SCAN = "scan"
ROW_SEGMENT = "segment"
ROW_SEQ = "seq"
ROW_SERVER = "server"
ROW_SIZE = "size"
ROW_START = "start"
ROW_STATE = "state"
ROW_STATUS = "status"
ROW_STRIPE = "stripe"
ROW_SUM_IN_DIR = "sumInDir"
ROW_TERM = "term"
ROW_THROTTLE = "throttle"
ROW_TOTAL = "total"
ROW_TYPE = "type"
ROW_USED = "used"
ROW_VERSION = "version"
ROW_ZONE = "zone"
ROW_IP = "ip"
ROW_PORT = "port"
ROW_REASON = "reason"
ROW_PEER = "peer"
ROW_COPYSET = "copyset"
ROW_LEADER = "leader"
ROW_COPYSET_COUNT = "copysetCount"
ROW_UNHEALTHY_COPYSET_COUNT = "unhealthy copyset count"
ROW_UNHEALTHY_COPYSET_RATIO = "unhealthy copyset ratio"

// s3
ROW_S3CHUNKINFO_CHUNKID = "s3ChunkId"
ROW_S3CHUNKINFO_LENGTH = "s3Length"
ROW_S3CHUNKINFO_OFFSET = "s3Offset"
ROW_S3CHUNKINFO_SIZE = "s3Size"

// vale
ROW_VALUE_ADD = "add"
ROW_VALUE_DEL = "del"
ROW_VALUE_DNE = "DNE"
ROW_VALUE_OFFLINE = "offline"
ROW_VALUE_UNKNOWN = "unknown"
ROW_VALUE_SUCCESS = "success"
ROW_VALUE_FAILED = "failed"
ROW_VALUE_NULL = "null"
)

// topology type
const (
TYPE_POOL = "pool"
TYPE_SERVER = "server"
TYPE_ZONE = "zone"
TYPE_PHYPOOL = "physicalpool"
TYPE_LGPOOL = "logicalpool"
)

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.NewCheckServerCommand(),
)
}

Expand Down
146 changes: 146 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,146 @@
/*
* Copyright (c) 2022 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 {
ccCmd := &CopysetidsCommand{
FinalCurveCmd: basecmd.FinalCurveCmd{},
}
basecmd.NewFinalCurveCli(&ccCmd.FinalCurveCmd, ccCmd)
return ccCmd
}

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.AddBsChunkServerIDFlag(cCmd.Cmd)
config.AddBsHostIpFlag(cCmd.Cmd)
config.AddBsPortFlag(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)

chunkserverId, _ := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_CHUNK_SERVER_ID)
hostip := config.GetBsFlagString(cCmd.Cmd, config.CURVEBS_HOST_IP)
port, _ := config.GetBsFlagUint32(cCmd.Cmd, config.CURVEBS_PORT)

// fmt.Printf("%d %s %d", chunkserverId, hostip, 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 {
result, err := basecmd.GetRpcResponse(cCmd.Rpc.Info, cCmd.Rpc)

if err.Message != "success" {
fmt.Print(err.Message)
return err.ToError()
}

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

// 根据ChunkServerID, HostIP, Port返回 copysetid2poolid
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_CHUNK_SERVER_ID,
config.CURVEBS_HOST_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