在HDFS中,提供了fsck命令,用于检查HDFS上文件和目录的健康状态、获取文件的block信息和位置信息等。
fsck命令必须由HDFS超级用户来执行,普通用户无权限。
hdfs fsck /data/test/cdh9 -list-corruptfileblocks
hdfs fsck /data/test/cdh9 -move
hdfs fsck /data/test/cdh9 -delete
hdfs fsck /data/test/cdh9 -openforwrite
例:hdfs fsck /data/test/cdh9 -files -blocks -locations
Connecting to namenode via http://xxxx:50070/fsck?ugi=hdfs&files=1&blocks=1&locations=1&path=%2Fdata%2Ftest%2Fcdh9
FSCK started by hdfs (auth:SIMPLE) from /xxxx for path /data/test/cdh9 at Mon Jul 04 09:36:44 CST 2022
/data/test/cdh9 3700657201 bytes, 28 block(s): OK
0. BP-1582775312-10.193.81.148-1656473793148:blk_1073745470_4646 len=134217728 Live_repl=3 [DatanodeInfoWithStorage[10.193.224.30:50010,DS-0ca68924-ede5-4a24-83be-c2e7488fa568,DISK], DatanodeInfoWithStorage[10.193.224.27:50010,DS-d455ccc0-ca31-491b-a86e-cb177a603a7a,DISK], DatanodeInfoWithStorage[10.193.82.172:50010,DS-c4a619ec-6443-47c1-9139-c5374038b98f,DISK]]
1. BP-1582775312-10.193.81.148-1656473793148:blk_1073745471_4647 len=134217728 Live_repl=3 [DatanodeInfoWithStorage[10.193.224.30:50010,DS-27fc81c4-e599-4d40-b9a6-efb568273046,DISK], DatanodeInfoWithStorage[10.193.82.172:50010,DS-d6e167dd-483d-437c-a8e1-1b75af772c24,DISK], DatanodeInfoWithStorage[10.193.81.148:50010,DS-33f4cf6c-2a46-4180-bdae-ac0888375737,DISK]]
参数含义:
String bpid = "" + rand + "-"+ ip + "-" + Time.now(); Where: rand = Some random number ip = IP address of the Name Node Time.now() - Current system time在此处阅读有关块池的信息:Apache Hadoop 3.3.3 – HDFS Federation
blk_<blockid>_<genstamp> Where: blockid = ID of the block genstamp = an incrementing integer that records the version of a particular block在这里阅读关于代邮票:Cloudera Blog
10.193.224.30 => IP address of the Data Node holding this block 50010 => Data streaming port DS-0ca68924-ede5-4a24-83be-c2e7488fa568 => Storage ID. It is an internal ID of the Data Node. It is assigned, when the Data Node registers with Name Node DISK => storageType. It is DISK here. Storage type can be: RAM_DISK, SSD, DISK and ARCHIVE
第5点的描述适用于剩余的2个区块:
DatanodeInfoWithStorage[10.193.224.27:50010,DS-d455ccc0-ca31-491b-a86e-cb177a603a7a,DISK], DatanodeInfoWithStorage[10.193.82.172:50010,DS-c4a619ec-6443-47c1-9139-c5374038b98f,DISK]]
参考:hdfs fsck命令查看HDFS文件对应的文件块信息(Block)和位置信息(Locations) - 走看看