tikv

package
v0.0.0-...-40faf7d Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2016 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package tikv provides tcp connection to kvserver.

Index

Constants

View Source
const (
	// NoJitter makes the backoff sequence strict exponential.
	NoJitter = 1 + iota
	// FullJitter applies random factors to strict exponential.
	FullJitter
	// EqualJitter is also randomized, but prevents very short sleeps.
	EqualJitter
	// DecorrJitter increases the maximum jitter based on the last random value.
	DecorrJitter
)

Variables

This section is empty.

Functions

func NewBackoffFn

func NewBackoffFn(base, cap, jitter int) func() int

NewBackoffFn creates a backoff func which implements exponential backoff with optional jitters. See http://www.awsarchitectureblog.com/2015/03/backoff.html

func NewMockTikvStore

func NewMockTikvStore() (kv.Storage, error)

NewMockTikvStore creates a mocked tikv store.

Types

type Backoffer

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

Backoffer is a utility for retrying queries.

func NewBackoffer

func NewBackoffer(maxSleep int, ctx context.Context) *Backoffer

NewBackoffer creates a Backoffer with maximum sleep time(in ms).

func (*Backoffer) Backoff

func (b *Backoffer) Backoff(typ backoffType, err error) error

Backoff sleeps a while base on the backoffType and records the error message. It returns a retryable error if total sleep time exceeds maxSleep.

func (*Backoffer) Fork

func (b *Backoffer) Fork() *Backoffer

Fork creates a new Backoffer which keeps current Backoffer's sleep time and errors.

func (*Backoffer) WithCancel

func (b *Backoffer) WithCancel() context.CancelFunc

WithCancel returns a cancel function which, when called, would cancel backoffer's context.

type Client

type Client interface {
	// Close should release all data.
	Close() error
	// SendKVReq sends kv request.
	SendKVReq(addr string, req *kvrpcpb.Request, timeout time.Duration) (*kvrpcpb.Response, error)
	// SendCopReq sends coprocessor request.
	SendCopReq(addr string, req *coprocessor.Request, timeout time.Duration) (*coprocessor.Response, error)
}

Client is a client that sends RPC. It should not be used after calling Close().

type Conn

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

Conn is a simple wrapper of net.Conn.

func NewConnection

func NewConnection(addr string, dialTimeout time.Duration) (*Conn, error)

NewConnection creates a Conn with dial timeout.

func NewConnectionWithSize

func NewConnectionWithSize(addr string, dialTimeout time.Duration, readSize int, writeSize int) (*Conn, error)

NewConnectionWithSize creates a Conn with dial timeout and read/write buffer size.

func (*Conn) BufioReader

func (c *Conn) BufioReader() *bufio.Reader

BufioReader returns a bufio.Reader for writing.

func (*Conn) Close

func (c *Conn) Close()

Close closes the net.Conn.

func (*Conn) Flush

func (c *Conn) Flush() error

Flush writes buffered data to net.Conn.

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls.

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls.

func (*Conn) Write

func (c *Conn) Write(p []byte) (int, error)

Write writes data to the bufio.Writer.

type CopClient

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

CopClient is coprocessor client.

func (*CopClient) Send

func (c *CopClient) Send(req *kv.Request) kv.Response

Send builds the request and gets the coprocessor iterator response.

func (*CopClient) SupportRequestType

func (c *CopClient) SupportRequestType(reqType, subType int64) bool

SupportRequestType checks whether reqType is supported.

type Driver

type Driver struct {
}

Driver implements engine Driver.

func (Driver) Open

func (d Driver) Open(path string) (kv.Storage, error)

Open opens or creates an TiKV storage with given path. Path example: tikv://etcd-node1:port,etcd-node2:port?cluster=1&disableGC=false

type GCWorker

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

GCWorker periodically triggers GC process on tikv server.

func NewGCWorker

func NewGCWorker(store kv.Storage) (*GCWorker, error)

NewGCWorker creates a GCWorker instance.

func (*GCWorker) Close

func (w *GCWorker) Close()

Close stops backgroud goroutines.

func (*GCWorker) DoGC

func (w *GCWorker) DoGC(safePoint uint64) error

DoGC sends GC command to KV, it is exported for testing purpose.

type Lock

type Lock struct {
	Key     []byte
	Primary []byte
	TxnID   uint64
	TTL     uint64
}

Lock represents a lock from tikv server.

type LockResolver

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

LockResolver resolves locks and also caches resolved txn status.

func NewLockResolver

func NewLockResolver(etcdAddrs []string) (*LockResolver, error)

NewLockResolver creates a LockResolver.

func (*LockResolver) GetTxnStatus

func (lr *LockResolver) GetTxnStatus(txnID uint64, primary []byte) (TxnStatus, error)

GetTxnStatus queries tikv-server for a txn's status (commit/rollback). If the primary key is still locked, it will launch a Rollback to abort it. To avoid unnecessarily aborting too many txns, it is wiser to wait a few seconds before calling it after Prewrite.

func (*LockResolver) ResolveLocks

func (lr *LockResolver) ResolveLocks(bo *Backoffer, locks []*Lock) (ok bool, err error)

ResolveLocks tries to resolve Locks. The resolving process is in 3 steps:

  1. Use the `lockTTL` to pick up all expired locks. Only locks that are too old are considered orphan locks and will be handled later. If all locks are expired then all locks will be resolved so the returned `ok` will be true, otherwise caller should sleep a while before retry.
  2. For each lock, query the primary key to get txn(which left the lock)'s commit status.
  3. Send `ResolveLock` cmd to the lock's region to resolve all locks belong to the same transaction.

type Pool

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

Pool is a TCP connection pool that maintains connections with a specific addr.

func NewPool

func NewPool(addr string, capability int, f createConnFunc) *Pool

NewPool creates a Pool.

func (*Pool) Close

func (p *Pool) Close()

Close closes the pool.

func (*Pool) GetConn

func (p *Pool) GetConn() (*Conn, error)

GetConn takes a connection out of the pool.

func (*Pool) PutConn

func (p *Pool) PutConn(c *Conn)

PutConn puts a connection back to the pool.

type Pools

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

Pools maintains connections with multiple addrs.

func NewPools

func NewPools(capability int, f createConnFunc) *Pools

NewPools creates a Pools. It maintains a Pool for each address, and each Pool has the same capability.

func (*Pools) Close

func (p *Pools) Close()

Close closes the pool.

func (*Pools) GetConn

func (p *Pools) GetConn(addr string) (*Conn, error)

GetConn takes a connection out of the pool by addr.

func (*Pools) PutConn

func (p *Pools) PutConn(c *Conn)

PutConn puts a connection back to the pool.

type Region

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

Region stores region info. Region is a readonly class.

func (*Region) Clone

func (r *Region) Clone() *Region

Clone returns a copy of Region.

func (*Region) Contains

func (r *Region) Contains(key []byte) bool

Contains checks whether the key is in the region, for the maximum region endKey is empty. startKey <= key < endKey.

func (*Region) EndKey

func (r *Region) EndKey() []byte

EndKey returns EndKey.

func (*Region) GetAddress

func (r *Region) GetAddress() string

GetAddress returns address.

func (*Region) GetContext

func (r *Region) GetContext() *kvrpcpb.Context

GetContext constructs kvprotopb.Context from region info.

func (*Region) GetID

func (r *Region) GetID() uint64

GetID returns id.

func (*Region) NextPeer

func (r *Region) NextPeer() (*metapb.Peer, error)

NextPeer picks next peer as leader, if out of range return error.

func (*Region) StartKey

func (r *Region) StartKey() []byte

StartKey returns StartKey.

func (*Region) VerID

func (r *Region) VerID() RegionVerID

VerID returns the Region's RegionVerID.

type RegionCache

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

RegionCache caches Regions loaded from PD.

func NewRegionCache

func NewRegionCache(pdClient pd.Client) *RegionCache

NewRegionCache creates a RegionCache.

func (*RegionCache) DropRegion

func (c *RegionCache) DropRegion(id RegionVerID)

DropRegion removes a cached Region.

func (*RegionCache) GetRegion

func (c *RegionCache) GetRegion(bo *Backoffer, key []byte) (*Region, error)

GetRegion find in cache, or get new region.

func (*RegionCache) GetRegionByVerID

func (c *RegionCache) GetRegionByVerID(id RegionVerID) *Region

GetRegionByVerID finds a Region by Region's verID.

func (*RegionCache) GroupKeysByRegion

func (c *RegionCache) GroupKeysByRegion(bo *Backoffer, keys [][]byte) (map[RegionVerID][][]byte, RegionVerID, error)

GroupKeysByRegion separates keys into groups by their belonging Regions. Specially it also returns the first key's region which may be used as the 'PrimaryLockKey' and should be committed ahead of others.

func (*RegionCache) NextPeer

func (c *RegionCache) NextPeer(id RegionVerID)

NextPeer picks next peer as new leader, if out of range of peers delete region.

func (*RegionCache) OnRegionStale

func (c *RegionCache) OnRegionStale(old *Region, newRegions []*metapb.Region) error

OnRegionStale removes the old region and inserts new regions into the cache.

func (*RegionCache) UpdateLeader

func (c *RegionCache) UpdateLeader(regionID RegionVerID, leaderID uint64)

UpdateLeader update some region cache with newer leader info.

type RegionVerID

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

RegionVerID is a unique ID that can identify a Region at a specific version.

type Scanner

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

Scanner support tikv scan

func (*Scanner) Close

func (s *Scanner) Close()

Close close iterator.

func (*Scanner) Key

func (s *Scanner) Key() kv.Key

Key return key.

func (*Scanner) Next

func (s *Scanner) Next() error

Next return next element.

func (*Scanner) Valid

func (s *Scanner) Valid() bool

Valid return valid.

func (*Scanner) Value

func (s *Scanner) Value() []byte

Value return value.

type TxnStatus

type TxnStatus uint64

TxnStatus represents a txn's final status. It should be Commit or Rollback.

func (TxnStatus) CommitTS

func (s TxnStatus) CommitTS() uint64

CommitTS returns the txn's commitTS. It is valid iff `IsCommitted` is true.

func (TxnStatus) IsCommitted

func (s TxnStatus) IsCommitted() bool

IsCommitted returns true if the txn's final status is Commit.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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