client

package
v2.0.0-...-d47a232 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package client provides tcp connection to kvserver.

Package client provides tcp connection to kvserver.

Package client provides tcp connection to kvserver.

Index

Constants

View Source
const (
	// ModeRaw represent a raw operation in TiKV
	ModeRaw = iota

	// ModeTxn represent a transaction operation in TiKV
	ModeTxn
)
View Source
const (
	ReadTimeoutShort  = 30 * time.Second // For requests that read/write several key-values.
	ReadTimeoutMedium = 60 * time.Second // For requests that may need scan region.

	// MaxWriteExecutionTime is the MaxExecutionDurationMs field for write requests.
	// Because the last deadline check is before proposing, let us give it 10 more seconds
	// after proposing.
	MaxWriteExecutionTime = ReadTimeoutShort - 10*time.Second
)

Timeout durations.

View Source
const (
	GrpcInitialWindowSize     = 1 << 30
	GrpcInitialConnWindowSize = 1 << 30
)

Grpc window size

Variables

View Source
var (
	// APIV2RawKeyPrefix is prefix of raw key in API V2.
	APIV2RawKeyPrefix = []byte{'r', 0, 0, 0}

	// APIV2RawEndKey is max key of raw key in API V2.
	APIV2RawEndKey = []byte{'r', 0, 0, 1}

	// APIV2TxnKeyPrefix is prefix of txn key in API V2.
	APIV2TxnKeyPrefix = []byte{'x', 0, 0, 0}

	// APIV2TxnEndKey is max key of txn key in API V2.
	APIV2TxnEndKey = []byte{'x', 0, 0, 1}
)
View Source
var MaxRecvMsgSize = math.MaxInt64 - 1

MaxRecvMsgSize 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.

Functions

func DecodeResponse

func DecodeResponse(req *tikvrpc.Request, resp *tikvrpc.Response) (*tikvrpc.Response, error)

DecodeResponse decode the resp in specified API version format.

func DecodeV2Key

func DecodeV2Key(mode Mode, key []byte) ([]byte, error)

DecodeV2Key decodes API V2 encoded key into a normal user key.

func DecodeV2Pairs

func DecodeV2Pairs(mode Mode, pairs []*kvrpcpb.KvPair) ([]*kvrpcpb.KvPair, error)

DecodeV2Pairs decodes API V2 encoded pairs into normal user pairs.

func EncodeRequest

func EncodeRequest(req *tikvrpc.Request) (*tikvrpc.Request, error)

EncodeRequest encodes req into specified API version format. NOTE: req is reused on retry. MUST encode on cloned request, other than overwrite the original.

func EncodeV2Key

func EncodeV2Key(mode Mode, key []byte) []byte

EncodeV2Key encode a user key into API V2 format.

func EncodeV2KeyRanges

func EncodeV2KeyRanges(mode Mode, keyRanges []*kvrpcpb.KeyRange) []*kvrpcpb.KeyRange

EncodeV2KeyRanges encode KeyRange slice into API V2 formatted new slice.

func EncodeV2Keys

func EncodeV2Keys(mode Mode, keys [][]byte) [][]byte

EncodeV2Keys encodes keys into API V2 format.

func EncodeV2Pairs

func EncodeV2Pairs(mode Mode, pairs []*kvrpcpb.KvPair) []*kvrpcpb.KvPair

EncodeV2Pairs encodes pairs into API V2 format.

func EncodeV2Range

func EncodeV2Range(mode Mode, start, end []byte) ([]byte, []byte)

EncodeV2Range encode a range into API V2 format.

func MapV2RangeToV1

func MapV2RangeToV1(mode Mode, start []byte, end []byte) ([]byte, []byte)

MapV2RangeToV1 maps a range in API V2 format into V1 range. This function forbid the user seeing other keyspace.

Types

type Client

type Client interface {
	// Close should release all data.
	Close() error
	// CloseAddr closes gRPC connections to the address. It will reconnect the next time it's used.
	CloseAddr(addr string) error
	// SendRequest sends Request.
	SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error)
}

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

func NewInterceptedClient

func NewInterceptedClient(client Client) Client

NewInterceptedClient creates a Client which can execute interceptor.

func NewReqCollapse

func NewReqCollapse(client Client) Client

NewReqCollapse creates a reqCollapse.

type Mode

type Mode int

Mode represents the operation mode of a request.

type Opt

type Opt func(*option)

Opt is the option for the client.

func WithGRPCDialOptions

func WithGRPCDialOptions(grpcDialOptions ...grpc.DialOption) Opt

WithGRPCDialOptions is used to set the grpc.DialOption.

func WithSecurity

func WithSecurity(security config.Security) Opt

WithSecurity is used to set the security config.

type RPCClient

type RPCClient struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RPCClient is RPC client struct. TODO: Add flow control between RPC clients in TiDB ond RPC servers in TiKV. Since we use shared client connection to communicate to the same TiKV, it's possible that there are too many concurrent requests which overload the service of TiKV.

func NewRPCClient

func NewRPCClient(opts ...Opt) *RPCClient

NewRPCClient creates a client that manages connections and rpc calls with tikv-servers.

func (*RPCClient) Close

func (c *RPCClient) Close() error

Close closes all connections.

func (*RPCClient) CloseAddr

func (c *RPCClient) CloseAddr(addr string) error

CloseAddr closes gRPC connections to the address.

func (*RPCClient) SendRequest

func (c *RPCClient) SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error)

SendRequest sends a Request to server and receives Response.

Jump to

Keyboard shortcuts

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