HBase对外暴露出来的是一个表格数据模型,如下图所示

rowkey应用程序可以自己设计。每一个Cell可以保存多个版本的数据,由timestamp标示版本。应用程序可以自己指定timestamp,如果不指定HBase会设置为当前时间。

RegionServer是HBase对外提供数据存取的server,核心的数据结构是java.util.concurrent ConcurrentSkipListMap, 实际上是一个用SkipList实现有序Map,对外是一个KV的接口。那上图中的表格数据模型是如何映射到KV接口上的?

实际上,从表格模型可以看出,<rowkey,column family, column qualifier, timestamp>这个4元组唯一的决定一个value,从这里可以看出,KV接口的Key基本就是由上述这几项组成。具体的在HBase中,

rowkey, column family, column qualifier, timestamp,value 都存储在结构KeyValue中,结构如下图所示:

这个结构直接存储在ConcurrentSkipListMap中,作为Key,ConcurrentSkipListMap的Value不重要,在实现中也是KeyValue。

ConcurrentSkipListMap在构造时,会传入一个java.util.Comparator,实现中对普通的数据表格来说,传入的是KVComparator,它比较两个KeyValue,比较准则是先比较按照字典序比较rowkey,如果相等则比较column family,接着是column qualifier, timestamp, type, mvcc。其中type有如下几种:

public static enum Type {
Minimum((byte)0),
Put((byte)4),
Delete((byte)8),
DeleteFamilyVersion((byte)10),
DeleteColumn((byte)12),
DeleteFamily((byte)14), // Maximum is used when searching; you look from maximum on down.
Maximum((byte)255);
}

所以实际上,删除某行,或者某个column family,或者某个qualifier的过程实际上都是往ConcurrentSkipListMap插入了一行,并且,一次put多个qualifier最后体现在ConcurrentSkipListMap中也是多行。那么,显然,在读一行数据的时候,需要scan这个ConcurrentSkipListMap,将rowkey相同的行都给扫描出来,将相关的qualifier组装起来,并且需要处理各种Delete相关的type,TTL以及KeyValue是否可读的问题(mvcc字段,关于MVCC,参见这篇博客),还有用户设置的一些filter等等。由于用户一般读数据都是读最新的版本,为了scan更少的数据,KeyValue的排序中有一个规则是,timestamp越大的KeyValue排在更前面。

LevelDB/RocksDB实际上提供的就是KV的接口,Key和Value都是byte[]。它实际上是一个LSM的系统。普遍认为它是BigTable的tablet server中的一个模块,将和NameNode打交道,上层的表格封装给去掉了。

实际上,国内Baidu的网页搜索部已经开源了一个叫做Tera的表格系统,其中tablet server就是基于LevelDB做的。它的格式"KeyValue"格式是这样:

[rowkey\0|column\0|qualifier\0|type|timestamp]

[rlen+1B | clen+1B | qlen+1B | 1B | 7B ]

参考资料

HBase 0.98

Tera

基于KV Data Model实现Table Data Model的更多相关文章

  1. The Model represents your data structures.

    w模型代表数据结构. https://www.codeigniter.com/userguide3/overview/mvc.html http://codeigniter.org.cn/user_g ...

  2. Data Management Technology(2) -- Data Model

    1.Data Model Model Is the abstraction of real world Reveal the essence of objects, help people to lo ...

  3. Generic recipe for data analysis with general linear model

    Generic recipe for data analysis with general linear model Courtesy of David Schneider State populat ...

  4. 報錯:One or more validation errors were detected during model generation:System.Data.Edm.EdmEntityType: : EntityType 'Movie' has no key

    報錯:One or more validation errors were detected during model generation:System.Data.Edm.EdmEntityType ...

  5. 【集成学习】sklearn中xgboot模块中fit函数参数详解(fit model for train data)

    参数解释,后续补上. # -*- coding: utf-8 -*- """ ############################################## ...

  6. QStandardItemModel的data线程安全(在插入数据时,临时禁止sizeHint去读model中的data)

    版权声明:本文为博主原创文章,欢迎转载,转载请注明出处 https://blog.csdn.net/MatchYang/article/details/52988257 在直接使用QStandardI ...

  7. [Node.js] Create a model to persist data in a Node.js LoopBack API

    In this lesson you will learn what a LoopBack model is, you will create a Product model using the Lo ...

  8. 架构模式数据源模式之:表数据入口(Table Data Gateway)、行数据入口(Row Data Gateway)、活动记录(Active Record)

    一:表数据入口(Table Data Gateway) 表数据入口提供了用于访问单个表或者视图(也包含了联表查询)的所有SQL,通常一个表一个类.其它代码通过它来实现对数据库的交互.基于这个特点,表数 ...

  9. Table View Programming Guide for iOS---(四)---Navigating a Data Hierarchy with Table Views

    Navigating a Data Hierarchy with Table Views 导航数据表视图层次 A common use of table views—and one to which ...

随机推荐

  1. web跨域解决方案

    阅读目录 什么是跨域 常用的几种跨域处理方法: 跨域的原理解析及实现方法 总结 摘要:跨域问题,无论是面试还是平时的工作中,都会遇到,本文总结处理跨域问题的几种方法以及其原理,也让自己搞懂这方面的知识 ...

  2. MySql 执行语句错误 Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

    关于用Power Designer 生成sql文件出现 错误  [Err] 1064 - You have an error in your SQL syntax; check the manual ...

  3. mac osx 系统 brew install hadoop 安装指南

    mac osx 系统 brew  install hadoop 安装指南   brew install hadoop 配置 core-site.xml:配置hdfs文件地址(记得chmod 对应文件夹 ...

  4. Mysql 字符串截取

    1.从左开始截取字符串 left(str, length) 说明:left(被截取字段,截取长度) 例:select left(content,200) as abstract from my_con ...

  5. javascript 搜索二叉树

    function Tree() { this.root = null; } Tree.prototype = { constructor: Tree, addItem: function(value) ...

  6. 重建 windows 图标缓存

    执行命令: ie4uinit –show 好像可以吧?

  7. post 的body json要使用双引号,而不是单引号

      string parse error , JS eval error {'name' : 'wade' }   http://json.parser.online.fr/ string parse ...

  8. Windows下Git安装指南

    参考<Git权威指南>安装整理,图书配套网址参见[1] 1. Cygwin下安装配置Git 1. 在Windows下安装配置Git有2种不同的方案 (1)msysGit, (2)Cygwi ...

  9. Excel的一些常用设置

    1. Freeze表头 (1) 下拉Worksheet的Pane,让该sheet有2个工作区,将该pane下拉到某一特定的行. (2)Window->Freeze Panes.此时会将pane智 ...

  10. android 编译 release 签名

    1.编译 ionic build --release android 2.签名文件 keytool -genkey -alias kwwy -keyalg RSA -validity 40000 -k ...