You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/10/06 17:56:57 UTC

[3/7] git commit: PHOENIX-1323 Use utility method to get HTableInterface for scans from coprocessor

PHOENIX-1323 Use utility method to get HTableInterface for scans from coprocessor

Conflicts:
	phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java


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

Branch: refs/heads/3.0
Commit: 29361c6b0c0ad06eafd49599c0f7c9a71dff3573
Parents: 66a8808
Author: James Taylor <jt...@salesforce.com>
Authored: Sat Oct 4 18:12:18 2014 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Mon Oct 6 01:24:37 2014 -0700

----------------------------------------------------------------------
 .../coprocessor/MetaDataEndpointImpl.java       | 52 ++++++++++----------
 .../org/apache/phoenix/util/ServerUtil.java     |  2 -
 2 files changed, 25 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/29361c6b/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 cc1117c..7d6317f 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
@@ -467,11 +467,9 @@ public class MetaDataEndpointImpl extends BaseEndpointCoprocessor implements Met
     }
     
     private PTableStats updateStatsInternal(byte[] tableNameBytes) throws IOException {
-        HTableInterface statsHTable = null;
         ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+        HTableInterface statsHTable = getEnvironment().getTable(PhoenixDatabaseMetaData.SYSTEM_STATS_NAME_BYTES);
         try {
-            // Can we do a new HTable instance here? Or get it from a pool or cache of these instances?
-            statsHTable = getEnvironment().getTable(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);
@@ -519,9 +517,7 @@ public class MetaDataEndpointImpl extends BaseEndpointCoprocessor implements Met
                 throw new IOException(e);
             }
         } finally {
-            if (statsHTable != null) {
-                statsHTable.close();
-            }
+            statsHTable.close();
         }
         return PTableStatsImpl.NO_STATS;
     }
@@ -700,33 +696,35 @@ public class MetaDataEndpointImpl extends BaseEndpointCoprocessor implements Met
         scan.setFilter(filter);
         scan.addColumn(TABLE_FAMILY_BYTES, LINK_TYPE_BYTES);
         HTableInterface hTable = getEnvironment().getTable(PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME_BYTES);
-        ResultScanner scanner = hTable.getScanner(scan);
-
-        boolean allViewsInCurrentRegion = true;
-        int numOfChildViews = 0;
-        List<Result> results = Lists.newArrayList();
         try {
-            for (Result result = scanner.next(); (result != null); result = scanner.next()) {
-                numOfChildViews++;
-                ImmutableBytesWritable ptr = new ImmutableBytesWritable();
-                ResultTuple resultTuple = new ResultTuple(result);
-                resultTuple.getKey(ptr);
-                byte[] key = ptr.copyBytes();
-                if (checkTableKeyInRegion(key, region) != null) {
-                    allViewsInCurrentRegion = false;
+            ResultScanner scanner = hTable.getScanner(scan);
+    
+            boolean allViewsInCurrentRegion = true;
+            int numOfChildViews = 0;
+            List<Result> results = Lists.newArrayList();
+            try {
+                for (Result result = scanner.next(); (result != null); result = scanner.next()) {
+                    numOfChildViews++;
+                    ImmutableBytesWritable ptr = new ImmutableBytesWritable();
+                    ResultTuple resultTuple = new ResultTuple(result);
+                    resultTuple.getKey(ptr);
+                    byte[] key = ptr.copyBytes();
+                    if (checkTableKeyInRegion(key, region) != null) {
+                        allViewsInCurrentRegion = false;
+                    }
+                    results.add(result);
+                }
+                TableViewFinderResult tableViewFinderResult = new TableViewFinderResult(results);
+                if (numOfChildViews > 0 && !allViewsInCurrentRegion) {
+                    tableViewFinderResult.setAllViewsNotInSingleRegion();
                 }
-                results.add(result);
+                return tableViewFinderResult;
+            } finally {
+                scanner.close();
             }
         } finally {
-            scanner.close();
             hTable.close();
         }
-        TableViewFinderResult tableViewFinderResult = new TableViewFinderResult(results);
-        if (numOfChildViews > 0 && !allViewsInCurrentRegion) {
-            tableViewFinderResult.setAllViewsNotInSingleRegion();
-        }
-        return tableViewFinderResult;
-
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/29361c6b/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 45a6f14..8dcf8c5 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
@@ -31,7 +31,6 @@ import org.apache.phoenix.exception.SQLExceptionInfo;
 
 
 public class ServerUtil {
-
     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
@@ -122,5 +121,4 @@ public class ServerUtil {
         	}
         return null;
     }
-
 }