transaction

package
v2.0.0-...-d47a232 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const CommitSecondaryMaxBackoff = 41000

CommitSecondaryMaxBackoff is max sleep time of the 'commit' command

View Source
const MaxTxnTimeUse = 24 * 60 * 60 * 1000

MaxTxnTimeUse is the max time a Txn may use (in ms) from its begin to commit. We use it to abort the transaction to guarantee GC worker will not influence it.

View Source
const (

	// TsoMaxBackoff is the max sleep time to get tso.
	TsoMaxBackoff = 15000
)

Variables

View Source
var (
	// PrewriteMaxBackoff is max sleep time of the `pre-write` command.
	PrewriteMaxBackoff = atomicutil.NewUint64(40000)
	// CommitMaxBackoff is max sleep time of the 'commit' command
	CommitMaxBackoff = uint64(40000)
)
View Source
var (
	ManagedLockTTL uint64 = 20000 // 20s
)

Global variable set by config file.

View Source
var SetSuccess = false

SetSuccess is used to probe if kv variables are set or not. It is ONLY used in test cases.

Functions

func SendTxnHeartBeat

func SendTxnHeartBeat(bo *retry.Backoffer, store kvstore, primary []byte, startTS, ttl uint64) (newTTL uint64, stopHeartBeat bool, err error)

SendTxnHeartBeat renews a txn's ttl.

Types

type BatchBufferGetter

type BatchBufferGetter interface {
	Len() int
	unionstore.Getter
}

BatchBufferGetter is the interface for BatchGet.

type BatchGetter

type BatchGetter interface {
	// BatchGet gets a batch of values.
	BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)
}

BatchGetter is the interface for BatchGet.

type BinlogExecutor

type BinlogExecutor interface {
	Prewrite(ctx context.Context, primary []byte) <-chan BinlogWriteResult
	Commit(ctx context.Context, commitTS int64)
	Skip()
}

BinlogExecutor defines the logic to replicate binlogs during transaction commit.

type BinlogWriteResult

type BinlogWriteResult interface {
	Skipped() bool
	GetError() error
}

BinlogWriteResult defines the result of prewrite binlog.

type BufferBatchGetter

type BufferBatchGetter struct {
	// contains filtered or unexported fields
}

BufferBatchGetter is the type for BatchGet with MemBuffer.

func NewBufferBatchGetter

func NewBufferBatchGetter(buffer BatchBufferGetter, snapshot BatchGetter) *BufferBatchGetter

NewBufferBatchGetter creates a new BufferBatchGetter.

func (*BufferBatchGetter) BatchGet

func (b *BufferBatchGetter) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)

BatchGet gets a batch of values.

type CommitterMutationFlags

type CommitterMutationFlags uint8

CommitterMutationFlags represents various bit flags of mutations.

const (
	// MutationFlagIsPessimisticLock is the flag that marks a mutation needs to be pessimistic-locked.
	MutationFlagIsPessimisticLock CommitterMutationFlags = 1 << iota

	// MutationFlagIsAssertExists is the flag that marks a mutation needs to be asserted to be existed when prewriting.
	MutationFlagIsAssertExists

	// MutationFlagIsAssertNotExists is the flag that marks a mutation needs to be asserted to be not-existed when prewriting.
	MutationFlagIsAssertNotExists

	// MutationFlagNeedConstraintCheckInPrewrite is the flag that marks a mutation needs to be checked for conflicts in prewrite.
	MutationFlagNeedConstraintCheckInPrewrite
)

type CommitterMutations

type CommitterMutations interface {
	Len() int
	GetKey(i int) []byte
	GetKeys() [][]byte
	GetOp(i int) kvrpcpb.Op
	GetValue(i int) []byte
	IsPessimisticLock(i int) bool
	Slice(from, to int) CommitterMutations
	IsAssertExists(i int) bool
	IsAssertNotExist(i int) bool
	NeedConstraintCheckInPrewrite(i int) bool
}

CommitterMutations contains the mutations to be submitted.

type CommitterProbe

type CommitterProbe struct {
	// contains filtered or unexported fields
}

CommitterProbe wraps a 2PC committer and exports internal states for testing purpose.

func (CommitterProbe) BuildPrewriteRequest

func (c CommitterProbe) BuildPrewriteRequest(regionID, regionConf, regionVersion uint64, mutations CommitterMutations, txnSize uint64) *tikvrpc.Request

BuildPrewriteRequest builds rpc request for mutation.

func (CommitterProbe) CheckAsyncCommit

func (c CommitterProbe) CheckAsyncCommit() bool

CheckAsyncCommit returns if async commit is available.

func (CommitterProbe) Cleanup

func (c CommitterProbe) Cleanup(ctx context.Context)

Cleanup cleans dirty data of a committer.

func (CommitterProbe) CleanupMutations

func (c CommitterProbe) CleanupMutations(ctx context.Context) error

CleanupMutations performs the clean up phase.

func (CommitterProbe) CloseTTLManager

func (c CommitterProbe) CloseTTLManager()

CloseTTLManager closes the TTL manager.

func (CommitterProbe) CommitMutations

func (c CommitterProbe) CommitMutations(ctx context.Context) error

CommitMutations performs the second phase of commit.

func (CommitterProbe) Execute

func (c CommitterProbe) Execute(ctx context.Context) error

Execute runs the commit process.

func (CommitterProbe) GetCommitTS

func (c CommitterProbe) GetCommitTS() uint64

GetCommitTS returns the commit ts of the committer.

func (CommitterProbe) GetForUpdateTS

func (c CommitterProbe) GetForUpdateTS() uint64

GetForUpdateTS returns the pessimistic ForUpdate ts.

func (CommitterProbe) GetLockTTL

func (c CommitterProbe) GetLockTTL() uint64

GetLockTTL returns the lock ttl duration of the transaction.

func (CommitterProbe) GetMinCommitTS

func (c CommitterProbe) GetMinCommitTS() uint64

GetMinCommitTS returns the minimal commit ts can be used.

func (CommitterProbe) GetMutations

func (c CommitterProbe) GetMutations() CommitterMutations

GetMutations returns the mutation buffer to commit.

func (CommitterProbe) GetOnePCCommitTS

func (c CommitterProbe) GetOnePCCommitTS() uint64

GetOnePCCommitTS returns the commit ts of one pc.

func (CommitterProbe) GetPrimaryKey

func (c CommitterProbe) GetPrimaryKey() []byte

GetPrimaryKey returns primary key of the committer.

func (CommitterProbe) GetStartTS

func (c CommitterProbe) GetStartTS() uint64

GetStartTS returns the start ts of the transaction.

func (CommitterProbe) GetUndeterminedErr

func (c CommitterProbe) GetUndeterminedErr() error

GetUndeterminedErr returns the encountered undetermined error (if any).

func (CommitterProbe) InitKeysAndMutations

func (c CommitterProbe) InitKeysAndMutations() error

InitKeysAndMutations prepares the committer for commit.

func (CommitterProbe) IsAsyncCommit

func (c CommitterProbe) IsAsyncCommit() bool

IsAsyncCommit returns if the committer uses async commit.

func (CommitterProbe) IsOnePC

func (c CommitterProbe) IsOnePC() bool

IsOnePC returns if the committer is using one PC.

func (CommitterProbe) IsTTLRunning

func (c CommitterProbe) IsTTLRunning() bool

IsTTLRunning returns if the TTL manager is running state.

func (CommitterProbe) IsTTLUninitialized

func (c CommitterProbe) IsTTLUninitialized() bool

IsTTLUninitialized returns if the TTL manager is uninitialized.

func (CommitterProbe) MutationsOfKeys

func (c CommitterProbe) MutationsOfKeys(keys [][]byte) CommitterMutations

MutationsOfKeys returns mutations match the keys.

func (CommitterProbe) PessimisticRollbackMutations

func (c CommitterProbe) PessimisticRollbackMutations(ctx context.Context, muts CommitterMutations) error

PessimisticRollbackMutations rolls mutations back.

func (CommitterProbe) PrewriteAllMutations

func (c CommitterProbe) PrewriteAllMutations(ctx context.Context) error

PrewriteAllMutations performs the first phase of commit.

func (CommitterProbe) PrewriteMutations

func (c CommitterProbe) PrewriteMutations(ctx context.Context, mutations CommitterMutations) error

PrewriteMutations performs the first phase of commit for given keys.

func (CommitterProbe) SetCommitTS

func (c CommitterProbe) SetCommitTS(ts uint64)

SetCommitTS resets the committer's commit ts.

func (CommitterProbe) SetDiskFullOpt

func (c CommitterProbe) SetDiskFullOpt(level kvrpcpb.DiskFullOpt)

func (CommitterProbe) SetForUpdateTS

func (c CommitterProbe) SetForUpdateTS(ts uint64)

SetForUpdateTS sets pessimistic ForUpdate ts.

func (CommitterProbe) SetLockTTL

func (c CommitterProbe) SetLockTTL(ttl uint64)

SetLockTTL sets the lock ttl duration.

func (CommitterProbe) SetLockTTLByTimeAndSize

func (c CommitterProbe) SetLockTTLByTimeAndSize(start time.Time, size int)

SetLockTTLByTimeAndSize sets the lock ttl duration by time and size.

func (CommitterProbe) SetMaxCommitTS

func (c CommitterProbe) SetMaxCommitTS(ts uint64)

SetMaxCommitTS sets the max commit ts can be used.

func (CommitterProbe) SetMinCommitTS

func (c CommitterProbe) SetMinCommitTS(ts uint64)

SetMinCommitTS sets the minimal commit ts can be used.

func (CommitterProbe) SetMutations

func (c CommitterProbe) SetMutations(muts CommitterMutations)

SetMutations replace the mutation buffer.

func (CommitterProbe) SetNoFallBack

func (c CommitterProbe) SetNoFallBack()

SetNoFallBack disallows async commit to fall back to normal mode.

func (CommitterProbe) SetPrimaryKey

func (c CommitterProbe) SetPrimaryKey(key []byte)

SetPrimaryKey resets the committer's commit ts.

func (CommitterProbe) SetPrimaryKeyBlocker

func (c CommitterProbe) SetPrimaryKeyBlocker(ac, bk chan struct{})

SetPrimaryKeyBlocker is used to block committer after primary is sent.

func (CommitterProbe) SetSessionID

func (c CommitterProbe) SetSessionID(id uint64)

SetSessionID sets the session id of the committer.

func (CommitterProbe) SetTxnSize

func (c CommitterProbe) SetTxnSize(sz int)

SetTxnSize resets the txn size of the committer and updates lock TTL.

func (CommitterProbe) SetUseAsyncCommit

func (c CommitterProbe) SetUseAsyncCommit()

SetUseAsyncCommit enables async commit feature.

func (CommitterProbe) WaitCleanup

func (c CommitterProbe) WaitCleanup()

WaitCleanup waits for the committer to complete.

type ConfigProbe

type ConfigProbe struct{}

ConfigProbe exposes configurations and global variables for testing purpose.

func (ConfigProbe) GetDefaultLockTTL

func (c ConfigProbe) GetDefaultLockTTL() uint64

GetDefaultLockTTL returns the default lock TTL.

func (ConfigProbe) GetPessimisticLockMaxBackoff

func (c ConfigProbe) GetPessimisticLockMaxBackoff() int

GetPessimisticLockMaxBackoff returns pessimisticLockMaxBackoff

func (ConfigProbe) GetTTLFactor

func (c ConfigProbe) GetTTLFactor() int

GetTTLFactor returns the factor to calculate txn TTL.

func (ConfigProbe) GetTxnCommitBatchSize

func (c ConfigProbe) GetTxnCommitBatchSize() uint64

GetTxnCommitBatchSize returns the batch size to commit txn.

func (ConfigProbe) LoadPreSplitDetectThreshold

func (c ConfigProbe) LoadPreSplitDetectThreshold() uint32

LoadPreSplitDetectThreshold returns presplit detect threshold config.

func (ConfigProbe) LoadPreSplitSizeThreshold

func (c ConfigProbe) LoadPreSplitSizeThreshold() uint32

LoadPreSplitSizeThreshold returns presplit size threshold config.

func (ConfigProbe) StorePreSplitDetectThreshold

func (c ConfigProbe) StorePreSplitDetectThreshold(v uint32)

StorePreSplitDetectThreshold updates presplit detect threshold config.

func (ConfigProbe) StorePreSplitSizeThreshold

func (c ConfigProbe) StorePreSplitSizeThreshold(v uint32)

StorePreSplitSizeThreshold updates presplit size threshold config.

type KVFilter

type KVFilter interface {
	// IsUnnecessaryKeyValue returns whether this KV pair should be committed.
	IsUnnecessaryKeyValue(key, value []byte, flags kv.KeyFlags) (bool, error)
}

KVFilter is a filter that filters out unnecessary KV pairs.

type KVTxn

type KVTxn struct {
	*util.RequestSource
	// contains filtered or unexported fields
}

KVTxn contains methods to interact with a TiKV transaction.

func NewTiKVTxn

func NewTiKVTxn(store kvstore, snapshot *txnsnapshot.KVSnapshot, startTS uint64, options *TxnOptions) (*KVTxn, error)

NewTiKVTxn creates a new KVTxn.

func (*KVTxn) AddRPCInterceptor

func (txn *KVTxn) AddRPCInterceptor(it interceptor.RPCInterceptor)

AddRPCInterceptor adds an interceptor, the order of addition is the order of execution.

func (*KVTxn) BatchGet

func (txn *KVTxn) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)

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.

func (*KVTxn) ClearDiskFullOpt

func (txn *KVTxn) ClearDiskFullOpt()

ClearDiskFullOpt clears the options of current operation in each tikv disk usage level.

func (*KVTxn) Commit

func (txn *KVTxn) Commit(ctx context.Context) error

Commit commits the transaction operations to KV store.

func (*KVTxn) Delete

func (txn *KVTxn) Delete(k []byte) error

Delete removes the entry for key k from kv store.

func (*KVTxn) EnableForceSyncLog

func (txn *KVTxn) EnableForceSyncLog()

EnableForceSyncLog indicates tikv to always sync log for the transaction.

func (*KVTxn) Get

func (txn *KVTxn) Get(ctx context.Context, k []byte) ([]byte, error)

Get implements transaction interface.

func (*KVTxn) GetClusterID

func (txn *KVTxn) GetClusterID() uint64

GetClusterID returns store's cluster id.

func (*KVTxn) GetDiskFullOpt

func (txn *KVTxn) GetDiskFullOpt() kvrpcpb.DiskFullOpt

GetDiskFullOpt gets the options of current operation in each TiKV disk usage level.

func (*KVTxn) GetMemBuffer

func (txn *KVTxn) GetMemBuffer() *unionstore.MemDB

GetMemBuffer return the MemBuffer binding to this transaction.

func (*KVTxn) GetScope

func (txn *KVTxn) GetScope() string

GetScope returns the geographical scope of the transaction.

func (*KVTxn) GetSnapshot

func (txn *KVTxn) GetSnapshot() *txnsnapshot.KVSnapshot

GetSnapshot returns the Snapshot binding to this transaction.

func (*KVTxn) GetUnionStore

func (txn *KVTxn) GetUnionStore() *unionstore.KVUnionStore

GetUnionStore returns the UnionStore binding to this transaction.

func (*KVTxn) GetVars

func (txn *KVTxn) GetVars() *tikv.Variables

GetVars gets variables from the transaction.

func (*KVTxn) IsCasualConsistency

func (txn *KVTxn) IsCasualConsistency() bool

IsCasualConsistency returns if the transaction allows linearizability inconsistency.

func (*KVTxn) IsPessimistic

func (txn *KVTxn) IsPessimistic() bool

IsPessimistic returns true if it is pessimistic.

func (*KVTxn) IsReadOnly

func (txn *KVTxn) IsReadOnly() bool

IsReadOnly checks if the transaction has only performed read operations.

func (*KVTxn) Iter

func (txn *KVTxn) Iter(k []byte, upperBound []byte) (unionstore.Iterator, error)

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.

func (*KVTxn) IterReverse

func (txn *KVTxn) IterReverse(k []byte) (unionstore.Iterator, error)

IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.

func (*KVTxn) Len

func (txn *KVTxn) Len() int

Len returns the number of entries in the DB.

func (*KVTxn) LockKeys

func (txn *KVTxn) LockKeys(ctx context.Context, lockCtx *tikv.LockCtx, keysInput ...[]byte) error

LockKeys tries to lock the entries with the keys in KV store. lockCtx is the context for lock, lockCtx.lockWaitTime in ms

func (*KVTxn) LockKeysWithWaitTime

func (txn *KVTxn) LockKeysWithWaitTime(ctx context.Context, lockWaitTime int64, keysInput ...[]byte) (err error)

LockKeysWithWaitTime tries to lock the entries with the keys in KV store. lockWaitTime in ms, 0 means nowait lock.

func (*KVTxn) Mem

func (txn *KVTxn) Mem() uint64

Mem returns the current memory footprint

func (*KVTxn) Reset

func (txn *KVTxn) Reset()

Reset reset the Transaction to initial states.

func (*KVTxn) Rollback

func (txn *KVTxn) Rollback() error

Rollback undoes the transaction operations to KV store.

func (*KVTxn) Set

func (txn *KVTxn) Set(k []byte, v []byte) error

Set sets the value for key k as v into kv store. v must NOT be nil or empty, otherwise it returns ErrCannotSetNilValue.

func (*KVTxn) SetAssertionLevel

func (txn *KVTxn) SetAssertionLevel(assertionLevel kvrpcpb.AssertionLevel)

SetAssertionLevel sets how strict the assertions in the transaction should be.

func (*KVTxn) SetBinlogExecutor

func (txn *KVTxn) SetBinlogExecutor(binlog BinlogExecutor)

SetBinlogExecutor sets the method to perform binlong synchronization.

func (*KVTxn) SetCausalConsistency

func (txn *KVTxn) SetCausalConsistency(b bool)

SetCausalConsistency indicates if the transaction does not need to guarantee linearizability. Default value is false which means linearizability is guaranteed.

func (*KVTxn) SetCommitCallback

func (txn *KVTxn) SetCommitCallback(f func(string, error))

SetCommitCallback sets up a function that will be called when the transaction is finished.

func (*KVTxn) SetCommitTSUpperBoundCheck

func (txn *KVTxn) SetCommitTSUpperBoundCheck(f func(commitTS uint64) bool)

SetCommitTSUpperBoundCheck provide a way to restrict the commit TS upper bound. The 2PC processing will pass the commitTS for the checker function, if the function returns false, the 2PC processing will abort.

func (*KVTxn) SetDiskFullOpt

func (txn *KVTxn) SetDiskFullOpt(level kvrpcpb.DiskFullOpt)

SetDiskFullOpt sets whether current operation is allowed in each TiKV disk usage level.

func (*KVTxn) SetEnable1PC

func (txn *KVTxn) SetEnable1PC(b bool)

SetEnable1PC indicates that the transaction will try to use 1 phase commit(which should be faster). 1PC does not work if the keys to update in the current txn are in multiple regions.

func (*KVTxn) SetEnableAsyncCommit

func (txn *KVTxn) SetEnableAsyncCommit(b bool)

SetEnableAsyncCommit indicates if the transaction will try to use async commit.

func (*KVTxn) SetKVFilter

func (txn *KVTxn) SetKVFilter(filter KVFilter)

SetKVFilter sets the filter to ignore key-values in memory buffer.

func (*KVTxn) SetMemoryFootprintChangeHook

func (txn *KVTxn) SetMemoryFootprintChangeHook(hook func(uint64))

SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows

func (*KVTxn) SetPessimistic

func (txn *KVTxn) SetPessimistic(b bool)

SetPessimistic indicates if the transaction should use pessimictic lock.

func (*KVTxn) SetPriority

func (txn *KVTxn) SetPriority(pri txnutil.Priority)

SetPriority sets the priority for both write and read.

func (*KVTxn) SetRPCInterceptor

func (txn *KVTxn) SetRPCInterceptor(it interceptor.RPCInterceptor)

SetRPCInterceptor sets interceptor.RPCInterceptor for the transaction and its related snapshot. interceptor.RPCInterceptor will be executed before each RPC request is initiated. Note that SetRPCInterceptor will replace the previously set interceptor.

func (*KVTxn) SetRequestSourceInternal

func (txn *KVTxn) SetRequestSourceInternal(internal bool)

SetRequestSourceInternal sets the scope of the request source.

func (*KVTxn) SetRequestSourceType

func (txn *KVTxn) SetRequestSourceType(tp string)

SetRequestSourceType sets the type of the request source.

func (*KVTxn) SetResourceGroupTag

func (txn *KVTxn) SetResourceGroupTag(tag []byte)

SetResourceGroupTag sets the resource tag for both write and read.

func (*KVTxn) SetResourceGroupTagger

func (txn *KVTxn) SetResourceGroupTagger(tagger tikvrpc.ResourceGroupTagger)

SetResourceGroupTagger sets the resource tagger for both write and read. Before sending the request, if resourceGroupTag is not nil, use resourceGroupTag directly, otherwise use resourceGroupTagger.

func (*KVTxn) SetSchemaAmender

func (txn *KVTxn) SetSchemaAmender(sa SchemaAmender)

SetSchemaAmender sets an amender to update mutations after schema change.

func (*KVTxn) SetSchemaLeaseChecker

func (txn *KVTxn) SetSchemaLeaseChecker(checker SchemaLeaseChecker)

SetSchemaLeaseChecker sets a hook to check schema version.

func (*KVTxn) SetSchemaVer

func (txn *KVTxn) SetSchemaVer(schemaVer SchemaVer)

SetSchemaVer updates schema version to validate transaction.

func (*KVTxn) SetScope

func (txn *KVTxn) SetScope(scope string)

SetScope sets the geographical scope of the transaction.

func (*KVTxn) SetVars

func (txn *KVTxn) SetVars(vars *tikv.Variables)

SetVars sets variables to the transaction.

func (*KVTxn) Size

func (txn *KVTxn) Size() int

Size returns sum of keys and values length.

func (*KVTxn) StartTS

func (txn *KVTxn) StartTS() uint64

StartTS returns the transaction start timestamp.

func (*KVTxn) String

func (txn *KVTxn) String() string

String implements fmt.Stringer interface.

func (*KVTxn) Valid

func (txn *KVTxn) Valid() bool

Valid returns if the transaction is valid. A transaction become invalid after commit or rollback.

type MemBufferMutationsProbe

type MemBufferMutationsProbe struct {
	// contains filtered or unexported fields
}

MemBufferMutationsProbe exports memBufferMutations for test purposes.

func NewMemBufferMutationsProbe

func NewMemBufferMutationsProbe(sizeHint int, storage *unionstore.MemDB) MemBufferMutationsProbe

NewMemBufferMutationsProbe creates a new memBufferMutations instance for testing purpose.

func (MemBufferMutationsProbe) GetKey

func (m MemBufferMutationsProbe) GetKey(i int) []byte

func (MemBufferMutationsProbe) GetKeys

func (m MemBufferMutationsProbe) GetKeys() [][]byte

func (MemBufferMutationsProbe) GetOp

func (m MemBufferMutationsProbe) GetOp(i int) kvrpcpb.Op

func (MemBufferMutationsProbe) GetValue

func (m MemBufferMutationsProbe) GetValue(i int) []byte

func (MemBufferMutationsProbe) IsAssertExists

func (m MemBufferMutationsProbe) IsAssertExists(i int) bool

func (MemBufferMutationsProbe) IsAssertNotExist

func (m MemBufferMutationsProbe) IsAssertNotExist(i int) bool

func (MemBufferMutationsProbe) IsPessimisticLock

func (m MemBufferMutationsProbe) IsPessimisticLock(i int) bool

func (MemBufferMutationsProbe) Len

func (m MemBufferMutationsProbe) Len() int

func (MemBufferMutationsProbe) NeedConstraintCheckInPrewrite

func (m MemBufferMutationsProbe) NeedConstraintCheckInPrewrite(i int) bool

func (MemBufferMutationsProbe) Push

func (m MemBufferMutationsProbe) Push(op kvrpcpb.Op, isPessimisticLock, assertExist, assertNotExist, NeedConstraintCheckInPrewrite bool,
	handle unionstore.MemKeyHandle)

func (MemBufferMutationsProbe) Slice

func (m MemBufferMutationsProbe) Slice(from, to int) CommitterMutations

type PlainMutation

type PlainMutation struct {
	KeyOp kvrpcpb.Op
	Key   []byte
	Value []byte
	Flags CommitterMutationFlags
}

PlainMutation represents a single transaction operation.

type PlainMutations

type PlainMutations struct {
	// contains filtered or unexported fields
}

PlainMutations contains transaction operations.

func NewPlainMutations

func NewPlainMutations(sizeHint int) PlainMutations

NewPlainMutations creates a PlainMutations object with sizeHint reserved.

func (*PlainMutations) AppendMutation

func (c *PlainMutations) AppendMutation(mutation PlainMutation)

AppendMutation merges a single Mutation into the current mutations.

func (*PlainMutations) GetFlags

func (c *PlainMutations) GetFlags() []CommitterMutationFlags

GetFlags returns the flags on the mutations.

func (*PlainMutations) GetKey

func (c *PlainMutations) GetKey(i int) []byte

GetKey returns the key at index.

func (*PlainMutations) GetKeys

func (c *PlainMutations) GetKeys() [][]byte

GetKeys returns the keys.

func (*PlainMutations) GetOp

func (c *PlainMutations) GetOp(i int) kvrpcpb.Op

GetOp returns the key op at index.

func (*PlainMutations) GetOps

func (c *PlainMutations) GetOps() []kvrpcpb.Op

GetOps returns the key ops.

func (*PlainMutations) GetValue

func (c *PlainMutations) GetValue(i int) []byte

GetValue returns the key value at index.

func (*PlainMutations) GetValues

func (c *PlainMutations) GetValues() [][]byte

GetValues returns the key values.

func (*PlainMutations) IsAssertExists

func (c *PlainMutations) IsAssertExists(i int) bool

IsAssertExists returns the key assertExist flag at index.

func (*PlainMutations) IsAssertNotExist

func (c *PlainMutations) IsAssertNotExist(i int) bool

IsAssertNotExist returns the key assertNotExist flag at index.

func (*PlainMutations) IsPessimisticLock

func (c *PlainMutations) IsPessimisticLock(i int) bool

IsPessimisticLock returns the key pessimistic flag at index.

func (*PlainMutations) Len

func (c *PlainMutations) Len() int

Len returns the count of mutations.

func (*PlainMutations) MergeMutations

func (c *PlainMutations) MergeMutations(mutations PlainMutations)

MergeMutations append input mutations into current mutations.

func (*PlainMutations) NeedConstraintCheckInPrewrite

func (c *PlainMutations) NeedConstraintCheckInPrewrite(i int) bool

NeedConstraintCheckInPrewrite returns the key NeedConstraintCheckInPrewrite flag at index.

func (*PlainMutations) Push

func (c *PlainMutations) Push(op kvrpcpb.Op, key []byte, value []byte, isPessimisticLock, assertExist,
	assertNotExist, NeedConstraintCheckInPrewrite bool)

Push another mutation into mutations.

func (*PlainMutations) Slice

func (c *PlainMutations) Slice(from, to int) CommitterMutations

Slice return a sub mutations in range [from, to).

type RelatedSchemaChange

type RelatedSchemaChange struct {
	PhyTblIDS        []int64
	ActionTypes      []uint64
	LatestInfoSchema SchemaVer
	Amendable        bool
}

RelatedSchemaChange contains information about schema diff between two schema versions.

type SchemaAmender

type SchemaAmender interface {
	// AmendTxn is the amend entry, new mutations will be generated based on input mutations using schema change info.
	// The returned results are mutations need to prewrite and mutations need to cleanup.
	AmendTxn(ctx context.Context, startInfoSchema SchemaVer, change *RelatedSchemaChange, mutations CommitterMutations) (CommitterMutations, error)
}

SchemaAmender is used by pessimistic transactions to amend commit mutations for schema change during 2pc.

type SchemaLeaseChecker

type SchemaLeaseChecker interface {
	// CheckBySchemaVer checks if the schema has changed for the transaction related tables between the startSchemaVer
	// and the schema version at txnTS, all the related schema changes will be returned.
	CheckBySchemaVer(txnTS uint64, startSchemaVer SchemaVer) (*RelatedSchemaChange, error)
}

SchemaLeaseChecker is used to validate schema version is not changed during transaction execution.

type SchemaVer

type SchemaVer interface {
	// SchemaMetaVersion returns the meta schema version.
	SchemaMetaVersion() int64
}

SchemaVer is the infoSchema which will return the schema version.

type TxnInfo

type TxnInfo struct {
	TxnScope            string `json:"txn_scope"`
	StartTS             uint64 `json:"start_ts"`
	CommitTS            uint64 `json:"commit_ts"`
	TxnCommitMode       string `json:"txn_commit_mode"`
	AsyncCommitFallback bool   `json:"async_commit_fallback"`
	OnePCFallback       bool   `json:"one_pc_fallback"`
	ErrMsg              string `json:"error,omitempty"`
}

TxnInfo is used to keep track the info of a committed transaction (mainly for diagnosis and testing)

type TxnOptions

type TxnOptions struct {
	TxnScope                  string
	StartTS                   *uint64
	MemoryFootprintChangeHook func(uint64)
}

TxnOptions indicates the option when beginning a transaction. TxnOptions are set by the TxnOption values passed to Begin

type TxnProbe

type TxnProbe struct {
	*KVTxn
}

TxnProbe wraps a txn and exports internal states for testing purpose.

func (TxnProbe) BatchGetSingleRegion

func (txn TxnProbe) BatchGetSingleRegion(bo *retry.Backoffer, region locate.RegionVerID, keys [][]byte, collect func([]byte, []byte)) error

BatchGetSingleRegion gets a batch of keys from a region.

func (TxnProbe) CollectLockedKeys

func (txn TxnProbe) CollectLockedKeys() [][]byte

CollectLockedKeys returns all locked keys of a transaction.

func (TxnProbe) GetCommitTS

func (txn TxnProbe) GetCommitTS() uint64

GetCommitTS returns the commit ts.

func (TxnProbe) GetCommitter

func (txn TxnProbe) GetCommitter() CommitterProbe

GetCommitter returns the transaction committer.

func (TxnProbe) GetLockedCount

func (txn TxnProbe) GetLockedCount() int

GetLockedCount returns the count of locks acquired by the transaction

func (TxnProbe) GetStartTime

func (txn TxnProbe) GetStartTime() time.Time

GetStartTime returns the time when txn starts.

func (TxnProbe) GetUnionStore

func (txn TxnProbe) GetUnionStore() *unionstore.KVUnionStore

GetUnionStore returns transaction's embedded unionstore.

func (TxnProbe) IsAsyncCommit

func (txn TxnProbe) IsAsyncCommit() bool

IsAsyncCommit returns if the txn is committed using async commit.

func (TxnProbe) NewCommitter

func (txn TxnProbe) NewCommitter(sessionID uint64) (CommitterProbe, error)

NewCommitter creates an committer.

func (TxnProbe) NewScanner

func (txn TxnProbe) NewScanner(start, end []byte, batchSize int, reverse bool) (*txnsnapshot.Scanner, error)

NewScanner returns a scanner to iterate given key range.

func (TxnProbe) SetCommitter

func (txn TxnProbe) SetCommitter(committer CommitterProbe)

SetCommitter sets the bind committer of a transaction.

func (TxnProbe) SetStartTS

func (txn TxnProbe) SetStartTS(ts uint64)

SetStartTS resets the txn's start ts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL