This is an automated email from the ASF dual-hosted git repository.
vincentpoon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push:
new 0b3e7aa PHOENIX-5194 Thread Cache is not update for Index retries in
for MutationState#send()#doMutation()
0b3e7aa is described below
commit 0b3e7aac0d4b646a6aa27216014a178494b62611
Author: Monani Mihir <[email protected]>
AuthorDate: Fri Apr 12 23:25:33 2019 +0530
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();