phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject [2/5] git commit: PHOENIX-1323 Use utility method to get HTableInterface for scans from coprocessor
Date Mon, 06 Oct 2014 01:35:20 GMT
PHOENIX-1323 Use utility method to get HTableInterface for scans from coprocessor


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/8840af66
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8840af66
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8840af66

Branch: refs/heads/4.0
Commit: 8840af6607935054982fc6a6b0b8aad2081a716c
Parents: 8c054b2
Author: James Taylor <jtaylor@salesforce.com>
Authored: Sat Oct 4 18:12:18 2014 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Sat Oct 4 18:12:18 2014 -0700

----------------------------------------------------------------------
 .../coprocessor/MetaDataEndpointImpl.java       | 33 +++++++-------------
 .../org/apache/phoenix/util/ServerUtil.java     | 23 +++++++++++++-
 2 files changed, 34 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8840af66/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index aa77882..6a4f69b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -73,9 +73,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.KeyValue.Type;
 import org.apache.hadoop.hbase.client.Delete;
 import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.HTableInterface;
-import org.apache.hadoop.hbase.client.HTablePool;
 import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
@@ -692,13 +690,10 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements
Coprocesso
             multiTenant, viewType, viewIndexId, indexType, stats);
     }
 
-    private PTableStats updateStatsInternal(byte[] tableNameBytes)
-            throws IOException {
-        HTable statsHTable = null;
+    private PTableStats updateStatsInternal(byte[] tableNameBytes) throws IOException {
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        HTableInterface statsHTable = ServerUtil.getHTableForCoprocessorScan(env, PhoenixDatabaseMetaData.SYSTEM_STATS_NAME);
         try {
-            // Can we do a new HTable instance here? Or get it from a pool or cache of these
instances?
-            statsHTable = new HTable(this.env.getConfiguration(), PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES);
             Scan s = newTableRowsScan(tableNameBytes);
             s.addColumn(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, PhoenixDatabaseMetaData.GUIDE_POSTS_BYTES);
             ResultScanner scanner = statsHTable.getScanner(s);
@@ -745,9 +740,7 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements
Coprocesso
                 throw new IOException(e);
             }
         } finally {
-            if (statsHTable != null) {
-                statsHTable.close();
-            }
+            statsHTable.close();
         }
         return PTableStatsImpl.NO_STATS;
     }
@@ -970,13 +963,12 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements
Coprocesso
         // TableName systemCatalogTableName = region.getTableDesc().getTableName();
         // HTableInterface hTable = env.getTable(systemCatalogTableName);
         // These deprecated calls work around the issue
-        HTablePool pool = new HTablePool (env.getConfiguration(),1);
+        HTableInterface hTable = ServerUtil.getHTableForCoprocessorScan(env, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
         try {
-            HTableInterface hTable = pool.getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME);
-            ResultScanner scanner = hTable.getScanner(scan);
             boolean allViewsInCurrentRegion = true;
             int numOfChildViews = 0;
             List<Result> results = Lists.newArrayList();
+            ResultScanner scanner = hTable.getScanner(scan);
             try {
                 for (Result result = scanner.next(); (result != null); result = scanner.next())
{
                     numOfChildViews++;
@@ -989,17 +981,16 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements
Coprocesso
                     }
                     results.add(result);
                 }
+                TableViewFinderResult tableViewFinderResult = new TableViewFinderResult(results);
+                if (numOfChildViews > 0 && !allViewsInCurrentRegion) {
+                    tableViewFinderResult.setAllViewsNotInSingleRegion();
+                }
+                return tableViewFinderResult;
             } finally {
-                scanner.close();
-                hTable.close();
-            }
-            TableViewFinderResult tableViewFinderResult = new TableViewFinderResult(results);
-            if (numOfChildViews > 0 && !allViewsInCurrentRegion) {
-                tableViewFinderResult.setAllViewsNotInSingleRegion();
+                    scanner.close();
             }
-            return tableViewFinderResult;
         } finally {
-            pool.close();
+            hTable.close();
         }
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8840af66/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
index 90e1b07..3327dba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
@@ -25,13 +25,19 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.hadoop.hbase.DoNotRetryIOException;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.HTablePool;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.phoenix.exception.PhoenixIOException;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.exception.SQLExceptionInfo;
+import org.apache.phoenix.hbase.index.util.VersionUtil;
 
 
 public class ServerUtil {
-
+    private static final int COPROCESSOR_SCAN_WORKS = VersionUtil.encodeVersion("0.98.6");
+    
     private static final String FORMAT = "ERROR %d (%s): %s";
     private static final Pattern PATTERN = Pattern.compile("ERROR (\\d+) \\((\\w+)\\): (.*)");
     private static final Map<Class<? extends Exception>, SQLExceptionCode> errorcodeMap
@@ -127,4 +133,19 @@ public class ServerUtil {
         return null;
     }
 
+    @SuppressWarnings("deprecation")
+    public static HTableInterface getHTableForCoprocessorScan (RegionCoprocessorEnvironment
env, String tableName) throws IOException {
+        String versionString = env.getHBaseVersion();
+        int version = VersionUtil.encodeVersion(versionString);
+        if (version >= COPROCESSOR_SCAN_WORKS) {
+            // The following *should* work, but doesn't due to HBASE-11837 which was fixed
in 0.98.6
+            return env.getTable(TableName.valueOf(tableName));
+        }
+        // This code works around HBASE-11837
+        // It's ok to not ever do a pool.close() as we're storing a single
+        // table only. The HTablePool holds no other resources that this table
+        // which will be closed itself when it's no longer needed.
+        HTablePool pool = new HTablePool(env.getConfiguration(),1);
+        return pool.getTable(tableName);
+    }
 }


Mime
View raw message