Documentation ¶
Index ¶
- Constants
- Variables
- func CmpKey(k, another []byte) int
- func NextKey(k []byte) []byte
- func PrefixNextKey(k []byte) []byte
- func StrKey(k []byte) string
- type FlagsOp
- 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) 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 LockCtx
- type ReplicaReadType
- type ReturnedValue
- type Variables
Constants ¶
const ( LockAlwaysWait = int64(math.MaxInt64) LockNoWait = int64(-1) )
Used for pessimistic lock wait time these two constants are special for lock protocol with tikv math.MaxInt64 means always wait, -1 means nowait, 0 means the default wait duration in TiKV, others meaning lock wait in milliseconds
const ( DefBackoffLockFast = 10 DefBackOffWeight = 2 )
Default values
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 DefaultVars = NewVariables(&ignoreKill)
DefaultVars is the default variables instance.
var StoreLimit atomic.Int64
StoreLimit will update from config reload and global variable set.
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 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'.
Types ¶
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 )
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) 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 LockCtx ¶
type LockCtx struct { Killed *uint32 ForUpdateTS uint64 WaitStartTime time.Time PessimisticLockWaited *int32 LockKeysDuration *int64 LockKeysCount *int32 ReturnValues bool CheckExistence bool Values map[string]ReturnedValue ValuesLock sync.Mutex LockExpired *uint32 Stats *util.LockKeysDetails ResourceGroupTag []byte // ResourceGroupTagger is a special tagger used only for PessimisticLockRequest. // We did not use tikvrpc.ResourceGroupTagger here because the kv package is a // more basic component, and we cannot rely on tikvrpc.Request here, so we treat // LockCtx specially. ResourceGroupTagger func(*kvrpcpb.PessimisticLockRequest) []byte OnDeadlock func(*tikverr.ErrDeadlock) // contains filtered or unexported fields }
LockCtx contains information for LockKeys method.
func NewLockCtx ¶
NewLockCtx creates a LockCtx.
func (*LockCtx) GetValueNotLocked ¶
GetValueNotLocked returns a value if the key is not already locked. (nil, false) means already locked.
func (*LockCtx) InitCheckExistence ¶
InitCheckExistence creates the map to store whether each key exists or not.
func (*LockCtx) InitReturnValues ¶
InitReturnValues creates the map to store returned value.
func (*LockCtx) IterateValuesNotLocked ¶
IterateValuesNotLocked applies f to all key-values that are not already locked.
func (*LockCtx) LockWaitTime ¶
LockWaitTime returns lockWaitTimeInMs
type ReplicaReadType ¶
type ReplicaReadType byte
ReplicaReadType is the type of replica to read data from
const ( // ReplicaReadLeader stands for 'read from leader'. ReplicaReadLeader ReplicaReadType = iota // ReplicaReadFollower stands for 'read from follower'. ReplicaReadFollower // ReplicaReadMixed stands for 'read from leader and follower and learner'. ReplicaReadMixed )
func (ReplicaReadType) IsFollowerRead ¶
func (r ReplicaReadType) IsFollowerRead() bool
IsFollowerRead checks if follower is going to be used to read data.
type ReturnedValue ¶
ReturnedValue pairs the Value and AlreadyLocked flag for PessimisticLock return values result.
type Variables ¶
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 // 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 ¶
NewVariables create a new Variables instance with default values.