Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeBytes(b []byte, buf []byte) ([]byte, []byte, error)
- func DecodeUintDesc(b []byte) ([]byte, uint64, error)
- func EncodeBytes(b []byte, data []byte) []byte
- func EncodeUintDesc(b []byte, v uint64) []byte
- func ExtractPhysical(ts uint64) int64
- func InitFileLog(cfg *log.FileLogConfig) error
- func InitLogger(cfg *log.Config) error
- func LogPanic()
- type Config
- type ErrAbort
- type ErrAlreadyCommitted
- type ErrLocked
- type ErrRetryable
- 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) (uint64, uint64, error)
- func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS 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) Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel) ([]byte, error)
- func (mvcc *MVCCLevelDB) Prewrite(mutations []*kvrpcpb.Mutation, primary []byte, startTS uint64, ttl uint64) []error
- func (mvcc *MVCCLevelDB) RawBatchDelete(keys [][]byte)
- func (mvcc *MVCCLevelDB) RawBatchGet(keys [][]byte) []Pair
- 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) 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)
- type MVCCStore
- type MvccKey
- type Pair
- type RawKV
- type Server
- func (s *Server) CreateCluster(cluster *api.Cluster) (*api.Cluster, error)
- func (s *Server) DeleteCluster(id uint64)
- func (s *Server) DeleteStoreFailPoint(clusterID, storeID uint64, failPoint string) (interface{}, error)
- func (s *Server) GetCluster(id uint64) *api.Cluster
- func (s *Server) GetClusterStore(clusterID, storeID uint64) (*api.Store, error)
- func (s *Server) GetClusterStores(clusterID uint64) ([]*api.Store, error)
- func (s *Server) GetClusters() []*api.Cluster
- func (s *Server) GetStoreFailPoint(clusterID, storeID uint64, failPoint string) (interface{}, error)
- func (s *Server) GetStoreFailPoints(clusterID, storeID uint64) (map[string]interface{}, error)
- func (s *Server) UpdateStoreFailPoint(clusterID, storeID uint64, failPoint, value string) (interface{}, error)
Constants ¶
const (
IOFailPoint = "io-timeout"
)
Variables ¶
var ErrInvalidEncodedKey = errors.New("invalid encoded key")
ErrInvalidEncodedKey describes parsing an invalid format of EncodedKey.
Functions ¶
func DecodeBytes ¶
DecodeBytes decodes bytes which is encoded by EncodeBytes before, returns the leftover bytes and decoded value if no error. `buf` is used to buffer data to avoid the cost of makeslice in decodeBytes when DecodeBytes is called by Decoder.DecodeOne.
func DecodeUintDesc ¶
DecodeUintDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.
func EncodeBytes ¶
EncodeBytes guarantees the encoded value is in ascending order for comparison, encoding with the following rule:
[group1][marker1]...[groupN][markerN] group is 8 bytes slice which is padding with 0. marker is `0xFF - padding 0 count`
For example:
[] -> [0, 0, 0, 0, 0, 0, 0, 0, 247] [1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250] [1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251] [1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]
Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format
func EncodeUintDesc ¶
EncodeUintDesc appends the encoded value to slice b and returns the appended slice. EncodeUintDesc guarantees that the encoded value is in descending order for comparison.
func ExtractPhysical ¶
func InitFileLog ¶
func InitFileLog(cfg *log.FileLogConfig) error
InitFileLog initializes file based logging options.
Types ¶
type Config ¶
type Config struct { *flag.FlagSet `json:"-"` ClientEndpoint string `toml:"client-endpoint" json:"client-endpoint"` // Log related config. Log log.Config `toml:"log" json:"log"` // contains filtered or unexported fields }
Config is the mock tikv server configuration
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 Iterator ¶
Iterator wraps iterator.Iterator to provide Valid() method.
type MVCCDebugger ¶
type MVCCDebugger interface { MvccGetByStartTS(startKey, endKey []byte, 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) []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 (*MVCCLevelDB) Cleanup ¶
func (mvcc *MVCCLevelDB) Cleanup(key []byte, startTS uint64) error
Cleanup implements the MVCCStore interface.
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) Get ¶
func (mvcc *MVCCLevelDB) Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel) ([]byte, error)
Get implements the MVCCStore interface. key cannot be nil or []byte{}
func (*MVCCLevelDB) Prewrite ¶
func (mvcc *MVCCLevelDB) Prewrite(mutations []*kvrpcpb.Mutation, primary []byte, startTS uint64, ttl uint64) []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) []Pair
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) 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) []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) []Pair
Scan implements the MVCCStore interface.
type MVCCStore ¶
type MVCCStore interface { Get(key []byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel) ([]byte, error) Scan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel) []Pair ReverseScan(startKey, endKey []byte, limit int, startTS uint64, isoLevel kvrpcpb.IsolationLevel) []Pair BatchGet(ks [][]byte, startTS uint64, isoLevel kvrpcpb.IsolationLevel) []Pair Prewrite(mutations []*kvrpcpb.Mutation, primary []byte, startTS uint64, ttl uint64) []error Commit(keys [][]byte, startTS, commitTS uint64) error Rollback(keys [][]byte, startTS uint64) error Cleanup(key []byte, startTS uint64) error ScanLock(startKey, endKey []byte, maxTS uint64) ([]*kvrpcpb.LockInfo, error) ResolveLock(startKey, endKey []byte, startTS, commitTS uint64) error BatchResolveLock(startKey, endKey []byte, txnInfos map[uint64]uint64) error DeleteRange(startKey, endKey []byte) 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 RawKV ¶
type RawKV interface { RawGet(key []byte) []byte RawBatchGet(keys [][]byte) []Pair RawScan(startKey, endKey []byte, limit int) []Pair 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 Server ¶
Server is the mock tikv server.
func CreateServer ¶
CreateServer creates the mock tikv server with given configuration.
func (*Server) CreateCluster ¶
CreateCluster adds and starts a new tikv cluster with given spec.
func (*Server) DeleteCluster ¶
DeleteCluster stops and deletes a cluster by id
func (*Server) DeleteStoreFailPoint ¶
func (s *Server) DeleteStoreFailPoint(clusterID, storeID uint64, failPoint string) (interface{}, error)
DeleteStoreFailPoint Disable a particular fail point
func (*Server) GetCluster ¶
GetCluster returns current state of tikv cluster with given id
func (*Server) GetClusterStore ¶
GetClusterStore returns current state of tikv store of a cluster with given id
func (*Server) GetClusterStores ¶
GetClusterStores returns current state of tikv stores of a cluster
func (*Server) GetClusters ¶
GetClusters returns all currently available tikv clusters
func (*Server) GetStoreFailPoint ¶
func (s *Server) GetStoreFailPoint(clusterID, storeID uint64, failPoint string) (interface{}, error)
GetStoreFailPoint returns given fail point of a store
func (*Server) GetStoreFailPoints ¶
GetStoreFailPoints returns all fail points of a store