看了一些文章,HBase高可靠性是实现了HLog(Write-ahead Log)机制,那么HLog到底存在哪里了呢
首先去HDFS的/hbase目录查看一下.
hadoop fs -ls -R /hbase, 可以看到hbase下面有个.logs文件夹.
logs文件夹下存放的内容就是各个Region Server的HLog
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-1,60020,1378438220355
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-1,60020,1378438220355/cdh-1%2C60020%2C1378438220355.1378438256072
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-2,60020,1378438216417
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-2,60020,1378438216417/cdh-2%2C60020%2C1378438216417.1378438251272
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-3,60020,1378438206589
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-3,60020,1378438206589/cdh-3%2C60020%2C1378438206589.1378438239527
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-4,60020,1378438234235
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-4,60020,1378438234235/cdh-4%2C60020%2C1378438234235.1378438266141
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-5,60020,1378438229856
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-5,60020,1378438229856/cdh-5%2C60020%2C1378438229856.1378438260843
drwxr-xr-x - hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-6,60020,1378438228454
-rw-r--r-- 3 hbase hadoop 0 2013-09-06 11:31 /hbase/.logs/cdh-6,60020,1378438228454/cdh-6%2C60020%2C1378438228454.1378438257558
通过以下命令可以查看cdh-6机器上的HLog内容
hbase hlog /hbase/.logs/cdh-6,60020,1378438228454/cdh-6%2C60020%2C1378438228454.1378438257558
主要内容如下所示:
Sequence 595307 from region 48ad7920dfcefa6fe4ec01dfaea71fec in table users
Action:
row: 2101159060
column: info:name
at time: Fri Sep 06 11:38:53 CST 2013
Sequence 595308 from region 48ad7920dfcefa6fe4ec01dfaea71fec in table users
Action:
row: 2101159060
column: info:name
at time: Fri Sep 06 11:38:53 CST 2013
Sequence 595309 from region 48ad7920dfcefa6fe4ec01dfaea71fec in table users
Action:
row: 2101159060
column: info:name
at time: Fri Sep 06 11:38:53 CST 2013
Sequence 595310 from region 48ad7920dfcefa6fe4ec01dfaea71fec in table users
Action:
row: 2101159060
column: info:name
at time: Fri Sep 06 11:38:53 CST 2013
Sequence 595311 from region 48ad7920dfcefa6fe4ec01dfaea71fec in table users
Action:
row: 2101159060
column: info:name
at time: Fri Sep 06 11:38:53 CST 2013
这里有Region name, Sequence ID, Table name, Row ID, column name,以及时间,如果想看row的value,可以在后面加一个-p参数, hbase hlog的具体用法如下:
usage: HLog <filename...> [-h] [-j] [-p] [-r <arg>] [-s <arg>] [-w <arg>]
-h,--help Output help message
-j,--json Output JSON
-p,--printvals Print values
-r,--region <arg> Region to filter by. Pass region name; e.g.
'.META.,,1'
-s,--sequence <arg> Sequence to filter by. Pass sequence number.
-w,--row <arg> Row to filter by. Pass row name.
通过查看HDFS,可以看到HFile储存在/hbase/user下边
查看hfile命令是: hbase hfile 具体参数如下所示:
usage: HFile [-a] [-b] [-e] [-f <arg>] [-k] [-m] [-p] [-r <arg>] [-s] [-v]
[-w <arg>]
-a,--checkfamily Enable family check
-b,--printblocks Print block index meta data
-e,--printkey Print keys
-f,--file <arg> File to scan. Pass full-path; e.g.
hdfs://a:9000/hbase/.META./12/34
-k,--checkrow Enable row order check; looks for out-of-order
keys
-m,--printmeta Print meta data of file
-p,--printkv Print key/value pairs
-r,--region <arg> Region to scan. Pass region name; e.g. '.META.,,1'
-s,--stats Print statistics
-v,--verbose Verbose output; emits file and meta data
delimiters
-w,--seekToRow <arg> Seek to this row and print all the kvs for this
row only
查看一个HFile具体信息如下:
hbase hfile -s -f /hbase/users/f0bad95c7999b57010dfb4707a29c747/info/2584769dd8334bcda4632b57f50bbe76
Stats:
Key length: count: 3 min: 31 max: 31 mean: 31.0
Val length: count: 3 min: 10242 max: 10242 mean: 10242.0
Row size (bytes): count: 1 min: 30843 max: 30843 mean: 30843.0
Row size (columns): count: 1 min: 3 max: 3 mean: 3.0
Key of biggest row: -2016043148
我们可以根据日常需求,用不同的命令来查看HFile和HLog中的内容.