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

Branch: refs/heads/master
Commit: 43da29f4777f0f9ac9f5373bafe3c2e4643e26a5
Parents: 8cceea6
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:54:21 2018 +0200

----------------------------------------------------------------------
 .../org/apache/phoenix/tx/TransactionIT.java    | 29 ++++++++++++++++++++
 .../query/ConnectionQueryServicesImpl.java      |  3 ++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/43da29f4/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 baaac8d..2cf15d2 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;
@@ -36,9 +37,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Properties;
 
+import org.apache.hadoop.hbase.client.Admin;
 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;
 import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
 import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.TableName;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
 import org.apache.phoenix.exception.SQLExceptionCode;
@@ -55,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;
@@ -371,4 +375,29 @@ public class TransactionIT  extends 
ParallelStatsDisabledIT {
             conn.close();
         }
     }
+    
+    private static void assertTTL(Admin admin, String tableName, int ttl) 
throws Exception {
+        TableDescriptor tableDesc = 
admin.getTableDescriptor(TableName.valueOf(tableName));
+        for (ColumnFamilyDescriptor colDesc : tableDesc.getColumnFamilies()) {
+            
assertEquals(ttl,Integer.parseInt(Bytes.toString(colDesc.getValue(Bytes.toBytes(TxConstants.PROPERTY_TTL)))));
+            
assertEquals(ColumnFamilyDescriptorBuilder.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/43da29f4/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 f1ab653..3c232aa 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
@@ -2262,6 +2262,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, new 
Integer(ttl));
                         // Remove HBase TTL if we're not transitioning an 
existing table to become transactional
@@ -2269,6 +2271,7 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                         if (!willBeTransactional && 
!Boolean.valueOf(newTableDescriptorBuilder.build().getValue(PhoenixTransactionContext.READ_NON_TX_DATA)))
 {
                             props.remove(TTL);
                         }
+                        entry.setValue(props);
                     }
                 }
             }

Reply via email to