Repository: hbase Updated Branches: refs/heads/master 0d784efc3 -> bc9f9ae08
HBASE-20532 Use try-with-resources in BackupSystemTable Signed-off-by: tedyu <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/bc9f9ae0 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/bc9f9ae0 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/bc9f9ae0 Branch: refs/heads/master Commit: bc9f9ae080c1d6e8f6ed400883cc2d756bbc3fa2 Parents: 0d784ef Author: Yang Ming <[email protected]> Authored: Thu Jun 21 20:16:43 2018 +0800 Committer: tedyu <[email protected]> Committed: Thu Jun 21 09:10:01 2018 -0700 ---------------------------------------------------------------------- .../hbase/backup/impl/BackupSystemTable.java | 35 +++++--------------- 1 file changed, 9 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/bc9f9ae0/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java ---------------------------------------------------------------------- diff --git a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java index 5e174eb..1b36944 100644 --- a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java +++ b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java @@ -1174,25 +1174,16 @@ public final class BackupSystemTable implements Closeable { LOG.trace("Backup set list"); List<String> list = new ArrayList<>(); - Table table = null; - ResultScanner scanner = null; - try { - table = connection.getTable(tableName); + try (Table table = connection.getTable(tableName)) { Scan scan = createScanForBackupSetList(); scan.setMaxVersions(1); - scanner = table.getScanner(scan); - Result res; - while ((res = scanner.next()) != null) { - res.advance(); - list.add(cellKeyToBackupSetName(res.current())); - } - return list; - } finally { - if (scanner != null) { - scanner.close(); - } - if (table != null) { - table.close(); + try (ResultScanner scanner = table.getScanner(scan)) { + Result res; + while ((res = scanner.next()) != null) { + res.advance(); + list.add(cellKeyToBackupSetName(res.current())); + } + return list; } } } @@ -1207,24 +1198,16 @@ public final class BackupSystemTable implements Closeable { if (LOG.isTraceEnabled()) { LOG.trace(" Backup set describe: " + name); } - Table table = null; - try { - table = connection.getTable(tableName); + try (Table table = connection.getTable(tableName)) { Get get = createGetForBackupSet(name); Result res = table.get(get); - if (res.isEmpty()) { return null; } - res.advance(); String[] tables = cellValueToBackupSet(res.current()); return Arrays.asList(tables).stream().map(item -> TableName.valueOf(item)) .collect(Collectors.toList()); - } finally { - if (table != null) { - table.close(); - } } }
