import "github.com/pingcap/tidb/kv"
cachedb.go checker.go error.go fault_injection.go iter.go key.go kv.go memdb.go memdb_arena.go memdb_iterator.go memdb_snapshot.go mpp.go txn.go union_iter.go union_store.go utils.go variables.go version.go
Priority value for transaction priority.
const ( ReqTypeSelect = 101 ReqTypeIndex = 102 ReqTypeDAG = 103 ReqTypeAnalyze = 104 ReqTypeChecksum = 105 ReqSubTypeBasic = 0 ReqSubTypeDesc = 10000 ReqSubTypeGroupBy = 10001 ReqSubTypeTopN = 10002 ReqSubTypeSignature = 10003 ReqSubTypeAnalyzeIdx = 10004 ReqSubTypeAnalyzeCol = 10005 )
ReqTypes.
const ( DefBackoffLockFast = 100 DefBackOffWeight = 2 )
Default values
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.
const TxnRetryableMark = "[try again later]"
TxnRetryableMark is used to uniform the commit error messages which could retry the transaction. *WARNING*: changing this string will affect the backward compatibility.
UnCommitIndexKVFlag uses to indicate the index key/value is no need to commit. This is used in the situation of the index key/value was unchanged when do update. Usage: 1. For non-unique index: normally, the index value is '0'. Change the value to '1' indicate the index key/value is no need to commit. 2. For unique index: normally, the index value is the record handle ID, 8 bytes. Append UnCommitIndexKVFlag to the value indicate the index key/value is no need to commit.
var ( // ErrNotExist is used when try to get an entry with an unexist key from KV store. ErrNotExist = dbterror.ClassKV.NewStd(mysql.ErrNotExist) // ErrTxnRetryable is used when KV store occurs retryable error which SQL layer can safely retry the transaction. // When using TiKV as the storage node, the error is returned ONLY when lock not found (txnLockNotFound) in Commit, // subject to change it in the future. ErrTxnRetryable = dbterror.ClassKV.NewStdErr(mysql.ErrTxnRetryable, pmysql.Message(mysql.MySQLErrName[mysql.ErrTxnRetryable].Raw+TxnRetryableMark, []int{0})) // ErrCannotSetNilValue is the error when sets an empty value. ErrCannotSetNilValue = dbterror.ClassKV.NewStd(mysql.ErrCannotSetNilValue) // ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction. ErrInvalidTxn = dbterror.ClassKV.NewStd(mysql.ErrInvalidTxn) // ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value. ErrTxnTooLarge = dbterror.ClassKV.NewStd(mysql.ErrTxnTooLarge) // ErrEntryTooLarge is the error when a key value entry is too large. ErrEntryTooLarge = dbterror.ClassKV.NewStd(mysql.ErrEntryTooLarge) // ErrKeyExists returns when key is already exist. ErrKeyExists = dbterror.ClassKV.NewStd(mysql.ErrDupEntry) // ErrNotImplemented returns when a function is not implemented yet. ErrNotImplemented = dbterror.ClassKV.NewStd(mysql.ErrNotImplemented) // ErrWriteConflict is the error when the commit meets an write conflict error. ErrWriteConflict = dbterror.ClassKV.NewStdErr(mysql.ErrWriteConflict, pmysql.Message(mysql.MySQLErrName[mysql.ErrWriteConflict].Raw+" "+TxnRetryableMark, []int{3})) // ErrWriteConflictInTiDB is the error when the commit meets an write conflict error when local latch is enabled. ErrWriteConflictInTiDB = dbterror.ClassKV.NewStdErr(mysql.ErrWriteConflictInTiDB, pmysql.Message(mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].Raw+" "+TxnRetryableMark, nil)) )
var ( // TxnEntrySizeLimit is limit of single entry size (len(key) + len(value)). TxnEntrySizeLimit uint64 = config.DefTxnEntrySizeLimit // TxnTotalSizeLimit is limit of the sum of all entry size. TxnTotalSizeLimit uint64 = config.DefTxnTotalSizeLimit )
Those limits is enforced to make sure the transaction can be well handled by TiKV.
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
var ( // MaxVersion is the maximum version, notice that it's not a valid version. MaxVersion = Version{Ver: math.MaxUint64} // MinVersion is the minimum version, it's not a valid version, too. MinVersion = Version{Ver: 0} )
var DefaultVars = NewVariables(&ignoreKill)
DefaultVars is the default variables instance.
BackOff Implements exponential backoff with full jitter. Returns real back off time in microsecond. See http://www.awsarchitectureblog.com/2015/03/backoff.html.
GetDuplicateErrorHandleString is used to concat the handle columns data with '-'. This is consistent with MySQL.
GetInt64 get int64 value which created by IncInt64 method.
IncInt64 increases the value for key k in kv store by step.
IsErrNotFound checks if err is a kind of NotFound error.
IsMockCommitErrorEnable exports for gofail testing.
IsTombstone returns whether the value is a tombstone.
IsTxnRetryableError checks if the error could safely retry the transaction.
func MockCommitErrorDisable()
MockCommitErrorDisable exports for gofail testing.
func MockCommitErrorEnable()
MockCommitErrorEnable exports for gofail testing.
NextUntil applies FnKeyCmp to each entry of the iterator until meets some condition. It will stop when fn returns true, or iterator is invalid or an error occurs.
func RunInNewTxn(ctx context.Context, store Storage, retryable bool, f func(ctx context.Context, txn Transaction) error) error
RunInNewTxn will run the f in a new transaction environment.
WalkMemBuffer iterates all buffered kv pairs in memBuf
AssertionType is the type of a assertion.
const ( None AssertionType = iota Exist NotExist )
The AssertionType constants.
type BatchGetter interface { // BatchGet gets a batch of values. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) }
BatchGetter is the interface for BatchGet.
type BufferBatchGetter struct {
// contains filtered or unexported fields
}
BufferBatchGetter is the type for BatchGet with MemBuffer.
func NewBufferBatchGetter(buffer MemBuffer, middleCache Getter, snapshot Snapshot) *BufferBatchGetter
NewBufferBatchGetter creates a new BufferBatchGetter.
BatchGet implements the BatchGetter interface.
type Client interface { // Send sends request to KV layer, returns a Response. Send(ctx context.Context, req *Request, vars *Variables, sessionMemTracker *memory.Tracker, enabledRateLimitAction bool) Response // IsRequestTypeSupported checks if reqType and subType is supported. IsRequestTypeSupported(reqType, subType int64) bool }
Client is used to send request to KV layer.
type CommonHandle struct {
// contains filtered or unexported fields
}
CommonHandle implements the Handle interface for non-int64 type handle.
func NewCommonHandle(encoded []byte) (*CommonHandle, error)
NewCommonHandle creates a CommonHandle from a encoded bytes which is encoded by code.EncodeKey.
func (ch *CommonHandle) Compare(h Handle) int
Compare implements the Handle interface.
func (ch *CommonHandle) Data() ([]types.Datum, error)
Data implements the Handle interface.
func (ch *CommonHandle) Encoded() []byte
Encoded implements the Handle interface.
func (ch *CommonHandle) EncodedCol(idx int) []byte
EncodedCol implements the Handle interface.
func (ch *CommonHandle) Equal(h Handle) bool
Equal implements the Handle interface.
func (ch *CommonHandle) IntValue() int64
IntValue implements the Handle interface, not supported for CommonHandle type.
func (ch *CommonHandle) IsInt() bool
IsInt implements the Handle interface.
func (ch *CommonHandle) Len() int
Len implements the Handle interface.
func (ch *CommonHandle) Next() Handle
Next implements the Handle interface.
func (ch *CommonHandle) NumCols() int
NumCols implements the Handle interface.
func (ch *CommonHandle) String() string
String implements the Handle interface.
type Driver interface { // Open returns a new Storage. // The path is the string for storage specific format. Open(path string) (Storage, error) }
Driver is the interface that must be implemented by a KV storage.
FlagsOp describes KeyFlags modify operation.
const ( // SetPresumeKeyNotExists marks the existence of the associated key is checked lazily. // Implies KeyFlags.HasNeedCheckExists() == true. SetPresumeKeyNotExists FlagsOp = 1 << iota // DelPresumeKeyNotExists reverts SetPresumeKeyNotExists. DelPresumeKeyNotExists // SetKeyLocked marks the associated key has acquired lock. SetKeyLocked // DelKeyLocked reverts SetKeyLocked. DelKeyLocked // SetNeedLocked marks the associated key need to be acquired lock. SetNeedLocked // DelNeedLocked reverts SetKeyNeedLocked. DelNeedLocked // SetKeyLockedValueExists marks the value exists when key has been locked in Transaction.LockKeys. SetKeyLockedValueExists // SetKeyLockedValueNotExists marks the value doesn't exists when key has been locked in Transaction.LockKeys. SetKeyLockedValueNotExists // DelNeedCheckExists marks the key no need to be checked in Transaction.LockKeys. DelNeedCheckExists // SetPrewriteOnly marks the key shouldn't be used in 2pc commit phase. SetPrewriteOnly // SetIgnoredIn2PC marks the key will be ignored in 2pc. SetIgnoredIn2PC )
FnKeyCmp is the function for iterator the keys
type Getter interface { // Get gets the value for key k from kv store. // If corresponding kv pair does not exist, it returns nil and ErrNotExist. Get(ctx context.Context, k Key) ([]byte, error) }
Getter is the interface for the Get method.
type Handle interface { // IsInt returns if the handle type is int64. IsInt() bool // IntValue returns the int64 value if IsInt is true, it panics if IsInt returns false. IntValue() int64 // Next returns the minimum handle that is greater than this handle. Next() Handle // Equal returns if the handle equals to another handle, it panics if the types are different. Equal(h Handle) bool // Compare returns the comparison result of the two handles, it panics if the types are different. Compare(h Handle) int // Encoded returns the encoded bytes. Encoded() []byte // Len returns the length of the encoded bytes. Len() int // NumCols returns the number of columns of the handle, NumCols() int // EncodedCol returns the encoded column value at the given column index. EncodedCol(idx int) []byte // Data returns the data of all columns of a handle. Data() ([]types.Datum, error) // String implements the fmt.Stringer interface. String() string }
Handle is the ID of a row.
func BuildHandleFromDatumRow(sctx *stmtctx.StatementContext, row []types.Datum, handleOrdinals []int) (Handle, error)
BuildHandleFromDatumRow builds kv.Handle from cols in row.
type HandleMap struct {
// contains filtered or unexported fields
}
HandleMap is the map for Handle.
NewHandleMap creates a new map for handle.
Delete deletes a entry from the map.
Get gets a value by a Handle.
Len returns the length of the map.
Range iterates the HandleMap with fn, the fn returns true to continue, returns false to stop.
Set sets a value with a Handle.
InjectedSnapshot wraps a Snapshot with injections.
BatchGet returns an error if cfg.getError is set.
Get returns an error if cfg.getError is set.
InjectedStore wraps a Storage with injections.
func (s *InjectedStore) Begin() (Transaction, error)
Begin creates an injected Transaction.
func (s *InjectedStore) BeginWithStartTS(txnScope string, startTS uint64) (Transaction, error)
BeginWithStartTS creates an injected Transaction with startTS.
func (s *InjectedStore) GetSnapshot(ver Version) Snapshot
GetSnapshot creates an injected Snapshot.
type InjectedTransaction struct { Transaction // contains filtered or unexported fields }
InjectedTransaction wraps a Transaction with injections.
BatchGet returns an error if cfg.getError is set.
func (t *InjectedTransaction) Commit(ctx context.Context) error
Commit returns an error if cfg.commitError is set.
Get returns an error if cfg.getError is set.
InjectionConfig is used for fault injections for KV components.
func (c *InjectionConfig) SetCommitError(err error)
SetCommitError injects an error for all Transaction.Commit() methods.
func (c *InjectionConfig) SetGetError(err error)
SetGetError injects an error for all kv.Get() methods.
IntHandle implement the Handle interface for int64 type handle.
Compare implements the Handle interface.
Data implements the Handle interface.
Encoded implements the Handle interface.
EncodedCol implements the Handle interface., not supported for IntHandle type.
Equal implements the Handle interface.
IntValue implements the Handle interface.
IsInt implements the Handle interface.
Len implements the Handle interface.
Next implements the Handle interface.
NumCols implements the Handle interface, not supported for IntHandle type.
String implements the Handle interface.
IsoLevel is the transaction's isolation level.
const ( // SI stands for 'snapshot isolation'. SI IsoLevel = iota // RC stands for 'read committed'. RC )
Iterator is the interface for a iterator on KV store.
Key represents high-level Key type.
Clone returns a deep copy of the Key.
Cmp returns the comparison result of two key. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
HasPrefix tests whether the Key begins with prefix.
Next returns the next key in byte-order.
PrefixNext returns the next prefix key.
Assume there are keys like:
rowkey1 rowkey1_column1 rowkey1_column2 rowKey2
If we seek 'rowkey1' Next, we will get 'rowkey1_column1'. If we seek 'rowkey1' PrefixNext, we will get 'rowkey2'.
String implements fmt.Stringer interface.
KeyFlags are metadata associated with key
HasIgnoredIn2PC returns whether the key will be ignored in 2pc.
HasLocked returns whether the associated key has acquired pessimistic lock.
HasLockedValueExists returns whether the value exists when key locked.
HasNeedCheckExists returns whether the key need to check existence when it has been locked.
HasNeedLocked return whether the key needed to be locked
HasPresumeKeyNotExists returns whether the associated key use lazy check.
HasPrewriteOnly returns whether the key should be used in 2pc commit phase.
KeyRange represents a range where StartKey <= key < EndKey.
IsPoint checks if the key range represents a point.
type LockCtx struct { Killed *uint32 ForUpdateTS uint64 LockWaitTime int64 WaitStartTime time.Time PessimisticLockWaited *int32 LockKeysDuration *int64 LockKeysCount *int32 ReturnValues bool Values map[string]ReturnedValue ValuesLock sync.Mutex LockExpired *uint32 Stats *execdetails.LockKeysDetails }
LockCtx contains information for LockKeys method.
MPPBuildTasksRequest request the stores allocation for a mpp plan fragment. However, the request doesn't contain the particular plan, because only key ranges take effect on the location assignment.
type MPPClient interface { // ConstructMPPTasks schedules task for a plan fragment. // TODO:: This interface will be refined after we support more executors. ConstructMPPTasks(context.Context, *MPPBuildTasksRequest) ([]MPPTaskMeta, error) // DispatchMPPTasks dispatches ALL mpp requests at once, and returns an iterator that transfers the data. DispatchMPPTasks(context.Context, []*MPPDispatchRequest) Response }
MPPClient accepts and processes mpp requests.
type MPPDispatchRequest struct { Data []byte // data encodes the dag coprocessor request. Meta MPPTaskMeta // mpp store is the location of tiflash store. IsRoot bool // root task returns data to tidb directly. Timeout uint64 // If task is assigned but doesn't receive a connect request during timeout, the task should be destroyed. // SchemaVer is for any schema-ful storage (like tiflash) to validate schema correctness if necessary. SchemaVar int64 StartTs uint64 ID int64 // identify a single task }
MPPDispatchRequest stands for a dispatching task.
type MPPTask struct { Meta MPPTaskMeta // on which store this task will execute ID int64 // mppTaskID StartTs uint64 TableID int64 // physical table id }
MPPTask means the minimum execution unit of a mpp computation job.
ToPB generates the pb structure.
type MPPTaskMeta interface { // GetAddress indicates which node this task should execute on. GetAddress() string }
MPPTaskMeta means the meta info such as location of a mpp task.
type MemBuffer interface { RetrieverMutator // RLock locks the MemBuffer for shared read. // In the most case, MemBuffer will only used by single goroutine, // but it will be read by multiple goroutine when combined with executor.UnionScanExec. // To avoid race introduced by executor.UnionScanExec, MemBuffer expose read lock for it. RLock() // RUnlock unlocks the MemBuffer. RUnlock() // GetFlags returns the latest flags associated with key. GetFlags(Key) (KeyFlags, error) // IterWithFlags returns a MemBufferIterator. IterWithFlags(k Key, upperBound Key) MemBufferIterator // IterReverseWithFlags returns a reversed MemBufferIterator. IterReverseWithFlags(k Key) MemBufferIterator // SetWithFlags put key-value into the last active staging buffer with the given KeyFlags. SetWithFlags(Key, []byte, ...FlagsOp) error // UpdateFlags update the flags associated with key. UpdateFlags(Key, ...FlagsOp) // DeleteWithFlags delete key with the given KeyFlags DeleteWithFlags(Key, ...FlagsOp) error GetKeyByHandle(MemKeyHandle) []byte GetValueByHandle(MemKeyHandle) ([]byte, bool) // Reset reset the MemBuffer to initial states. Reset() // DiscardValues releases the memory used by all values. // NOTE: any operation need value will panic after this function. DiscardValues() // Staging create a new staging buffer inside the MemBuffer. // Subsequent writes will be temporarily stored in this new staging buffer. // When you think all modifications looks good, you can call `Release` to public all of them to the upper level buffer. Staging() StagingHandle // Release publish all modifications in the latest staging buffer to upper level. Release(StagingHandle) // Cleanup cleanup the resources referenced by the StagingHandle. // If the changes are not published by `Release`, they will be discarded. Cleanup(StagingHandle) // InspectStage used to inspect the value updates in the given stage. InspectStage(StagingHandle, func(Key, KeyFlags, []byte)) // SelectValueHistory select the latest value which makes `predicate` returns true from the modification history. SelectValueHistory(key Key, predicate func(value []byte) bool) ([]byte, error) // SnapshotGetter returns a Getter for a snapshot of MemBuffer. SnapshotGetter() Getter // SnapshotIter returns a Iterator for a snapshot of MemBuffer. SnapshotIter(k, upperbound Key) Iterator // Size returns sum of keys and values length. Size() int // Len returns the number of entries in the DB. Len() int // Dirty returns whether the root staging buffer is updated. Dirty() bool }
MemBuffer is an in-memory kv collection, can be used to buffer write operations.
type MemBufferIterator interface { Iterator HasValue() bool Flags() KeyFlags UpdateFlags(...FlagsOp) Handle() MemKeyHandle }
MemBufferIterator is an Iterator with KeyFlags related functions.
type MemKeyHandle struct { // Opaque user data UserData uint16 // contains filtered or unexported fields }
MemKeyHandle represents a pointer for key in MemBuffer.
type MemManager interface { // UnionGet gets the value from cacheDB first, if it not exists, // it gets the value from the snapshot, then caches the value in cacheDB. UnionGet(ctx context.Context, tid int64, snapshot Snapshot, key Key) ([]byte, error) // Delete releases the cache by tableID. Delete(tableID int64) }
MemManager adds a cache between transaction buffer and the storage to reduce requests to the storage. Beware, it uses table ID for partition tables, because the keys are unique for partition tables. no matter the physical IDs are the same or not.
func NewCacheDB() MemManager
NewCacheDB news the cacheDB.
type Mutator interface { // Set sets the value for key k as v into kv store. // v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue. Set(k Key, v []byte) error // Delete removes the entry for key k from kv store. Delete(k Key) error }
Mutator is the interface wraps the basic Set and Delete methods.
Option is used for customizing kv store's behaviors during a transaction.
const ( // BinlogInfo contains the binlog data and client. BinlogInfo Option = iota + 1 // SchemaChecker is used for checking schema-validity. SchemaChecker // IsolationLevel sets isolation level for current transaction. The default level is SI. IsolationLevel // Priority marks the priority of this transaction. Priority // NotFillCache makes this request do not touch the LRU cache of the underlying storage. NotFillCache // SyncLog decides whether the WAL(write-ahead log) of this request should be synchronized. SyncLog // KeyOnly retrieve only keys, it can be used in scan now. KeyOnly // Pessimistic is defined for pessimistic lock Pessimistic // SnapshotTS is defined to set snapshot ts. SnapshotTS // Set replica read ReplicaRead // Set task ID TaskID // InfoSchema is schema version used by txn startTS. InfoSchema // CollectRuntimeStats is used to enable collect runtime stats. CollectRuntimeStats // SchemaAmender is used to amend mutations for pessimistic transactions SchemaAmender // SampleStep skips 'SampleStep - 1' number of keys after each returned key. SampleStep // CommitHook is a callback function called right after the transaction gets committed CommitHook // EnableAsyncCommit indicates whether async commit is enabled EnableAsyncCommit // Enable1PC indicates whether one-phase commit is enabled Enable1PC // GuaranteeExternalConsistency indicates whether to guarantee external consistency at the cost of an extra tso request before prewrite GuaranteeExternalConsistency // TxnScope indicates which @@txn_scope this transaction will work with. TxnScope // StalenessReadOnly indicates whether the transaction is staleness read only transaction IsStalenessReadOnly )
Transaction options
Options is an interface of a set of options. Each option is associated with a value.
PartitionHandle combines a handle and a PartitionID, used to location a row in partioned table. Now only used in global index. TODO: support PartitionHandle in HandleMap.
func NewPartitionHandle(pid int64, h Handle) PartitionHandle
NewPartitionHandle creates a PartitionHandle from a normal handle and a pid.
func (ph PartitionHandle) Compare(h Handle) int
Compare implements the Handle interface.
func (ph PartitionHandle) Equal(h Handle) bool
Equal implements the Handle interface.
ReplicaReadType is the type of replica to read data from
const ( // ReplicaReadLeader stands for 'read from leader'. ReplicaReadLeader ReplicaReadType = 1 << iota // ReplicaReadFollower stands for 'read from follower'. ReplicaReadFollower // ReplicaReadMixed stands for 'read from leader and follower and learner'. ReplicaReadMixed )
func (r ReplicaReadType) IsFollowerRead() bool
IsFollowerRead checks if leader is going to be used to read data.
type Request struct { // Tp is the request type. Tp int64 StartTs uint64 Data []byte KeyRanges []KeyRange // Concurrency is 1, if it only sends the request to a single storage unit when // ResponseIterator.Next is called. If concurrency is greater than 1, the request will be // sent to multiple storage units concurrently. Concurrency int // IsolationLevel is the isolation level, default is SI. IsolationLevel IsoLevel // Priority is the priority of this KV request, its value may be PriorityNormal/PriorityLow/PriorityHigh. Priority int // memTracker is used to trace and control memory usage in co-processor layer. MemTracker *memory.Tracker // KeepOrder is true, if the response should be returned in order. KeepOrder bool // Desc is true, if the request is sent in descending order. Desc bool // NotFillCache makes this request do not touch the LRU cache of the underlying storage. NotFillCache bool // SyncLog decides whether the WAL(write-ahead log) of this request should be synchronized. SyncLog bool // Streaming indicates using streaming API for this request, result in that one Next() // call would not corresponds to a whole region result. Streaming bool // ReplicaRead is used for reading data from replicas, only follower is supported at this time. ReplicaRead ReplicaReadType // StoreType represents this request is sent to the which type of store. StoreType StoreType // Cacheable is true if the request can be cached. Currently only deterministic DAG requests can be cached. Cacheable bool // SchemaVer is for any schema-ful storage to validate schema correctness if necessary. SchemaVar int64 // BatchCop indicates whether send batch coprocessor request to tiflash. BatchCop bool // TaskID is an unique ID for an execution of a statement TaskID uint64 // TiDBServerID is the specified TiDB serverID to execute request. `0` means all TiDB instances. TiDBServerID uint64 }
Request represents a kv request.
type RequestTypeSupportedChecker struct{}
RequestTypeSupportedChecker is used to check expression can be pushed down.
func (d RequestTypeSupportedChecker) IsRequestTypeSupported(reqType, subType int64) bool
IsRequestTypeSupported checks whether reqType is supported.
type Response interface { // Next returns a resultSubset from a single storage unit. // When full result set is returned, nil is returned. Next(ctx context.Context) (resultSubset ResultSubset, err error) // Close response. Close() error }
Response represents the response returned from KV layer.
type ResultSubset interface { // GetData gets the data. GetData() []byte // GetStartKey gets the start key. GetStartKey() Key // MemSize returns how many bytes of memory this result use for tracing memory usage. MemSize() int64 // RespTime returns the response time for the request. RespTime() time.Duration }
ResultSubset represents a result subset from a single storage unit. TODO: Find a better interface for ResultSubset that can reuse bytes.
type Retriever interface { Getter // 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. Iter(k Key, upperBound Key) (Iterator, error) // IterReverse creates a reversed Iterator positioned on the first entry which key is less than k. // The returned iterator will iterate from greater key to smaller key. // If k is nil, the returned iterator will be positioned at the last key. // TODO: Add lower bound limit IterReverse(k Key) (Iterator, error) }
Retriever is the interface wraps the basic Get and Seek methods.
RetrieverMutator is the interface that groups Retriever and Mutator interfaces.
ReturnedValue pairs the Value and AlreadyLocked flag for PessimisticLock return values result.
type Snapshot interface { Retriever // BatchGet gets a batch of values from snapshot. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) // SetOption sets an option with a value, when val is nil, uses the default // value of this option. Only ReplicaRead is supported for snapshot SetOption(opt Option, val interface{}) // DelOption deletes an option. DelOption(opt Option) }
Snapshot defines the interface for the snapshot fetched from KV store.
type SplittableStore interface { SplitRegions(ctx context.Context, splitKey [][]byte, scatter bool, tableID *int64) (regionID []uint64, err error) WaitScatterRegionFinish(ctx context.Context, regionID uint64, backOff int) error CheckRegionInScattering(regionID uint64) (bool, error) }
SplittableStore is the kv store which supports split regions.
StagingHandle is the reference of a staging buffer.
var ( // InvalidStagingHandle is an invalid handler, MemBuffer will check handler to ensure safety. InvalidStagingHandle StagingHandle = 0 // LastActiveStagingHandle is an special handler which always point to the last active staging buffer. LastActiveStagingHandle StagingHandle = -1 )
type Storage interface { // Begin a global transaction Begin() (Transaction, error) // Begin a transaction with the given txnScope (local or global) BeginWithTxnScope(txnScope string) (Transaction, error) // BeginWithStartTS begins transaction with given txnScope and startTS. BeginWithStartTS(txnScope string, startTS uint64) (Transaction, error) // BeginWithStalenessTS begins transaction with given staleness BeginWithExactStaleness(txnScope string, prevSec uint64) (Transaction, error) // GetSnapshot gets a snapshot that is able to read any data which data is <= ver. // if ver is MaxVersion or > current max committed version, we will use current version for this snapshot. GetSnapshot(ver Version) Snapshot // GetClient gets a client instance. GetClient() Client // GetClient gets a mpp client instance. GetMPPClient() MPPClient // Close store Close() error // UUID return a unique ID which represents a Storage. UUID() string // CurrentVersion returns current max committed version with the given txnScope (local or global). CurrentVersion(txnScope string) (Version, error) // GetOracle gets a timestamp oracle client. GetOracle() oracle.Oracle // SupportDeleteRange gets the storage support delete range or not. SupportDeleteRange() (supported bool) // Name gets the name of the storage engine Name() string // Describe returns of brief introduction of the storage Describe() string // ShowStatus returns the specified status of the storage ShowStatus(ctx context.Context, key string) (interface{}, error) // GetMemCache return memory mamager of the storage GetMemCache() MemManager }
Storage defines the interface for storage. Isolation should be at least SI(SNAPSHOT ISOLATION)
func NewInjectedStore(store Storage, cfg *InjectionConfig) Storage
NewInjectedStore creates a InjectedStore with config.
StoreType represents the type of a store.
const ( // TiKV means the type of a store is TiKV. TiKV StoreType = iota // TiFlash means the type of a store is TiFlash. TiFlash // TiDB means the type of a store is TiDB. TiDB // UnSpecified means the store type is unknown UnSpecified = 255 )
Name returns the name of store type.
type Transaction interface { RetrieverMutator // Size returns sum of keys and values length. Size() int // Len returns the number of entries in the DB. Len() int // Reset reset the Transaction to initial states. Reset() // Commit commits the transaction operations to KV store. Commit(context.Context) error // Rollback undoes the transaction operations to KV store. Rollback() error // String implements fmt.Stringer interface. String() string // LockKeys tries to lock the entries with the keys in KV store. LockKeys(ctx context.Context, lockCtx *LockCtx, keys ...Key) error // SetOption sets an option with a value, when val is nil, uses the default // value of this option. SetOption(opt Option, val interface{}) // DelOption deletes an option. DelOption(opt Option) // IsReadOnly checks if the transaction has only performed read operations. IsReadOnly() bool // StartTS returns the transaction start timestamp. StartTS() uint64 // Valid returns if the transaction is valid. // A transaction become invalid after commit or rollback. Valid() bool // GetMemBuffer return the MemBuffer binding to this transaction. GetMemBuffer() MemBuffer // GetSnapshot returns the Snapshot binding to this transaction. GetSnapshot() Snapshot // GetUnionStore returns the UnionStore binding to this transaction. GetUnionStore() UnionStore // SetVars sets variables to the transaction. SetVars(vars *Variables) // GetVars gets variables from the transaction. GetVars() *Variables // BatchGet gets kv from the memory buffer of statement and transaction, and the kv storage. // Do not use len(value) == 0 or value == nil to represent non-exist. // If a key doesn't exist, there shouldn't be any corresponding entry in the result map. BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error) IsPessimistic() bool }
Transaction defines the interface for operations inside a Transaction. This is not thread safe.
type TxnInfo struct { TxnScope string `json:"txn_scope"` StartTS uint64 `json:"start_ts"` CommitTS uint64 `json:"commit_ts"` ErrMsg string `json:"error,omitempty"` }
TxnInfo is used to keep track the info of a committed transaction (mainly for diagnosis and testing)
type UnionIter struct {
// contains filtered or unexported fields
}
UnionIter is the iterator on an UnionStore.
NewUnionIter returns a union iterator for BufferStore.
Close implements the Iterator Close interface.
Key implements the Iterator Key interface.
Next implements the Iterator Next interface.
Valid implements the Iterator Valid interface.
Value implements the Iterator Value interface. Multi columns
type UnionStore interface { Retriever // HasPresumeKeyNotExists returns whether the key presumed key not exists error for the lazy check. HasPresumeKeyNotExists(k Key) bool // UnmarkPresumeKeyNotExists deletes the key presume key not exists error flag for the lazy check. UnmarkPresumeKeyNotExists(k Key) // CacheIndexName caches the index name. // PresumeKeyNotExists will use this to help decode error message. CacheTableInfo(id int64, info *model.TableInfo) // GetIndexName returns the cached index name. // If there is no such index already inserted through CacheIndexName, it will return UNKNOWN. GetTableInfo(id int64) *model.TableInfo // SetOption sets an option with a value, when val is nil, uses the default // value of this option. SetOption(opt Option, val interface{}) // DelOption deletes an option. DelOption(opt Option) // GetOption gets an option. GetOption(opt Option) interface{} // GetMemBuffer return the MemBuffer binding to this unionStore. GetMemBuffer() MemBuffer }
UnionStore is a store that wraps a snapshot for read and a MemBuffer for buffered write. Also, it provides some transaction related utilities.
func NewUnionStore(snapshot Snapshot) UnionStore
NewUnionStore builds a new unionStore.
type Variables struct { // BackoffLockFast specifies the LockFast backoff base duration in milliseconds. BackoffLockFast int // BackOffWeight specifies the weight of the max back off time duration. BackOffWeight int // Hook is used for test to verify the variable take effect. Hook func(name string, vars *Variables) // Pointer to SessionVars.Killed // Killed is a flag to indicate that this query is killed. Killed *uint32 }
Variables defines the variables used by KV storage.
NewVariables create a new Variables instance with default values.
Version is the wrapper of KV's version.
NewVersion creates a new Version struct.
Cmp returns the comparison result of two versions. The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
VersionProvider provides increasing IDs.
Package kv imports 32 packages (graph) and is imported by 1447 packages. Updated 2021-01-13. Refresh now. Tools for package owners.