tidb: github.com/pingcap/tidb/store/tikv Index | Files | Directories

package tikv

import "github.com/pingcap/tidb/store/tikv"

Package tikv provides tcp connection to kvserver.

Package tikv provides tcp connection to kvserver.

Index

Package Files

2pc.go backoff.go client.go client_batch.go coprocessor.go delete_range.go error.go interface.go kv.go lock_resolver.go mock_tikv_service.go pd_codec.go range_task.go rawkv.go region_cache.go region_request.go safepoint.go scan.go snapshot.go split_region.go test_util.go txn.go

Constants

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
)
const (
    BoTxnLock backoffType

    BoPDRPC
    BoRegionMiss
    BoUpdateLeader
)

Back off types.

const (
    GcOneRegionMaxBackoff   = 20000
    GcResolveLockMaxBackoff = 100000
)

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

const (
    // This is almost the same as 'tikv_gc_safe_point' in the table 'mysql.tidb',
    // save this to pd instead of tikv, because we can't use interface of table
    // if the safepoint on tidb is expired.
    GcSavedSafePoint = "/tidb/store/gcworker/saved_safe_point"

    GcSafePointCacheInterval = time.Second * 100
)

Safe point constants.

const ResolvedCacheSize = 2048

ResolvedCacheSize is max number of cached txn status.

Variables

var (
    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.

var (
    ErrTiKVServerTimeout  = terror.ClassTiKV.New(mysql.ErrTiKVServerTimeout, mysql.MySQLErrName[mysql.ErrTiKVServerTimeout])
    ErrResolveLockTimeout = terror.ClassTiKV.New(mysql.ErrResolveLockTimeout, mysql.MySQLErrName[mysql.ErrResolveLockTimeout])
    ErrPDServerTimeout    = terror.ClassTiKV.New(mysql.ErrPDServerTimeout, mysql.MySQLErrName[mysql.ErrPDServerTimeout])
    ErrRegionUnavailable  = terror.ClassTiKV.New(mysql.ErrRegionUnavailable, mysql.MySQLErrName[mysql.ErrRegionUnavailable])
    ErrTiKVServerBusy     = terror.ClassTiKV.New(mysql.ErrTiKVServerBusy, mysql.MySQLErrName[mysql.ErrTiKVServerBusy])
    ErrGCTooEarly         = terror.ClassTiKV.New(mysql.ErrGCTooEarly, mysql.MySQLErrName[mysql.ErrGCTooEarly])
)

MySQL error instances.

var (
    // MaxRawKVScanLimit is the maximum scan limit for rawkv Scan.
    MaxRawKVScanLimit = 10240
    // ErrMaxScanLimitExceeded is returned when the limit for rawkv Scan is to large.
    ErrMaxScanLimitExceeded = errors.New("limit should be less than MaxRawKVScanLimit")
)
var CommitMaxBackoff = 41000

CommitMaxBackoff is max sleep time of the 'commit' command

var (
    // ErrBodyMissing response body is missing error
    ErrBodyMissing = errors.New("response body is missing")
)
var MaxRecvMsgSize = math.MaxInt64

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.

var NewGCHandlerFunc func(storage Storage, pdClient pd.Client) (GCHandler, error)

NewGCHandlerFunc creates a new GCHandler. To enable real GC, we should assign the function to `gcworker.NewGCWorker`.

var (
    PessimisticLockTTL uint64
)

Global variable set by config file.

var ShuttingDown uint32

ShuttingDown is a flag to indicate tidb-server is exiting (Ctrl+C signal receved for example). If this flag is set, tikv client should not retry on network error because tidb-server expect tikv client to exit as soon as possible.

func NewBackoffFn Uses

func NewBackoffFn(base, cap, jitter int) func(ctx context.Context, maxSleepMs int) int

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

func NewTestTiKVStore Uses

func NewTestTiKVStore(client Client, pdClient pd.Client, clientHijack func(Client) Client, pdClientHijack func(pd.Client) pd.Client, txnLocalLatches uint) (kv.Storage, error)

NewTestTiKVStore creates a test store with Option

func SplitRegionRanges Uses

func SplitRegionRanges(bo *Backoffer, cache *RegionCache, keyRanges []kv.KeyRange) ([]kv.KeyRange, error)

SplitRegionRanges get the split ranges from pd region.

type Backoffer Uses

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

Backoffer is a utility for retrying queries.

func NewBackoffer Uses

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

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

func NewNoopBackoff Uses

func NewNoopBackoff(ctx context.Context) *Backoffer

NewNoopBackoff create a Backoffer do nothing just return error directly

func (*Backoffer) Backoff Uses

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) BackoffWithMaxSleep Uses

func (b *Backoffer) BackoffWithMaxSleep(typ backoffType, maxSleepMs int, err error) error

BackoffWithMaxSleep sleeps a while base on the backoffType and records the error message and never sleep more than maxSleepMs for each sleep.

func (*Backoffer) Clone Uses

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 Uses

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 Uses

func (b *Backoffer) String() string

func (*Backoffer) WithVars Uses

func (b *Backoffer) WithVars(vars *kv.Variables) *Backoffer

WithVars sets the kv.Variables to the Backoffer and return it.

type Client Uses

type Client interface {
    // Close should release all data.
    Close() 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 NewTestRPCClient Uses

func NewTestRPCClient() Client

NewTestRPCClient is for some external tests.

type CopClient Uses

type CopClient struct {
    kv.RequestTypeSupportedChecker
    // contains filtered or unexported fields
}

CopClient is coprocessor client.

func (*CopClient) Send Uses

func (c *CopClient) Send(ctx context.Context, req *kv.Request, vars *kv.Variables) kv.Response

Send builds the request and gets the coprocessor iterator response.

type DeleteRangeTask Uses

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

DeleteRangeTask is used to delete all keys in a range. After performing DeleteRange, it keeps how many ranges it affects and if the task was canceled or not.

func NewDeleteRangeTask Uses

func NewDeleteRangeTask(store Storage, startKey []byte, endKey []byte, concurrency int) *DeleteRangeTask

NewDeleteRangeTask creates a DeleteRangeTask. Deleting will be performed when `Execute` method is invoked. Be careful while using this API. This API doesn't keep recent MVCC versions, but will delete all versions of all keys in the range immediately. Also notice that frequent invocation to this API may cause performance problems to TiKV.

func NewNotifyDeleteRangeTask Uses

func NewNotifyDeleteRangeTask(store Storage, startKey []byte, endKey []byte, concurrency int) *DeleteRangeTask

NewNotifyDeleteRangeTask creates a task that sends delete range requests to all regions in the range, but with the flag `notifyOnly` set. TiKV will not actually delete the range after receiving request, but it will be replicated via raft. This is used to notify the involved regions before sending UnsafeDestroyRange requests.

func (*DeleteRangeTask) CompletedRegions Uses

func (t *DeleteRangeTask) CompletedRegions() int

CompletedRegions returns the number of regions that are affected by this delete range task

func (*DeleteRangeTask) Execute Uses

func (t *DeleteRangeTask) Execute(ctx context.Context) error

Execute performs the delete range operation.

type Driver Uses

type Driver struct {
}

Driver implements engine Driver.

func (Driver) Open Uses

func (d Driver) Open(path string) (kv.Storage, error)

Open opens or creates an TiKV storage with given path. Path example: tikv://etcd-node1:port,etcd-node2:port?cluster=1&disableGC=false

type ErrDeadlock Uses

type ErrDeadlock struct {
    *kvrpcpb.Deadlock
    IsRetryable bool
}

ErrDeadlock wraps *kvrpcpb.Deadlock to implement the error interface. It also marks if the deadlock is retryable.

func (*ErrDeadlock) Error Uses

func (d *ErrDeadlock) Error() string

type EtcdBackend Uses

type EtcdBackend interface {
    EtcdAddrs() []string
    TLSConfig() *tls.Config
    StartGCWorker() error
}

EtcdBackend is used for judging a storage is a real TiKV.

type EtcdSafePointKV Uses

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

EtcdSafePointKV implements SafePointKV at runtime

func NewEtcdSafePointKV Uses

func NewEtcdSafePointKV(addrs []string, tlsConfig *tls.Config) (*EtcdSafePointKV, error)

NewEtcdSafePointKV creates an instance of EtcdSafePointKV

func (*EtcdSafePointKV) Get Uses

func (w *EtcdSafePointKV) Get(k string) (string, error)

Get implements the Get method for SafePointKV

func (*EtcdSafePointKV) Put Uses

func (w *EtcdSafePointKV) Put(k string, v string) error

Put implements the Put method for SafePointKV

type GCHandler Uses

type GCHandler interface {
    // Start starts the GCHandler.
    Start()

    // Close closes the GCHandler.
    Close()
}

GCHandler runs garbage collection job.

type KeyLocation Uses

type KeyLocation struct {
    Region   RegionVerID
    StartKey kv.Key
    EndKey   kv.Key
}

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

func (*KeyLocation) Contains Uses

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

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

type Lock Uses

type Lock struct {
    Key     []byte
    Primary []byte
    TxnID   uint64
    TTL     uint64
    TxnSize uint64
}

Lock represents a lock from tikv server.

func NewLock Uses

func NewLock(l *kvrpcpb.LockInfo) *Lock

NewLock creates a new *Lock.

func (*Lock) String Uses

func (l *Lock) String() string

type LockResolver Uses

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

LockResolver resolves locks and also caches resolved txn status.

func NewLockResolver Uses

func NewLockResolver(etcdAddrs []string, security config.Security) (*LockResolver, error)

NewLockResolver creates a LockResolver. It is exported for other pkg to use. For instance, binlog service needs to determine a transaction's commit state.

func (*LockResolver) BatchResolveLocks Uses

func (lr *LockResolver) BatchResolveLocks(bo *Backoffer, locks []*Lock, loc RegionVerID) (bool, error)

BatchResolveLocks resolve locks in a batch

func (*LockResolver) GetTxnStatus Uses

func (lr *LockResolver) GetTxnStatus(txnID uint64, primary []byte) (TxnStatus, error)

GetTxnStatus queries tikv-server for a txn's status (commit/rollback). If the primary key is still locked, it will launch a Rollback to abort it. To avoid unnecessarily aborting too many txns, it is wiser to wait a few seconds before calling it after Prewrite.

func (*LockResolver) ResolveLocks Uses

func (lr *LockResolver) ResolveLocks(bo *Backoffer, locks []*Lock) (msBeforeTxnExpired int64, err error)

ResolveLocks tries to resolve Locks. The resolving process is in 3 steps: 1) Use the `lockTTL` to pick up all expired locks. Only locks that are too

old are considered orphan locks and will be handled later. If all locks
are expired then all locks will be resolved so the returned `ok` will be
true, otherwise caller should sleep a while before retry.

2) For each lock, query the primary key to get txn(which left the lock)'s

commit status.

3) Send `ResolveLock` cmd to the lock's region to resolve all locks belong to

the same transaction.

type MockSafePointKV Uses

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

MockSafePointKV implements SafePointKV at mock test

func NewMockSafePointKV Uses

func NewMockSafePointKV() *MockSafePointKV

NewMockSafePointKV creates an instance of MockSafePointKV

func (*MockSafePointKV) Get Uses

func (w *MockSafePointKV) Get(k string) (string, error)

Get implements the Get method for SafePointKV

func (*MockSafePointKV) Put Uses

func (w *MockSafePointKV) Put(k string, v string) error

Put implements the Put method for SafePointKV

type RPCContext Uses

type RPCContext struct {
    Region  RegionVerID
    Meta    *metapb.Region
    Peer    *metapb.Peer
    PeerIdx int
    Store   *Store
    Addr    string
}

RPCContext contains data that is needed to send RPC to a region.

func (*RPCContext) GetStoreID Uses

func (c *RPCContext) GetStoreID() uint64

GetStoreID returns StoreID.

func (*RPCContext) String Uses

func (c *RPCContext) String() string

type RangeTaskHandler Uses

type RangeTaskHandler = func(ctx context.Context, r kv.KeyRange) (RangeTaskStat, error)

RangeTaskHandler is the type of functions that processes a task of a key range. The function should calculate Regions that succeeded or failed to the task. Returning error from the handler means the error caused the whole task should be stopped.

type RangeTaskRunner Uses

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

RangeTaskRunner splits a range into many ranges to process concurrently, and convenient to send requests to all regions in the range. Because of merging and splitting, it's possible that multiple requests for disjoint ranges are sent to the same region.

func NewRangeTaskRunner Uses

func NewRangeTaskRunner(
    name string,
    store Storage,
    concurrency int,
    handler RangeTaskHandler,
) *RangeTaskRunner

NewRangeTaskRunner creates a RangeTaskRunner.

`requestCreator` is the function used to create RPC request according to the given range. `responseHandler` is the function to process responses of errors. If `responseHandler` returns error, the whole job will be canceled.

func (*RangeTaskRunner) CompletedRegions Uses

func (s *RangeTaskRunner) CompletedRegions() int

CompletedRegions returns how many regions has been sent requests.

func (*RangeTaskRunner) FailedRegions Uses

func (s *RangeTaskRunner) FailedRegions() int

FailedRegions returns how many regions has failed to do the task.

func (*RangeTaskRunner) RunOnRange Uses

func (s *RangeTaskRunner) RunOnRange(ctx context.Context, startKey, endKey kv.Key) error

RunOnRange runs the task on the given range. Empty startKey or endKey means unbounded.

func (*RangeTaskRunner) SetRegionsPerTask Uses

func (s *RangeTaskRunner) SetRegionsPerTask(regionsPerTask int)

SetRegionsPerTask sets how many regions is in a divided task. Since regions may split and merge, it's possible that a sub task contains not exactly specified number of regions.

func (*RangeTaskRunner) SetStatLogInterval Uses

func (s *RangeTaskRunner) SetStatLogInterval(interval time.Duration)

SetStatLogInterval sets the time interval to log the stats.

type RangeTaskStat Uses

type RangeTaskStat struct {
    CompletedRegions int
    FailedRegions    int
}

RangeTaskStat is used to count Regions that completed or failed to do the task.

type RawKVClient Uses

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

RawKVClient is a client of TiKV server which is used as a key-value storage, only GET/PUT/DELETE commands are supported.

func NewRawKVClient Uses

func NewRawKVClient(pdAddrs []string, security config.Security) (*RawKVClient, error)

NewRawKVClient creates a client with PD cluster addrs.

func (*RawKVClient) BatchDelete Uses

func (c *RawKVClient) BatchDelete(keys [][]byte) error

BatchDelete deletes key-value pairs from TiKV

func (*RawKVClient) BatchGet Uses

func (c *RawKVClient) BatchGet(keys [][]byte) ([][]byte, error)

BatchGet queries values with the keys.

func (*RawKVClient) BatchPut Uses

func (c *RawKVClient) BatchPut(keys, values [][]byte) error

BatchPut stores key-value pairs to TiKV.

func (*RawKVClient) Close Uses

func (c *RawKVClient) Close() error

Close closes the client.

func (*RawKVClient) ClusterID Uses

func (c *RawKVClient) ClusterID() uint64

ClusterID returns the TiKV cluster ID.

func (*RawKVClient) Delete Uses

func (c *RawKVClient) Delete(key []byte) error

Delete deletes a key-value pair from TiKV.

func (*RawKVClient) DeleteRange Uses

func (c *RawKVClient) DeleteRange(startKey []byte, endKey []byte) error

DeleteRange deletes all key-value pairs in a range from TiKV

func (*RawKVClient) Get Uses

func (c *RawKVClient) Get(key []byte) ([]byte, error)

Get queries value with the key. When the key does not exist, it returns `nil, nil`.

func (*RawKVClient) Put Uses

func (c *RawKVClient) Put(key, value []byte) error

Put stores a key-value pair to TiKV.

func (*RawKVClient) ReverseScan Uses

func (c *RawKVClient) ReverseScan(startKey, endKey []byte, limit int) (keys [][]byte, values [][]byte, err error)

ReverseScan queries continuous kv pairs in range [endKey, startKey), up to limit pairs. Direction is different from Scan, upper to lower. If endKey is empty, it means unbounded. If you want to include the startKey or exclude the endKey, append a '\0' to the key. For example, to scan (endKey, startKey], you can write: `ReverseScan(append(startKey, '\0'), append(endKey, '\0'), limit)`. It doesn't support Scanning from "", because locating the last Region is not yet implemented.

func (*RawKVClient) Scan Uses

func (c *RawKVClient) Scan(startKey, endKey []byte, limit int) (keys [][]byte, values [][]byte, err error)

Scan queries continuous kv pairs in range [startKey, endKey), up to limit pairs. If endKey is empty, it means unbounded. If you want to exclude the startKey or include the endKey, append a '\0' to the key. For example, to scan (startKey, endKey], you can write: `Scan(append(startKey, '\0'), append(endKey, '\0'), limit)`.

type Region Uses

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

Region presents kv region

func (*Region) Contains Uses

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

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

func (*Region) ContainsByEnd Uses

func (r *Region) ContainsByEnd(key []byte) bool

ContainsByEnd check the region contains the greatest key that is less than key. for the maximum region endKey is empty. startKey < key <= endKey.

func (*Region) EndKey Uses

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

EndKey returns EndKey.

func (*Region) FollowerStorePeer Uses

func (r *Region) FollowerStorePeer(rs *RegionStore, followerStoreSeed uint32) (store *Store, peer *metapb.Peer, idx int)

FollowerStorePeer returns a follower store with follower peer.

func (*Region) GetID Uses

func (r *Region) GetID() uint64

GetID returns id.

func (*Region) GetLeaderID Uses

func (r *Region) GetLeaderID() uint64

GetLeaderID returns leader region ID.

func (*Region) GetLeaderStoreID Uses

func (r *Region) GetLeaderStoreID() uint64

GetLeaderStoreID returns the store ID of the leader region.

func (*Region) GetMeta Uses

func (r *Region) GetMeta() *metapb.Region

GetMeta returns region meta.

func (*Region) StartKey Uses

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

StartKey returns StartKey.

func (*Region) VerID Uses

func (r *Region) VerID() RegionVerID

VerID returns the Region's RegionVerID.

func (*Region) WorkStorePeer Uses

func (r *Region) WorkStorePeer(rs *RegionStore) (store *Store, peer *metapb.Peer, idx int)

WorkStorePeer returns current work store with work peer.

type RegionCache Uses

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

RegionCache caches Regions loaded from PD.

func NewRegionCache Uses

func NewRegionCache(pdClient pd.Client) *RegionCache

NewRegionCache creates a RegionCache.

func (*RegionCache) BatchLoadRegionsFromKey Uses

func (c *RegionCache) BatchLoadRegionsFromKey(bo *Backoffer, startKey []byte, count int) ([]byte, error)

BatchLoadRegionsFromKey loads at most given numbers of regions to the RegionCache, from the given startKey. Returns the endKey of the last loaded region. If some of the regions has no leader, their entries in RegionCache will not be updated.

func (*RegionCache) Close Uses

func (c *RegionCache) Close()

Close releases region cache's resource.

func (*RegionCache) GetRPCContext Uses

func (c *RegionCache) GetRPCContext(bo *Backoffer, id RegionVerID, replicaRead kv.ReplicaReadType, followerStoreSeed uint32) (*RPCContext, error)

GetRPCContext returns RPCContext for a region. If it returns nil, the region must be out of date and already dropped from cache.

func (*RegionCache) GroupKeysByRegion Uses

func (c *RegionCache) GroupKeysByRegion(bo *Backoffer, keys [][]byte, filter func(key, regionStartKey []byte) bool) (map[RegionVerID][][]byte, RegionVerID, 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. filter is used to filter some unwanted keys.

func (*RegionCache) InvalidateCachedRegion Uses

func (c *RegionCache) InvalidateCachedRegion(id RegionVerID)

InvalidateCachedRegion removes a cached Region.

func (*RegionCache) ListRegionIDsInKeyRange Uses

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

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

func (*RegionCache) LoadRegionsInKeyRange Uses

func (c *RegionCache) LoadRegionsInKeyRange(bo *Backoffer, startKey, endKey []byte) (regions []*Region, err error)

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

func (*RegionCache) LocateEndKey Uses

func (c *RegionCache) LocateEndKey(bo *Backoffer, key []byte) (*KeyLocation, error)

LocateEndKey searches for the region and range that the key is located. Unlike LocateKey, start key of a region is exclusive and end key is inclusive.

func (*RegionCache) LocateKey Uses

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

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

func (*RegionCache) LocateRegionByID Uses

func (c *RegionCache) LocateRegionByID(bo *Backoffer, regionID uint64) (*KeyLocation, error)

LocateRegionByID searches for the region with ID.

func (*RegionCache) OnRegionEpochNotMatch Uses

func (c *RegionCache) OnRegionEpochNotMatch(bo *Backoffer, ctx *RPCContext, currentRegions []*metapb.Region) error

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

func (*RegionCache) OnSendFail Uses

func (c *RegionCache) OnSendFail(bo *Backoffer, ctx *RPCContext, scheduleReload bool, err error)

OnSendFail handles send request fail logic.

func (*RegionCache) PDClient Uses

func (c *RegionCache) PDClient() pd.Client

PDClient returns the pd.Client in RegionCache.

func (*RegionCache) UpdateLeader Uses

func (c *RegionCache) UpdateLeader(regionID RegionVerID, leaderStoreID uint64, currentPeerIdx int)

UpdateLeader update some region cache with newer leader info.

type RegionRequestSender Uses

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 Uses

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

NewRegionRequestSender creates a new sender.

func (*RegionRequestSender) SendReq Uses

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

SendReq sends a request to tikv server.

func (*RegionRequestSender) SendReqCtx Uses

func (s *RegionRequestSender) SendReqCtx(bo *Backoffer, req *tikvrpc.Request, regionID RegionVerID, timeout time.Duration) (*tikvrpc.Response, *RPCContext, error)

SendReqCtx sends a request to tikv server and return response and RPCCtx of this RPC.

type RegionStore Uses

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

RegionStore represents region stores info it will be store as unsafe.Pointer and be load at once

type RegionVerID Uses

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

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

func (*RegionVerID) GetID Uses

func (r *RegionVerID) GetID() uint64

GetID returns the id of the region

type SafePointKV Uses

type SafePointKV interface {
    Put(k string, v string) error
    Get(k string) (string, error)
}

SafePointKV is used for a seamingless integration for mockTest and runtime.

type Scanner Uses

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

Scanner support tikv scan

func (*Scanner) Close Uses

func (s *Scanner) Close()

Close close iterator.

func (*Scanner) Key Uses

func (s *Scanner) Key() kv.Key

Key return key.

func (*Scanner) Next Uses

func (s *Scanner) Next() error

Next return next element.

func (*Scanner) Valid Uses

func (s *Scanner) Valid() bool

Valid return valid.

func (*Scanner) Value Uses

func (s *Scanner) Value() []byte

Value return value.

type Storage Uses

type Storage interface {
    kv.Storage

    // GetRegionCache gets the RegionCache.
    GetRegionCache() *RegionCache

    // SendReq sends a request to TiKV.
    SendReq(bo *Backoffer, req *tikvrpc.Request, regionID RegionVerID, timeout time.Duration) (*tikvrpc.Response, error)

    // GetLockResolver gets the LockResolver.
    GetLockResolver() *LockResolver

    // GetSafePointKV gets the SafePointKV.
    GetSafePointKV() SafePointKV

    // UpdateSPCache updates the cache of safe point.
    UpdateSPCache(cachedSP uint64, cachedTime time.Time)

    // GetGCHandler gets the GCHandler.
    GetGCHandler() GCHandler

    // SetOracle sets the Oracle.
    SetOracle(oracle oracle.Oracle)

    // SetTiKVClient sets the TiKV client.
    SetTiKVClient(client Client)

    // GetTiKVClient gets the TiKV client.
    GetTiKVClient() Client

    // Closed returns the closed channel.
    Closed() <-chan struct{}
}

Storage represent the kv.Storage runs on TiKV.

type Store Uses

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

Store contains a kv process's address.

type TxnStatus Uses

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

TxnStatus represents a txn's final status. It should be Lock or Commit or Rollback.

func (TxnStatus) CommitTS Uses

func (s TxnStatus) CommitTS() uint64

CommitTS returns the txn's commitTS. It is valid iff `IsCommitted` is true.

func (TxnStatus) IsCommitted Uses

func (s TxnStatus) IsCommitted() bool

IsCommitted returns true if the txn's final status is Commit.

Directories

PathSynopsis
gcworker
latch
oracle
oracle/oracles
tikvrpc

Package tikv imports 62 packages (graph) and is imported by 73 packages. Updated 2019-09-12. Refresh now. Tools for package owners.