tikvrpc

package
v2.0.0-...-5317c89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EngineLabelKey            = "engine"
	EngineLabelTiFlash        = "tiflash"
	EngineLabelTiFlashCompute = "tiflash_compute"
)

Constants to determine engine type. They should be synced with PD.

Variables

This section is empty.

Functions

func CheckStreamTimeoutLoop

func CheckStreamTimeoutLoop(ch <-chan *Lease, done <-chan struct{})

CheckStreamTimeoutLoop runs periodically to check is there any stream request timed out. Lease is an object to track stream requests, call this function with "go CheckStreamTimeoutLoop()" It is not guaranteed to call every Lease.Cancel() putting into channel when exits. If grpc-go supports SetDeadline(https://github.com/grpc/grpc-go/issues/2917), we can stop using this method.

func SetContext

func SetContext(req *Request, region *metapb.Region, peer *metapb.Peer) error

SetContext set the Context field for the given req to the specified ctx.

Types

type BatchCopStreamResponse

type BatchCopStreamResponse struct {
	tikvpb.Tikv_BatchCoprocessorClient
	*coprocessor.BatchResponse
	Timeout time.Duration
	Lease   // Shared by this object and a background goroutine.
}

BatchCopStreamResponse comprises the BatchCoprocessorClient , the first result and timeout detector.

func (*BatchCopStreamResponse) Close

func (resp *BatchCopStreamResponse) Close()

Close closes the BatchCopStreamResponse object.

func (*BatchCopStreamResponse) Recv

Recv overrides the stream client Recv() function.

type CmdType

type CmdType uint16

CmdType represents the concrete request type in Request or response type in Response.

const (
	CmdGet CmdType = 1 + iota
	CmdScan
	CmdPrewrite
	CmdCommit
	CmdCleanup
	CmdBatchGet
	CmdBatchRollback
	CmdScanLock
	CmdResolveLock
	CmdGC
	CmdDeleteRange
	CmdPessimisticLock
	CmdPessimisticRollback
	CmdTxnHeartBeat
	CmdCheckTxnStatus
	CmdCheckSecondaryLocks
	CmdFlashbackToVersion
	CmdPrepareFlashbackToVersion

	CmdRawGet CmdType = 256 + iota
	CmdRawBatchGet
	CmdRawPut
	CmdRawBatchPut
	CmdRawDelete
	CmdRawBatchDelete
	CmdRawDeleteRange
	CmdRawScan
	CmdGetKeyTTL
	CmdRawCompareAndSwap
	CmdRawChecksum

	CmdUnsafeDestroyRange

	CmdRegisterLockObserver
	CmdCheckLockObserver
	CmdRemoveLockObserver
	CmdPhysicalScanLock

	CmdStoreSafeTS
	CmdLockWaitInfo

	CmdCop CmdType = 512 + iota
	CmdCopStream
	CmdBatchCop
	CmdMPPTask   // TODO: These non TiKV RPCs should be moved out of TiKV client
	CmdMPPConn   // TODO: These non TiKV RPCs should be moved out of TiKV client
	CmdMPPCancel // TODO: These non TiKV RPCs should be moved out of TiKV client
	CmdMPPAlive  // TODO: These non TiKV RPCs should be moved out of TiKV client

	CmdMvccGetByKey CmdType = 1024 + iota
	CmdMvccGetByStartTs
	CmdSplitRegion

	CmdDebugGetRegionProperties CmdType = 2048 + iota
	CmdCompact                          // TODO: These non TiKV RPCs should be moved out of TiKV client

	CmdEmpty CmdType = 3072 + iota
)

CmdType values.

func (CmdType) String

func (t CmdType) String() string

type CopStreamResponse

type CopStreamResponse struct {
	tikvpb.Tikv_CoprocessorStreamClient
	*coprocessor.Response // The first result of Recv()
	Timeout               time.Duration
	Lease                 // Shared by this object and a background goroutine.
}

CopStreamResponse combines tikvpb.Tikv_CoprocessorStreamClient and the first Recv() result together. In streaming API, get grpc stream client may not involve any network packet, then region error have to be handled in Recv() function. This struct facilitates the error handling.

func (*CopStreamResponse) Close

func (resp *CopStreamResponse) Close()

Close closes the CopStreamResponse object.

func (*CopStreamResponse) Recv

func (resp *CopStreamResponse) Recv() (*coprocessor.Response, error)

Recv overrides the stream client Recv() function.

type EndpointType

type EndpointType uint8

EndpointType represents the type of a remote endpoint..

const (
	TiKV EndpointType = iota
	TiFlash
	TiDB
	TiFlashCompute
)

EndpointType type enums.

func GetStoreTypeByMeta

func GetStoreTypeByMeta(store *metapb.Store) EndpointType

GetStoreTypeByMeta gets store type by store meta pb.

func (EndpointType) IsTiFlashRelatedType

func (t EndpointType) IsTiFlashRelatedType() bool

IsTiFlashRelatedType return true if it's tiflash or tiflash_compute.

func (EndpointType) Name

func (t EndpointType) Name() string

Name returns the name of endpoint type.

type Lease

type Lease struct {
	Cancel context.CancelFunc
	// contains filtered or unexported fields
}

Lease is used to implement grpc stream timeout.

type MPPStreamResponse

type MPPStreamResponse struct {
	tikvpb.Tikv_EstablishMPPConnectionClient
	*mpp.MPPDataPacket
	Timeout time.Duration
	Lease
}

MPPStreamResponse is indeed a wrapped client that can receive data packet from tiflash mpp server.

func (*MPPStreamResponse) Close

func (resp *MPPStreamResponse) Close()

Close closes the MPPStreamResponse object.

func (*MPPStreamResponse) Recv

func (resp *MPPStreamResponse) Recv() (*mpp.MPPDataPacket, error)

Recv overrides the stream client Recv() function.

type Request

type Request struct {
	Type CmdType
	Req  interface{}
	kvrpcpb.Context
	ReadReplicaScope string
	// remove txnScope after tidb removed txnScope
	TxnScope        string
	ReplicaReadType kv.ReplicaReadType // different from `kvrpcpb.Context.ReplicaRead`
	ReplicaReadSeed *uint32            // pointer to follower read seed in snapshot/coprocessor
	StoreTp         EndpointType
	// ForwardedHost is the address of a store which will handle the request. It's different from
	// the address the request sent to.
	// If it's not empty, the store which receive the request will forward it to
	// the forwarded host. It's useful when network partition occurs.
	ForwardedHost string
}

Request wraps all kv/coprocessor requests.

func NewReplicaReadRequest

func NewReplicaReadRequest(typ CmdType, pointer interface{}, replicaReadType kv.ReplicaReadType, replicaReadSeed *uint32, ctxs ...kvrpcpb.Context) *Request

NewReplicaReadRequest returns new kv rpc request with replica read.

func NewRequest

func NewRequest(typ CmdType, pointer interface{}, ctxs ...kvrpcpb.Context) *Request

NewRequest returns new kv rpc request.

func (*Request) BatchCop

func (req *Request) BatchCop() *coprocessor.BatchRequest

BatchCop returns BatchCop request in request.

func (*Request) BatchGet

func (req *Request) BatchGet() *kvrpcpb.BatchGetRequest

BatchGet returns BatchGetRequest in request.

func (*Request) BatchRollback

func (req *Request) BatchRollback() *kvrpcpb.BatchRollbackRequest

BatchRollback returns BatchRollbackRequest in request.

func (*Request) CancelMPPTask

func (req *Request) CancelMPPTask() *mpp.CancelTaskRequest

CancelMPPTask returns canceling task in request

func (*Request) CheckLockObserver

func (req *Request) CheckLockObserver() *kvrpcpb.CheckLockObserverRequest

CheckLockObserver returns CheckLockObserverRequest in request.

func (*Request) CheckSecondaryLocks

func (req *Request) CheckSecondaryLocks() *kvrpcpb.CheckSecondaryLocksRequest

CheckSecondaryLocks returns CheckSecondaryLocksRequest in request.

func (*Request) CheckTxnStatus

func (req *Request) CheckTxnStatus() *kvrpcpb.CheckTxnStatusRequest

CheckTxnStatus returns CheckTxnStatusRequest in request.

func (*Request) Cleanup

func (req *Request) Cleanup() *kvrpcpb.CleanupRequest

Cleanup returns CleanupRequest in request.

func (*Request) Commit

func (req *Request) Commit() *kvrpcpb.CommitRequest

Commit returns CommitRequest in request.

func (*Request) Compact

func (req *Request) Compact() *kvrpcpb.CompactRequest

Compact returns CompactRequest in request.

func (*Request) Cop

func (req *Request) Cop() *coprocessor.Request

Cop returns coprocessor request in request.

func (*Request) DebugGetRegionProperties

func (req *Request) DebugGetRegionProperties() *debugpb.GetRegionPropertiesRequest

DebugGetRegionProperties returns GetRegionPropertiesRequest in request.

func (*Request) DeleteRange

func (req *Request) DeleteRange() *kvrpcpb.DeleteRangeRequest

DeleteRange returns DeleteRangeRequest in request.

func (*Request) DispatchMPPTask

func (req *Request) DispatchMPPTask() *mpp.DispatchTaskRequest

DispatchMPPTask returns dispatch task request in request.

func (*Request) Empty

Empty returns BatchCommandsEmptyRequest in request.

func (*Request) EnableStaleRead

func (req *Request) EnableStaleRead()

EnableStaleRead enables stale read

func (*Request) EstablishMPPConn

func (req *Request) EstablishMPPConn() *mpp.EstablishMPPConnectionRequest

EstablishMPPConn returns EstablishMPPConnectionRequest in request.

func (*Request) FlashbackToVersion

func (req *Request) FlashbackToVersion() *kvrpcpb.FlashbackToVersionRequest

FlashbackToVersion returns FlashbackToVersionRequest in request.

func (*Request) GC

func (req *Request) GC() *kvrpcpb.GCRequest

GC returns GCRequest in request.

func (*Request) Get

func (req *Request) Get() *kvrpcpb.GetRequest

Get returns GetRequest in request.

func (*Request) GetReplicaReadSeed

func (req *Request) GetReplicaReadSeed() *uint32

GetReplicaReadSeed returns ReplicaReadSeed pointer.

func (*Request) IsDebugReq

func (req *Request) IsDebugReq() bool

IsDebugReq check whether the req is debug req.

func (*Request) IsGlobalStaleRead

func (req *Request) IsGlobalStaleRead() bool

IsGlobalStaleRead checks if the request is a global stale read request.

func (*Request) IsGreenGCRequest

func (req *Request) IsGreenGCRequest() bool

IsGreenGCRequest checks if the request is used by Green GC's protocol. This is used for failpoints to inject errors to specified RPC requests.

func (*Request) IsMPPAlive

func (req *Request) IsMPPAlive() *mpp.IsAliveRequest

IsMPPAlive returns IsAlive request in request.

func (*Request) IsTxnWriteRequest

func (req *Request) IsTxnWriteRequest() bool

IsTxnWriteRequest checks if the request is a transactional write request. This is used for failpoints to inject errors to specified RPC requests.

func (*Request) LockWaitInfo

func (req *Request) LockWaitInfo() *kvrpcpb.GetLockWaitInfoRequest

LockWaitInfo returns GetLockWaitInfoRequest in request.

func (*Request) MvccGetByKey

func (req *Request) MvccGetByKey() *kvrpcpb.MvccGetByKeyRequest

MvccGetByKey returns MvccGetByKeyRequest in request.

func (*Request) MvccGetByStartTs

func (req *Request) MvccGetByStartTs() *kvrpcpb.MvccGetByStartTsRequest

MvccGetByStartTs returns MvccGetByStartTsRequest in request.

func (*Request) PessimisticLock

func (req *Request) PessimisticLock() *kvrpcpb.PessimisticLockRequest

PessimisticLock returns PessimisticLockRequest in request.

func (*Request) PessimisticRollback

func (req *Request) PessimisticRollback() *kvrpcpb.PessimisticRollbackRequest

PessimisticRollback returns PessimisticRollbackRequest in request.

func (*Request) PhysicalScanLock

func (req *Request) PhysicalScanLock() *kvrpcpb.PhysicalScanLockRequest

PhysicalScanLock returns PhysicalScanLockRequest in request.

func (*Request) PrepareFlashbackToVersion

func (req *Request) PrepareFlashbackToVersion() *kvrpcpb.PrepareFlashbackToVersionRequest

PrepareFlashbackToVersion returns PrepareFlashbackToVersion in request.

func (*Request) Prewrite

func (req *Request) Prewrite() *kvrpcpb.PrewriteRequest

Prewrite returns PrewriteRequest in request.

func (*Request) RawBatchDelete

func (req *Request) RawBatchDelete() *kvrpcpb.RawBatchDeleteRequest

RawBatchDelete returns RawBatchDeleteRequest in request.

func (*Request) RawBatchGet

func (req *Request) RawBatchGet() *kvrpcpb.RawBatchGetRequest

RawBatchGet returns RawBatchGetRequest in request.

func (*Request) RawBatchPut

func (req *Request) RawBatchPut() *kvrpcpb.RawBatchPutRequest

RawBatchPut returns RawBatchPutRequest in request.

func (*Request) RawChecksum

func (req *Request) RawChecksum() *kvrpcpb.RawChecksumRequest

RawChecksum returns RawChecksumRequest in request.

func (*Request) RawCompareAndSwap

func (req *Request) RawCompareAndSwap() *kvrpcpb.RawCASRequest

RawCompareAndSwap returns RawCASRequest in request.

func (*Request) RawDelete

func (req *Request) RawDelete() *kvrpcpb.RawDeleteRequest

RawDelete returns PrewriteRequest in request.

func (*Request) RawDeleteRange

func (req *Request) RawDeleteRange() *kvrpcpb.RawDeleteRangeRequest

RawDeleteRange returns RawDeleteRangeRequest in request.

func (*Request) RawGet

func (req *Request) RawGet() *kvrpcpb.RawGetRequest

RawGet returns RawGetRequest in request.

func (*Request) RawGetKeyTTL

func (req *Request) RawGetKeyTTL() *kvrpcpb.RawGetKeyTTLRequest

RawGetKeyTTL returns RawGetKeyTTLRequest in request.

func (*Request) RawPut

func (req *Request) RawPut() *kvrpcpb.RawPutRequest

RawPut returns RawPutRequest in request.

func (*Request) RawScan

func (req *Request) RawScan() *kvrpcpb.RawScanRequest

RawScan returns RawScanRequest in request.

func (*Request) RegisterLockObserver

func (req *Request) RegisterLockObserver() *kvrpcpb.RegisterLockObserverRequest

RegisterLockObserver returns RegisterLockObserverRequest in request.

func (*Request) RemoveLockObserver

func (req *Request) RemoveLockObserver() *kvrpcpb.RemoveLockObserverRequest

RemoveLockObserver returns RemoveLockObserverRequest in request.

func (*Request) ResolveLock

func (req *Request) ResolveLock() *kvrpcpb.ResolveLockRequest

ResolveLock returns ResolveLockRequest in request.

func (*Request) Scan

func (req *Request) Scan() *kvrpcpb.ScanRequest

Scan returns ScanRequest in request.

func (*Request) ScanLock

func (req *Request) ScanLock() *kvrpcpb.ScanLockRequest

ScanLock returns ScanLockRequest in request.

func (*Request) SplitRegion

func (req *Request) SplitRegion() *kvrpcpb.SplitRegionRequest

SplitRegion returns SplitRegionRequest in request.

func (*Request) StoreSafeTS

func (req *Request) StoreSafeTS() *kvrpcpb.StoreSafeTSRequest

StoreSafeTS returns StoreSafeTSRequest in request.

func (*Request) ToBatchCommandsRequest

func (req *Request) ToBatchCommandsRequest() *tikvpb.BatchCommandsRequest_Request

ToBatchCommandsRequest converts the request to an entry in BatchCommands request.

func (*Request) TxnHeartBeat

func (req *Request) TxnHeartBeat() *kvrpcpb.TxnHeartBeatRequest

TxnHeartBeat returns TxnHeartBeatRequest in request.

func (*Request) UnsafeDestroyRange

func (req *Request) UnsafeDestroyRange() *kvrpcpb.UnsafeDestroyRangeRequest

UnsafeDestroyRange returns UnsafeDestroyRangeRequest in request.

type ResourceGroupTagger

type ResourceGroupTagger func(req *Request)

ResourceGroupTagger is used to fill the ResourceGroupTag in the kvrpcpb.Context.

type Response

type Response struct {
	Resp interface{}
}

Response wraps all kv/coprocessor responses.

func CallDebugRPC

func CallDebugRPC(ctx context.Context, client debugpb.DebugClient, req *Request) (*Response, error)

CallDebugRPC launches a debug rpc call.

func CallRPC

func CallRPC(ctx context.Context, client tikvpb.TikvClient, req *Request) (*Response, error)

CallRPC launches a rpc call. ch is needed to implement timeout for coprocessor streaming, the stream object's cancel function will be sent to the channel, together with a lease checked by a background goroutine.

func FromBatchCommandsResponse

func FromBatchCommandsResponse(res *tikvpb.BatchCommandsResponse_Response) (*Response, error)

FromBatchCommandsResponse converts a BatchCommands response to Response.

func GenRegionErrorResp

func GenRegionErrorResp(req *Request, e *errorpb.Error) (*Response, error)

GenRegionErrorResp returns corresponding Response with specified RegionError according to the given req.

func (*Response) GetExecDetailsV2

func (resp *Response) GetExecDetailsV2() *kvrpcpb.ExecDetailsV2

GetExecDetailsV2 returns the ExecDetailsV2 of the underlying concrete response.

func (*Response) GetRegionError

func (resp *Response) GetRegionError() (*errorpb.Error, error)

GetRegionError returns the RegionError of the underlying concrete response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL