Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
chore: update pb definition (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuLiangWang authored Nov 29, 2022
1 parent 97b7100 commit 51c36f6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/AlekSi/gocov-xml v1.0.0
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221115062517-8cd021e19e44
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221129093313-317dca741863
github.com/axw/gocov v1.1.0
github.com/caarlos0/env/v6 v6.10.1
github.com/json-iterator/go v1.1.11
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221115062517-8cd021e19e44 h1:vyeukX4KmF5881Mh5kmaCsJvt6CiowsZs3rZ9bebpiA=
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221115062517-8cd021e19e44/go.mod h1:qLTh6jtSu2ZLIFsU3iiDIKvkrQvyY/Csg6Mk0Ub0QZ4=
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221129093313-317dca741863 h1:LJOG/OhSD0YB9SpYKM6I1sNcwicQ4AqgCneHim+PL+U=
github.com/CeresDB/ceresdbproto/golang v0.0.0-20221129093313-317dca741863/go.mod h1:qLTh6jtSu2ZLIFsU3iiDIKvkrQvyY/Csg6Mk0Ub0QZ4=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
4 changes: 2 additions & 2 deletions server/storage/storage_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s *metaStorageImpl) GetClusterView(ctx context.Context, req GetClusterView
return GetClusterViewResult{}, errors.WithMessagef(err, "get cluster view, clusterID:%d, key:%s", req.ClusterID, key)
}

clusterView := &clusterpb.ClusterTopology{}
clusterView := &clusterpb.ClusterView{}
if err = proto.Unmarshal([]byte(value), clusterView); err != nil {
return GetClusterViewResult{}, ErrDecode.WithCausef("decode cluster view, clusterID:%d, err:%v", req.ClusterID, err)
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func (s *metaStorageImpl) ListShardViews(ctx context.Context, req ListShardViews
return ListShardViewsResult{}, errors.WithMessagef(err, "list shard view, clusterID:%d, shardID:%d, key:%s", req.ClusterID, shardID, key)
}

shardViewPB := &clusterpb.ShardTopology{}
shardViewPB := &clusterpb.ShardView{}
if err = proto.Unmarshal([]byte(value), shardViewPB); err != nil {
return ListShardViewsResult{}, ErrDecode.WithCausef("decode shard view, clusterID:%d, shardID:%d, err:%v", req.ClusterID, shardID, err)
}
Expand Down
59 changes: 27 additions & 32 deletions server/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ type NodeStats struct {
type Node struct {
Name string
NodeStats NodeStats
CreatedAt uint64
LastTouchTime uint64
State NodeState
}
Expand All @@ -205,8 +204,7 @@ func convertNodeToPB(node Node) clusterpb.Node {
nodeStats := convertNodeStatsToPB(node.NodeStats)
return clusterpb.Node{
Name: node.Name,
NodeStats: &nodeStats,
CreateTime: node.CreatedAt,
Stats: &nodeStats,
LastTouchTime: node.LastTouchTime,
State: convertNodeStateToPB(node.State),
}
Expand Down Expand Up @@ -234,21 +232,21 @@ func convertClusterToPB(cluster Cluster) clusterpb.Cluster {
}
}

func convertClusterStateToPB(state ClusterState) clusterpb.ClusterTopology_ClusterState {
func convertClusterStateToPB(state ClusterState) clusterpb.ClusterView_ClusterState {
switch state {
case ClusterStateEmpty:
return clusterpb.ClusterTopology_EMPTY
return clusterpb.ClusterView_EMPTY
case ClusterStateStable:
return clusterpb.ClusterTopology_STABLE
return clusterpb.ClusterView_STABLE
}
return clusterpb.ClusterTopology_EMPTY
return clusterpb.ClusterView_EMPTY
}

func convertClusterStatePB(state clusterpb.ClusterTopology_ClusterState) ClusterState {
func convertClusterStatePB(state clusterpb.ClusterView_ClusterState) ClusterState {
switch state {
case clusterpb.ClusterTopology_EMPTY:
case clusterpb.ClusterView_EMPTY:
return ClusterStateEmpty
case clusterpb.ClusterTopology_STABLE:
case clusterpb.ClusterView_STABLE:
return ClusterStateStable
}
return ClusterStateEmpty
Expand All @@ -264,43 +262,42 @@ func ConvertShardRoleToPB(role ShardRole) clusterpb.ShardRole {
return clusterpb.ShardRole_FOLLOWER
}

func convertShardNodeToPB(shardNode ShardNode) clusterpb.Shard {
return clusterpb.Shard{
func convertShardNodeToPB(shardNode ShardNode) clusterpb.ShardNode {
return clusterpb.ShardNode{
Id: uint32(shardNode.ID),
ShardRole: ConvertShardRoleToPB(shardNode.ShardRole),
Node: shardNode.NodeName,
}
}

func convertShardNodePB(shardNode *clusterpb.Shard) ShardNode {
func convertShardNodePB(shardNode *clusterpb.ShardNode) ShardNode {
return ShardNode{
ID: ShardID(shardNode.Id),
ShardRole: ConvertShardRolePB(shardNode.ShardRole),
NodeName: shardNode.Node,
}
}

func convertClusterViewToPB(view ClusterView) clusterpb.ClusterTopology {
shardViews := make([]*clusterpb.Shard, 0, len(view.ShardNodes))
func convertClusterViewToPB(view ClusterView) clusterpb.ClusterView {
shardViews := make([]*clusterpb.ShardNode, 0, len(view.ShardNodes))
for _, shardNode := range view.ShardNodes {
shardNodePB := convertShardNodeToPB(shardNode)
shardViews = append(shardViews, &shardNodePB)
}

return clusterpb.ClusterTopology{
ClusterId: uint32(view.ClusterID),
Version: view.Version,
State: convertClusterStateToPB(view.State),
ShardView: shardViews,
Cause: "",
CreatedAt: view.CreatedAt,
ChangeNodeShards: nil,
return clusterpb.ClusterView{
ClusterId: uint32(view.ClusterID),
Version: view.Version,
State: convertClusterStateToPB(view.State),
ShardNodes: shardViews,
Cause: "",
CreatedAt: view.CreatedAt,
}
}

func convertClusterViewPB(view *clusterpb.ClusterTopology) ClusterView {
shardNodes := make([]ShardNode, 0, len(view.ShardView))
for _, shardNodePB := range view.ShardView {
func convertClusterViewPB(view *clusterpb.ClusterView) ClusterView {
shardNodes := make([]ShardNode, 0, len(view.ShardNodes))
for _, shardNodePB := range view.ShardNodes {
shardNode := convertShardNodePB(shardNodePB)
shardNodes = append(shardNodes, shardNode)
}
Expand Down Expand Up @@ -337,7 +334,6 @@ func convertTableToPB(table Table) clusterpb.Table {
Id: uint64(table.ID),
Name: table.Name,
SchemaId: uint32(table.SchemaID),
ShardId: uint32(table.SchemaID),
Desc: "",
CreatedAt: table.CreatedAt,
}
Expand All @@ -352,21 +348,21 @@ func convertTablePB(table *clusterpb.Table) Table {
}
}

func convertShardViewToPB(view ShardView) clusterpb.ShardTopology {
func convertShardViewToPB(view ShardView) clusterpb.ShardView {
tableIDs := make([]uint64, 0, len(view.TableIDs))
for _, id := range view.TableIDs {
tableIDs = append(tableIDs, uint64(id))
}

return clusterpb.ShardTopology{
return clusterpb.ShardView{
ShardId: uint32(view.ShardID),
TableIds: tableIDs,
Version: view.Version,
CreatedAt: view.CreatedAt,
}
}

func convertShardViewPB(shardTopology *clusterpb.ShardTopology) ShardView {
func convertShardViewPB(shardTopology *clusterpb.ShardView) ShardView {
tableIDs := make([]TableID, 0, len(shardTopology.TableIds))
for _, id := range shardTopology.TableIds {
tableIDs = append(tableIDs, TableID(id))
Expand Down Expand Up @@ -417,11 +413,10 @@ func convertNodeStatePB(state clusterpb.NodeState) NodeState {
}

func convertNodePB(node *clusterpb.Node) Node {
nodeStats := convertNodeStatsPB(node.NodeStats)
nodeStats := convertNodeStatsPB(node.Stats)
return Node{
Name: node.Name,
NodeStats: nodeStats,
CreatedAt: node.CreateTime,
LastTouchTime: node.LastTouchTime,
State: convertNodeStatePB(node.State),
}
Expand Down

0 comments on commit 51c36f6

Please sign in to comment.