hbase java 获取表大小,HBase:我如何估算HBase表的大小?

I have multiple HBase tables, how can I estimate the approximate size of the tables using in java?

解决方案

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;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值