Skip to content

Commit

Permalink
store/tikv: support debug PB in client. (#10038)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored and zz-jason committed Apr 4, 2019
1 parent f5fb5aa commit e6a5070
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions store/tikv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/coprocessor"
"github.com/pingcap/kvproto/pkg/debugpb"
"github.com/pingcap/kvproto/pkg/tikvpb"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/config"
Expand Down Expand Up @@ -579,6 +580,13 @@ func (c *rpcClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.R
}
}

if req.IsDebugReq() {
client := debugpb.NewDebugClient(connArray.Get())
ctx1, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return tikvrpc.CallDebugRPC(ctx1, client, req)
}

client := tikvpb.NewTikvClient(connArray.Get())

if req.Type != tikvrpc.CmdCopStream {
Expand Down
32 changes: 32 additions & 0 deletions store/tikv/tikvrpc/tikvrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/coprocessor"
"github.com/pingcap/kvproto/pkg/debugpb"
"github.com/pingcap/kvproto/pkg/errorpb"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/kvproto/pkg/metapb"
Expand Down Expand Up @@ -61,6 +62,8 @@ const (
CmdMvccGetByKey CmdType = 1024 + iota
CmdMvccGetByStartTs
CmdSplitRegion

CmdDebugGetRegionProperties CmdType = 2048 + iota
)

func (t CmdType) String() string {
Expand Down Expand Up @@ -115,6 +118,8 @@ func (t CmdType) String() string {
return "MvccGetByStartTS"
case CmdSplitRegion:
return "SplitRegion"
case CmdDebugGetRegionProperties:
return "DebugGetRegionProperties"
}
return "Unknown"
}
Expand Down Expand Up @@ -147,6 +152,8 @@ type Request struct {
MvccGetByKey *kvrpcpb.MvccGetByKeyRequest
MvccGetByStartTs *kvrpcpb.MvccGetByStartTsRequest
SplitRegion *kvrpcpb.SplitRegionRequest

DebugGetRegionProperties *debugpb.GetRegionPropertiesRequest
}

// ToBatchCommandsRequest converts the request to an entry in BatchCommands request.
Expand Down Expand Up @@ -196,6 +203,15 @@ func (req *Request) ToBatchCommandsRequest() *tikvpb.BatchCommandsRequest_Reques
return nil
}

// IsDebugReq check whether the req is debug req.
func (req *Request) IsDebugReq() bool {
switch req.Type {
case CmdDebugGetRegionProperties:
return true
}
return false
}

// Response wraps all kv/coprocessor responses.
type Response struct {
Type CmdType
Expand Down Expand Up @@ -224,6 +240,8 @@ type Response struct {
MvccGetByKey *kvrpcpb.MvccGetByKeyResponse
MvccGetByStartTS *kvrpcpb.MvccGetByStartTsResponse
SplitRegion *kvrpcpb.SplitRegionResponse

DebugGetRegionProperties *debugpb.GetRegionPropertiesResponse
}

// FromBatchCommandsResponse converts a BatchCommands response to Response.
Expand Down Expand Up @@ -592,6 +610,20 @@ func CallRPC(ctx context.Context, client tikvpb.TikvClient, req *Request) (*Resp
return resp, nil
}

// CallDebugRPC launches a debug rpc call.
func CallDebugRPC(ctx context.Context, client debugpb.DebugClient, req *Request) (*Response, error) {
resp := &Response{Type: req.Type}
resp.Type = req.Type
var err error
switch req.Type {
case CmdDebugGetRegionProperties:
resp.DebugGetRegionProperties, err = client.GetRegionProperties(ctx, req.DebugGetRegionProperties)
default:
return nil, errors.Errorf("invalid request type: %v", req.Type)
}
return resp, err
}

// Lease is used to implement grpc stream timeout.
type Lease struct {
Cancel context.CancelFunc
Expand Down

0 comments on commit e6a5070

Please sign in to comment.