server

package
v0.0.0-...-60d5921 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: Apache-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IOFailPoint = "io-timeout"
)

Variables

View Source
var ErrInvalidEncodedKey = errors.New("invalid encoded key")

ErrInvalidEncodedKey describes parsing an invalid format of EncodedKey.

Functions

func DecodeBytes

func DecodeBytes(b []byte, buf []byte) ([]byte, []byte, error)

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

func DecodeUintDesc(b []byte) ([]byte, uint64, error)

DecodeUintDesc decodes value encoded by EncodeInt before. It returns the leftover un-decoded slice, decoded value if no error.

func EncodeBytes

func EncodeBytes(b []byte, data []byte) []byte

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

func EncodeUintDesc(b []byte, v uint64) []byte

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 ExtractPhysical(ts uint64) int64

func InitFileLog

func InitFileLog(cfg *log.FileLogConfig) error

InitFileLog initializes file based logging options.

func InitLogger

func InitLogger(cfg *log.Config) error

InitLogger initializes PD's logger.

func LogPanic

func LogPanic()

LogPanic logs the panic reason and stack, then exit the process. Commonly used with a `defer`.

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

func NewConfig

func NewConfig() *Config

NewConfig creates a new config.

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     MvccKey
	Primary []byte
	StartTS uint64
	TTL     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 Iterator

type Iterator struct {
	iterator.Iterator
	// contains filtered or unexported fields
}

Iterator wraps iterator.Iterator to provide Valid() method.

func (*Iterator) Next

func (iter *Iterator) Next()

Next moves the iterator to the next key/value pair.

func (*Iterator) Valid

func (iter *Iterator) Valid() bool

Valid returns whether the iterator is exhausted.

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 (mvcc *MVCCLevelDB) CheckTxnStatus(primaryKey []byte, lockTS, callerStartTS, currentTS uint64) (uint64, uint64, error)

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.

func (*MVCCLevelDB) ScanLock

func (mvcc *MVCCLevelDB) ScanLock(startKey, endKey []byte, maxTS uint64) ([]*kvrpcpb.LockInfo, error)

ScanLock 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.

func NewMvccKey

func NewMvccKey(key []byte) MvccKey

NewMvccKey encodes a key into MvccKey.

func (MvccKey) Raw

func (key MvccKey) Raw() []byte

Raw decodes a MvccKey to original key.

type Pair

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

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

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

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Server is the mock tikv server.

func CreateServer

func CreateServer(cfg *Config) (s *Server, err error)

CreateServer creates the mock tikv server with given configuration.

func (*Server) CreateCluster

func (s *Server) CreateCluster(cluster *api.Cluster) (*api.Cluster, error)

CreateCluster adds and starts a new tikv cluster with given spec.

func (*Server) DeleteCluster

func (s *Server) DeleteCluster(id uint64)

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

func (s *Server) GetCluster(id uint64) *api.Cluster

GetCluster returns current state of tikv cluster with given id

func (*Server) GetClusterStore

func (s *Server) GetClusterStore(clusterID, storeID uint64) (*api.Store, error)

GetClusterStore returns current state of tikv store of a cluster with given id

func (*Server) GetClusterStores

func (s *Server) GetClusterStores(clusterID uint64) ([]*api.Store, error)

GetClusterStores returns current state of tikv stores of a cluster

func (*Server) GetClusters

func (s *Server) GetClusters() []*api.Cluster

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

func (s *Server) GetStoreFailPoints(clusterID, storeID uint64) (map[string]interface{}, error)

GetStoreFailPoints returns all fail points of a store

func (*Server) UpdateStoreFailPoint

func (s *Server) UpdateStoreFailPoint(clusterID, storeID uint64, failPoint, value string) (interface{}, error)

UpdateStoreFailPoint Update value of a particular fail point

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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