kv

package
v3.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const (
	DefBackoffLockFast = 10
	DefBackOffWeight   = 2
)

Default values

View Source
const DefTxnCommitBatchSize uint64 = 16 * 1024

DefTxnCommitBatchSize is the default value of TxnCommitBatchSize.

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.

View Source
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

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

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

func (f KeyFlags) HasAssertExist() bool

HasAssertExist returns whether the key need ensure exists in 2pc.

func (KeyFlags) HasAssertNotExist

func (f KeyFlags) HasAssertNotExist() bool

HasAssertNotExist returns whether the key need ensure non-exists in 2pc.

func (KeyFlags) HasAssertUnknown

func (f KeyFlags) HasAssertUnknown() bool

HasAssertUnknown returns whether the key is marked unable to do any assertion.

func (KeyFlags) HasAssertionFlags

func (f KeyFlags) HasAssertionFlags() bool

HasAssertionFlags returns whether the key's assertion is set.

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

func (f KeyFlags) HasNewlyInserted() bool

HasNewlyInserted returns whether the in-transaction key is generated by an "insert" operation.

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

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

func (ctx *LockCtx) InitCheckExistence(capacity int)

InitCheckExistence creates the map to store whether each key exists or not.

func (*LockCtx) InitReturnValues

func (ctx *LockCtx) InitReturnValues(capacity 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
	Exists        bool
	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