You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by vi...@apache.org on 2018/02/01 00:39:56 UTC

[3/3] phoenix git commit: PHOENIX-4130 Avoid server retries for mutable indexes (Addendum)

PHOENIX-4130 Avoid server retries for mutable indexes (Addendum)


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 9a2d4747d90704580241ae7177a4ff45a1e6a2d8
Parents: 0db17ed
Author: Vincent Poon <vi...@apache.org>
Authored: Wed Jan 31 16:33:01 2018 -0800
Committer: Vincent Poon <vi...@apache.org>
Committed: Wed Jan 31 16:35:12 2018 -0800

----------------------------------------------------------------------
 .../end2end/index/PartialIndexRebuilderIT.java  |  3 +--
 .../index/exception/IndexWriteException.java    | 21 +++++++++++---------
 .../MultiIndexWriteFailureException.java        | 14 +++++++++++--
 .../SingleIndexWriteFailureException.java       | 15 +++++++++++---
 .../index/PhoenixIndexFailurePolicy.java        | 18 +++++++++++++++++
 5 files changed, 55 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a2d4747/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java
index dd986aa..3961d32 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PartialIndexRebuilderIT.java
@@ -1098,8 +1098,7 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT {
                     conn.createStatement().execute("DELETE FROM " + fullTableName);
                     fail();
                 } catch (SQLException e) {
-                    // Expected
-                    assertEquals(SQLExceptionCode.INDEX_WRITE_FAILURE.getErrorCode(), e.getErrorCode());
+                    // expected
                 }
                 assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.DISABLE, null));
             } finally {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a2d4747/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/IndexWriteException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/IndexWriteException.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/IndexWriteException.java
index 531baa6..5dc6f60 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/IndexWriteException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/IndexWriteException.java
@@ -22,6 +22,8 @@ import java.util.regex.Pattern;
 import org.apache.hadoop.hbase.HBaseIOException;
 import org.apache.phoenix.query.QueryServicesOptions;
 
+import com.google.common.base.Objects;
+
 /**
  * Generic {@link Exception} that an index write has failed
  */
@@ -33,7 +35,7 @@ public class IndexWriteException extends HBaseIOException {
      * server side.
      */
     private static final String DISABLE_INDEX_ON_FAILURE_MSG = "disableIndexOnFailure=";
-    private boolean disableIndexOnFailure;
+    private boolean disableIndexOnFailure = QueryServicesOptions.DEFAULT_INDEX_FAILURE_DISABLE_INDEX;
 
   public IndexWriteException() {
     super();
@@ -49,19 +51,15 @@ public class IndexWriteException extends HBaseIOException {
       super(message, cause);
   }
 
-  public IndexWriteException(String message, Throwable cause, boolean disableIndexOnFailure) {
-    super(prependDisableIndexMsg(message, disableIndexOnFailure), cause);
+  public IndexWriteException(Throwable cause, boolean disableIndexOnFailure) {
+    super(cause);
+    this.disableIndexOnFailure = disableIndexOnFailure;
   }
 
-  public IndexWriteException(String message, boolean disableIndexOnFailure) {
-    super(prependDisableIndexMsg(message, disableIndexOnFailure));
+  public IndexWriteException(boolean disableIndexOnFailure) {
     this.disableIndexOnFailure = disableIndexOnFailure;
   }
 
-  private static String prependDisableIndexMsg(String message, boolean disableIndexOnFailure) {
-    return DISABLE_INDEX_ON_FAILURE_MSG + disableIndexOnFailure + " " + message;
-}
-
 public IndexWriteException(Throwable cause) {
     super(cause);
   }
@@ -81,4 +79,9 @@ public IndexWriteException(Throwable cause) {
     public boolean isDisableIndexOnFailure() {
         return disableIndexOnFailure;
     }
+
+    @Override
+    public String getMessage() {
+        return Objects.firstNonNull(super.getMessage(), "") + " " + DISABLE_INDEX_ON_FAILURE_MSG + disableIndexOnFailure + ",";
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a2d4747/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/MultiIndexWriteFailureException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/MultiIndexWriteFailureException.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/MultiIndexWriteFailureException.java
index d593791..a14e8a5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/MultiIndexWriteFailureException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/MultiIndexWriteFailureException.java
@@ -25,6 +25,7 @@ import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.table.HTableInterfaceReference;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 
+import com.google.common.base.Objects;
 import com.google.common.collect.Lists;
 
 /**
@@ -40,7 +41,7 @@ public class MultiIndexWriteFailureException extends IndexWriteException {
    * @param failures the tables to which the index write did not succeed
    */
   public MultiIndexWriteFailureException(List<HTableInterfaceReference> failures, boolean disableIndexOnFailure) {
-    super(FAILURE_MSG + failures, disableIndexOnFailure);
+    super(disableIndexOnFailure);
     this.failures = failures;
   }
 
@@ -50,7 +51,7 @@ public class MultiIndexWriteFailureException extends IndexWriteException {
    * @param message detail message
    */
   public MultiIndexWriteFailureException(String message) {
-      super(message, IndexWriteException.parseDisableIndexOnFailure(message));
+      super(IndexWriteException.parseDisableIndexOnFailure(message));
       Pattern p = Pattern.compile(FAILURE_MSG + "\\[(.*)\\]");
       Matcher m = p.matcher(message);
       if (m.find()) {
@@ -66,4 +67,13 @@ public class MultiIndexWriteFailureException extends IndexWriteException {
   public List<HTableInterfaceReference> getFailedTables() {
     return this.failures;
   }
+
+  public void setFailedTables(List<HTableInterfaceReference> failedTables) {
+      this.failures = failedTables;
+  }
+
+  @Override
+    public String getMessage() {
+        return Objects.firstNonNull(super.getMessage(),"") + " " + FAILURE_MSG + failures;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a2d4747/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/SingleIndexWriteFailureException.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/SingleIndexWriteFailureException.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/SingleIndexWriteFailureException.java
index 610a82a..67dabba 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/SingleIndexWriteFailureException.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/exception/SingleIndexWriteFailureException.java
@@ -23,6 +23,8 @@ import java.util.regex.Pattern;
 
 import org.apache.hadoop.hbase.client.Mutation;
 
+import com.google.common.base.Objects;
+
 /**
  * Exception thrown if we cannot successfully write to an index table.
  */
@@ -31,6 +33,7 @@ public class SingleIndexWriteFailureException extends IndexWriteException {
 
   public static final String FAILED_MSG = "Failed to make index update:";
   private String table;
+  private String mutationsMsg;
 
   /**
    * Cannot reach the index, but not sure of the table or the mutations that caused the failure
@@ -49,9 +52,9 @@ public class SingleIndexWriteFailureException extends IndexWriteException {
    */
   public SingleIndexWriteFailureException(String targetTableName, List<Mutation> mutations,
       Exception cause, boolean disableIndexOnFailure) {
-    super(FAILED_MSG + "\n\t table: " + targetTableName + "\n\t edits: " + mutations
-        + "\n\tcause: " + cause == null ? "UNKNOWN" : cause.getMessage(), cause, disableIndexOnFailure);
+    super(cause, disableIndexOnFailure);
     this.table = targetTableName;
+    this.mutationsMsg = mutations.toString();
   }
 
   /**
@@ -60,7 +63,7 @@ public class SingleIndexWriteFailureException extends IndexWriteException {
    * @param message detail message
    */
   public SingleIndexWriteFailureException(String msg) {
-      super(msg, IndexWriteException.parseDisableIndexOnFailure(msg));
+      super(IndexWriteException.parseDisableIndexOnFailure(msg));
       Pattern pattern = Pattern.compile(FAILED_MSG + ".* table: ([\\S]*)\\s.*", Pattern.DOTALL);
       Matcher m = pattern.matcher(msg);
       if (m.find()) {
@@ -75,4 +78,10 @@ public class SingleIndexWriteFailureException extends IndexWriteException {
   public String getTableName() {
     return this.table;
   }
+
+  @Override
+    public String getMessage() {
+      return Objects.firstNonNull(super.getMessage(), "") + " " + FAILED_MSG + "\n\t table: " + this.table + "\n\t edits: " + mutationsMsg
+      + "\n\tcause: " + getCause() == null ? "UNKNOWN" : getCause().getMessage();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9a2d4747/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
index 14f8307..55192e7 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/PhoenixIndexFailurePolicy.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
 import org.apache.commons.logging.Log;
@@ -53,6 +54,7 @@ import org.apache.phoenix.hbase.index.exception.IndexWriteException;
 import org.apache.phoenix.hbase.index.exception.MultiIndexWriteFailureException;
 import org.apache.phoenix.hbase.index.exception.SingleIndexWriteFailureException;
 import org.apache.phoenix.hbase.index.table.HTableInterfaceReference;
+import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.hbase.index.write.DelegateIndexFailurePolicy;
 import org.apache.phoenix.hbase.index.write.KillServerOnFailurePolicy;
 import org.apache.phoenix.jdbc.PhoenixConnection;
@@ -70,6 +72,9 @@ import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.ServerUtil;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
 
 /**
@@ -208,6 +213,19 @@ public class PhoenixIndexFailurePolicy extends DelegateIndexFailurePolicy {
                 for (String tableName : getLocalIndexNames(ref, mutations)) {
                     indexTableNames.put(tableName, minTimeStamp);
                 }
+                // client disables the index, so we pass the index names in the thrown exception
+                if (cause instanceof MultiIndexWriteFailureException) {
+                    List<HTableInterfaceReference> failedLocalIndexes =
+                            Lists.newArrayList(Iterables.transform(indexTableNames.entrySet(),
+                                new Function<Map.Entry<String, Long>, HTableInterfaceReference>() {
+                                    @Override
+                                    public HTableInterfaceReference apply(Entry<String, Long> input) {
+                                        return new HTableInterfaceReference(new ImmutableBytesPtr(
+                                                Bytes.toBytes(input.getKey())));
+                                    }
+                                }));
+                    ((MultiIndexWriteFailureException) cause).setFailedTables(failedLocalIndexes);
+                }
             } else {
                 indexTableNames.put(ref.getTableName(), minTimeStamp);
             }