This is an automated email from the ASF dual-hosted git repository.

pboado pushed a commit to branch 5.x-cdh6
in repository https://gitbox.apache.org/repos/asf/phoenix.git

commit c21c02dac426c71c3d6aa227ad2c79a5043bb6fa
Author: Monani Mihir <monani.mi...@gmail.com>
AuthorDate: Fri Apr 12 18:55:33 2019 +0100

    PHOENIX-5194 Thread Cache is not update for Index retries in for 
MutationState#send()#doMutation()
---
 .../org/apache/phoenix/execute/MutationState.java  | 28 ++++++++++++++++++++++
 .../phoenix/index/PhoenixIndexFailurePolicy.java   | 10 ++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
index 93ee43d..677b4e0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -993,6 +993,9 @@ public class MutationState implements SQLCloseable {
                             if (shouldRetryIndexedMutation) {
                                 // if there was an index write failure, retry 
the mutation in a loop
                                 final Table finalHTable = hTable;
+                                final ImmutableBytesWritable 
finalindexMetaDataPtr =
+                                        indexMetaDataPtr;
+                                final PTable finalPTable = table;
                                 
PhoenixIndexFailurePolicy.doBatchWithRetries(new MutateCommand() {
                                     @Override
                                     public void doMutation() throws 
IOException {
@@ -1001,6 +1004,9 @@ public class MutationState implements SQLCloseable {
                                         } catch (InterruptedException e) {
                                             Thread.currentThread().interrupt();
                                             throw new IOException(e);
+                                        } catch (IOException e) {
+                                            e = 
updateTableRegionCacheIfNecessary(e);
+                                            throw e;
                                         }
                                     }
 
@@ -1008,6 +1014,28 @@ public class MutationState implements SQLCloseable {
                                     public List<Mutation> getMutationList() {
                                         return mutationBatch;
                                     }
+
+                                    private IOException
+                                            
updateTableRegionCacheIfNecessary(IOException ioe) {
+                                        SQLException sqlE =
+                                                
ServerUtil.parseLocalOrRemoteServerException(ioe);
+                                        if (sqlE != null
+                                                && sqlE.getErrorCode() == 
SQLExceptionCode.INDEX_METADATA_NOT_FOUND
+                                                        .getErrorCode()) {
+                                            try {
+                                                
connection.getQueryServices().clearTableRegionCache(
+                                                    finalHTable.getName());
+                                                
IndexMetaDataCacheClient.setMetaDataOnMutations(
+                                                    connection, finalPTable, 
mutationBatch,
+                                                    finalindexMetaDataPtr);
+                                            } catch (SQLException e) {
+                                                return 
ServerUtil.createIOException(
+                                                    "Exception during updating 
index meta data cache",
+                                                    ioe);
+                                            }
+                                        }
+                                        return ioe;
+                                    }
                                 }, iwe, connection, 
connection.getQueryServices().getProps());
                             } else {
                                 hTable.batch(mutationBatch, null);
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 f0379dd..f13616a 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
@@ -488,8 +488,14 @@ public class PhoenixIndexFailurePolicy extends 
DelegateIndexFailurePolicy {
             } catch (IOException e) {
                 SQLException inferredE = 
ServerUtil.parseLocalOrRemoteServerException(e);
                 if (inferredE == null || inferredE.getErrorCode() != 
SQLExceptionCode.INDEX_WRITE_FAILURE.getErrorCode()) {
-                    // if it's not an index write exception, throw exception, 
to be handled normally in caller's try-catch
-                    throw e;
+                    // If this call is from phoenix client, we also need to 
check if SQLException
+                    // error is INDEX_METADATA_NOT_FOUND or not
+                    // if it's not an INDEX_METADATA_NOT_FOUND, throw 
exception,
+                    // to be handled normally in caller's try-catch
+                    if (inferredE.getErrorCode() != 
SQLExceptionCode.INDEX_METADATA_NOT_FOUND
+                            .getErrorCode()) {
+                        throw e;
+                    }
                 }
             } catch (InterruptedException e) {
                 Thread.currentThread().interrupt();

Reply via email to