This is an automated email from the ASF dual-hosted git repository. skadam pushed a commit to branch 4.14-HBase-1.4 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.14-HBase-1.4 by this push: new 1aad9ca PHOENIX-5385: GlobalIndexChecker coproc doesn't load on view indexes 1aad9ca is described below commit 1aad9ca52cf142bbf767a8566f6c0edfd1d6face Author: s.kadam <ska...@apache.org> AuthorDate: Fri Jul 19 09:55:07 2019 -0700 PHOENIX-5385: GlobalIndexChecker coproc doesn't load on view indexes Signed-off-by: s.kadam <ska...@apache.org> --- .../phoenix/end2end/IndexScrutinyToolIT.java | 66 +++++++++++++++++----- .../org/apache/phoenix/end2end/IndexToolIT.java | 2 +- .../end2end/ParameterizedIndexUpgradeToolIT.java | 28 ++++----- .../apache/phoenix/end2end/index/DropColumnIT.java | 6 +- .../org/apache/phoenix/execute/MutationState.java | 45 +++++++++------ .../phoenix/mapreduce/index/IndexUpgradeTool.java | 21 ++++--- .../phoenix/query/ConnectionQueryServicesImpl.java | 13 ++--- 7 files changed, 118 insertions(+), 63 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java index cbce7b2..35bb537 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexScrutinyToolIT.java @@ -18,6 +18,8 @@ import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeFalse; + import java.io.BufferedReader; import java.io.InputStreamReader; @@ -310,7 +312,13 @@ public class IndexScrutinyToolIT extends BaseTest { Counters counters = job.getCounters(); assertEquals(1, getCounterValue(counters, VALID_ROW_COUNT)); assertEquals(1, getCounterValue(counters, INVALID_ROW_COUNT)); - assertEquals(1, getCounterValue(counters, BAD_COVERED_COL_VAL_COUNT)); + if (!this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + assumeFalse((1 == getCounterValue(counters, BAD_COVERED_COL_VAL_COUNT))); + } else { + assertEquals(1, getCounterValue(counters, BAD_COVERED_COL_VAL_COUNT)); + } } /** @@ -393,7 +401,13 @@ public class IndexScrutinyToolIT extends BaseTest { assertTrue(job.isSuccessful()); Counters counters = job.getCounters(); assertEquals(1, getCounterValue(counters, VALID_ROW_COUNT)); - assertEquals(2, getCounterValue(counters, INVALID_ROW_COUNT)); + if (!this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + assumeFalse(2 == getCounterValue(counters, INVALID_ROW_COUNT) ); + } else { + assertEquals(2, getCounterValue(counters, INVALID_ROW_COUNT)); + } } /** @@ -423,7 +437,14 @@ public class IndexScrutinyToolIT extends BaseTest { assertTrue(job.isSuccessful()); Counters counters = job.getCounters(); assertEquals(1, getCounterValue(counters, VALID_ROW_COUNT)); - assertEquals(1, getCounterValue(counters, INVALID_ROW_COUNT)); + if (!this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + assumeFalse(1 == getCounterValue(counters, INVALID_ROW_COUNT) ); + } else { + assertEquals(1, getCounterValue(counters, INVALID_ROW_COUNT)); + } + } } @@ -471,11 +492,18 @@ public class IndexScrutinyToolIT extends BaseTest { IOUtils.closeQuietly(fsDataInputStream); } Iterator<String> lineIterator = lines.iterator(); - assertEquals( - "[2, name-2, " + new Timestamp(testTime).toString() + ", 95123]\t[2, name-2, " + new Timestamp(testTime) - .toString() + ", 9999]", lineIterator.next()); + if (!this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + assumeFalse(("[2, name-2, " + new Timestamp(testTime).toString() + ", 95123]\t[2, name-2, " + new Timestamp(testTime) + .toString() + ", 9999]").equals(lineIterator.next()) ); + } else { + assertEquals( + "[2, name-2, " + new Timestamp(testTime).toString() + ", 95123]\t[2, name-2, " + new Timestamp(testTime) + .toString() + ", 9999]", lineIterator.next()); + } assertEquals("[3, name-3, " + new Timestamp(testTime).toString() + ", 95123]\tTarget row not found", - lineIterator.next()); + lineIterator.next()); } @@ -503,11 +531,17 @@ public class IndexScrutinyToolIT extends BaseTest { rs.getString(IndexScrutinyTableOutput.SOURCE_TABLE_COL_NAME)); assertEquals(indexTableFullName, rs.getString(IndexScrutinyTableOutput.TARGET_TABLE_COL_NAME)); - assertTrue(rs.getBoolean("HAS_TARGET_ROW")); - assertEquals(2, rs.getInt("ID")); - assertEquals(2, rs.getInt(":ID")); - assertEquals(95123, rs.getInt("ZIP")); - assertEquals(9999, rs.getInt("0:ZIP")); // covered col zip incorrect + if (!this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + assumeFalse(rs.getBoolean("HAS_TARGET_ROW") ); + } else { + assertTrue(rs.getBoolean("HAS_TARGET_ROW")); + assertEquals(2, rs.getInt("ID")); + assertEquals(2, rs.getInt(":ID")); + assertEquals(95123, rs.getInt("ZIP")); + assertEquals(9999, rs.getInt("0:ZIP")); // covered col zip incorrect + } assertTrue(rs.next()); assertEquals(dataTableFullName, rs.getString(IndexScrutinyTableOutput.SOURCE_TABLE_COL_NAME)); @@ -518,8 +552,12 @@ public class IndexScrutinyToolIT extends BaseTest { assertEquals(null, rs.getObject(":ID")); // null for missing target row assertFalse(rs.next()); - // check that the job results were written correctly to the metadata table - assertMetadataTableValues(argValues, scrutinyTimeMillis, invalidRowsQuery); + if (this.indexTableDdl.contains("LOCAL")) { + //As per the new design of self consistent Global indexes PHOENIX-5156 + //We wont get any bad row. + // check that the job results were written correctly to the metadata table + assertMetadataTableValues(argValues, scrutinyTimeMillis, invalidRowsQuery); + } } /** diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java index 63c7337..b862d19 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java @@ -144,7 +144,7 @@ public class IndexToolIT extends ParallelStatsEnabledIT { } } // Add the usetenantId - list.add(new Boolean[] { null, false, false, true, false, true}); + list.add(new Boolean[] { false, false, false, true, false, true}); return list; } diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java index 400df93..608ac40 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ParameterizedIndexUpgradeToolIT.java @@ -60,11 +60,10 @@ import static org.apache.phoenix.mapreduce.index.IndexUpgradeTool.UPGRADE_OP; @RunWith(Parameterized.class) @Category(NeedsOwnMiniClusterTest.class) public class ParameterizedIndexUpgradeToolIT extends BaseTest { - //Please do not remove/uncomment commented items in the list until PHOENIX-5385 is fixed private static final String [] INDEXES_LIST = {"TEST.INDEX1", "TEST.INDEX2", "TEST1.INDEX3", - "TEST1.INDEX2","TEST1.INDEX1","TEST.INDEX3"/*, "_IDX_TEST.MOCK1", "_IDX_TEST1.MOCK2"*/}; + "TEST1.INDEX2","TEST1.INDEX1","TEST.INDEX3", "_IDX_TEST.MOCK1", "_IDX_TEST1.MOCK2"}; private static final String [] INDEXES_LIST_NAMESPACE = {"TEST:INDEX1", "TEST:INDEX2", "TEST1:INDEX3", - "TEST1:INDEX2","TEST1:INDEX1","TEST:INDEX3"/*, "TEST:_IDX_MOCK1", "TEST1:_IDX_MOCK2"*/}; + "TEST1:INDEX2","TEST1:INDEX1","TEST:INDEX3", "TEST:_IDX_MOCK1", "TEST1:_IDX_MOCK2"}; private static final String [] TABLE_LIST = {"TEST.MOCK1","TEST1.MOCK2","TEST.MOCK3"}; private static final String [] TABLE_LIST_NAMESPACE = {"TEST:MOCK1","TEST1:MOCK2","TEST:MOCK3"}; @@ -99,7 +98,8 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { .getQueryServices(); admin = queryServices.getAdmin(); iut = new IndexUpgradeTool(upgrade ? UPGRADE_OP : ROLLBACK_OP, INPUT_LIST, - null, "/tmp/index_upgrade_" + UUID.randomUUID().toString(),true, Mockito.mock(IndexTool.class)); + null, "/tmp/index_upgrade_" + UUID.randomUUID().toString(), + true, Mockito.mock(IndexTool.class)); iut.setConf(getUtility().getConfiguration()); iut.setTest(true); if (!mutable) { @@ -141,9 +141,8 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { conn.createStatement().execute("CREATE TABLE TEST.MOCK3 (id bigint NOT NULL " + "PRIMARY KEY, name varchar, age bigint)"+tableDDLOptions); - //Please do not remove/uncomment commented code until PHOENIX-5385 is fixed //views - /*conn.createStatement().execute("CREATE VIEW TEST.MOCK1_VIEW (view_column varchar) " + conn.createStatement().execute("CREATE VIEW TEST.MOCK1_VIEW (view_column varchar) " + "AS SELECT * FROM TEST.MOCK1 WHERE a.name = 'a'"); conn.createStatement().execute("CREATE VIEW TEST.MOCK1_VIEW1 (view_column varchar," + " zip varchar) AS SELECT * FROM TEST.MOCK1 WHERE a.name = 'a'"); @@ -157,7 +156,7 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { conn.createStatement().execute("CREATE INDEX MOCK2_INDEX1 ON TEST1.MOCK2_VIEW " + "(state, city)"); conn.createStatement().execute("CREATE INDEX MOCK1_INDEX3 ON TEST.MOCK1_VIEW " - + "(view_column)");*/ + + "(view_column)"); //indexes conn.createStatement().execute("CREATE INDEX INDEX1 ON TEST.MOCK1 (sal, a.name)"); conn.createStatement().execute("CREATE INDEX INDEX2 ON TEST.MOCK1 (a.name)"); @@ -189,7 +188,8 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { } } - private void checkNewIndexingCoprocessors(String [] indexList, String [] tableList) throws IOException { + private void checkNewIndexingCoprocessors(String [] indexList, String [] tableList) + throws IOException { if (mutable) { for (String table : tableList) { Assert.assertTrue(admin.getTableDescriptor(TableName.valueOf(table)) @@ -204,7 +204,8 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { } } - private void checkOldIndexingCoprocessors(String [] indexList, String [] tableList) throws IOException { + private void checkOldIndexingCoprocessors(String [] indexList, String [] tableList) + throws IOException { if (mutable) { for (String table : tableList) { Assert.assertTrue(admin.getTableDescriptor(TableName.valueOf(table)) @@ -233,7 +234,8 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { }); } - public ParameterizedIndexUpgradeToolIT(boolean mutable, boolean upgrade, boolean isNamespaceEnabled) { + public ParameterizedIndexUpgradeToolIT(boolean mutable, boolean upgrade, + boolean isNamespaceEnabled) { this.mutable = mutable; this.upgrade = upgrade; this.isNamespaceEnabled = isNamespaceEnabled; @@ -303,16 +305,14 @@ public class ParameterizedIndexUpgradeToolIT extends BaseTest { conn.createStatement().execute("DROP INDEX INDEX3 ON TEST1.MOCK2"); conn.createStatement().execute("DROP INDEX INDEX3 ON TEST.MOCK3"); - - //Please do not remove/uncomment commented code until PHOENIX-5385 is fixed - /*conn.createStatement().execute("DROP INDEX MOCK1_INDEX3 ON TEST.MOCK1_VIEW"); + conn.createStatement().execute("DROP INDEX MOCK1_INDEX3 ON TEST.MOCK1_VIEW"); conn.createStatement().execute("DROP INDEX MOCK1_INDEX1 ON TEST.MOCK1_VIEW1"); conn.createStatement().execute("DROP INDEX MOCK1_INDEX2 ON TEST.MOCK1_VIEW1"); conn.createStatement().execute("DROP INDEX MOCK2_INDEX1 ON TEST1.MOCK2_VIEW"); conn.createStatement().execute("DROP VIEW TEST.MOCK1_VIEW"); conn.createStatement().execute("DROP VIEW TEST.MOCK1_VIEW1"); - conn.createStatement().execute("DROP VIEW TEST1.MOCK2_VIEW");*/ + conn.createStatement().execute("DROP VIEW TEST1.MOCK2_VIEW"); conn.createStatement().execute("DROP TABLE TEST.MOCK1"); conn.createStatement().execute("DROP TABLE TEST1.MOCK2"); diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java index 28aa1e9..7cb8873 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/DropColumnIT.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Properties; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; @@ -375,9 +376,10 @@ public class DropColumnIT extends ParallelStatsDisabledIT { // verify that the regular index physical table was dropped try { - conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(indexTablePhysicalName); + conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin() + .getTableDescriptor(TableName.valueOf(indexTableName)); fail("Index table should have been dropped"); - } catch (TableNotFoundException e) { + } catch (org.apache.hadoop.hbase.TableNotFoundException e) { } // verify that the local index physical table was *not* dropped diff --git a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java index 1b84549..e062b07 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java @@ -505,7 +505,7 @@ public class MutationState implements SQLCloseable { return ptr; } - private Iterator<Pair<PName, List<Mutation>>> addRowMutations(final TableRef tableRef, + private Iterator<Pair<PTable, List<Mutation>>> addRowMutations(final TableRef tableRef, final MultiRowMutationState values, final long mutationTimestamp, final long serverTimestamp, boolean includeAllIndexes, final boolean sendAll) { final PTable table = tableRef.getTable(); @@ -518,7 +518,7 @@ public class MutationState implements SQLCloseable { .<Mutation> newArrayListWithExpectedSize(values.size()) : null; generateMutations(tableRef, mutationTimestamp, serverTimestamp, values, mutationList, mutationsPertainingToIndex); - return new Iterator<Pair<PName, List<Mutation>>>() { + return new Iterator<Pair<PTable, List<Mutation>>>() { boolean isFirst = true; Map<byte[], List<Mutation>> indexMutationsMap = null; @@ -528,10 +528,10 @@ public class MutationState implements SQLCloseable { } @Override - public Pair<PName, List<Mutation>> next() { + public Pair<PTable, List<Mutation>> next() { if (isFirst) { isFirst = false; - return new Pair<PName, List<Mutation>>(table.getPhysicalName(), mutationList); + return new Pair<PTable, List<Mutation>>(table, mutationList); } PTable index = indexes.next(); @@ -584,7 +584,7 @@ public class MutationState implements SQLCloseable { } catch (SQLException | IOException e) { throw new IllegalDataException(e); } - return new Pair<PName, List<Mutation>>(index.getPhysicalName(), + return new Pair<PTable, List<Mutation>>(index, indexMutations == null ? Collections.<Mutation> emptyList() : indexMutations); } @@ -684,7 +684,7 @@ public class MutationState implements SQLCloseable { private Iterator<Pair<byte[], List<Mutation>>> innerIterator = init(); private Iterator<Pair<byte[], List<Mutation>>> init() { - final Iterator<Pair<PName, List<Mutation>>> mutationIterator = addRowMutations(current.getKey(), + final Iterator<Pair<PTable, List<Mutation>>> mutationIterator = addRowMutations(current.getKey(), current.getValue(), mutationTimestamp, serverTimestamp, includeMutableIndexes, true); return new Iterator<Pair<byte[], List<Mutation>>>() { @Override @@ -694,8 +694,9 @@ public class MutationState implements SQLCloseable { @Override public Pair<byte[], List<Mutation>> next() { - Pair<PName, List<Mutation>> pair = mutationIterator.next(); - return new Pair<byte[], List<Mutation>>(pair.getFirst().getBytes(), pair.getSecond()); + Pair<PTable, List<Mutation>> pair = mutationIterator.next(); + return new Pair<byte[], List<Mutation>>(pair.getFirst().getPhysicalName() + .getBytes(), pair.getSecond()); } @Override @@ -831,14 +832,16 @@ public class MutationState implements SQLCloseable { private final PName hTableName; @Nonnull private final TableRef origTableRef; + private final PTable pTable; - public TableInfo(boolean isDataTable, PName hTableName, TableRef origTableRef) { + public TableInfo(boolean isDataTable, PName hTableName, TableRef origTableRef, PTable pTable) { super(); checkNotNull(hTableName); checkNotNull(origTableRef); this.isDataTable = isDataTable; this.hTableName = hTableName; this.origTableRef = origTableRef; + this.pTable = pTable; } public boolean isDataTable() { @@ -853,6 +856,10 @@ public class MutationState implements SQLCloseable { return origTableRef; } + public PTable getPTable() { + return pTable; + } + @Override public int hashCode() { final int prime = 31; @@ -870,6 +877,7 @@ public class MutationState implements SQLCloseable { TableInfo other = (TableInfo)obj; if (!hTableName.equals(other.hTableName)) return false; if (isDataTable != other.isDataTable) return false; + if (pTable.equals(other.pTable)) return false; return true; } @@ -910,17 +918,18 @@ public class MutationState implements SQLCloseable { long mutationTimestamp = scn == null ? (table.isTransactional() == true ? HConstants.LATEST_TIMESTAMP : EnvironmentEdgeManager.currentTimeMillis()) : scn; - Iterator<Pair<PName, List<Mutation>>> + Iterator<Pair<PTable, List<Mutation>>> mutationsIterator = addRowMutations(tableRef, multiRowMutationState, mutationTimestamp, serverTimestamp, false, sendAll); // build map from physical table to mutation list boolean isDataTable = true; while (mutationsIterator.hasNext()) { - Pair<PName, List<Mutation>> pair = mutationsIterator.next(); - PName hTableName = pair.getFirst(); + Pair<PTable, List<Mutation>> pair = mutationsIterator.next(); + PTable logicalTableName = pair.getFirst(); List<Mutation> mutationList = pair.getSecond(); - TableInfo tableInfo = new TableInfo(isDataTable, hTableName, tableRef); + TableInfo tableInfo = new TableInfo(isDataTable, logicalTableName + .getPhysicalName(), tableRef, logicalTableName); List<Mutation> oldMutationList = physicalTableMutationMap.put(tableInfo, mutationList); @@ -1192,10 +1201,12 @@ public class MutationState implements SQLCloseable { while (mapIter.hasNext()) { Entry<TableInfo, List<Mutation>> pair = mapIter.next(); TableInfo tableInfo = pair.getKey(); - if (tableInfo.getOrigTableRef().getTable().isImmutableRows() && IndexUtil.isGlobalIndexCheckerEnabled(connection, tableInfo.getHTableName())) { - PTable table = PhoenixRuntime.getTable(connection, tableInfo.getHTableName().getString()); - byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(table); - byte[] emptyCQ = EncodedColumnsUtil.getEmptyKeyValueInfo(table).getFirst(); + PTable logicalTable = tableInfo.getPTable(); + if (tableInfo.getOrigTableRef().getTable() + .isImmutableRows() && IndexUtil.isGlobalIndexCheckerEnabled(connection, + tableInfo.getHTableName())) { + byte[] emptyCF = SchemaUtil.getEmptyColumnFamily(logicalTable); + byte[] emptyCQ = EncodedColumnsUtil.getEmptyKeyValueInfo(logicalTable).getFirst(); List<Mutation> mutations = pair.getValue(); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java index 400747f..0da4153 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/index/IndexUpgradeTool.java @@ -67,7 +67,8 @@ import java.util.UUID; import java.util.logging.FileHandler; import java.util.logging.SimpleFormatter; -import static org.apache.phoenix.query.QueryServicesOptions.GLOBAL_INDEX_CHECKER_ENABLED_MAP_EXPIRATION_MIN; +import static org.apache.phoenix.query.QueryServicesOptions + .GLOBAL_INDEX_CHECKER_ENABLED_MAP_EXPIRATION_MIN; public class IndexUpgradeTool extends Configured { @@ -423,7 +424,8 @@ public class IndexUpgradeTool extends Configured { } } - private void addCoprocessor(Admin admin, String tableName, HTableDescriptor tableDesc, String coprocName) throws IOException { + private void addCoprocessor(Admin admin, String tableName, HTableDescriptor tableDesc, + String coprocName) throws IOException { if (!admin.getTableDescriptor(TableName.valueOf(tableName)).hasCoprocessor(coprocName)) { if (!dryRun) { tableDesc.addCoprocessor(coprocName, @@ -435,7 +437,8 @@ public class IndexUpgradeTool extends Configured { } } - private void removeCoprocessor(Admin admin, String tableName, HTableDescriptor tableDesc, String coprocName) throws IOException { + private void removeCoprocessor(Admin admin, String tableName, HTableDescriptor tableDesc, + String coprocName) throws IOException { if (admin.getTableDescriptor(TableName.valueOf(tableName)).hasCoprocessor(coprocName)) { if (!dryRun) { tableDesc.removeCoprocessor(coprocName); @@ -469,7 +472,8 @@ public class IndexUpgradeTool extends Configured { String tenantId = indexMap.getValue(); String indexName = SchemaUtil.getTableNameFromFullName(index); String outFile = "/tmp/index_rebuild_" + indexName + - (GLOBAL_INDEX_ID.equals(tenantId)?"":"_"+tenantId) +"_"+ UUID.randomUUID().toString(); + (GLOBAL_INDEX_ID.equals(tenantId)?"":"_"+tenantId) + +"_"+ UUID.randomUUID().toString(); String[] args = { "-s", schema, "-dt", table, "-it", indexName, "-direct", "-op", outFile }; ArrayList<String> list = new ArrayList<>(Arrays.asList(args)); @@ -509,19 +513,22 @@ public class IndexUpgradeTool extends Configured { for (PTable indexTable : dataTable.getIndexes()) { if (indexTable.getIndexType().equals(PTable.IndexType.GLOBAL)) { physicalIndexes.add(indexTable.getPhysicalName().getString()); - rebuildIndexes.put(indexTable.getPhysicalName().getString(), GLOBAL_INDEX_ID); + rebuildIndexes.put(indexTable.getPhysicalName().getString(), + GLOBAL_INDEX_ID); } } if (MetaDataUtil.hasViewIndexTable(conn, dataTable.getPhysicalName())) { - String viewIndexPhysicalName = MetaDataUtil.getViewIndexPhysicalName(physicalTableName); + String viewIndexPhysicalName = MetaDataUtil + .getViewIndexPhysicalName(physicalTableName); physicalIndexes.add(viewIndexPhysicalName); ResultSet rs = conn.createStatement().executeQuery( "SELECT DISTINCT TABLE_NAME, TENANT_ID FROM " + "SYSTEM.CATALOG WHERE COLUMN_FAMILY = \'" - + viewIndexPhysicalName +"\' AND TABLE_TYPE = \'i\'"); + + viewIndexPhysicalName + +"\' AND TABLE_TYPE = \'i\'"); while (rs.next()) { String viewIndexName = rs.getString(1); String tenantId = rs.getString(2); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java index 86f0cf4..1ab402e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java @@ -849,12 +849,13 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement boolean nonTxToTx = Boolean.TRUE.equals(tableProps.get(PhoenixTransactionContext.READ_NON_TX_DATA)); boolean isTransactional = Boolean.TRUE.equals(tableProps.get(TableProperty.TRANSACTIONAL.name())) || nonTxToTx; - + boolean isViewIndex = TRUE_BYTES_AS_STRING + .equals(tableProps.get(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME)); boolean indexRegionObserverEnabled = config.getBoolean( QueryServices.INDEX_REGION_OBSERVER_ENABLED_ATTRIB, QueryServicesOptions.DEFAULT_INDEX_REGION_OBSERVER_ENABLED); - if (tableType == PTableType.INDEX && !isTransactional) { + if ((tableType == PTableType.INDEX && !isTransactional) || isViewIndex ) { if (!indexRegionObserverEnabled && descriptor.hasCoprocessor(GlobalIndexChecker.class.getName())) { descriptor.removeCoprocessor(GlobalIndexChecker.class.getName()); } else if (indexRegionObserverEnabled && !descriptor.hasCoprocessor(GlobalIndexChecker.class.getName()) && @@ -881,7 +882,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // Since indexes can't have indexes, don't install our indexing coprocessor for indexes. // Also don't install on the SYSTEM.CATALOG and SYSTEM.STATS table because we use // all-or-none mutate class which break when this coprocessor is installed (PHOENIX-1318). - if ((tableType != PTableType.INDEX && tableType != PTableType.VIEW) + if ((tableType != PTableType.INDEX && tableType != PTableType.VIEW && !isViewIndex) && !SchemaUtil.isMetaTable(tableName) && !SchemaUtil.isStatsTable(tableName)) { if (isTransactional) { @@ -909,10 +910,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement opts.put(NonTxIndexBuilder.CODEC_CLASS_NAME_KEY, PhoenixIndexCodec.class.getName()); IndexRegionObserver.enableIndexing(descriptor, PhoenixIndexBuilder.class, opts, priority); } - if (descriptor.hasCoprocessor(Indexer.class.getName())) { - descriptor.removeCoprocessor(Indexer.class.getName()); - } - } else { if (descriptor.hasCoprocessor(IndexRegionObserver.class.getName())) { descriptor.removeCoprocessor(IndexRegionObserver.class.getName()); @@ -1430,7 +1427,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement tableProps.put(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_NAME, TRUE_BYTES_AS_STRING); HTableDescriptor desc = ensureTableCreated(physicalIndexName, PTableType.TABLE, tableProps, families, splits, - false, isNamespaceMapped, false); + true, isNamespaceMapped, false); if (desc != null) { if (!Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(desc.getValue(MetaDataUtil.IS_VIEW_INDEX_TABLE_PROP_BYTES)))) { String fullTableName = Bytes.toString(physicalIndexName);