mvcc

package
v0.0.0-...-959c02d Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const LockVer = math.MaxUint64

Variables

View Source
var (
	// ErrInvalidEncodedKey describes parsing an invalid format of EncodedKey.
	ErrInvalidEncodedKey = errors.New("invalid encoded key")
)

Functions

func Decode

func Decode(encodedKey []byte) (kv.Key, kv.Version, error)

Decode parses the origin key and version of an encoded key. Will return the original key if the encoded key is a meta key.

Types

type Entry

type Entry struct {
	Key    Key
	Values []Value
	Lock   *Lock
}

func (*Entry) Get

func (e *Entry) Get(ver kv.Version, resolvedLocks []kv.Version) ([]byte, error)

func (*Entry) Less

func (e *Entry) Less(than btree.Item) bool

type Key

type Key []byte

Key is the encoded key type with timestamp.

func Encode

func Encode(key kv.Key, ver kv.Version) Key

Encode encodes a user defined key with timestamp.

func LockKey

func LockKey(key kv.Key) Key

LockKey returns the encoded lock key of specified raw key.

func NewKey

func NewKey(key []byte) Key

NewKey encodes a key into MvccKey.

func (Key) Raw

func (key Key) Raw() []byte

Raw decodes a MvccKey to original key.

type Lock

type Lock struct {
	StartVer kv.Version
	Primary  []byte
	Value    []byte
	Op       Op
	TTL      uint64
}

func (*Lock) Check

func (l *Lock) Check(ver kv.Version, key []byte, resolvedLocks []kv.Version) (kv.Version, error)

func (*Lock) LockErr

func (l *Lock) LockErr(key []byte) error

LockErr returns LockedError. Note that parameter key is raw key, while key in LockedError is mvcc key.

func (*Lock) MarshalBinary

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

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*Lock) UnmarshalBinary

func (l *Lock) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler interface.

type LockDecoder

type LockDecoder struct {
	Lock      Lock
	ExpectKey []byte
}

LockDecoder is used to decode Lock entry of low-level key-value store.

func (*LockDecoder) Decode

func (dec *LockDecoder) Decode(iter *pebble.Iterator) (bool, error)

Decode decodes the Lock value if current iterator is at expectKey::Lock.

type LockedError

type LockedError struct {
	Key      kv.Key
	Primary  kv.Key
	StartVer kv.Version
	TTL      uint64
}

LockedError is returned when trying to Read/Write on a locked key. Caller should backoff or cleanup the lock then retry.

func (*LockedError) Error

func (e *LockedError) Error() string

Error formats the lock to a string.

type Op

type Op int32
const (
	Op_Put      Op = 0
	Op_Del      Op = 1
	Op_Lock     Op = 2
	Op_Rollback Op = 3
	// insert operation has a constraint that key should not exist before.
	Op_Insert         Op = 4
	Op_CheckNotExists Op = 5
)

type SkipDecoder

type SkipDecoder struct {
	CurrKey []byte
}

SkipDecoder is used to decode useless versions of value entry.

func (*SkipDecoder) Decode

func (dec *SkipDecoder) Decode(iter *pebble.Iterator) (bool, error)

Decode skips the iterator as long as its key is currKey, the new key would be stored.

type Value

type Value struct {
	Type      ValueType
	StartVer  kv.Version
	CommitVer kv.Version
	Value     []byte
}

func (*Value) MarshalBinary

func (v *Value) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler interface.

func (*Value) UnmarshalBinary

func (v *Value) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler interface.

type ValueDecoder

type ValueDecoder struct {
	Value     Value
	ExpectKey []byte
}

ValueDecoder is used to decode the value entries. There will be multiple versions of specified key.

func (*ValueDecoder) Decode

func (dec *ValueDecoder) Decode(iter *pebble.Iterator) (bool, error)

Decode decodes a mvcc value if iter key is expectKey.

type ValueType

type ValueType int
const (
	ValueTypePut ValueType = iota
	ValueTypeDelete
	ValueTypeRollback
	ValueTypeLock
)

Jump to

Keyboard shortcuts

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