You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ch...@apache.org on 2019/08/27 00:37:56 UTC
[phoenix] branch 4.x-HBase-1.3 updated: PHOENIX-4743: ALTER TABLE
ADD COLUMN for global index should not modify HBase metadata if failed
This is an automated email from the ASF dual-hosted git repository.
chinmayskulkarni pushed a commit to branch 4.x-HBase-1.3
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x-HBase-1.3 by this push:
new 9298bbb PHOENIX-4743: ALTER TABLE ADD COLUMN for global index should not modify HBase metadata if failed
9298bbb is described below
commit 9298bbbb8fe20d8aedf031a0ed6219265d737afc
Author: Sandeep Pal <sa...@salesforce.com>
AuthorDate: Mon Aug 26 14:54:33 2019 -0700
PHOENIX-4743: ALTER TABLE ADD COLUMN for global index should not modify HBase metadata if failed
Signed-off-by: Chinmay Kulkarni <ch...@gmail.com>
---
.../org/apache/phoenix/end2end/AlterTableIT.java | 30 ++++++++++++++++++++++
.../phoenix/query/ConnectionQueryServicesImpl.java | 9 ++++---
2 files changed, 36 insertions(+), 3 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 163be71..ef08fea 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
@@ -851,6 +851,36 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
conn1.close();
}
+ @Test
+ public void testAlterTableOnGlobalIndex() throws Exception {
+ try (Connection conn = DriverManager.getConnection(getUrl());
+ HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+ Statement stmt = conn.createStatement()) {
+ conn.setAutoCommit(false);
+ String tableName = generateUniqueName();
+ String globalIndexTableName = generateUniqueName();
+
+ stmt.execute("CREATE TABLE " + tableName +
+ " (ID INTEGER PRIMARY KEY, COL1 VARCHAR(10), COL2 BOOLEAN)");
+
+ stmt.execute("CREATE INDEX " + globalIndexTableName + " on " + tableName + " (COL2)");
+ HTableDescriptor originalDesc = admin.getTableDescriptor(Bytes.toBytes(globalIndexTableName));
+
+ try {
+ stmt.execute("ALTER TABLE " + globalIndexTableName + " ADD CF1.AGE INTEGER ");
+ conn.commit();
+ fail("The alter table did not fail as expected");
+ } catch (SQLException e) {
+ assertEquals(e.getErrorCode(), SQLExceptionCode.CANNOT_MUTATE_TABLE.getErrorCode());
+ }
+
+ HTableDescriptor finalDesc = admin.getTableDescriptor(Bytes.toBytes(globalIndexTableName));
+ assertTrue(finalDesc.equals(originalDesc));
+
+ // drop the table
+ stmt.execute("DROP TABLE " + tableName);
+ }
+ }
@Test
public void testAlterStoreNulls() throws SQLException {
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 d5a08bc..fd9092f 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
@@ -2042,9 +2042,6 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
// When adding a column to a view, base physical table should only be modified when new column families are being added.
modifyHTable = canViewsAddNewCF && !existingColumnFamiliesForBaseTable(table.getPhysicalName()).containsAll(colFamiliesForPColumnsToBeAdded);
}
- if (modifyHTable) {
- sendHBaseMetaData(tableDescriptors, pollingNeeded);
- }
// Special case for call during drop table to ensure that the empty column family exists.
// In this, case we only include the table header row, as until we add schemaBytes and tableBytes
@@ -2052,6 +2049,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
// TODO: change to if (tableMetaData.isEmpty()) once we pass through schemaBytes and tableBytes
// Also, could be used to update property values on ALTER TABLE t SET prop=xxx
if ((tableMetaData.isEmpty()) || (tableMetaData.size() == 1 && tableMetaData.get(0).isEmpty())) {
+ if (modifyHTable) {
+ sendHBaseMetaData(tableDescriptors, pollingNeeded);
+ }
return new MetaDataMutationResult(MutationCode.NO_OP, EnvironmentEdgeManager.currentTimeMillis(), table);
}
byte[][] rowKeyMetaData = new byte[3][];
@@ -2109,6 +2109,9 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
}
}
}
+ if (modifyHTable && result.getMutationCode() != MutationCode.UNALLOWED_TABLE_MUTATION) {
+ sendHBaseMetaData(tableDescriptors, pollingNeeded);
+ }
} finally {
// If we weren't successful with our metadata update
// and we've already pushed the HBase metadata changes to the server