gokceni commented on a change in pull request #550: PHOENIX-5348: Fix flaky 
test: testIndexRebuildTask
URL: https://github.com/apache/phoenix/pull/550#discussion_r307843524
 
 

 ##########
 File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexRebuildTaskIT.java
 ##########
 @@ -129,43 +128,48 @@ public void testIndexRebuildTask() throws Throwable {
             Task.addTask(conn.unwrap(PhoenixConnection.class), 
PTable.TaskType.INDEX_REBUILD,
                     TENANT1, null, viewName,
                     PTable.TaskStatus.CREATED.toString(), data, null, startTs, 
null, true);
-
-
             task.run();
+            waitForTaskState(conn, PTable.TaskType.INDEX_REBUILD, viewName, 
PTable.TaskStatus.COMPLETED);
 
             String viewIndexTableName = 
MetaDataUtil.getViewIndexPhysicalName(baseTable);
             ConnectionQueryServices queryServices = 
conn.unwrap(PhoenixConnection.class).getQueryServices();
             int count = 
getUtility().countRows(queryServices.getTable(Bytes.toBytes(viewIndexTableName)));
             assertTrue(count == numOfValues);
 
-
             // Remove index contents and try again
             Admin admin = queryServices.getAdmin();
             TableName tableName = TableName.valueOf(viewIndexTableName);
             admin.disableTable(tableName);
-            admin.truncateTable(tableName, false);
+            admin.truncateTable(tableName, true);
 
             data = "{IndexName:" + indexName + ", DisableBefore:true}";
 
-            // Add a new task (update status to created) to System.Task to 
rebuild indexes
+            // Add a new task to System.Task to rebuild indexes
+            conn.createStatement().execute("DELETE " + " FROM " + 
PhoenixDatabaseMetaData.SYSTEM_TASK_NAME
+                    + " WHERE TABLE_NAME ='" + viewName  + "'");
+            conn.commit();
+            Thread.sleep(1);
+            startTs = new 
Timestamp(EnvironmentEdgeManager.currentTimeMillis());
             Task.addTask(conn.unwrap(PhoenixConnection.class), 
PTable.TaskType.INDEX_REBUILD,
                     TENANT1, null, viewName,
                     PTable.TaskStatus.CREATED.toString(), data, null, startTs, 
null, true);
+            conn.commit();
             task.run();
 
             Table systemHTable= 
queryServices.getTable(Bytes.toBytes("SYSTEM."+PhoenixDatabaseMetaData.SYSTEM_TASK_TABLE));
             count = getUtility().countRows(systemHTable);
             assertEquals(1, count);
 
             // Check task status and other column values.
-            waitForTaskState(conn, PTable.TaskType.INDEX_REBUILD, 
PTable.TaskStatus.COMPLETED);
+            waitForTaskState(conn, PTable.TaskType.INDEX_REBUILD, viewName, 
PTable.TaskStatus.COMPLETED);
 
             // See that index is rebuilt and confirm index has rows
             Table htable= 
queryServices.getTable(Bytes.toBytes(viewIndexTableName));
             count = getUtility().countRows(htable);
             assertEquals(numOfValues, count);
         } finally {
-            conn.createStatement().execute("DELETE " + " FROM " + 
PhoenixDatabaseMetaData.SYSTEM_TASK_NAME);
+            conn.createStatement().execute("DELETE " + " FROM " + 
PhoenixDatabaseMetaData.SYSTEM_TASK_NAME
+            + " WHERE TABLE_NAME ='" + viewName  + "'");
 
 Review comment:
   @ChinmaySKulkarni, there is one task I create before this point in the same 
test function. I run an IndexRebuild task, and then I go ahead and remove the 
contents of index via admin api and re-run it to see if it builds. We can do it 
two ways: delete the task record and create a new record or just update the 
task record and set its status so that it gets picked up. Same thing really in 
terms of what we want to achieve.  

----------------------------------------------------------------
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