Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 02-10-2018 08:14 AM
Hello,
i want to get details "Block-Locations" of a particular file say abc.csv(500mb)(Cluster: 1NM and 3DNs).
when i -put a file it is divided into blocks of default size 64MB and spread across Hadoop Cluster.
By using Web interface "http://namenode:50070" we can find out block location across cluster.
Also by using command : hadoop fsck <file-pat> -files -blocks -locations
But what i am trying to achieve is to get these information through JAVA API or WEB- API.
Please let me know the solution if any.
Any help will be appretiated.
Created 02-13-2018 07:23 PM
@Yog Prabhhu, you can get the file block information from WebHDFS REST API like
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<FilePath>?op=GETFILEBLOCKLOCATIONS
The corresponding JAVA API is FileSystem.getFileBlockLocations:
public BlockLocation[] getFileBlockLocations(FileStatus file,
long start, long len)
You will get an array of block locations like below:
[BlockLocation(offset: 0, length: BLOCK_SIZE,* hosts: {"host1:9866", "host2:9866, host3:9866"},...,]
Created 02-13-2018 07:23 PM
@Yog Prabhhu, you can get the file block information from WebHDFS REST API like
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<FilePath>?op=GETFILEBLOCKLOCATIONS
The corresponding JAVA API is FileSystem.getFileBlockLocations:
public BlockLocation[] getFileBlockLocations(FileStatus file,
long start, long len)
You will get an array of block locations like below:
[BlockLocation(offset: 0, length: BLOCK_SIZE,* hosts: {"host1:9866", "host2:9866, host3:9866"},...,]
Created on 08-07-2022 06:02 PM - edited 08-07-2022 06:03 PM
Hey, do you have an idea how I can actually locate and read a specific block using BlockLocation? I want to read the block byte by byte.(I understand it might be a remote read)
Created 08-08-2022 03:17 AM
@husseljo, as this is an older post, you would have a better chance of receiving a resolution by starting a new thread. This will also be an opportunity to provide details specific to your environment that could aid others in assisting you with a more accurate answer to your question. You can link this thread as a reference in your new post.
Regards,
Vidya Sargur,