kvenc

package
v2.1.0-alpha+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Allocator

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

Allocator is an id allocator, it is only used in lightning.

func NewAllocator

func NewAllocator() *Allocator

NewAllocator creates an Allocator.

func (*Allocator) Alloc

func (alloc *Allocator) Alloc(tableID int64) (int64, error)

Alloc allocs a next autoID for table with tableID.

func (*Allocator) Base

func (alloc *Allocator) Base() int64

Base returns the current base of Allocator.

func (*Allocator) End

func (alloc *Allocator) End() int64

End is only used for test.

func (*Allocator) NextGlobalAutoID

func (alloc *Allocator) NextGlobalAutoID(tableID int64) (int64, error)

NextGlobalAutoID returns the next global autoID.

func (*Allocator) Rebase

func (alloc *Allocator) Rebase(tableID, newBase int64, allocIDs bool) error

Rebase not allow newBase smaller than alloc.base, and will skip the smaller newBase.

func (*Allocator) Reset

func (alloc *Allocator) Reset(newBase int64)

Reset allow newBase smaller than alloc.base, and will set the alloc.base to newBase.

type KvEncoder

type KvEncoder interface {
	// Encode transfers sql to kv pairs.
	// Before use Encode() method, please make sure you already created schame by calling ExecDDLSQL() method.
	// NOTE: now we just support transfers insert statement to kv pairs.
	// (if we wanna support other statement, we need to add a kv.Storage parameter,
	// and pass tikv store in.)
	// return encoded kvs array that generate by sql, and affectRows count.
	Encode(sql string, tableID int64) (kvPairs []KvPair, affectedRows uint64, err error)

	// PrepareStmt prepare query statement, and return statement id.
	// Pass stmtID into EncodePrepareStmt to execute a prepare statement.
	PrepareStmt(query string) (stmtID uint32, err error)

	// EncodePrepareStmt transfer prepare query to kv pairs.
	// stmtID is generated by PrepareStmt.
	EncodePrepareStmt(tableID int64, stmtID uint32, param ...interface{}) (kvPairs []KvPair, affectedRows uint64, err error)

	// ExecDDLSQL executes ddl sql, you must use it to create schema infos.
	ExecDDLSQL(sql string) error

	// EncodeMetaAutoID encode the table meta info, autoID to coresponding key-value pair.
	EncodeMetaAutoID(dbID, tableID, autoID int64) (KvPair, error)

	// SetSystemVariable set system variable name = value.
	SetSystemVariable(name string, value string) error

	// GetSystemVariable get the system variable value of name.
	GetSystemVariable(name string) (string, bool)

	// Close cleanup the kvEncoder.
	Close() error
}

KvEncoder is an encoder that transfer sql to key-value pairs.

func New

func New(dbName string, idAlloc autoid.Allocator) (KvEncoder, error)

New new a KvEncoder

type KvPair

type KvPair struct {
	// Key is the key of the pair.
	Key []byte
	// Val is the value of the pair. if the op is delete, the len(Val) == 0
	Val []byte
}

KvPair is a key-value pair.

Jump to

Keyboard shortcuts

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