tidb: github.com/pingcap/tidb/kv Index | Files

package kv

import "github.com/pingcap/tidb/kv"

Index

Package Files

checker.go error.go fault_injection.go iter.go key.go kv.go memdb.go memdb_arena.go memdb_iterator.go memdb_snapshot.go txn.go union_iter.go union_store.go utils.go variables.go version.go

Constants

const (
    PriorityNormal = iota
    PriorityLow
    PriorityHigh
)

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.

const UnCommitIndexKVFlag byte = '1'

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.

Variables

var (
    // ErrNotExist is used when try to get an entry with an unexist key from KV store.
    ErrNotExist = terror.ClassKV.New(mysql.ErrNotExist, mysql.MySQLErrName[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 = terror.ClassKV.New(mysql.ErrTxnRetryable,
        mysql.MySQLErrName[mysql.ErrTxnRetryable]+TxnRetryableMark)
    // ErrCannotSetNilValue is the error when sets an empty value.
    ErrCannotSetNilValue = terror.ClassKV.New(mysql.ErrCannotSetNilValue, mysql.MySQLErrName[mysql.ErrCannotSetNilValue])
    // ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction.
    ErrInvalidTxn = terror.ClassKV.New(mysql.ErrInvalidTxn, mysql.MySQLErrName[mysql.ErrInvalidTxn])
    // ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value.
    ErrTxnTooLarge = terror.ClassKV.New(mysql.ErrTxnTooLarge, mysql.MySQLErrName[mysql.ErrTxnTooLarge])
    // ErrEntryTooLarge is the error when a key value entry is too large.
    ErrEntryTooLarge = terror.ClassKV.New(mysql.ErrEntryTooLarge, mysql.MySQLErrName[mysql.ErrEntryTooLarge])
    // ErrKeyExists returns when key is already exist.
    ErrKeyExists = redact.NewRedactError(terror.ClassKV.New(mysql.ErrDupEntry, mysql.MySQLErrName[mysql.ErrDupEntry]), 0, 1)
    // ErrNotImplemented returns when a function is not implemented yet.
    ErrNotImplemented = terror.ClassKV.New(mysql.ErrNotImplemented, mysql.MySQLErrName[mysql.ErrNotImplemented])
    // ErrWriteConflict is the error when the commit meets an write conflict error.
    ErrWriteConflict = terror.ClassKV.New(mysql.ErrWriteConflict,
        mysql.MySQLErrName[mysql.ErrWriteConflict]+" "+TxnRetryableMark)
    // ErrWriteConflictInTiDB is the error when the commit meets an write conflict error when local latch is enabled.
    ErrWriteConflictInTiDB = terror.ClassKV.New(mysql.ErrWriteConflictInTiDB,
        mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB]+" "+TxnRetryableMark)
)
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.

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

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.

func BackOff Uses

func BackOff(attempts uint) int

BackOff Implements exponential backoff with full jitter. Returns real back off time in microsecond. See http://www.awsarchitectureblog.com/2015/03/backoff.html.

func GetDuplicateErrorHandleString Uses

func GetDuplicateErrorHandleString(handle Handle) string

GetDuplicateErrorHandleString is used to concat the handle columns data with '-'. This is consistent with MySQL.

func GetInt64 Uses

func GetInt64(ctx context.Context, r Retriever, k Key) (int64, error)

GetInt64 get int64 value which created by IncInt64 method.

func IncInt64 Uses

func IncInt64(rm RetrieverMutator, k Key, step int64) (int64, error)

IncInt64 increases the value for key k in kv store by step.

func IsErrNotFound Uses

func IsErrNotFound(err error) bool

IsErrNotFound checks if err is a kind of NotFound error.

func IsMockCommitErrorEnable Uses

func IsMockCommitErrorEnable() bool

IsMockCommitErrorEnable exports for gofail testing.

func IsTombstone Uses

func IsTombstone(val []byte) bool

IsTombstone returns whether the value is a tombstone.

func IsTxnRetryableError Uses

func IsTxnRetryableError(err error) bool

IsTxnRetryableError checks if the error could safely retry the transaction.

func MockCommitErrorDisable Uses

func MockCommitErrorDisable()

MockCommitErrorDisable exports for gofail testing.

func MockCommitErrorEnable Uses

func MockCommitErrorEnable()

MockCommitErrorEnable exports for gofail testing.

func NextUntil Uses

func NextUntil(it Iterator, fn FnKeyCmp) error

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 Uses

func RunInNewTxn(store Storage, retryable bool, f func(txn Transaction) error) error

RunInNewTxn will run the f in a new transaction environment.

func WalkMemBuffer Uses

func WalkMemBuffer(memBuf Retriever, f func(k Key, v []byte) error) error

WalkMemBuffer iterates all buffered kv pairs in memBuf

type AssertionType Uses

type AssertionType int

AssertionType is the type of a assertion.

const (
    None AssertionType = iota
    Exist
    NotExist
)

The AssertionType constants.

type BatchGetter Uses

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 Uses

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

BufferBatchGetter is the type for BatchGet with MemBuffer.

func NewBufferBatchGetter Uses

func NewBufferBatchGetter(buffer MemBuffer, middleCache Getter, snapshot Snapshot) *BufferBatchGetter

NewBufferBatchGetter creates a new BufferBatchGetter.

func (*BufferBatchGetter) BatchGet Uses

func (b *BufferBatchGetter) BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error)

BatchGet implements the BatchGetter interface.

type Client Uses

type Client interface {
    // Send sends request to KV layer, returns a Response.
    Send(ctx context.Context, req *Request, vars *Variables, sessionMemTracker *memory.Tracker) 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 Uses

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

CommonHandle implements the Handle interface for non-int64 type handle.

func NewCommonHandle Uses

func NewCommonHandle(encoded []byte) (*CommonHandle, error)

NewCommonHandle creates a CommonHandle from a encoded bytes which is encoded by code.EncodeKey.

func (*CommonHandle) Compare Uses

func (ch *CommonHandle) Compare(h Handle) int

Compare implements the Handle interface.

func (*CommonHandle) Data Uses

func (ch *CommonHandle) Data() ([]types.Datum, error)

Data implements the Handle interface.

func (*CommonHandle) Encoded Uses

func (ch *CommonHandle) Encoded() []byte

Encoded implements the Handle interface.

func (*CommonHandle) EncodedCol Uses

func (ch *CommonHandle) EncodedCol(idx int) []byte

EncodedCol implements the Handle interface.

func (*CommonHandle) Equal Uses

func (ch *CommonHandle) Equal(h Handle) bool

Equal implements the Handle interface.

func (*CommonHandle) IntValue Uses

func (ch *CommonHandle) IntValue() int64

IntValue implements the Handle interface, not supported for CommonHandle type.

func (*CommonHandle) IsInt Uses

func (ch *CommonHandle) IsInt() bool

IsInt implements the Handle interface.

func (*CommonHandle) Len Uses

func (ch *CommonHandle) Len() int

Len implements the Handle interface.

func (*CommonHandle) Next Uses

func (ch *CommonHandle) Next() Handle

Next implements the Handle interface.

func (*CommonHandle) NumCols Uses

func (ch *CommonHandle) NumCols() int

NumCols implements the Handle interface.

func (*CommonHandle) String Uses

func (ch *CommonHandle) String() string

String implements the Handle interface.

type Driver Uses

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.

type FlagsOp Uses

type FlagsOp uint16

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

type FnKeyCmp Uses

type FnKeyCmp func(key Key) bool

FnKeyCmp is the function for iterator the keys

type Getter Uses

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 Uses

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 Uses

func BuildHandleFromDatumRow(sctx *stmtctx.StatementContext, row []types.Datum, handleOrdinals []int) (Handle, error)

BuildHandleFromDatumRow builds kv.Handle from cols in row.

type HandleMap Uses

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

HandleMap is the map for Handle.

func NewHandleMap Uses

func NewHandleMap() *HandleMap

NewHandleMap creates a new map for handle.

func (*HandleMap) Delete Uses

func (m *HandleMap) Delete(h Handle)

Delete deletes a entry from the map.

func (*HandleMap) Get Uses

func (m *HandleMap) Get(h Handle) (v interface{}, ok bool)

Get gets a value by a Handle.

func (*HandleMap) Len Uses

func (m *HandleMap) Len() int

Len returns the length of the map.

func (*HandleMap) Range Uses

func (m *HandleMap) Range(fn func(h Handle, val interface{}) bool)

Range iterates the HandleMap with fn, the fn returns true to continue, returns false to stop.

func (*HandleMap) Set Uses

func (m *HandleMap) Set(h Handle, val interface{})

Set sets a value with a Handle.

type InjectedSnapshot Uses

type InjectedSnapshot struct {
    Snapshot
    // contains filtered or unexported fields
}

InjectedSnapshot wraps a Snapshot with injections.

func (*InjectedSnapshot) BatchGet Uses

func (t *InjectedSnapshot) BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error)

BatchGet returns an error if cfg.getError is set.

func (*InjectedSnapshot) Get Uses

func (t *InjectedSnapshot) Get(ctx context.Context, k Key) ([]byte, error)

Get returns an error if cfg.getError is set.

type InjectedStore Uses

type InjectedStore struct {
    Storage
    // contains filtered or unexported fields
}

InjectedStore wraps a Storage with injections.

func (*InjectedStore) Begin Uses

func (s *InjectedStore) Begin() (Transaction, error)

Begin creates an injected Transaction.

func (*InjectedStore) BeginWithStartTS Uses

func (s *InjectedStore) BeginWithStartTS(startTS uint64) (Transaction, error)

BeginWithStartTS creates an injected Transaction with startTS.

func (*InjectedStore) GetSnapshot Uses

func (s *InjectedStore) GetSnapshot(ver Version) (Snapshot, error)

GetSnapshot creates an injected Snapshot.

type InjectedTransaction Uses

type InjectedTransaction struct {
    Transaction
    // contains filtered or unexported fields
}

InjectedTransaction wraps a Transaction with injections.

func (*InjectedTransaction) BatchGet Uses

func (t *InjectedTransaction) BatchGet(ctx context.Context, keys []Key) (map[string][]byte, error)

BatchGet returns an error if cfg.getError is set.

func (*InjectedTransaction) Commit Uses

func (t *InjectedTransaction) Commit(ctx context.Context) error

Commit returns an error if cfg.commitError is set.

func (*InjectedTransaction) Get Uses

func (t *InjectedTransaction) Get(ctx context.Context, k Key) ([]byte, error)

Get returns an error if cfg.getError is set.

type InjectionConfig Uses

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

InjectionConfig is used for fault injections for KV components.

func (*InjectionConfig) SetCommitError Uses

func (c *InjectionConfig) SetCommitError(err error)

SetCommitError injects an error for all Transaction.Commit() methods.

func (*InjectionConfig) SetGetError Uses

func (c *InjectionConfig) SetGetError(err error)

SetGetError injects an error for all kv.Get() methods.

type IntHandle Uses

type IntHandle int64

IntHandle implement the Handle interface for int64 type handle.

func (IntHandle) Compare Uses

func (ih IntHandle) Compare(h Handle) int

Compare implements the Handle interface.

func (IntHandle) Data Uses

func (ih IntHandle) Data() ([]types.Datum, error)

Data implements the Handle interface.

func (IntHandle) Encoded Uses

func (ih IntHandle) Encoded() []byte

Encoded implements the Handle interface.

func (IntHandle) EncodedCol Uses

func (ih IntHandle) EncodedCol(idx int) []byte

EncodedCol implements the Handle interface., not supported for IntHandle type.

func (IntHandle) Equal Uses

func (ih IntHandle) Equal(h Handle) bool

Equal implements the Handle interface.

func (IntHandle) IntValue Uses

func (ih IntHandle) IntValue() int64

IntValue implements the Handle interface.

func (IntHandle) IsInt Uses

func (ih IntHandle) IsInt() bool

IsInt implements the Handle interface.

func (IntHandle) Len Uses

func (ih IntHandle) Len() int

Len implements the Handle interface.

func (IntHandle) Next Uses

func (ih IntHandle) Next() Handle

Next implements the Handle interface.

func (IntHandle) NumCols Uses

func (ih IntHandle) NumCols() int

NumCols implements the Handle interface, not supported for IntHandle type.

func (IntHandle) String Uses

func (ih IntHandle) String() string

String implements the Handle interface.

type IsoLevel Uses

type IsoLevel int

IsoLevel is the transaction's isolation level.

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

type Iterator Uses

type Iterator interface {
    Valid() bool
    Key() Key
    Value() []byte
    Next() error
    Close()
}

Iterator is the interface for a iterator on KV store.

type Key Uses

type Key []byte

Key represents high-level Key type.

func (Key) Clone Uses

func (k Key) Clone() Key

Clone returns a deep copy of the Key.

func (Key) Cmp Uses

func (k Key) Cmp(another Key) int

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.

func (Key) HasPrefix Uses

func (k Key) HasPrefix(prefix Key) bool

HasPrefix tests whether the Key begins with prefix.

func (Key) Next Uses

func (k Key) Next() Key

Next returns the next key in byte-order.

func (Key) PrefixNext Uses

func (k Key) PrefixNext() Key

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

func (Key) String Uses

func (k Key) String() string

String implements fmt.Stringer interface.

type KeyFlags Uses

type KeyFlags uint8

KeyFlags are metadata associated with key

func (KeyFlags) HasIgnoredIn2PC Uses

func (f KeyFlags) HasIgnoredIn2PC() bool

HasIgnoredIn2PC returns whether the key will be ignored in 2pc.

func (KeyFlags) HasLocked Uses

func (f KeyFlags) HasLocked() bool

HasLocked returns whether the associated key has acquired pessimistic lock.

func (KeyFlags) HasLockedValueExists Uses

func (f KeyFlags) HasLockedValueExists() bool

HasLockedValueExists returns whether the value exists when key locked.

func (KeyFlags) HasNeedCheckExists Uses

func (f KeyFlags) HasNeedCheckExists() bool

HasNeedCheckExists returns whether the key need to check existence when it has been locked.

func (KeyFlags) HasPresumeKeyNotExists Uses

func (f KeyFlags) HasPresumeKeyNotExists() bool

HasPresumeKeyNotExists returns whether the associated key use lazy check.

func (KeyFlags) HasPrewriteOnly Uses

func (f KeyFlags) HasPrewriteOnly() bool

HasPrewriteOnly returns whether the key should be used in 2pc commit phase.

type KeyRange Uses

type KeyRange struct {
    StartKey Key
    EndKey   Key
}

KeyRange represents a range where StartKey <= key < EndKey.

func (*KeyRange) IsPoint Uses

func (r *KeyRange) IsPoint() bool

IsPoint checks if the key range represents a point.

type LockCtx Uses

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.

type MemBuffer Uses

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)

    // 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 Uses

type MemBufferIterator interface {
    Iterator
    HasValue() bool
    Flags() KeyFlags
    UpdateFlags(...FlagsOp)
}

MemBufferIterator is an Iterator with KeyFlags related functions.

type Mutator Uses

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.

type Option Uses

type Option int

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
)

Transaction options

type Options Uses

type Options interface {
    // Get gets an option value.
    Get(opt Option) (v interface{}, ok bool)
}

Options is an interface of a set of options. Each option is associated with a value.

type PartitionHandle Uses

type PartitionHandle struct {
    Handle
    PartitionID int64
}

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 Uses

func NewPartitionHandle(pid int64, h Handle) PartitionHandle

NewPartitionHandle creates a PartitionHandle from a normal handle and a pid.

func (PartitionHandle) Compare Uses

func (ph PartitionHandle) Compare(h Handle) int

Compare implements the Handle interface.

func (PartitionHandle) Equal Uses

func (ph PartitionHandle) Equal(h Handle) bool

Equal implements the Handle interface.

type ReplicaReadType Uses

type ReplicaReadType byte

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 (ReplicaReadType) IsFollowerRead Uses

func (r ReplicaReadType) IsFollowerRead() bool

IsFollowerRead checks if leader is going to be used to read data.

type Request Uses

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
}

Request represents a kv request.

type RequestTypeSupportedChecker Uses

type RequestTypeSupportedChecker struct{}

RequestTypeSupportedChecker is used to check expression can be pushed down.

func (RequestTypeSupportedChecker) IsRequestTypeSupported Uses

func (d RequestTypeSupportedChecker) IsRequestTypeSupported(reqType, subType int64) bool

IsRequestTypeSupported checks whether reqType is supported.

type Response Uses

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 Uses

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 Uses

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.

type RetrieverMutator Uses

type RetrieverMutator interface {
    Retriever
    Mutator
}

RetrieverMutator is the interface that groups Retriever and Mutator interfaces.

type ReturnedValue Uses

type ReturnedValue struct {
    Value         []byte
    AlreadyLocked bool
}

ReturnedValue pairs the Value and AlreadyLocked flag for PessimisticLock return values result.

type Snapshot Uses

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 Uses

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.

type StagingHandle Uses

type StagingHandle int

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 Uses

type Storage interface {
    // Begin transaction
    Begin() (Transaction, error)
    // BeginWithStartTS begins transaction with startTS.
    BeginWithStartTS(startTS 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, error)
    // GetClient gets a client instance.
    GetClient() Client
    // Close store
    Close() error
    // UUID return a unique ID which represents a Storage.
    UUID() string
    // CurrentVersion returns current max committed version.
    CurrentVersion() (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)
}

Storage defines the interface for storage. Isolation should be at least SI(SNAPSHOT ISOLATION)

func NewInjectedStore Uses

func NewInjectedStore(store Storage, cfg *InjectionConfig) Storage

NewInjectedStore creates a InjectedStore with config.

type StoreType Uses

type StoreType uint8

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
)

func (StoreType) Name Uses

func (t StoreType) Name() string

Name returns the name of store type.

type Transaction Uses

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 Uses

type TxnInfo struct {
    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 Uses

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

UnionIter is the iterator on an UnionStore.

func NewUnionIter Uses

func NewUnionIter(dirtyIt Iterator, snapshotIt Iterator, reverse bool) (*UnionIter, error)

NewUnionIter returns a union iterator for BufferStore.

func (*UnionIter) Close Uses

func (iter *UnionIter) Close()

Close implements the Iterator Close interface.

func (*UnionIter) Key Uses

func (iter *UnionIter) Key() Key

Key implements the Iterator Key interface.

func (*UnionIter) Next Uses

func (iter *UnionIter) Next() error

Next implements the Iterator Next interface.

func (*UnionIter) Valid Uses

func (iter *UnionIter) Valid() bool

Valid implements the Iterator Valid interface.

func (*UnionIter) Value Uses

func (iter *UnionIter) Value() []byte

Value implements the Iterator Value interface. Multi columns

type UnionStore Uses

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 Uses

func NewUnionStore(snapshot Snapshot) UnionStore

NewUnionStore builds a new unionStore.

type Variables Uses

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.

func NewVariables Uses

func NewVariables(killed *uint32) *Variables

NewVariables create a new Variables instance with default values.

type Version Uses

type Version struct {
    Ver uint64
}

Version is the wrapper of KV's version.

func NewVersion Uses

func NewVersion(v uint64) Version

NewVersion creates a new Version struct.

func (Version) Cmp Uses

func (v Version) Cmp(another Version) int

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.

type VersionProvider Uses

type VersionProvider interface {
    CurrentVersion() (Version, error)
}

VersionProvider provides increasing IDs.

Package kv imports 29 packages (graph) and is imported by 1423 packages. Updated 2020-09-27. Refresh now. Tools for package owners.