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

package kv

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


Package Files

buffer_store.go checker.go error.go fault_injection.go iter.go key.go kv.go memdb_buffer.go mock.go txn.go union_iter.go union_store.go utils.go variables.go version.go


const (
    PriorityNormal = iota

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


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.


var (
    // DefaultTxnMembufCap is the default transaction membuf capability.
    DefaultTxnMembufCap = 4 * 1024
    // TempTxnMemBufCap is the capability of temporary membuf.
    TempTxnMemBufCap = 64
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,
    // 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 = terror.ClassKV.New(mysql.ErrDupEntry, mysql.MySQLErrName[mysql.ErrDupEntry])
    // 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 = 6 * 1024 * 1024
    // 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()

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

func NewExistErrInfo(idxName string, value string) *existErrInfo

NewExistErrInfo is used to new an existErrInfo

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 MemBuffer, 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

The AssertionType constants.

type BufferStore Uses

type BufferStore struct {
    // contains filtered or unexported fields

BufferStore wraps a Retriever for read and a MemBuffer for buffered write. Common usage pattern:

bs := NewBufferStore(r) // use BufferStore to wrap a Retriever
// ...
// read/write on bs
// ...
bs.SaveTo(m)	        // save above operations to a Mutator

func NewBufferStore Uses

func NewBufferStore(r Retriever, cap int) *BufferStore

NewBufferStore creates a BufferStore using r for read.

func (*BufferStore) Get Uses

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

Get implements the Retriever interface.

func (*BufferStore) Iter Uses

func (s *BufferStore) Iter(k Key, upperBound Key) (Iterator, error)

Iter implements the Retriever interface.

func (*BufferStore) IterReverse Uses

func (s *BufferStore) IterReverse(k Key) (Iterator, error)

IterReverse implements the Retriever interface.

func (*BufferStore) Reset Uses

func (s *BufferStore) Reset()

Reset resets s.MemBuffer.

func (*BufferStore) SaveTo Uses

func (s *BufferStore) SaveTo(m Mutator) error

SaveTo saves all buffered kv pairs into a Mutator.

func (*BufferStore) SetCap Uses

func (s *BufferStore) SetCap(cap int)

SetCap sets the MemBuffer capability.

func (*BufferStore) WalkBuffer Uses

func (s *BufferStore) WalkBuffer(f func(k Key, v []byte) error) error

WalkBuffer iterates all buffered kv pairs.

type Client Uses

type Client interface {
    // Send sends request to KV layer, returns a Response.
    Send(ctx context.Context, req *Request, vars *Variables) Response

    // IsRequestTypeSupported checks if reqType and subType is supported.
    IsRequestTypeSupported(reqType, subType int64) bool

Client is used to send request to KV layer.

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

type FnKeyCmp func(key Key) bool

FnKeyCmp is the function for iterator the keys

type InjectedSnapshot Uses

type InjectedSnapshot struct {
    // 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 {
    // 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 {
    // 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 {
    // 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 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'.

type Iterator Uses

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

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:


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 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      *time.Duration

LockCtx contains information for LockKeys method.

type MemBuffer Uses

type MemBuffer interface {
    // Size returns sum of keys and values length.
    Size() int
    // Len returns the number of entries in the DB.
    Len() int
    // Reset cleanup the MemBuffer
    // SetCap sets the MemBuffer capability, to reduce memory allocations.
    // Please call it before you use the MemBuffer, otherwise it will not works.
    SetCap(cap int)

MemBuffer is an in-memory kv collection, can be used to buffer write operations.

func NewMemDbBuffer Uses

func NewMemDbBuffer(initBlockSize int) MemBuffer

NewMemDbBuffer creates a new memDbBuffer.

type MockTxn Uses

type MockTxn interface {
    GetOption(opt Option) interface{}

MockTxn is used for test cases that need more interfaces than Transaction.

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 (
    // PresumeKeyNotExists indicates that when dealing with a Get operation but failing to read data from cache,
    // we presume that the key does not exist in Store. The actual existence will be checked before the
    // transaction's commit.
    // This option is an optimization for frequent checks during a transaction, e.g. batch inserts.
    PresumeKeyNotExists Option = iota + 1
    // PresumeKeyNotExistsError is the option key for error.
    // When PresumeKeyNotExists is set and condition is not match, should throw the error.
    // BinlogInfo contains the binlog data and client.
    // SchemaChecker is used for checking schema-validity.
    // IsolationLevel sets isolation level for current transaction. The default level is SI.
    // Priority marks the priority of this transaction.
    // NotFillCache makes this request do not touch the LRU cache of the underlying storage.
    // SyncLog decides whether the WAL(write-ahead log) of this request should be synchronized.
    // KeyOnly retrieve only keys, it can be used in scan now.
    // Pessimistic is defined for pessimistic lock
    // SnapshotTS is defined to set snapshot ts.
    // Set replica read

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 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'.
    // ReplicaReadLearner stands for 'read from learner'.

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

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
    // GetExecDetails gets the detail information.
    GetExecDetails() *execdetails.ExecDetails
    // 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 {
    // 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)
    // 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 {

RetrieverMutator is the interface that groups Retriever and Mutator interfaces.

type Snapshot Uses

type Snapshot interface {
    // 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) (regionID []uint64, err error)
    WaitScatterRegionFinish(regionID uint64, backOff int) error
    CheckRegionInScattering(regionID uint64) (bool, error)

SplittableStore is the kv store which supports split regions.

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.

func NewMockStorage Uses

func NewMockStorage() Storage

NewMockStorage creates a new mockStorage.

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.
    // TiDB means the type of a store is TiDB.

func (StoreType) Name Uses

func (t StoreType) Name() string

Name returns the name of store type.

type Transaction Uses

type Transaction interface {
    // 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
    // SetVars sets variables to the transaction.
    SetVars(vars *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.

func NewMockTxn Uses

func NewMockTxn() Transaction

NewMockTxn new a mockTxn.

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 {
    // GetKeyExistErrInfo gets the key exist error info for the lazy check.
    GetKeyExistErrInfo(k Key) *existErrInfo
    // DeleteKeyExistErrInfo deletes the key exist error info for the lazy check.
    DeleteKeyExistErrInfo(k Key)
    // WalkBuffer iterates all buffered kv pairs.
    WalkBuffer(f func(k Key, v []byte) error) 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)
    // 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 BufferStore 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)

Variables defines the variables used by KV storage.

func NewVariables Uses

func NewVariables() *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 20 packages (graph) and is imported by 1399 packages. Updated 2020-01-09. Refresh now. Tools for package owners.