tikv

package module
v2.0.0-...-7ffc49f Latest Latest
Warning

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

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

README

TiKV Go Client

TiKV Go Client provides support for interacting with the TiKV server in the form of a Go library.

Its main codes and structure are stripped from the pingcap/tidb repository. The main reason for extracting this repo is to provide a cleaner option without directly accessing github.com/pingcap/tidb/store/tikv and introducing a lot of unnecessary dependencies.

There are examples of how to use them in the example/ directory. Please note that it is not recommended or supported to use both the raw and transactional APIs on the same keyspace.

Documentation

Index

Constants

View Source
const (
	ReadTimeoutMedium = client.ReadTimeoutMedium
	ReadTimeoutShort  = client.ReadTimeoutShort
)

Timeout durations.

View Source
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.

View Source
const (
	PriorityNormal = Priority(kvrpcpb.CommandPri_Normal)
	PriorityLow    = Priority(kvrpcpb.CommandPri_Low)
	PriorityHigh   = Priority(kvrpcpb.CommandPri_High)
)

Priority value for transaction priority.

View Source
const (

	// CommitSecondaryMaxBackoff is max sleep time of the 'commit' command
	CommitSecondaryMaxBackoff = 41000
)

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

View Source
const DCLabelKey = "zone"

DCLabelKey indicates the key of label which represents the dc for Store.

View Source
const MaxTxnTimeUse = 24 * 60 * 60 * 1000

MaxTxnTimeUse is the max time a Txn may use (in ms) from its begin to commit. We use it to abort the transaction to guarantee GC worker will not influence it.

View Source
const ResolvedCacheSize = 2048

ResolvedCacheSize is max number of cached txn status.

Variables

View Source
var (
	// CommitMaxBackoff is max sleep time of the 'commit' command
	CommitMaxBackoff = uint64(41000)
	// PrewriteMaxBackoff is max sleep time of the `pre-write` command.
	PrewriteMaxBackoff = 20000
)
View Source
var (
	LockAlwaysWait = int64(0)
	LockNoWait     = int64(-1)
)

Used for pessimistic lock wait time these two constants are special for lock protocol with tikv 0 means always wait, -1 means nowait, others meaning lock wait in milliseconds

View Source
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")
)
View Source
var (
	ManagedLockTTL uint64 = 20000 // 20s
)

Global variable set by config file.

View Source
var SetSuccess = false

SetSuccess is used to probe if kv variables are set or not. It is ONLY used in test cases.

View Source
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. TODO: make it private when br is ready.

View Source
var VeryLongMaxBackoff = uint64(600000) // 10mins

VeryLongMaxBackoff is the max sleep time of transaction commit.

Functions

func ExtractStartTS

func ExtractStartTS(store *KVStore, option StartTSOption) (uint64, error)

ExtractStartTS use `option` to get the proper startTS for a transaction.

func GetStoreLivenessTimeout

func GetStoreLivenessTimeout() time.Duration

GetStoreLivenessTimeout returns storeLivenessTimeout.

func GetStoreTypeByMeta

func GetStoreTypeByMeta(store *metapb.Store) tikvrpc.EndpointType

GetStoreTypeByMeta gets store type by store meta pb.

func IsMockCommitErrorEnable

func IsMockCommitErrorEnable() bool

IsMockCommitErrorEnable exports for gofail testing.

func LoadShuttingDown

func LoadShuttingDown() uint32

LoadShuttingDown atomically loads ShuttingDown.

func MockCommitErrorDisable

func MockCommitErrorDisable()

MockCommitErrorDisable exports for gofail testing.

func MockCommitErrorEnable

func MockCommitErrorEnable()

MockCommitErrorEnable exports for gofail testing.

func NewRPCClient

func NewRPCClient(security config.Security, opts ...func(c *client.RPCClient)) *client.RPCClient

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

func RecordRegionRequestRuntimeStats

func RecordRegionRequestRuntimeStats(stats map[tikvrpc.CmdType]*RPCRuntimeStats, cmd tikvrpc.CmdType, d time.Duration)

RecordRegionRequestRuntimeStats records request runtime stats.

func SetRegionCacheTTLSec

func SetRegionCacheTTLSec(t int64)

SetRegionCacheTTLSec sets regionCacheTTLSec to t.

func SetStoreLivenessTimeout

func SetStoreLivenessTimeout(t time.Duration)

SetStoreLivenessTimeout sets storeLivenessTimeout to t.

func StoreShuttingDown

func StoreShuttingDown(v uint32)

StoreShuttingDown atomically stores ShuttingDown into v.

func TxnStartKey

func TxnStartKey() interface{}

TxnStartKey is a key for transaction start_ts info in context.Context.

Types

type AccessIndex

type AccessIndex int

AccessIndex represent the index for accessIndex array

type AccessMode

type AccessMode int

AccessMode uses to index stores for different region cache access requirements.

const (
	// TiKVOnly indicates stores list that use for TiKv access(include both leader request and follower read).
	TiKVOnly AccessMode = iota
	// TiFlashOnly indicates stores list that use for TiFlash request.
	TiFlashOnly
	// NumAccessMode reserved to keep max access mode value.
	NumAccessMode
)

func (AccessMode) String

func (a AccessMode) String() string

type BackoffConfig

type BackoffConfig = retry.Config

BackoffConfig defines the backoff configuration.

func BoPDRPC

func BoPDRPC() *BackoffConfig

BoPDRPC returns the default backoff config for PDRPC.

func BoRegionMiss

func BoRegionMiss() *BackoffConfig

BoRegionMiss returns the default backoff config for RegionMiss.

func BoTiFlashRPC

func BoTiFlashRPC() *BackoffConfig

BoTiFlashRPC returns the default backoff config for TiFlashRPC.

func BoTiKVRPC

func BoTiKVRPC() *BackoffConfig

BoTiKVRPC returns the default backoff config for TiKVRPC.

func BoTxnLock

func BoTxnLock() *BackoffConfig

BoTxnLock returns the default backoff config for TxnLock.

type Backoffer

type Backoffer = retry.Backoffer

Backoffer is a utility for retrying queries.

func NewBackoffer

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

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

func NewBackofferWithVars

func NewBackofferWithVars(ctx context.Context, maxSleep int, vars *kv.Variables) *Backoffer

NewBackofferWithVars creates a Backoffer with maximum sleep time(in ms) and kv.Variables.

func NewGcResolveLockMaxBackoffer

func NewGcResolveLockMaxBackoffer(ctx context.Context) *Backoffer

NewGcResolveLockMaxBackoffer creates a Backoffer for Gc to resolve lock.

type BinlogExecutor

type BinlogExecutor interface {
	Prewrite(ctx context.Context, primary []byte) <-chan BinlogWriteResult
	Commit(ctx context.Context, commitTS int64)
	Skip()
}

BinlogExecutor defines the logic to replicate binlogs during transaction commit.

type BinlogWriteResult

type BinlogWriteResult interface {
	Skipped() bool
	GetError() error
}

BinlogWriteResult defines the result of prewrite binlog.

type Client

type Client = client.Client

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

func NewTestRPCClient

func NewTestRPCClient(security config.Security) Client

NewTestRPCClient is for some external tests.

type ClientHelper

type ClientHelper struct {
	RegionRequestRuntimeStats
	// contains filtered or unexported fields
}

ClientHelper wraps LockResolver and RegionRequestSender. It's introduced to support the new lock resolving pattern in the large transaction. In the large transaction protocol, sending requests and resolving locks are context-dependent. For example, when a send request meets a secondary lock, we'll call ResolveLock, and if the lock belongs to a large transaction, we may retry the request. If there is no context information about the resolved locks, we'll meet the secondary lock again and run into a deadloop.

func NewClientHelper

func NewClientHelper(store *KVStore, resolvedLocks *util.TSSet) *ClientHelper

NewClientHelper creates a helper instance.

func (*ClientHelper) ResolveLocks

func (ch *ClientHelper) ResolveLocks(bo *Backoffer, callerStartTS uint64, locks []*Lock) (int64, error)

ResolveLocks wraps the ResolveLocks function and store the resolved result.

func (*ClientHelper) SendReqCtx

func (ch *ClientHelper) SendReqCtx(bo *Backoffer, req *tikvrpc.Request, regionID RegionVerID, timeout time.Duration, et tikvrpc.EndpointType, directStoreAddr string, opts ...StoreSelectorOption) (*tikvrpc.Response, *RPCContext, string, error)

SendReqCtx wraps the SendReqCtx function and use the resolved lock result in the kvrpcpb.Context.

type CodecPDClient

type CodecPDClient struct {
	pd.Client
}

CodecPDClient wraps a PD Client to decode the encoded keys in region meta.

func (*CodecPDClient) GetPrevRegion

func (c *CodecPDClient) GetPrevRegion(ctx context.Context, key []byte) (*pd.Region, error)

GetPrevRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) GetRegion

func (c *CodecPDClient) GetRegion(ctx context.Context, key []byte) (*pd.Region, error)

GetRegion encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) GetRegionByID

func (c *CodecPDClient) GetRegionByID(ctx context.Context, regionID uint64) (*pd.Region, error)

GetRegionByID encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

func (*CodecPDClient) ScanRegions

func (c *CodecPDClient) ScanRegions(ctx context.Context, startKey []byte, endKey []byte, limit int) ([]*pd.Region, error)

ScanRegions encodes the key before send requests to pd-server and decodes the returned StartKey && EndKey from pd-server.

type CommitterMutations

type CommitterMutations interface {
	Len() int
	GetKey(i int) []byte
	GetKeys() [][]byte
	GetOp(i int) pb.Op
	GetValue(i int) []byte
	IsPessimisticLock(i int) bool
	Slice(from, to int) CommitterMutations
}

CommitterMutations contains the mutations to be submitted.

type CommitterProbe

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

CommitterProbe wraps a 2PC committer and exports internal states for testing purpose.

func (CommitterProbe) BuildPrewriteRequest

func (c CommitterProbe) BuildPrewriteRequest(regionID, regionConf, regionVersion uint64, mutations CommitterMutations, txnSize uint64) *tikvrpc.Request

BuildPrewriteRequest builds rpc request for mutation.

func (CommitterProbe) CheckAsyncCommit

func (c CommitterProbe) CheckAsyncCommit() bool

CheckAsyncCommit returns if async commit is available.

func (CommitterProbe) Cleanup

func (c CommitterProbe) Cleanup(ctx context.Context)

Cleanup cleans dirty data of a committer.

func (CommitterProbe) CleanupMutations

func (c CommitterProbe) CleanupMutations(ctx context.Context) error

CleanupMutations performs the clean up phase.

func (CommitterProbe) CloseTTLManager

func (c CommitterProbe) CloseTTLManager()

CloseTTLManager closes the TTL manager.

func (CommitterProbe) CommitMutations

func (c CommitterProbe) CommitMutations(ctx context.Context) error

CommitMutations performs the second phase of commit.

func (CommitterProbe) Execute

func (c CommitterProbe) Execute(ctx context.Context) error

Execute runs the commit process.

func (CommitterProbe) GetCommitTS

func (c CommitterProbe) GetCommitTS() uint64

GetCommitTS returns the commit ts of the committer.

func (CommitterProbe) GetForUpdateTS

func (c CommitterProbe) GetForUpdateTS() uint64

GetForUpdateTS returns the pessimistic ForUpdate ts.

func (CommitterProbe) GetLockTTL

func (c CommitterProbe) GetLockTTL() uint64

GetLockTTL returns the lock ttl duration of the transaction.

func (CommitterProbe) GetMinCommitTS

func (c CommitterProbe) GetMinCommitTS() uint64

GetMinCommitTS returns the minimal commit ts can be used.

func (CommitterProbe) GetMutations

func (c CommitterProbe) GetMutations() CommitterMutations

GetMutations returns the mutation buffer to commit.

func (CommitterProbe) GetOnePCCommitTS

func (c CommitterProbe) GetOnePCCommitTS() uint64

GetOnePCCommitTS returns the commit ts of one pc.

func (CommitterProbe) GetPrimaryKey

func (c CommitterProbe) GetPrimaryKey() []byte

GetPrimaryKey returns primary key of the committer.

func (CommitterProbe) GetStartTS

func (c CommitterProbe) GetStartTS() uint64

GetStartTS returns the start ts of the transaction.

func (CommitterProbe) GetUndeterminedErr

func (c CommitterProbe) GetUndeterminedErr() error

GetUndeterminedErr returns the encountered undetermined error (if any).

func (CommitterProbe) InitKeysAndMutations

func (c CommitterProbe) InitKeysAndMutations() error

InitKeysAndMutations prepares the committer for commit.

func (CommitterProbe) IsAsyncCommit

func (c CommitterProbe) IsAsyncCommit() bool

IsAsyncCommit returns if the committer uses async commit.

func (CommitterProbe) IsOnePC

func (c CommitterProbe) IsOnePC() bool

IsOnePC returns if the committer is using one PC.

func (CommitterProbe) IsTTLRunning

func (c CommitterProbe) IsTTLRunning() bool

IsTTLRunning returns if the TTL manager is running state.

func (CommitterProbe) IsTTLUninitialized

func (c CommitterProbe) IsTTLUninitialized() bool

IsTTLUninitialized returns if the TTL manager is uninitialized.

func (CommitterProbe) MutationsOfKeys

func (c CommitterProbe) MutationsOfKeys(keys [][]byte) CommitterMutations

MutationsOfKeys returns mutations match the keys.

func (CommitterProbe) PessimisticRollbackMutations

func (c CommitterProbe) PessimisticRollbackMutations(ctx context.Context, muts CommitterMutations) error

PessimisticRollbackMutations rolls mutations back.

func (CommitterProbe) PrewriteAllMutations

func (c CommitterProbe) PrewriteAllMutations(ctx context.Context) error

PrewriteAllMutations performs the first phase of commit.

func (CommitterProbe) PrewriteMutations

func (c CommitterProbe) PrewriteMutations(ctx context.Context, mutations CommitterMutations) error

PrewriteMutations performs the first phase of commit for given keys.

func (CommitterProbe) SetCommitTS

func (c CommitterProbe) SetCommitTS(ts uint64)

SetCommitTS resets the committer's commit ts.

func (CommitterProbe) SetForUpdateTS

func (c CommitterProbe) SetForUpdateTS(ts uint64)

SetForUpdateTS sets pessimistic ForUpdate ts.

func (CommitterProbe) SetLockTTL

func (c CommitterProbe) SetLockTTL(ttl uint64)

SetLockTTL sets the lock ttl duration.

func (CommitterProbe) SetLockTTLByTimeAndSize

func (c CommitterProbe) SetLockTTLByTimeAndSize(start time.Time, size int)

SetLockTTLByTimeAndSize sets the lock ttl duration by time and size.

func (CommitterProbe) SetMaxCommitTS

func (c CommitterProbe) SetMaxCommitTS(ts uint64)

SetMaxCommitTS sets the max commit ts can be used.

func (CommitterProbe) SetMinCommitTS

func (c CommitterProbe) SetMinCommitTS(ts uint64)

SetMinCommitTS sets the minimal commit ts can be used.

func (CommitterProbe) SetMutations

func (c CommitterProbe) SetMutations(muts CommitterMutations)

SetMutations replace the mutation buffer.

func (CommitterProbe) SetNoFallBack

func (c CommitterProbe) SetNoFallBack()

SetNoFallBack disallows async commit to fall back to normal mode.

func (CommitterProbe) SetPrimaryKey

func (c CommitterProbe) SetPrimaryKey(key []byte)

SetPrimaryKey resets the committer's commit ts.

func (CommitterProbe) SetPrimaryKeyBlocker

func (c CommitterProbe) SetPrimaryKeyBlocker(ac, bk chan struct{})

SetPrimaryKeyBlocker is used to block committer after primary is sent.

func (CommitterProbe) SetSessionID

func (c CommitterProbe) SetSessionID(id uint64)

SetSessionID sets the session id of the committer.

func (CommitterProbe) SetTxnSize

func (c CommitterProbe) SetTxnSize(sz int)

SetTxnSize resets the txn size of the committer and updates lock TTL.

func (CommitterProbe) SetUseAsyncCommit

func (c CommitterProbe) SetUseAsyncCommit()

SetUseAsyncCommit enables async commit feature.

func (CommitterProbe) WaitCleanup

func (c CommitterProbe) WaitCleanup()

WaitCleanup waits for the committer to complete.

type ConfigProbe

type ConfigProbe struct{}

ConfigProbe exposes configurations and global variables for testing purpose.

func (ConfigProbe) GetBigTxnThreshold

func (c ConfigProbe) GetBigTxnThreshold() int

GetBigTxnThreshold returns the txn size to be considered as big txn.

func (ConfigProbe) GetDefaultLockTTL

func (c ConfigProbe) GetDefaultLockTTL() uint64

GetDefaultLockTTL returns the default lock TTL.

func (ConfigProbe) GetGetMaxBackoff

func (c ConfigProbe) GetGetMaxBackoff() int

GetGetMaxBackoff returns the max sleep for get command.

func (ConfigProbe) GetRawBatchPutSize

func (c ConfigProbe) GetRawBatchPutSize() int

GetRawBatchPutSize returns the raw batch put size config.

func (ConfigProbe) GetScanBatchSize

func (c ConfigProbe) GetScanBatchSize() int

GetScanBatchSize returns the batch size to scan ranges.

func (ConfigProbe) GetTTLFactor

func (c ConfigProbe) GetTTLFactor() int

GetTTLFactor returns the factor to calculate txn TTL.

func (ConfigProbe) GetTxnCommitBatchSize

func (c ConfigProbe) GetTxnCommitBatchSize() uint64

GetTxnCommitBatchSize returns the batch size to commit txn.

func (ConfigProbe) LoadPreSplitDetectThreshold

func (c ConfigProbe) LoadPreSplitDetectThreshold() uint32

LoadPreSplitDetectThreshold returns presplit detect threshold config.

func (ConfigProbe) LoadPreSplitSizeThreshold

func (c ConfigProbe) LoadPreSplitSizeThreshold() uint32

LoadPreSplitSizeThreshold returns presplit size threshold config.

func (ConfigProbe) SetOracleUpdateInterval

func (c ConfigProbe) SetOracleUpdateInterval(v int)

SetOracleUpdateInterval sets the interval of updating cached ts.

func (ConfigProbe) StorePreSplitDetectThreshold

func (c ConfigProbe) StorePreSplitDetectThreshold(v uint32)

StorePreSplitDetectThreshold updates presplit detect threshold config.

func (ConfigProbe) StorePreSplitSizeThreshold

func (c ConfigProbe) StorePreSplitSizeThreshold(v uint32)

StorePreSplitSizeThreshold updates presplit size threshold config.

type DeleteRangeTask

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

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

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

func (t *DeleteRangeTask) CompletedRegions() int

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

func (*DeleteRangeTask) Execute

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

Execute performs the delete range operation.

type EtcdSafePointKV

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

EtcdSafePointKV implements SafePointKV at runtime

func NewEtcdSafePointKV

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

NewEtcdSafePointKV creates an instance of EtcdSafePointKV

func (*EtcdSafePointKV) Close

func (w *EtcdSafePointKV) Close() error

Close implements the Close for SafePointKV

func (*EtcdSafePointKV) Get

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

Get implements the Get method for SafePointKV

func (*EtcdSafePointKV) GetWithPrefix

func (w *EtcdSafePointKV) GetWithPrefix(k string) ([]*mvccpb.KeyValue, error)

GetWithPrefix implements the GetWithPrefix for SafePointKV

func (*EtcdSafePointKV) Put

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

Put implements the Put method for SafePointKV

type InvalidReason

type InvalidReason int32

InvalidReason is the reason why a cached region is invalidated. The region cache may take different strategies to handle different reasons. For example, when a cached region is invalidated due to no leader, region cache will always access to a different peer.

const (
	// Ok indicates the cached region is valid
	Ok InvalidReason = iota
	// NoLeader indicates it's invalidated due to no leader
	NoLeader
	// RegionNotFound indicates it's invalidated due to region not found in the store
	RegionNotFound
	// EpochNotMatch indicates it's invalidated due to epoch not match
	EpochNotMatch
	// StoreNotFound indicates it's invalidated due to store not found in PD
	StoreNotFound
	// Other indicates it's invalidated due to other reasons, e.g., the store
	// is removed from the cluster, fail to send requests to the store.
	Other
)

type IsoLevel

type IsoLevel kvrpcpb.IsolationLevel

IsoLevel is the transaction's isolation level.

const (
	// SI stands for 'snapshot isolation'.
	SI IsoLevel = IsoLevel(kvrpcpb.IsolationLevel_SI)
	// RC stands for 'read committed'.
	RC IsoLevel = IsoLevel(kvrpcpb.IsolationLevel_RC)
)

func (IsoLevel) ToPB

func (l IsoLevel) ToPB() kvrpcpb.IsolationLevel

ToPB converts isolation level to wire type.

type KVFilter

type KVFilter interface {
	// IsUnnecessaryKeyValue returns whether this KV pair should be committed.
	IsUnnecessaryKeyValue(key, value []byte, flags kv.KeyFlags) bool
}

KVFilter is a filter that filters out unnecessary KV pairs.

type KVSnapshot

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

KVSnapshot implements the tidbkv.Snapshot interface.

func (*KVSnapshot) BatchGet

func (s *KVSnapshot) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)

BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs. The map will not contain nonexistent keys.

func (*KVSnapshot) Get

func (s *KVSnapshot) Get(ctx context.Context, k []byte) ([]byte, error)

Get gets the value for key k from snapshot.

func (*KVSnapshot) Iter

func (s *KVSnapshot) Iter(k []byte, upperBound []byte) (unionstore.Iterator, error)

Iter return a list of key-value pair after `k`.

func (*KVSnapshot) IterReverse

func (s *KVSnapshot) IterReverse(k []byte) (unionstore.Iterator, error)

IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.

func (*KVSnapshot) SetIsStatenessReadOnly

func (s *KVSnapshot) SetIsStatenessReadOnly(b bool)

SetIsStatenessReadOnly indicates whether the transaction is staleness read only transaction

func (*KVSnapshot) SetIsolationLevel

func (s *KVSnapshot) SetIsolationLevel(level IsoLevel)

SetIsolationLevel sets the isolation level used to scan data from tikv.

func (*KVSnapshot) SetKeyOnly

func (s *KVSnapshot) SetKeyOnly(b bool)

SetKeyOnly indicates if tikv can return only keys.

func (*KVSnapshot) SetMatchStoreLabels

func (s *KVSnapshot) SetMatchStoreLabels(labels []*metapb.StoreLabel)

SetMatchStoreLabels sets up labels to filter target stores.

func (*KVSnapshot) SetNotFillCache

func (s *KVSnapshot) SetNotFillCache(b bool)

SetNotFillCache indicates whether tikv should skip filling cache when loading data.

func (*KVSnapshot) SetPriority

func (s *KVSnapshot) SetPriority(pri Priority)

SetPriority sets the priority for tikv to execute commands.

func (*KVSnapshot) SetReplicaRead

func (s *KVSnapshot) SetReplicaRead(readType kv.ReplicaReadType)

SetReplicaRead sets up the replica read type.

func (*KVSnapshot) SetResourceGroupTag

func (s *KVSnapshot) SetResourceGroupTag(tag []byte)

SetResourceGroupTag sets resource group of the kv request.

func (*KVSnapshot) SetRuntimeStats

func (s *KVSnapshot) SetRuntimeStats(stats *SnapshotRuntimeStats)

SetRuntimeStats sets the stats to collect runtime statistics. Set it to nil to clear stored stats.

func (*KVSnapshot) SetSampleStep

func (s *KVSnapshot) SetSampleStep(step uint32)

SetSampleStep skips 'step - 1' number of keys after each returned key.

func (*KVSnapshot) SetSnapshotTS

func (s *KVSnapshot) SetSnapshotTS(ts uint64)

SetSnapshotTS resets the timestamp for reads.

func (*KVSnapshot) SetTaskID

func (s *KVSnapshot) SetTaskID(id uint64)

SetTaskID marks current task's unique ID to allow TiKV to schedule tasks more fairly.

func (*KVSnapshot) SetTxnScope

func (s *KVSnapshot) SetTxnScope(txnScope string)

SetTxnScope sets up the txn scope.

func (*KVSnapshot) SnapCacheHitCount

func (s *KVSnapshot) SnapCacheHitCount() int

SnapCacheHitCount gets the snapshot cache hit count. Only for test.

func (*KVSnapshot) SnapCacheSize

func (s *KVSnapshot) SnapCacheSize() int

SnapCacheSize gets the snapshot cache size. Only for test.

type KVStore

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

KVStore contains methods to interact with a TiKV cluster.

func NewKVStore

func NewKVStore(uuid string, pdClient pd.Client, spkv SafePointKV, tikvclient Client) (*KVStore, error)

NewKVStore creates a new TiKV store instance.

func NewTestTiKVStore

func NewTestTiKVStore(client Client, pdClient pd.Client, clientHijack func(Client) Client, pdClientHijack func(pd.Client) pd.Client, txnLocalLatches uint) (*KVStore, error)

NewTestTiKVStore creates a test store with Option

func (*KVStore) Begin

func (s *KVStore) Begin() (*KVTxn, error)

Begin a global transaction.

func (*KVStore) BeginWithOption

func (s *KVStore) BeginWithOption(options StartTSOption) (*KVTxn, error)

BeginWithOption begins a transaction with the given StartTSOption

func (*KVStore) CheckRegionInScattering

func (s *KVStore) CheckRegionInScattering(regionID uint64) (bool, error)

CheckRegionInScattering uses to check whether scatter region finished.

func (*KVStore) CheckVisibility

func (s *KVStore) CheckVisibility(startTime uint64) error

CheckVisibility checks if it is safe to read using given ts.

func (*KVStore) Close

func (s *KVStore) Close() error

Close store

func (*KVStore) Closed

func (s *KVStore) Closed() <-chan struct{}

Closed returns a channel that indicates if the store is closed.

func (*KVStore) CurrentTimestamp

func (s *KVStore) CurrentTimestamp(txnScope string) (uint64, error)

CurrentTimestamp returns current timestamp with the given txnScope (local or global).

func (*KVStore) EnableTxnLocalLatches

func (s *KVStore) EnableTxnLocalLatches(size uint)

EnableTxnLocalLatches enables txn latch. It should be called before using the store to serve any requests.

func (*KVStore) GetLockResolver

func (s *KVStore) GetLockResolver() *LockResolver

GetLockResolver returns the lock resolver instance.

func (*KVStore) GetMinSafeTS

func (s *KVStore) GetMinSafeTS(txnScope string) uint64

GetMinSafeTS return the minimal safeTS of the storage with given txnScope.

func (*KVStore) GetOracle

func (s *KVStore) GetOracle() oracle.Oracle

GetOracle gets a timestamp oracle client.

func (*KVStore) GetPDClient

func (s *KVStore) GetPDClient() pd.Client

GetPDClient returns the PD client.

func (*KVStore) GetRegionCache

func (s *KVStore) GetRegionCache() *RegionCache

GetRegionCache returns the region cache instance.

func (*KVStore) GetSafePointKV

func (s *KVStore) GetSafePointKV() SafePointKV

GetSafePointKV returns the kv store that used for safepoint.

func (*KVStore) GetSnapshot

func (s *KVStore) GetSnapshot(ts uint64) *KVSnapshot

GetSnapshot gets a snapshot that is able to read any data which data is <= ver. if ts is MaxVersion or > current max committed version, we will use current version for this snapshot.

func (*KVStore) GetTiKVClient

func (s *KVStore) GetTiKVClient() (client Client)

GetTiKVClient gets the client instance.

func (*KVStore) IsLatchEnabled

func (s *KVStore) IsLatchEnabled() bool

IsLatchEnabled is used by mockstore.TestConfig.

func (*KVStore) SendReq

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

SendReq sends a request to region.

func (*KVStore) SetOracle

func (s *KVStore) SetOracle(oracle oracle.Oracle)

SetOracle resets the oracle instance.

func (*KVStore) SetTiKVClient

func (s *KVStore) SetTiKVClient(client Client)

SetTiKVClient resets the client instance.

func (*KVStore) SplitRegions

func (s *KVStore) SplitRegions(ctx context.Context, splitKeys [][]byte, scatter bool, tableID *int64) (regionIDs []uint64, err error)

SplitRegions splits regions by splitKeys.

func (*KVStore) SupportDeleteRange

func (s *KVStore) SupportDeleteRange() (supported bool)

SupportDeleteRange gets the storage support delete range or not.

func (*KVStore) UUID

func (s *KVStore) UUID() string

UUID return a unique ID which represents a Storage.

func (*KVStore) UpdateSPCache

func (s *KVStore) UpdateSPCache(cachedSP uint64, cachedTime time.Time)

UpdateSPCache updates cached safepoint.

func (*KVStore) WaitScatterRegionFinish

func (s *KVStore) WaitScatterRegionFinish(ctx context.Context, regionID uint64, backOff int) error

WaitScatterRegionFinish implements SplittableStore interface. backOff is the back off time of the wait scatter region.(Milliseconds) if backOff <= 0, the default wait scatter back off time will be used.

type KVTxn

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

KVTxn contains methods to interact with a TiKV transaction.

func (*KVTxn) Commit

func (txn *KVTxn) Commit(ctx context.Context) error

Commit commits the transaction operations to KV store.

func (*KVTxn) Delete

func (txn *KVTxn) Delete(k []byte) error

Delete removes the entry for key k from kv store.

func (*KVTxn) EnableForceSyncLog

func (txn *KVTxn) EnableForceSyncLog()

EnableForceSyncLog indicates tikv to always sync log for the transaction.

func (*KVTxn) Get

func (txn *KVTxn) Get(ctx context.Context, k []byte) ([]byte, error)

Get implements transaction interface.

func (*KVTxn) GetClusterID

func (txn *KVTxn) GetClusterID() uint64

GetClusterID returns store's cluster id.

func (*KVTxn) GetMemBuffer

func (txn *KVTxn) GetMemBuffer() *unionstore.MemDB

GetMemBuffer return the MemBuffer binding to this transaction.

func (*KVTxn) GetScope

func (txn *KVTxn) GetScope() string

GetScope returns the geographical scope of the transaction.

func (*KVTxn) GetSnapshot

func (txn *KVTxn) GetSnapshot() *KVSnapshot

GetSnapshot returns the Snapshot binding to this transaction.

func (*KVTxn) GetUnionStore

func (txn *KVTxn) GetUnionStore() *unionstore.KVUnionStore

GetUnionStore returns the UnionStore binding to this transaction.

func (*KVTxn) GetVars

func (txn *KVTxn) GetVars() *tikv.Variables

GetVars gets variables from the transaction.

func (*KVTxn) IsCasualConsistency

func (txn *KVTxn) IsCasualConsistency() bool

IsCasualConsistency returns if the transaction allows linearizability inconsistency.

func (*KVTxn) IsPessimistic

func (txn *KVTxn) IsPessimistic() bool

IsPessimistic returns true if it is pessimistic.

func (*KVTxn) IsReadOnly

func (txn *KVTxn) IsReadOnly() bool

IsReadOnly checks if the transaction has only performed read operations.

func (*KVTxn) Iter

func (txn *KVTxn) Iter(k []byte, upperBound []byte) (unionstore.Iterator, error)

Iter creates an Iterator positioned on the first entry that k <= entry's key. If such entry is not found, it returns an invalid Iterator with no error. It yields only keys that < upperBound. If upperBound is nil, it means the upperBound is unbounded. The Iterator must be Closed after use.

func (*KVTxn) IterReverse

func (txn *KVTxn) IterReverse(k []byte) (unionstore.Iterator, error)

IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.

func (*KVTxn) Len

func (txn *KVTxn) Len() int

Len returns the number of entries in the DB.

func (*KVTxn) LockKeys

func (txn *KVTxn) LockKeys(ctx context.Context, lockCtx *tikv.LockCtx, keysInput ...[]byte) error

LockKeys tries to lock the entries with the keys in KV store. lockWaitTime in ms, except that kv.LockAlwaysWait(0) means always wait lock, kv.LockNowait(-1) means nowait lock

func (*KVTxn) Reset

func (txn *KVTxn) Reset()

Reset reset the Transaction to initial states.

func (*KVTxn) Rollback

func (txn *KVTxn) Rollback() error

Rollback undoes the transaction operations to KV store.

func (*KVTxn) Set

func (txn *KVTxn) Set(k []byte, v []byte) error

Set sets the value for key k as v into kv store. v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue.

func (*KVTxn) SetBinlogExecutor

func (txn *KVTxn) SetBinlogExecutor(binlog BinlogExecutor)

SetBinlogExecutor sets the method to perform binlong synchronization.

func (*KVTxn) SetCausalConsistency

func (txn *KVTxn) SetCausalConsistency(b bool)

SetCausalConsistency indicates if the transaction does not need to guarantee linearizability. Default value is false which means linearizability is guaranteed.

func (*KVTxn) SetCommitCallback

func (txn *KVTxn) SetCommitCallback(f func(string, error))

SetCommitCallback sets up a function that will be called when the transaction is finished.

func (*KVTxn) SetEnable1PC

func (txn *KVTxn) SetEnable1PC(b bool)

SetEnable1PC indicates if the transaction will try to use 1 phase commit.

func (*KVTxn) SetEnableAsyncCommit

func (txn *KVTxn) SetEnableAsyncCommit(b bool)

SetEnableAsyncCommit indicates if the transaction will try to use async commit.

func (*KVTxn) SetKVFilter

func (txn *KVTxn) SetKVFilter(filter KVFilter)

SetKVFilter sets the filter to ignore key-values in memory buffer.

func (*KVTxn) SetPessimistic

func (txn *KVTxn) SetPessimistic(b bool)

SetPessimistic indicates if the transaction should use pessimictic lock.

func (*KVTxn) SetPriority

func (txn *KVTxn) SetPriority(pri Priority)

SetPriority sets the priority for both write and read.

func (*KVTxn) SetResourceGroupTag

func (txn *KVTxn) SetResourceGroupTag(tag []byte)

SetResourceGroupTag sets the resource tag for both write and read.

func (*KVTxn) SetSchemaAmender

func (txn *KVTxn) SetSchemaAmender(sa SchemaAmender)

SetSchemaAmender sets an amender to update mutations after schema change.

func (*KVTxn) SetSchemaLeaseChecker

func (txn *KVTxn) SetSchemaLeaseChecker(checker SchemaLeaseChecker)

SetSchemaLeaseChecker sets a hook to check schema version.

func (*KVTxn) SetSchemaVer

func (txn *KVTxn) SetSchemaVer(schemaVer SchemaVer)

SetSchemaVer updates schema version to validate transaction.

func (*KVTxn) SetScope

func (txn *KVTxn) SetScope(scope string)

SetScope sets the geographical scope of the transaction.

func (*KVTxn) SetVars

func (txn *KVTxn) SetVars(vars *tikv.Variables)

SetVars sets variables to the transaction.

func (*KVTxn) Size

func (txn *KVTxn) Size() int

Size returns sum of keys and values length.

func (*KVTxn) StartTS

func (txn *KVTxn) StartTS() uint64

StartTS returns the transaction start timestamp.

func (*KVTxn) String

func (txn *KVTxn) String() string

String implements fmt.Stringer interface.

func (*KVTxn) Valid

func (txn *KVTxn) Valid() bool

Valid returns if the transaction is valid. A transaction become invalid after commit or rollback.

type KeyLocation

type KeyLocation struct {
	Region   RegionVerID
	StartKey []byte
	EndKey   []byte
}

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

func (*KeyLocation) String

func (l *KeyLocation) String() string

String implements fmt.Stringer interface.

type Lock

type Lock struct {
	Key             []byte
	Primary         []byte
	TxnID           uint64
	TTL             uint64
	TxnSize         uint64
	LockType        kvrpcpb.Op
	UseAsyncCommit  bool
	LockForUpdateTS uint64
	MinCommitTS     uint64
}

Lock represents a lock from tikv server.

func NewLock

func NewLock(l *kvrpcpb.LockInfo) *Lock

NewLock creates a new *Lock.

func (*Lock) String

func (l *Lock) String() string

type LockProbe

type LockProbe struct {
}

LockProbe exposes some lock utilities for testing purpose.

func (LockProbe) ExtractLockFromKeyErr

func (l LockProbe) ExtractLockFromKeyErr(err *pb.KeyError) (*Lock, error)

ExtractLockFromKeyErr makes a Lock based on a key error.

func (LockProbe) GetPrimaryKeyFromTxnStatus

func (l LockProbe) GetPrimaryKeyFromTxnStatus(s TxnStatus) []byte

GetPrimaryKeyFromTxnStatus returns the primary key of the transaction.

func (LockProbe) NewLockStatus

func (l LockProbe) NewLockStatus(keys [][]byte, useAsyncCommit bool, minCommitTS uint64) TxnStatus

NewLockStatus returns a txn state that has been locked.

type LockResolver

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

LockResolver resolves locks and also caches resolved txn status.

func NewLockResolver

func NewLockResolver(etcdAddrs []string, security config.Security, opts ...pd.ClientOption) (*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

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

BatchResolveLocks resolve locks in a batch. Used it in gcworker only!

func (*LockResolver) GetTxnStatus

func (lr *LockResolver) GetTxnStatus(txnID uint64, callerStartTS 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

func (lr *LockResolver) ResolveLocks(bo *Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, 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.

func (*LockResolver) ResolveLocksLite

func (lr *LockResolver) ResolveLocksLite(bo *Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, error)

ResolveLocksLite resolves locks while preventing scan whole region.

type LockResolverProbe

type LockResolverProbe struct {
	*LockResolver
}

LockResolverProbe wraps a LockResolver and exposes internal stats for testing purpose.

func (LockResolverProbe) CheckAllSecondaries

func (l LockResolverProbe) CheckAllSecondaries(bo *Backoffer, lock *Lock, status *TxnStatus) error

CheckAllSecondaries checks the secondary locks of an async commit transaction to find out the final status of the transaction.

func (LockResolverProbe) GetSecondariesFromTxnStatus

func (l LockResolverProbe) GetSecondariesFromTxnStatus(status TxnStatus) [][]byte

GetSecondariesFromTxnStatus returns the secondary locks from txn status.

func (LockResolverProbe) GetTxnStatus

func (l LockResolverProbe) GetTxnStatus(bo *Backoffer, txnID uint64, primary []byte,
	callerStartTS, currentTS uint64, rollbackIfNotExist bool, forceSyncCommit bool, lockInfo *Lock) (TxnStatus, error)

GetTxnStatus sends the CheckTxnStatus request to the TiKV server.

func (LockResolverProbe) GetTxnStatusFromLock

func (l LockResolverProbe) GetTxnStatusFromLock(bo *Backoffer, lock *Lock, callerStartTS uint64, forceSyncCommit bool) (TxnStatus, error)

GetTxnStatusFromLock queries tikv for a txn's status.

func (LockResolverProbe) IsErrorNotFound

func (l LockResolverProbe) IsErrorNotFound(err error) bool

IsErrorNotFound checks if an error is caused by txnNotFoundErr.

func (LockResolverProbe) IsNonAsyncCommitLock

func (l LockResolverProbe) IsNonAsyncCommitLock(err error) bool

IsNonAsyncCommitLock checks if an error is nonAsyncCommitLock error.

func (LockResolverProbe) ResolveLock

func (l LockResolverProbe) ResolveLock(ctx context.Context, lock *Lock) error

ResolveLock resolves single lock.

func (LockResolverProbe) ResolveLockAsync

func (l LockResolverProbe) ResolveLockAsync(bo *Backoffer, lock *Lock, status TxnStatus) error

ResolveLockAsync tries to resolve a lock using the txn states.

func (LockResolverProbe) ResolvePessimisticLock

func (l LockResolverProbe) ResolvePessimisticLock(ctx context.Context, lock *Lock) error

ResolvePessimisticLock resolves single pessimistic lock.

func (LockResolverProbe) SetMeetLockCallback

func (l LockResolverProbe) SetMeetLockCallback(f func([]*Lock))

SetMeetLockCallback is called whenever it meets locks.

type MockSafePointKV

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

MockSafePointKV implements SafePointKV at mock test

func NewMockSafePointKV

func NewMockSafePointKV() *MockSafePointKV

NewMockSafePointKV creates an instance of MockSafePointKV

func (*MockSafePointKV) Close

func (w *MockSafePointKV) Close() error

Close implements the Close method for SafePointKV

func (*MockSafePointKV) Get

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

Get implements the Get method for SafePointKV

func (*MockSafePointKV) GetWithPrefix

func (w *MockSafePointKV) GetWithPrefix(prefix string) ([]*mvccpb.KeyValue, error)

GetWithPrefix implements the Get method for SafePointKV

func (*MockSafePointKV) Put

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

Put implements the Put method for SafePointKV

type PlainMutation

type PlainMutation struct {
	KeyOp             pb.Op
	Key               []byte
	Value             []byte
	IsPessimisticLock bool
}

PlainMutation represents a single transaction operation.

type PlainMutations

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

PlainMutations contains transaction operations.

func NewPlainMutations

func NewPlainMutations(sizeHint int) PlainMutations

NewPlainMutations creates a PlainMutations object with sizeHint reserved.

func (*PlainMutations) AppendMutation

func (c *PlainMutations) AppendMutation(mutation PlainMutation)

AppendMutation merges a single Mutation into the current mutations.

func (*PlainMutations) GetKey

func (c *PlainMutations) GetKey(i int) []byte

GetKey returns the key at index.

func (*PlainMutations) GetKeys

func (c *PlainMutations) GetKeys() [][]byte

GetKeys returns the keys.

func (*PlainMutations) GetOp

func (c *PlainMutations) GetOp(i int) pb.Op

GetOp returns the key op at index.

func (*PlainMutations) GetOps

func (c *PlainMutations) GetOps() []pb.Op

GetOps returns the key ops.

func (*PlainMutations) GetPessimisticFlags

func (c *PlainMutations) GetPessimisticFlags() []bool

GetPessimisticFlags returns the key pessimistic flags.

func (*PlainMutations) GetValue

func (c *PlainMutations) GetValue(i int) []byte

GetValue returns the key value at index.

func (*PlainMutations) GetValues

func (c *PlainMutations) GetValues() [][]byte

GetValues returns the key values.

func (*PlainMutations) IsPessimisticLock

func (c *PlainMutations) IsPessimisticLock(i int) bool

IsPessimisticLock returns the key pessimistic flag at index.

func (*PlainMutations) Len

func (c *PlainMutations) Len() int

Len returns the count of mutations.

func (*PlainMutations) MergeMutations

func (c *PlainMutations) MergeMutations(mutations PlainMutations)

MergeMutations append input mutations into current mutations.

func (*PlainMutations) Push

func (c *PlainMutations) Push(op pb.Op, key []byte, value []byte, isPessimisticLock bool)

Push another mutation into mutations.

func (*PlainMutations) Slice

func (c *PlainMutations) Slice(from, to int) CommitterMutations

Slice return a sub mutations in range [from, to).

type Priority

type Priority kvrpcpb.CommandPri

Priority is the priority for tikv to execute a command.

func (Priority) ToPB

func (p Priority) ToPB() kvrpcpb.CommandPri

ToPB converts priority to wire type.

type RPCCanceller

type RPCCanceller struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RPCCanceller is rpc send cancelFunc collector.

func NewRPCanceller

func NewRPCanceller() *RPCCanceller

NewRPCanceller creates RPCCanceller with init state.

func (*RPCCanceller) CancelAll

func (h *RPCCanceller) CancelAll()

CancelAll cancels all inflight rpc context.

func (*RPCCanceller) WithCancel

func (h *RPCCanceller) WithCancel(ctx context.Context) (context.Context, func())

WithCancel generates new context with cancel func.

type RPCCancellerCtxKey

type RPCCancellerCtxKey struct{}

RPCCancellerCtxKey is context key attach rpc send cancelFunc collector to ctx.

type RPCContext

type RPCContext struct {
	Region         RegionVerID
	Meta           *metapb.Region
	Peer           *metapb.Peer
	AccessIdx      AccessIndex
	Store          *Store
	Addr           string
	AccessMode     AccessMode
	ProxyStore     *Store      // nil means proxy is not used
	ProxyAccessIdx AccessIndex // valid when ProxyStore is not nil
	ProxyAddr      string      // valid when ProxyStore is not nil
	TiKVNum        int         // Number of TiKV nodes among the region's peers. Assuming non-TiKV peers are all TiFlash peers.
	// contains filtered or unexported fields
}

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

func (*RPCContext) String

func (c *RPCContext) String() string

type RPCRuntimeStats

type RPCRuntimeStats struct {
	Count int64
	// Send region request consume time.
	Consume int64
}

RPCRuntimeStats indicates the RPC request count and consume time.

type RangeTaskHandler

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

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

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

func (s *RangeTaskRunner) CompletedRegions() int

CompletedRegions returns how many regions has been sent requests.

func (*RangeTaskRunner) FailedRegions

func (s *RangeTaskRunner) FailedRegions() int

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

func (*RangeTaskRunner) RunOnRange

func (s *RangeTaskRunner) RunOnRange(ctx context.Context, startKey, endKey []byte) error

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

func (*RangeTaskRunner) SetRegionsPerTask

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.

type RangeTaskStat

type RangeTaskStat struct {
	CompletedRegions int
	FailedRegions    int
}

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

type RawKVClient

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

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

NewRawKVClient creates a client with PD cluster addrs.

func (*RawKVClient) BatchDelete

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

BatchDelete deletes key-value pairs from TiKV

func (*RawKVClient) BatchGet

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

BatchGet queries values with the keys.

func (*RawKVClient) BatchPut

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

BatchPut stores key-value pairs to TiKV.

func (*RawKVClient) Close

func (c *RawKVClient) Close() error

Close closes the client.

func (*RawKVClient) ClusterID

func (c *RawKVClient) ClusterID() uint64

ClusterID returns the TiKV cluster ID.

func (*RawKVClient) Delete

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

Delete deletes a key-value pair from TiKV.

func (*RawKVClient) DeleteRange

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

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

func (*RawKVClient) Get

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

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

Put stores a key-value pair to TiKV.

func (*RawKVClient) ReverseScan

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, push a '\0' to the key. For example, to scan (endKey, startKey], you can write: `ReverseScan(push(startKey, '\0'), push(endKey, '\0'), limit)`. It doesn't support Scanning from "", because locating the last Region is not yet implemented.

func (*RawKVClient) Scan

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, push a '\0' to the key. For example, to scan (startKey, endKey], you can write: `Scan(push(startKey, '\0'), push(endKey, '\0'), limit)`.

type RawKVClientProbe

type RawKVClientProbe struct {
	*RawKVClient
}

RawKVClientProbe wraps RawKVClient and exposes internal states for testing purpose.

func (RawKVClientProbe) GetRegionCache

func (c RawKVClientProbe) GetRegionCache() *RegionCache

GetRegionCache returns the internal region cache container.

func (RawKVClientProbe) SetPDClient

func (c RawKVClientProbe) SetPDClient(client pd.Client)

SetPDClient resets the interval PD client.

func (RawKVClientProbe) SetRPCClient

func (c RawKVClientProbe) SetRPCClient(client Client)

SetRPCClient resets the internal RPC client.

func (RawKVClientProbe) SetRegionCache

func (c RawKVClientProbe) SetRegionCache(regionCache *RegionCache)

SetRegionCache resets the internal region cache container.

type Region

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

Region presents kv region

func (*Region) AnyStorePeer

func (r *Region) AnyStorePeer(rs *RegionStore, followerStoreSeed uint32, op *storeSelectorOp) (store *Store, peer *metapb.Peer, accessIdx AccessIndex, storeIdx int)

AnyStorePeer returns a leader or follower store with the associated peer.

func (*Region) Contains

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

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

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

EndKey returns EndKey.

func (*Region) FollowerStorePeer

func (r *Region) FollowerStorePeer(rs *RegionStore, followerStoreSeed uint32, op *storeSelectorOp) (store *Store, peer *metapb.Peer, accessIdx AccessIndex, storeIdx int)

FollowerStorePeer returns a follower store with follower peer.

func (*Region) GetID

func (r *Region) GetID() uint64

GetID returns id.

func (*Region) GetLeaderPeerID

func (r *Region) GetLeaderPeerID() uint64

GetLeaderPeerID returns leader peer ID.

func (*Region) GetLeaderStoreID

func (r *Region) GetLeaderStoreID() uint64

GetLeaderStoreID returns the store ID of the leader region.

func (*Region) GetMeta

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

GetMeta returns region meta.

func (*Region) StartKey

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

StartKey returns StartKey.

func (*Region) VerID

func (r *Region) VerID() RegionVerID

VerID returns the Region's RegionVerID.

func (*Region) WorkStorePeer

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

WorkStorePeer returns current work store with work peer.

type RegionCache

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

RegionCache caches Regions loaded from PD.

func NewRegionCache

func NewRegionCache(pdClient pd.Client) *RegionCache

NewRegionCache creates a RegionCache.

func (*RegionCache) BatchLoadRegionsFromKey

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

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

BatchLoadRegionsWithKeyRange loads at most given numbers of regions to the RegionCache, within the given key range from the startKey to endKey. Returns the loaded regions.

func (*RegionCache) Close

func (c *RegionCache) Close()

Close releases region cache's resource.

func (*RegionCache) GetAllValidTiFlashStores

func (c *RegionCache) GetAllValidTiFlashStores(id RegionVerID, currentStore *Store) []uint64

GetAllValidTiFlashStores returns the store ids of all valid TiFlash stores, the store id of currentStore is always the first one

func (*RegionCache) GetCachedRegionWithRLock

func (c *RegionCache) GetCachedRegionWithRLock(regionID RegionVerID) (r *Region)

GetCachedRegionWithRLock returns region with lock.

func (*RegionCache) GetStoresByType

func (c *RegionCache) GetStoresByType(typ tikvrpc.EndpointType) []*Store

GetStoresByType gets stores by type `typ` TODO: revise it by get store by closure.

func (*RegionCache) GetTiFlashRPCContext

func (c *RegionCache) GetTiFlashRPCContext(bo *Backoffer, id RegionVerID, loadBalance bool) (*RPCContext, error)

GetTiFlashRPCContext returns RPCContext for a region must access flash store. If it returns nil, the region must be out of date and already dropped from cache or not flash store found. `loadBalance` is an option. For MPP and batch cop, it is pointless and might cause try the failed store repeatly.

func (*RegionCache) GetTiFlashStoreAddrs

func (c *RegionCache) GetTiFlashStoreAddrs() []string

GetTiFlashStoreAddrs returns addresses of all tiflash nodes.

func (*RegionCache) GetTiKVRPCContext

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

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

func (*RegionCache) GroupKeysByRegion

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

func (c *RegionCache) InvalidateCachedRegion(id RegionVerID)

InvalidateCachedRegion removes a cached Region.

func (*RegionCache) InvalidateCachedRegionWithReason

func (c *RegionCache) InvalidateCachedRegionWithReason(id RegionVerID, reason InvalidReason)

InvalidateCachedRegionWithReason removes a cached Region with the reason why it's invalidated.

func (*RegionCache) ListRegionIDsInKeyRange

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

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

LoadRegionsInKeyRange lists regions in [start_key,end_key].

func (*RegionCache) LocateEndKey

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

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

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

LocateRegionByID searches for the region with ID.

func (*RegionCache) OnRegionEpochNotMatch

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

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

func (*RegionCache) OnSendFail

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

OnSendFail handles send request fail logic.

func (*RegionCache) OnSendFailForTiFlash

func (c *RegionCache) OnSendFailForTiFlash(bo *Backoffer, store *Store, region RegionVerID, prev *metapb.Region, scheduleReload bool, err error)

OnSendFailForTiFlash handles send request fail logic for tiflash.

func (*RegionCache) PDClient

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

PDClient returns the pd.Client in RegionCache.

func (*RegionCache) UpdateLeader

func (c *RegionCache) UpdateLeader(regionID RegionVerID, leader *metapb.Peer, currentPeerIdx AccessIndex)

UpdateLeader update some region cache with newer leader info.

type RegionRequestRuntimeStats

type RegionRequestRuntimeStats struct {
	Stats map[tikvrpc.CmdType]*RPCRuntimeStats
}

RegionRequestRuntimeStats records the runtime stats of send region requests.

func NewRegionRequestRuntimeStats

func NewRegionRequestRuntimeStats() RegionRequestRuntimeStats

NewRegionRequestRuntimeStats returns a new RegionRequestRuntimeStats.

func (*RegionRequestRuntimeStats) Clone

Clone returns a copy of itself.

func (*RegionRequestRuntimeStats) Merge

Merge merges other RegionRequestRuntimeStats.

func (*RegionRequestRuntimeStats) String

func (r *RegionRequestRuntimeStats) String() string

String implements fmt.Stringer interface.

type RegionRequestSender

type RegionRequestSender struct {
	RegionRequestRuntimeStats
	// 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'. If fails to send the request to all replicas, a fake rregion error may be returned. Caller which receives the error should retry the request.

For other region 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 *RegionCache, client Client) *RegionRequestSender

NewRegionRequestSender creates a new sender.

func (*RegionRequestSender) GetClient

func (s *RegionRequestSender) GetClient() Client

GetClient returns the RPC client.

func (*RegionRequestSender) GetRPCError

func (s *RegionRequestSender) GetRPCError() error

GetRPCError returns the RPC error.

func (*RegionRequestSender) GetRegionCache

func (s *RegionRequestSender) GetRegionCache() *RegionCache

GetRegionCache returns the region cache.

func (*RegionRequestSender) GetStoreAddr

func (s *RegionRequestSender) GetStoreAddr() string

GetStoreAddr returns the dest store address.

func (*RegionRequestSender) NeedReloadRegion

func (s *RegionRequestSender) NeedReloadRegion(ctx *RPCContext) (need bool)

NeedReloadRegion checks is all peers has sent failed, if so need reload.

func (*RegionRequestSender) SendReq

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

SendReq sends a request to tikv server. If fails to send the request to all replicas, a fake region error may be returned. Caller which receives the error should retry the request.

func (*RegionRequestSender) SendReqCtx

func (s *RegionRequestSender) SendReqCtx(
	bo *Backoffer,
	req *tikvrpc.Request,
	regionID RegionVerID,
	timeout time.Duration,
	et tikvrpc.EndpointType,
	opts ...StoreSelectorOption,
) (
	resp *tikvrpc.Response,
	rpcCtx *RPCContext,
	err error,
)

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

func (*RegionRequestSender) SetRPCError

func (s *RegionRequestSender) SetRPCError(err error)

SetRPCError rewrite the rpc error.

func (*RegionRequestSender) SetStoreAddr

func (s *RegionRequestSender) SetStoreAddr(addr string)

SetStoreAddr specifies the dest store address.

type RegionStore

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

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

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

func NewRegionVerID

func NewRegionVerID(id, confVer, ver uint64) RegionVerID

NewRegionVerID creates a region ver id, which used for invalidating regions.

func (*RegionVerID) Equals

func (r *RegionVerID) Equals(another RegionVerID) bool

Equals checks whether the RegionVerID equals to another one

func (*RegionVerID) GetConfVer

func (r *RegionVerID) GetConfVer() uint64

GetConfVer returns the conf ver of the region's epoch

func (*RegionVerID) GetID

func (r *RegionVerID) GetID() uint64

GetID returns the id of the region

func (*RegionVerID) GetVer

func (r *RegionVerID) GetVer() uint64

GetVer returns the version of the region's epoch

func (*RegionVerID) String

func (r *RegionVerID) String() string

String formats the RegionVerID to string

type RelatedSchemaChange

type RelatedSchemaChange struct {
	PhyTblIDS        []int64
	ActionTypes      []uint64
	LatestInfoSchema SchemaVer
	Amendable        bool
}

RelatedSchemaChange contains information about schema diff between two schema versions.

type SafePointKV

type SafePointKV interface {
	Put(k string, v string) error
	Get(k string) (string, error)
	GetWithPrefix(k string) ([]*mvccpb.KeyValue, error)
	Close() error
}

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

type Scanner

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

Scanner support tikv scan

func (*Scanner) Close

func (s *Scanner) Close()

Close close iterator.

func (*Scanner) Key

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

Key return key.

func (*Scanner) Next

func (s *Scanner) Next() error

Next return next element.

func (*Scanner) Valid

func (s *Scanner) Valid() bool

Valid return valid.

func (*Scanner) Value

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

Value return value.

type SchemaAmender

type SchemaAmender interface {
	// AmendTxn is the amend entry, new mutations will be generated based on input mutations using schema change info.
	// The returned results are mutations need to prewrite and mutations need to cleanup.
	AmendTxn(ctx context.Context, startInfoSchema SchemaVer, change *RelatedSchemaChange, mutations CommitterMutations) (CommitterMutations, error)
}

SchemaAmender is used by pessimistic transactions to amend commit mutations for schema change during 2pc.

type SchemaLeaseChecker

type SchemaLeaseChecker interface {
	// CheckBySchemaVer checks if the schema has changed for the transaction related tables between the startSchemaVer
	// and the schema version at txnTS, all the related schema changes will be returned.
	CheckBySchemaVer(txnTS uint64, startSchemaVer SchemaVer) (*RelatedSchemaChange, error)
}

SchemaLeaseChecker is used to validate schema version is not changed during transaction execution.

type SchemaVer

type SchemaVer interface {
	// SchemaMetaVersion returns the meta schema version.
	SchemaMetaVersion() int64
}

SchemaVer is the infoSchema which will return the schema version.

type SnapshotProbe

type SnapshotProbe struct {
	*KVSnapshot
}

SnapshotProbe exposes some snapshot utilities for testing purpose.

func (SnapshotProbe) FormatStats

func (s SnapshotProbe) FormatStats() string

FormatStats dumps information of stats.

func (SnapshotProbe) MergeExecDetail

func (s SnapshotProbe) MergeExecDetail(detail *pb.ExecDetailsV2)

MergeExecDetail merges exec stats into snapshot's stats.

func (SnapshotProbe) MergeRegionRequestStats

func (s SnapshotProbe) MergeRegionRequestStats(stats map[tikvrpc.CmdType]*RPCRuntimeStats)

MergeRegionRequestStats merges RPC runtime stats into snapshot's stats.

func (SnapshotProbe) RecordBackoffInfo

func (s SnapshotProbe) RecordBackoffInfo(bo *Backoffer)

RecordBackoffInfo records backoff stats into snapshot's stats.

type SnapshotRuntimeStats

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

SnapshotRuntimeStats records the runtime stats of snapshot.

func (*SnapshotRuntimeStats) Clone

Clone implements the RuntimeStats interface.

func (*SnapshotRuntimeStats) Merge

func (rs *SnapshotRuntimeStats) Merge(other *SnapshotRuntimeStats)

Merge implements the RuntimeStats interface.

func (*SnapshotRuntimeStats) String

func (rs *SnapshotRuntimeStats) String() string

String implements fmt.Stringer interface.

type StartTSOption

type StartTSOption struct {
	TxnScope string
	StartTS  *uint64
}

StartTSOption indicates the option when beginning a transaction `TxnScope` must be set for each object Every other fields are optional, but currently at most one of them can be set

func DefaultStartTSOption

func DefaultStartTSOption() StartTSOption

DefaultStartTSOption creates a default StartTSOption, ie. Work in GlobalTxnScope and get start ts when got used

func (StartTSOption) SetStartTS

func (to StartTSOption) SetStartTS(startTS uint64) StartTSOption

SetStartTS returns a new StartTSOption with StartTS set to the given startTS

func (StartTSOption) SetTxnScope

func (to StartTSOption) SetTxnScope(txnScope string) StartTSOption

SetTxnScope returns a new StartTSOption with TxnScope set to txnScope

type Storage

type Storage interface {
	// 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)

	// 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{}

	// Close store
	Close() error
	// UUID return a unique ID which represents a Storage.
	UUID() string
	// CurrentTimestamp returns current timestamp with the given txnScope (local or global).
	CurrentTimestamp(txnScope string) (uint64, error)
	// GetOracle gets a timestamp oracle client.
	GetOracle() oracle.Oracle
	// SupportDeleteRange gets the storage support delete range or not.
	SupportDeleteRange() (supported bool)
}

Storage represent the kv.Storage runs on TiKV.

type Store

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

Store contains a kv process's address.

func (*Store) GetAddr

func (s *Store) GetAddr() string

GetAddr returns the address of the store

func (*Store) IsLabelsMatch

func (s *Store) IsLabelsMatch(labels []*metapb.StoreLabel) bool

IsLabelsMatch return whether the store's labels match the target labels

func (*Store) IsSameLabels

func (s *Store) IsSameLabels(labels []*metapb.StoreLabel) bool

IsSameLabels returns whether the store have the same labels with target labels

func (*Store) IsTiFlash

func (s *Store) IsTiFlash() bool

IsTiFlash returns true if the storeType is TiFlash

type StoreProbe

type StoreProbe struct {
	*KVStore
}

StoreProbe wraps KVSTore and exposes internal states for testing purpose.

func (StoreProbe) Begin

func (s StoreProbe) Begin() (TxnProbe, error)

Begin starts a transaction.

func (StoreProbe) ClearTxnLatches

func (s StoreProbe) ClearTxnLatches()

ClearTxnLatches clears store's txn latch scheduler.

func (StoreProbe) GetSnapshot

func (s StoreProbe) GetSnapshot(ts uint64) SnapshotProbe

GetSnapshot returns a snapshot.

func (StoreProbe) GetTimestampWithRetry

func (s StoreProbe) GetTimestampWithRetry(bo *Backoffer, scope string) (uint64, error)

GetTimestampWithRetry returns latest timestamp.

func (StoreProbe) LoadSafePoint

func (s StoreProbe) LoadSafePoint() (uint64, error)

LoadSafePoint from safepoint kv.

func (StoreProbe) NewLockResolver

func (s StoreProbe) NewLockResolver() LockResolverProbe

NewLockResolver creates a new LockResolver instance.

func (StoreProbe) SaveSafePoint

func (s StoreProbe) SaveSafePoint(v uint64) error

SaveSafePoint saves safepoint to kv.

func (StoreProbe) SendTxnHeartbeat

func (s StoreProbe) SendTxnHeartbeat(ctx context.Context, key []byte, startTS uint64, ttl uint64) (uint64, error)

SendTxnHeartbeat renews a txn's ttl.

func (StoreProbe) SetRegionCachePDClient

func (s StoreProbe) SetRegionCachePDClient(client pd.Client)

SetRegionCachePDClient replaces pd client inside region cache.

func (StoreProbe) SetRegionCacheStore

func (s StoreProbe) SetRegionCacheStore(id uint64, storeType tikvrpc.EndpointType, state uint64, labels []*metapb.StoreLabel)

SetRegionCacheStore is used to set a store in region cache, for testing only

func (StoreProbe) SetSafeTS

func (s StoreProbe) SetSafeTS(storeID, safeTS uint64)

SetSafeTS is used to set safeTS for the store with `storeID`

type StoreSelectorOption

type StoreSelectorOption func(*storeSelectorOp)

StoreSelectorOption configures storeSelectorOp.

func WithLeaderOnly

func WithLeaderOnly() StoreSelectorOption

WithLeaderOnly indicates selecting stores with leader only.

func WithMatchLabels

func WithMatchLabels(labels []*metapb.StoreLabel) StoreSelectorOption

WithMatchLabels indicates selecting stores with matched labels.

type TxnInfo

type TxnInfo struct {
	TxnScope            string `json:"txn_scope"`
	StartTS             uint64 `json:"start_ts"`
	CommitTS            uint64 `json:"commit_ts"`
	TxnCommitMode       string `json:"txn_commit_mode"`
	AsyncCommitFallback bool   `json:"async_commit_fallback"`
	OnePCFallback       bool   `json:"one_pc_fallback"`
	ErrMsg              string `json:"error,omitempty"`
}

TxnInfo is used to keep track the info of a committed transaction (mainly for diagnosis and testing)

type TxnProbe

type TxnProbe struct {
	*KVTxn
}

TxnProbe wraps a txn and exports internal states for testing purpose.

func (TxnProbe) BatchGetSingleRegion

func (txn TxnProbe) BatchGetSingleRegion(bo *Backoffer, region RegionVerID, keys [][]byte, collect func([]byte, []byte)) error

BatchGetSingleRegion gets a batch of keys from a region.

func (TxnProbe) CollectLockedKeys

func (txn TxnProbe) CollectLockedKeys() [][]byte

CollectLockedKeys returns all locked keys of a transaction.

func (TxnProbe) GetCommitTS

func (txn TxnProbe) GetCommitTS() uint64

GetCommitTS returns the commit ts.

func (TxnProbe) GetCommitter

func (txn TxnProbe) GetCommitter() CommitterProbe

GetCommitter returns the transaction committer.

func (TxnProbe) GetStartTime

func (txn TxnProbe) GetStartTime() time.Time

GetStartTime returns the time when txn starts.

func (TxnProbe) GetUnionStore

func (txn TxnProbe) GetUnionStore() *unionstore.KVUnionStore

GetUnionStore returns transaction's embedded unionstore.

func (TxnProbe) IsAsyncCommit

func (txn TxnProbe) IsAsyncCommit() bool

IsAsyncCommit returns if the txn is committed using async commit.

func (TxnProbe) NewCommitter

func (txn TxnProbe) NewCommitter(sessionID uint64) (CommitterProbe, error)

NewCommitter creates an committer.

func (TxnProbe) NewScanner

func (txn TxnProbe) NewScanner(start, end []byte, batchSize int, reverse bool) (*Scanner, error)

NewScanner returns a scanner to iterate given key range.

func (TxnProbe) SetCommitter

func (txn TxnProbe) SetCommitter(committer CommitterProbe)

SetCommitter sets the bind committer of a transaction.

func (TxnProbe) SetStartTS

func (txn TxnProbe) SetStartTS(ts uint64)

SetStartTS resets the txn's start ts.

type TxnStatus

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

func (s TxnStatus) Action() kvrpcpb.Action

Action returns what the CheckTxnStatus request have done to the transaction.

func (TxnStatus) CommitTS

func (s TxnStatus) CommitTS() uint64

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

func (TxnStatus) IsCommitted

func (s TxnStatus) IsCommitted() bool

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

func (TxnStatus) StatusCacheable

func (s TxnStatus) StatusCacheable() bool

StatusCacheable checks whether the transaction status is certain.True will be returned if its status is certain:

If transaction is already committed, the result could be cached.
Otherwise:
  If l.LockType is pessimistic lock type:
      - if its primary lock is pessimistic too, the check txn status result should not be cached.
      - if its primary lock is prewrite lock type, the check txn status could be cached.
  If l.lockType is prewrite lock type:
      - always cache the check txn status result.

For prewrite locks, their primary keys should ALWAYS be the correct one and will NOT change.

func (TxnStatus) TTL

func (s TxnStatus) TTL() uint64

TTL returns the TTL of the transaction if the transaction is still alive.

type Variables

type Variables = kv.Variables

Variables defines the variables used by TiKV storage.

Directories

Path Synopsis
Package client provides tcp connection to kvserver.
Package client provides tcp connection to kvserver.
mockstore

Jump to

Keyboard shortcuts

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