HBASE-20532 Use try-with-resources in BackupSystemTable

Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
Yang Ming 2018-06-21 20:16:43 +08:00 committed by tedyu
parent 0d784efc37
commit bc9f9ae080
1 changed files with 9 additions and 26 deletions

View File

@ -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);
try (ResultScanner 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();
}
}
}
@ -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();
}
}
}