Documentation ¶
Index ¶
- Constants
- type Lock
- type LockProbe
- type LockResolver
- func (lr *LockResolver) BatchResolveLocks(bo *retry.Backoffer, locks []*Lock, loc locate.RegionVerID) (bool, error)
- func (lr *LockResolver) Close()
- func (lr *LockResolver) GetTxnStatus(txnID uint64, callerStartTS uint64, primary []byte) (TxnStatus, error)
- func (lr *LockResolver) RecordResolvingLocks(locks []*Lock, callerStartTS uint64) int
- func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, error)
- func (lr *LockResolver) ResolveLocksDone(callerStartTS uint64, token int)
- func (lr *LockResolver) ResolveLocksForRead(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock, lite bool) (int64, []uint64, []uint64, error)
- func (lr *LockResolver) ResolveLocksWithOpts(bo *retry.Backoffer, opts ResolveLocksOptions) (ResolveLockResult, error)
- func (lr *LockResolver) Resolving() []ResolvingLock
- func (lr *LockResolver) UpdateResolvingLocks(locks []*Lock, callerStartTS uint64, token int)
- type LockResolverProbe
- func (l LockResolverProbe) CheckAllSecondaries(bo *retry.Backoffer, lock *Lock, status *TxnStatus) error
- func (l LockResolverProbe) GetSecondariesFromTxnStatus(status TxnStatus) [][]byte
- func (l LockResolverProbe) GetTxnStatus(bo *retry.Backoffer, txnID uint64, primary []byte, ...) (TxnStatus, error)
- func (l LockResolverProbe) GetTxnStatusFromLock(bo *retry.Backoffer, lock *Lock, callerStartTS uint64, forceSyncCommit bool) (TxnStatus, error)
- func (l LockResolverProbe) IsErrorNotFound(err error) bool
- func (l LockResolverProbe) IsNonAsyncCommitLock(err error) bool
- func (l LockResolverProbe) ResolveAsyncCommitLock(bo *retry.Backoffer, lock *Lock, status TxnStatus) error
- func (l LockResolverProbe) ResolveLock(bo *retry.Backoffer, lock *Lock) error
- func (l LockResolverProbe) ResolvePessimisticLock(bo *retry.Backoffer, lock *Lock) error
- func (l LockResolverProbe) SetMeetLockCallback(f func([]*Lock))
- func (l LockResolverProbe) SetResolving(currentStartTS uint64, locks []Lock)
- type ResolveLockResult
- type ResolveLocksOptions
- type ResolvingLock
- type TxnStatus
Constants ¶
const ResolvedCacheSize = 2048
ResolvedCacheSize is max number of cached txn status.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct { Key []byte Primary []byte TxnID uint64 TTL uint64 TxnSize uint64 LockType kvrpcpb.Op UseAsyncCommit bool LockForUpdateTS uint64 MinCommitTS uint64 }
Lock represents a lock from tikv server.
func ExtractLockFromKeyErr ¶
ExtractLockFromKeyErr extracts the KeyError.
type LockProbe ¶
type LockProbe struct{}
LockProbe exposes some lock utilities for testing purpose.
func (LockProbe) GetPrimaryKeyFromTxnStatus ¶
GetPrimaryKeyFromTxnStatus returns the primary key of the transaction.
type LockResolver ¶
type LockResolver struct {
// contains filtered or unexported fields
}
LockResolver resolves locks and also caches resolved txn status.
func NewLockResolver ¶
func NewLockResolver(store storage) *LockResolver
NewLockResolver creates a new LockResolver instance.
func (*LockResolver) BatchResolveLocks ¶
func (lr *LockResolver) BatchResolveLocks(bo *retry.Backoffer, locks []*Lock, loc locate.RegionVerID) (bool, error)
BatchResolveLocks resolve locks in a batch. Used it in gcworker only!
func (*LockResolver) Close ¶
func (lr *LockResolver) Close()
Close cancels all background goroutines.
func (*LockResolver) GetTxnStatus ¶
func (lr *LockResolver) GetTxnStatus(txnID uint64, callerStartTS uint64, primary []byte) (TxnStatus, error)
GetTxnStatus queries tikv-server for a txn's status (commit/rollback). If the primary key is still locked, it will launch a Rollback to abort it. To avoid unnecessarily aborting too many txns, it is wiser to wait a few seconds before calling it after Prewrite.
func (*LockResolver) RecordResolvingLocks ¶ added in v2.0.2
func (lr *LockResolver) RecordResolvingLocks(locks []*Lock, callerStartTS uint64) int
RecordResolvingLocks records a txn which startTS is callerStartTS tries to resolve locks Call this when start trying to resolve locks Return a token which is used to call ResolvingLocksDone
func (*LockResolver) ResolveLocks ¶
func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, error)
ResolveLocks tries to resolve Locks. The resolving process is in 3 steps:
- Use the `lockTTL` to pick up all expired locks. Only locks that are too old are considered orphan locks and will be handled later. If all locks are expired then all locks will be resolved so the returned `ok` will be true, otherwise caller should sleep a while before retry.
- For each lock, query the primary key to get txn(which left the lock)'s commit status.
- Send `ResolveLock` cmd to the lock's region to resolve all locks belong to the same transaction.
func (*LockResolver) ResolveLocksDone ¶ added in v2.0.2
func (lr *LockResolver) ResolveLocksDone(callerStartTS uint64, token int)
ResolveLocksDone will remove resolving locks information related with callerStartTS
func (*LockResolver) ResolveLocksForRead ¶
func (lr *LockResolver) ResolveLocksForRead(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock, lite bool) (int64, []uint64, []uint64, error)
ResolveLocksForRead is essentially the same as ResolveLocks, except with some optimizations for read. Read operations needn't wait for resolve secondary locks and can read through(the lock's transaction is committed and its commitTS is less than or equal to callerStartTS) or ignore(the lock's transaction is rolled back or its minCommitTS is pushed) the lock .
func (*LockResolver) ResolveLocksWithOpts ¶ added in v2.0.2
func (lr *LockResolver) ResolveLocksWithOpts(bo *retry.Backoffer, opts ResolveLocksOptions) (ResolveLockResult, error)
ResolveLocksWithOpts wraps ResolveLocks and ResolveLocksForRead, which extract the parameters into structs for better extension.
func (*LockResolver) Resolving ¶ added in v2.0.2
func (lr *LockResolver) Resolving() []ResolvingLock
Resolving returns the locks' information we are resolving currently.
func (*LockResolver) UpdateResolvingLocks ¶ added in v2.0.2
func (lr *LockResolver) UpdateResolvingLocks(locks []*Lock, callerStartTS uint64, token int)
UpdateResolvingLocks update the lock resoling information of the txn `callerStartTS`
type LockResolverProbe ¶
type LockResolverProbe struct {
*LockResolver
}
LockResolverProbe wraps a LockResolver and exposes internal stats for testing purpose.
func (LockResolverProbe) CheckAllSecondaries ¶
func (l LockResolverProbe) CheckAllSecondaries(bo *retry.Backoffer, lock *Lock, status *TxnStatus) error
CheckAllSecondaries checks the secondary locks of an async commit transaction to find out the final status of the transaction.
func (LockResolverProbe) GetSecondariesFromTxnStatus ¶
func (l LockResolverProbe) GetSecondariesFromTxnStatus(status TxnStatus) [][]byte
GetSecondariesFromTxnStatus returns the secondary locks from txn status.
func (LockResolverProbe) GetTxnStatus ¶
func (l LockResolverProbe) GetTxnStatus(bo *retry.Backoffer, txnID uint64, primary []byte, callerStartTS, currentTS uint64, rollbackIfNotExist bool, forceSyncCommit bool, lockInfo *Lock) (TxnStatus, error)
GetTxnStatus sends the CheckTxnStatus request to the TiKV server.
func (LockResolverProbe) GetTxnStatusFromLock ¶
func (l LockResolverProbe) GetTxnStatusFromLock(bo *retry.Backoffer, lock *Lock, callerStartTS uint64, forceSyncCommit bool) (TxnStatus, error)
GetTxnStatusFromLock queries tikv for a txn's status.
func (LockResolverProbe) IsErrorNotFound ¶
func (l LockResolverProbe) IsErrorNotFound(err error) bool
IsErrorNotFound checks if an error is caused by txnNotFoundErr.
func (LockResolverProbe) IsNonAsyncCommitLock ¶
func (l LockResolverProbe) IsNonAsyncCommitLock(err error) bool
IsNonAsyncCommitLock checks if an error is nonAsyncCommitLock error.
func (LockResolverProbe) ResolveAsyncCommitLock ¶
func (l LockResolverProbe) ResolveAsyncCommitLock(bo *retry.Backoffer, lock *Lock, status TxnStatus) error
ResolveAsyncCommitLock tries to resolve a lock using the txn states.
func (LockResolverProbe) ResolveLock ¶
func (l LockResolverProbe) ResolveLock(bo *retry.Backoffer, lock *Lock) error
ResolveLock resolves single lock.
func (LockResolverProbe) ResolvePessimisticLock ¶
func (l LockResolverProbe) ResolvePessimisticLock(bo *retry.Backoffer, lock *Lock) error
ResolvePessimisticLock resolves single pessimistic lock.
func (LockResolverProbe) SetMeetLockCallback ¶
func (l LockResolverProbe) SetMeetLockCallback(f func([]*Lock))
SetMeetLockCallback is called whenever it meets locks.
func (LockResolverProbe) SetResolving ¶ added in v2.0.2
func (l LockResolverProbe) SetResolving(currentStartTS uint64, locks []Lock)
SetResolving set the resolving lock status for LockResolver
type ResolveLockResult ¶ added in v2.0.2
ResolveLockResult is the result struct for resolving lock.
type ResolveLocksOptions ¶ added in v2.0.2
type ResolveLocksOptions struct { CallerStartTS uint64 Locks []*Lock Lite bool ForRead bool Detail *util.ResolveLockDetail }
ResolveLocksOptions is the options struct for calling resolving lock.
type ResolvingLock ¶ added in v2.0.2
ResolvingLock stands for current resolving locks' information
type TxnStatus ¶
type TxnStatus struct {
// contains filtered or unexported fields
}
TxnStatus represents a txn's final status. It should be Lock or Commit or Rollback.
func (TxnStatus) Action ¶
Action returns what the CheckTxnStatus request have done to the transaction.
func (TxnStatus) CommitTS ¶
CommitTS returns the txn's commitTS. It is valid iff `IsCommitted` is true.
func (TxnStatus) IsCommitted ¶
IsCommitted returns true if the txn's final status is Commit.
func (TxnStatus) IsRolledBack ¶
IsRolledBack returns true if the txn's final status is rolled back.
func (TxnStatus) StatusCacheable ¶
StatusCacheable checks whether the transaction status is certain.True will be returned if its status is certain:
If transaction is already committed, the result could be cached. Otherwise: If l.LockType is pessimistic lock type: - if its primary lock is pessimistic too, the check txn status result should not be cached. - if its primary lock is prewrite lock type, the check txn status could be cached. If l.lockType is prewrite lock type: - always cache the check txn status result.
For prewrite locks, their primary keys should ALWAYS be the correct one and will NOT change.