HBASE-20532 Use try-with-resources in BackupSystemTable
Signed-off-by: tedyu <yuzhihong@gmail.com>
This commit is contained in:
parent
0d784efc37
commit
bc9f9ae080
|
@ -1174,25 +1174,16 @@ public final class BackupSystemTable implements Closeable {
|
||||||
LOG.trace("Backup set list");
|
LOG.trace("Backup set list");
|
||||||
|
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
Table table = null;
|
try (Table table = connection.getTable(tableName)) {
|
||||||
ResultScanner scanner = null;
|
|
||||||
try {
|
|
||||||
table = connection.getTable(tableName);
|
|
||||||
Scan scan = createScanForBackupSetList();
|
Scan scan = createScanForBackupSetList();
|
||||||
scan.setMaxVersions(1);
|
scan.setMaxVersions(1);
|
||||||
scanner = table.getScanner(scan);
|
try (ResultScanner scanner = table.getScanner(scan)) {
|
||||||
Result res;
|
Result res;
|
||||||
while ((res = scanner.next()) != null) {
|
while ((res = scanner.next()) != null) {
|
||||||
res.advance();
|
res.advance();
|
||||||
list.add(cellKeyToBackupSetName(res.current()));
|
list.add(cellKeyToBackupSetName(res.current()));
|
||||||
}
|
}
|
||||||
return list;
|
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()) {
|
if (LOG.isTraceEnabled()) {
|
||||||
LOG.trace(" Backup set describe: " + name);
|
LOG.trace(" Backup set describe: " + name);
|
||||||
}
|
}
|
||||||
Table table = null;
|
try (Table table = connection.getTable(tableName)) {
|
||||||
try {
|
|
||||||
table = connection.getTable(tableName);
|
|
||||||
Get get = createGetForBackupSet(name);
|
Get get = createGetForBackupSet(name);
|
||||||
Result res = table.get(get);
|
Result res = table.get(get);
|
||||||
|
|
||||||
if (res.isEmpty()) {
|
if (res.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.advance();
|
res.advance();
|
||||||
String[] tables = cellValueToBackupSet(res.current());
|
String[] tables = cellValueToBackupSet(res.current());
|
||||||
return Arrays.asList(tables).stream().map(item -> TableName.valueOf(item))
|
return Arrays.asList(tables).stream().map(item -> TableName.valueOf(item))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} finally {
|
|
||||||
if (table != null) {
|
|
||||||
table.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue