phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vincentp...@apache.org
Subject [1/2] phoenix git commit: PHOENIX-4130 Avoid server retries for mutable indexes
Date Fri, 20 Apr 2018 18:38:13 GMT
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 83825dec5 -> 629bc29bc


http://git-wip-us.apache.org/repos/asf/phoenix/blob/629bc29b/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 23604f2..591c145 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
@@ -121,6 +121,25 @@ public class ServerUtil {
         }
         return new PhoenixIOException(t);
     }
+
+    /**
+     * Return the first SQLException in the exception chain, otherwise parse it.
+     * When we're receiving an exception locally, there's no need to string parse,
+     * as the SQLException will already be part of the chain.
+     * @param t
+     * @return the SQLException, or null if none found
+     */
+    public static SQLException parseLocalOrRemoteServerException(Throwable t) {
+        while (t.getCause() != null) {
+            if (t instanceof NotServingRegionException) {
+                return parseRemoteException(new StaleRegionBoundaryCacheException());
+            } else if (t instanceof SQLException) {
+                return (SQLException) t;
+            }
+            t = t.getCause();
+        }
+        return parseRemoteException(t);
+    }
     
     public static SQLException parseServerExceptionOrNull(Throwable t) {
         while (t.getCause() != null) {
@@ -197,7 +216,7 @@ public class ServerUtil {
         return parseTimestampFromRemoteException(t);
     }
 
-    private static long parseTimestampFromRemoteException(Throwable t) {
+    public static long parseTimestampFromRemoteException(Throwable t) {
         String message = t.getLocalizedMessage();
         if (message != null) {
             // If the message matches the standard pattern, recover the SQLException and
throw it.
@@ -217,7 +236,7 @@ public class ServerUtil {
             msg = "";
         }
         if (t instanceof SQLException) {
-            msg = constructSQLErrorMessage((SQLException) t, msg);
+            msg = t.getMessage() + " " + msg;
         }
         msg += String.format(FORMAT_FOR_TIMESTAMP, timestamp);
         return new DoNotRetryIOException(msg, t);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/629bc29b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestIndexWriter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestIndexWriter.java
b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestIndexWriter.java
index 642b83e..5c32998 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestIndexWriter.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestIndexWriter.java
@@ -37,10 +37,12 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Abortable;
 import org.apache.hadoop.hbase.Stoppable;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Row;
 import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
 import org.apache.hadoop.hbase.regionserver.Region;
@@ -98,6 +100,14 @@ public class TestIndexWriter {
     Configuration conf =new Configuration();
     Mockito.when(e.getConfiguration()).thenReturn(conf);
     Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
+    Region mockRegion = Mockito.mock(Region.class);
+    Mockito.when(e.getRegion()).thenReturn(mockRegion);
+    TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
+    Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
+    TableName mockTN = TableName.valueOf("test");
+    Mockito.when(mockTableDesc.getTableName()).thenReturn(mockTN);
+    Connection mockConnection = Mockito.mock(Connection.class);
+    Mockito.when(e.getConnection()).thenReturn(mockConnection);
     ExecutorService exec = Executors.newFixedThreadPool(1);
     Map<ImmutableBytesPtr, Table> tables = new HashMap<ImmutableBytesPtr, Table>();
     FakeTableFactory factory = new FakeTableFactory(tables);
@@ -152,6 +162,13 @@ public class TestIndexWriter {
     Configuration conf =new Configuration();
     Mockito.when(e.getConfiguration()).thenReturn(conf);
     Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
+    Region mockRegion = Mockito.mock(Region.class);
+    Mockito.when(e.getRegion()).thenReturn(mockRegion);
+    TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
+    Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
+    Mockito.when(mockTableDesc.getTableName()).thenReturn(TableName.valueOf("test"));
+    Connection mockConnection = Mockito.mock(Connection.class);
+    Mockito.when(e.getConnection()).thenReturn(mockConnection);
     FakeTableFactory factory = new FakeTableFactory(tables);
 
     byte[] tableName = this.testName.getTableName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/629bc29b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleIndexWriter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleIndexWriter.java
b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleIndexWriter.java
index cc185ce..121b781 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleIndexWriter.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleIndexWriter.java
@@ -31,10 +31,14 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Abortable;
 import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.VersionInfo;
 import org.apache.phoenix.hbase.index.IndexTableName;
@@ -92,6 +96,13 @@ public class TestParalleIndexWriter {
     Configuration conf =new Configuration();
     Mockito.when(e.getConfiguration()).thenReturn(conf);
     Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
+    Region mockRegion = Mockito.mock(Region.class);
+    Mockito.when(e.getRegion()).thenReturn(mockRegion);
+    TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
+    Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
+    Mockito.when(mockTableDesc.getTableName()).thenReturn(TableName.valueOf("test"));
+    Connection mockConnection = Mockito.mock(Connection.class);
+    Mockito.when(e.getConnection()).thenReturn(mockConnection);
     ImmutableBytesPtr tableName = new ImmutableBytesPtr(this.test.getTableName());
     Put m = new Put(row);
     m.addColumn(Bytes.toBytes("family"), Bytes.toBytes("qual"), null);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/629bc29b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleWriterIndexCommitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleWriterIndexCommitter.java
b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleWriterIndexCommitter.java
index d8dde82..d069026 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleWriterIndexCommitter.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/hbase/index/write/TestParalleWriterIndexCommitter.java
@@ -30,10 +30,14 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
 import org.apache.hadoop.hbase.client.Mutation;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
 import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.regionserver.Region;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.VersionInfo;
 import org.apache.phoenix.hbase.index.IndexTableName;
@@ -84,6 +88,13 @@ public class TestParalleWriterIndexCommitter {
     Configuration conf =new Configuration();
     Mockito.when(e.getConfiguration()).thenReturn(conf);
     Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
+    Region mockRegion = Mockito.mock(Region.class);
+    Mockito.when(e.getRegion()).thenReturn(mockRegion);
+    TableDescriptor mockTableDesc = Mockito.mock(TableDescriptor.class);
+    Mockito.when(mockTableDesc.getTableName()).thenReturn(TableName.valueOf("test"));
+    Connection mockConnection = Mockito.mock(Connection.class);
+    Mockito.when(e.getConnection()).thenReturn(mockConnection);
+    Mockito.when(mockRegion.getTableDescriptor()).thenReturn(mockTableDesc);
     Stoppable stop = Mockito.mock(Stoppable.class);
     ExecutorService exec = Executors.newFixedThreadPool(1);
     Map<ImmutableBytesPtr, Table> tables =


Mime
View raw message