kv

package
v0.0.0-...-503c688 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0, Apache-2.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExtraHandleColumnInfo = model.NewExtraHandleColInfo()

ExtraHandleColumnInfo is the column info of extra handle column.

Functions

func GetActualDatum

func GetActualDatum(encoder encode.Encoder, col *table.Column, rowID int64,
	inputDatum *types.Datum) (types.Datum, error)

GetActualDatum export getActualDatum function.

func GetAutoRecordID

func GetAutoRecordID(d types.Datum, target *types.FieldType) int64

GetAutoRecordID returns the record ID for an auto-increment field. get record value for auto-increment field

See:

https://github.com/pingcap/tidb/blob/47f0f15b14ed54fc2222f3e304e29df7b05e6805/executor/insert_common.go#L781-L852

func GetEncoderIncrementalID

func GetEncoderIncrementalID(encoder encode.Encoder, id int64) int64

GetEncoderIncrementalID return Auto increment id.

func GetSession4test

func GetSession4test(encoder encode.Encoder) sessionctx.Context

GetSession4test is only used for test.

func IsAutoIncCol

func IsAutoIncCol(colInfo *model.ColumnInfo) bool

IsAutoIncCol return true if the column is auto increment column.

func MakeRowFromKvPairs

func MakeRowFromKvPairs(pairs []common.KvPair) encode.Row

MakeRowFromKvPairs converts a KvPair slice into a Row instance. This is mainly used for testing only. The resulting Row instance should only be used for the importer backend.

func MakeRowsFromKvPairs

func MakeRowsFromKvPairs(pairs []common.KvPair) encode.Rows

MakeRowsFromKvPairs converts a KvPair slice into a Rows instance. This is mainly used for testing only. The resulting Rows instance should only be used for the importer backend.

func NewPanickingAllocators

func NewPanickingAllocators(base int64) autoid.Allocators

NewPanickingAllocators creates a PanickingAllocator shared by all allocation types.

func NewSessionCtx

func NewSessionCtx(options *encode.SessionOptions, logger log.Logger) sessionctx.Context

NewSessionCtx creates a new trimmed down Session matching the options.

func NewTableKVEncoder

func NewTableKVEncoder(
	config *encode.EncodingConfig,
	metrics *metric.Metrics,
) (encode.Encoder, error)

NewTableKVEncoder creates a new tableKVEncoder.

func Row2KvPairs

func Row2KvPairs(row encode.Row) []common.KvPair

Row2KvPairs converts a Row instance constructed from MakeRowFromKvPairs back into a slice of KvPair. This method panics if the Row is not constructed in such way.

func Rows2KvPairs

func Rows2KvPairs(rows encode.Rows) []common.KvPair

Rows2KvPairs converts a Rows instance constructed from MakeRowsFromKvPairs back into a slice of KvPair. This method panics if the Rows is not constructed in such way.

Types

type AutoIDConverterFn

type AutoIDConverterFn func(int64) int64

AutoIDConverterFn is a function to convert auto id.

type BaseKVEncoder

type BaseKVEncoder struct {
	GenCols         []GeneratedCol
	SessionCtx      *Session
	Table           table.Table
	Columns         []*table.Column
	AutoRandomColID int64
	// convert auto id for shard rowid or auto random id base on row id generated by lightning
	AutoIDFn AutoIDConverterFn

	// the first auto-generated ID in the current encoder.
	// if there's no auto-generated id column or the column value is not auto-generated, it will be 0.
	LastInsertID uint64
	// contains filtered or unexported fields
}

BaseKVEncoder encodes a row into a KV pair.

func NewBaseKVEncoder

func NewBaseKVEncoder(config *encode.EncodingConfig) (*BaseKVEncoder, error)

NewBaseKVEncoder creates a new BaseKVEncoder.

func (*BaseKVEncoder) EvalGeneratedColumns

func (e *BaseKVEncoder) EvalGeneratedColumns(record []types.Datum,
	cols []*table.Column) (errCol *model.ColumnInfo, err error)

EvalGeneratedColumns evaluates the generated columns.

func (*BaseKVEncoder) GetOrCreateRecord

func (e *BaseKVEncoder) GetOrCreateRecord() []types.Datum

GetOrCreateRecord returns a record slice from the cache if possible, otherwise creates a new one.

func (*BaseKVEncoder) IsAutoRandomCol

func (e *BaseKVEncoder) IsAutoRandomCol(col *model.ColumnInfo) bool

IsAutoRandomCol checks if the column is auto random column.

func (*BaseKVEncoder) LogEvalGenExprFailed

func (e *BaseKVEncoder) LogEvalGenExprFailed(row []types.Datum, colInfo *model.ColumnInfo, err error) error

LogEvalGenExprFailed logs the error when evaluating the generated column expression failed.

func (*BaseKVEncoder) LogKVConvertFailed

func (e *BaseKVEncoder) LogKVConvertFailed(row []types.Datum, j int, colInfo *model.ColumnInfo, err error) error

LogKVConvertFailed logs the error when converting a row to KV pair failed.

func (*BaseKVEncoder) ProcessColDatum

func (e *BaseKVEncoder) ProcessColDatum(col *table.Column, rowID int64, inputDatum *types.Datum) (types.Datum, error)

ProcessColDatum processes the datum of a column.

func (*BaseKVEncoder) Record2KV

func (e *BaseKVEncoder) Record2KV(record, originalRow []types.Datum, rowID int64) (*Pairs, error)

Record2KV converts a row into a KV pair.

func (*BaseKVEncoder) TruncateWarns

func (e *BaseKVEncoder) TruncateWarns()

TruncateWarns resets the warnings in session context.

type BytesBuf

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

BytesBuf bytes buffer.

type GeneratedCol

type GeneratedCol struct {
	// index of the column in the table
	Index int
	Expr  expression.Expression
}

GeneratedCol generated column info.

func CollectGeneratedColumns

func CollectGeneratedColumns(se *Session, meta *model.TableInfo, cols []*table.Column) ([]GeneratedCol, error)

CollectGeneratedColumns collects all expressions required to evaluate the results of all generated columns. The returning slice is in evaluation order.

type MemBuf

type MemBuf struct {
	sync.Mutex
	kv.MemBuffer
	// contains filtered or unexported fields
}

MemBuf used to store the data in memory.

func (*MemBuf) AllocateBuf

func (mb *MemBuf) AllocateBuf(size int)

AllocateBuf allocates a byte buffer.

func (*MemBuf) Cleanup

func (*MemBuf) Cleanup(_ kv.StagingHandle)

Cleanup the resources referenced by the StagingHandle. If the changes are not published by `Release`, they will be discarded.

func (*MemBuf) Delete

func (*MemBuf) Delete(_ kv.Key) error

Delete implements the kv.MemBuffer interface.

func (*MemBuf) Recycle

func (mb *MemBuf) Recycle(buf *BytesBuf)

Recycle recycles the byte buffer.

func (*MemBuf) Release

func (*MemBuf) Release(_ kv.StagingHandle)

Release publish all modifications in the latest staging buffer to upper level.

func (*MemBuf) Set

func (mb *MemBuf) Set(k kv.Key, v []byte) error

Set sets the key-value pair.

func (*MemBuf) SetWithFlags

func (mb *MemBuf) SetWithFlags(k kv.Key, v []byte, _ ...kv.FlagsOp) error

SetWithFlags implements the kv.MemBuffer interface.

func (*MemBuf) Size

func (mb *MemBuf) Size() int

Size returns sum of keys and values length.

func (*MemBuf) Staging

func (*MemBuf) Staging() kv.StagingHandle

Staging creates a new staging buffer.

type Pairs

type Pairs struct {
	Pairs    []common.KvPair
	BytesBuf *BytesBuf
	MemBuf   *MemBuf
}

Pairs implements the Encoder interface.

func (*Pairs) ClassifyAndAppend

func (kvs *Pairs) ClassifyAndAppend(
	data *encode.Rows,
	dataChecksum *verification.KVChecksum,
	indices *encode.Rows,
	indexChecksum *verification.KVChecksum,
)

ClassifyAndAppend separates the key-value pairs into data and index key-value pairs.

func (*Pairs) Clear

func (kvs *Pairs) Clear() encode.Rows

Clear clears the key-value pairs.

func (*Pairs) Size

func (kvs *Pairs) Size() uint64

Size returns the total size of the key-value pairs.

func (*Pairs) SplitIntoChunks

func (kvs *Pairs) SplitIntoChunks(splitSize int) []encode.Rows

SplitIntoChunks splits the key-value pairs into chunks.

type RowArrayMarshaller

type RowArrayMarshaller []types.Datum

RowArrayMarshaller wraps a slice of types.Datum for logging the content into zap.

func (RowArrayMarshaller) MarshalLogArray

func (row RowArrayMarshaller) MarshalLogArray(encoder zapcore.ArrayEncoder) error

MarshalLogArray implements the zapcore.ArrayMarshaler interface

type Session

type Session struct {
	sessionctx.Context

	Vars *variable.SessionVars
	// contains filtered or unexported fields
}

Session is a trimmed down Session type which only wraps our own trimmed-down transaction type and provides the session variables to the TiDB library optimized for Lightning.

func GetEncoderSe

func GetEncoderSe(encoder encode.Encoder) *Session

GetEncoderSe return session.

func NewSession

func NewSession(options *encode.SessionOptions, logger log.Logger) *Session

NewSession creates a new trimmed down Session matching the options.

func (*Session) BuiltinFunctionUsageInc

func (*Session) BuiltinFunctionUsageInc(_ string)

BuiltinFunctionUsageInc implements the sessionctx.Context interface.

func (*Session) Close

func (se *Session) Close()

Close implements the sessionctx.Context interface

func (*Session) GetBuiltinFunctionUsage

func (*Session) GetBuiltinFunctionUsage() map[string]uint32

GetBuiltinFunctionUsage returns the BuiltinFunctionUsage of current Context, which is not thread safe. Use primitive map type to prevent circular import. Should convert it to telemetry.BuiltinFunctionUsage before using.

func (*Session) GetInfoSchema

func (*Session) GetInfoSchema() sessionctx.InfoschemaMetaVersion

GetInfoSchema implements the sessionctx.Context interface.

func (*Session) GetSessionVars

func (se *Session) GetSessionVars() *variable.SessionVars

GetSessionVars implements the sessionctx.Context interface

func (*Session) GetStmtStats

func (*Session) GetStmtStats() *stmtstats.StatementStats

GetStmtStats implements the sessionctx.Context interface.

func (*Session) SetValue

func (se *Session) SetValue(key fmt.Stringer, value interface{})

SetValue saves a value associated with this context for key.

func (*Session) StmtAddDirtyTableOP

func (*Session) StmtAddDirtyTableOP(_ int, _ int64, _ kv.Handle)

StmtAddDirtyTableOP implements the sessionctx.Context interface

func (*Session) TakeKvPairs

func (se *Session) TakeKvPairs() *Pairs

TakeKvPairs returns the current Pairs and resets the buffer.

func (*Session) Txn

func (se *Session) Txn(_ bool) (kv.Transaction, error)

Txn implements the sessionctx.Context interface

func (*Session) Value

func (se *Session) Value(key fmt.Stringer) interface{}

Value returns the value associated with this context for key.

type TableKVDecoder

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

TableKVDecoder is a KVDecoder that decodes the key-value pairs of a table.

func NewTableKVDecoder

func NewTableKVDecoder(
	tbl table.Table,
	tableName string,
	options *encode.SessionOptions,
	logger log.Logger,
) (*TableKVDecoder, error)

NewTableKVDecoder creates a new TableKVDecoder.

func (*TableKVDecoder) DecodeHandleFromIndex

func (t *TableKVDecoder) DecodeHandleFromIndex(indexInfo *model.IndexInfo, key, value []byte) (kv.Handle, error)

DecodeHandleFromIndex implements KVDecoder.DecodeHandleFromIndex.

func (*TableKVDecoder) DecodeHandleFromRowKey

func (*TableKVDecoder) DecodeHandleFromRowKey(key []byte) (kv.Handle, error)

DecodeHandleFromRowKey implements KVDecoder.DecodeHandleFromRowKey.

func (*TableKVDecoder) DecodeRawRowData

func (t *TableKVDecoder) DecodeRawRowData(h kv.Handle, value []byte) ([]types.Datum, map[int64]types.Datum, error)

DecodeRawRowData decodes raw row data into a datum slice and a (columnID:columnValue) map.

func (*TableKVDecoder) DecodeRawRowDataAsStr

func (t *TableKVDecoder) DecodeRawRowDataAsStr(h kv.Handle, value []byte) (res string)

DecodeRawRowDataAsStr decodes raw row data into a string.

func (*TableKVDecoder) IterRawIndexKeys

func (t *TableKVDecoder) IterRawIndexKeys(h kv.Handle, rawRow []byte, fn func([]byte) error) error

IterRawIndexKeys generates the raw index keys corresponding to the raw row, and then iterate them using `fn`. The input buffer will be reused.

func (*TableKVDecoder) Name

func (t *TableKVDecoder) Name() string

Name implements KVDecoder.Name.

Jump to

Keyboard shortcuts

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