Skip to content

Commit

Permalink
Support the kv_flashback_to_version cmd
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <ghzpotato@gmail.com>
  • Loading branch information
JmPotato committed Sep 2, 2022
1 parent 0f6bff3 commit 5a82e9a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0
github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00/go.mod h1:4qGtCB
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 h1:surzm05a8C9dN8dIUmo4Be2+pMRb6f55i+UIYrluu2E=
github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17XtbryoCJhkKGbT62+L2OlrniwqiGLSqrmdHCMzZw=
github.com/pingcap/kvproto v0.0.0-20220510035547-0e2f26c0a46a/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee h1:s1al2ci3MEj5VnNuUCGAfeqpbCxcMeZibOyxw8ClHLE=
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331 h1:LLPNqaM0C0hHER4U+cl17pvVBFuSDBbVl2oJQ6f6bg4=
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee h1:VO2t6IBpfvW34TdtD/G10VvnGqjLic1jzOuHjUb5VqM=
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/ninedraft/israce v0.0.3
github.com/pingcap/errors v0.11.5-0.20211224045212-9687c2b0f87c
github.com/pingcap/failpoint v0.0.0-20220423142525-ae43b7f4e5c3
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331
github.com/pingcap/tidb v1.1.0-beta.0.20220902042024-0482b2e83ed2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.8.0
Expand Down
2 changes: 2 additions & 0 deletions integration_tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989/go.mod h1:O17Xtb
github.com/pingcap/kvproto v0.0.0-20220510035547-0e2f26c0a46a/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee h1:s1al2ci3MEj5VnNuUCGAfeqpbCxcMeZibOyxw8ClHLE=
github.com/pingcap/kvproto v0.0.0-20220818023518-a0f02b6efcee/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331 h1:LLPNqaM0C0hHER4U+cl17pvVBFuSDBbVl2oJQ6f6bg4=
github.com/pingcap/kvproto v0.0.0-20220902075447-f95ac338b331/go.mod h1:OYtxs0786qojVTmkVeufx93xe+jUgm56GUYRIKnmaGI=
github.com/pingcap/log v0.0.0-20200511115504-543df19646ad/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
github.com/pingcap/log v0.0.0-20211215031037-e024ba4eb0ee/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pingcap/log v1.1.0 h1:ELiPxACz7vdo1qAvvaWJg1NrYFoY6gqAh/+Uo6aXdD8=
Expand Down
4 changes: 4 additions & 0 deletions internal/locate/region_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ func (s *mockTikvGrpcServer) GetLockWaitHistory(ctx context.Context, request *kv
return nil, errors.New("unreachable")
}

func (s *mockTikvGrpcServer) KvFlashbackToVersion(context.Context, *kvrpcpb.FlashbackToVersionRequest) (*kvrpcpb.FlashbackToVersionResponse, error) {
return nil, errors.New("unreachable")
}

func (s *testRegionRequestToSingleStoreSuite) TestNoReloadRegionForGrpcWhenCtxCanceled() {
// prepare a mock tikv grpc server
addr := "localhost:56341"
Expand Down
22 changes: 21 additions & 1 deletion tikvrpc/tikvrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const (
CmdTxnHeartBeat
CmdCheckTxnStatus
CmdCheckSecondaryLocks
CmdFlashbackToVersion

CmdRawGet CmdType = 256 + iota
CmdRawBatchGet
Expand Down Expand Up @@ -203,6 +204,8 @@ func (t CmdType) String() string {
return "StoreSafeTS"
case CmdLockWaitInfo:
return "LockWaitInfo"
case CmdFlashbackToVersion:
return "FlashbackToVersion"
}
return "Unknown"
}
Expand Down Expand Up @@ -511,6 +514,10 @@ func (req *Request) LockWaitInfo() *kvrpcpb.GetLockWaitInfoRequest {
return req.Req.(*kvrpcpb.GetLockWaitInfoRequest)
}

func (req *Request) FlashbackToVersion() *kvrpcpb.FlashbackToVersionRequest {
return req.Req.(*kvrpcpb.FlashbackToVersionRequest)
}

// ToBatchCommandsRequest converts the request to an entry in BatchCommands request.
func (req *Request) ToBatchCommandsRequest() *tikvpb.BatchCommandsRequest_Request {
switch req.Type {
Expand Down Expand Up @@ -566,6 +573,8 @@ func (req *Request) ToBatchCommandsRequest() *tikvpb.BatchCommandsRequest_Reques
return &tikvpb.BatchCommandsRequest_Request{Cmd: &tikvpb.BatchCommandsRequest_Request_CheckSecondaryLocks{CheckSecondaryLocks: req.CheckSecondaryLocks()}}
case CmdTxnHeartBeat:
return &tikvpb.BatchCommandsRequest_Request{Cmd: &tikvpb.BatchCommandsRequest_Request_TxnHeartBeat{TxnHeartBeat: req.TxnHeartBeat()}}
case CmdFlashbackToVersion:
return &tikvpb.BatchCommandsRequest_Request{Cmd: &tikvpb.BatchCommandsRequest_Request_FlashbackToVersion{FlashbackToVersion: req.FlashbackToVersion()}}
}
return nil
}
Expand Down Expand Up @@ -603,6 +612,8 @@ func FromBatchCommandsResponse(res *tikvpb.BatchCommandsResponse_Response) (*Res
return &Response{Resp: res.GC}, nil
case *tikvpb.BatchCommandsResponse_Response_DeleteRange:
return &Response{Resp: res.DeleteRange}, nil
case *tikvpb.BatchCommandsResponse_Response_FlashbackToVersion:
return &Response{Resp: res.FlashbackToVersion}, nil
case *tikvpb.BatchCommandsResponse_Response_RawGet:
return &Response{Resp: res.RawGet}, nil
case *tikvpb.BatchCommandsResponse_Response_RawBatchGet:
Expand Down Expand Up @@ -753,6 +764,8 @@ func SetContext(req *Request, region *metapb.Region, peer *metapb.Peer) error {
req.CheckTxnStatus().Context = ctx
case CmdCheckSecondaryLocks:
req.CheckSecondaryLocks().Context = ctx
case CmdFlashbackToVersion:
req.FlashbackToVersion().Context = ctx
default:
return errors.Errorf("invalid request type %v", req.Type)
}
Expand Down Expand Up @@ -900,6 +913,10 @@ func GenRegionErrorResp(req *Request, e *errorpb.Error) (*Response, error) {
p = &kvrpcpb.CheckSecondaryLocksResponse{
RegionError: e,
}
case CmdFlashbackToVersion:
p = &kvrpcpb.FlashbackToVersionResponse{
RegionError: e,
}
default:
return nil, errors.Errorf("invalid request type %v", req.Type)
}
Expand Down Expand Up @@ -1054,6 +1071,8 @@ func CallRPC(ctx context.Context, client tikvpb.TikvClient, req *Request) (*Resp
resp.Resp, err = client.GetLockWaitInfo(ctx, req.LockWaitInfo())
case CmdCompact:
resp.Resp, err = client.Compact(ctx, req.Compact())
case CmdFlashbackToVersion:
resp.Resp, err = client.KvFlashbackToVersion(ctx, req.FlashbackToVersion())
default:
return nil, errors.Errorf("invalid request type: %v", req.Type)
}
Expand Down Expand Up @@ -1215,7 +1234,8 @@ func (req *Request) IsTxnWriteRequest() bool {
req.Type == CmdCheckSecondaryLocks ||
req.Type == CmdCleanup ||
req.Type == CmdTxnHeartBeat ||
req.Type == CmdResolveLock {
req.Type == CmdResolveLock ||
req.Type == CmdFlashbackToVersion {
return true
}
return false
Expand Down

0 comments on commit 5a82e9a

Please sign in to comment.