keys

package
v0.0.0-...-4b82dee Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2015 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxReservedDescID is the maximum value of the system IDs
	// under 'TableDataPrefix'.
	// It is here only so that we may define keys/ranges using it.
	// NOTE: this is not great, but the alternative is to
	// move all the ID/keying from sql/ here, or drop ID entirely.
	MaxReservedDescID = 999
)

Variables

View Source
var (
	// LocalPrefix is the prefix for keys which hold data local to a
	// RocksDB instance, such as store and range-specific metadata which
	// must not pollute the user key space, but must be collocate with
	// the store and/or ranges which they refer to. Storing this
	// information in the normal system keyspace would place the data on
	// an arbitrary set of stores, with no guarantee of collocation.
	// Local data includes store metadata, range metadata, response
	// cache values, transaction records, range-spanning binary tree
	// node pointers, and message queues.
	//
	// The local key prefix has been deliberately chosen to sort before
	// the SystemPrefix, because these local keys are not addressable
	// via the meta range addressing indexes.
	//
	// Some local data are not replicated, such as the store's 'ident'
	// record. Most local data are replicated, such as response cache
	// entries and transaction rows, but are not addressable as normal
	// MVCC values as part of transactions. Finally, some local data are
	// stored as MVCC values and are addressable as part of distributed
	// transactions, such as range metadata, range-spanning binary tree
	// node pointers, and message queues.
	LocalPrefix = proto.Key("\x00\x00\x00")

	// LocalSuffixLength specifies the length in bytes of all local
	// key suffixes.
	LocalSuffixLength = 4

	// LocalStorePrefix is the prefix identifying per-store data.
	LocalStorePrefix = MakeKey(LocalPrefix, proto.Key("s"))
	// LocalStoreIdentSuffix stores an immutable identifier for this
	// store, created when the store is first bootstrapped.
	LocalStoreIdentSuffix = proto.Key("iden")

	// LocalRangeIDPrefix is the prefix identifying per-range data
	// indexed by Range ID. The Range ID is appended to this prefix,
	// encoded using EncodeUvarint. The specific sort of per-range
	// metadata is identified by one of the suffixes listed below, along
	// with potentially additional encoded key info, such as a command
	// ID in the case of response cache entry.
	//
	// NOTE: LocalRangeIDPrefix must be kept in sync with the value
	// in storage/engine/db.cc.
	LocalRangeIDPrefix = MakeKey(LocalPrefix, proto.Key("i"))
	// LocalResponseCacheSuffix is the suffix for keys storing
	// command responses used to guarantee idempotency (see ResponseCache).
	// NOTE: if this value changes, it must be updated in C++
	// (storage/engine/db.cc).
	LocalResponseCacheSuffix = proto.Key("res-")
	// LocalRaftLeaderLeaseSuffix is the suffix for the raft leader lease.
	LocalRaftLeaderLeaseSuffix = proto.Key("rfll")
	// LocalRaftHardStateSuffix is the Suffix for the raft HardState.
	LocalRaftHardStateSuffix = proto.Key("rfth")
	// LocalRaftAppliedIndexSuffix is the suffix for the raft applied index.
	LocalRaftAppliedIndexSuffix = proto.Key("rfta")
	// LocalRaftLogSuffix is the suffix for the raft log.
	LocalRaftLogSuffix = proto.Key("rftl")
	// LocalRaftTruncatedStateSuffix is the suffix for the RaftTruncatedState.
	LocalRaftTruncatedStateSuffix = proto.Key("rftt")
	// LocalRaftLastIndexSuffix is the suffix for raft's last index.
	LocalRaftLastIndexSuffix = proto.Key("rfti")
	// LocalRangeGCMetadataSuffix is the suffix for a range's GC metadata.
	LocalRangeGCMetadataSuffix = proto.Key("rgcm")
	// LocalRangeLastVerificationTimestampSuffix is the suffix for a range's
	// last verification timestamp (for checking integrity of on-disk data).
	LocalRangeLastVerificationTimestampSuffix = proto.Key("rlvt")
	// LocalRangeStatsSuffix is the suffix for range statistics.
	LocalRangeStatsSuffix = proto.Key("stat")

	// LocalRangePrefix is the prefix identifying per-range data indexed
	// by range key (either start key, or some key in the range). The
	// key is appended to this prefix, encoded using EncodeBytes. The
	// specific sort of per-range metadata is identified by one of the
	// suffixes listed below, along with potentially additional encoded
	// key info, such as the txn ID in the case of a transaction record.
	//
	// NOTE: LocalRangePrefix must be kept in sync with the value in
	// storage/engine/db.cc.
	LocalRangePrefix = MakeKey(LocalPrefix, proto.Key("k"))
	LocalRangeMax    = LocalRangePrefix.PrefixEnd()
	// LocalRangeDescriptorSuffix is the suffix for keys storing
	// range descriptors. The value is a struct of type RangeDescriptor.
	LocalRangeDescriptorSuffix = proto.Key("rdsc")
	// LocalRangeTreeNodeSuffix is the suffix for keys storing
	// range tree nodes.  The value is a struct of type RangeTreeNode.
	LocalRangeTreeNodeSuffix = proto.Key("rtn-")
	// LocalTransactionSuffix specifies the key suffix for
	// transaction records. The additional detail is the transaction id.
	// NOTE: if this value changes, it must be updated in C++
	// (storage/engine/db.cc).
	LocalTransactionSuffix = proto.Key("txn-")

	// LocalMax is the end of the local key range.
	LocalMax = LocalPrefix.PrefixEnd()

	// SystemPrefix indicates the beginning of the key range for
	// global, system data which are replicated across the cluster.
	SystemPrefix = proto.Key("\x00")
	SystemMax    = proto.Key("\x01")

	// MetaPrefix is the prefix for range metadata keys. Notice that
	// an extra null character in the prefix causes all range addressing
	// records to sort before any system tables which they might describe.
	MetaPrefix = MakeKey(SystemPrefix, proto.Key("\x00meta"))
	// Meta1Prefix is the first level of key addressing. The value is a
	// RangeDescriptor struct.
	Meta1Prefix = MakeKey(MetaPrefix, proto.Key("1"))
	// Meta2Prefix is the second level of key addressing. The value is a
	// RangeDescriptor struct.
	Meta2Prefix = MakeKey(MetaPrefix, proto.Key("2"))
	// Meta1KeyMax is the end of the range of the first level of key addressing.
	// The value is a RangeDescriptor struct.
	Meta1KeyMax = MakeKey(Meta1Prefix, proto.KeyMax)
	// Meta2KeyMax is the end of the range of the second level of key addressing.
	// The value is a RangeDescriptor struct.
	Meta2KeyMax = MakeKey(Meta2Prefix, proto.KeyMax)

	// MetaMax is the end of the range of addressing keys.
	MetaMax = MakeKey(SystemPrefix, proto.Key("\x01"))

	// ConfigZonePrefix specifies the key prefix for zone
	// configurations. The suffix is the affected key prefix.
	ConfigZonePrefix = MakeKey(SystemPrefix, proto.Key("zone"))
	// DescIDGenerator is the global descriptor ID generator sequence used for
	// table and namespace IDs.
	DescIDGenerator = MakeKey(SystemPrefix, proto.Key("desc-idgen"))
	// NodeIDGenerator is the global node ID generator sequence.
	NodeIDGenerator = MakeKey(SystemPrefix, proto.Key("node-idgen"))
	// RangeIDGenerator is the global range ID generator sequence.
	RangeIDGenerator = MakeKey(SystemPrefix, proto.Key("range-idgen"))
	// StoreIDGenerator is the global store ID generator sequence.
	StoreIDGenerator = MakeKey(SystemPrefix, proto.Key("store-idgen"))
	// RangeTreeRoot specifies the root range in the range tree.
	RangeTreeRoot = MakeKey(SystemPrefix, proto.Key("range-tree-root"))

	// StatusPrefix specifies the key prefix to store all status details.
	StatusPrefix = MakeKey(SystemPrefix, proto.Key("status-"))
	// StatusStorePrefix stores all status info for stores.
	StatusStorePrefix = MakeKey(StatusPrefix, proto.Key("store-"))
	// StatusNodePrefix stores all status info for nodes.
	StatusNodePrefix = MakeKey(StatusPrefix, proto.Key("node-"))

	// TableDataPrefix prefixes all table data. It is specifically chosen to
	// occur after the range of common user data prefixes so that tests which use
	// those prefixes will not see table data.
	TableDataPrefix = proto.Key("\xff")

	// UserTableDataMin is the start key of user structured data.
	UserTableDataMin = MakeTablePrefix(MaxReservedDescID + 1)
)

Constants for system-reserved keys in the KV map.

View Source
var (
	// Meta1Span holds all first level addressing.
	Meta1Span = Span{proto.KeyMin, Meta2Prefix}

	// ZoneConfigSpan is the range for all zone configs.
	ZoneConfigSpan = Span{ConfigZonePrefix, ConfigZonePrefix.PrefixEnd()}

	// UserDataSpan is the non-meta and non-structured portion of the key space.
	UserDataSpan = Span{SystemMax, TableDataPrefix}

	// SystemDBSpan is the range of system objects for structured data.
	SystemDBSpan = Span{TableDataPrefix, UserTableDataMin}

	// NoSplitSpans describes the ranges that should never be split.
	// Meta1Span: needed to find other ranges.
	// ZoneConfigSpan: configs are hierarchical by prefix.
	// SystemDBSpan: system objects have interdepencies.
	NoSplitSpans = []Span{Meta1Span, ZoneConfigSpan, SystemDBSpan}
)

Functions

func DecodeRaftStateKey

func DecodeRaftStateKey(key proto.Key) proto.RangeID

DecodeRaftStateKey extracts the Range ID from a RaftStateKey.

func DecodeRangeKey

func DecodeRangeKey(key proto.Key) (startKey, suffix, detail proto.Key)

DecodeRangeKey decodes the range key into range start key, suffix and optional detail (may be nil).

func KeyAddress

func KeyAddress(k proto.Key) proto.Key

KeyAddress returns the address for the key, used to lookup the range containing the key. In the normal case, this is simply the key's value. However, for local keys, such as transaction records, range-spanning binary tree node pointers, and message queues, the address is the trailing suffix of the key, with the local key prefix removed. In this way, local keys address to the same range as non-local keys, but are stored separately so that they don't collide with user-space or global system keys.

However, not all local keys are addressable in the global map. Only range local keys incorporating a range key (start key or transaction key) are addressable (e.g. range metadata and txn records). Range local keys incorporating the Range ID are not (e.g. response cache entries, and range stats).

func MakeKey

func MakeKey(keys ...proto.Key) proto.Key

MakeKey makes a new key which is the concatenation of the given inputs, in order.

func MakeRangeIDKey

func MakeRangeIDKey(rangeID proto.RangeID, suffix, detail proto.Key) proto.Key

MakeRangeIDKey creates a range-local key based on the range's Range ID, metadata key suffix, and optional detail (e.g. the encoded command ID for a response cache entry, etc.).

func MakeRangeKey

func MakeRangeKey(key, suffix, detail proto.Key) proto.Key

MakeRangeKey creates a range-local key based on the range start key, metadata key suffix, and optional detail (e.g. the transaction ID for a txn record, etc.).

func MakeStoreKey

func MakeStoreKey(suffix, detail proto.Key) proto.Key

MakeStoreKey creates a store-local key based on the metadata key suffix, and optional detail.

func MakeTablePrefix

func MakeTablePrefix(tableID uint32) []byte

MakeTablePrefix returns the key prefix used for the table's data.

func MetaReverseScanBounds

func MetaReverseScanBounds(key proto.Key) (proto.Key, proto.Key, error)

MetaReverseScanBounds returns the range [start,end) within which the desired meta record can be found by means of a reverse engine scan. The given key must be a valid RangeMetaKey as defined by ValidateRangeMetaKey.

func MetaScanBounds

func MetaScanBounds(key proto.Key) (proto.Key, proto.Key)

MetaScanBounds returns the range [start,end) within which the desired meta record can be found by means of an engine scan. The given key must be a valid RangeMetaKey as defined by ValidateRangeMetaKey.

func NodeStatusKey

func NodeStatusKey(nodeID int32) proto.Key

NodeStatusKey returns the key for accessing the node status for the specified node ID.

func RaftAppliedIndexKey

func RaftAppliedIndexKey(rangeID proto.RangeID) proto.Key

RaftAppliedIndexKey returns a system-local key for a raft applied index.

func RaftHardStateKey

func RaftHardStateKey(rangeID proto.RangeID) proto.Key

RaftHardStateKey returns a system-local key for a Raft HardState.

func RaftLastIndexKey

func RaftLastIndexKey(rangeID proto.RangeID) proto.Key

RaftLastIndexKey returns a system-local key for a raft last index.

func RaftLeaderLeaseKey

func RaftLeaderLeaseKey(rangeID proto.RangeID) proto.Key

RaftLeaderLeaseKey returns a system-local key for a raft leader lease.

func RaftLogKey

func RaftLogKey(rangeID proto.RangeID, logIndex uint64) proto.Key

RaftLogKey returns a system-local key for a Raft log entry.

func RaftLogPrefix

func RaftLogPrefix(rangeID proto.RangeID) proto.Key

RaftLogPrefix returns the system-local prefix shared by all entries in a Raft log.

func RaftTruncatedStateKey

func RaftTruncatedStateKey(rangeID proto.RangeID) proto.Key

RaftTruncatedStateKey returns a system-local key for a RaftTruncatedState.

func RangeDescriptorKey

func RangeDescriptorKey(key proto.Key) proto.Key

RangeDescriptorKey returns a range-local key for the descriptor for the range with specified key.

func RangeGCMetadataKey

func RangeGCMetadataKey(rangeID proto.RangeID) proto.Key

RangeGCMetadataKey returns a range-local key for range garbage collection metadata.

func RangeLastVerificationTimestampKey

func RangeLastVerificationTimestampKey(rangeID proto.RangeID) proto.Key

RangeLastVerificationTimestampKey returns a range-local key for the range's last verification timestamp.

func RangeMetaKey

func RangeMetaKey(key proto.Key) proto.Key

RangeMetaKey returns a range metadata (meta1, meta2) indexing key for the given key. For ordinary keys this returns a level 2 metadata key - for level 2 keys, it returns a level 1 key. For level 1 keys and local keys, KeyMin is returned.

func RangeStatsKey

func RangeStatsKey(rangeID proto.RangeID) proto.Key

RangeStatsKey returns the key for accessing the MVCCStats struct for the specified Range ID.

func RangeTreeNodeKey

func RangeTreeNodeKey(key proto.Key) proto.Key

RangeTreeNodeKey returns a range-local key for the the range's node in the range tree.

func ResponseCacheKey

func ResponseCacheKey(rangeID proto.RangeID, cmdID *proto.ClientCmdID) proto.Key

ResponseCacheKey returns a range-local key by Range ID for a response cache entry, with detail specified by encoding the supplied client command ID.

func StoreIdentKey

func StoreIdentKey() proto.Key

StoreIdentKey returns a store-local key for the store metadata.

func StoreStatusKey

func StoreStatusKey(storeID int32) proto.Key

StoreStatusKey returns the key for accessing the store status for the specified store ID.

func TransactionKey

func TransactionKey(key proto.Key, id []byte) proto.Key

TransactionKey returns a transaction key based on the provided transaction key and ID. The base key is encoded in order to guarantee that all transaction records for a range sort together.

func ValidateRangeMetaKey

func ValidateRangeMetaKey(key proto.Key) error

ValidateRangeMetaKey validates that the given key is a valid Range Metadata key.

Types

type InvalidRangeMetaKeyError

type InvalidRangeMetaKeyError struct {
	Msg string
	Key proto.Key
}

InvalidRangeMetaKeyError indicates that a Range Metadata key is somehow invalid.

func NewInvalidRangeMetaKeyError

func NewInvalidRangeMetaKeyError(msg string, k proto.Key) *InvalidRangeMetaKeyError

NewInvalidRangeMetaKeyError returns a new InvalidRangeMetaKeyError

func (*InvalidRangeMetaKeyError) Error

func (i *InvalidRangeMetaKeyError) Error() string

Error formats error string.

type Span

type Span struct {
	Start, End proto.Key
}

Span describes a span of keys: [start,end). This will correspond to one or more range.

func (*Span) ContainsKey

func (s *Span) ContainsKey(key proto.Key) bool

ContainsKey returns true if the span contains 'key'.

Jump to

Keyboard shortcuts

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