PHOENIX-4875: Don't acquire a mutex while dropping a table and while creating a view
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c2afbcf0 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c2afbcf0 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c2afbcf0 Branch: refs/heads/omid2 Commit: c2afbcf03dfff5d6580c95af071530a21b8824bb Parents: c5d4759 Author: Chinmay Kulkarni <[email protected]> Authored: Tue Sep 11 21:40:45 2018 -0700 Committer: Thomas D'Silva <[email protected]> Committed: Mon Oct 1 15:50:13 2018 -0700 ---------------------------------------------------------------------- .../java/org/apache/phoenix/end2end/ViewIT.java | 21 +++------- .../apache/phoenix/schema/MetaDataClient.java | 41 -------------------- 2 files changed, 6 insertions(+), 56 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2afbcf0/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java index 5e465b4..796c3d9 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ViewIT.java @@ -1350,7 +1350,6 @@ public class ViewIT extends SplitSystemCatalogIT { try (Connection conn = DriverManager.getConnection(getUrl())) { String fullTableName = SchemaUtil.getTableName(SCHEMA1, generateUniqueName()); String fullViewName1 = SLOW_VIEWNAME_PREFIX + "_" + generateUniqueName(); - String fullViewName2 = SchemaUtil.getTableName(SCHEMA3, generateUniqueName()); latch1 = new CountDownLatch(1); latch2 = new CountDownLatch(1); String tableDdl = @@ -1375,23 +1374,15 @@ public class ViewIT extends SplitSystemCatalogIT { // wait till the thread makes the rpc to create the view latch1.await(); tableDdl = "DROP TABLE " + fullTableName; - try { - // drop table should fail as we are concurrently adding a view - conn.createStatement().execute(tableDdl); - fail("Creating a view while concurrently dropping the base table should fail"); - } catch (ConcurrentTableMutationException e) { - } + // drop table goes through first and so the view creation should fail + conn.createStatement().execute(tableDdl); latch2.countDown(); Exception e = future.get(); - assertNull(e); + assertTrue("Expected TableNotFoundException since drop table goes through first", + e instanceof TableNotFoundException && + fullTableName.equals(((TableNotFoundException) e).getTableName())); - // create another view to ensure that the cell used to prevent - // concurrent modifications was removed - String ddl = - "CREATE VIEW " + fullViewName2 + " (v2 VARCHAR) AS SELECT * FROM " - + fullTableName + " WHERE k = 6"; - conn.createStatement().execute(ddl); } } @@ -1470,7 +1461,7 @@ public class ViewIT extends SplitSystemCatalogIT { "CREATE TABLE " + fullTableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 DATE)" + tableDDLOptions; conn.createStatement().execute(tableDdl); - // create a two views + // create two views String ddl = "CREATE VIEW " + fullViewName1 + " (v2 VARCHAR) AS SELECT * FROM " + fullTableName + " WHERE k = 6"; http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2afbcf0/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 ac4cdad..3520692 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 @@ -1905,7 +1905,6 @@ public class MetaDataClient { final PTableType tableType = statement.getTableType(); boolean wasAutoCommit = connection.getAutoCommit(); connection.rollback(); - boolean acquiredMutex = false; try { connection.setAutoCommit(false); List<Mutation> tableMetaData = Lists.newArrayListWithExpectedSize(statement.getColumnDefs().size() + 3); @@ -1935,21 +1934,6 @@ public class MetaDataClient { boolean isLocalIndex = indexType == IndexType.LOCAL; QualifierEncodingScheme encodingScheme = NON_ENCODED_QUALIFIERS; ImmutableStorageScheme immutableStorageScheme = ONE_CELL_PER_COLUMN; - - if (tableType == PTableType.VIEW) { - PName physicalName = parent.getPhysicalName(); - String physicalSchemaName = - SchemaUtil.getSchemaNameFromFullName(physicalName.getString()); - String physicalTableName = - SchemaUtil.getTableNameFromFullName(physicalName.getString()); - // acquire the mutex using the global physical table name to - // prevent creating views while concurrently dropping the base - // table - acquiredMutex = writeCell(null, physicalSchemaName, physicalTableName, null); - if (!acquiredMutex) { - throw new ConcurrentTableMutationException(physicalSchemaName, physicalTableName); - } - } if (parent != null && tableType == PTableType.INDEX) { timestamp = TransactionUtil.getTableTimestamp(connection, transactionProvider != null, transactionProvider); storeNulls = parent.getStoreNulls(); @@ -2871,16 +2855,6 @@ public class MetaDataClient { } } finally { connection.setAutoCommit(wasAutoCommit); - if (acquiredMutex && tableType == PTableType.VIEW) { - PName physicalName = parent.getPhysicalName(); - String physicalSchemaName = - SchemaUtil.getSchemaNameFromFullName(physicalName.getString()); - String physicalTableName = - SchemaUtil.getTableNameFromFullName(physicalName.getString()); - // releasing mutex on the table (required to prevent creating views while concurrently - // dropping the base table) - deleteCell(null, physicalSchemaName, physicalTableName, null); - } } } @@ -2992,8 +2966,6 @@ public class MetaDataClient { boolean wasAutoCommit = connection.getAutoCommit(); PName tenantId = connection.getTenantId(); String tenantIdStr = tenantId == null ? null : tenantId.getString(); - boolean acquiredMutex = false; - String physicalTableName = SchemaUtil.getTableName(schemaName, tableName); try { byte[] key = SchemaUtil.getTableKey(tenantIdStr, schemaName, tableName); Long scn = connection.getSCN(); @@ -3007,14 +2979,6 @@ public class MetaDataClient { Delete linkDelete = new Delete(linkKey, clientTimeStamp); tableMetaData.add(linkDelete); } - if (tableType == PTableType.TABLE) { - // acquire a mutex on the table to prevent creating views while concurrently - // dropping the base table - acquiredMutex = writeCell(null, schemaName, tableName, null); - if (!acquiredMutex) { - throw new ConcurrentTableMutationException(schemaName, schemaName); - } - } MetaDataMutationResult result = connection.getQueryServices().dropTable(tableMetaData, tableType, cascade, skipAddingParentColumns); MutationCode code = result.getMutationCode(); PTable table = result.getTable(); @@ -3092,11 +3056,6 @@ public class MetaDataClient { return new MutationState(0, 0, connection); } finally { connection.setAutoCommit(wasAutoCommit); - // releasing mutex on the table (required to prevent creating views while concurrently - // dropping the base table) - if (acquiredMutex && tableType == PTableType.TABLE) { - deleteCell(null, schemaName, tableName, null); - } } }
