keys

package
v0.0.0-...-6538a59 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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 Raft ID. The Raft 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"))
	// 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"))

	// ConfigAccountingPrefix specifies the key prefix for accounting
	// configurations. The suffix is the affected key prefix.
	ConfigAccountingPrefix = MakeKey(SystemPrefix, proto.Key("acct"))
	// ConfigPermissionPrefix specifies the key prefix for accounting
	// configurations. The suffix is the affected key prefix.
	ConfigPermissionPrefix = MakeKey(SystemPrefix, proto.Key("perm"))
	// ConfigUserPrefix specified the key prefix for user configurations.
	// The suffix is the username.
	ConfigUserPrefix = MakeKey(SystemPrefix, proto.Key("user"))
	// 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"))
	// DescMetadataPrefix is the key prefix for all descriptor metadata.
	DescMetadataPrefix = MakeKey(SystemPrefix, proto.Key("desc-"))
	// NodeIDGenerator is the global node ID generator sequence.
	NodeIDGenerator = MakeKey(SystemPrefix, proto.Key("node-idgen"))
	// RaftIDGenerator is the global Raft consensus group ID generator sequence.
	RaftIDGenerator = MakeKey(SystemPrefix, proto.Key("raft-idgen"))
	// SchemaPrefix specifies key prefixes for schema definitions.
	SchemaPrefix = MakeKey(SystemPrefix, proto.Key("schema"))
	// NameMetadataPrefix is the key prefix for all name metadata.
	NameMetadataPrefix = MakeKey(SystemPrefix, proto.Key("name-"))
	// 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 to aid in transitioning
	// key:value data to Table data, and for ease of debugging.
	TableDataPrefix = proto.Key("table-")
)

Constants for system-reserved keys in the KV map.

Functions

func DecodeRaftStateKey

func DecodeRaftStateKey(key proto.Key) proto.RangeID

DecodeRaftStateKey extracts the Raft 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 Raft ID are not (e.g. response cache entries, and range stats).

func MakeDescMetadataKey

func MakeDescMetadataKey(descID uint32) proto.Key

MakeDescMetadataKey returns the key for the table in namespaceID.

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 MakeNameMetadataKey

func MakeNameMetadataKey(parentID uint32, name string) proto.Key

MakeNameMetadataKey returns the key for the namespace.

func MakeRangeIDKey

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

MakeRangeIDKey creates a range-local key based on the range's Raft 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 MakeTableDataKey

func MakeTableDataKey(tableID, indexID, columnID uint32, columnValues ...[]byte) proto.Key

MakeTableDataKey returns a key to a value at a specific row and column in the table.

func MakeTableIndexKey

func MakeTableIndexKey(tableID, indexID uint32, columnValues ...[]byte) proto.Key

MakeTableIndexKey returns a primary or a secondary index key.

func MetaScanBounds

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

MetaScanBounds returns the start and end keys of the range 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(raftID proto.RangeID) proto.Key

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

func RaftHardStateKey

func RaftHardStateKey(raftID proto.RangeID) proto.Key

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

func RaftLastIndexKey

func RaftLastIndexKey(raftID proto.RangeID) proto.Key

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

func RaftLeaderLeaseKey

func RaftLeaderLeaseKey(raftID proto.RangeID) proto.Key

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

func RaftLogKey

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

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

func RaftLogPrefix

func RaftLogPrefix(raftID proto.RangeID) proto.Key

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

func RaftTruncatedStateKey

func RaftTruncatedStateKey(raftID 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(raftID proto.RangeID) proto.Key

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

func RangeLastVerificationTimestampKey

func RangeLastVerificationTimestampKey(raftID 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(raftID proto.RangeID) proto.Key

RangeStatsKey returns the key for accessing the MVCCStats struct for the specified Raft 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(raftID proto.RangeID, cmdID *proto.ClientCmdID) proto.Key

ResponseCacheKey returns a range-local key by Raft 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.

Jump to

Keyboard shortcuts

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