Documentation ¶
Index ¶
- Constants
- Variables
- func SplitRegion(store *TiKVStore, splitKey key.Key) error
- type CommitDetails
- type DeleteRangeTask
- type ErrKeyAlreadyExist
- type EtcdSafePointKV
- type ExecDetails
- type Lock
- type LockResolver
- type MockSafePointKV
- type SafePointKV
- type Scanner
- type TiKVSnapshot
- func (s *TiKVSnapshot) BatchGet(keys []key.Key) (map[string][]byte, error)
- func (s *TiKVSnapshot) Get(k key.Key) ([]byte, error)
- func (s *TiKVSnapshot) Iter(k key.Key, upperBound key.Key) (kv.Iterator, error)
- func (s *TiKVSnapshot) IterReverse(k key.Key) (kv.Iterator, error)
- func (s *TiKVSnapshot) SetPriority(priority int)
- type TiKVStore
- func (s *TiKVStore) CheckVisibility(startTS uint64) error
- func (s *TiKVStore) Close() error
- func (s *TiKVStore) Closed() <-chan struct{}
- func (s *TiKVStore) GetConfig() *config.Config
- func (s *TiKVStore) GetLockResolver() *LockResolver
- func (s *TiKVStore) GetOracle() oracle.Oracle
- func (s *TiKVStore) GetRPCClient() rpc.Client
- func (s *TiKVStore) GetRegionCache() *locate.RegionCache
- func (s *TiKVStore) GetSnapshot(ts uint64) *TiKVSnapshot
- func (s *TiKVStore) GetTimestampWithRetry(bo *retry.Backoffer) (uint64, error)
- func (s *TiKVStore) GetTxnLatches() *latch.LatchesScheduler
- func (s *TiKVStore) SendReq(bo *retry.Backoffer, req *rpc.Request, regionID locate.RegionVerID, ...) (*rpc.Response, error)
- type TxnCommitter
- type TxnStatus
Constants ¶
const TxnRetryableMark = "[try again later]"
TxnRetryableMark is used to direct user to restart a transaction. TiDB decides whether to retry transaction by checking if error message contains string "try again later" literally. The common usage is `errors.Annotate(err, TxnRetryableMark)`. Note that it should be only used if i) the error occurs inside a transaction and ii) the error is not totally unexpected and hopefully will recover soon.
Variables ¶
var ( // ErrResultUndetermined means that the commit status is unknown. ErrResultUndetermined = errors.New("result undetermined") // ErrNotImplemented returns when a function is not implemented yet. ErrNotImplemented = errors.New("not implemented") // ErrPDServerTimeout is the error that PD does not repond in time. ErrPDServerTimeout = errors.New("PD server timeout") // ErrStartTSFallBehind is the error a transaction runs too long and data // loaded from TiKV may out of date because of GC. ErrStartTSFallBehind = errors.New("StartTS may fall behind safePoint") )
Functions ¶
Types ¶
type CommitDetails ¶
type CommitDetails struct { GetCommitTsTime time.Duration PrewriteTime time.Duration CommitTime time.Duration LocalLatchTime time.Duration TotalBackoffTime time.Duration ResolveLockTime int64 WriteKeys int WriteSize int PrewriteRegionNum int32 TxnRetry int }
CommitDetails contains commit detail information.
type DeleteRangeTask ¶
type DeleteRangeTask struct {
// contains filtered or unexported fields
}
DeleteRangeTask is used to delete all keys in a range. After performing DeleteRange, it keeps how many ranges it affects and if the task was canceled or not.
func NewDeleteRangeTask ¶
func NewDeleteRangeTask(ctx context.Context, store *TiKVStore, startKey []byte, endKey []byte) *DeleteRangeTask
NewDeleteRangeTask creates a DeleteRangeTask. Deleting will not be performed right away. WARNING: Currently, this API may leave some waste key-value pairs uncleaned in TiKV. Be careful while using it.
func (*DeleteRangeTask) CompletedRegions ¶
func (t *DeleteRangeTask) CompletedRegions() int
CompletedRegions returns the number of regions that are affected by this delete range task
func (*DeleteRangeTask) Execute ¶
func (t *DeleteRangeTask) Execute() error
Execute performs the delete range operation.
func (*DeleteRangeTask) IsCanceled ¶
func (t *DeleteRangeTask) IsCanceled() bool
IsCanceled returns true if the delete range operation was canceled on the half way
type ErrKeyAlreadyExist ¶
ErrKeyAlreadyExist is the error that a key exists in TiKV when it should not.
func (ErrKeyAlreadyExist) Error ¶
func (e ErrKeyAlreadyExist) Error() string
type EtcdSafePointKV ¶
type EtcdSafePointKV struct {
// contains filtered or unexported fields
}
EtcdSafePointKV implements SafePointKV at runtime
func NewEtcdSafePointKV ¶
func NewEtcdSafePointKV(addrs []string, tlsConfig *tls.Config) (*EtcdSafePointKV, error)
NewEtcdSafePointKV creates an instance of EtcdSafePointKV
type ExecDetails ¶
type ExecDetails struct { CalleeAddress string ProcessTime time.Duration WaitTime time.Duration BackoffTime time.Duration RequestCount int TotalKeys int64 ProcessedKeys int64 CommitDetail *CommitDetails }
ExecDetails contains execution detail information.
func (ExecDetails) String ¶
func (d ExecDetails) String() string
String implements the fmt.Stringer interface.
type LockResolver ¶
type LockResolver struct {
// contains filtered or unexported fields
}
LockResolver resolves locks and also caches resolved txn status.
func NewLockResolver ¶
func NewLockResolver(etcdAddrs []string, conf config.Config) (*LockResolver, error)
NewLockResolver creates a LockResolver. It is exported for other pkg to use. For instance, binlog service needs to determine a transaction's commit state.
func (*LockResolver) BatchResolveLocks ¶
func (lr *LockResolver) BatchResolveLocks(bo *retry.Backoffer, locks []*Lock, loc locate.RegionVerID) (bool, error)
BatchResolveLocks resolve locks in a batch
func (*LockResolver) GetTxnStatus ¶
func (lr *LockResolver) GetTxnStatus(txnID 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 ¶
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.
type MockSafePointKV ¶
type MockSafePointKV struct {
// contains filtered or unexported fields
}
MockSafePointKV implements SafePointKV at mock test
func NewMockSafePointKV ¶
func NewMockSafePointKV() *MockSafePointKV
NewMockSafePointKV creates an instance of MockSafePointKV
type SafePointKV ¶
SafePointKV is used for a seamingless integration for mockTest and runtime.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner support tikv scan
type TiKVSnapshot ¶
type TiKVSnapshot struct { Priority pb.CommandPri NotFillCache bool SyncLog bool KeyOnly bool // contains filtered or unexported fields }
TiKVSnapshot supports read from TiKV.
func (*TiKVSnapshot) BatchGet ¶
BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs. The map will not contain nonexistent keys.
func (*TiKVSnapshot) Get ¶
func (s *TiKVSnapshot) Get(k key.Key) ([]byte, error)
Get gets the value for key k from snapshot.
func (*TiKVSnapshot) IterReverse ¶
IterReverse creates a reversed Iterator positioned on the first entry which key is less than k.
func (*TiKVSnapshot) SetPriority ¶
func (s *TiKVSnapshot) SetPriority(priority int)
SetPriority sets the priority of read requests.
type TiKVStore ¶
type TiKVStore struct {
// contains filtered or unexported fields
}
TiKVStore contains methods to interact with a TiKV cluster.
func (*TiKVStore) CheckVisibility ¶
CheckVisibility checks if it is safe to read using startTS (the startTS should
be greater than current GC safepoint).
func (*TiKVStore) Closed ¶
func (s *TiKVStore) Closed() <-chan struct{}
Closed returns a channel that will be closed when TiKVStore is closed.
func (*TiKVStore) GetLockResolver ¶
func (s *TiKVStore) GetLockResolver() *LockResolver
GetLockResolver returns the lock resolver instance.
func (*TiKVStore) GetRPCClient ¶
GetRPCClient returns the rpc client instance.
func (*TiKVStore) GetRegionCache ¶
func (s *TiKVStore) GetRegionCache() *locate.RegionCache
GetRegionCache returns the region cache instance.
func (*TiKVStore) GetSnapshot ¶
func (s *TiKVStore) GetSnapshot(ts uint64) *TiKVSnapshot
GetSnapshot creates a snapshot for read.
func (*TiKVStore) GetTimestampWithRetry ¶
GetTimestampWithRetry queries PD for a new timestamp.
func (*TiKVStore) GetTxnLatches ¶
func (s *TiKVStore) GetTxnLatches() *latch.LatchesScheduler
GetTxnLatches returns the latch scheduler instance.
type TxnCommitter ¶
type TxnCommitter struct { Priority pb.CommandPri SyncLog bool ConnID uint64 // ConnID is used for log. // contains filtered or unexported fields }
TxnCommitter executes a two-phase commit protocol.
func NewTxnCommitter ¶
func NewTxnCommitter(store *TiKVStore, startTS uint64, startTime time.Time, mutations map[string]*pb.Mutation) (*TxnCommitter, error)
NewTxnCommitter creates a TxnCommitter.
func (*TxnCommitter) Execute ¶
func (c *TxnCommitter) Execute(ctx context.Context) error
Execute executes the two-phase commit protocol.
func (*TxnCommitter) GetCommitTS ¶
func (c *TxnCommitter) GetCommitTS() uint64
GetCommitTS returns the commit timestamp of the transaction.
func (*TxnCommitter) GetKeys ¶
func (c *TxnCommitter) GetKeys() [][]byte
GetKeys returns all keys of the committer.
type TxnStatus ¶
type TxnStatus uint64
TxnStatus represents a txn's final status. It should be Commit or Rollback.
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.