rpc

package
v0.0.0-...-d674cee Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReadTimeoutShort          = 20 * time.Second  // For requests that read/write several key-values.
	ReadTimeoutMedium         = 60 * time.Second  // For requests that may need scan region.
	ReadTimeoutLong           = 150 * time.Second // For requests that may need scan region multiple times.
	GCTimeout                 = 5 * time.Minute
	UnsafeDestroyRangeTimeout = 5 * time.Minute
)

Timeout durations.

Variables

View Source
var GrpcKeepAliveTime = time.Duration(10) * time.Second

GrpcKeepAliveTime is the duration of time after which if the client doesn't see any activity it pings the server to see if the transport is still alive.

View Source
var GrpcKeepAliveTimeout = time.Duration(3) * time.Second

GrpcKeepAliveTimeout is the duration of time for which the client waits after having pinged for keepalive check and if no activity is seen even after that the connection is closed.

View Source
var MaxCallMsgSize = 1<<31 - 1

MaxCallMsgSize set max gRPC receive message size received from server. If any message size is larger than current value, an error will be reported from gRPC.

View Source
var MaxConnectionCount uint = 16

MaxConnectionCount is the max gRPC connections that will be established with each tikv-server.

View Source
var MaxSendMsgSize = 1<<31 - 1

MaxSendMsgSize set max gRPC request message size sent to server. If any request message size is larger than current value, an error will be reported from gRPC.

Functions

func CheckStreamTimeoutLoop

func CheckStreamTimeoutLoop(ch <-chan *Lease)

CheckStreamTimeoutLoop runs periodically to check is there any stream request timeouted. Lease is an object to track stream requests, call this function with "go CheckStreamTimeoutLoop()"

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 Client

type Client interface {
	// Close should release all data.
	Close() error
	// SendRequest sends Request.
	SendRequest(ctx context.Context, addr string, req *Request, timeout time.Duration) (*Response, error)
}

Client is a client that sends RPC. It should not be used after calling Close().

func NewRPCClient

func NewRPCClient(security config.Security) Client

NewRPCClient manages connections and rpc calls with tikv-servers.

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

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

	CmdUnsafeDestroyRange

	CmdCop CmdType = 512 + iota
	CmdCopStream

	CmdMvccGetByKey CmdType = 1024 + iota
	CmdMvccGetByStartTs
	CmdSplitRegion
)

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 combinates 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 Lease

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

Lease is used to implement grpc stream timeout.

type RegionRequestSender

type RegionRequestSender struct {
	// contains filtered or unexported fields
}

RegionRequestSender sends KV/Cop requests to tikv server. It handles network errors and some region errors internally.

Typically, a KV/Cop request is bind to a region, all keys that are involved in the request should be located in the region. The sending process begins with looking for the address of leader store's address of the target region from cache, and the request is then sent to the destination tikv server over TCP connection. If region is updated, can be caused by leader transfer, region split, region merge, or region balance, tikv server may not able to process request and send back a RegionError. RegionRequestSender takes care of errors that does not relevant to region range, such as 'I/O timeout', 'NotLeader', and 'ServerIsBusy'. For other errors, since region range have changed, the request may need to split, so we simply return the error to caller.

func NewRegionRequestSender

func NewRegionRequestSender(regionCache *locate.RegionCache, client Client) *RegionRequestSender

NewRegionRequestSender creates a new sender.

func (*RegionRequestSender) SendReq

func (s *RegionRequestSender) SendReq(bo *retry.Backoffer, req *Request, regionID locate.RegionVerID, timeout time.Duration) (*Response, error)

SendReq sends a request to tikv server.

type Request

Request wraps all kv/coprocessor requests.

type Response

Response wraps all kv/coprocessor responses.

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 streaing, the stream object's cancel function will be sent to the channel, together with a lease checked by a background goroutine.

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) GetRegionError

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

GetRegionError returns the RegionError of the underlying concrete response.

Jump to

Keyboard shortcuts

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