Documentation ¶
Index ¶
- type Cluster
- func (c *Cluster) AddPeer(regionID, storeID uint64)
- func (c *Cluster) AddStore(storeID uint64, addr string)
- func (c *Cluster) AllocID() uint64
- func (c *Cluster) AllocIDs(n int) []uint64
- func (c *Cluster) Bootstrap(regionID uint64, storeIDs []uint64, leaderStoreID uint64)
- func (c *Cluster) ChangeLeader(regionID, leaderStoreID uint64)
- func (c *Cluster) GetRegion(regionID uint64) (*metapb.Region, uint64)
- func (c *Cluster) GetRegionByKey(key []byte) *metapb.Region
- 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) RemovePeer(regionID, storeID uint64)
- func (c *Cluster) RemoveStore(storeID uint64)
- func (c *Cluster) Split(regionID, newRegionID uint64, key []byte, leaderStoreID uint64)
- type ErrAbort
- type ErrAlreadyCommitted
- type ErrLocked
- type ErrRetryable
- type MvccStore
- func (s *MvccStore) BatchGet(ks [][]byte, startTS uint64) []Pair
- func (s *MvccStore) Cleanup(key []byte, startTS uint64) error
- func (s *MvccStore) Commit(keys [][]byte, startTS, commitTS uint64) error
- func (s *MvccStore) CommitThenGet(key []byte, lockTS, commitTS, getTS uint64) ([]byte, error)
- func (s *MvccStore) Get(key []byte, startTS uint64) ([]byte, error)
- func (s *MvccStore) Prewrite(mutations []*kvrpcpb.Mutation, primary []byte, startTS uint64) []error
- func (s *MvccStore) Rollback(keys [][]byte, startTS uint64) error
- func (s *MvccStore) RollbackThenGet(key []byte, lockTS uint64) ([]byte, error)
- func (s *MvccStore) Scan(startKey, endKey []byte, limit int, startTS uint64) []Pair
- type Pair
- type Region
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster struct {
// contains filtered or unexported fields
}
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 ¶
func NewCluster() *Cluster
NewCluster creates an empty cluster. It needs to be bootstrapped before providing service.
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) ChangeLeader ¶
ChangeLeader sets the Region's leader Peer. Caller should guarantee the Peer exists.
func (*Cluster) GetRegionByKey ¶
GetRegionByKey returns the Region 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) 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.
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 ErrLocked ¶
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. e.g. write conflict.
func (ErrRetryable) Error ¶
func (e ErrRetryable) Error() string
type MvccStore ¶
type MvccStore struct {
// contains filtered or unexported fields
}
MvccStore is an in-memory, multi-versioned, transaction-supported kv storage.
func (*MvccStore) CommitThenGet ¶
CommitThenGet is a shortcut for Commit+Get, often used when resolving lock.
func (*MvccStore) Rollback ¶
Rollback cleanups multiple locks, often used when rolling back a conflict txn.
func (*MvccStore) RollbackThenGet ¶
RollbackThenGet is a shortcut for Rollback+Get, often used when resolving lock.