Documentation ¶
Index ¶
- Constants
- Variables
- func CmpKey(k, another []byte) int
- func IsErrNotFound(err error) bool
- func IsRetryable(err error) bool
- func NextKey(k []byte) []byte
- func PrefixNextKey(k []byte) []byte
- func StrKey(k []byte) string
- func Txn(store Storage, fn func(txn Transaction) error) error
- func TxnContext(ctx context.Context, store Storage, ...) error
- type BatchGetter
- type Entry
- type ErrConflict
- type ErrEntryTooLarge
- type ErrGroup
- type ErrKeyAlreadyExist
- type ErrTxnTooLarge
- type FlagsOp
- type Getter
- type Iterator
- type Key
- type KeyFlags
- func (f KeyFlags) AndPersistent() KeyFlags
- func (f KeyFlags) HasAssertExist() bool
- func (f KeyFlags) HasAssertNotExist() bool
- func (f KeyFlags) HasAssertUnknown() bool
- func (f KeyFlags) HasAssertionFlags() bool
- func (f KeyFlags) HasIgnoredIn2PC() bool
- func (f KeyFlags) HasLocked() bool
- func (f KeyFlags) HasLockedValueExists() bool
- func (f KeyFlags) HasNeedCheckExists() bool
- func (f KeyFlags) HasNeedConstraintCheckInPrewrite() bool
- func (f KeyFlags) HasNeedLocked() bool
- func (f KeyFlags) HasNewlyInserted() bool
- func (f KeyFlags) HasPresumeKeyNotExists() bool
- func (f KeyFlags) HasPrewriteOnly() bool
- func (f KeyFlags) HasReadable() bool
- type KeyRange
- type Mutator
- type Pair
- type Retriever
- type RetrieverMutator
- type Snapshot
- type Storage
- type Transaction
- type Version
- type VersionPair
- type VersionProvider
Constants ¶
const DefTxnCommitBatchSize uint64 = 16 * 1024
DefTxnCommitBatchSize is the default value of TxnCommitBatchSize.
const (
// FlagBytes is the byte size of type KeyFlags
FlagBytes = 2
)
Variables ¶
var ( // ErrTxnConflicts indicates the current transaction contains some vertex/edge/index // conflicts with others. ErrTxnConflicts = errors.New("transaction conflicts") // ErrNotExist means the related data not exist. ErrNotExist = errors.New("not exist") // ErrCannotSetNilValue is the error when sets an empty value. ErrCannotSetNilValue = errors.New("can not set nil value") // ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction. ErrInvalidTxn = errors.New("invalid transaction") ErrInvalidStartVer = errors.New("invalid start timestamp for transaction") )
var ( // MaxVersion is the maximum version, notice that it's not a valid version. MaxVersion = Version(math.MaxUint64) // MinVersion is the minimum version, it's not a valid version, too. MinVersion = Version(0) )
var TxnCommitBatchSize atomic.Uint64
TxnCommitBatchSize controls the batch size of transaction commit related requests sent by client to TiKV, TiKV recommends each RPC packet should be less than ~1MB.
Functions ¶
func CmpKey ¶
CmpKey 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 IsErrNotFound ¶
func PrefixNextKey ¶
PrefixNextKey returns the next prefix key.
Assume there are keys like:
rowkey1 rowkey1_column1 rowkey1_column2 rowKey2
If we seek 'rowkey1' NextKey, we will get 'rowkey1_column1'. If we seek 'rowkey1' PrefixNextKey, we will get 'rowkey2'.
func Txn ¶
func Txn(store Storage, fn func(txn Transaction) error) error
Txn creates a new transaction and call the user-define transaction callback.
func TxnContext ¶
func TxnContext(ctx context.Context, store Storage, fn func(ctx context.Context, txn Transaction) error) error
TxnContext creates a new transaction and call the user-define transaction callback. The transaction will be committed automatically.
Types ¶
type BatchGetter ¶
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 ErrConflict ¶
type ErrConflict struct { StartVer Version ConflictStartVer Version ConflictCommitVer Version Key Key }
ErrConflict is returned when the commitTS of key in the DB is greater than startTS.
func (*ErrConflict) Error ¶
func (e *ErrConflict) Error() string
type ErrEntryTooLarge ¶
ErrEntryTooLarge is the error when a key value entry is too large.
func (*ErrEntryTooLarge) Error ¶
func (e *ErrEntryTooLarge) Error() string
type ErrGroup ¶
type ErrGroup struct {
Errors []error
}
ErrGroup is used to collect multiple errors.
type ErrKeyAlreadyExist ¶
type ErrKeyAlreadyExist struct {
Key []byte
}
ErrKeyAlreadyExist is returned when key exists but this key has a constraint that it should not exist. Client should return duplicated entry error.
func (*ErrKeyAlreadyExist) Error ¶
func (e *ErrKeyAlreadyExist) Error() string
type ErrTxnTooLarge ¶
type ErrTxnTooLarge struct {
Size int
}
ErrTxnTooLarge is the error when transaction is too large, lock time reached the maximum value.
func (*ErrTxnTooLarge) Error ¶
func (e *ErrTxnTooLarge) Error() string
type FlagsOp ¶
type FlagsOp uint32
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 // SetReadable marks the key is readable by in-transaction read. SetReadable // SetNewlyInserted marks the key is newly inserted with value length greater than zero. SetNewlyInserted // SetAssertExist marks the key must exist. SetAssertExist // SetAssertNotExist marks the key must not exist. SetAssertNotExist // SetAssertUnknown mark the key maybe exists or not exists. SetAssertUnknown // SetAssertNone cleans up the key's assert. SetAssertNone // SetNeedConstraintCheckInPrewrite marks the key needs to check conflict in prewrite. SetNeedConstraintCheckInPrewrite // DelNeedConstraintCheckInPrewrite reverts SetNeedConstraintCheckInPrewrite. This is required when we decide to // make up the pessimistic lock. DelNeedConstraintCheckInPrewrite // SetPreviousPresumeKNE sets flagPreviousPresumeKNE. SetPreviousPresumeKNE )
type Getter ¶
type Getter interface { // Get gets the value for key k from kv db. // 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 Key ¶
type Key []byte
Key represents high-level Key type.
func (Key) Cmp ¶
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) PrefixNext ¶
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'.
type KeyFlags ¶
type KeyFlags uint16
KeyFlags are metadata associated with key. Notice that the highest bit is used by red black tree, do not set flags on it.
func ApplyFlagsOps ¶
ApplyFlagsOps applys flagspos to origin.
func (KeyFlags) AndPersistent ¶
AndPersistent returns the value of current flags&persistentFlags
func (KeyFlags) HasAssertExist ¶
HasAssertExist returns whether the key need ensure exists in 2pc.
func (KeyFlags) HasAssertNotExist ¶
HasAssertNotExist returns whether the key need ensure non-exists in 2pc.
func (KeyFlags) HasAssertUnknown ¶
HasAssertUnknown returns whether the key is marked unable to do any assertion.
func (KeyFlags) HasAssertionFlags ¶
HasAssertionFlags returns whether the key's assertion is set.
func (KeyFlags) HasIgnoredIn2PC ¶
HasIgnoredIn2PC returns whether the key will be ignored in 2pc.
func (KeyFlags) HasLocked ¶
HasLocked returns whether the associated key has acquired pessimistic lock.
func (KeyFlags) HasLockedValueExists ¶
HasLockedValueExists returns whether the value exists when key locked.
func (KeyFlags) HasNeedCheckExists ¶
HasNeedCheckExists returns whether the key need to check existence when it has been locked.
func (KeyFlags) HasNeedConstraintCheckInPrewrite ¶
HasNeedConstraintCheckInPrewrite returns whether the key needs to check conflict in prewrite.
func (KeyFlags) HasNeedLocked ¶
HasNeedLocked return whether the key needed to be locked
func (KeyFlags) HasNewlyInserted ¶
HasNewlyInserted returns whether the in-transaction key is generated by an "insert" operation.
func (KeyFlags) HasPresumeKeyNotExists ¶
HasPresumeKeyNotExists returns whether the associated key use lazy check.
func (KeyFlags) HasPrewriteOnly ¶
HasPrewriteOnly returns whether the key should be used in 2pc commit phase.
func (KeyFlags) HasReadable ¶
HasReadable returns whether the in-transaction operations is able to read the key.
type KeyRange ¶
type KeyRange struct { StartKey Key EndKey Key XXXNoUnkeyedLiteral struct{} XXXunrecognized []byte XXXsizecache int32 }
KeyRange represents a range where StartKey <= key < EndKey. Hack: make the layout exactly the same with github.com/pingcap/kvproto/pkg/coprocessor.KeyRange So we can avoid allocation of converting kv.KeyRange to coprocessor.KeyRange Not defined as "type KeyRange = coprocessor.KeyRange" because their field name are different. kv.KeyRange use StartKey,EndKey while coprocessor.KeyRange use Start,End
type Mutator ¶
type Mutator interface { // Set sets the value for key k as v into kv db. // 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 db. Delete(k Key) error }
Mutator is the interface wraps the basic Set and Delete methods.
type Retriever ¶
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(lowerBound Key, upperBound Key) (Iterator, error) // IterReverse creates a reversed Iterator positioned on the first entry which key is less than k. // The returned SnapshotIter will iterate from greater key to smaller key. // If k is nil, the returned SnapshotIter will be positioned at the last key. IterReverse(lowerBound Key, upperBound Key) (Iterator, error) }
Retriever is the interface wraps the basic Get and Seek methods.
type RetrieverMutator ¶
RetrieverMutator is the interface that groups Retriever and Mutator interfaces.
type Snapshot ¶
type Snapshot interface { Retriever BatchGetter // StartVer returns the start verstion of the current snapshot. StartVer() Version }
Snapshot defines the interface for the snapshot fetched from KV db.
type Storage ¶
type Storage interface { VersionProvider Begin() (Transaction, error) Snapshot(ver Version) (Snapshot, error) Close() error }
type Transaction ¶
type Transaction interface { RetrieverMutator StartVer() Version // Snapshot returns the Snapshot binding to this transaction. Snapshot() Snapshot // 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) // 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 db. Commit(context.Context) error // Rollback undoes the transaction operations to KV db. Rollback() error // String implements fmt.Stringer interface. String() string }
type VersionPair ¶
type VersionProvider ¶
type VersionProvider interface {
CurrentVersion() Version
}
VersionProvider provides increasing IDs.