mocktikv

package
v0.0.0-...-887f819 Latest Latest
Warning

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

Go to latest
Published: May 4, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

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:

  1. 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.
  2. 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.
  3. 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) AddPeer

func (c *Cluster) AddPeer(regionID, storeID uint64)

AddPeer adds a new Peer for the Region on the Store.

func (*Cluster) AddStore

func (c *Cluster) AddStore(storeID uint64, addr string)

AddStore add a new Store to the cluster.

func (*Cluster) AllocID

func (c *Cluster) AllocID() uint64

AllocID creates an unique ID in cluster. The ID could be used as either StoreID, RegionID, or PeerID.

func (*Cluster) AllocIDs

func (c *Cluster) AllocIDs(n int) []uint64

AllocIDs creates multiple IDs.

func (*Cluster) Bootstrap

func (c *Cluster) Bootstrap(regionID uint64, storeIDs []uint64, leaderStoreID uint64)

Bootstrap creates the first Region. The Stores should be in the Cluster before bootstrap.

func (*Cluster) ChangeLeader

func (c *Cluster) ChangeLeader(regionID, leaderStoreID uint64)

ChangeLeader sets the Region's leader Peer. Caller should guarantee the Peer exists.

func (*Cluster) GetRegion

func (c *Cluster) GetRegion(regionID uint64) (*metapb.Region, uint64)

GetRegion returns a Region's meta and leader ID.

func (*Cluster) GetRegionByKey

func (c *Cluster) GetRegionByKey(key []byte) *metapb.Region

GetRegionByKey returns the Region whose range contains the key.

func (*Cluster) GetStore

func (c *Cluster) GetStore(storeID uint64) *metapb.Store

GetStore returns a Store's meta.

func (*Cluster) GetStoreByAddr

func (c *Cluster) GetStoreByAddr(addr string) *metapb.Store

GetStoreByAddr returns a Store's meta by an addr.

func (*Cluster) GiveUpLeader

func (c *Cluster) GiveUpLeader(regionID uint64)

GiveUpLeader sets the Region's leader to 0. The Region will have no leader before calling ChangeLeader().

func (*Cluster) RemovePeer

func (c *Cluster) RemovePeer(regionID, storeID uint64)

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

func (c *Cluster) RemoveStore(storeID uint64)

RemoveStore removes a Store from the cluster.

func (*Cluster) Split

func (c *Cluster) Split(regionID, newRegionID uint64, key []byte, leaderStoreID uint64)

Split splits a Region at the key and creates new Region.

type ErrAbort

type ErrAbort string

ErrAbort means something is wrong and client should abort the txn.

func (ErrAbort) Error

func (e ErrAbort) Error() string

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

type ErrLocked struct {
	Key     []byte
	Primary []byte
	StartTS uint64
}

ErrLocked is returned when trying to Read/Write on a locked key. Client should backoff or cleanup the lock then retry.

func (*ErrLocked) Error

func (e *ErrLocked) Error() string

Error formats the lock to a string.

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 NewMvccStore

func NewMvccStore() *MvccStore

NewMvccStore creates a MvccStore.

func (*MvccStore) BatchGet

func (s *MvccStore) BatchGet(ks [][]byte, startTS uint64) []Pair

BatchGet gets values with keys and ts.

func (*MvccStore) Cleanup

func (s *MvccStore) Cleanup(key []byte, startTS uint64) error

Cleanup cleanups a lock, often used when resolving a expired lock.

func (*MvccStore) Commit

func (s *MvccStore) Commit(keys [][]byte, startTS, commitTS uint64) error

Commit commits the lock on a key. (2nd phase of 2PC).

func (*MvccStore) CommitThenGet

func (s *MvccStore) CommitThenGet(key []byte, lockTS, commitTS, getTS uint64) ([]byte, error)

CommitThenGet is a shortcut for Commit+Get, often used when resolving lock.

func (*MvccStore) Get

func (s *MvccStore) Get(key []byte, startTS uint64) ([]byte, error)

Get reads a key by ts.

func (*MvccStore) Prewrite

func (s *MvccStore) Prewrite(mutations []*kvrpcpb.Mutation, primary []byte, startTS uint64) []error

Prewrite acquires a lock on a key. (1st phase of 2PC).

func (*MvccStore) Rollback

func (s *MvccStore) Rollback(keys [][]byte, startTS uint64) error

Rollback cleanups multiple locks, often used when rolling back a conflict txn.

func (*MvccStore) RollbackThenGet

func (s *MvccStore) RollbackThenGet(key []byte, lockTS uint64) ([]byte, error)

RollbackThenGet is a shortcut for Rollback+Get, often used when resolving lock.

func (*MvccStore) Scan

func (s *MvccStore) Scan(startKey, endKey []byte, limit int, startTS uint64) []Pair

Scan reads up to limit numbers of Pairs from a key.

type Pair

type Pair struct {
	Key   []byte
	Value []byte
	Err   error
}

A Pair is a KV pair read from MvccStore or an error if any occurs.

type Region

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

Region is the Region meta data.

type Store

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

Store is the Store's meta data.

Jump to

Keyboard shortcuts

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