mvcc

package
v0.0.0-...-76a7b18 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LockUserMetaNoneByte   = 0
	LockUserMetaDeleteByte = 2
)

UserMeta value for lock.

View Source
const (
	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 *MvccLock) ([]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
}

type DBSnapshot

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

func NewDBSnapshot

func NewDBSnapshot(db *DBBundle) *DBSnapshot

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)
}

type LockType

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

type MvccLock

type MvccLock struct {
	MvccLockHdr
	Primary     []byte
	Value       []byte
	Secondaries [][]byte
}

MvccLock is the structure for MVCC lock.

func DecodeLock

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

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

func ParseLockCFValue

func ParseLockCFValue(data []byte) (lock MvccLock, err error)

func (*MvccLock) MarshalBinary

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

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*MvccLock) ToLockInfo

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

ToLockInfo converts an MvccLock to kvrpcpb.LockInfo

type MvccLockHdr

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

MvccLockHdr holds fixed size fields for MvccLock.

type WriteBatch

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

type WriteCFValue

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

func ParseWriteCFValue

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

type WriteType

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

Jump to

Keyboard shortcuts

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