KYLIN-1564 Close table in BuildCubeWithEngine#checkHFilesInHBase()
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e6e29bb7 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e6e29bb7 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e6e29bb7 Branch: refs/heads/1.5.x-HBase1.1.3 Commit: e6e29bb7a1ae606f5d4e464d9c7014ab98d1a3c0 Parents: 633a1cc Author: lidongsjtu <lid...@apache.org> Authored: Thu Apr 7 10:10:26 2016 +0800 Committer: lidongsjtu <lid...@apache.org> Committed: Thu Apr 7 10:10:36 2016 +0800 ---------------------------------------------------------------------- .../kylin/provision/BuildCubeWithEngine.java | 47 ++++++++++---------- 1 file changed, 24 insertions(+), 23 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/e6e29bb7/kylin-it/src/test/java/org/apache/kylin/provision/BuildCubeWithEngine.java ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/java/org/apache/kylin/provision/BuildCubeWithEngine.java b/kylin-it/src/test/java/org/apache/kylin/provision/BuildCubeWithEngine.java index cfefef3..c945485 100644 --- a/kylin-it/src/test/java/org/apache/kylin/provision/BuildCubeWithEngine.java +++ b/kylin-it/src/test/java/org/apache/kylin/provision/BuildCubeWithEngine.java @@ -369,30 +369,31 @@ public class BuildCubeWithEngine { private void checkHFilesInHBase(CubeSegment segment) throws IOException { Configuration conf = HBaseConfiguration.create(HadoopUtil.getCurrentConfiguration()); String tableName = segment.getStorageLocationIdentifier(); - HTable table = new HTable(conf, tableName); - HBaseRegionSizeCalculator cal = new HBaseRegionSizeCalculator(table); - Map<byte[], Long> sizeMap = cal.getRegionSizeMap(); - long totalSize = 0; - for (Long size : sizeMap.values()) { - totalSize += size; - } - if (totalSize == 0) { - return; - } - Map<byte[], Pair<Integer, Integer>> countMap = cal.getRegionHFileCountMap(); - // check if there's region contains more than one hfile, which means the hfile config take effects - boolean hasMultiHFileRegions = false; - for (Pair<Integer, Integer> count : countMap.values()) { - // check if hfile count is greater than store count - if (count.getSecond() > count.getFirst()) { - hasMultiHFileRegions = true; - break; + try (HTable table = new HTable(conf, tableName)) { + HBaseRegionSizeCalculator cal = new HBaseRegionSizeCalculator(table); + Map<byte[], Long> sizeMap = cal.getRegionSizeMap(); + long totalSize = 0; + for (Long size : sizeMap.values()) { + totalSize += size; + } + if (totalSize == 0) { + return; + } + Map<byte[], Pair<Integer, Integer>> countMap = cal.getRegionHFileCountMap(); + // check if there's region contains more than one hfile, which means the hfile config take effects + boolean hasMultiHFileRegions = false; + for (Pair<Integer, Integer> count : countMap.values()) { + // check if hfile count is greater than store count + if (count.getSecond() > count.getFirst()) { + hasMultiHFileRegions = true; + break; + } + } + if (KylinConfig.getInstanceFromEnv().getHBaseHFileSizeGB() == 0 && hasMultiHFileRegions) { + throw new IOException("hfile size set to 0, but found region contains more than one hfiles"); + } else if (KylinConfig.getInstanceFromEnv().getHBaseHFileSizeGB() > 0 && !hasMultiHFileRegions) { + throw new IOException("hfile size set greater than 0, but all regions still has only one hfile"); } - } - if (KylinConfig.getInstanceFromEnv().getHBaseHFileSizeGB() == 0 && hasMultiHFileRegions) { - throw new IOException("hfile size set to 0, but found region contains more than one hfiles"); - } else if (KylinConfig.getInstanceFromEnv().getHBaseHFileSizeGB() > 0 && !hasMultiHFileRegions) { - throw new IOException("hfile size set greater than 0, but all regions still has only one hfile"); } }