You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gj...@apache.org on 2020/11/20 17:43:44 UTC
[phoenix] branch 4.x updated: PHOENIX-6228 : Close Admin resources
for certain workflows
This is an automated email from the ASF dual-hosted git repository.
gjacoby pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push:
new e57fcc8 PHOENIX-6228 : Close Admin resources for certain workflows
e57fcc8 is described below
commit e57fcc863e88c2e3535cdbc3b4e4f02a51461bad
Author: Viraj Jasani <vj...@apache.org>
AuthorDate: Thu Nov 19 12:48:09 2020 +0530
PHOENIX-6228 : Close Admin resources for certain workflows
---
.../apache/phoenix/mapreduce/OrphanViewTool.java | 11 ++++++----
.../mapreduce/index/IndexScrutinyMapper.java | 7 +++++--
.../phoenix/mapreduce/index/IndexUpgradeTool.java | 4 ++--
.../index/IndexVerificationOutputRepository.java | 24 ++++++++++++----------
.../index/IndexVerificationResultRepository.java | 23 ++++++++++++---------
.../phoenix/schema/SchemaExtractionProcessor.java | 7 +++++--
6 files changed, 45 insertions(+), 31 deletions(-)
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
index dbbb003..a916a60 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/OrphanViewTool.java
@@ -59,6 +59,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -758,10 +759,12 @@ public class OrphanViewTool extends Configured implements Tool {
private void createSnapshot(PhoenixConnection phoenixConnection, long scn)
throws Exception {
- phoenixConnection.getQueryServices().getAdmin().snapshot("OrphanViewTool." + Long.toString(scn),
- TableName.valueOf(SYSTEM_CATALOG_NAME));
- phoenixConnection.getQueryServices().getAdmin().snapshot("OrphanViewTool." + Long.toString(scn+1),
- TableName.valueOf(SYSTEM_CHILD_LINK_NAME));
+ try (Admin admin = phoenixConnection.getQueryServices().getAdmin()) {
+ admin.snapshot("OrphanViewTool." + scn, TableName
+ .valueOf(SYSTEM_CATALOG_NAME));
+ admin.snapshot("OrphanViewTool." + (scn + 1), TableName
+ .valueOf(SYSTEM_CHILD_LINK_NAME));
+ }
}
private void readOrphanViews() throws Exception {
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java
index bf3c765..af38aa4 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexScrutinyMapper.java
@@ -331,10 +331,13 @@ public class IndexScrutinyMapper extends Mapper<NullWritable, PhoenixIndexDBWrit
}
ConnectionQueryServices
cqsi = connection.unwrap(PhoenixConnection.class).getQueryServices();
- Admin admin = cqsi.getAdmin();
String physicalTable = getSourceTableName(pSourceTable,
SchemaUtil.isNamespaceMappingEnabled(null, cqsi.getProps()));
- HTableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(physicalTable));
+ HTableDescriptor tableDesc;
+ try (Admin admin = cqsi.getAdmin()) {
+ tableDesc = admin.getTableDescriptor(TableName
+ .valueOf(physicalTable));
+ }
return tableDesc.getFamily(SchemaUtil.getEmptyColumnFamily(pSourceTable)).getTimeToLive();
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
index 74ccd91..1621e12 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java
@@ -498,8 +498,8 @@ public class IndexUpgradeTool extends Configured implements Tool {
LOGGER.severe("Revert of the "+operation +" failed in error handling, "
+ "re-enabling tables and then throwing runtime exception");
LOGGER.severe("Confirm the state for "+getSubListString(tableList, dataTableFullName));
- try {
- enableTable(queryServices.getAdmin(), dataTableFullName, indexes);
+ try (Admin admin = queryServices.getAdmin()) {
+ enableTable(admin, dataTableFullName, indexes);
} catch (Exception ex) {
throw new RuntimeException("Error re-enabling tables after rollback failure. " +
"Original exception that caused the rollback: [" + e.toString() + " " + "]", ex);
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
index 549f876..c7a2753 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationOutputRepository.java
@@ -171,20 +171,22 @@ public class IndexVerificationOutputRepository implements AutoCloseable {
public void createOutputTable(Connection connection) throws IOException, SQLException {
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
- Admin admin = queryServices.getAdmin();
- TableName outputTableName = TableName.valueOf(OUTPUT_TABLE_NAME);
- if (!admin.tableExists(outputTableName)) {
- HTableDescriptor tableDescriptor = new
- HTableDescriptor(TableName.valueOf(OUTPUT_TABLE_NAME));
- HColumnDescriptor columnDescriptor = new HColumnDescriptor(OUTPUT_TABLE_COLUMN_FAMILY);
- columnDescriptor.setValue(HColumnDescriptor.TTL,
+ try (Admin admin = queryServices.getAdmin()) {
+ TableName outputTableName = TableName.valueOf(OUTPUT_TABLE_NAME);
+ if (!admin.tableExists(outputTableName)) {
+ HTableDescriptor tableDescriptor = new
+ HTableDescriptor(TableName.valueOf(OUTPUT_TABLE_NAME));
+ HColumnDescriptor columnDescriptor =
+ new HColumnDescriptor(OUTPUT_TABLE_COLUMN_FAMILY);
+ columnDescriptor.setValue(HColumnDescriptor.TTL,
String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
- tableDescriptor.addFamily(columnDescriptor);
- admin.createTable(tableDescriptor);
- outputTable = admin.getConnection().getTable(outputTableName);
+ tableDescriptor.addFamily(columnDescriptor);
+ admin.createTable(tableDescriptor);
+ outputTable = admin.getConnection().getTable(outputTableName);
+ }
}
}
-
+
@VisibleForTesting
public void logToIndexToolOutputTable(byte[] dataRowKey, byte[] indexRowKey, long dataRowTs,
long indexRowTs,
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java
index bf9b4bf..388c793 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexVerificationResultRepository.java
@@ -142,19 +142,22 @@ public class IndexVerificationResultRepository implements AutoCloseable {
public void createResultTable(Connection connection) throws IOException, SQLException {
ConnectionQueryServices queryServices = connection.unwrap(PhoenixConnection.class).getQueryServices();
- Admin admin = queryServices.getAdmin();
- TableName resultTableName = TableName.valueOf(RESULT_TABLE_NAME);
- if (!admin.tableExists(resultTableName)) {
- HTableDescriptor tableDescriptor = new
- HTableDescriptor(TableName.valueOf(RESULT_TABLE_NAME));
- HColumnDescriptor columnDescriptor = new HColumnDescriptor(RESULT_TABLE_COLUMN_FAMILY);
- columnDescriptor.setValue(HColumnDescriptor.TTL,
+ try (Admin admin = queryServices.getAdmin()) {
+ TableName resultTableName = TableName.valueOf(RESULT_TABLE_NAME);
+ if (!admin.tableExists(resultTableName)) {
+ HTableDescriptor tableDescriptor =
+ new HTableDescriptor(TableName.valueOf(RESULT_TABLE_NAME));
+ HColumnDescriptor columnDescriptor =
+ new HColumnDescriptor(RESULT_TABLE_COLUMN_FAMILY);
+ columnDescriptor.setValue(HColumnDescriptor.TTL,
String.valueOf(MetaDataProtocol.DEFAULT_LOG_TTL));
- tableDescriptor.addFamily(columnDescriptor);
- admin.createTable(tableDescriptor);
- setResultTable(admin.getConnection().getTable(resultTableName));
+ tableDescriptor.addFamily(columnDescriptor);
+ admin.createTable(tableDescriptor);
+ setResultTable(admin.getConnection().getTable(resultTableName));
+ }
}
}
+
private static byte[] generatePartialResultTableRowKey(long ts, byte[] indexTableName) {
byte[] keyPrefix = Bytes.toBytes(Long.toString(ts));
int targetOffset = 0;
diff --git a/phoenix-tools/src/main/java/org/apache/phoenix/schema/SchemaExtractionProcessor.java b/phoenix-tools/src/main/java/org/apache/phoenix/schema/SchemaExtractionProcessor.java
index 27fda90..93632cb 100644
--- a/phoenix-tools/src/main/java/org/apache/phoenix/schema/SchemaExtractionProcessor.java
+++ b/phoenix-tools/src/main/java/org/apache/phoenix/schema/SchemaExtractionProcessor.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -308,8 +309,10 @@ public class SchemaExtractionProcessor {
private HTableDescriptor getTableDescriptor(ConnectionQueryServices cqsi, PTable table)
throws SQLException, IOException {
- return cqsi.getAdmin().getTableDescriptor(
- TableName.valueOf(table.getPhysicalName().getString()));
+ try (Admin admin = cqsi.getAdmin()) {
+ return admin.getTableDescriptor(TableName.valueOf(
+ table.getPhysicalName().getString()));
+ }
}
private String convertPropertiesToString() {