HBase提供了hbck命令来检查各种不一致问题。hbck的名字仿效了HDFS的fsck命令,后者是一个用于检查HDFS中不一致问题的工具。下面这段非常易懂的介绍出自于hbck的源程序。
检查数据在Master及RegionServer的内存中状态与数据在HDFS中的状态之间的一致性。
HBase的hbck不仅能够检查不一致问题,而且还能够修复不一致问题。
在生产环境中,应当经常运行hbck,以便及早发现不一致问题并更容易地解决问题。
首先,在HBase上创建一张表usertable。
然后,在HDFS上直接删除usertable表的目录/hbase/usertable来删除表的数据(错误的做法)。
1.hbase hbck
Status:OK,表示没有发现不一致问题。
Status:INCONSISTENT,表示有不一致问题。
2.hbase hbck -fixAssignments
Try to fix region assignments. Replaces the old -fix
[zk: 192.168.147.15:2181(CONNECTED) 3] ls /hbase/unassigned
3.hbase hbck -fixMeta
Try to fix meta problems. This assumes HDFS region info is good.
hbase(main):007:0> scan '.META.'
4.hbase(main):015:0> create 'usertable','f1'
ERROR: Table already exists: usertable!
[zk: 192.168.147.15:2181(CONNECTED) 4] ls /hbase/table
[usertable]
[zk: 192.168.147.15:2181(CONNECTED) 5] get /hbase/table/usertable
ENABLING
[zk: 192.168.147.15:2181(CONNECTED) 6] rmr /hbase/table/usertable
[zk: 192.168.147.15:2181(CONNECTED) 7] get /hbase/table/usertable
Node does not exist: /hbase/table/usertable
此时,create 'usertable','f1',依然提示同样的错误。
查看ZKTable源码:
/** * Cache of what we found in zookeeper so we don't have to go to zk ensemble * for every query. Synchronize access rather than use concurrent Map because * synchronization needs to span query of zk. */ private final Map<String, TableState> cache = new HashMap<String, TableState>(); this.cache.put(tableName, state);
把ZK中的数据缓存在本地内存中,以加速访问,减少访问时间。
为了让本地内存中的数据失效,必须重启HBase集群。
重启HBase集群。
此时,create 'usertable','f1',没有提示错误,表创建成功。
[bigdata@tbe192168147015 ~]$ hbase hbck -h Usage: fsck [opts] {only tables} where [opts] are: -help Display help options (this) -details Display full report of all regions. -timelag {timeInSeconds} Process only regions that have not experienced any metadata updates in the last {{timeInSeconds} seconds. -sleepBeforeRerun {timeInSeconds} Sleep this many seconds before checking if the fix worked if run with -fix -summary Print only summary of the tables and status. -metaonly Only check the state of ROOT and META tables. Repair options: (expert features, use with caution!) -fix Try to fix region assignments. This is for backwards compatiblity -fixAssignments Try to fix region assignments. Replaces the old -fix -fixMeta Try to fix meta problems. This assumes HDFS region info is good. -fixHdfsHoles Try to fix region holes in hdfs. -fixHdfsOrphans Try to fix region dirs with no .regioninfo file in hdfs -fixHdfsOverlaps Try to fix region overlaps in hdfs. -fixVersionFile Try to fix missing hbase.version file in hdfs. -maxMerge <n> When fixing region overlaps, allow at most <n> regions to merge. (n=5 by default) -sidelineBigOverlaps When fixing region overlaps, allow to sideline big overlaps -maxOverlapsToSideline <n> When fixing region overlaps, allow at most <n> regions to sideline per group. (n=2 by default) -repair Shortcut for -fixAssignments -fixMeta -fixHdfsHoles -fixHdfsOrphans -fixHdfsOverlaps -fixVersionFile -sidelineBigOverlaps -repairHoles Shortcut for -fixAssignments -fixMeta -fixHdfsHoles -fixHdfsOrphans