You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by sk...@apache.org on 2020/02/18 23:49:34 UTC
[phoenix] branch 4.x-HBase-1.3 updated: PHOENIX-5723
PhoenixIndexImportDirectReducer cleanup method updates index state to
active
This is an automated email from the ASF dual-hosted git repository.
skadam pushed a commit to branch 4.x-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.3 by this push:
new 9e8f14d PHOENIX-5723 PhoenixIndexImportDirectReducer cleanup method updates index state to active
9e8f14d is described below
commit 9e8f14da1157fad32679691c02e1d8164919842c
Author: Tanuj Khurana <kh...@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....@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());
}
}