You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by pb...@apache.org on 2018/12/03 19:41:50 UTC
[2/9] phoenix git commit: PHOENIX-4519 - Index rebuild MR jobs not
created for "alter index rebuild async" rebuilds
PHOENIX-4519 - Index rebuild MR jobs not created for "alter index rebuild async" rebuilds
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/a9706bb2
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a9706bb2
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a9706bb2
Branch: refs/heads/4.14-cdh5.14
Commit: a9706bb294c9781ff9687cbcb8737b3c4870e665
Parents: 3b00c16
Author: Geoffrey <gj...@apache.org>
Authored: Fri Sep 7 00:18:09 2018 +0100
Committer: Pedro Boado <pb...@apache.org>
Committed: Mon Dec 3 08:36:48 2018 +0000
----------------------------------------------------------------------
.../end2end/index/PhoenixMRJobSubmitterIT.java | 113 +++++++++++++++++++
.../index/automation/PhoenixMRJobSubmitter.java | 16 ++-
.../apache/phoenix/schema/MetaDataClient.java | 2 +-
3 files changed, 126 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9706bb2/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PhoenixMRJobSubmitterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PhoenixMRJobSubmitterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PhoenixMRJobSubmitterIT.java
new file mode 100644
index 0000000..7cc3aa0
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/PhoenixMRJobSubmitterIT.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end.index;
+
+import org.apache.phoenix.end2end.BaseUniqueNamesOwnClusterIT;
+import org.apache.phoenix.end2end.NeedsOwnMiniClusterTest;
+import org.apache.phoenix.mapreduce.index.automation.PhoenixAsyncIndex;
+import org.apache.phoenix.mapreduce.index.automation.PhoenixMRJobSubmitter;
+import org.apache.phoenix.schema.MetaDataClient;
+import org.apache.phoenix.schema.PIndexState;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.RunUntilFailure;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.util.Map;
+
+@Category(NeedsOwnMiniClusterTest.class)
+public class PhoenixMRJobSubmitterIT extends BaseUniqueNamesOwnClusterIT {
+
+ private static String REQUEST_INDEX_REBUILD_SQL = "ALTER INDEX %s ON %s REBUILD ASYNC";
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ setUpTestDriver(ReadOnlyProps.EMPTY_PROPS);
+
+ }
+
+ @Test
+ public void testGetCandidateJobs() throws Exception {
+ String tableName = "TBL_" + generateUniqueName();
+ String asyncIndexName = "IDX_" + generateUniqueName();
+ String needsRebuildIndexName = "IDX_" + generateUniqueName();
+ String tableDDL = "CREATE TABLE " + tableName + TestUtil.TEST_TABLE_SCHEMA;
+ String asyncIndexDDL = "CREATE INDEX " + asyncIndexName + " ON " + tableName + " (a.varchar_col1) ASYNC";
+ String needsRebuildIndexDDL = "CREATE INDEX " + needsRebuildIndexName + " ON " + tableName + " (a.char_col1)";
+ long rebuildTimestamp = 100L;
+
+ createTestTable(getUrl(), tableDDL);
+
+ createTestTable(getUrl(), needsRebuildIndexDDL);
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = DriverManager.getConnection(getUrl());
+ TestUtil.assertIndexState(conn, needsRebuildIndexName, PIndexState.ACTIVE, 0L);
+
+ //first make sure that we don't return an active index
+ PhoenixMRJobSubmitter submitter = new PhoenixMRJobSubmitter(getUtility().getConfiguration());
+ Map<String, PhoenixAsyncIndex> candidateMap = submitter.getCandidateJobs(conn);
+ Assert.assertNotNull(candidateMap);
+ Assert.assertEquals(0, candidateMap.size());
+
+ //create an index with ASYNC that will need building via MapReduce
+ createTestTable(getUrl(), asyncIndexDDL);
+ TestUtil.assertIndexState(conn, asyncIndexName, PIndexState.BUILDING, 0L);
+
+ //now force a rebuild on the needsRebuildIndex
+ stmt = conn.prepareStatement(String.format(REQUEST_INDEX_REBUILD_SQL, needsRebuildIndexName, tableName));
+ stmt.execute();
+ conn.commit();
+ TestUtil.assertIndexState(conn, asyncIndexName, PIndexState.BUILDING, 0L);
+
+ //regenerate the candidateMap. We should get both indexes back this time.
+ candidateMap = submitter.getCandidateJobs(conn);
+ Assert.assertNotNull(candidateMap);
+ Assert.assertEquals(2, candidateMap.size());
+ boolean foundAsyncIndex = false;
+ boolean foundNeedsRebuildIndex = false;
+ for (PhoenixAsyncIndex indexInfo : candidateMap.values()){
+ if (indexInfo.getTableName().equals(asyncIndexName)){
+ foundAsyncIndex = true;
+ } else if (indexInfo.getTableName().equals(needsRebuildIndexName)){
+ foundNeedsRebuildIndex = true;
+ }
+ }
+ Assert.assertTrue("Did not return index in BUILDING created with ASYNC!", foundAsyncIndex);
+ Assert.assertTrue("Did not return index in REBUILD with an ASYNC_REBUILD_TIMESTAMP!", foundNeedsRebuildIndex);
+ } catch(Exception e) {
+ Assert.fail(e.getMessage());
+ } finally {
+ if (stmt != null) {
+ stmt.close();
+ }
+ if (conn != null) {
+ conn.close();
+ }
+ }
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9706bb2/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
index 3e20bd2..31e657a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/automation/PhoenixMRJobSubmitter.java
@@ -53,6 +53,7 @@ import org.apache.phoenix.schema.PIndexState;
import org.apache.phoenix.schema.PTable.IndexType;
import org.apache.phoenix.schema.PTableType;
import org.apache.phoenix.schema.types.PDate;
+import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.util.PhoenixMRJobUtil;
import org.apache.phoenix.util.PhoenixMRJobUtil.MR_SCHEDULER_TYPE;
import org.apache.phoenix.util.UpgradeUtil;
@@ -97,14 +98,17 @@ public class PhoenixMRJobSubmitter {
+ PhoenixDatabaseMetaData.DATA_TABLE_NAME + ", "
+ PhoenixDatabaseMetaData.TABLE_SCHEM + ", "
+ PhoenixDatabaseMetaData.TABLE_NAME + ", "
- + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE
+ + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE + ", "
+ + PhoenixDatabaseMetaData.ASYNC_REBUILD_TIMESTAMP
+ " FROM "
+ PhoenixDatabaseMetaData.SYSTEM_CATALOG_SCHEMA + ".\"" + PhoenixDatabaseMetaData.SYSTEM_CATALOG_TABLE + "\""
- + " (" + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE + " " + PDate.INSTANCE.getSqlTypeName() + ") "
+ + " (" + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE + " " + PDate.INSTANCE.getSqlTypeName() + ", "
+ + PhoenixDatabaseMetaData.ASYNC_REBUILD_TIMESTAMP + " " + PLong.INSTANCE.getSqlTypeName() + ") "
+ " WHERE "
+ PhoenixDatabaseMetaData.COLUMN_NAME + " IS NULL and "
+ PhoenixDatabaseMetaData.COLUMN_FAMILY + " IS NULL and "
- + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE + " IS NOT NULL and "
+ + "(" + PhoenixDatabaseMetaData.ASYNC_CREATED_DATE + " IS NOT NULL OR "
+ + PhoenixDatabaseMetaData.ASYNC_REBUILD_TIMESTAMP + " IS NOT NULL ) and "
+ PhoenixDatabaseMetaData.TABLE_TYPE + " = '" + PTableType.INDEX.getSerializedValue() + "' and "
+ PhoenixDatabaseMetaData.INDEX_STATE + " = '" + PIndexState.BUILDING.getSerializedValue() + "'";
@@ -202,9 +206,13 @@ public class PhoenixMRJobSubmitter {
}
public Map<String, PhoenixAsyncIndex> getCandidateJobs() throws SQLException {
+ Connection con = DriverManager.getConnection("jdbc:phoenix:" + zkQuorum);
+ return getCandidateJobs(con);
+ }
+
+ public Map<String, PhoenixAsyncIndex> getCandidateJobs(Connection con) throws SQLException {
Properties props = new Properties();
UpgradeUtil.doNotUpgradeOnFirstConnection(props);
- Connection con = DriverManager.getConnection("jdbc:phoenix:" + zkQuorum);
Statement s = con.createStatement();
ResultSet rs = s.executeQuery(CANDIDATE_INDEX_INFO_QUERY);
Map<String, PhoenixAsyncIndex> candidateIndexes = new HashMap<String, PhoenixAsyncIndex>();
http://git-wip-us.apache.org/repos/asf/phoenix/blob/a9706bb2/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 21391f3..765cedd 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -363,7 +363,7 @@ public class MetaDataClient {
TABLE_SEQ_NUM + "," +
COLUMN_COUNT +
") VALUES (?, ?, ?, ?, ?, ?)";
- private static final String UPDATE_INDEX_STATE =
+ public static final String UPDATE_INDEX_STATE =
"UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"( " +
TENANT_ID + "," +
TABLE_SCHEM + "," +