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 f25a45f PHOENIX-5524: Connections with SCN should fail mutations on tables with any index f25a45f is described below commit f25a45f28bdb2c1ba095d833d2681f8f625b6354 Author: Chinmay Kulkarni <chinmayskulka...@gmail.com> AuthorDate: Tue Oct 15 00:08:41 2019 -0700 PHOENIX-5524: Connections with SCN should fail mutations on tables with any index --- .../apache/phoenix/end2end/UpsertWithSCNIT.java | 55 +++++++++++++++------- .../org/apache/phoenix/compile/UpsertCompiler.java | 11 ++--- .../apache/phoenix/exception/SQLExceptionCode.java | 7 ++- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java index 40bb883..c21f84e 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertWithSCNIT.java @@ -18,14 +18,11 @@ package org.apache.phoenix.end2end; import org.apache.phoenix.exception.SQLExceptionCode; -import org.apache.phoenix.exception.SQLExceptionInfo; -import org.junit.Assert; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import java.sql.Connection; -import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -33,7 +30,6 @@ import java.sql.SQLException; import java.util.Properties; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -44,10 +40,10 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { @Rule public final ExpectedException exception = ExpectedException.none(); Properties props = null; - PreparedStatement prep = null; + private PreparedStatement prep = null; String tableName =null; - private void helpTestUpserWithSCNIT(boolean rowColumn, boolean txTable, + private void helpTestUpsertWithSCNIT(boolean rowColumn, boolean txTable, boolean mutable, boolean local, boolean global) throws SQLException { @@ -57,8 +53,8 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { + (rowColumn ? "CREATED_DATE DATE NOT NULL, ":"") + "METRIC_ID CHAR(15) NOT NULL,METRIC_VALUE VARCHAR(50) CONSTRAINT PK PRIMARY KEY(" + (rowColumn? "CREATED_DATE ROW_TIMESTAMP, ":"") + "METRIC_ID)) " - + (mutable? "IMMUTABLE_ROWS=false":"" ) - + (txTable ? "TRANSACTION_PROVIDER='TEPHRA',TRANSACTIONAL=true":""); + + "IMMUTABLE_ROWS=" + (mutable? "false" : "true" ) + + (txTable ? ", TRANSACTION_PROVIDER='TEPHRA',TRANSACTIONAL=true":""); props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); conn.createStatement().execute(createTable); @@ -81,7 +77,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { @Test // See https://issues.apache.org/jira/browse/PHOENIX-4983 public void testUpsertOnSCNSetTxnTable() throws SQLException { - helpTestUpserWithSCNIT(false, true, false, false, false); + helpTestUpsertWithSCNIT(false, true, false, false, false); exception.expect(SQLException.class); exception.expectMessage(containsString(String.valueOf( SQLExceptionCode @@ -93,7 +89,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { @Test public void testUpsertOnSCNSetMutTableWithoutIdx() throws Exception { - helpTestUpserWithSCNIT(false, false, true, false, false); + helpTestUpsertWithSCNIT(false, false, true, false, false); prep.executeUpdate(); props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(),props); @@ -107,7 +103,7 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { @Test public void testUpsertOnSCNSetTable() throws Exception { - helpTestUpserWithSCNIT(false, false, false, false, false); + helpTestUpsertWithSCNIT(false, false, false, false, false); prep.executeUpdate(); props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(),props); @@ -121,34 +117,59 @@ public class UpsertWithSCNIT extends ParallelStatsDisabledIT { @Test public void testUpsertOnSCNSetMutTableWithLocalIdx() throws Exception { - helpTestUpserWithSCNIT(false, false, true, true, false); + helpTestUpsertWithSCNIT(false, false, true, true, false); exception.expect(SQLException.class); exception.expectMessage(containsString(String.valueOf( SQLExceptionCode - .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES + .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES .getErrorCode()))); prep.executeUpdate(); } + + @Test + public void testUpsertOnSCNSetImmutableTableWithLocalIdx() throws Exception { + + helpTestUpsertWithSCNIT(false, false, false, true, false); + exception.expect(SQLException.class); + exception.expectMessage(containsString(String.valueOf( + SQLExceptionCode + .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES + .getErrorCode()))); + prep.executeUpdate(); + } + @Test public void testUpsertOnSCNSetMutTableWithGlobalIdx() throws Exception { - helpTestUpserWithSCNIT(false, false, true, false, true); + helpTestUpsertWithSCNIT(false, false, true, false, true); exception.expect(SQLException.class); exception.expectMessage(containsString(String.valueOf( SQLExceptionCode - .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES + .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES .getErrorCode()))); prep.executeUpdate(); + } + + @Test + public void testUpsertOnSCNSetImmutableTableWithGlobalIdx() throws Exception { + helpTestUpsertWithSCNIT(false, false, false, false, true); + exception.expect(SQLException.class); + exception.expectMessage(containsString(String.valueOf( + SQLExceptionCode + .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES + .getErrorCode()))); + prep.executeUpdate(); } + @Test public void testUpsertOnSCNSetWithRowTSColumn() throws Exception { - helpTestUpserWithSCNIT(true, false, false, false, false); + helpTestUpsertWithSCNIT(true, false, false, false, false); exception.expect(SQLException.class); exception.expectMessage(containsString(String.valueOf( SQLExceptionCode - .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN + .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN .getErrorCode()))); prep.executeUpdate(); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java index b237059..38da86c 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java @@ -368,7 +368,7 @@ public class UpsertCompiler { // Cannot update: // - read-only VIEW // - transactional table with a connection having an SCN - // - mutable table with indexes and SCN set + // - table with indexes and SCN set // - tables with ROW_TIMESTAMP columns if (table.getType() == PTableType.VIEW && table.getViewType().isReadOnly()) { throw new ReadOnlyTableException(schemaName,tableName); @@ -382,19 +382,18 @@ public class UpsertCompiler { .CANNOT_SPECIFY_SCN_FOR_TXN_TABLE) .setSchemaName(schemaName) .setTableName(tableName).build().buildException(); - } else if (!table.isImmutableRows() && connection.getSCN() != null - && !table.getIndexes().isEmpty() && !connection.isRunningUpgrade() - && !connection.isBuildingIndex()) { + } else if (connection.getSCN() != null && !table.getIndexes().isEmpty() + && !connection.isRunningUpgrade() && !connection.isBuildingIndex()) { throw new SQLExceptionInfo .Builder(SQLExceptionCode - .CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES) + .CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES) .setSchemaName(schemaName) .setTableName(tableName).build().buildException(); } else if(connection.getSCN() != null && !connection.isRunningUpgrade() && !connection.isBuildingIndex() && table.getRowTimestampColPos() >= 0) { throw new SQLExceptionInfo .Builder(SQLExceptionCode - .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN) + .CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN) .setSchemaName(schemaName) .setTableName(tableName).build().buildException(); } diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java index 0bcdfdf..559b52e 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java @@ -488,12 +488,11 @@ public enum SQLExceptionCode { INSUFFICIENT_MEMORY(999, "50M01", "Unable to allocate enough memory."), HASH_JOIN_CACHE_NOT_FOUND(900, "HJ01", "Hash Join cache not found"), - CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMSTAMP_COLUMN(901,"43M12", + CANNOT_UPSERT_WITH_SCN_FOR_ROW_TIMESTAMP_COLUMN(901,"43M12", "Cannot use a connection with SCN set to upsert data for " + "table with ROW_TIMESTAMP column."), - CANNOT_UPSERT_WITH_SCN_FOR_MUTABLE_TABLE_WITH_INDEXES(903,"43M14", - "Cannot use a connection with SCN set to " + - "upsert data for a mutable table with indexes."); + CANNOT_UPSERT_WITH_SCN_FOR_TABLE_WITH_INDEXES(903,"43M14", + "Cannot use a connection with SCN set to upsert data for a table with indexes."); private final int errorCode;