crdbtest

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package crdbtest provides facilities for representing keys, workloads, etc representative of CockroachDB's use of Pebble.

Index

Constants

View Source
const MaxSuffixLen = 1 + max(
	engineKeyVersionLockTableLen,
	engineKeyVersionWallLogicalAndSyntheticTimeLen,
	engineKeyVersionWallAndLogicalTimeLen,
	engineKeyVersionWallTimeLen,
)

MaxSuffixLen is the maximum length of the CockroachDB key suffix.

Variables

View Source
var Comparer = base.Comparer{
	Split:                Split,
	ComparePointSuffixes: ComparePointSuffixes,
	CompareRangeSuffixes: CompareRangeSuffixes,
	Compare:              Compare,
	Equal:                Equal,
	AbbreviatedKey: func(k []byte) uint64 {
		key, ok := getKeyPartFromEngineKey(k)
		if !ok {
			return 0
		}
		return base.DefaultComparer.AbbreviatedKey(key)
	},
	FormatKey: base.DefaultFormatter,
	Separator: func(dst, a, b []byte) []byte {
		aKey, ok := getKeyPartFromEngineKey(a)
		if !ok {
			return append(dst, a...)
		}
		bKey, ok := getKeyPartFromEngineKey(b)
		if !ok {
			return append(dst, a...)
		}

		if bytes.Equal(aKey, bKey) {
			return append(dst, a...)
		}
		n := len(dst)
		dst = base.DefaultComparer.Separator(dst, aKey, bKey)

		buf := dst[n:]
		if bytes.Equal(aKey, buf) {
			return append(dst[:n], a...)
		}

		return append(dst, 0)
	},
	Successor: func(dst, a []byte) []byte {
		aKey, ok := getKeyPartFromEngineKey(a)
		if !ok {
			return append(dst, a...)
		}
		n := len(dst)

		dst = base.DefaultComparer.Successor(dst, aKey)

		buf := dst[n:]
		if bytes.Equal(aKey, buf) {
			return append(dst[:n], a...)
		}

		return append(dst, 0)
	},
	ImmediateSuccessor: func(dst, a []byte) []byte {

		return append(append(dst, a...), 0)
	},
	Name: "cockroach_comparator",
}

Comparer is a base.Comparer for CockroachDB keys.

View Source
var KeySchema = colblk.KeySchema{
	Name:       "crdb1",
	HeaderSize: 1,
	ColumnTypes: []colblk.DataType{
		// contains filtered or unexported fields
	},
	NewKeyWriter: func() colblk.KeyWriter {
		return makeCockroachKeyWriter()
	},
	InitKeySeekerMetadata: func(meta *colblk.KeySeekerMetadata, d *colblk.DataBlockDecoder) {
		ks := (*cockroachKeySeeker)(unsafe.Pointer(meta))
		ks.init(d)
	},
	KeySeeker: func(meta *colblk.KeySeekerMetadata) colblk.KeySeeker {
		return (*cockroachKeySeeker)(unsafe.Pointer(meta))
	},
}

Functions

func AppendTimestamp

func AppendTimestamp(key []byte, walltime uint64, logical uint32) []byte

AppendTimestamp appends an encoded MVCC timestamp onto key, returning the new key. The provided key should already have the 0x00 sentinel byte (i.e., key should be a proper prefix from the perspective of Pebble).

func Compare

func Compare(a, b []byte) int

Compare compares cockroach keys, including the version (which could be MVCC timestamps).

func ComparePointSuffixes

func ComparePointSuffixes(a, b []byte) int

ComparePointSuffixes compares point key suffixes (normally timestamps).

func CompareRangeSuffixes

func CompareRangeSuffixes(a, b []byte) int

CompareRangeSuffixes compares range key suffixes (normally timestamps).

func DecodeEngineKey

func DecodeEngineKey(b []byte) (roachKey, version []byte, ok bool)

DecodeEngineKey decodes the given bytes as an EngineKey.

func EncodeMVCCKey

func EncodeMVCCKey(dst []byte, key []byte, walltime uint64, logical uint32) []byte

EncodeMVCCKey encodes a MVCC key into dst, growing dst as necessary.

func EncodeTimestamp

func EncodeTimestamp(key []byte, walltime uint64, logical uint32) []byte

EncodeTimestamp encodes a MVCC timestamp into a key, returning the new key. The key's capacity must be sufficiently large to hold the encoded timestamp.

func Equal

func Equal(a, b []byte) bool

Equal implements base.Equal for Cockroach keys.

func Split

func Split(key []byte) int

Split implements base.Split for CockroachDB keys.

Types

This section is empty.

Jump to

Keyboard shortcuts

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