Revert "PHOENIX-4523 phoenix.schema.isNamespaceMappingEnabled problem (Karan Mehta)"
This reverts commit 4a3435a Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7296e510 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7296e510 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7296e510 Branch: refs/heads/4.x-cdh5.11.2 Commit: 7296e5109ea8f7197f2047e070cd95bf36291b98 Parents: 760d459 Author: Pedro Boado <[email protected]> Authored: Thu Jan 25 01:08:59 2018 +0000 Committer: Pedro Boado <[email protected]> Committed: Wed Jan 31 22:24:48 2018 +0000 ---------------------------------------------------------------------- .../query/ConnectionQueryServicesImpl.java | 32 +++++++++----------- .../org/apache/phoenix/util/UpgradeUtil.java | 2 -- .../query/ConnectionQueryServicesImplTest.java | 6 ++-- 3 files changed, 18 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/7296e510/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 a3a6c3a..6d06087 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 @@ -2524,15 +2524,15 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement } } - void createSysMutexTableIfNotExists(HBaseAdmin admin, ReadOnlyProps props) throws IOException, SQLException { + void createSysMutexTable(HBaseAdmin admin, ReadOnlyProps props) throws IOException, SQLException { try { - if(admin.tableExists(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME) || admin.tableExists(TableName.valueOf( - PhoenixDatabaseMetaData.SYSTEM_SCHEMA_NAME,PhoenixDatabaseMetaData.SYSTEM_MUTEX_TABLE_NAME))) { + final TableName mutexTableName = SchemaUtil.getPhysicalTableName( + PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME, props); + List<TableName> systemTables = getSystemTableNames(admin); + if (systemTables.contains(mutexTableName)) { logger.debug("System mutex table already appears to exist, not creating it"); return; } - final TableName mutexTableName = SchemaUtil.getPhysicalTableName( - PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME, props); HTableDescriptor tableDesc = new HTableDescriptor(mutexTableName); HColumnDescriptor columnDesc = new HColumnDescriptor( PhoenixDatabaseMetaData.SYSTEM_MUTEX_FAMILY_NAME_BYTES); @@ -2548,17 +2548,10 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement } } catch (TableExistsException e) { // Ignore - } catch (IOException e) { - if(!Iterables.isEmpty(Iterables.filter(Throwables.getCausalChain(e), AccessDeniedException.class)) || - !Iterables.isEmpty(Iterables.filter(Throwables.getCausalChain(e), org.apache.hadoop.hbase.TableNotFoundException.class))) { - // Ignore - } else { - throw e; - } } } - List<TableName> getSystemTableNamesInDefaultNamespace(HBaseAdmin admin) throws IOException { + List<TableName> getSystemTableNames(HBaseAdmin admin) throws IOException { return Lists.newArrayList(admin.listTableNames(QueryConstants.SYSTEM_SCHEMA_NAME + "\\..*")); } @@ -2577,7 +2570,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // Catch the IOException to log the error message and then bubble it up for the client to retry. try { - createSysMutexTableIfNotExists(hbaseAdmin, ConnectionQueryServicesImpl.this.getProps()); + createSysMutexTable(hbaseAdmin, ConnectionQueryServicesImpl.this.getProps()); } catch (IOException exception) { logger.error("Failed to created SYSMUTEX table. Upgrade or migration is not possible without it. Please retry."); throw exception; @@ -2629,7 +2622,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement !SchemaUtil.isNamespaceMappingEnabled(PTableType.SYSTEM, ConnectionQueryServicesImpl.this.getProps())) { try (HBaseAdmin admin = getAdmin()) { - createSysMutexTableIfNotExists(admin, this.getProps()); + createSysMutexTable(admin, this.getProps()); } } if (acquiredMutexLock = acquireUpgradeMutex(currentServerSideTableTimeStamp, mutexRowKey)) { @@ -3172,7 +3165,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // below. If the NS does exist and is mapped, the below check will exit gracefully. } - List<TableName> tableNames = getSystemTableNamesInDefaultNamespace(admin); + List<TableName> tableNames = getSystemTableNames(admin); // No tables exist matching "SYSTEM\..*", they are all already in "SYSTEM:.*" if (tableNames.size() == 0) { return; } // Try to move any remaining tables matching "SYSTEM\..*" into "SYSTEM:" @@ -3184,7 +3177,12 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement // If we cannot acquire lock, it means some old client is either migrating SYSCAT or trying to upgrade the // schema of SYSCAT table and hence it should not be interrupted // Create mutex if not already created - createSysMutexTableIfNotExists(admin, props); + if (!tableNames.contains(PhoenixDatabaseMetaData.SYSTEM_MUTEX_HBASE_TABLE_NAME)) { + TableName mutexName = SchemaUtil.getPhysicalTableName(PhoenixDatabaseMetaData.SYSTEM_MUTEX_NAME, props); + if (PhoenixDatabaseMetaData.SYSTEM_MUTEX_HBASE_TABLE_NAME.equals(mutexName) || !tableNames.contains(mutexName)) { + createSysMutexTable(admin, props); + } + } acquiredMutexLock = acquireUpgradeMutex(MetaDataProtocol.MIN_SYSTEM_TABLE_MIGRATION_TIMESTAMP, mutexRowKey); if(acquiredMutexLock) { logger.debug("Acquired lock in SYSMUTEX table for migrating SYSTEM tables to SYSTEM namespace"); http://git-wip-us.apache.org/repos/asf/phoenix/blob/7296e510/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 f09590d..548e306 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 @@ -1779,8 +1779,6 @@ public class UpgradeUtil { admin.deleteTable(srcTableName); logger.info(String.format("deleting snapshot %s..", snapshotName)); admin.deleteSnapshot(snapshotName); - } else { - logger.info(String.format("Destination Table %s already exists. No migration needed.", destTableName)); } } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/7296e510/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java index b5c3e4a..4708ffb 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/query/ConnectionQueryServicesImplTest.java @@ -49,10 +49,10 @@ public class ConnectionQueryServicesImplTest { when(cqs.createSchema(any(List.class), anyString())).thenCallRealMethod(); doCallRealMethod().when(cqs).ensureSystemTablesMigratedToSystemNamespace(any(ReadOnlyProps.class)); // Do nothing for this method, just check that it was invoked later - doNothing().when(cqs).createSysMutexTableIfNotExists(any(HBaseAdmin.class), any(ReadOnlyProps.class)); + doNothing().when(cqs).createSysMutexTable(any(HBaseAdmin.class), any(ReadOnlyProps.class)); // Spoof out this call so that ensureSystemTablesUpgrade() will return-fast. - when(cqs.getSystemTableNamesInDefaultNamespace(any(HBaseAdmin.class))).thenReturn(Collections.<TableName> emptyList()); + when(cqs.getSystemTableNames(any(HBaseAdmin.class))).thenReturn(Collections.<TableName> emptyList()); // Throw a special exception to check on later doThrow(PHOENIX_IO_EXCEPTION).when(cqs).ensureNamespaceCreated(anyString()); @@ -64,7 +64,7 @@ public class ConnectionQueryServicesImplTest { // Should be called after upgradeSystemTables() // Proves that execution proceeded - verify(cqs).getSystemTableNamesInDefaultNamespace(any(HBaseAdmin.class)); + verify(cqs).getSystemTableNames(any(HBaseAdmin.class)); try { // Verifies that the exception is propagated back to the caller
