dskv

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Copyright 2016 PingCAP, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// NoJitter makes the backoff sequence strict exponential.
	NoJitter = 1 + iota
	// FullJitter applies random factors to strict exponential.
	FullJitter
	// EqualJitter is also randomized, but prevents very short sleeps.
	EqualJitter
	// DecorrJitter increases the maximum jitter based on the last random value.
	DecorrJitter
)
View Source
const (
	MsMaxBackoff          = 5000
	ScannerNextMaxBackoff = 20000
	SetMaxBackoff         = 20000
	BatchGetMaxBackoff    = 20000
	GetMaxBackoff         = 20000
	RawkvMaxBackoff       = 20000
)

Maximum total sleep time(in ms) for kv commands.

Variables

View Source
var (
	ErrRetryLater             = errors.New("try again later")
	ErrServerBusy             = errors.New("server is busy")
	ErrInternalError          = errors.New("internal error")
	ErrRouteChange            = errors.New("route change")
	ErrInvalidNode            = errors.New("invalid node ID")
	ErrNotSupportParallelExec = errors.New("proxy not support parallel exec")

	ErrAffectRows = errors.New("affect rows is not equal")
)
View Source
var Type_name = map[int32]string{
	0: "InvalidType",
	1: "RawGet",
	2: "RawPut",
	3: "RawDelete",
	4: "RawExecute",
	5: "Insert",
	6: "Select",
	7: "Delete",
}
View Source
var Type_value = map[string]int32{
	"InvalidType": 0,
	"RawGet":      1,
	"RawPut":      2,
	"RawDelete":   3,
	"RawExecute":  4,
	"Insert":      5,
	"Select":      6,
	"Delete":      7,
}

Functions

func EnumName

func EnumName(m map[int32]string, v int32) string

func NewBackoffFn

func NewBackoffFn(base, cap, jitter int) func() int

NewBackoffFn creates a backoff func which implements exponential backoff with optional jitters. See http://www.awsarchitectureblog.com/2015/03/backoff.html

func PutKvProxy

func PutKvProxy(proxy *KvProxy)

func PutRequest

func PutRequest(req *Request)

Types

type Backoffer

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

Backoffer is a utility for retrying queries.

func NewBackoffer

func NewBackoffer(maxSleep int, ctx context.Context) *Backoffer

NewBackoffer creates a Backoffer with maximum sleep time(in ms).

func (*Backoffer) Backoff

func (b *Backoffer) Backoff(typ backoffType, err error) error

Backoff sleeps a while base on the backoffType and records the error message. It returns a retryable error if total sleep time exceeds maxSleep.

func (*Backoffer) Clone

func (b *Backoffer) Clone() *Backoffer

Clone creates a new Backoffer which keeps current Backoffer's sleep time and errors, and shares current Backoffer's context.

func (*Backoffer) Fork

func (b *Backoffer) Fork() (*Backoffer, context.CancelFunc)

Fork creates a new Backoffer which keeps current Backoffer's sleep time and errors, and holds a child context of current Backoffer's context.

func (*Backoffer) String

func (b *Backoffer) String() string

type Context

type Context struct {
	VID           RangeVerID
	RequestHeader *kvrpcpb.RequestHeader
	NodeId        uint64
	NodeAddr      string
	Timeout       time.Duration
}

type KeyLocation

type KeyLocation struct {
	Region   RangeVerID
	StartKey []byte
	EndKey   []byte
	NodeId   uint64
}

KeyLocation is the region and range that a key is located.

func (*KeyLocation) Contains

func (l *KeyLocation) Contains(key []byte) bool

Contains checks if key is in [StartKey, EndKey).

type KvParisSlice

type KvParisSlice []*kvrpcpb.KeyValue

func (KvParisSlice) Len

func (p KvParisSlice) Len() int

func (KvParisSlice) Less

func (p KvParisSlice) Less(i int, j int) bool

func (KvParisSlice) Swap

func (p KvParisSlice) Swap(i int, j int)

type KvProxy

type KvProxy struct {
	Cli          client.KvClient
	Clock        *hlc.Clock
	RangeCache   *RangeCache
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
}

func GetKvProxy

func GetKvProxy() *KvProxy

func (*KvProxy) ConditionUpdate

func (p *KvProxy) ConditionUpdate(req *kvrpcpb.LockUpdateRequest) (*kvrpcpb.LockResponse, error)

func (*KvProxy) Delete

func (*KvProxy) Init

func (p *KvProxy) Init(cli client.KvClient, clock *hlc.Clock, cache *RangeCache, wTimeout, rTimeout time.Duration)

func (*KvProxy) Insert

func (*KvProxy) KvBatchDelete

func (*KvProxy) KvBatchGet

func (*KvProxy) KvBatchSet

func (*KvProxy) KvDelete

func (*KvProxy) KvGet

func (*KvProxy) KvRangeDelete

func (*KvProxy) KvScan

func (*KvProxy) KvSet

func (*KvProxy) Lock

func (*KvProxy) LockScan added in v0.6.3

func (*KvProxy) LockUpdate

func (p *KvProxy) LockUpdate(req *kvrpcpb.LockUpdateRequest) (*kvrpcpb.LockResponse, error)

func (*KvProxy) RawDelete

func (*KvProxy) RawGet

func (*KvProxy) RawPut

func (*KvProxy) Reset

func (p *KvProxy) Reset()

func (*KvProxy) SqlDelete

func (p *KvProxy) SqlDelete(req *kvrpcpb.DeleteRequest, scope *kvrpcpb.Scope) ([]*kvrpcpb.DeleteResponse, error)

func (*KvProxy) SqlInsert

func (p *KvProxy) SqlInsert(req *kvrpcpb.InsertRequest, scope *kvrpcpb.Scope) ([]*kvrpcpb.InsertResponse, error)

func (*KvProxy) SqlQuery

func (p *KvProxy) SqlQuery(req *kvrpcpb.SelectRequest, key []byte) (*kvrpcpb.SelectResponse, *KeyLocation, error)

func (*KvProxy) Unlock

func (p *KvProxy) Unlock(req *kvrpcpb.UnlockRequest) (*kvrpcpb.LockResponse, error)

func (*KvProxy) UnlockForce

func (p *KvProxy) UnlockForce(req *kvrpcpb.UnlockForceRequest) (*kvrpcpb.LockResponse, error)

type NodeCache

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

func NewNodeCache

func NewNodeCache(cli client.Client) *NodeCache

func (*NodeCache) DeleteNode

func (nc *NodeCache) DeleteNode(nodeId uint64)

func (*NodeCache) GetNode

func (nc *NodeCache) GetNode(bo *Backoffer, nodeId uint64) (node *metapb.Node, err error)

type Range

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

Region stores region's meta and its leader peer.

func (*Range) Contains

func (r *Range) Contains(key []byte) bool

Contains checks whether the key is in the region, for the maximum region endKey is empty. startKey <= key < endKey.

func (*Range) EndKey

func (r *Range) EndKey() []byte

EndKey returns EndKey.

func (*Range) GetID

func (r *Range) GetID() uint64

GetID returns id.

func (*Range) Leader

func (r *Range) Leader() *metapb.Peer

func (*Range) OnRequestFail

func (r *Range) OnRequestFail(nodeId uint64) bool

OnRequestFail records unreachable peer and tries to select another valid peer. It returns false if all peers are unreachable.

func (*Range) StartKey

func (r *Range) StartKey() []byte

StartKey returns StartKey.

func (*Range) SwitchPeer

func (r *Range) SwitchPeer(nodeId uint64) bool

SwitchPeer switches current peer to the one on specific store. It returns false if no peer matches the storeID.

func (*Range) VerID

func (r *Range) VerID() RangeVerID

VerID returns the Region's RegionVerID.

type RangeCache

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

RegionCache caches Regions loaded from PD.

func NewRangeCache

func NewRangeCache(dbId, tableId uint64, msClient client.Client, nodeCache *NodeCache) *RangeCache

NewRegionCache creates a RegionCache.

func (*RangeCache) DropRegion

func (c *RangeCache) DropRegion(id RangeVerID)

DropRegion removes a cached Region.

func (*RangeCache) GetNodeAddr

func (c *RangeCache) GetNodeAddr(bo *Backoffer, nodeId uint64) (string, error)

func (*RangeCache) GroupKeysByRegion

func (c *RangeCache) GroupKeysByRegion(bo *Backoffer, keys [][]byte) (map[RangeVerID][][]byte, RangeVerID, error)

GroupKeysByRegion separates keys into groups by their belonging Regions. Specially it also returns the first key's region which may be used as the 'PrimaryLockKey' and should be committed ahead of others.

func (*RangeCache) ListRegionIDsInKeyRange

func (c *RangeCache) ListRegionIDsInKeyRange(bo *Backoffer, startKey, endKey []byte) (regionIDs []uint64, err error)

ListRegionIDsInKeyRange lists ids of regions in [start_key,end_key].

func (*RangeCache) LocateKey

func (c *RangeCache) LocateKey(bo *Backoffer, key []byte) (*KeyLocation, error)

LocateKey searches for the region and range that the key is located.

func (*RangeCache) MsClient

func (c *RangeCache) MsClient() client.Client

PDClient returns the pd.Client in RegionCache.

func (*RangeCache) OnRegionStale

func (c *RangeCache) OnRegionStale(ctx *Context, newRegions []*metapb.Range) error

OnRegionStale removes the old region and inserts new regions into the cache.

func (*RangeCache) OnRequestFail

func (c *RangeCache) OnRequestFail(regionID RangeVerID, nodeId uint64, err error)

OnRequestFail is used for clearing cache when a ds server does not respond.

func (*RangeCache) UpdateLeader

func (c *RangeCache) UpdateLeader(regionID RangeVerID, leaderNodeID uint64)

UpdateLeader update some region cache with newer leader info.

type RangeVerID

type RangeVerID struct {
	Id      uint64
	ConfVer uint64
	Cer     uint64
}

RegionVerID is a unique ID that can identify a Region at a specific version.

type Request

func GetRequest

func GetRequest() *Request

func (*Request) GetDeleteReq

func (m *Request) GetDeleteReq() *kvrpcpb.DsDeleteRequest

func (*Request) GetInsertReq

func (m *Request) GetInsertReq() *kvrpcpb.DsInsertRequest

func (*Request) GetKvBatchDelReq

func (m *Request) GetKvBatchDelReq() *kvrpcpb.DsKvBatchDeleteRequest

func (*Request) GetKvBatchGetReq

func (m *Request) GetKvBatchGetReq() *kvrpcpb.DsKvBatchGetRequest

func (*Request) GetKvBatchSetReq

func (m *Request) GetKvBatchSetReq() *kvrpcpb.DsKvBatchSetRequest

func (*Request) GetKvDeleteReq

func (m *Request) GetKvDeleteReq() *kvrpcpb.DsKvDeleteRequest

func (*Request) GetKvGetReq

func (m *Request) GetKvGetReq() *kvrpcpb.DsKvGetRequest

func (*Request) GetKvRangeDelReq

func (m *Request) GetKvRangeDelReq() *kvrpcpb.DsKvRangeDeleteRequest

func (*Request) GetKvScanReq

func (m *Request) GetKvScanReq() *kvrpcpb.DsKvScanRequest

func (*Request) GetKvSetReq

func (m *Request) GetKvSetReq() *kvrpcpb.DsKvSetRequest

func (*Request) GetLockReq

func (m *Request) GetLockReq() *kvrpcpb.DsLockRequest

func (*Request) GetLockScanReq added in v0.6.3

func (m *Request) GetLockScanReq() *kvrpcpb.DsLockScanRequest

func (*Request) GetLockUpdateReq

func (m *Request) GetLockUpdateReq() *kvrpcpb.DsLockUpdateRequest

func (*Request) GetRawDeleteReq

func (m *Request) GetRawDeleteReq() *kvrpcpb.DsKvRawDeleteRequest

func (*Request) GetRawExecuteReq

func (m *Request) GetRawExecuteReq() *kvrpcpb.DsKvRawExecuteRequest

func (*Request) GetRawGetReq

func (m *Request) GetRawGetReq() *kvrpcpb.DsKvRawGetRequest

func (*Request) GetRawPutReq

func (m *Request) GetRawPutReq() *kvrpcpb.DsKvRawPutRequest

func (*Request) GetSelectReq

func (m *Request) GetSelectReq() *kvrpcpb.DsSelectRequest

func (*Request) GetType

func (m *Request) GetType() Type

func (*Request) GetUnlockForceReq

func (m *Request) GetUnlockForceReq() *kvrpcpb.DsUnlockForceRequest

func (*Request) GetUnlockReq

func (m *Request) GetUnlockReq() *kvrpcpb.DsUnlockRequest

func (*Request) Reset

func (m *Request) Reset()

type Response

type Response struct {
	Type           Type
	RawGetResp     *kvrpcpb.DsKvRawGetResponse
	RawPutResp     *kvrpcpb.DsKvRawPutResponse
	RawDeleteResp  *kvrpcpb.DsKvRawDeleteResponse
	RawExecuteResp *kvrpcpb.DsKvRawExecuteResponse

	SelectResp *kvrpcpb.DsSelectResponse
	InsertResp *kvrpcpb.DsInsertResponse
	DeleteResp *kvrpcpb.DsDeleteResponse

	LockResp        *kvrpcpb.DsLockResponse
	LockUpdateResp  *kvrpcpb.DsLockUpdateResponse
	UnlockResp      *kvrpcpb.DsUnlockResponse
	UnlockForceResp *kvrpcpb.DsUnlockForceResponse
	LockScanResp    *kvrpcpb.DsLockScanResponse

	KvSetResp      *kvrpcpb.DsKvSetResponse
	KvBatchSetResp *kvrpcpb.DsKvBatchSetResponse
	KvGetResp      *kvrpcpb.DsKvGetResponse
	KvBatchGetResp *kvrpcpb.DsKvBatchGetResponse
	KvScanResp     *kvrpcpb.DsKvScanResponse
	KvDeleteResp   *kvrpcpb.DsKvDeleteResponse
	KvBatchDelResp *kvrpcpb.DsKvBatchDeleteResponse
	KvRangeDelResp *kvrpcpb.DsKvRangeDeleteResponse
}

func (*Response) GetDeleteResp

func (m *Response) GetDeleteResp() *kvrpcpb.DsDeleteResponse

func (*Response) GetErr

func (resp *Response) GetErr() (pErr *errorpb.Error, err error)

func (*Response) GetInsertResp

func (m *Response) GetInsertResp() *kvrpcpb.DsInsertResponse

func (*Response) GetKvBatchDelResp

func (m *Response) GetKvBatchDelResp() *kvrpcpb.DsKvBatchDeleteResponse

func (*Response) GetKvBatchGetResp

func (m *Response) GetKvBatchGetResp() *kvrpcpb.DsKvBatchGetResponse

func (*Response) GetKvBatchSetResp

func (m *Response) GetKvBatchSetResp() *kvrpcpb.DsKvBatchSetResponse

func (*Response) GetKvDeleteResp

func (m *Response) GetKvDeleteResp() *kvrpcpb.DsKvDeleteResponse

func (*Response) GetKvGetResp

func (m *Response) GetKvGetResp() *kvrpcpb.DsKvGetResponse

func (*Response) GetKvRangeDelResp

func (m *Response) GetKvRangeDelResp() *kvrpcpb.DsKvRangeDeleteResponse

func (*Response) GetKvScanResp

func (m *Response) GetKvScanResp() *kvrpcpb.DsKvScanResponse

func (*Response) GetKvSetResp

func (m *Response) GetKvSetResp() *kvrpcpb.DsKvSetResponse

func (*Response) GetLockResp

func (m *Response) GetLockResp() *kvrpcpb.DsLockResponse

func (*Response) GetLockScanResp added in v0.6.3

func (m *Response) GetLockScanResp() *kvrpcpb.DsLockScanResponse

func (*Response) GetLockUpdateResp

func (m *Response) GetLockUpdateResp() *kvrpcpb.DsLockUpdateResponse

func (*Response) GetRawDeleteResp

func (m *Response) GetRawDeleteResp() *kvrpcpb.DsKvRawDeleteResponse

func (*Response) GetRawExecuteResp

func (m *Response) GetRawExecuteResp() *kvrpcpb.DsKvRawExecuteResponse

func (*Response) GetRawGetResp

func (m *Response) GetRawGetResp() *kvrpcpb.DsKvRawGetResponse

func (*Response) GetRawPutResp

func (m *Response) GetRawPutResp() *kvrpcpb.DsKvRawPutResponse

func (*Response) GetSelectResp

func (m *Response) GetSelectResp() *kvrpcpb.DsSelectResponse

func (*Response) GetType

func (m *Response) GetType() Type

func (*Response) GetUnlockForceResp

func (m *Response) GetUnlockForceResp() *kvrpcpb.DsUnlockForceResponse

func (*Response) GetUnlockResp

func (m *Response) GetUnlockResp() *kvrpcpb.DsUnlockResponse

type Type

type Type int32
const (
	Type_InvalidType Type = 0
	Type_RawGet      Type = 1
	Type_RawPut      Type = 2
	Type_RawDelete   Type = 3
	Type_RawExecute  Type = 4
	Type_Insert      Type = 5
	Type_Select      Type = 6
	Type_Delete      Type = 7
	Type_KvSet       Type = 8
	Type_KvBatchSet  Type = 9
	Type_KvGet       Type = 10
	Type_KvBatchGet  Type = 11
	Type_KvScan      Type = 12
	Type_KvDelete    Type = 13
	Type_KvBatchDel  Type = 14
	Type_KvRangeDel  Type = 15
	Type_Lock        Type = 20
	Type_LockUpdate  Type = 21
	Type_Unlock      Type = 22
	Type_UnlockForce Type = 23
	Type_LockScan    Type = 24
)

func (Type) String

func (x Type) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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