Documentation ¶
Index ¶
- Constants
- Variables
- func SendTxnHeartBeat(bo *retry.Backoffer, store kvstore, primary []byte, startTS, ttl uint64) (newTTL uint64, stopHeartBeat bool, err error)
- type BatchBufferGetter
- type BatchGetter
- type BinlogExecutor
- type BinlogWriteResult
- type BufferBatchGetter
- type CommitterMutationFlags
- type CommitterMutations
- type CommitterProbe
- func (c CommitterProbe) BuildPrewriteRequest(regionID, regionConf, regionVersion uint64, mutations CommitterMutations, ...) *tikvrpc.Request
- func (c CommitterProbe) CheckAsyncCommit() bool
- func (c CommitterProbe) Cleanup(ctx context.Context)
- func (c CommitterProbe) CleanupMutations(ctx context.Context) error
- func (c CommitterProbe) CloseTTLManager()
- func (c CommitterProbe) CommitMutations(ctx context.Context) error
- func (c CommitterProbe) Execute(ctx context.Context) error
- func (c CommitterProbe) GetCommitTS() uint64
- func (c CommitterProbe) GetForUpdateTS() uint64
- func (c CommitterProbe) GetLockTTL() uint64
- func (c CommitterProbe) GetMinCommitTS() uint64
- func (c CommitterProbe) GetMutations() CommitterMutations
- func (c CommitterProbe) GetOnePCCommitTS() uint64
- func (c CommitterProbe) GetPrimaryKey() []byte
- func (c CommitterProbe) GetStartTS() uint64
- func (c CommitterProbe) GetUndeterminedErr() error
- func (c CommitterProbe) InitKeysAndMutations() error
- func (c CommitterProbe) IsAsyncCommit() bool
- func (c CommitterProbe) IsOnePC() bool
- func (c CommitterProbe) IsTTLRunning() bool
- func (c CommitterProbe) IsTTLUninitialized() bool
- func (c CommitterProbe) MutationsOfKeys(keys [][]byte) CommitterMutations
- func (c CommitterProbe) PessimisticRollbackMutations(ctx context.Context, muts CommitterMutations) error
- func (c CommitterProbe) PrewriteAllMutations(ctx context.Context) error
- func (c CommitterProbe) PrewriteMutations(ctx context.Context, mutations CommitterMutations) error
- func (c CommitterProbe) SetCommitTS(ts uint64)
- func (c CommitterProbe) SetDiskFullOpt(level kvrpcpb.DiskFullOpt)
- func (c CommitterProbe) SetForUpdateTS(ts uint64)
- func (c CommitterProbe) SetLockTTL(ttl uint64)
- func (c CommitterProbe) SetLockTTLByTimeAndSize(start time.Time, size int)
- func (c CommitterProbe) SetMaxCommitTS(ts uint64)
- func (c CommitterProbe) SetMinCommitTS(ts uint64)
- func (c CommitterProbe) SetMutations(muts CommitterMutations)
- func (c CommitterProbe) SetNoFallBack()
- func (c CommitterProbe) SetPrimaryKey(key []byte)
- func (c CommitterProbe) SetPrimaryKeyBlocker(ac, bk chan struct{})
- func (c CommitterProbe) SetSessionID(id uint64)
- func (c CommitterProbe) SetTxnSize(sz int)
- func (c CommitterProbe) SetTxnSource(txnSource uint64)
- func (c CommitterProbe) SetUseAsyncCommit()
- func (c CommitterProbe) WaitCleanup()
- type ConfigProbe
- func (c ConfigProbe) GetDefaultLockTTL() uint64
- func (c ConfigProbe) GetPessimisticLockMaxBackoff() int
- func (c ConfigProbe) GetTTLFactor() int
- func (c ConfigProbe) GetTxnCommitBatchSize() uint64
- func (c ConfigProbe) LoadPreSplitDetectThreshold() uint32
- func (c ConfigProbe) LoadPreSplitSizeThreshold() uint32
- func (c ConfigProbe) StorePreSplitDetectThreshold(v uint32)
- func (c ConfigProbe) StorePreSplitSizeThreshold(v uint32)
- type KVFilter
- type KVTxn
- func (txn *KVTxn) AddRPCInterceptor(it interceptor.RPCInterceptor)
- func (txn *KVTxn) BatchGet(ctx context.Context, keys [][]byte) (map[string][]byte, error)
- func (txn *KVTxn) CancelAggressiveLocking(ctx context.Context)
- func (txn *KVTxn) ClearDiskFullOpt()
- func (txn *KVTxn) Commit(ctx context.Context) error
- func (txn *KVTxn) Delete(k []byte) error
- func (txn *KVTxn) DoneAggressiveLocking(ctx context.Context)
- func (txn *KVTxn) EnableForceSyncLog()
- func (txn *KVTxn) Get(ctx context.Context, k []byte) ([]byte, error)
- func (txn *KVTxn) GetClusterID() uint64
- func (txn *KVTxn) GetDiskFullOpt() kvrpcpb.DiskFullOpt
- func (txn *KVTxn) GetMemBuffer() *unionstore.MemDB
- func (txn *KVTxn) GetScope() string
- func (txn *KVTxn) GetSnapshot() *txnsnapshot.KVSnapshot
- func (txn *KVTxn) GetUnionStore() *unionstore.KVUnionStore
- func (txn *KVTxn) GetVars() *tikv.Variables
- func (txn *KVTxn) IsCasualConsistency() bool
- func (txn *KVTxn) IsInAggressiveLockingMode() bool
- func (txn *KVTxn) IsInAggressiveLockingStage(key []byte) bool
- func (txn *KVTxn) IsPessimistic() bool
- func (txn *KVTxn) IsReadOnly() bool
- func (txn *KVTxn) Iter(k []byte, upperBound []byte) (unionstore.Iterator, error)
- func (txn *KVTxn) IterReverse(k []byte) (unionstore.Iterator, error)
- func (txn *KVTxn) Len() int
- func (txn *KVTxn) LockKeys(ctx context.Context, lockCtx *tikv.LockCtx, keysInput ...[]byte) error
- func (txn *KVTxn) LockKeysFunc(ctx context.Context, lockCtx *tikv.LockCtx, fn func(), keysInput ...[]byte) error
- func (txn *KVTxn) LockKeysWithWaitTime(ctx context.Context, lockWaitTime int64, keysInput ...[]byte) (err error)
- func (txn *KVTxn) Mem() uint64
- func (txn *KVTxn) Reset()
- func (txn *KVTxn) RetryAggressiveLocking(ctx context.Context)
- func (txn *KVTxn) Rollback() error
- func (txn *KVTxn) Set(k []byte, v []byte) error
- func (txn *KVTxn) SetAssertionLevel(assertionLevel kvrpcpb.AssertionLevel)
- func (txn *KVTxn) SetBinlogExecutor(binlog BinlogExecutor)
- func (txn *KVTxn) SetCausalConsistency(b bool)
- func (txn *KVTxn) SetCommitCallback(f func(string, error))
- func (txn *KVTxn) SetCommitTSUpperBoundCheck(f func(commitTS uint64) bool)
- func (txn *KVTxn) SetDiskFullOpt(level kvrpcpb.DiskFullOpt)
- func (txn *KVTxn) SetEnable1PC(b bool)
- func (txn *KVTxn) SetEnableAsyncCommit(b bool)
- func (txn *KVTxn) SetKVFilter(filter KVFilter)
- func (txn *KVTxn) SetMemoryFootprintChangeHook(hook func(uint64))
- func (txn *KVTxn) SetPessimistic(b bool)
- func (txn *KVTxn) SetPriority(pri txnutil.Priority)
- func (txn *KVTxn) SetRPCInterceptor(it interceptor.RPCInterceptor)
- func (txn *KVTxn) SetRequestSourceInternal(internal bool)
- func (txn *KVTxn) SetRequestSourceType(tp string)
- func (txn *KVTxn) SetResourceGroupName(name string)
- func (txn *KVTxn) SetResourceGroupTag(tag []byte)
- func (txn *KVTxn) SetResourceGroupTagger(tagger tikvrpc.ResourceGroupTagger)
- func (txn *KVTxn) SetSchemaLeaseChecker(checker SchemaLeaseChecker)
- func (txn *KVTxn) SetSchemaVer(schemaVer SchemaVer)
- func (txn *KVTxn) SetScope(scope string)
- func (txn *KVTxn) SetTxnSource(txnSource uint64)
- func (txn *KVTxn) SetVars(vars *tikv.Variables)
- func (txn *KVTxn) Size() int
- func (txn *KVTxn) StartAggressiveLocking()
- func (txn *KVTxn) StartTS() uint64
- func (txn *KVTxn) String() string
- func (txn *KVTxn) Valid() bool
- type MemBufferMutationsProbe
- func (m MemBufferMutationsProbe) GetKey(i int) []byte
- func (m MemBufferMutationsProbe) GetKeys() [][]byte
- func (m MemBufferMutationsProbe) GetOp(i int) kvrpcpb.Op
- func (m MemBufferMutationsProbe) GetValue(i int) []byte
- func (m MemBufferMutationsProbe) IsAssertExists(i int) bool
- func (m MemBufferMutationsProbe) IsAssertNotExist(i int) bool
- func (m MemBufferMutationsProbe) IsPessimisticLock(i int) bool
- func (m MemBufferMutationsProbe) Len() int
- func (m MemBufferMutationsProbe) NeedConstraintCheckInPrewrite(i int) bool
- func (m MemBufferMutationsProbe) Push(op kvrpcpb.Op, ...)
- func (m MemBufferMutationsProbe) Slice(from, to int) CommitterMutations
- type PlainMutation
- type PlainMutations
- func (c *PlainMutations) AppendMutation(mutation PlainMutation)
- func (c *PlainMutations) GetFlags() []CommitterMutationFlags
- func (c *PlainMutations) GetKey(i int) []byte
- func (c *PlainMutations) GetKeys() [][]byte
- func (c *PlainMutations) GetOp(i int) kvrpcpb.Op
- func (c *PlainMutations) GetOps() []kvrpcpb.Op
- func (c *PlainMutations) GetValue(i int) []byte
- func (c *PlainMutations) GetValues() [][]byte
- func (c *PlainMutations) IsAssertExists(i int) bool
- func (c *PlainMutations) IsAssertNotExist(i int) bool
- func (c *PlainMutations) IsPessimisticLock(i int) bool
- func (c *PlainMutations) Len() int
- func (c *PlainMutations) MergeMutations(mutations PlainMutations)
- func (c *PlainMutations) NeedConstraintCheckInPrewrite(i int) bool
- func (c *PlainMutations) Push(op kvrpcpb.Op, key []byte, value []byte, ...)
- func (c *PlainMutations) Slice(from, to int) CommitterMutations
- type RelatedSchemaChange
- type SchemaLeaseChecker
- type SchemaVer
- type TxnInfo
- type TxnOptions
- type TxnProbe
- func (txn TxnProbe) BatchGetSingleRegion(bo *retry.Backoffer, region locate.RegionVerID, keys [][]byte, ...) error
- func (txn TxnProbe) CollectLockedKeys() [][]byte
- func (txn TxnProbe) GetAggressiveLockingKeys() []string
- func (txn TxnProbe) GetAggressiveLockingPreviousKeys() []string
- func (txn TxnProbe) GetCommitTS() uint64
- func (txn TxnProbe) GetCommitter() CommitterProbe
- func (txn TxnProbe) GetLockedCount() int
- func (txn TxnProbe) GetStartTime() time.Time
- func (txn TxnProbe) GetUnionStore() *unionstore.KVUnionStore
- func (txn TxnProbe) IsAsyncCommit() bool
- func (txn TxnProbe) NewCommitter(sessionID uint64) (CommitterProbe, error)
- func (txn TxnProbe) NewScanner(start, end []byte, batchSize int, reverse bool) (*txnsnapshot.Scanner, error)
- func (txn TxnProbe) SetCommitter(committer CommitterProbe)
- func (txn TxnProbe) SetStartTS(ts uint64)
Constants ¶
const CommitSecondaryMaxBackoff = 41000
CommitSecondaryMaxBackoff is max sleep time of the 'commit' command
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.
const (
// TsoMaxBackoff is the max sleep time to get tso.
TsoMaxBackoff = 15000
)
Variables ¶
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) )
var (
ManagedLockTTL uint64 = 20000 // 20s
)
Global variable set by config file.
var SetSuccess = *atomicutil.NewBool(false)
SetSuccess is used to probe if kv variables are set or not. It is ONLY used in test cases.
Functions ¶
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 ¶
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.
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) SetTxnSource ¶ added in v2.0.3
func (c CommitterProbe) SetTxnSource(txnSource uint64)
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 ¶
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) CancelAggressiveLocking ¶ added in v2.0.3
CancelAggressiveLocking cancels the current aggressive locking state. All pessimistic locks that were acquired during the aggressive locking state will be rolled back by PessimisticRollback.
func (*KVTxn) ClearDiskFullOpt ¶
func (txn *KVTxn) ClearDiskFullOpt()
ClearDiskFullOpt clears the options of current operation in each tikv disk usage level.
func (*KVTxn) DoneAggressiveLocking ¶ added in v2.0.3
DoneAggressiveLocking finishes the current aggressive locking. The locked keys will be moved to the membuffer as if these keys are locked in nomral way. If there's any unneeded locks, they will be released.
func (*KVTxn) EnableForceSyncLog ¶
func (txn *KVTxn) EnableForceSyncLog()
EnableForceSyncLog indicates tikv to always sync log for the transaction.
func (*KVTxn) GetClusterID ¶
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) 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) IsCasualConsistency ¶
IsCasualConsistency returns if the transaction allows linearizability inconsistency.
func (*KVTxn) IsInAggressiveLockingMode ¶ added in v2.0.3
IsInAggressiveLockingMode checks if the transaction is currently in aggressive locking mode.
func (*KVTxn) IsInAggressiveLockingStage ¶ added in v2.0.3
IsInAggressiveLockingStage checks if a key is locked during the current aggressive locking stage.
func (*KVTxn) IsPessimistic ¶
IsPessimistic returns true if it is pessimistic.
func (*KVTxn) IsReadOnly ¶
IsReadOnly checks if the transaction has only performed read operations.
func (*KVTxn) Iter ¶
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) LockKeys ¶
LockKeys tries to lock the entries with the keys in KV store. lockCtx is the context for lock, lockCtx.lockWaitTime in ms
func (*KVTxn) LockKeysFunc ¶ added in v2.0.4
func (txn *KVTxn) LockKeysFunc(ctx context.Context, lockCtx *tikv.LockCtx, fn func(), keysInput ...[]byte) error
LockKeysFunc tries to lock the entries with the keys in KV store. lockCtx is the context for lock, lockCtx.lockWaitTime in ms fn is a function which run before the lock is released.
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) RetryAggressiveLocking ¶ added in v2.0.3
RetryAggressiveLocking tells the transaction that the current statement will be retried (ends the current attempt and starts the next attempt). If some keys are already locked during the aggressive locking, after calling this function, these locks will then be regarded as being acquired in the previous attempt. If some locks is acquired in the previous attempt but not needed in the current attempt, after calling this function, these locks will then be released.
func (*KVTxn) Set ¶
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 ¶
SetCausalConsistency indicates if the transaction does not need to guarantee linearizability. Default value is false which means linearizability is guaranteed.
func (*KVTxn) SetCommitCallback ¶
SetCommitCallback sets up a function that will be called when the transaction is finished.
func (*KVTxn) SetCommitTSUpperBoundCheck ¶
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 ¶
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 ¶
SetEnableAsyncCommit indicates if the transaction will try to use async commit.
func (*KVTxn) SetKVFilter ¶
SetKVFilter sets the filter to ignore key-values in memory buffer.
func (*KVTxn) SetMemoryFootprintChangeHook ¶ added in v2.0.2
SetMemoryFootprintChangeHook sets the hook function that is triggered when memdb grows
func (*KVTxn) SetPessimistic ¶
SetPessimistic indicates if the transaction should use pessimictic lock.
func (*KVTxn) SetPriority ¶
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 ¶ added in v2.0.2
SetRequestSourceInternal sets the scope of the request source.
func (*KVTxn) SetRequestSourceType ¶ added in v2.0.2
SetRequestSourceType sets the type of the request source.
func (*KVTxn) SetResourceGroupName ¶ added in v2.0.5
SetResourceGroupName set resource group name for both read and write.
func (*KVTxn) SetResourceGroupTag ¶
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) SetSchemaLeaseChecker ¶
func (txn *KVTxn) SetSchemaLeaseChecker(checker SchemaLeaseChecker)
SetSchemaLeaseChecker sets a hook to check schema version.
func (*KVTxn) SetSchemaVer ¶
SetSchemaVer updates schema version to validate transaction.
func (*KVTxn) SetTxnSource ¶ added in v2.0.3
SetTxnSource sets the source of the transaction.
func (*KVTxn) StartAggressiveLocking ¶ added in v2.0.3
func (txn *KVTxn) StartAggressiveLocking()
StartAggressiveLocking makes the transaction enters aggressive locking state.
Aggressive locking refers to the behavior that when a DML in a pessimistic transaction encounters write conflict, do not pessimistic-rollback them immediately; instead, keep the already-acquired locks and retry the statement. In this way, during retry, if it needs to acquire the same locks that was acquired in the previous execution, the lock RPC can be skipped. After finishing the execution, if some of the locks that were acquired in the previous execution but not needed in the current retried execution, they will be released.
In aggressive locking state, keys locked by `LockKeys` will be recorded to a separated buffer. For `LockKeys` invocations that involves only one key, the pessimistic lock request will be performed in ForceLock mode (kvrpcpb.PessimisticLockWakeUpMode_WakeUpModeForceLock).
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) IsAssertExists ¶
func (MemBufferMutationsProbe) IsAssertNotExist ¶
func (MemBufferMutationsProbe) IsPessimisticLock ¶
func (MemBufferMutationsProbe) NeedConstraintCheckInPrewrite ¶ added in v2.0.2
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) MergeMutations ¶
func (c *PlainMutations) MergeMutations(mutations PlainMutations)
MergeMutations append input mutations into current mutations.
func (*PlainMutations) NeedConstraintCheckInPrewrite ¶ added in v2.0.2
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 }
RelatedSchemaChange contains information about schema diff between two schema versions.
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 ¶ added in v2.0.2
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 ¶
CollectLockedKeys returns all locked keys of a transaction.
func (TxnProbe) GetAggressiveLockingKeys ¶ added in v2.0.3
GetAggressiveLockingKeys returns the keys that are in the current aggressive locking stage.
func (TxnProbe) GetAggressiveLockingPreviousKeys ¶ added in v2.0.3
GetAggressiveLockingPreviousKeys returns the keys that were locked in the previous aggressive locking stage.
func (TxnProbe) GetCommitTS ¶
GetCommitTS returns the commit ts.
func (TxnProbe) GetCommitter ¶
func (txn TxnProbe) GetCommitter() CommitterProbe
GetCommitter returns the transaction committer.
func (TxnProbe) GetLockedCount ¶ added in v2.0.2
GetLockedCount returns the count of locks acquired by the transaction
func (TxnProbe) GetStartTime ¶
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 ¶
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 ¶
SetStartTS resets the txn's start ts.