Skip to content

Commit

Permalink
curvebs|tools-v2|rebuild cil check-chunkserver
Browse files Browse the repository at this point in the history
Signed-off-by: jolly-sy <[email protected]>
  • Loading branch information
jolly-sy committed Dec 19, 2022
1 parent 06a100a commit a8b979d
Show file tree
Hide file tree
Showing 13 changed files with 1,314 additions and 123 deletions.
54 changes: 54 additions & 0 deletions proto/topology.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ enum OnlineState {
UNSTABLE = 2;
}

enum PoolsetType{
SSD = 0;
HDD = 1;
NVME = 2;
}

// etcd struct defination
message ClusterInfoData {
required string clusterId = 1;
Expand Down Expand Up @@ -236,6 +242,7 @@ message ServerRegistRequest {
optional uint32 physicalPoolID = 8;
optional string physicalPoolName = 9; //physicalPoolName is unique
required string desc = 10;
required string poolsetName = 11;
}

message ServerRegistResponse {
Expand Down Expand Up @@ -317,13 +324,16 @@ message PhysicalPoolInfo {
required uint32 physicalPoolID = 1;
required string physicalPoolName = 2;
optional string desc = 3;
optional uint32 poolsetId = 4;
optional string poolsetName = 5;
}

message PhysicalPoolRequest {
//use either physicalPoolID or physicalPoolName
optional uint32 physicalPoolID = 1;
optional string physicalPoolName = 2;
optional string desc = 3;
optional string poolsetName = 4;
}

message PhysicalPoolResponse {
Expand All @@ -334,11 +344,49 @@ message PhysicalPoolResponse {
message ListPhysicalPoolRequest {
}

message ListPhyPoolsInPoolsetRequest {
repeated uint32 poolsetId = 1;
}

message ListPhysicalPoolResponse {
required sint32 statusCode = 1;
repeated PhysicalPoolInfo physicalPoolInfos = 2;
}

//poolset message
message PoolsetRequest{
//use either poolsetID or poolsetName
optional uint32 poolsetID = 1;
optional string poolsetName = 2;
optional PoolsetType type = 3;
optional string desc = 4;
}

message PoolsetInfo {
required uint32 poolsetID = 1;
required string poolsetName = 2;
required PoolsetType type = 3;
required uint32 poolsNum = 4;
optional string desc = 5;
}

message PoolsetResponse {
required sint32 statusCode = 1;
optional PoolsetInfo poolsetInfo = 2;
}



message ListPoolsetRequest{

}

message ListPoolsetResponse{
required sint32 statusCode = 1;
repeated PoolsetInfo poolsetInfos = 2;
}


//logicalpool message
message LogicalPoolInfo {
required uint32 logicalPoolID = 1;
Expand Down Expand Up @@ -518,6 +566,12 @@ service TopologyService {
rpc DeletePhysicalPool(PhysicalPoolRequest) returns (PhysicalPoolResponse);
rpc GetPhysicalPool(PhysicalPoolRequest) returns (PhysicalPoolResponse);
rpc ListPhysicalPool(ListPhysicalPoolRequest) returns (ListPhysicalPoolResponse);
rpc ListPhyPoolsInPoolset(ListPhyPoolsInPoolsetRequest) returns (ListPhysicalPoolResponse);

rpc CreatePoolset(PoolsetRequest) returns (PoolsetResponse);
rpc DeletePoolset(PoolsetRequest) returns (PoolsetResponse);
rpc GetPoolset(PoolsetRequest) returns (PoolsetResponse);
rpc ListPoolset(ListPoolsetRequest) returns (ListPoolsetResponse);

rpc CreateLogicalPool(CreateLogicalPoolRequest) returns (CreateLogicalPoolResponse);
rpc DeleteLogicalPool(DeleteLogicalPoolRequest) returns (DeleteLogicalPoolResponse);
Expand Down
66 changes: 51 additions & 15 deletions tools-v2/internal/error/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ var (
return NewInternalCmdError(36, "get time of day fail, the error is: %s")
}
ErrBsGetFileInfo = func() *CmdError {
return NewInternalCmdError(37, "%s")
return NewInternalCmdError(37, "get file info fail, the error is: %s")
}
ErrBsGetFileSize = func() *CmdError {
return NewInternalCmdError(38, "get file size fail, the error is: %s")
Expand Down Expand Up @@ -406,6 +406,14 @@ var (
ErrBsApplyIndex = func() *CmdError {
return NewInternalCmdError(51, "apply index are not consistency")
}
ErrParseRaftState = func() *CmdError {
return NewInternalCmdError(52, "fail to parse %s! the line is: %s")
}

ErrChunkServerNotHealth = func() *CmdError {
return NewInternalCmdError(53, "Some copysets not found on chunkserver, may be tranfered, chunkserver is not healthy")
}

// http error
ErrHttpUnreadableResult = func() *CmdError {
return NewHttpResultCmdError(1, "http response is unreadable, the uri is: %s, the error is: %s")
Expand Down Expand Up @@ -635,7 +643,7 @@ var (
default:
message = fmt.Sprintf("create %s[%s], err: %s", topoType, name, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListVolsOnDamagedCps = func(statusCode nameserver2.StatusCode) *CmdError {
var message string
Expand All @@ -657,7 +665,7 @@ var (
default:
message = fmt.Sprintf("get copysets in chunk server fail errCode: %s, chunkserver addr is %s", statusCode.String(), csAddr)
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrGetChunkServerListInCopySets = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -668,7 +676,7 @@ var (
default:
message = fmt.Sprintf("Get chunk server list in copysets fail errCode: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListChunkServers = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -679,7 +687,7 @@ var (
default:
message = fmt.Sprintf("list chunk servers fail errCode: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListPoolsets = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -690,7 +698,7 @@ var (
default:
message = fmt.Sprintf("list poolsets err: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListPhyPoolsInPst = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -701,7 +709,7 @@ var (
default:
message = fmt.Sprintf("list physicalpools in poolset err: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListZonesInPhyPool = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -712,7 +720,7 @@ var (
default:
message = fmt.Sprintf("list zones in physicalpool err: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}
ErrListServers = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
Expand All @@ -723,7 +731,7 @@ var (
default:
message = fmt.Sprintf("list servers err: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrListZones = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
Expand All @@ -735,7 +743,7 @@ var (
default:
message = fmt.Sprintf("list topology err: %s", statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrDelServer = func(statusCode bs_statuscode.TopoStatusCode, topoType string, name string) *CmdError {
Expand All @@ -747,7 +755,7 @@ var (
default:
message = fmt.Sprintf("delete %s[%s], err: %s", topoType, name, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrDelZone = func(statusCode bs_statuscode.TopoStatusCode, topoType string, name string) *CmdError {
Expand All @@ -759,7 +767,7 @@ var (
default:
message = fmt.Sprintf("delete %s[%s], err: %s", topoType, name, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrDelPhyPool = func(statusCode bs_statuscode.TopoStatusCode, topoType string, name string) *CmdError {
Expand All @@ -771,7 +779,7 @@ var (
default:
message = fmt.Sprintf("delete %s[%s], err: %s", topoType, name, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrGetChunkServerListInCopySetsRpc = func(statusCode bs_statuscode.TopoStatusCode, logicalpoolId uint32) *CmdError {
Expand All @@ -783,7 +791,7 @@ var (
default:
message = fmt.Sprintf("the logicalpool id of copysets is %d, err: %s", logicalpoolId, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrBsGetChunkHash = func(scode bs_statuscode.ChunkStatusCode) *CmdError {
Expand Down Expand Up @@ -848,7 +856,7 @@ var (
default:
message = fmt.Sprintf("delete %s[%s], err: %s", topoType, name, statusCode.String())
}
return NewRpcReultCmdError(code, message)
return NewRpcReultCmdError(-code, message)
}

ErrBsGetSegInfo = func(statusCode bs_statuscode.GetSegmentRes) *CmdError {
Expand All @@ -868,4 +876,32 @@ var (
}
return NewRpcReultCmdError(code, message)
}
ErrBsGetChunkServer = func(statusCode bs_statuscode.TopoStatusCode) *CmdError {
var message string
code := int(statusCode)
switch statusCode {
case bs_statuscode.TopoStatusCode_Success:
message = "get chunkserver info successfully"
case bs_statuscode.TopoStatusCode_ChunkServerNotFound:
message = fmt.Sprintf("chunkserver not found, errCode is %s", statusCode.String())
default:
message = fmt.Sprintf("get chunkserver info fail, errCode is %s", statusCode.String())
}
return NewRpcReultCmdError(-code, message)
}
ErrBsGetRaftStatus = func(statusCode bs_statuscode.CsHealthStatus, csAddr string) *CmdError {
var message string
code := int(statusCode)
switch statusCode {
case bs_statuscode.CsHealthStatus_CpsHealthy:
message = "chunkserver is healthy"
case bs_statuscode.CsHealthStatus_CpsNotHealthy:
message = fmt.Sprintf("chunkserver is healthy, errCode is %s", statusCode.String())
case bs_statuscode.CsHealthStatus_CsNotOnline:
message = fmt.Sprintf("chunkserver is not online, csAddr is %s", csAddr)
default:
message = fmt.Sprintf("get chunkserver raft status fail, errCode is %s", statusCode.String())
}
return NewRpcReultCmdError(-code, message)
}
)
7 changes: 6 additions & 1 deletion tools-v2/internal/proto/curvebs/topology/statuscode.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ enum ChunkStatusCode{
EpochOld = 12; // 请求中的epoch太老了
}


// chunkserver health status
enum CsHealthStatus{
CpsHealthy = 0; // chunkserver上的所有copyset健康
CpsNotHealthy = -1; //chunkserver上的所有copyset不健康
CsNotOnline = -2; //chunkserver 不在线
}
23 changes: 20 additions & 3 deletions tools-v2/internal/utils/copyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const (
)

const (
COPYSET_OK_STR = "ok"
COPYSET_WARN_STR = "warn"
COPYSET_ERROR_STR = "error"
COPYSET_OK_STR = "ok"
COPYSET_WARN_STR = "warn"
COPYSET_ERROR_STR = "error"
COPYSET_NOTEXIST_STR = "not exist"
)

Expand Down Expand Up @@ -163,3 +163,20 @@ func CopysetKey2PoolidCopysetid(copysetKey uint64) (uint32, uint32) {
copysetid := copysetKey & (1<<32 - 1)
return uint32(poolid), uint32(copysetid)
}

// use poolId and copysetId to caculate groupId
func GenGroupId(poolId uint32, copysetId uint32) uint64 {
res := (uint64(poolId) << 32) | uint64(copysetId)
return res
}

// use groupId to caculate poolId
func GetPoolIdFromGid(gid uint64) uint32 {
return uint32(gid >> 32)
}

// use groupId to caculate copysetId
func GetCpsIdFromGid(gid uint64) uint32 {
res := gid & ((uint64(1) << 32) - 1)
return uint32(res)
}
14 changes: 14 additions & 0 deletions tools-v2/internal/utils/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (

const (
IP_PORT_REGEX = "((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]):([0-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-4]\\d{4}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5]))|(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])"
IP_REGEX = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$"
PATH_REGEX = `^(/[^/ ]*)+/?$`
FS_NAME_REGEX = "^([a-z0-9]+\\-?)+$"
)
Expand All @@ -51,6 +52,19 @@ func IsValidAddr(addr string) bool {
return true
}

func IsValidIp(ip string) bool {
isMatch, err := regexp.MatchString(IP_REGEX, ip)
if err != nil {
return false
}
return isMatch
}

func IsValidPort(port string) bool {
p, _ := strconv.ParseInt(port, 10, 32)
return p >= 0 && p <= 65535
}

func IsValidFsname(fsName string) bool {
matched, err := regexp.MatchString(FS_NAME_REGEX, fsName)
if err != nil || !matched {
Expand Down
4 changes: 4 additions & 0 deletions tools-v2/pkg/cli/command/curvebs/check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package check

import (
basecmd "github.com/opencurve/curve/tools-v2/pkg/cli/command"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/chunkserver"
"github.com/opencurve/curve/tools-v2/pkg/cli/command/curvebs/check/consistency"
"github.com/spf13/cobra"
)
Expand All @@ -38,6 +39,9 @@ func (checkCmd *CheckCmd) AddSubCommands() {
checkCmd.Cmd.AddCommand(
consistency.NewConsistencyCmd(),
)
checkCmd.Cmd.AddCommand(
chunkserver.NewChunkServerCmd(),
)
}

func NewCheckCmd() *cobra.Command {
Expand Down
Loading

0 comments on commit a8b979d

Please sign in to comment.