mvcc

package
v1.1.0-beta.0...-68ac9ec Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockUserMetaNoneByte   = 0
	LockUserMetaDeleteByte = 2
)

UserMeta value for lock.

View Source
const (

	//ShortValueMaxLen defines max length of short value.
	ShortValueMaxLen = 64
)

Variables

View Source
var (
	LockUserMetaNone   = []byte{LockUserMetaNoneByte}
	LockUserMetaDelete = []byte{LockUserMetaDeleteByte}
)

UserMeta byte slices for lock.

Functions

func DecodeExtraTxnStatusKey

func DecodeExtraTxnStatusKey(extraKey []byte) (key []byte)

DecodeExtraTxnStatusKey decodes a extra transaction status key.

func DecodeKeyTS

func DecodeKeyTS(buf []byte) uint64

DecodeKeyTS decodes the TS in a key.

func EncodeExtraTxnStatusKey

func EncodeExtraTxnStatusKey(key []byte, startTS uint64) []byte

EncodeExtraTxnStatusKey encodes a extra transaction status key. It is only used for Rollback and Op_Lock.

func EncodeLockCFValue

func EncodeLockCFValue(lock *Lock) ([]byte, []byte)

EncodeLockCFValue encodes the mvcc lock and returns putLock value and putDefault value if exists.

func EncodeWriteCFValue

func EncodeWriteCFValue(t WriteType, startTs uint64, shortVal []byte) []byte

EncodeWriteCFValue accepts a write cf parameters and return the encoded bytes data. Just like the tikv encoding form. See tikv/src/storage/mvcc/write.rs for more detail.

Types

type DBBundle

type DBBundle struct {
	DB         *badger.DB
	LockStore  *lockstore.MemStore
	MemStoreMu sync.Mutex
	StateTS    uint64
}

DBBundle represents the db bundle.

type DBSnapshot

type DBSnapshot struct {
	Txn       *badger.Txn
	LockStore *lockstore.MemStore
}

DBSnapshot represents the db snapshot.

func NewDBSnapshot

func NewDBSnapshot(db *DBBundle) *DBSnapshot

NewDBSnapshot returns a new db snapshot.

type DBUserMeta

type DBUserMeta []byte

DBUserMeta is the user meta used in DB.

func NewDBUserMeta

func NewDBUserMeta(startTS, commitTS uint64) DBUserMeta

NewDBUserMeta creates a new DBUserMeta.

func (DBUserMeta) CommitTS

func (m DBUserMeta) CommitTS() uint64

CommitTS reads the commitTS from the DBUserMeta.

func (DBUserMeta) StartTS

func (m DBUserMeta) StartTS() uint64

StartTS reads the startTS from the DBUserMeta.

type DBWriter

type DBWriter interface {
	Open()
	Close()
	Write(batch WriteBatch) error
	DeleteRange(start, end []byte, latchHandle LatchHandle) error
	NewWriteBatch(startTS, commitTS uint64, ctx *kvrpcpb.Context) WriteBatch
}

DBWriter is the interface to persistent data.

type LatchHandle

type LatchHandle interface {
	AcquireLatches(hashVals []uint64)
	ReleaseLatches(hashVals []uint64)
}

LatchHandle is the interface for handling latches.

type Lock

type Lock struct {
	LockHdr
	Primary     []byte
	Value       []byte
	Secondaries [][]byte
}

Lock is the structure for MVCC lock.

func DecodeLock

func DecodeLock(data []byte) (l Lock)

DecodeLock decodes data to lock, the primary and value is copied, the secondaries are copied if async commit is enabled.

func (*Lock) MarshalBinary

func (l *Lock) MarshalBinary() []byte

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*Lock) String

func (l *Lock) String() string

String implements fmt.Stringer for Lock.

func (*Lock) ToLockInfo

func (l *Lock) ToLockInfo(key []byte) *kvrpcpb.LockInfo

ToLockInfo converts an mvcc Lock to kvrpcpb.LockInfo

type LockHdr

type LockHdr struct {
	StartTS        uint64
	ForUpdateTS    uint64
	MinCommitTS    uint64
	TTL            uint32
	Op             uint8
	HasOldVer      bool
	PrimaryLen     uint16
	UseAsyncCommit bool
	SecondaryNum   uint32
}

LockHdr holds fixed size fields for mvcc Lock.

type LockType

type LockType = byte

LockType defines a lock type.

const (
	LockTypePut         LockType = 'P'
	LockTypeDelete      LockType = 'D'
	LockTypeLock        LockType = 'L'
	LockTypePessimistic LockType = 'S'
)

LockType

type WriteBatch

type WriteBatch interface {
	Prewrite(key []byte, lock *Lock)
	Commit(key []byte, lock *Lock)
	Rollback(key []byte, deleleLock bool)
	PessimisticLock(key []byte, lock *Lock)
	PessimisticRollback(key []byte)
}

WriteBatch is the interface to batch write.

type WriteCFValue

type WriteCFValue struct {
	Type     WriteType
	StartTS  uint64
	ShortVal []byte
}

WriteCFValue represents a write CF value.

func ParseWriteCFValue

func ParseWriteCFValue(data []byte) (wv WriteCFValue, err error)

ParseWriteCFValue parses the []byte data and returns a WriteCFValue.

type WriteType

type WriteType = byte

WriteType defines a write type.

const (
	WriteTypeLock     WriteType = 'L'
	WriteTypeRollback WriteType = 'R'
	WriteTypeDelete   WriteType = 'D'
	WriteTypePut      WriteType = 'P'
)

WriteType

Jump to

Keyboard shortcuts

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