kv

package
v2.5.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockAlwaysWait = int64(math.MaxInt64)
	LockNoWait     = int64(0)
)

Used for pessimistic lock wait time these two constants are special for lock protocol with tikv math.MaxInt64 means always wait, 0 means nowait, others meaning lock wait in milliseconds

View Source
const (
	DefBackoffLockFast = 100
	DefBackOffWeight   = 2
)

Default values

View Source
const (
	// FlagBytes is the byte size of type KeyFlags
	FlagBytes = 2
)

Variables

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.

Functions

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:

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 StrKey

func StrKey(k []byte) string

StrKey returns string for key.

Types

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

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

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.

func (KeyFlags) HasReadable

func (f KeyFlags) HasReadable() bool

HasReadable returns whether the in-transaction operations is able to read the key.

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

	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)
	// contains filtered or unexported fields
}

LockCtx contains information for LockKeys method.

func NewLockCtx

func NewLockCtx(forUpdateTS uint64, lockWaitTime int64, waitStartTime time.Time) *LockCtx

NewLockCtx creates a LockCtx.

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.

func (*LockCtx) LockWaitTime

func (ctx *LockCtx) LockWaitTime() int64

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

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
y or Y : Canonical URL