Cockroach Design 翻译 ( 四) 键、多版本值

4  Keys键

Cockroachkeys are arbitrary byte arrays. Keys come in two flavors: system keys and tabledata keys. System keys are used by Cockroach for internal data structures andmetadata. Table data keys contain SQL table data (as well as index data).System and table data keys are prefixed in such a way that all system keys sortbefore any table data keys.

Cockroach key是任意byte数组。Key分成两种:系统Key和表数据Key。系统KeyCockroach使用,用于内部数据结构和元数据。表数据Key包含SQL表数据(也包含索引数据)。系统Key和表数据Key都被增加前缀,使用此种方式来使得排序时所有系统Key都在表数据Key之前。

System keyscome in several subtypes:

Global keys store cluster-wide datasuch as the "meta1" and "meta2" keys as well as variousother system-wide keys such as the node and store ID allocators.

Store local keys are used forunreplicated store metadata (e.g. the StoreIdent structure). "Unreplicated" indicates that thesevalues are not replicated across multiple stores because the data they hold istied to the lifetime of the store they are present on.

Range local keys store rangemetadata that is associated with a global key. Range local keys have a specialprefix followed by a global key and a special suffix. For example, transactionrecords are range local keys which look like: \x01k<global-key>txn-<txnID>.

Replicated Range ID local keysstore range metadata that is present on all of the replicas for a range. Thesekeys are updated via Raft operations. Examples include the range lease stateand abort cache entries.

Unreplicated Range ID local keysstore range metadata that is local to a replica. The primary examples of suchkeys are the Raft state and Raft log.

系统Key分成以下几类:

全局Key,存储集群范围内数据(如:”meta1””meta2” key)和各种其他系统范围内Key(如:节点和store ID分配器)。

store本地Key,用于非复制store元数据(如:StoreIdent结构)。“非复制”指这些值不会跨越多个store进行复制,因为这些Key所容纳数据与它们所在的store的生命周期紧密联系在一起。

Range本地Key,存储与一个全局Key相联系的range元数据。Range本地Key有一个后跟全局Key的特殊前缀和一个特殊的后缀。例如:事务记录是Range本地Key,它看起来会是如下样子:\x01k<global-key>txn-<txnID>。

复制RangeID本地Key存储range元数据,出现在一个range的所有副本中。这些Key通过Raft操作来更新。例如,包括range租约状态和放弃缓存的条目。

非复制RangeID本地Key存储range元数据,对于一个副本是本地的。这些Key的例子主要是Raft状态和Raft日志。

Table datakeys are used to store all SQL data. Table data keys contain internal structureas described in the section on mapping databetween the SQL model and KV.

表数据Key用于存储所有SQL数据。表数据Key包含内部结构,该内部结构在下面的“SQL模型与KV间的数据映射”章节中描述。

5  Versioned Values多版本值

Cockroachmaintains historical versions of values by storing them with associated committimestamps. Reads and scans can specify a snapshot time to return the mostrecent writes prior to the snapshot timestamp. Older versions of values aregarbage collected by the system during compaction according to a user-specifiedexpiration interval. In order to support long-running scans (e.g. forMapReduce), all versions have a minimum expiration.

Cockroach通过存储commit时间戳来维护值的多个历史版本。读取和扫描可以通过指定一个快照时间来返回该时间戳之前的最近一次更新后的数据。值的老版本在系统根据用户指定的过期间隔而执行合并(compaction)期间被垃圾回收掉。为了支持运行时间较长的数据扫描(如,MapReduce),所有的版本都有一个最小过期时间。

Versionedvalues are supported via modifications to RocksDB to record commit timestampsand GC expirations per key.

多版本值是通过修改RocksDB来记录每个Key的提交时间戳和GC过期时间来实现的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值