Version: v2.0.0-alpha Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 5




View Source
const (
	DefBackoffLockFast = 100
	DefBackOffWeight   = 2

Default values


View Source
var DefaultVars = NewVariables(&ignoreKill)

DefaultVars is the default variables instance.

View Source
var StoreLimit atomic.Int64

StoreLimit will update from config reload and global variable set.


func CmpKey

func CmpKey(k, another []byte) int

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 NextKey

func NextKey(k []byte) []byte

NextKey returns the next key in byte-order.

func PrefixNextKey

func PrefixNextKey(k []byte) []byte

PrefixNextKey returns the next prefix key.

Assume there are keys like:


If we seek 'rowkey1' NextKey, we will get 'rowkey1_column1'. If we seek 'rowkey1' PrefixNextKey, we will get 'rowkey2'.

func StrKey

func StrKey(k []byte) string

StrKey returns string for key.


type FlagsOp

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.
	// SetKeyLocked marks the associated key has acquired lock.
	// DelKeyLocked reverts SetKeyLocked.
	// SetNeedLocked marks the associated key need to be acquired lock.
	// DelNeedLocked reverts SetKeyNeedLocked.
	// SetKeyLockedValueExists marks the value exists when key has been locked in Transaction.LockKeys.
	// SetKeyLockedValueNotExists marks the value doesn't exists when key has been locked in Transaction.LockKeys.
	// DelNeedCheckExists marks the key no need to be checked in Transaction.LockKeys.
	// SetPrewriteOnly marks the key shouldn't be used in 2pc commit phase.
	// SetIgnoredIn2PC marks the key will be ignored in 2pc.

type KeyFlags

type KeyFlags uint8

KeyFlags are metadata associated with key

func ApplyFlagsOps

func ApplyFlagsOps(origin KeyFlags, ops ...FlagsOp) KeyFlags

ApplyFlagsOps applys flagspos to origin.

func (KeyFlags) AndPersistent

func (f KeyFlags) AndPersistent() KeyFlags

AndPersistent returns the value of current flags&persistentFlags

func (KeyFlags) HasIgnoredIn2PC

func (f KeyFlags) HasIgnoredIn2PC() bool

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

func (KeyFlags) HasLocked

func (f KeyFlags) HasLocked() bool

HasLocked returns whether the associated key has acquired pessimistic lock.

func (KeyFlags) HasLockedValueExists

func (f KeyFlags) HasLockedValueExists() bool

HasLockedValueExists returns whether the value exists when key locked.

func (KeyFlags) HasNeedCheckExists

func (f KeyFlags) HasNeedCheckExists() bool

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

func (KeyFlags) HasNeedLocked

func (f KeyFlags) HasNeedLocked() bool

HasNeedLocked return whether the key needed to be locked

func (KeyFlags) HasPresumeKeyNotExists

func (f KeyFlags) HasPresumeKeyNotExists() bool

HasPresumeKeyNotExists returns whether the associated key use lazy check.

func (KeyFlags) HasPrewriteOnly

func (f KeyFlags) HasPrewriteOnly() bool

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

type KeyRange

type KeyRange struct {
	StartKey []byte
	EndKey   []byte

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

type LockCtx

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                 *util.LockKeysDetails
	ResourceGroupTag      []byte
	OnDeadlock            func(*tikverr.ErrDeadlock)

LockCtx contains information for LockKeys method.

func (*LockCtx) GetValueNotLocked

func (ctx *LockCtx) GetValueNotLocked(key []byte) ([]byte, bool)

GetValueNotLocked returns a value if the key is not already locked. (nil, false) means already locked.

func (*LockCtx) InitReturnValues

func (ctx *LockCtx) InitReturnValues(valueLen int)

InitReturnValues creates the map to store returned value.

func (*LockCtx) IterateValuesNotLocked

func (ctx *LockCtx) IterateValuesNotLocked(f func([]byte, []byte))

IterateValuesNotLocked applies f to all key-values that are not already locked.

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'.
	// ReplicaReadMixed stands for 'read from leader and follower and learner'.

func (ReplicaReadType) IsFollowerRead

func (r ReplicaReadType) IsFollowerRead() bool

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

type ReturnedValue

type ReturnedValue struct {
	Value         []byte
	AlreadyLocked bool

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

func NewVariables(killed *uint32) *Variables

NewVariables create a new Variables instance with default values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL