tidb: github.com/pingcap/tidb/util/kvencoder Index | Files

package kvenc

import "github.com/pingcap/tidb/util/kvencoder"


Package Files

allocator.go kv_encoder.go

type Allocator Uses

type Allocator struct {
    // contains filtered or unexported fields

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

func NewAllocator Uses

func NewAllocator() *Allocator

NewAllocator creates an Allocator.

func (*Allocator) Alloc Uses

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

Alloc allocs a next autoID for table with tableID.

func (*Allocator) Base Uses

func (alloc *Allocator) Base() int64

Base returns the current base of Allocator.

func (*Allocator) End Uses

func (alloc *Allocator) End() int64

End is only used for test.

func (*Allocator) NextGlobalAutoID Uses

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

NextGlobalAutoID returns the next global autoID.

func (*Allocator) Rebase Uses

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 Uses

func (alloc *Allocator) Reset(newBase int64)

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

type KvEncoder Uses

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 Uses

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

New new a KvEncoder

type KvPair Uses

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.

Package kvenc imports 18 packages (graph). Updated 2019-08-06. Refresh now. Tools for package owners.