swaroopak commented on a change in pull request #499: Phoenix-5272 ALTER INDEX 
REBUILD ALL 
URL: https://github.com/apache/phoenix/pull/499#discussion_r281459554
 
 

 ##########
 File path: phoenix-core/src/test/java/org/apache/phoenix/util/TestUtil.java
 ##########
 @@ -934,7 +934,30 @@ public IndexStateCheck(PIndexState indexState, Long 
indexDisableTimestamp, Boole
                this.success = success;
        }
     }
-    
+
+    public static void waitForIndexState(Connection conn, String 
fullIndexName, PIndexState expectedIndexState) throws InterruptedException, 
SQLException {
+        int maxTries = 60, nTries = 0;
+        do {
+            String schema = 
SchemaUtil.getSchemaNameFromFullName(fullIndexName);
+            String index = SchemaUtil.getTableNameFromFullName(fullIndexName);
+            Thread.sleep(1000); // sleep 1 sec
+            String query = "SELECT " + PhoenixDatabaseMetaData.INDEX_STATE + " 
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";
+            ResultSet rs = conn.createStatement().executeQuery(query);
+            PIndexState actualIndexState = null;
+            if (rs.next()) {
+                actualIndexState = 
PIndexState.fromSerializedValue(rs.getString(1));
+                boolean matchesExpected = (actualIndexState == 
expectedIndexState);
+                if (matchesExpected) {
+                    return;
+                }
+            }
+        } while (++nTries < maxTries);
 
 Review comment:
   Do you wanna utilize exponential backoff? Maybe worth looking at hbase's 
RetryCounter utility. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to