Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.1 ecbfc761f -> d78a8621b
PHOENIX-4032 Make MutableIndexFailureIT more resilient Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d78a8621 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d78a8621 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d78a8621 Branch: refs/heads/4.x-HBase-1.1 Commit: d78a8621bdc1d5482a247c29394ebe115fdfe785 Parents: ecbfc76 Author: Samarth Jain <[email protected]> Authored: Mon Jul 17 22:20:55 2017 -0700 Committer: Samarth Jain <[email protected]> Committed: Mon Jul 17 22:20:55 2017 -0700 ---------------------------------------------------------------------- .../end2end/index/MutableIndexFailureIT.java | 59 ++++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/d78a8621/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 99e4b23..c07abb4 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 @@ -287,7 +287,7 @@ public class MutableIndexFailureIT extends BaseTest { FailingRegionObserver.FAIL_WRITE = false; if (rebuildIndexOnWriteFailure) { // wait for index to be rebuilt automatically - waitForIndexToBeRebuilt(conn,indexName); + waitForIndexRebuild(conn,indexName, PIndexState.ACTIVE); } else { // simulate replaying failed mutation replayMutations(); @@ -304,36 +304,28 @@ public class MutableIndexFailureIT extends BaseTest { // verify index table has correct data (note that second index has been dropped) validateDataWithIndex(conn, fullTableName, fullIndexName, localIndex); } else { - try { - // Wait for index to be rebuilt automatically. This should fail because - // we haven't flipped the FAIL_WRITE flag to false and as a result this - // should cause index rebuild to fail too. - waitForIndexToBeRebuilt(conn, indexName); - // verify that the index was marked as disabled and the index disable - // timestamp set to 0 - String q = - "SELECT INDEX_STATE, INDEX_DISABLE_TIMESTAMP FROM SYSTEM.CATALOG WHERE TABLE_SCHEM = '" - + schema + "' AND TABLE_NAME = '" + indexName + "'" - + " AND COLUMN_NAME IS NULL AND COLUMN_FAMILY IS NULL"; - try (ResultSet r = conn.createStatement().executeQuery(q)) { - assertTrue(r.next()); - assertEquals(PIndexState.DISABLE.getSerializedValue(), r.getString(1)); - assertEquals(0, r.getLong(2)); - assertFalse(r.next()); - } - } finally { - // even if the above test fails, make sure we leave the index active - // as other tests might be dependent on it - FAIL_WRITE = false; - waitForIndexToBeRebuilt(conn, indexName); + // Wait for index to be rebuilt automatically. This should fail because + // we haven't flipped the FAIL_WRITE flag to false and as a result this + // should cause index rebuild to fail too. + waitForIndexRebuild(conn, indexName, PIndexState.DISABLE); + // verify that the index was marked as disabled and the index disable + // timestamp set to 0 + String q = + "SELECT INDEX_STATE, INDEX_DISABLE_TIMESTAMP FROM SYSTEM.CATALOG WHERE TABLE_SCHEM = '" + + schema + "' AND TABLE_NAME = '" + indexName + "'" + + " AND COLUMN_NAME IS NULL AND COLUMN_FAMILY IS NULL"; + try (ResultSet r = conn.createStatement().executeQuery(q)) { + assertTrue(r.next()); + assertEquals(PIndexState.DISABLE.getSerializedValue(), r.getString(1)); + assertEquals(0, r.getLong(2)); + assertFalse(r.next()); } + } - } finally { - FAIL_WRITE = false; } } - private void waitForIndexToBeRebuilt(Connection conn, String index) throws InterruptedException, SQLException { + private void waitForIndexRebuild(Connection conn, String index, PIndexState expectedIndexState) throws InterruptedException, SQLException { boolean isActive = false; if (!transactional) { int maxTries = 12, nTries = 0; @@ -342,15 +334,20 @@ public class MutableIndexFailureIT extends BaseTest { String query = "SELECT CAST(" + PhoenixDatabaseMetaData.INDEX_DISABLE_TIMESTAMP + " AS BIGINT) FROM " + PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME + " WHERE (" + PhoenixDatabaseMetaData.TABLE_SCHEM + "," + PhoenixDatabaseMetaData.TABLE_NAME + ") = (" + "'" + schema + "','" + index + "') " - + "AND " + PhoenixDatabaseMetaData.COLUMN_FAMILY + " IS NULL AND " + PhoenixDatabaseMetaData.COLUMN_NAME + " IS NULL"; + + "AND " + PhoenixDatabaseMetaData.COLUMN_FAMILY + " IS NULL AND " + PhoenixDatabaseMetaData.COLUMN_NAME + " IS NULL" + + " AND " + PhoenixDatabaseMetaData.INDEX_STATE + " = '" + expectedIndexState.getSerializedValue() + "'"; ResultSet rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); - if (rs.getLong(1) == 0 && !rs.wasNull()) { - isActive = true; - break; + if (expectedIndexState == PIndexState.ACTIVE) { + if (rs.getLong(1) == 0 && !rs.wasNull()) { + isActive = true; + break; + } } } while (++nTries < maxTries); - assertTrue(isActive); + if (expectedIndexState == PIndexState.ACTIVE) { + assertTrue(isActive); + } } }
