Documentation ¶
Index ¶
- Variables
- func BootstrapWithMultiRegions(cluster *Cluster, splitKeys ...[]byte) (storeID uint64, regionIDs, peerIDs []uint64)
- func BootstrapWithMultiStores(cluster *Cluster, n int) (storeIDs, peerIDs []uint64, regionID uint64, leaderPeer uint64)
- func BootstrapWithSingleStore(cluster *Cluster) (storeID, peerID, regionID uint64)
- func MustPrewrite(store MVCCStore, mutations []*kvrpcpb.Mutation, primary string, startTS uint64, ...) bool
- func NewPDClient(cluster *Cluster) pd.Client
- func NewTiKVAndPDClient(path string, coprHandler CoprRPCHandler) (*RPCClient, *Cluster, pd.Client, error)
- type Client
- type Cluster
- func (c *Cluster) AddPeer(regionID, storeID, peerID uint64)
- func (c *Cluster) AddStore(storeID uint64, addr string, labels ...*metapb.StoreLabel)
- func (c *Cluster) AllocID() uint64
- func (c *Cluster) AllocIDs(n int) []uint64
- func (c *Cluster) Bootstrap(regionID uint64, storeIDs, peerIDs []uint64, leaderPeerID uint64)
- func (c *Cluster) CancelStore(storeID uint64)
- func (c *Cluster) ChangeLeader(regionID, leaderPeerID uint64)
- func (c *Cluster) GetAllRegions() []*Region
- func (c *Cluster) GetAllStores() []*metapb.Store
- func (c *Cluster) GetAndCheckStoreByAddr(addr string) (ss []*metapb.Store, err error)
- func (c *Cluster) GetPrevRegionByKey(key []byte) (*metapb.Region, *metapb.Peer)
- func (c *Cluster) GetRegion(regionID uint64) (*metapb.Region, uint64)
- func (c *Cluster) GetRegionByID(regionID uint64) (*metapb.Region, *metapb.Peer)
- func (c *Cluster) GetRegionByKey(key []byte) (*metapb.Region, *metapb.Peer)
- func (c *Cluster) GetStore(storeID uint64) *metapb.Store
- func (c *Cluster) GetStoreByAddr(addr string) *metapb.Store
- func (c *Cluster) GiveUpLeader(regionID uint64)
- func (c *Cluster) MarkTombstone(storeID uint64)
- func (c *Cluster) Merge(regionID1, regionID2 uint64)
- func (c *Cluster) RemovePeer(regionID, storeID uint64)
- func (c *Cluster) RemoveStore(storeID uint64)
- func (c *Cluster) ScanRegions(startKey, endKey []byte, limit int) []*pd.Region
- func (c *Cluster) ScheduleDelay(startTS, regionID uint64, dur time.Duration)
- func (c *Cluster) Split(regionID, newRegionID uint64, key []byte, peerIDs []uint64, ...)
- func (c *Cluster) SplitKeys(start, end []byte, count int)
- func (c *Cluster) SplitRaw(regionID, newRegionID uint64, rawKey []byte, peerIDs []uint64, ...) *metapb.Region
- func (c *Cluster) StartStore(storeID uint64)
- func (c *Cluster) StopStore(storeID uint64)
- func (c *Cluster) UnCancelStore(storeID uint64)
- func (c *Cluster) UpdateStoreAddr(storeID uint64, addr string, labels ...*metapb.StoreLabel)
- func (c *Cluster) UpdateStoreLabels(storeID uint64, labels []*metapb.StoreLabel)
- type CoprRPCHandler
- type ErrAbort
- type ErrAlreadyCommitted
- type ErrAlreadyRollbacked
- type ErrCommitTSExpired
- type ErrConflict
- type ErrDeadlock
- type ErrKeyAlreadyExist
- type ErrLocked
- type ErrRetryable
- type ErrTxnNotFound
- type Iterator
- type MVCCDebugger
- type MVCCLevelDB
- func (mvcc *MVCCLevelDB) BatchGet(ks [][]byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, ...) []Pair
- func (mvcc *MVCCLevelDB) BatchResolveLock(startKey, endKey []byte, txnInfos map[uint64]uint64) error
- func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS, currentTS uint64, ...) (ttl uint64, commitTS uint64, action kvrpcpb.Action, err error)
- func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS, currentTS uint64) error
- func (mvcc *MVCCLevelDB) Close() error
- func (mvcc *MVCCLevelDB) Commit(keys [][]byte, startTS, commitTS uint64) error
- func (mvcc *MVCCLevelDB) DeleteRange(startKey, endKey []byte) error
- func (mvcc *MVCCLevelDB) GC(startKey, endKey []byte, safePoint uint64) error
- func (mvcc *MVCCLevelDB) Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, ...) ([]byte, error)
- func (mvcc *MVCCLevelDB) MvccGetByKey(key []byte) *kvrpcpb.MvccInfo
- func (mvcc *MVCCLevelDB) MvccGetByStartTS(starTS uint64) (*kvrpcpb.MvccInfo, []byte)
- func (mvcc *MVCCLevelDB) PessimisticLock(req *kvrpcpb.PessimisticLockRequest) *kvrpcpb.PessimisticLockResponse
- func (mvcc *MVCCLevelDB) PessimisticRollback(keys [][]byte, startTS, forUpdateTS uint64) []error
- func (mvcc *MVCCLevelDB) Prewrite(req *kvrpcpb.PrewriteRequest) []error
- func (mvcc *MVCCLevelDB) RawBatchDelete(keys [][]byte)
- func (mvcc *MVCCLevelDB) RawBatchGet(keys [][]byte) [][]byte
- func (mvcc *MVCCLevelDB) RawBatchPut(keys, values [][]byte)
- func (mvcc *MVCCLevelDB) RawDelete(key []byte)
- func (mvcc *MVCCLevelDB) RawDeleteRange(startKey, endKey []byte)
- func (mvcc *MVCCLevelDB) RawGet(key []byte) []byte
- func (mvcc *MVCCLevelDB) RawPut(key, value []byte)
- func (mvcc *MVCCLevelDB) RawReverseScan(startKey, endKey []byte, limit int) []Pair
- func (mvcc *MVCCLevelDB) RawScan(startKey, endKey []byte, limit int) []Pair
- func (mvcc *MVCCLevelDB) ResolveLock(startKey, endKey []byte, startTS, commitTS uint64) error
- func (mvcc *MVCCLevelDB) ReverseScan(startKey, endKey []byte, limit int, startTS uint64, ...) []Pair
- func (mvcc *MVCCLevelDB) Rollback(keys [][]byte, startTS uint64) error
- func (mvcc *MVCCLevelDB) Scan(startKey, endKey []byte, limit int, startTS uint64, ...) []Pair
- func (mvcc *MVCCLevelDB) ScanLock(startKey, endKey []byte, maxTS uint64) ([]*kvrpcpb.LockInfo, error)
- func (mvcc *MVCCLevelDB) TxnHeartBeat(key []byte, startTS uint64, adviseTTL uint64) (uint64, error)
- type MVCCStore
- type MvccKey
- type Pair
- type RPCClient
- type RawKV
- type Region
- type Session
- func (s *Session) CheckRequestContext(ctx *kvrpcpb.Context) *errorpb.Error
- func (s *Session) GetIsolationLevel() kvrpcpb.IsolationLevel
- func (s *Session) GetMVCCStore() MVCCStore
- func (s *Session) GetRawEndKey() []byte
- func (s *Session) GetRawStartKey() []byte
- func (s *Session) GetResolvedLocks() []uint64
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( LockAlwaysWait = int64(0) LockNoWait = int64(-1) )
Used for pessimistic lock wait time these two constants are special for lock protocol with tikv 0 means always wait, -1 means nowait, others meaning lock wait in milliseconds
var ErrInvalidEncodedKey = errors.New("invalid encoded key")
ErrInvalidEncodedKey describes parsing an invalid format of EncodedKey.
var PutMutations = putMutations
PutMutations is exported for testing.
Functions ¶
func BootstrapWithMultiRegions ¶
func BootstrapWithMultiRegions(cluster *Cluster, splitKeys ...[]byte) (storeID uint64, regionIDs, peerIDs []uint64)
BootstrapWithMultiRegions initializes a Cluster with multiple Regions and 1 Store. The number of Regions will be len(splitKeys) + 1.
func BootstrapWithMultiStores ¶
func BootstrapWithMultiStores(cluster *Cluster, n int) (storeIDs, peerIDs []uint64, regionID uint64, leaderPeer uint64)
BootstrapWithMultiStores initializes a Cluster with 1 Region and n Stores.
func BootstrapWithSingleStore ¶
BootstrapWithSingleStore initializes a Cluster with 1 Region and 1 Store.
func MustPrewrite ¶
func MustPrewrite(store MVCCStore, mutations []*kvrpcpb.Mutation, primary string, startTS uint64, ttl uint64) bool
MustPrewrite write mutations to mvcc store.
func NewPDClient ¶
NewPDClient creates a mock pd.Client that uses local timestamp and meta data from a Cluster.
func NewTiKVAndPDClient ¶
func NewTiKVAndPDClient(path string, coprHandler CoprRPCHandler) (*RPCClient, *Cluster, pd.Client, error)
NewTiKVAndPDClient creates a TiKV client and PD client from options.
Types ¶
type Client ¶
type Client interface { // Close should release all data. Close() error // SendRequest sends Request. SendRequest(ctx context.Context, addr string, req *tikvrpc.Request, timeout time.Duration) (*tikvrpc.Response, error) }
Client is a client that sends RPC. This is same with tikv.Client, define again for avoid circle import.
type Cluster ¶
Cluster simulates a TiKV cluster. It focuses on management and the change of meta data. A Cluster mainly includes following 3 kinds of meta data:
- Region: A Region is a fragment of TiKV's data whose range is [start, end). The data of a Region is duplicated to multiple Peers and distributed in multiple Stores.
- Peer: A Peer is a replica of a Region's data. All peers of a Region form a group, each group elects a Leader to provide services.
- Store: A Store is a storage/service node. Try to think it as a TiKV server process. Only the store with request's Region's leader Peer could respond to client's request.
func NewCluster ¶
NewCluster creates an empty cluster. It needs to be bootstrapped before providing service.
func (*Cluster) AddStore ¶
func (c *Cluster) AddStore(storeID uint64, addr string, labels ...*metapb.StoreLabel)
AddStore add a new Store to the cluster.
func (*Cluster) AllocID ¶
AllocID creates an unique ID in cluster. The ID could be used as either StoreID, RegionID, or PeerID.
func (*Cluster) Bootstrap ¶
Bootstrap creates the first Region. The Stores should be in the Cluster before bootstrap.
func (*Cluster) CancelStore ¶
CancelStore makes the store with cancel state true.
func (*Cluster) ChangeLeader ¶
ChangeLeader sets the Region's leader Peer. Caller should guarantee the Peer exists.
func (*Cluster) GetAllRegions ¶
GetAllRegions gets all the regions in the cluster.
func (*Cluster) GetAllStores ¶
GetAllStores returns all Stores' meta.
func (*Cluster) GetAndCheckStoreByAddr ¶
GetAndCheckStoreByAddr checks and returns a Store's meta by an addr
func (*Cluster) GetPrevRegionByKey ¶
GetPrevRegionByKey returns the previous Region and its leader whose range contains the key.
func (*Cluster) GetRegionByID ¶
GetRegionByID returns the Region and its leader whose ID is regionID.
func (*Cluster) GetRegionByKey ¶
GetRegionByKey returns the Region and its leader whose range contains the key.
func (*Cluster) GetStoreByAddr ¶
GetStoreByAddr returns a Store's meta by an addr.
func (*Cluster) GiveUpLeader ¶
GiveUpLeader sets the Region's leader to 0. The Region will have no leader before calling ChangeLeader().
func (*Cluster) MarkTombstone ¶
MarkTombstone marks store as tombstone.
func (*Cluster) RemovePeer ¶
RemovePeer removes the Peer from the Region. Note that if the Peer is leader, the Region will have no leader before calling ChangeLeader().
func (*Cluster) RemoveStore ¶
RemoveStore removes a Store from the cluster.
func (*Cluster) ScanRegions ¶
ScanRegions returns at most `limit` regions from given `key` and their leaders.
func (*Cluster) ScheduleDelay ¶
ScheduleDelay schedules a delay event for a transaction on a region.
func (*Cluster) Split ¶
func (c *Cluster) Split(regionID, newRegionID uint64, key []byte, peerIDs []uint64, leaderPeerID uint64)
Split splits a Region at the key (encoded) and creates new Region.
func (*Cluster) SplitKeys ¶
SplitKeys evenly splits the start, end key into "count" regions. Only works for single store.
func (*Cluster) SplitRaw ¶
func (c *Cluster) SplitRaw(regionID, newRegionID uint64, rawKey []byte, peerIDs []uint64, leaderPeerID uint64) *metapb.Region
SplitRaw splits a Region at the key (not encoded) and creates new Region.
func (*Cluster) StartStore ¶
StartStore starts a store with storeID.
func (*Cluster) UnCancelStore ¶
UnCancelStore makes the store with cancel state false.
func (*Cluster) UpdateStoreAddr ¶
func (c *Cluster) UpdateStoreAddr(storeID uint64, addr string, labels ...*metapb.StoreLabel)
UpdateStoreAddr updates store address for cluster.
func (*Cluster) UpdateStoreLabels ¶
func (c *Cluster) UpdateStoreLabels(storeID uint64, labels []*metapb.StoreLabel)
UpdateStoreLabels merge the target and owned labels together
type CoprRPCHandler ¶
type CoprRPCHandler interface { HandleCmdCop(reqCtx *kvrpcpb.Context, session *Session, r *coprocessor.Request) *coprocessor.Response HandleBatchCop(ctx context.Context, reqCtx *kvrpcpb.Context, session *Session, r *coprocessor.BatchRequest, timeout time.Duration) (*tikvrpc.BatchCopStreamResponse, error) HandleCopStream(ctx context.Context, reqCtx *kvrpcpb.Context, session *Session, r *coprocessor.Request, timeout time.Duration) (*tikvrpc.CopStreamResponse, error) Close() }
CoprRPCHandler is the interface to handle coprocessor RPC commands.
type ErrAbort ¶
type ErrAbort string
ErrAbort means something is wrong and client should abort the txn.
type ErrAlreadyCommitted ¶
type ErrAlreadyCommitted uint64
ErrAlreadyCommitted is returned specially when client tries to rollback a committed lock.
func (ErrAlreadyCommitted) Error ¶
func (e ErrAlreadyCommitted) Error() string
type ErrAlreadyRollbacked ¶
type ErrAlreadyRollbacked struct {
// contains filtered or unexported fields
}
ErrAlreadyRollbacked is returned when lock operation meets rollback write record
func (*ErrAlreadyRollbacked) Error ¶
func (e *ErrAlreadyRollbacked) Error() string
type ErrCommitTSExpired ¶
type ErrCommitTSExpired struct {
kvrpcpb.CommitTsExpired
}
ErrCommitTSExpired is returned when commit.CommitTS < lock.MinCommitTS
func (*ErrCommitTSExpired) Error ¶
func (e *ErrCommitTSExpired) Error() string
type ErrConflict ¶
ErrConflict is returned when the commitTS of key in the DB is greater than startTS.
func (*ErrConflict) Error ¶
func (e *ErrConflict) Error() string
type ErrDeadlock ¶
ErrDeadlock is returned when deadlock error is detected.
func (*ErrDeadlock) Error ¶
func (e *ErrDeadlock) Error() string
type ErrKeyAlreadyExist ¶
type ErrKeyAlreadyExist struct {
Key []byte
}
ErrKeyAlreadyExist is returned when key exists but this key has a constraint that it should not exist. Client should return duplicated entry error.
func (*ErrKeyAlreadyExist) Error ¶
func (e *ErrKeyAlreadyExist) Error() string
type ErrLocked ¶
type ErrLocked struct { Key MvccKey Primary []byte StartTS uint64 ForUpdateTS uint64 TTL uint64 TxnSize uint64 LockType kvrpcpb.Op }
ErrLocked is returned when trying to Read/Write on a locked key. Client should backoff or cleanup the lock then retry.
type ErrRetryable ¶
type ErrRetryable string
ErrRetryable suggests that client may restart the txn.
func (ErrRetryable) Error ¶
func (e ErrRetryable) Error() string
type ErrTxnNotFound ¶
type ErrTxnNotFound struct {
kvrpcpb.TxnNotFound
}
ErrTxnNotFound is returned when the primary lock of the txn is not found.
func (*ErrTxnNotFound) Error ¶
func (e *ErrTxnNotFound) Error() string
type Iterator ¶
Iterator wraps iterator.Iterator to provide Valid() method.
type MVCCDebugger ¶
type MVCCDebugger interface { MvccGetByStartTS(starTS uint64) (*kvrpcpb.MvccInfo, []byte) MvccGetByKey(key []byte) *kvrpcpb.MvccInfo }
MVCCDebugger is for debugging.
type MVCCLevelDB ¶
type MVCCLevelDB struct {
// contains filtered or unexported fields
}
MVCCLevelDB implements the MVCCStore interface.
func NewMVCCLevelDB ¶
func NewMVCCLevelDB(path string) (*MVCCLevelDB, error)
NewMVCCLevelDB returns a new MVCCLevelDB object.
func (*MVCCLevelDB) BatchGet ¶
func (mvcc *MVCCLevelDB) BatchGet(ks [][]byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) []Pair
BatchGet implements the MVCCStore interface.
func (*MVCCLevelDB) BatchResolveLock ¶
func (mvcc *MVCCLevelDB) BatchResolveLock(startKey, endKey []byte, txnInfos map[uint64]uint64) error
BatchResolveLock implements the MVCCStore interface.
func (*MVCCLevelDB) CheckTxnStatus ¶
func (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS, currentTS uint64, rollbackIfNotExist bool, resolvingPessimisticLock bool) (ttl uint64, commitTS uint64, action kvrpcpb.Action, err error)
CheckTxnStatus checks the primary lock of a transaction to decide its status. The return values are (ttl, commitTS, err): If the transaction is active, this function returns the ttl of the lock; If the transaction is committed, this function returns the commitTS; If the transaction is rollbacked, this function returns (0, 0, nil) Note that CheckTxnStatus may also push forward the `minCommitTS` of the transaction, so it's not simply a read-only operation.
primaryKey + lockTS together could locate the primary lock. callerStartTS is the start ts of reader transaction. currentTS is the current ts, but it may be inaccurate. Just use it to check TTL.
func (*MVCCLevelDB) Cleanup ¶
func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS, currentTS uint64) error
Cleanup implements the MVCCStore interface. Cleanup API is deprecated, use CheckTxnStatus instead.
func (*MVCCLevelDB) Close ¶
func (mvcc *MVCCLevelDB) Close() error
Close calls leveldb's Close to free resources.
func (*MVCCLevelDB) Commit ¶
func (mvcc *MVCCLevelDB) Commit(keys [][]byte, startTS, commitTS uint64) error
Commit implements the MVCCStore interface.
func (*MVCCLevelDB) DeleteRange ¶
func (mvcc *MVCCLevelDB) DeleteRange(startKey, endKey []byte) error
DeleteRange implements the MVCCStore interface.
func (*MVCCLevelDB) GC ¶
func (mvcc *MVCCLevelDB) GC(startKey, endKey []byte, safePoint uint64) error
GC implements the MVCCStore interface
func (*MVCCLevelDB) Get ¶
func (mvcc *MVCCLevelDB) Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) ([]byte, error)
Get implements the MVCCStore interface. key cannot be nil or []byte{}
func (*MVCCLevelDB) MvccGetByKey ¶
func (mvcc *MVCCLevelDB) MvccGetByKey(key []byte) *kvrpcpb.MvccInfo
MvccGetByKey implements the MVCCDebugger interface.
func (*MVCCLevelDB) MvccGetByStartTS ¶
func (mvcc *MVCCLevelDB) MvccGetByStartTS(starTS uint64) (*kvrpcpb.MvccInfo, []byte)
MvccGetByStartTS implements the MVCCDebugger interface.
func (*MVCCLevelDB) PessimisticLock ¶
func (mvcc *MVCCLevelDB) PessimisticLock(req *kvrpcpb.PessimisticLockRequest) *kvrpcpb.PessimisticLockResponse
PessimisticLock writes the pessimistic lock.
func (*MVCCLevelDB) PessimisticRollback ¶
func (mvcc *MVCCLevelDB) PessimisticRollback(keys [][]byte, startTS, forUpdateTS uint64) []error
PessimisticRollback implements the MVCCStore interface.
func (*MVCCLevelDB) Prewrite ¶
func (mvcc *MVCCLevelDB) Prewrite(req *kvrpcpb.PrewriteRequest) []error
Prewrite implements the MVCCStore interface.
func (*MVCCLevelDB) RawBatchDelete ¶
func (mvcc *MVCCLevelDB) RawBatchDelete(keys [][]byte)
RawBatchDelete implements the RawKV interface.
func (*MVCCLevelDB) RawBatchGet ¶
func (mvcc *MVCCLevelDB) RawBatchGet(keys [][]byte) [][]byte
RawBatchGet implements the RawKV interface.
func (*MVCCLevelDB) RawBatchPut ¶
func (mvcc *MVCCLevelDB) RawBatchPut(keys, values [][]byte)
RawBatchPut implements the RawKV interface
func (*MVCCLevelDB) RawDelete ¶
func (mvcc *MVCCLevelDB) RawDelete(key []byte)
RawDelete implements the RawKV interface.
func (*MVCCLevelDB) RawDeleteRange ¶
func (mvcc *MVCCLevelDB) RawDeleteRange(startKey, endKey []byte)
RawDeleteRange implements the RawKV interface.
func (*MVCCLevelDB) RawGet ¶
func (mvcc *MVCCLevelDB) RawGet(key []byte) []byte
RawGet implements the RawKV interface.
func (*MVCCLevelDB) RawPut ¶
func (mvcc *MVCCLevelDB) RawPut(key, value []byte)
RawPut implements the RawKV interface.
func (*MVCCLevelDB) RawReverseScan ¶
func (mvcc *MVCCLevelDB) RawReverseScan(startKey, endKey []byte, limit int) []Pair
RawReverseScan implements the RawKV interface. Scan the range of [endKey, startKey) It doesn't support Scanning from "", because locating the last Region is not yet implemented.
func (*MVCCLevelDB) RawScan ¶
func (mvcc *MVCCLevelDB) RawScan(startKey, endKey []byte, limit int) []Pair
RawScan implements the RawKV interface.
func (*MVCCLevelDB) ResolveLock ¶
func (mvcc *MVCCLevelDB) ResolveLock(startKey, endKey []byte, startTS, commitTS uint64) error
ResolveLock implements the MVCCStore interface.
func (*MVCCLevelDB) ReverseScan ¶
func (mvcc *MVCCLevelDB) ReverseScan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) []Pair
ReverseScan implements the MVCCStore interface. The search range is [startKey, endKey).
func (*MVCCLevelDB) Rollback ¶
func (mvcc *MVCCLevelDB) Rollback(keys [][]byte, startTS uint64) error
Rollback implements the MVCCStore interface.
func (*MVCCLevelDB) Scan ¶
func (mvcc *MVCCLevelDB) Scan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLock []uint64) []Pair
Scan implements the MVCCStore interface.
func (*MVCCLevelDB) ScanLock ¶
func (mvcc *MVCCLevelDB) ScanLock(startKey, endKey []byte, maxTS uint64) ([]*kvrpcpb.LockInfo, error)
ScanLock implements the MVCCStore interface.
func (*MVCCLevelDB) TxnHeartBeat ¶
TxnHeartBeat implements the MVCCStore interface.
type MVCCStore ¶
type MVCCStore interface { Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) ([]byte, error) Scan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) []Pair ReverseScan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) []Pair BatchGet(ks [][]byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel, resolvedLocks []uint64) []Pair PessimisticLock(req *kvrpcpb.PessimisticLockRequest) *kvrpcpb.PessimisticLockResponse PessimisticRollback(keys [][]byte, startTS, forUpdateTS uint64) []error Prewrite(req *kvrpcpb.PrewriteRequest) []error Commit(keys [][]byte, startTS, commitTS uint64) error Rollback(keys [][]byte, startTS uint64) error Cleanup(key []byte, startTS, currentTS uint64) error ScanLock(startKey, endKey []byte, maxTS uint64) ([]*kvrpcpb.LockInfo, error) TxnHeartBeat(primaryKey []byte, startTS uint64, adviseTTL uint64) (uint64, error) ResolveLock(startKey, endKey []byte, startTS, commitTS uint64) error BatchResolveLock(startKey, endKey []byte, txnInfos map[uint64]uint64) error GC(startKey, endKey []byte, safePoint uint64) error DeleteRange(startKey, endKey []byte) error CheckTxnStatus(primaryKey []byte, lockTS uint64, startTS, currentTS uint64, rollbackIfNotFound bool, resolvingPessimisticLock bool) (uint64, uint64, kvrpcpb.Action, error) Close() error }
MVCCStore is a mvcc key-value storage.
func MustNewMVCCStore ¶
func MustNewMVCCStore() MVCCStore
MustNewMVCCStore is used for testing, use NewMVCCLevelDB instead.
type MvccKey ¶
type MvccKey []byte
MvccKey is the encoded key type. On TiKV, keys are encoded before they are saved into storage engine.
type RPCClient ¶
type RPCClient struct { Cluster *Cluster MvccStore MVCCStore // contains filtered or unexported fields }
RPCClient sends kv RPC calls to mock cluster. RPCClient mocks the behavior of a rpc client at tikv's side.
func NewRPCClient ¶
func NewRPCClient(cluster *Cluster, mvccStore MVCCStore, coprHandler CoprRPCHandler) *RPCClient
NewRPCClient creates an RPCClient. Note that close the RPCClient may close the underlying MvccStore.
type RawKV ¶
type RawKV interface { RawGet(key []byte) []byte RawBatchGet(keys [][]byte) [][]byte RawScan(startKey, endKey []byte, limit int) []Pair // Scan the range of [startKey, endKey) RawReverseScan(startKey, endKey []byte, limit int) []Pair // Scan the range of [endKey, startKey) RawPut(key, value []byte) RawBatchPut(keys, values [][]byte) RawDelete(key []byte) RawBatchDelete(keys [][]byte) RawDeleteRange(startKey, endKey []byte) }
RawKV is a key-value storage. MVCCStore can be implemented upon it with timestamp encoded into key.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session stores session scope rpc data.
func (*Session) CheckRequestContext ¶
CheckRequestContext checks if the context matches the request status.
func (*Session) GetIsolationLevel ¶
func (s *Session) GetIsolationLevel() kvrpcpb.IsolationLevel
GetIsolationLevel returns the session's isolation level.
func (*Session) GetMVCCStore ¶
GetMVCCStore returns the mock mvcc store.
func (*Session) GetRawEndKey ¶
GetRawEndKey returns the raw end key of the request.
func (*Session) GetRawStartKey ¶
GetRawStartKey returns the raw start key of the request.
func (*Session) GetResolvedLocks ¶
GetResolvedLocks returns the resolved locks of the request.