You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2015/12/11 19:59:46 UTC
phoenix git commit: PHOENIX-2497 Disallow usage of ROW_TIMESTAMP with
transactional tables
Repository: phoenix
Updated Branches:
refs/heads/4.x-HBase-1.0 9eb25340c -> ec3cc1870
PHOENIX-2497 Disallow usage of ROW_TIMESTAMP with transactional tables
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ec3cc187
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ec3cc187
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ec3cc187
Branch: refs/heads/4.x-HBase-1.0
Commit: ec3cc1870d3ece715c58e2390776a52b321022c6
Parents: 9eb2534
Author: Thomas D'Silva <td...@salesforce.com>
Authored: Thu Dec 10 15:52:58 2015 -0800
Committer: Thomas D'Silva <td...@salesforce.com>
Committed: Fri Dec 11 10:55:54 2015 -0800
----------------------------------------------------------------------
.../apache/phoenix/end2end/AlterTableIT.java | 2 ++
.../org/apache/phoenix/tx/TransactionIT.java | 24 ++++++++++++++++++++
.../phoenix/exception/SQLExceptionCode.java | 2 ++
.../apache/phoenix/schema/MetaDataClient.java | 14 ++++++++++++
.../org/apache/phoenix/util/SchemaUtil.java | 4 ++++
5 files changed, 46 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec3cc187/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
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 c86f8c5..122ec16 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
@@ -2190,6 +2190,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// creating a transactional table should fail if transactions are disabled
try {
conn.createStatement().execute("CREATE TABLE DEMO1(k INTEGER PRIMARY KEY, v VARCHAR) TRANSACTIONAL=true");
+ fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_IF_TXNS_DISABLED.getErrorCode(), e.getErrorCode());
}
@@ -2197,6 +2198,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.createStatement().execute("CREATE TABLE DEMO2(k INTEGER PRIMARY KEY, v VARCHAR)");
try {
conn.createStatement().execute("ALTER TABLE DEMO2 SET TRANSACTIONAL=true");
+ fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED.getErrorCode(), e.getErrorCode());
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec3cc187/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index 2eb6edf..70e31b9 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -548,4 +548,28 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, "DEMO")).isTransactional());
assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, "DEMO_IDX")).isTransactional());
}
+
+ @Test
+ public void testRowTimestampDisabled() throws SQLException {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.setAutoCommit(false);
+ Statement stmt = conn.createStatement();
+ try {
+ stmt.execute("CREATE TABLE DEMO(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT PK PRIMARY KEY(k,d ROW_TIMESTAMP)) TRANSACTIONAL=true");
+ fail();
+ }
+ catch(SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP.getErrorCode(), e.getErrorCode());
+ }
+ stmt.execute("CREATE TABLE DEMO(k VARCHAR, v VARCHAR, d DATE NOT NULL, CONSTRAINT PK PRIMARY KEY(k,d ROW_TIMESTAMP))");
+ try {
+ stmt.execute("ALTER TABLE DEMO SET TRANSACTIONAL=true");
+ fail();
+ }
+ catch(SQLException e) {
+ assertEquals(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP.getErrorCode(), e.getErrorCode());
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec3cc187/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
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 fb8ebfd..39f2c14 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
@@ -278,6 +278,8 @@ public enum SQLExceptionCode {
TRANSACTION_FAILED(1077, "44A08", "Transaction Failure "),
CANNOT_CREATE_TXN_TABLE_IF_TXNS_DISABLED(1078, "44A09", "Cannot create a transactional table if transactions are disabled"),
CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED(1079, "44A10", "Cannot alter table to be transactional table if transactions are disabled"),
+ CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP(1080, "44A11", "Cannot create a transactional table if transactions are disabled"),
+ CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP(1081, "44A12", "Cannot alter table to be transactional table if transactions are disabled"),
/** Sequence related */
SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new Factory() {
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec3cc187/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 ccfb1cb..9c365ab 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
@@ -1718,6 +1718,14 @@ public class MetaDataClient {
.setSchemaName(schemaName).setTableName(tableName)
.build().buildException();
}
+ // can't create a transactional table if it has a row timestamp column
+ if (pkConstraint.getNumColumnsWithRowTimestamp()>0 && transactional) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_TXN_TABLE_WITH_ROW_TIMESTAMP)
+ .setSchemaName(schemaName).setTableName(tableName)
+ .build().buildException();
+ }
+
+
tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, transactional);
if (transactional) {
// If TTL set, use Tephra TTL property name instead
@@ -2667,6 +2675,12 @@ public class MetaDataClient {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_IF_TXNS_DISABLED)
.setSchemaName(schemaName).setTableName(tableName).build().buildException();
}
+ // cannot make a table transactional if it has a row timestamp column
+ if (SchemaUtil.hasRowTimestampColumn(table)) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_ALTER_TO_BE_TXN_WITH_ROW_TIMESTAMP)
+ .setSchemaName(schemaName).setTableName(tableName)
+ .build().buildException();
+ }
timeStamp = TransactionUtil.getTableTimestamp(connection, isTransactional);
changingPhoenixTableProperty = true;
nonTxToTx = true;
http://git-wip-us.apache.org/repos/asf/phoenix/blob/ec3cc187/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
index cb8aced..c6a20b3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/SchemaUtil.java
@@ -886,4 +886,8 @@ public class SchemaUtil {
}
return columnInfoList;
}
+
+ public static boolean hasRowTimestampColumn(PTable table) {
+ return table.getRowTimestampColPos()>0;
+ }
}