查看HBase表在HDFS中的文件结构

为了查看HBASE表在HDFS中的文件结构.

在HBASE中建立一张表结构如下:

{NAME => 'USER_TEST_TABLE', 
MEMSTORE_FLUSHSIZE => '67108864', 
MAX_FILESIZE => '1073741824', 
FAMILIES => [
{NAME => 'info', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', 
COMPRESSION => 'NONE', VERSIONS => '1', TTL => '2147483647', 
BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'
}, 
{NAME => 'info2', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', 
COMPRESSION => 'NONE', VERSIONS => '1', TTL => '2147483647', 
BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'
}
]
}

结构图如下, 往下表插入测试数据, 下面查看此表在HDFS中文件的存储方式.

查看HBase表在HDFS中的文件结构_第1张图片

由于在HBase服务器配置文件中指定的存储HBase文件的HDFS地址为:

hdfs://HADOOPCLUS01:端口/hbase

登录到namenode服务器,这里为HADOOPCLUS01, 用hadoop命令查看hbase在hdfs中此表的文件.

1. 查看Hbase根目录. 

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -ls hadoop fs -ls /hbase
Found 37 items
drwxr-xr-x   - hadoop cug-admin          0 2013-03-27 09:29 /hbase/-ROOT-
drwxr-xr-x   - hadoop cug-admin          0 2013-03-27 09:29 /hbase/.META.
drwxr-xr-x   - hadoop cug-admin          0 2013-03-26 13:15 /hbase/.corrupt
drwxr-xr-x   - hadoop cug-admin          0 2013-03-27 09:48 /hbase/.logs
drwxr-xr-x   - hadoop cug-admin          0 2013-03-30 17:49 /hbase/.oldlogs
drwxr-xr-x   - hadoop cug-admin          0 2013-03-30 17:49 /hbase/splitlog
drwxr-xr-x   - hadoop cug-admin          0 2013-03-30 17:49 /hbase/USER_TEST_TABLE

 可以看到所有表的信息. 在hdfs中的建立的目录. 一个表对应一个目录.

-ROOT-表和.META.表也不例外, -ROOT-表和.META.表都有同样的表结构, 关于两表的表结构和怎么对应HBase整个环境的表的HRegion, 可以查看上篇转载的文章.

splitlog和.corrupt目录分别是log split进程用来存储中间split文件的和损坏的日志文件的。

.logs和.oldlogs目录为HLog的存储.

.oldlogs为已经失效的HLog(Hlog对HBase数据库写Put已经全部完毕), 后面进行删除.

HLog File 是一个Sequence File,HLog File 由一条条的 HLog.Entry构成。可以说Entry是HLog的基本组成部分,也是Read 和Write的基本单位。

Entry由两个部分组成:HLogKey和WALEdit。

2. 查看建立表hdfs目录内容:

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -ls /hbase/USER_TEST_TABLE
Found 2 items
drwxr-xr-x   - hadoop cug-admin          0 2013-03-28 10:18 /hbase/USER_TEST_TABLE/03d99a89a256f0e09d0222709b1d0cbe
drwxr-xr-x   - hadoop cug-admin          0 2013-03-28 10:18 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce

 有两个目录, 说明此表已经分裂成两个HRegion.

3. 在查看其中一个HRegion的文件目录.

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -ls /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce
Found 4 items
-rw-r--r--   3 hadoop cug-admin       1454 2013-03-28 10:18 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/.regioninfo
drwxr-xr-x   - hadoop cug-admin          0 2013-03-29 15:21 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/.tmp
drwxr-xr-x   - hadoop cug-admin          0 2013-03-29 15:21 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info
drwxr-xr-x   - hadoop cug-admin          0 2013-03-28 10:18 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info2

 .regioninfo 此HRegion的信息. StartRowKey, EndRowKey. 记录Region在表中的范围信息.

 info, info2, 两个ColumnFamily.  为两个目录.

4. 再对.regioninfo文件用cat查看内容:

乱码已经过滤, 存储的信息整理:

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -cat /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/.regioninfo
USER_TEST_TABLE,AAA-AAA11110UC1,1364437081331.68b8ad74920040ba9f39141e908c67ce.
AA-AAA11110UC1
USER_TEST_TABLE

IS_ROOT false
IS_META false
MAX_FILESIZE 1073741824
MEMSTORE_FLUSHSIZ 6710886

info
BLOOMFILTER NONE 
REPLICATION_SCOPEVERSIONS 1
COMPRESSION NONE
TTL 2147483647
BLOCKSIZE 65536  
IN_MEMORY false
BLOCKCACHE true

info2
BLOOMFILTER NONE 
REPLICATION_SCOPEVERSIONS 1
COMPRESSION NONE
TTL 2147483647
BLOCKSIZE 65536
IN_MEMORY false
BLOCKCACHE true

REGION => {NAME => 'USER_TEST_TABLE,\x00\x00\x00\x0A\x00\x00\x00\x09AAA-AAA11110UC1\x00\x00\x00\x00,
1364437081331.68b8ad74920040ba9f39141e908c67ce.', 
STARTKEY => '\x00\x00\x00\x0A\x00\x00\x00\x09AAA-AAA11110UC1\x00\x00\x00\x00', 
ENDKEY => '', 
ENCODED => 68b8ad74920040ba9f39141e908c67ce, 
TABLE => {{NAME => 'USER_TEST_TABLE', MAX_FILESIZE => '1073741824', 
MEMSTORE_FLUSHSIZE => '67108864', 
FAMILIES => [{NAME => 'info', BLOOMFILTER => 'NONE', 
REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', 
TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', 
BLOCKCACHE => 'true'}, 
{NAME => 'info2', BLOOMFILTER => 'NONE', 
REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', 
TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', 
BLOCKCACHE => 'true'}]}}
VT102VT102VT102VT102VT102VT102VT102VT102

 5. 查看info ColumnFamily中信息文件和目录:

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -ls /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info
Found 4 items
-rw-r--r--   3 hadoop cug-admin  547290902 2013-03-28 10:18 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info/4024386696476133625
-rw-r--r--   3 hadoop cug-admin  115507832 2013-03-29 15:20 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info/5184431447574744531
-rw-r--r--   3 hadoop cug-admin  220368457 2013-03-29 15:13 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info/6150330155463854827
-rw-r--r--   3 hadoop cug-admin   24207459 2013-03-29 15:21 /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info/7480382738108050697

6. 查看具体保存HBase数据的HDFS文件信息:

[hadoop@HADOOPCLUS01 bin]$ hadoop fs -cat /hbase/USER_TEST_TABLE/68b8ad74920040ba9f39141e908c67ce/info/4024386696476133625
AA-AAA11110UDFinfoChangeType=2 13560596974000
AA-AAA11110UDFinfoCountry=1 13560596974000
AA-AAA11110UDFinfoUpdateTime=13560596974105 13560596974000

AA-AAA11110UDGinfoChangeType=2 13560596974000
AA-AAA11110UDGinfoCountry=1 13560596974000
AA-AAA11110UDGinfoUpdateTime=13560334347205 13560596974000

AA-AAA11110UDHinfoChangeType=2 13560596974000
AA-AAA11110UDHinfoCountry=1 13560596974000
AA-AAA11110UDHinfoUpdateTime=13560281517235 13560596974000

  即是上面图片中插入的其中一部分数据.

在HBase中存储时, 对于每个Qualifer有如下5个属性RowKey, ColumnFamily, Qualifer, TimeStamp, Value.

AA-AAA11110UDFinfoCountry=1 13560596974000

   # AA-AAA11110UDH 部分对应RowKey;

   # info对应了ColumnFamily;

   # Country对应Qualifer;

   # 1对用Value;

   # 13560596974000对应TimeStamp.

 后面将分析RowKey与AA-AAA11110UDH的对应关系.

7. 使用HTTP查看文件:

 在上面命令中, 也可以有Http查看Hdfs中的文件, 配置在hdfs-site.xml下面配置:


dfs.datanode.http.address
0.0.0.0:62075

所以访问HDFS的HTTP的URL为:

http://HADOOPCLUS02:62075/browseDirectory.jsp?namenodeInfoPort=62070&dir=/

 

你可能感兴趣的:(Hbase)