You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ch...@apache.org on 2020/02/07 18:50:03 UTC
[phoenix] branch 4.15-HBase-1.3 updated: PHOENIX-5697 : Use
try-with-resources to avoid leakage
This is an automated email from the ASF dual-hosted git repository.
chinmayskulkarni pushed a commit to branch 4.15-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.15-HBase-1.3 by this push:
new 1e58d15 PHOENIX-5697 : Use try-with-resources to avoid leakage
1e58d15 is described below
commit 1e58d15be3dd81055117a3f717e053916fdc0c76
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Fri Jan 24 11:12:28 2020 -0800
PHOENIX-5697 : Use try-with-resources to avoid leakage
Signed-off-by: Chinmay Kulkarni <ch...@apache.org>
---
.../write/AbstractParallelWriterIndexCommitter.java | 13 ++++---------
.../write/TrackingParallelWriterIndexCommitter.java | 12 ++++--------
.../java/org/apache/phoenix/util/MetaDataUtil.java | 18 ++++--------------
3 files changed, 12 insertions(+), 31 deletions(-)
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/AbstractParallelWriterIndexCommitter.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/AbstractParallelWriterIndexCommitter.java
index 9e94e87..2fd70de 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/AbstractParallelWriterIndexCommitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/AbstractParallelWriterIndexCommitter.java
@@ -143,7 +143,6 @@ public abstract class AbstractParallelWriterIndexCommitter implements IndexCommi
@SuppressWarnings("deprecation")
@Override
public Void call() throws Exception {
- Table table = null;
// this may have been queued, so another task infront of us may have failed, so we should
// early exit, if that's the case
throwFailureIfDone();
@@ -176,9 +175,10 @@ public abstract class AbstractParallelWriterIndexCommitter implements IndexCommi
else {
factory = retryingFactory;
}
- table = factory.getTable(tableReference.get());
- throwFailureIfDone();
- table.batch(mutations, null);
+ try (Table table = factory.getTable(tableReference.get())) {
+ throwFailureIfDone();
+ table.batch(mutations, null);
+ }
} catch (SingleIndexWriteFailureException e) {
throw e;
} catch (IOException e) {
@@ -188,11 +188,6 @@ public abstract class AbstractParallelWriterIndexCommitter implements IndexCommi
Thread.currentThread().interrupt();
throw new SingleIndexWriteFailureException(tableReference.toString(), mutations, e, PhoenixIndexFailurePolicy.getDisableIndexOnFailure(env));
}
- finally{
- if (table != null) {
- table.close();
- }
- }
return null;
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java
index 76ec32a..7f85aee 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/write/TrackingParallelWriterIndexCommitter.java
@@ -160,7 +160,6 @@ public class TrackingParallelWriterIndexCommitter implements IndexCommitter {
@SuppressWarnings("deprecation")
@Override
public Boolean call() throws Exception {
- HTableInterface table = null;
try {
// this may have been queued, but there was an abort/stop so we try to early exit
throwFailureIfDone();
@@ -193,19 +192,16 @@ public class TrackingParallelWriterIndexCommitter implements IndexCommitter {
else {
factory = retryingFactory;
}
- table = factory.getTable(tableReference.get());
- throwFailureIfDone();
- table.batch(mutations);
+ try (HTableInterface table = factory.getTable(tableReference.get())) {
+ throwFailureIfDone();
+ table.batch(mutations);
+ }
} catch (InterruptedException e) {
// reset the interrupt status on the thread
Thread.currentThread().interrupt();
throw e;
} catch (Exception e) {
throw e;
- } finally {
- if (table != null) {
- table.close();
- }
}
return Boolean.TRUE;
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
index 6de553c..ae0d2ca 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/MetaDataUtil.java
@@ -759,12 +759,10 @@ public class MetaDataUtil {
* @throws
*/
public static boolean tableRegionsOnline(Configuration conf, PTable table) {
- HConnection hcon = null;
-
- try {
- hcon = HConnectionManager.getConnection(conf);
+ try (HConnection hcon =
+ HConnectionManager.getConnection(conf)) {
List<HRegionLocation> locations = hcon.locateRegions(
- org.apache.hadoop.hbase.TableName.valueOf(table.getPhysicalName().getBytes()));
+ org.apache.hadoop.hbase.TableName.valueOf(table.getPhysicalName().getBytes()));
for (HRegionLocation loc : locations) {
try {
@@ -786,17 +784,9 @@ public class MetaDataUtil {
}
}
} catch (IOException ex) {
- LOGGER.warn("tableRegionsOnline failed due to:" + ex);
+ LOGGER.warn("tableRegionsOnline failed due to:", ex);
return false;
- } finally {
- if (hcon != null) {
- try {
- hcon.close();
- } catch (IOException ignored) {
- }
- }
}
-
return true;
}