You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ra...@apache.org on 2016/09/14 15:24:42 UTC
phoenix git commit: PHOENIX-3162 TableNotFoundException might be
thrown when an index dropped while upserting.(Rajeshbabu)
Repository: phoenix
Updated Branches:
refs/heads/master b640b39ce -> e4fd03952
PHOENIX-3162 TableNotFoundException might be thrown when an index dropped while upserting.(Rajeshbabu)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e4fd0395
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e4fd0395
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e4fd0395
Branch: refs/heads/master
Commit: e4fd03952a15be60eee6ddc557a19ce917c606c2
Parents: b640b39
Author: Rajeshbabu Chintaguntla <ra...@apache.org>
Authored: Wed Sep 14 21:03:22 2016 +0530
Committer: Rajeshbabu Chintaguntla <ra...@apache.org>
Committed: Wed Sep 14 21:03:22 2016 +0530
----------------------------------------------------------------------
.../end2end/index/MutableIndexFailureIT.java | 34 +++++++++++++++++---
.../index/PhoenixIndexFailurePolicy.java | 5 +--
2 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e4fd0395/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index 0a85216..c68d897 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
+import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.PIndexState;
@@ -79,7 +80,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
private String tableName;
private String indexName;
- private String fullTableName;
+ public static volatile String fullTableName;
private String fullIndexName;
private final boolean transactional;
@@ -150,6 +151,11 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
FAIL_WRITE = false;
conn.createStatement().execute(
"CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
+ // Create other index which should be local/global if the other index is global/local to
+ // check the drop index.
+ conn.createStatement().execute(
+ "CREATE " + (!localIndex ? "LOCAL " : "") + "INDEX " + indexName + "_3" + " ON "
+ + fullTableName + " (v2) INCLUDE (v1)");
conn.createStatement().execute(
"CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + secondIndexName + " ON " + secondTableName + " (v1) INCLUDE (v2)");
@@ -166,7 +172,9 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
assertTrue(rs.next());
assertEquals(secondIndexName, rs.getString(3));
assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
- assertFalse(rs.next());
+ assertTrue(rs.next());
+ assertEquals(indexName+"_3", rs.getString(3));
+ assertEquals(PIndexState.ACTIVE.toString(), rs.getString("INDEX_STATE"));
initializeTable(conn, fullTableName);
initializeTable(conn, secondTableName);
@@ -262,7 +270,9 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.setString(3, "4");
stmt.execute();
conn.commit();
-
+ // To clear the index name from connection.
+ PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
+ phoenixConn.getMetaDataCache().removeTable(null, fullTableName, null, HConstants.LATEST_TIMESTAMP);
// verify index table has correct data
validateDataWithIndex(conn, fullTableName, fullIndexName);
validateDataWithIndex(conn, secondTableName, secondFullIndexName);
@@ -306,7 +316,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
}
private void validateDataWithIndex(Connection conn, String tableName, String indexName) throws SQLException {
- String query = "SELECT /*+ INDEX(" + indexName + ") */ k,v1 FROM " + tableName;
+ String query = "SELECT /*+ INDEX(" + indexName + ") */ k,v1 FROM " + tableName;
ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
String expectedPlan = " OVER "
+ (localIndex
@@ -314,7 +324,7 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
SchemaUtil.getPhysicalTableName(tableName.getBytes(), isNamespaceMapped).getName())
: SchemaUtil.getPhysicalTableName(indexName.getBytes(), isNamespaceMapped).getNameAsString());
String explainPlan = QueryUtil.getExplainPlan(rs);
- assertTrue(explainPlan.contains(expectedPlan));
+ assertTrue(explainPlan, explainPlan.contains(expectedPlan));
rs = conn.createStatement().executeQuery(query);
if (transactional) { // failed commit does not get retried
assertTrue(rs.next());
@@ -378,16 +388,30 @@ public class MutableIndexFailureIT extends BaseOwnClusterHBaseManagedTimeIT {
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
if (c.getEnvironment().getRegionInfo().getTable().getNameAsString().contains(INDEX_NAME) && FAIL_WRITE) {
+ dropIndex(c);
throw new DoNotRetryIOException();
}
Mutation operation = miniBatchOp.getOperation(0);
Set<byte[]> keySet = operation.getFamilyMap().keySet();
for(byte[] family: keySet) {
if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX) && FAIL_WRITE) {
+ dropIndex(c);
throw new DoNotRetryIOException();
}
}
}
+
+ private void dropIndex(ObserverContext<RegionCoprocessorEnvironment> c) {
+ try {
+ Connection connection =
+ QueryUtil.getConnection(c.getEnvironment().getConfiguration());
+ connection.createStatement().execute(
+ "DROP INDEX IF EXISTS " + INDEX_NAME + "_3" + " ON "
+ + fullTableName);
+ } catch (ClassNotFoundException e) {
+ } catch (SQLException e) {
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/e4fd0395/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 67242f6..c29d7b4 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
@@ -137,8 +137,9 @@ public class PhoenixIndexFailurePolicy extends DelegateIndexFailurePolicy {
}
}
- // its a local index table, so we need to convert it to the index table names we should disable
- if (MetaDataUtil.hasLocalIndexColumnFamily(env.getRegion().getTableDesc())) {
+ // If the data table has local index column families then get local indexes to disable.
+ if (ref.getTableName().equals(env.getRegion().getTableDesc().getNameAsString())
+ && MetaDataUtil.hasLocalIndexColumnFamily(env.getRegion().getTableDesc())) {
for (String tableName : getLocalIndexNames(ref, mutations)) {
indexTableNames.put(tableName, minTimeStamp);
}