Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeRaftStateKey(key proto.Key) proto.RangeID
- func DecodeRangeKey(key proto.Key) (startKey, suffix, detail proto.Key)
- func KeyAddress(k proto.Key) proto.Key
- func MakeKey(keys ...proto.Key) proto.Key
- func MakeRangeIDKey(rangeID proto.RangeID, suffix, detail proto.Key) proto.Key
- func MakeRangeKey(key, suffix, detail proto.Key) proto.Key
- func MakeStoreKey(suffix, detail proto.Key) proto.Key
- func MakeTablePrefix(tableID uint32) []byte
- func MetaReverseScanBounds(key proto.Key) (proto.Key, proto.Key, error)
- func MetaScanBounds(key proto.Key) (proto.Key, proto.Key, error)
- func NodeStatusKey(nodeID int32) proto.Key
- func RaftAppliedIndexKey(rangeID proto.RangeID) proto.Key
- func RaftHardStateKey(rangeID proto.RangeID) proto.Key
- func RaftLastIndexKey(rangeID proto.RangeID) proto.Key
- func RaftLeaderLeaseKey(rangeID proto.RangeID) proto.Key
- func RaftLogKey(rangeID proto.RangeID, logIndex uint64) proto.Key
- func RaftLogPrefix(rangeID proto.RangeID) proto.Key
- func RaftTruncatedStateKey(rangeID proto.RangeID) proto.Key
- func Range(br proto.BatchRequest) (proto.Key, proto.Key)
- func RangeDescriptorKey(key proto.Key) proto.Key
- func RangeGCMetadataKey(rangeID proto.RangeID) proto.Key
- func RangeLastVerificationTimestampKey(rangeID proto.RangeID) proto.Key
- func RangeMetaKey(key proto.Key) proto.Key
- func RangeStatsKey(rangeID proto.RangeID) proto.Key
- func RangeTreeNodeKey(key proto.Key) proto.Key
- func ResponseCacheKey(rangeID proto.RangeID, cmdID *proto.ClientCmdID) proto.Key
- func StoreIdentKey() proto.Key
- func StoreStatusKey(storeID int32) proto.Key
- func TransactionKey(key proto.Key, id []byte) proto.Key
- type InvalidRangeMetaKeyError
- type Span
Constants ¶
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. MaxReservedDescID = 999 // 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 should remain <= MaxReservedDescID. SystemDatabaseID = 1 NamespaceTableID = 2 DescriptorTableID = 3 UsersTableID = 4 ZonesTableID = 5 )
Various IDs used by the structured data layer. NOTE: these must not change during the lifetime of a cluster.
Variables ¶
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")) // 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.
var ( // Meta1Span holds all first level addressing. Meta1Span = Span{proto.KeyMin, Meta2Prefix} // 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. // SystemDBSpan: system objects have interdepencies. NoSplitSpans = []Span{Meta1Span, SystemDBSpan} )
Functions ¶
func DecodeRaftStateKey ¶
DecodeRaftStateKey extracts the Range ID from a RaftStateKey.
func DecodeRangeKey ¶
DecodeRangeKey decodes the range key into range start key, suffix and optional detail (may be nil).
func KeyAddress ¶
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 MakeRangeIDKey ¶
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 ¶
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 ¶
MakeStoreKey creates a store-local key based on the metadata key suffix, and optional detail.
func MakeTablePrefix ¶
MakeTablePrefix returns the key prefix used for the table's data.
func MetaReverseScanBounds ¶
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 ¶
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 ¶
NodeStatusKey returns the key for accessing the node status for the specified node ID.
func RaftAppliedIndexKey ¶
RaftAppliedIndexKey returns a system-local key for a raft applied index.
func RaftHardStateKey ¶
RaftHardStateKey returns a system-local key for a Raft HardState.
func RaftLastIndexKey ¶
RaftLastIndexKey returns a system-local key for a raft last index.
func RaftLeaderLeaseKey ¶
RaftLeaderLeaseKey returns a system-local key for a raft leader lease.
func RaftLogKey ¶
RaftLogKey returns a system-local key for a Raft log entry.
func RaftLogPrefix ¶
RaftLogPrefix returns the system-local prefix shared by all entries in a Raft log.
func RaftTruncatedStateKey ¶
RaftTruncatedStateKey returns a system-local key for a RaftTruncatedState.
func Range ¶
Range returns a key range encompassing all the keys in the Batch. In particular, this resolves local addressing. TODO(tschottdorf): testing. TODO(tschottdorf): figure out where we can pin down requests which span from range-local into range-global space. Those will currently slip through the cracks. TODO(tschottdorf): ideally method on *BatchRequest. See #2198. TODO(tschottdorf): return a keys.Span?
func RangeDescriptorKey ¶
RangeDescriptorKey returns a range-local key for the descriptor for the range with specified key.
func RangeGCMetadataKey ¶
RangeGCMetadataKey returns a range-local key for range garbage collection metadata.
func RangeLastVerificationTimestampKey ¶
RangeLastVerificationTimestampKey returns a range-local key for the range's last verification timestamp.
func RangeMetaKey ¶
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 ¶
RangeStatsKey returns the key for accessing the MVCCStats struct for the specified Range ID.
func RangeTreeNodeKey ¶
RangeTreeNodeKey returns a range-local key for the the range's node in the range tree.
func ResponseCacheKey ¶
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 ¶
StoreIdentKey returns a store-local key for the store metadata.
func StoreStatusKey ¶
StoreStatusKey returns the key for accessing the store status for the specified store ID.
Types ¶
type InvalidRangeMetaKeyError ¶
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.