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/9dbe20ac
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/9dbe20ac
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/9dbe20ac

Branch: refs/heads/4.x-HBase-1.4
Commit: 9dbe20ac7c90710e4ce37eb84be31b9e5e94bc87
Parents: 6acdae0
Author: James Taylor <jamestay...@apache.org>
Authored: Mon Jun 18 15:00:02 2018 +0200
Committer: James Taylor <jamestay...@apache.org>
Committed: Mon Jun 18 15:00:02 2018 +0200

----------------------------------------------------------------------
 .../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/9dbe20ac/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/9dbe20ac/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 63a598f..71d4b3d 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);
                     }
                 }
             }

Reply via email to