Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.1 8a0f320d9 -> 275f716c2
PHOENIX-3002 Upgrading to 4.8 doesn't recreate local indexes-addendum2(Rajeshbabu) Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/275f716c Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/275f716c Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/275f716c Branch: refs/heads/4.x-HBase-1.1 Commit: 275f716c25c7e7ea2ecec054cf0f17d586ac4683 Parents: 8a0f320 Author: Rajeshbabu Chintaguntla <[email protected]> Authored: Mon Jul 11 09:41:42 2016 +0530 Committer: Rajeshbabu Chintaguntla <[email protected]> Committed: Mon Jul 11 09:41:42 2016 +0530 ---------------------------------------------------------------------- .../end2end/QueryDatabaseMetaDataIT.java | 14 +++++++++++++ .../query/ConnectionQueryServicesImpl.java | 2 +- .../org/apache/phoenix/util/UpgradeUtil.java | 22 ++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/275f716c/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java index 4012d0c..12066e6 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryDatabaseMetaDataIT.java @@ -572,6 +572,20 @@ public class QueryDatabaseMetaDataIT extends BaseClientManagedTimeIT { assertFalse(rs.next()); + conn.createStatement().execute("CREATE TABLE SALTEDTABLE123 (k INTEGER PRIMARY KEY, v VARCHAR) SALT_BUCKETS=3"); + conn.close(); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10)); + conn = DriverManager.getConnection(getUrl(), props); + dbmd = conn.getMetaData(); + rs = dbmd.getPrimaryKeys(null, "", "SALTEDTABLE123"); + assertTrue(rs.next()); + assertEquals(null, rs.getString("TABLE_SCHEM")); + assertEquals("SALTEDTABLE123", rs.getString("TABLE_NAME")); + assertEquals(null, rs.getString("TABLE_CAT")); + assertEquals("K", rs.getString("COLUMN_NAME")); + assertEquals(1, rs.getInt("KEY_SEQ")); + assertEquals(null, rs.getString("PK_NAME")); + assertFalse(rs.next()); } @Test http://git-wip-us.apache.org/repos/asf/phoenix/blob/275f716c/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- 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 99666dd..bdb5960 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 @@ -2479,11 +2479,11 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0, PhoenixDatabaseMetaData.APPEND_ONLY_SCHEMA + " " + PBoolean.INSTANCE.getSqlTypeName()); + metaConnection = UpgradeUtil.disableViewIndexes(metaConnection); if(getProps().getBoolean(QueryServices.LOCAL_INDEX_CLIENT_UPGRADE_ATTRIB, QueryServicesOptions.DEFAULT_LOCAL_INDEX_CLIENT_UPGRADE)) { metaConnection = UpgradeUtil.upgradeLocalIndexes(metaConnection); } - metaConnection = UpgradeUtil.disableViewIndexes(metaConnection); ConnectionQueryServicesImpl.this.removeTable(null, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME, null, MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP_4_8_0); http://git-wip-us.apache.org/repos/asf/phoenix/blob/275f716c/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java index 9046287..7ed9f70 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/util/UpgradeUtil.java @@ -329,10 +329,10 @@ public class UpgradeUtil { globalConnection = new PhoenixConnection(metaConnection, metaConnection.getQueryServices(), props); SQLException sqlEx = null; try (HBaseAdmin admin = globalConnection.getQueryServices().getAdmin()) { - ResultSet rs = globalConnection.createStatement().executeQuery("SELECT TABLE_SCHEM, TABLE_NAME, DATA_TABLE_NAME, TENANT_ID FROM SYSTEM.CATALOG " + ResultSet rs = globalConnection.createStatement().executeQuery("SELECT TABLE_SCHEM, TABLE_NAME, DATA_TABLE_NAME, TENANT_ID, MULTI_TENANT, SALT_BUCKETS FROM SYSTEM.CATALOG " + " WHERE COLUMN_NAME IS NULL" + " AND COLUMN_FAMILY IS NULL" - + " AND INDEX_TYPE=2"); + + " AND INDEX_TYPE=" + IndexType.LOCAL.getSerializedValue()); boolean droppedLocalIndexes = false; while (rs.next()) { if(!droppedLocalIndexes) { @@ -373,12 +373,14 @@ public class UpgradeUtil { String indexTableName = rs.getString(2); String dataTableName = rs.getString(3); String tenantId = rs.getString(4); + boolean multiTenantTable = rs.getBoolean(5); + int numColumnsToSkip = 1 + (multiTenantTable ? 1 : 0); String getColumns = "SELECT COLUMN_NAME, COLUMN_FAMILY FROM SYSTEM.CATALOG WHERE TABLE_SCHEM " + (schemaName == null ? "IS NULL " : "='" + schemaName+ "'") + " AND TENANT_ID "+(tenantId == null ? "IS NULL " : "='" + tenantId + "'") + " and TABLE_NAME='" + indexTableName - + "' AND COLUMN_NAME IS NOT NULL ORDER BY KEY_SEQ"; + + "' AND COLUMN_NAME IS NOT NULL AND KEY_SEQ > "+ numColumnsToSkip +" ORDER BY KEY_SEQ"; ResultSet getColumnsRs = globalConnection.createStatement().executeQuery(getColumns); List<String> indexedColumns = new ArrayList<String>(1); List<String> coveredColumns = new ArrayList<String>(1); @@ -386,9 +388,6 @@ public class UpgradeUtil { while (getColumnsRs.next()) { String column = getColumnsRs.getString(1); String columnName = IndexUtil.getDataColumnName(column); - if (SchemaUtil.normalizeIdentifier(columnName).equals(MetaDataUtil.getViewIndexIdColumnName())) { - continue; - } String columnFamily = IndexUtil.getDataColumnFamilyName(column); if (getColumnsRs.getString(2) == null) { if (columnFamily != null && !columnFamily.isEmpty()) { @@ -493,7 +492,7 @@ public class UpgradeUtil { try (HBaseAdmin admin = globalConnection.getQueryServices().getAdmin()) { String fetchViewIndexes = "SELECT " + TENANT_ID + ", " + TABLE_SCHEM + ", " + TABLE_NAME + ", " + DATA_TABLE_NAME + " FROM " + SYSTEM_CATALOG_NAME + " WHERE " + VIEW_INDEX_ID - + " IS NOT NULL AND " + INDEX_TYPE + "<>" + IndexType.LOCAL.getSerializedValue(); + + " IS NOT NULL"; String disableIndexDDL = "ALTER INDEX %s ON %s DISABLE"; try (ResultSet rs = globalConnection.createStatement().executeQuery(fetchViewIndexes)) { while (rs.next()) { @@ -502,6 +501,7 @@ public class UpgradeUtil { String indexName = rs.getString(3); String viewName = rs.getString(4); String fullIndexName = SchemaUtil.getTableName(indexSchema, indexName); + String fullViewName = SchemaUtil.getTableName(indexSchema, viewName); PTable viewPTable = null; // Disable the view index and truncate the underlying hbase table. // Users would need to rebuild the view indexes. @@ -510,8 +510,8 @@ public class UpgradeUtil { newProps.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId); PTable indexPTable = null; try (PhoenixConnection tenantConnection = new PhoenixConnection(globalConnection, globalConnection.getQueryServices(), newProps)) { - viewPTable = PhoenixRuntime.getTable(tenantConnection, viewName); - tenantConnection.createStatement().execute(String.format(disableIndexDDL, fullIndexName, viewName)); + viewPTable = PhoenixRuntime.getTable(tenantConnection, fullViewName); + tenantConnection.createStatement().execute(String.format(disableIndexDDL, indexName, fullViewName)); indexPTable = PhoenixRuntime.getTable(tenantConnection, fullIndexName); } @@ -588,8 +588,8 @@ public class UpgradeUtil { } globalConnection.commit(); } else { - viewPTable = PhoenixRuntime.getTable(globalConnection, viewName); - globalConnection.createStatement().execute(String.format(disableIndexDDL, fullIndexName, viewName)); + viewPTable = PhoenixRuntime.getTable(globalConnection, fullViewName); + globalConnection.createStatement().execute(String.format(disableIndexDDL, indexName, fullViewName)); } String indexPhysicalTableName = MetaDataUtil.getViewIndexTableName(viewPTable.getPhysicalName().getString()); if (physicalTables.add(indexPhysicalTableName)) {
