sdk

package module
v0.0.0-...-66d8299 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2019 License: MIT Imports: 14 Imported by: 0

README

TiKV Spanner transaction interface SDK

RO/RW Transaction lifetime

Begin()
  • do nothing, gen txn struct with RO/RW
Get()
  • get TS if not exist
  • start heartbeat with transaction nodes
  • call tikv get RO/RW with TS
Set()/Delete()
  • store key value in local storage(map)
Commit()
  • map & gather all keys with regions
  • choose coordinator leader
  • call commit on every perticipators and leader

Documentation

Overview

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

package sdk defined spanner sdk for tikv transaction

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound    = errors.New("not found")
	ErrRegionError = errors.New("region error")
)
View Source
var (
	ErrInternal       = errors.New("error internal")
	ErrInvalid        = errors.New("error invalid operation")
	ErrNotImplemented = errors.New("error not implemeted yet")
)

Functions

This section is empty.

Types

type Key

type Key string

Key give out spanner sdk key

func (Key) String

func (k Key) String() string

type KeyStore

type KeyStore struct {
	sync.Mutex
	// contains filtered or unexported fields
}

KeyStore store all keys locally TODO should be an interface

func NewKVStore

func NewKVStore() *KeyStore

NewKVStore return a local in memory kv storage

func (*KeyStore) GetAllOperations

func (s *KeyStore) GetAllOperations() []Operation

GetAllOperations return all k-v pairs store in kvstore in operation set

func (*KeyStore) SetOp

func (s *KeyStore) SetOp(k, v []byte, op Type)

type Operation

type Operation struct {
	Type  Type
	Key   []byte
	Value []byte
}

type Pacemaker

type Pacemaker struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Pacemaker sent heartbeat to every perticapate nodes

func NewPacemaker

func NewPacemaker(c context.Context, txnid uint64) Pacemaker

NewPacemaker gen a pacemaker client with context, txnid

func (*Pacemaker) AddNode

func (p *Pacemaker) AddNode(rid uint64, cli TiKVClient)

AddNode add new node

func (*Pacemaker) AllNodes

func (p *Pacemaker) AllNodes() ([]TiKVClient, []uint64)

AllNodes return all stored kv client

func (*Pacemaker) ChooseLeader

func (p *Pacemaker) ChooseLeader() (TiKVClient, uint64)

ChooseLeader return all stored kv client

type TiKVClient

type TiKVClient interface {
	Get(ctx context.Context, txnID uint64, key []byte, version uint64, readOnly bool) ([]byte, error)
	Commit(ctx context.Context, txnID uint64, operations []Operation, coordinatorId uint64, participants []uint64) (uint64, error)
	HeartBeat(ctx context.Context, txnID uint64, ttl uint64) error
	Close() error
}

func NewTiKV

func NewTiKV(address string) (TiKVClient, error)

type Transaction

type Transaction interface {
	Get(key []byte) ([]byte, error)
	Set(key []byte, value []byte) error
	Delete(key []byte) error
	Rollback() error
	Commit() error
	Close() error
}

Transaction defiend spanner transaction interface, implemented by ro transaction and rw transaction

func Begin

func Begin(ro bool, ctx context.Context) (Transaction, error)

Begin start a transaction with option wether it is a RO transaction

type Type

type Type int
const (
	OpPut    Type = 0
	OpDelete Type = 1
	OpRead   Type = 2

	ErrorCode_NotFound    = 1
	ErrorCode_RegionError = 2
)

type Value

type Value struct {
	Type  Type
	Value []byte
}

Value defined a byte slice for transaction sdk value field

func (Value) String

func (v Value) String() string

Jump to

Keyboard shortcuts

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