store

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

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

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

func SplitRegion

func SplitRegion(ctx context.Context, store *TiKVStore, splitKey key.Key) error

SplitRegion splits the region contains splitKey into 2 regions: [start, splitKey) and [splitKey, end).

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

type ErrKeyAlreadyExist key.Key

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

func (*EtcdSafePointKV) Get

func (w *EtcdSafePointKV) Get(k string) (string, error)

Get implements the Get method for SafePointKV

func (*EtcdSafePointKV) Put

func (w *EtcdSafePointKV) Put(k string, v string) error

Put implements the Put method for SafePointKV

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 Lock

type Lock struct {
	Key     []byte
	Primary []byte
	TxnID   uint64
	TTL     uint64
}

Lock represents a lock from tikv server.

func NewLock

func NewLock(l *kvrpcpb.LockInfo, defaultTTL uint64) *Lock

NewLock creates a new *Lock.

type LockResolver

type LockResolver struct {
	// contains filtered or unexported fields
}

LockResolver resolves locks and also caches resolved txn status.

func NewLockResolver

func NewLockResolver(ctx context.Context, 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(ctx context.Context, 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

func (lr *LockResolver) ResolveLocks(bo *retry.Backoffer, locks []*Lock) (ok bool, err 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.

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

func (*MockSafePointKV) Get

func (w *MockSafePointKV) Get(k string) (string, error)

Get implements the Get method for SafePointKV

func (*MockSafePointKV) Put

func (w *MockSafePointKV) Put(k string, v string) error

Put implements the Put method for SafePointKV

type SafePointKV

type SafePointKV interface {
	Put(k string, v string) error
	Get(k string) (string, error)
}

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

func (*Scanner) Close

func (s *Scanner) Close()

Close close iterator.

func (*Scanner) Key

func (s *Scanner) Key() key.Key

Key return key.

func (*Scanner) Next

func (s *Scanner) Next(ctx context.Context) error

Next return next element.

func (*Scanner) Valid

func (s *Scanner) Valid() bool

Valid return valid.

func (*Scanner) Value

func (s *Scanner) Value() []byte

Value return value.

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

func (s *TiKVSnapshot) BatchGet(ctx context.Context, keys []key.Key) (map[string][]byte, error)

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(ctx context.Context, k key.Key) ([]byte, error)

Get gets the value for key k from snapshot.

func (*TiKVSnapshot) Iter

func (s *TiKVSnapshot) Iter(ctx context.Context, k key.Key, upperBound key.Key) (kv.Iterator, error)

Iter returns a list of key-value pair after `k`.

func (*TiKVSnapshot) IterReverse

func (s *TiKVSnapshot) IterReverse(ctx context.Context, k key.Key) (kv.Iterator, error)

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 NewStore

func NewStore(ctx context.Context, pdAddrs []string, conf config.Config) (*TiKVStore, error)

NewStore creates a TiKVStore instance.

func (*TiKVStore) CheckVisibility

func (s *TiKVStore) CheckVisibility(startTS uint64) error

CheckVisibility checks if it is safe to read using startTS (the startTS should

be greater than current GC safepoint).

func (*TiKVStore) Close

func (s *TiKVStore) Close() error

Close stops the TiKVStore instance and releases resources.

func (*TiKVStore) Closed

func (s *TiKVStore) Closed() <-chan struct{}

Closed returns a channel that will be closed when TiKVStore is closed.

func (*TiKVStore) GetConfig

func (s *TiKVStore) GetConfig() *config.Config

GetConfig returns the store's configurations.

func (*TiKVStore) GetLockResolver

func (s *TiKVStore) GetLockResolver() *LockResolver

GetLockResolver returns the lock resolver instance.

func (*TiKVStore) GetOracle

func (s *TiKVStore) GetOracle() oracle.Oracle

GetOracle returns the oracle instance.

func (*TiKVStore) GetRPCClient

func (s *TiKVStore) GetRPCClient() rpc.Client

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

func (s *TiKVStore) GetTimestampWithRetry(bo *retry.Backoffer) (uint64, error)

GetTimestampWithRetry queries PD for a new timestamp.

func (*TiKVStore) GetTxnLatches

func (s *TiKVStore) GetTxnLatches() *latch.LatchesScheduler

GetTxnLatches returns the latch scheduler instance.

func (*TiKVStore) SendReq

func (s *TiKVStore) SendReq(bo *retry.Backoffer, req *rpc.Request, regionID locate.RegionVerID, timeout time.Duration) (*rpc.Response, error)

SendReq sends a request to TiKV server.

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

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.

Jump to

Keyboard shortcuts

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