[英]HBase: How can I estimate the size of a HBase table?
我有多个HBase表,如何估计在Java中使用的表的大致大小?
一种方法是通常必须在/hbase
文件夹下的所有表信息下使用Java客户端访问hdfs。 将存在。
您可以使用hadoop fs -du -h **path to hbase**/hbase
在/ hbase下,每个表又占用一个文件夹...
hadoop fs -ls -R **path to hbase**/hbase
hadoop fs -du -h **path to hbase**/hbase/tablename
同样,您可以通过在hbase根目录下传递每个表路径来使用Java hdfs客户端,如下所示:检查getSizeOfPaths
和getSizeOfDirectory
方法
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.