keyspace

package
v2.2.0-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

This package is copied from tikv/pd

Index

Constants

View Source
const (
	// RawKeyspaceModePrefix is the raw keyspace prefix mode byte.
	RawKeyspaceModePrefix = byte('r')
	// TxnKeyspaceModePrefix is the txn keyspace prefix mode byte.
	TxnKeyspaceModePrefix = byte('x')
	// KeyspacePrefixLen is the raw keyspace prefix length before memcomparable encoding.
	KeyspacePrefixLen = 4

	// DefaultKeyspaceID is the default keyspace ID.
	// Valid keyspace id range is [0, 0xFFFFFF](uint24max, or 16777215)
	// 0 is reserved for default keyspace with the name "DEFAULT", It's initialized
	// when PD bootstrap and reserved for users who haven't been assigned keyspace.
	DefaultKeyspaceID = uint32(0)
	// MaxValidKeyspaceID is the max valid keyspace id.
	// Valid keyspace id range is [0, 0xFFFFFF](uint24max, or 16777215)
	// In kv encode, the first byte is represented by r/x, which means txn kv/raw kv, so there are 24 bits left.
	MaxValidKeyspaceID = uint32(0xFFFFFF)
)

Variables

This section is empty.

Functions

func MakeKeyspacePrefix

func MakeKeyspacePrefix(mode byte, id uint32) []byte

Types

type Key

type Key []byte

Key represents high-level Key type.

func EncodeBytes

func EncodeBytes(data []byte) Key

EncodeBytes guarantees the encoded value is in ascending order for comparison, encoding with the following rule:

[group1][marker1]...[groupN][markerN]
group is 8 bytes slice which is padding with 0.
marker is `0xFF - padding 0 count`

For example:

[] -> [0, 0, 0, 0, 0, 0, 0, 0, 247]
[1, 2, 3] -> [1, 2, 3, 0, 0, 0, 0, 0, 250]
[1, 2, 3, 0] -> [1, 2, 3, 0, 0, 0, 0, 0, 251]
[1, 2, 3, 4, 5, 6, 7, 8] -> [1, 2, 3, 4, 5, 6, 7, 8, 255, 0, 0, 0, 0, 0, 0, 0, 0, 247]

Refer: https://github.com/facebook/mysql-5.6/wiki/MyRocks-record-format#memcomparable-format

type KeyRange

type KeyRange struct {
	Type        string
	StartKeyHex string
	EndKeyHex   string
}

func MakeRegionBound

func MakeRegionBound(str string) ([]KeyRange, error)

type RegionBound

type RegionBound struct {
	RawLeftBound  []byte
	RawRightBound []byte
	TxnLeftBound  []byte
	TxnRightBound []byte
}

RegionBound represents the region boundary of the given keyspace. For a keyspace with id ['a', 'b', 'c'], it has four boundaries:

Lower bound for raw mode: ['r', 'a', 'b', 'c']
Upper bound for raw mode: ['r', 'a', 'b', 'c + 1']
Lower bound for txn mode: ['x', 'a', 'b', 'c']
Upper bound for txn mode: ['x', 'a', 'b', 'c + 1']
For the max valid keyspace ID, the upper bound advances the mode byte as an exclusive fencepost.

From which it shares the lower bound with keyspace with id ['a', 'b', 'c-1']. And shares upper bound with keyspace with id ['a', 'b', 'c + 1']. These repeated bound will not cause any problem, as repetitive bound will be ignored during rangeListBuild, but provides guard against hole in keyspace allocations should it occur.

Jump to

Keyboard shortcuts

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