I have multiple HBase tables, how can I estimate the approximate size of the tables using in java?
Asked
Active
Viewed 1,374 times
2
-
here you can use https://commons.apache.org/proper/commons-io/javadocs/api-2.5/org/apache/commons/io/FileUtils.html for printing size of hdfs (hbase ) folder size in human readable format. please check last method in the `HDFSUtil` given in my answer – Ram Ghadiyaram Nov 21 '16 at 18:30
1 Answers
3
One way is you have to access hdfs using java client usually under /hbase
folder
all the tables info. will be present.
Hadoop shell :
you can check that using hadoop fs -du -h **path to hbase**/hbase
under /hbase each table occupies one more folder...
hadoop fs -ls -R **path to hbase**/hbase
hadoop fs -du -h **path to hbase**/hbase/tablename
Java HDFS Client :
Same thing you can use java hdfs client by passing each table path under hbase root dir like below ...
Check getSizeOfPaths
& getSizeOfDirectory
methods
public class HdfsUtil {
/**
* Estimates the number of splits by taking the size of the paths and dividing by the splitSize.
*
* @param paths
* @param configuration
* @param splitSize
* @return
* @throws IOException
*/
public static long getNumOfSplitsForInputs(Path[] paths, Configuration configuration, long splitSize) throws IOException
{
long size = getSizeOfPaths(paths, configuration);
long splits = (int) Math.ceil( size / (splitSize)) ;
return splits;
}
public static long getSizeOfPaths(Path[] paths, Configuration configuration) throws IOException
{
long totalSize = 0L;
for(Path path: paths)
{
totalSize += getSizeOfDirectory(path, configuration);
}
return totalSize;
}
// here you can give hbase path folder which was described through shell
public static long getSizeOfDirectory(Path path, Configuration configuration) throws IOException {
//Get the file size of the unannotated Edges
FileSystem fileSystem = FileSystem.get(configuration);
long size = fileSystem.getContentSummary(path).getLength();
/**static String byteCountToDisplaySize(BigInteger size)
Returns a human-readable version of the file size, where the input represents a specific number of bytes.**/
System.out.println(FileUtils.byteCountToDisplaySize(size))
return size;
}
}

Community
- 1
- 1

Ram Ghadiyaram
- 28,239
- 13
- 95
- 121