This is an automated email from the ASF dual-hosted git repository.

skadam pushed a commit to branch 4.x-HBase-1.5
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x-HBase-1.5 by this push:
     new 1622ef9  PHOENIX-5723 PhoenixIndexImportDirectReducer cleanup method 
updates index state to active
1622ef9 is described below

commit 1622ef974ccd7d4ecd5d73058a6ff91a18b900c3
Author: Tanuj Khurana <khurana.ta...@gmail.com>
AuthorDate: Wed Feb 12 13:34:35 2020 -0800

    PHOENIX-5723 PhoenixIndexImportDirectReducer cleanup method updates index 
state to active
    
    Signed-off-by: s.kadam <s.ka...@apache.org>
---
 .../apache/phoenix/end2end/IndexExtendedIT.java    | 52 ++++++++++++++++++++++
 .../index/PhoenixIndexImportDirectReducer.java     | 11 +++--
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
index fd830c2..bf78cef 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
@@ -36,6 +36,7 @@ import java.util.Properties;
 
 import org.apache.hadoop.hbase.client.Table;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.hbase.index.IndexRegionObserver;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.mapreduce.index.IndexTool;
 import org.apache.phoenix.query.BaseTest;
@@ -314,4 +315,55 @@ public class IndexExtendedIT extends BaseTest {
             conn.close();
         }
     }
+
+    @Test
+    public void testIndexStateOnException() throws Exception {
+        if (localIndex  || useSnapshot || useViewIndex) {
+            return;
+        }
+
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, 
dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexFullName = SchemaUtil.getTableName(schemaName, 
indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)){
+            Statement stmt = conn.createStatement();
+            stmt.execute(String.format(
+                    "CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME 
VARCHAR, ZIP INTEGER) %s",
+                    dataTableFullName, tableDDLOptions));
+
+            stmt.execute(String.format(
+                    "UPSERT INTO %s VALUES(1, 'Phoenix', 12345)", 
dataTableFullName));
+
+            conn.commit();
+
+            // Configure IndexRegionObserver to fail the first write phase. 
This should not
+            // lead to any change on index and thus index verify during index 
rebuild should fail
+            IndexRegionObserver.setIgnoreIndexRebuildForTesting(true);
+            stmt.execute(String.format(
+                    "CREATE INDEX %s ON %s (NAME) INCLUDE (ZIP) ASYNC",
+                    indexTableName, dataTableFullName));
+
+            // Verify that the index table is not in the ACTIVE state
+            assertFalse(checkIndexState(conn, indexFullName, 
PIndexState.ACTIVE, 0L));
+
+            // Run the index MR job and verify that the index table rebuild 
fails
+            IndexToolIT.runIndexTool(true, false, schemaName, dataTableName,
+                    indexTableName, null, -1, IndexTool.IndexVerifyType.AFTER);
+
+            IndexRegionObserver.setIgnoreIndexRebuildForTesting(false);
+
+            // job failed, verify that the index table is still not in the 
ACTIVE state
+            assertFalse(checkIndexState(conn, indexFullName, 
PIndexState.ACTIVE, 0L));
+
+            // Run the index MR job and verify that the index table rebuild 
succeeds
+            IndexToolIT.runIndexTool(true, false, schemaName, dataTableName,
+                    indexTableName, null, 0, IndexTool.IndexVerifyType.AFTER);
+
+            // job passed, verify that the index table is in the ACTIVE state
+            assertTrue(checkIndexState(conn, indexFullName, 
PIndexState.ACTIVE, 0L));
+        }
+    }
 }
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java
index 46fb9ec..98000f7 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/PhoenixIndexImportDirectReducer.java
@@ -111,16 +111,21 @@ public class PhoenixIndexImportDirectReducer extends
         if (verifyType != IndexTool.IndexVerifyType.NONE) {
             updateCounters(verifyType, context);
         }
+
+        try {
+            IndexToolUtil.updateIndexState(context.getConfiguration(), 
PIndexState.ACTIVE);
+        } catch (SQLException e) {
+            LOGGER.error(" Failed to update the status to Active");
+            throw new RuntimeException(e.getMessage());
+        }
     }
 
     @Override
     protected void cleanup(Context context) throws IOException, 
InterruptedException{
         try {
-            IndexToolUtil.updateIndexState(context.getConfiguration(), 
PIndexState.ACTIVE);
-
             updateTasksTable(context);
         } catch (SQLException e) {
-            LOGGER.error(" Failed to update the status to Active");
+            LOGGER.error(" Failed to update the tasks table");
             throw new RuntimeException(e.getMessage());
         }
     }

Reply via email to