PHOENIX-4789 Exception when setting TTL on Tephra transactional table
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/d50f3e34 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/d50f3e34 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/d50f3e34 Branch: refs/heads/4.x-cdh5.15 Commit: d50f3e343a2212d655b5e45f99f00a6a551bb396 Parents: 2c00806 Author: James Taylor <jamestay...@apache.org> Authored: Mon Jun 18 14:00:02 2018 +0100 Committer: Pedro Boado <pbo...@apache.org> Committed: Wed Oct 17 21:26:15 2018 +0100 ---------------------------------------------------------------------- .../org/apache/phoenix/tx/TransactionIT.java | 30 ++++++++++++++++++++ .../query/ConnectionQueryServicesImpl.java | 3 ++ 2 files changed, 33 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/d50f3e34/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 c0ec6b8..12c3b7a 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 @@ -25,6 +25,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.IOException; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.DriverManager; @@ -38,6 +39,9 @@ import java.util.Properties; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.TableNotFoundException; +import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.end2end.ParallelStatsDisabledIT; import org.apache.phoenix.exception.SQLExceptionCode; @@ -54,6 +58,7 @@ import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.StringUtil; import org.apache.phoenix.util.TestUtil; +import org.apache.tephra.TxConstants; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -370,4 +375,29 @@ public class TransactionIT extends ParallelStatsDisabledIT { conn.close(); } } + + private static void assertTTL(Admin admin, String tableName, int ttl) throws TableNotFoundException, IOException { + HTableDescriptor tableDesc = admin.getTableDescriptor(TableName.valueOf(tableName)); + for (HColumnDescriptor colDesc : tableDesc.getFamilies()) { + assertEquals(ttl,Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL))); + assertEquals(HColumnDescriptor.DEFAULT_TTL,colDesc.getTimeToLive()); + } + } + + @Test + public void testSetTTL() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + TransactionFactory.Provider txProvider = TransactionFactory.Provider.valueOf(this.txProvider); + try (Connection conn = DriverManager.getConnection(getUrl(), props); Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) { + String tableName = generateUniqueName(); + conn.createStatement().execute("CREATE TABLE " + tableName + + "(K VARCHAR PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "',TTL=100"); + assertTTL(admin, tableName, 100); + tableName = generateUniqueName(); + conn.createStatement().execute("CREATE TABLE " + tableName + + "(K VARCHAR PRIMARY KEY) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + txProvider + "'"); + conn.createStatement().execute("ALTER TABLE " + tableName + " SET TTL=" + 200); + assertTTL(admin, tableName, 200); + } + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/d50f3e34/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java ---------------------------------------------------------------------- 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 bfaffbd..f8ca7a4 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 @@ -2234,6 +2234,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement Map<String, Object> props = entry.getValue(); if (props == null) { props = new HashMap<String, Object>(); + } else { + props = new HashMap<String, Object>(props); } props.put(PhoenixTransactionContext.PROPERTY_TTL, ttl); // Remove HBase TTL if we're not transitioning an existing table to become transactional @@ -2241,6 +2243,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement if (!willBeTransactional && !Boolean.valueOf(newTableDescriptor.getValue(PhoenixTransactionContext.READ_NON_TX_DATA))) { props.remove(TTL); } + entry.setValue(props); } } }