keys

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

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

Go to latest
Published: Feb 12, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxSystemConfigDescID is the maximum system descriptor ID that will be
	// gossiped as part of the SystemConfig. Be careful adding new descriptors to
	// this ID range.
	MaxSystemConfigDescID = 10

	// MaxReservedDescID is the maximum value of reserved descriptor
	// IDs. Reserved IDs are used by namespaces and tables used internally by
	// cockroach.
	MaxReservedDescID = 49

	// RootNamespaceID is the ID of the root namespace.
	RootNamespaceID = 0

	// SystemDatabaseID and following are the database/table IDs for objects
	// in the system span.
	// NOTE: IDs must be <= MaxSystemConfigDescID.
	SystemDatabaseID  = 1
	NamespaceTableID  = 2
	DescriptorTableID = 3
	UsersTableID      = 4
	ZonesTableID      = 5

	// Reserved IDs for other system tables.
	// NOTE: IDs must be <= MaxReservedDescID.
	LeaseTableID      = 11
	EventLogTableID   = 12
	RangeEventTableID = 13
)

Various IDs used by the structured data layer. NOTE: these must not change during the lifetime of a cluster.

Variables

View Source
var (

	// LocalMax is the end of the local key range.
	LocalMax = roachpb.Key("\x02")

	// 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, for instance in the
	// case of sequence cache entry.
	//
	// NOTE: LocalRangeIDPrefix must be kept in sync with the value
	// in storage/engine/rocksdb/db.cc.
	LocalRangeIDPrefix = roachpb.RKey(makeKey(localPrefix, roachpb.Key("i")))
	// LocalSequenceCacheSuffix is the suffix used for the replay protection
	// mechanism.
	LocalSequenceCacheSuffix = []byte("res-")

	// 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/rocksdb/db.cc.
	LocalRangePrefix = roachpb.Key(makeKey(localPrefix, roachpb.RKey("k")))
	LocalRangeMax    = LocalRangePrefix.PrefixEnd()
	// LocalRangeDescriptorSuffix is the suffix for keys storing
	// range descriptors. The value is a struct of type RangeDescriptor.
	LocalRangeDescriptorSuffix = roachpb.RKey("rdsc")

	// Meta1Prefix is the first level of key addressing. It is selected such that
	// all range addressing records sort before any system tables which they
	// might describe. The value is a RangeDescriptor struct.
	Meta1Prefix = roachpb.Key("\x02")
	// Meta2Prefix is the second level of key addressing. The value is a
	// RangeDescriptor struct.
	Meta2Prefix = roachpb.Key("\x03")
	// Meta1KeyMax is the end of the range of the first level of key addressing.
	// The value is a RangeDescriptor struct.
	Meta1KeyMax = roachpb.Key(makeKey(Meta1Prefix, roachpb.RKeyMax))
	// Meta2KeyMax is the end of the range of the second level of key addressing.
	// The value is a RangeDescriptor struct.
	Meta2KeyMax = roachpb.Key(makeKey(Meta2Prefix, roachpb.RKeyMax))

	// MetaMin is the start of the range of addressing keys.
	MetaMin = Meta1Prefix
	// MetaMax is the end of the range of addressing keys.
	MetaMax = roachpb.Key("\x04")

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

	// DescIDGenerator is the global descriptor ID generator sequence used for
	// table and namespace IDs.
	DescIDGenerator = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("desc-idgen")))
	// NodeIDGenerator is the global node ID generator sequence.
	NodeIDGenerator = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("node-idgen")))
	// RangeIDGenerator is the global range ID generator sequence.
	RangeIDGenerator = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("range-idgen")))
	// StoreIDGenerator is the global store ID generator sequence.
	StoreIDGenerator = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("store-idgen")))
	// RangeTreeRoot specifies the root range in the range tree.
	RangeTreeRoot = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("range-tree-root")))

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

	// TimeseriesPrefix is the key prefix for all timeseries data.
	TimeseriesPrefix = roachpb.Key(makeKey(SystemPrefix, roachpb.RKey("tsd")))

	// TableDataMin is the start of the range of table data keys.
	TableDataMin = roachpb.Key(encoding.EncodeVarintAscending(nil, math.MinInt64))
	// TableDataMin is the end of the range of table data keys.
	TableDataMax = roachpb.Key(encoding.EncodeVarintAscending(nil, math.MaxInt64))

	// SystemConfigTableDataMax is the end key of system config structured data.
	SystemConfigTableDataMax = roachpb.Key(MakeTablePrefix(MaxSystemConfigDescID + 1))

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

	// MaxKey is the infinity marker which is larger than any other key.
	MaxKey = roachpb.KeyMax
	// MinKey is a minimum key value which sorts before all other keys.
	MinKey = roachpb.KeyMin
)

Constants for system-reserved keys in the KV map.

View Source
var (
	// Meta1Span holds all first level addressing.
	Meta1Span = roachpb.Span{Key: roachpb.KeyMin, EndKey: Meta2Prefix}

	// UserDataSpan is the non-meta and non-structured portion of the key space.
	UserDataSpan = roachpb.Span{Key: SystemMax, EndKey: TableDataMin}

	// SystemConfigSpan is the range of system objects which will be gossiped.
	SystemConfigSpan = roachpb.Span{Key: TableDataMin, EndKey: SystemConfigTableDataMax}

	// NoSplitSpans describes the ranges that should never be split.
	// Meta1Span: needed to find other ranges.
	// SystemConfigSpan: system objects which will be gossiped.
	NoSplitSpans = []roachpb.Span{Meta1Span, SystemConfigSpan}
)

Functions

func Addr

func Addr(k roachpb.Key) roachpb.RKey

Addr 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, 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. sequence cache entries, and range stats).

TODO(pmattis): Should KeyAddress return an error when the key is malformed?

func DecodeRangeKey

func DecodeRangeKey(key roachpb.Key) (startKey, suffix, detail roachpb.Key, err error)

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

func DecodeTablePrefix

func DecodeTablePrefix(key roachpb.Key) ([]byte, uint64, error)

DecodeTablePrefix validates that the given key has a table prefix, returning the remainder of the key (with the prefix removed) and the decoded descriptor ID of the table.

func MakeColumnKey

func MakeColumnKey(rowKey []byte, colID uint32) []byte

MakeColumnKey returns the key for the column in the given row.

func MakeNonColumnKey

func MakeNonColumnKey(rowKey []byte) []byte

MakeNonColumnKey creates a non-column key for a row by appending a 0 column ID suffix size to rowKey.

func MakeRangeIDKey

func MakeRangeIDKey(rangeID roachpb.RangeID, suffix, detail roachpb.RKey) roachpb.Key

MakeRangeIDKey creates a range-local key based on the range's Range ID, metadata key suffix, and optional detail.

func MakeRangeIDPrefix

func MakeRangeIDPrefix(rangeID roachpb.RangeID) roachpb.Key

MakeRangeIDPrefix creates a range-local key prefix from rangeID.

func MakeRangeKey

func MakeRangeKey(key, suffix, detail roachpb.RKey) roachpb.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 MakeRangeKeyPrefix

func MakeRangeKeyPrefix(key roachpb.RKey) roachpb.Key

MakeRangeKeyPrefix creates a key prefix under which all range-local keys can be found.

func MakeSplitKey

func MakeSplitKey(key roachpb.Key) (roachpb.Key, error)

MakeSplitKey transforms an SQL table key such that it is a valid split key (i.e. does not occur in the middle of a row).

func MakeStoreKey

func MakeStoreKey(suffix, detail roachpb.RKey) roachpb.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 MassagePrettyPrintedSpanForTest

func MassagePrettyPrintedSpanForTest(span string, dirs []encoding.Direction) string

MassagePrettyPrintedSpanForTest does some transformations on pretty-printed spans and keys: - if dirs is not nil, replace all ints with their ones' complement for descendingly-encoded columns. - strips line numbers from error messages.

func MetaReverseScanBounds

func MetaReverseScanBounds(key roachpb.RKey) (roachpb.Key, roachpb.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 roachpb.RKey) (roachpb.Key, roachpb.Key, error)

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. TODO(tschottdorf): a lot of casting going on inside.

func NodeStatusKey

func NodeStatusKey(nodeID int32) roachpb.Key

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

func PrettyPrint

func PrettyPrint(key roachpb.Key) string

PrettyPrint prints the key in a human readable format:

Key's Format Key's Value /Local/... "\x01"+...

/Store/...                                  "\x01s"+...
/RangeID/...                                "\x01s"+[rangeid]
	/[rangeid]/SequenceCache/[id]/seq:[seq]   "\x01s"+[rangeid]+"res-"+[id]+[seq]
	/[rangeid]/RaftLeaderLease                "\x01s"+[rangeid]+"rfll"
	/[rangeid]/RaftTombstone                  "\x01s"+[rangeid]+"rftb"
	/[rangeid]/RaftHardState						      "\x01s"+[rangeid]+"rfth"
	/[rangeid]/RaftAppliedIndex						    "\x01s"+[rangeid]+"rfta"
	/[rangeid]/RaftLog/logIndex:[logIndex]    "\x01s"+[rangeid]+"rftl"+[logIndex]
	/[rangeid]/RaftTruncatedState             "\x01s"+[rangeid]+"rftt"
	/[rangeid]/RaftLastIndex                  "\x01s"+[rangeid]+"rfti"
	/[rangeid]/RangeLastVerificationTimestamp "\x01s"+[rangeid]+"rlvt"
	/[rangeid]/RangeStats                     "\x01s"+[rangeid]+"stat"
/Range/...                                  "\x01k"+...
	/RangeDescriptor/[key]                    "\x01k"+[key]+"rdsc"
	/RangeTreeNode/[key]                      "\x01k"+[key]+"rtn-"
	/Transaction/addrKey:[key]/id:[id]				"\x01k"+[key]+"txn-"+[id]

/Local/Max "\x02"

/Meta1/[key] "\x02"+[key] /Meta2/[key] "\x03"+[key] /System/... "\x04"

/StatusStore/[key]                          "\x04status-store-"+[key]
/StatusNode/[key]                           "\x04status-node-"+[key]

/System/Max "\x05"

/Table/[key] [key]

/Min "" /Max "\xff\xff"

func RaftAppliedIndexKey

func RaftAppliedIndexKey(rangeID roachpb.RangeID) roachpb.Key

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

func RaftHardStateKey

func RaftHardStateKey(rangeID roachpb.RangeID) roachpb.Key

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

func RaftLastIndexKey

func RaftLastIndexKey(rangeID roachpb.RangeID) roachpb.Key

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

func RaftLeaderLeaseKey

func RaftLeaderLeaseKey(rangeID roachpb.RangeID) roachpb.Key

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

func RaftLogKey

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

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

func RaftLogPrefix

func RaftLogPrefix(rangeID roachpb.RangeID) roachpb.Key

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

func RaftTombstoneKey

func RaftTombstoneKey(rangeID roachpb.RangeID) roachpb.Key

RaftTombstoneKey returns a system-local key for a raft tombstone.

func RaftTruncatedStateKey

func RaftTruncatedStateKey(rangeID roachpb.RangeID) roachpb.Key

RaftTruncatedStateKey returns a system-local key for a RaftTruncatedState.

func Range

Range returns a key range encompassing all the keys in the Batch. TODO(tschottdorf): there is no protection for doubly-local keys here; maybe Range should return an error.

func RangeDescriptorKey

func RangeDescriptorKey(key roachpb.RKey) roachpb.Key

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

func RangeLastVerificationTimestampKey

func RangeLastVerificationTimestampKey(rangeID roachpb.RangeID) roachpb.Key

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

func RangeMetaKey

func RangeMetaKey(key roachpb.RKey) roachpb.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 roachpb.RangeID) roachpb.Key

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

func RangeTreeNodeKey

func RangeTreeNodeKey(key roachpb.RKey) roachpb.Key

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

func SequenceCacheKey

func SequenceCacheKey(rangeID roachpb.RangeID, txnID *uuid.UUID, epoch uint32, seq uint32) roachpb.Key

SequenceCacheKey returns a range-local key by Range ID for a sequence cache entry, with detail specified by encoding the supplied transaction ID, epoch and sequence number.

func SequenceCacheKeyPrefix

func SequenceCacheKeyPrefix(rangeID roachpb.RangeID, txnID *uuid.UUID) roachpb.Key

SequenceCacheKeyPrefix returns the prefix common to all sequence cache keys for the given transaction ID.

func StoreGossipKey

func StoreGossipKey() roachpb.Key

StoreGossipKey returns a store-local key for the gossip bootstrap metadata.

func StoreIdentKey

func StoreIdentKey() roachpb.Key

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

func StoreStatusKey

func StoreStatusKey(storeID int32) roachpb.Key

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

func TransactionKey

func TransactionKey(key roachpb.Key, txnID *uuid.UUID) roachpb.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.

Types

type InvalidRangeMetaKeyError

type InvalidRangeMetaKeyError struct {
	Msg string
	Key roachpb.Key
}

InvalidRangeMetaKeyError indicates that a Range Metadata key is somehow invalid.

func NewInvalidRangeMetaKeyError

func NewInvalidRangeMetaKeyError(msg string, k []byte) *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