txnlock

package
v2.5.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

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

func ExtractLockFromKeyErr(keyErr *kvrpcpb.KeyError) (*Lock, error)

ExtractLockFromKeyErr extracts the KeyError.

func NewLock

func NewLock(l *kvrpcpb.LockInfo) *Lock

NewLock creates a new *Lock.

func (*Lock) String

func (l *Lock) String() string

type LockProbe

type LockProbe struct{}

LockProbe exposes some lock utilities for testing purpose.

func (LockProbe) GetPrimaryKeyFromTxnStatus

func (l LockProbe) GetPrimaryKeyFromTxnStatus(s TxnStatus) []byte

GetPrimaryKeyFromTxnStatus returns the primary key of the transaction.

func (LockProbe) NewLockStatus

func (l LockProbe) NewLockStatus(keys [][]byte, useAsyncCommit bool, minCommitTS uint64) TxnStatus

NewLockStatus returns a txn state that has been locked.

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:

  1. 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.
  2. For each lock, query the primary key to get txn(which left the lock)'s commit status.
  3. 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

func (s TxnStatus) Action() kvrpcpb.Action

Action returns what the CheckTxnStatus request have done to the transaction.

func (TxnStatus) CommitTS

func (s TxnStatus) CommitTS() uint64

CommitTS returns the txn's commitTS. It is valid iff `IsCommitted` is true.

func (TxnStatus) IsCommitted

func (s TxnStatus) IsCommitted() bool

IsCommitted returns true if the txn's final status is Commit.

func (TxnStatus) StatusCacheable

func (s TxnStatus) StatusCacheable() bool

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.

func (TxnStatus) TTL

func (s TxnStatus) TTL() uint64

TTL returns the TTL of the transaction if the transaction is still alive.

Jump to

Keyboard shortcuts

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