参考:http://hbase.apache.org/book.html#hbck
https://docs.cloudera.com/documentation/enterprise/5-16-x/topics/admin_hbase_hbck.html
HBaseFsck(hbck)是一种命令行工具,可检查region一致性和表完整性问题并修复损坏
它以两种基本模式工作:只读不一致标识模式和多阶段读写修复模式
- 只读不一致标识:在此模式下(默认情况下),将生成报告,但不尝试维修。
- 读写修复模式:在这种模式下,如果发现错误,则hbck尝试修复它们。
始终以HBase用户(通常为hbase)身份运行HBase管理命令,例如HBase Shell,hbck或bulk-load命令
hbase-1.x附带的hbck工具已在hbase-2.x中设为只读,由于hbase内部已更改,因此无法修复hbase-2.x群集。由于不了解hbase-2.x操作,因此也不应该信任其在只读模式下的评估
CDH5.16.1中的hbase版本为hbase1.2.0,在CDH6.x版本中不能使用hbase-1.x现在的命令
手动执行hbck
hbck命令位于HBase安装目录下的bin目录中。
- 如果不带任何参数,则hbck将检查HBase的不一致性,如果未发现不一致性,则打印OK,否则将显示不一致性的数量。
- 使用
-details
参数,hbck会检查HBase的不一致情况并打印详细的报告。 - 要将
hbck
限制为仅检查特定的表,请将它们提供为以空格分隔的列表:hbck <table1> <table2>
以下hbck选项会修改HBase元数据,这很危险。它们不受HMaster协调,并且可能与HMaster当前正在执行或协调的命令冲突,从而导致进一步损坏。即使HMaster关闭,它也可能会在重新启动时尝试恢复最新操作。这些选项只能用作不得已的方法。hbck命令只能修复实际的HBase元数据损坏,而不是通用维护工具。此外,运行任何这些命令都需要重新启动HMaster。
-
如果发现region级别的不一致,请使用-fix参数指示hbck尝试修复它们。遵循以下步骤顺序
- 运行不一致的标准检查
- 如果需要,可以修理表
- 如果需要,可以对region进行修理。region在修理期间将关闭
-
您也可以分别修复各个region级别的不一致,而不是使用-fix参数自动修复它们。
-fixAssignments
:修复未分配,分配错误或乘以分配的区域。-fixMeta
:当HDFS中不存在其对应region时,-fixMeta将从hbase:meta
中删除行,如果HDFS中存在region但hbase:meta
中不存在区域,则添加新的元数据行。-repairHoles
:为文件系统(HDFS等)上的新空白region创建HFiles并确保新的region一致-fixHdfsOrphans
:修复缺少region元数据文件(.regioninfo文件)的region目录-fixHdfsOverlaps
:修复重叠的region,您可以使用以下选项进一步调整此参数( The same start key. 超过5个时,一定要加-maxMerge <n>
不然没用)-maxMerge <n>
:控制要合并的最大region数-sidelineBigOverlaps
:当修复region重叠时,允许将较大的重叠放在一起-maxOverlapsToSideline <n>
:当修复区域重叠时,每组最多允许<n>
个区域边线。(默认为n=2)
-
要尝试一次修复所有不一致和损坏,请使用
-repair
选项,该选项包括所有区域和表一致性选项。
hbck命令
要运行hbck,请使用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 the hbase:meta table.
-sidelineDir <hdfs://> HDFS path to backup existing meta.
-boundaries Verify that regions boundaries are the same between META and store files.
-exclusive Abort if another hbck is exclusive or fixing.
Metadata 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.
-noHdfsChecking Don't load/check region info from HDFS. Assumes hbase:meta region info is good. Won't check/fix any HDFS issue, e.g. hole, orphan, or overlap
-fixHdfsHoles Try to fix region holes in hdfs.
-fixHdfsOrphans Try to fix region dirs with no .regioninfo file in hdfs
-fixTableOrphans Try to fix table dirs with no .tableinfo file in hdfs (online mode only)
-fixHdfsOverlaps Try to fix region overlaps in hdfs.( The same start key. 超过5个时,一定要加-maxMerge <n> 不然没用)
-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)
-fixSplitParents Try to force offline split parents to be online.
-removeParents Try to offline and sideline lingering parents and keep daughter regions.
-ignorePreCheckPermission ignore filesystem permission pre-check
-fixReferenceFiles Try to offline lingering reference store files
-fixEmptyMetaCells Try to fix hbase:meta entries not referencing any region (empty REGIONINFO_QUALIFIER rows)
Datafile Repair options: (expert features, use with caution!)
-checkCorruptHFiles Check all Hfiles by opening them to make sure they are valid
-sidelineCorruptHFiles Quarantine corrupted HFiles. implies -checkCorruptHFiles
Metadata Repair shortcuts
-repair Shortcut for -fixAssignments -fixMeta -fixHdfsHoles -fixHdfsOrphans -fixHdfsOverlaps -fixVersionFile -sidelineBigOverlaps -fixReferenceFiles -fixTableLocks -fixOrphanedTableZnodes
-repairHoles Shortcut for -fixAssignments -fixMeta -fixHdfsHoles
Table lock options
-fixTableLocks Deletes table locks held for a long time (hbase.table.lock.expire.ms, 10min by default)
Table Znode options
-fixOrphanedTableZnodes Set table state in ZNode to disabled if table does not exists
Replication options
-fixReplication Deletes replication queues for removed peers
一次修复步骤
sudo -u hbase hbase hbck -fixHdfsOverlaps <表名>
sudo -u hbase hbase hbck -details <表名> | grep ERROR | grep Region | wc -l
sudo -u hbase hbase hbck -fixHdfsOverlaps -maxMerge 6 <表名>
sudo -u hbase hbase hbck -repairHoles <表名>
sudo -u hbase hbase hbck -details <表名> | grep ERROR
sudo -u hbase hbase hbck -details 2>&1 | tee /tmp/hbase-hbck.txt
cat hbase-hbck.txt | grep 'ERROR'