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) GetTxnStatus(txnID uint64, callerStartTS uint64, primary []byte) (TxnStatus, error)
- func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, error)
- func (lr *LockResolver) ResolveLocksForWrite(bo *retry.Backoffer, callerStartTS, callerForUpdateTS uint64, locks []*Lock) (int64, error)
- func (lr *LockResolver) ResolveLocksLite(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, error)
- 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) ResolveLock(bo *retry.Backoffer, lock *Lock) error
- func (l LockResolverProbe) ResolveLockAsync(bo *retry.Backoffer, lock *Lock, status TxnStatus) error
- func (l LockResolverProbe) ResolvePessimisticLock(bo *retry.Backoffer, lock *Lock) error
- func (l LockResolverProbe) SetMeetLockCallback(f func([]*Lock))
- 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) 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) ResolveLocks ¶
func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, 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) ResolveLocksForWrite ¶
func (lr *LockResolver) ResolveLocksForWrite(bo *retry.Backoffer, callerStartTS, callerForUpdateTS uint64, locks []*Lock) (int64, error)
ResolveLocksForWrite resolves lock for write
func (*LockResolver) ResolveLocksLite ¶
func (lr *LockResolver) ResolveLocksLite(bo *retry.Backoffer, callerStartTS uint64, locks []*Lock) (int64, []uint64, error)
ResolveLocksLite resolves locks while preventing scan whole region.
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) ResolveLock ¶
func (l LockResolverProbe) ResolveLock(bo *retry.Backoffer, lock *Lock) error
ResolveLock resolves single lock.
func (LockResolverProbe) ResolveLockAsync ¶
func (l LockResolverProbe) ResolveLockAsync(bo *retry.Backoffer, lock *Lock, status TxnStatus) error
ResolveLockAsync tries to resolve a lock using the txn states.
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.
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) 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.