You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2017/09/27 00:30:54 UTC
phoenix git commit: PHOENIX-4239 Fix flapping test in
PartialIndexRebuilderIT
Repository: phoenix
Updated Branches:
refs/heads/4.x-HBase-0.98 29126a1ff -> df1c7e4b9
PHOENIX-4239 Fix flapping test in PartialIndexRebuilderIT
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/df1c7e4b
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/df1c7e4b
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/df1c7e4b
Branch: refs/heads/4.x-HBase-0.98
Commit: df1c7e4b9b89c081c4c6b4060514a5dc3daa5f1b
Parents: 29126a1
Author: James Taylor <ja...@apache.org>
Authored: Tue Sep 26 15:35:36 2017 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Tue Sep 26 17:26:11 2017 -0700
----------------------------------------------------------------------
.../end2end/index/PartialIndexRebuilderIT.java | 8 +--
.../java/org/apache/phoenix/util/TestUtil.java | 51 ++++++++++++++++----
2 files changed, 46 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/df1c7e4b/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 9095dbe..8bf2bc8 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
@@ -88,7 +88,7 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT {
Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(10);
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_ATTRIB, Boolean.TRUE.toString());
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_INTERVAL_ATTRIB, Long.toString(REBUILD_INTERVAL));
- serverProps.put(QueryServices.INDEX_REBUILD_DISABLE_TIMESTAMP_THRESHOLD, "300000"); // give up rebuilding after 5 minutes
+ serverProps.put(QueryServices.INDEX_REBUILD_DISABLE_TIMESTAMP_THRESHOLD, "50000000");
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_PERIOD, Long.toString(REBUILD_PERIOD)); // batch at 50 seconds
serverProps.put(QueryServices.INDEX_FAILURE_HANDLING_REBUILD_OVERLAP_FORWARD_TIME_ATTRIB, Long.toString(WAIT_AFTER_DISABLED));
setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), ReadOnlyProps.EMPTY_PROPS);
@@ -897,7 +897,7 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT {
TestUtil.removeCoprocessor(conn, fullIndexName, WriteFailingRegionObserver.class);
runIndexRebuilder();
- assertTrue(TestUtil.checkIndexState(conn, fullIndexName, indexStateOnFailure == PIndexState.DISABLE ? PIndexState.INACTIVE : PIndexState.ACTIVE, null));
+ assertEquals(indexStateOnFailure == PIndexState.DISABLE ? PIndexState.INACTIVE : PIndexState.ACTIVE, TestUtil.getIndexState(conn, fullIndexName));
clock.time += WAIT_AFTER_DISABLED;
// First batch should have been processed again because we started over
@@ -907,7 +907,9 @@ public class PartialIndexRebuilderIT extends BaseUniqueNamesOwnClusterIT {
clock.time += 2 * REBUILD_PERIOD;
// Second batch should have been processed now
runIndexRebuilder();
- assertTrue(TestUtil.checkIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L));
+ clock.time += 2 * REBUILD_PERIOD;
+ runIndexRebuilder();
+ TestUtil.assertIndexState(conn, fullIndexName, PIndexState.ACTIVE, 0L);
// Verify that other batches were processed
IndexScrutiny.scrutinizeIndex(conn, fullTableName, fullIndexName);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/df1c7e4b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
index d87e35c..5a5e176 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
@@ -888,14 +888,25 @@ public class TestUtil {
waitForIndexState(conn, fullIndexName, indexState, 0L);
}
- private enum IndexStateCheck {SUCCESS, FAIL, KEEP_TRYING};
+ private static class IndexStateCheck {
+ public final PIndexState indexState;
+ public final Long indexDisableTimestamp;
+ public final Boolean success;
+
+ public IndexStateCheck(PIndexState indexState, Long indexDisableTimestamp, Boolean success) {
+ this.indexState = indexState;
+ this.indexDisableTimestamp = indexDisableTimestamp;
+ this.success = success;
+ }
+ }
+
public static void waitForIndexState(Connection conn, String fullIndexName, PIndexState expectedIndexState, Long expectedIndexDisableTimestamp) throws InterruptedException, SQLException {
int maxTries = 60, nTries = 0;
do {
Thread.sleep(1000); // sleep 1 sec
IndexStateCheck state = checkIndexStateInternal(conn, fullIndexName, expectedIndexState, expectedIndexDisableTimestamp);
- if (state != IndexStateCheck.KEEP_TRYING) {
- if (state == IndexStateCheck.SUCCESS) {
+ if (state.success != null) {
+ if (Boolean.TRUE.equals(state.success)) {
return;
}
fail("Index state will not become " + expectedIndexState);
@@ -905,8 +916,26 @@ public class TestUtil {
}
public static boolean checkIndexState(Connection conn, String fullIndexName, PIndexState expectedIndexState, Long expectedIndexDisableTimestamp) throws SQLException {
- return checkIndexStateInternal(conn,fullIndexName, expectedIndexState, expectedIndexDisableTimestamp) == IndexStateCheck.SUCCESS;
+ return Boolean.TRUE.equals(checkIndexStateInternal(conn,fullIndexName, expectedIndexState, expectedIndexDisableTimestamp).success);
+ }
+
+ public static void assertIndexState(Connection conn, String fullIndexName, PIndexState expectedIndexState, Long expectedIndexDisableTimestamp) throws SQLException {
+ IndexStateCheck state = checkIndexStateInternal(conn,fullIndexName, expectedIndexState, expectedIndexDisableTimestamp);
+ if (!Boolean.TRUE.equals(state.success)) {
+ if (expectedIndexState != null) {
+ assertEquals(expectedIndexState, state.indexState);
+ }
+ if (expectedIndexDisableTimestamp != null) {
+ assertEquals(expectedIndexDisableTimestamp, state.indexDisableTimestamp);
+ }
+ }
+ }
+
+ public static PIndexState getIndexState(Connection conn, String fullIndexName) throws SQLException {
+ IndexStateCheck state = checkIndexStateInternal(conn, fullIndexName, null, null);
+ return state.indexState;
}
+
private static IndexStateCheck checkIndexStateInternal(Connection conn, String fullIndexName, PIndexState expectedIndexState, Long expectedIndexDisableTimestamp) throws SQLException {
String schema = SchemaUtil.getSchemaNameFromFullName(fullIndexName);
String index = SchemaUtil.getTableNameFromFullName(fullIndexName);
@@ -915,19 +944,21 @@ public class TestUtil {
+ ") = (" + "'" + schema + "','" + index + "') "
+ "AND " + PhoenixDatabaseMetaData.COLUMN_FAMILY + " IS NULL AND " + PhoenixDatabaseMetaData.COLUMN_NAME + " IS NULL";
ResultSet rs = conn.createStatement().executeQuery(query);
+ Long actualIndexDisableTimestamp = null;
+ PIndexState actualIndexState = null;
if (rs.next()) {
- Long actualIndexDisableTimestamp = rs.getLong(1);
- PIndexState actualIndexState = PIndexState.fromSerializedValue(rs.getString(2));
+ actualIndexDisableTimestamp = rs.getLong(1);
+ actualIndexState = PIndexState.fromSerializedValue(rs.getString(2));
boolean matchesExpected = (expectedIndexDisableTimestamp == null || Objects.equal(actualIndexDisableTimestamp, expectedIndexDisableTimestamp))
- && actualIndexState == expectedIndexState;
+ && (expectedIndexState == null || actualIndexState == expectedIndexState);
if (matchesExpected) {
- return IndexStateCheck.SUCCESS;
+ return new IndexStateCheck(actualIndexState, actualIndexDisableTimestamp, Boolean.TRUE);
}
if (ZERO.equals(actualIndexDisableTimestamp)) {
- return IndexStateCheck.FAIL;
+ return new IndexStateCheck(actualIndexState, actualIndexDisableTimestamp, Boolean.FALSE);
}
}
- return IndexStateCheck.KEEP_TRYING;
+ return new IndexStateCheck(actualIndexState, actualIndexDisableTimestamp, null);
}
public static long getRowCount(Connection conn, String tableName) throws SQLException {