You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gj...@apache.org on 2022/06/22 19:11:11 UTC

[phoenix] branch 5.1 updated: PHOENIX-6725 : ConcurrentMutationException when adding column to table/view (#1452)

This is an automated email from the ASF dual-hosted git repository.

gjacoby pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.1 by this push:
     new 062d509f46 PHOENIX-6725 : ConcurrentMutationException when adding column to table/view (#1452)
062d509f46 is described below

commit 062d509f464d18bce5f34e46b024278595c701bd
Author: Lokesh Khurana <kh...@gmail.com>
AuthorDate: Tue Jun 21 12:14:10 2022 -0700

    PHOENIX-6725 : ConcurrentMutationException when adding column to table/view (#1452)
    
    Co-authored-by: Lokesh Khurana <lo...@salesforce.com>
---
 .../org/apache/phoenix/end2end/AlterTableIT.java   | 23 ++++++++++++++++++++++
 .../phoenix/coprocessor/MetaDataEndpointImpl.java  | 12 +++++++++++
 .../org/apache/phoenix/schema/MetaDataClient.java  |  4 ++--
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 60fa923617..88caf7b744 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -54,6 +54,7 @@ import org.apache.hadoop.hbase.client.Table;
 import org.apache.hadoop.hbase.client.TableDescriptor;
 import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.coprocessor.MetaDataEndpointImpl;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
@@ -751,6 +752,28 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
         conn1.close();
     }
 
+    @Test
+    public void testAddColumnWithRetry_PostConcurrentFailureOnFirstTime() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+                +"ID VARCHAR(15) PRIMARY KEY,\n"
+                +"COL1 BIGINT) " + tableDDLOptions;
+        Connection conn1 = DriverManager.getConnection(getUrl(), props);
+        conn1.createStatement().execute(ddl);
+        MetaDataEndpointImpl.setFailConcurrentMutateAddColumnOneTimeForTesting(true);
+        ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
+        conn1.createStatement().execute(ddl);
+        ResultSet rs = conn1.getMetaData().getColumns("","",dataTableFullName,null);
+        assertTrue(rs.next());
+        assertEquals("ID", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("COL1", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("STRING", rs.getString(4));
+        assertTrue(rs.next());
+        assertEquals("STRING_DATA_TYPES", rs.getString(4));
+    }
+
     @Test
     public void testAddMultipleColumns() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 77da73278d..8756e4ff4c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -542,6 +542,7 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
         return PNameFactory.newName(keyBuffer, keyOffset, length);
     }
 
+    private static boolean failConcurrentMutateAddColumnOneTimeForTesting = false;
     private RegionCoprocessorEnvironment env;
 
     private PhoenixMetaDataCoprocessorHost phoenixAccessCoprocessorHost;
@@ -555,6 +556,12 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
     // before 4.15, so that we can rollback the upgrade to 4.15 if required
     private boolean allowSplittableSystemCatalogRollback;
 
+    private MetricsMetadataSource metricsSource;
+
+    public static void setFailConcurrentMutateAddColumnOneTimeForTesting(boolean fail) {
+        failConcurrentMutateAddColumnOneTimeForTesting = fail;
+    }
+
     /**
      * Stores a reference to the coprocessor environment provided by the
      * {@link org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost} from the region where this
@@ -2780,6 +2787,11 @@ TABLE_FAMILY_BYTES, TABLE_SEQ_NUM_BYTES);
                 List<ImmutableBytesPtr> invalidateList = new ArrayList<ImmutableBytesPtr>();
                 invalidateList.add(cacheKey);
                 PTable table = getTableFromCache(cacheKey, clientTimeStamp, clientVersion);
+                if (failConcurrentMutateAddColumnOneTimeForTesting) {
+                    failConcurrentMutateAddColumnOneTimeForTesting = false;
+                    return new MetaDataMutationResult(MutationCode.CONCURRENT_TABLE_MUTATION,
+                            EnvironmentEdgeManager.currentTimeMillis(), table);
+                }
                 if (LOGGER.isDebugEnabled()) {
                     if (table == null) {
                         LOGGER.debug("Table " + Bytes.toStringBinary(key)
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 511f8592e9..1a0cfcdebf 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
@@ -4122,7 +4122,7 @@ public class MetaDataClient {
                 }
 
                 if (EncodedColumnsUtil.usesEncodedColumnNames(table)
-                        && stmtProperties.isEmpty()) {
+                        && stmtProperties.isEmpty() && !acquiredBaseTableMutex) {
                     // For tables that use column encoding acquire a mutex on
                     // the base table as we need to update the encoded column
                     // qualifier counter on the base table. Not applicable to
@@ -4142,7 +4142,7 @@ public class MetaDataClient {
                     // a conflicting type etc
                     boolean acquiredMutex = writeCell(null, physicalSchemaName, physicalTableName,
                         pColumn.toString());
-                    if (!acquiredMutex) {
+                    if (!acquiredMutex && !acquiredColumnMutexSet.contains(pColumn.toString())) {
                         throw new ConcurrentTableMutationException(physicalSchemaName, physicalTableName);
                     }
                     acquiredColumnMutexSet.add(pColumn.toString());