How do you retrieve the replication factor info in Hdfs files?

我怕爱的太早我们不能终老 提交于 2019-12-10 03:34:33

问题


I have set the replication factor for my file as follows:

hadoop fs -D dfs.replication=5 -copyFromLocal file.txt /user/xxxx

When a NameNode restarts, it makes sure under-replicated blocks are replicated. Hence the replication info for the file is stored (possibly in nameNode). How can I get that information?


回答1:


Try to use command hadoop fs -stat %r /path/to/file, it should print the replication factor.




回答2:


You can run following command to get replication factor,

hadoop fs -ls /user/xxxx

The second column in the output signify replication factor for the file and for the folder it shows -, as shown in below pic.




回答3:


Apart from Alexey Shestakov's answer, which works perfectly and does exactly what you ask, other ways, mostly found here, include:

hadoop dfs -ls /parent/path 

which shows the replication factors of all the /parent/path contents on the second column.

Through Java, you can get this information by using:

FileStatus.getReplication()

You can also see the replication factors of files by using:

hadoop fsck /filename -files -blocks -racks

Finally, from the web UI of the namenode, I believe that this information is also available (didn't check that).




回答4:


We can use following commands to check replication of the file.

hdfs dfs -ls  /user/cloudera/input.txt

or

hdfs dfs -stat %r /user/cloudera/input.txt


来源:https://stackoverflow.com/questions/25166926/how-do-you-retrieve-the-replication-factor-info-in-hdfs-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!