Documentation ¶
Overview ¶
Package testkeys provides facilities for generating and comparing human-readable test keys for use in tests and benchmarks. This package provides a single Comparer implementation that compares all keys generated by this package.
Keys generated by this package may optionally have a 'suffix' encoding an MVCC timestamp. This suffix is of the form "@<integer>". Comparisons on the suffix are performed using integer value, not the byte representation.
Index ¶
- Variables
- func Key(k Keyspace, i int64) []byte
- func KeyAt(k Keyspace, i int64, t int64) []byte
- func ParseSuffix(s []byte) (int64, error)
- func RandomSeparator(dst, a, b []byte, suffix int64, maxLength int, rng *rand.Rand) []byte
- func Suffix(t int64) []byte
- func SuffixLen(t int64) int
- func WriteKey(dst []byte, k Keyspace, i int64) int
- func WriteKeyAt(dst []byte, k Keyspace, i int64, t int64) int
- func WriteSuffix(dst []byte, t int64) int
- type Keyspace
Constants ¶
This section is empty.
Variables ¶
var Comparer = &base.Comparer{ Compare: compare, Equal: func(a, b []byte) bool { return compare(a, b) == 0 }, AbbreviatedKey: func(k []byte) uint64 { return base.DefaultComparer.AbbreviatedKey(k[:split(k)]) }, FormatKey: base.DefaultFormatter, Separator: func(dst, a, b []byte) []byte { ai := split(a) if ai == len(a) { return append(dst, a...) } bi := split(b) if bi == len(b) { return append(dst, a...) } if bytes.Equal(a[:ai], b[:bi]) { return append(dst, a...) } n := len(dst) dst = base.DefaultComparer.Separator(dst, a[:ai], b[:bi]) buf := dst[n:] if bytes.Equal(a[:ai], buf) { return append(dst[:n], a...) } return dst }, Successor: func(dst, a []byte) []byte { ai := split(a) if ai == len(a) { return append(dst, a...) } n := len(dst) dst = base.DefaultComparer.Successor(dst, a[:ai]) buf := dst[n:] if bytes.Equal(a[:ai], buf) { return append(dst[:n], a...) } return dst }, ImmediateSuccessor: func(dst, a []byte) []byte { ai := split(a) if ai != len(a) { panic("pebble: ImmediateSuccessor invoked with a non-prefix key") } return append(append(dst, a...), 0x00) }, Split: split, Name: "pebble.internal.testkeys", }
Comparer is the comparer for test keys generated by this package.
MaxSuffixLen is the maximum length of a suffix generated by this package.
Functions ¶
func ParseSuffix ¶
ParseSuffix returns the integer representation of the encoded suffix.
func RandomSeparator ¶
RandomSeparator returns a random alphabetic key k such that a < k < b, pulling randomness from the provided random number generator. If dst is provided and the generated key fits within dst's capacity, the returned slice will use dst's memory.
If a prefix P exists such that Prefix(a) < P < Prefix(b), the generated key will consist of the prefix P appended with the provided suffix. A zero suffix generates an unsuffixed key. If no such prefix P exists, RandomSeparator will try to find a key k with either Prefix(a) or Prefix(b) such that a < k < b, but the generated key will not use the provided suffix. Note that it's possible that no separator key exists (eg, a='a@2', b='a@1'), in which case RandomSeparator returns nil.
If RandomSeparator generates a new prefix, the generated prefix will have length at most MAX(maxLength, len(Prefix(a)), len(Prefix(b))).
RandomSeparator panics if a or b fails to decode.
func WriteKey ¶
WriteKey writes the i-th unsuffixed key within the keyspace to the buffer dst. It returns the number of bytes written.
func WriteKeyAt ¶
WriteKeyAt writes the i-th key within the keyspace to the buffer dst, with a suffix encoding the timestamp t suffix. It returns the number of bytes written.
func WriteSuffix ¶
WriteSuffix writes the test keys suffix representation of timestamp t to dst, returning the number of bytes written.
Types ¶
type Keyspace ¶
type Keyspace interface { // Count returns the number of keys that exist within this keyspace. Count() int64 // MaxLen returns the maximum length, in bytes, of a key within this // keyspace. This is only guaranteed to return an upper bound. MaxLen() int // Slice returns the sub-keyspace from index i, inclusive, to index j, // exclusive. The receiver is unmodified. Slice(i, j int64) Keyspace // EveryN returns a key space that includes 1 key for every N keys in the // original keyspace. The receiver is unmodified. EveryN(n int64) Keyspace // contains filtered or unexported methods }
Keyspace describes a finite keyspace of unsuffixed test keys.