Repository: phoenix
Updated Branches:
  refs/heads/txn b3bb20001 -> 59ba25a59


PHOENIX-2376 Set Tephra TTL based on HBase TTL


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/59ba25a5
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/59ba25a5
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/59ba25a5

Branch: refs/heads/txn
Commit: 59ba25a59b9e94fe09fd4c25351c9fee6473d304
Parents: b3bb200
Author: James Taylor <[email protected]>
Authored: Mon Nov 9 21:03:17 2015 -0800
Committer: James Taylor <[email protected]>
Committed: Mon Nov 9 21:03:17 2015 -0800

----------------------------------------------------------------------
 .../org/apache/phoenix/tx/TransactionIT.java    |  34 +++++--
 .../apache/phoenix/execute/MutationState.java   |   3 -
 .../query/ConnectionQueryServicesImpl.java      | 100 +++++++++++++------
 .../apache/phoenix/schema/MetaDataClient.java   |  15 ++-
 .../org/apache/phoenix/schema/PTableImpl.java   |   6 +-
 5 files changed, 115 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/59ba25a5/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 974d104..be98b84 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
@@ -44,6 +44,7 @@ import org.junit.Test;
 
 import com.google.common.collect.Lists;
 
+import co.cask.tephra.TxConstants;
 import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;
 
 public class TransactionIT extends BaseHBaseManagedTimeIT {
@@ -350,27 +351,33 @@ public class TransactionIT extends BaseHBaseManagedTimeIT 
{
     }
     
     @Test
-    public void testMaxVersions() throws Exception {
+    public void testProperties() throws Exception {
         Connection conn = DriverManager.getConnection(getUrl());
-        conn.createStatement().execute("CREATE TABLE NON_TX_TABLE1(k INTEGER 
PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
-        conn.createStatement().execute("CREATE INDEX idx1 ON 
NON_TX_TABLE1(a.v, b.v)");
-        conn.createStatement().execute("CREATE INDEX idx2 ON 
NON_TX_TABLE1(c.v) INCLUDE (a.v, b.v)");
+        conn.createStatement().execute("CREATE TABLE NON_TX_TABLE1(k INTEGER 
PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR) TTL=1000");
+        conn.createStatement().execute("CREATE INDEX idx1 ON 
NON_TX_TABLE1(a.v, b.v) TTL=1000");
+        conn.createStatement().execute("CREATE INDEX idx2 ON 
NON_TX_TABLE1(c.v) INCLUDE (a.v, b.v) TTL=1000");
 
         conn.createStatement().execute("ALTER TABLE NON_TX_TABLE1 SET 
TRANSACTIONAL=true");
 
         HTableDescriptor desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("NON_TX_TABLE1"));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             
assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, 
colDesc.getMaxVersions());
+            assertEquals(1000, colDesc.getTimeToLive());
+            assertEquals(1000, 
Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL)));
         }
 
         desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("IDX1"));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             
assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, 
colDesc.getMaxVersions());
+            assertEquals(1000, colDesc.getTimeToLive());
+            assertEquals(1000, 
Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL)));
         }
         
         desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("IDX2"));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             
assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, 
colDesc.getMaxVersions());
+            assertEquals(1000, colDesc.getTimeToLive());
+            assertEquals(1000, 
Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL)));
         }
         
         conn.createStatement().execute("CREATE TABLE NON_TX_TABLE2(k INTEGER 
PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
@@ -378,6 +385,15 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
         desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("NON_TX_TABLE2"));
         for (HColumnDescriptor colDesc : desc.getFamilies()) {
             assertEquals(10, colDesc.getMaxVersions());
+            assertEquals(HColumnDescriptor.DEFAULT_TTL, 
colDesc.getTimeToLive());
+            assertEquals(null, colDesc.getValue(TxConstants.PROPERTY_TTL));
+        }
+        conn.createStatement().execute("ALTER TABLE NON_TX_TABLE2 SET 
TTL=1000");
+        desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("NON_TX_TABLE2"));
+        for (HColumnDescriptor colDesc : desc.getFamilies()) {
+            assertEquals(10, colDesc.getMaxVersions());
+            assertEquals(1000, colDesc.getTimeToLive());
+            assertEquals(1000, 
Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL)));
         }
 
         conn.createStatement().execute("CREATE TABLE NON_TX_TABLE3(k INTEGER 
PRIMARY KEY, a.v VARCHAR, b.v VARCHAR, c.v VARCHAR)");
@@ -401,7 +417,13 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
         } catch (SQLException e) {
             
assertEquals(SQLExceptionCode.TX_MAX_VERSIONS_MUST_BE_GREATER_THAN_ONE.getErrorCode(),
 e.getErrorCode());
         }
-    }
         
-
+        conn.createStatement().execute("CREATE TABLE TX_TABLE1(k INTEGER 
PRIMARY KEY, v VARCHAR) TTL=1000, TRANSACTIONAL=true");
+        desc = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTableDescriptor(Bytes.toBytes("TX_TABLE1"));
+        for (HColumnDescriptor colDesc : desc.getFamilies()) {
+            
assertEquals(QueryServicesOptions.DEFAULT_MAX_VERSIONS_TRANSACTIONAL, 
colDesc.getMaxVersions());
+            assertEquals(HColumnDescriptor.DEFAULT_TTL, 
colDesc.getTimeToLive());
+            assertEquals(1000, 
Integer.parseInt(colDesc.getValue(TxConstants.PROPERTY_TTL)));
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/59ba25a5/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
index ff9fa41..8b5bd14 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/MutationState.java
@@ -65,7 +65,6 @@ import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.IllegalDataException;
 import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.PRow;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.IndexType;
@@ -80,7 +79,6 @@ import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.LogUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SQLCloseable;
-import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.ServerUtil;
 import org.apache.phoenix.util.TransactionUtil;
 import org.slf4j.Logger;
@@ -124,7 +122,6 @@ public class MutationState implements SQLCloseable {
     private int numRows = 0;
     private boolean txStarted = false;
     
-    private final ImmutableBytesPtr tempPtr = new ImmutableBytesPtr();
     private final MutationMetricQueue mutationMetricQueue;
     private ReadMetricQueue readMetricQueue;
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/59ba25a5/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 0ace121..fdea6f8 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
@@ -46,12 +46,6 @@ import java.util.concurrent.TimeoutException;
 
 import javax.annotation.concurrent.GuardedBy;
 
-import co.cask.tephra.TransactionSystemClient;
-import co.cask.tephra.TxConstants;
-import co.cask.tephra.distributed.PooledClientProvider;
-import co.cask.tephra.distributed.TransactionServiceClient;
-import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;
-
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
@@ -179,7 +173,6 @@ import org.apache.twill.zookeeper.ZKClients;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Stopwatch;
 import com.google.common.base.Joiner;
 import com.google.common.base.Throwables;
 import com.google.common.cache.Cache;
@@ -189,6 +182,12 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
+import co.cask.tephra.TransactionSystemClient;
+import co.cask.tephra.TxConstants;
+import co.cask.tephra.distributed.PooledClientProvider;
+import co.cask.tephra.distributed.TransactionServiceClient;
+import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;
+
 
 public class ConnectionQueryServicesImpl extends DelegateQueryServices 
implements ConnectionQueryServices {
     private static final Logger logger = 
LoggerFactory.getLogger(ConnectionQueryServicesImpl.class);
@@ -1658,7 +1657,6 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                 // When adding a column to a view, base physical table should 
only be modified when new column families are being added.  
                 modifyHTable = canViewsAddNewCF && 
!existingColumnFamiliesForBaseTable(table.getPhysicalName()).containsAll(colFamiliesForPColumnsToBeAdded);
             }
-            boolean pollingNotNeeded = (!tableProps.isEmpty() && 
!existingColumnFamilies(table).containsAll(colFamiliesForPColumnsToBeAdded));
             if (modifyHTable) {
                 sendHBaseMetaData(tableDescriptors, pollingNeeded);
             }
@@ -1759,11 +1757,18 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                 if (index.getColumnFamilies().isEmpty()) {
                     byte[] dataFamilyName = 
SchemaUtil.getEmptyColumnFamily(table);
                     byte[] indexFamilyName = 
SchemaUtil.getEmptyColumnFamily(index);
-                    
indexDescriptor.getFamily(indexFamilyName).setMaxVersions(tableDescriptor.getFamily(dataFamilyName).getMaxVersions());
+                    HColumnDescriptor indexColDescriptor = 
indexDescriptor.getFamily(indexFamilyName);
+                    HColumnDescriptor tableColDescriptor = 
tableDescriptor.getFamily(dataFamilyName);
+                    
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
+                    indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, 
tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
                 } else {
                     for (PColumnFamily family : index.getColumnFamilies()) {
                         byte[] familyName = family.getName().getBytes();
                         
indexDescriptor.getFamily(familyName).setMaxVersions(tableDescriptor.getFamily(familyName).getMaxVersions());
+                        HColumnDescriptor indexColDescriptor = 
indexDescriptor.getFamily(familyName);
+                        HColumnDescriptor tableColDescriptor = 
tableDescriptor.getFamily(familyName);
+                        
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
+                        indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, 
tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
                     }
                 }
                 setTransactional(indexDescriptor, index.getType(), txValue, 
indexTableProps);
@@ -1802,13 +1807,18 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
             HTableDescriptor indexDescriptor) {
         if (table.getColumnFamilies().isEmpty()) {
             byte[] familyName = SchemaUtil.getEmptyColumnFamily(table);
-            
indexDescriptor.getFamily(familyName).setMaxVersions(tableDescriptor.getFamily(familyName).getMaxVersions());
+            HColumnDescriptor indexColDescriptor = 
indexDescriptor.getFamily(familyName);
+            HColumnDescriptor tableColDescriptor = 
tableDescriptor.getFamily(familyName);
+            
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
+            indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, 
tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
         } else {
             for (PColumnFamily family : table.getColumnFamilies()) {
                 byte[] familyName = family.getName().getBytes();
-                HColumnDescriptor colDescriptor = 
indexDescriptor.getFamily(familyName);
-                if (colDescriptor != null) {
-                    
colDescriptor.setMaxVersions(tableDescriptor.getFamily(familyName).getMaxVersions());
+                HColumnDescriptor indexColDescriptor = 
indexDescriptor.getFamily(familyName);
+                if (indexColDescriptor != null) {
+                    HColumnDescriptor tableColDescriptor = 
tableDescriptor.getFamily(familyName);
+                    
indexColDescriptor.setMaxVersions(tableColDescriptor.getMaxVersions());
+                    indexColDescriptor.setValue(TxConstants.PROPERTY_TTL, 
tableColDescriptor.getValue(TxConstants.PROPERTY_TTL));
                 }
             }
         }
@@ -1846,12 +1856,13 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
     private Pair<HTableDescriptor,HTableDescriptor> 
separateAndValidateProperties(PTable table, Map<String, List<Pair<String, 
Object>>> properties, Set<String> colFamiliesForPColumnsToBeAdded, 
List<Pair<byte[], Map<String, Object>>> families, Map<String, Object> 
tableProps) throws SQLException {
         Map<String, Map<String, Object>> stmtFamiliesPropsMap = new 
HashMap<>(properties.size());
         Map<String,Object> commonFamilyProps = new HashMap<>();
-        boolean addingColumns = colFamiliesForPColumnsToBeAdded != null && 
colFamiliesForPColumnsToBeAdded.size() > 0;
+        boolean addingColumns = colFamiliesForPColumnsToBeAdded != null && 
!colFamiliesForPColumnsToBeAdded.isEmpty();
         HashSet<String> existingColumnFamilies = existingColumnFamilies(table);
         Map<String, Map<String, Object>> allFamiliesProps = new 
HashMap<>(existingColumnFamilies.size());
         boolean isTransactional = table.isTransactional();
         boolean willBeTransactional = false;
         boolean isOrWillBeTransactional = isTransactional;
+        Integer newTTL = null;
         for (String family : properties.keySet()) {
             List<Pair<String, Object>> propsList = properties.get(family);
             if (propsList != null && propsList.size() > 0) {
@@ -1877,6 +1888,7 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                         if (TableProperty.isPhoenixTableProperty(propName)) {
                             TableProperty.valueOf(propName).validate(true, 
!family.equals(QueryConstants.ALL_FAMILY_PROPERTIES_KEY), table.getType());
                             if (propName.equals(TTL)) {
+                                newTTL = ((Number)prop.getSecond()).intValue();
                                 // Even though TTL is really a HColumnProperty 
we treat it specially.
                                 // We enforce that all column families have 
the same TTL.
                                 commonFamilyProps.put(propName, 
prop.getSecond());
@@ -1997,13 +2009,22 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                 }
             }
             if (addingColumns) {
-                // FIXME: we should be setting TTL on all table column 
families, not
-                // just the ones being modified here (if TTL is being set).
                 // Make sure that all the CFs of the table have the same TTL 
as the empty CF. 
-                setTTLToEmptyCFTTL(allFamiliesProps, table, 
newTableDescriptor);
+                setTTLForNewCFs(allFamiliesProps, table, newTableDescriptor, 
newTTL);
+            }
+            // Set TTL on all table column families, even if they're not 
referenced here
+            if (newTTL != null) {
+                for (PColumnFamily family : table.getColumnFamilies()) {
+                    if 
(!allFamiliesProps.containsKey(family.getName().getString())) {
+                        Map<String,Object> familyProps = 
Maps.newHashMapWithExpectedSize(1);
+                        familyProps.put(TTL, newTTL);
+                        allFamiliesProps.put(family.getName().getString(), 
familyProps);
+                    }
+                }
             }
             Integer defaultTxMaxVersions = null;
             if (isOrWillBeTransactional) {
+                // Calculate default for max versions
                 Map<String, Object> emptyFamilyProps = 
allFamiliesProps.get(SchemaUtil.getEmptyColumnFamilyAsString(table));
                 if (emptyFamilyProps != null) {
                     defaultTxMaxVersions = 
(Integer)emptyFamilyProps.get(HConstants.VERSIONS);
@@ -2029,6 +2050,26 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
                     }
                 }
             }
+            // Set Tephra's TTL property based on HBase property if we're 
+            // transitioning to become transactional or setting TTL on
+            // an already transactional table.
+            if (isOrWillBeTransactional) {
+                int ttl = getTTL(table, newTableDescriptor, newTTL);
+                if (ttl != HColumnDescriptor.DEFAULT_TTL) {
+                    for (Map.Entry<String, Map<String, Object>> entry : 
allFamiliesProps.entrySet()) {
+                        Map<String, Object> props = entry.getValue();
+                        if (props == null) {
+                            props = new HashMap<String, Object>();
+                        }
+                        props.put(TxConstants.PROPERTY_TTL, ttl);
+                        // Remove HBase TTL if we're not transitioning an 
existing table to become transactional
+                        // or if the existing transactional table wasn't 
originally non transactional.
+                        if (!willBeTransactional && 
!Boolean.valueOf(newTableDescriptor.getValue(TxConstants.READ_NON_TX_DATA))) {
+                            props.remove(TTL);
+                        }
+                    }
+                }
+            }
             for (Entry<String, Map<String, Object>> entry : 
allFamiliesProps.entrySet()) {
                 Map<String,Object> familyProps = entry.getValue();
                 if (isOrWillBeTransactional) {
@@ -2088,20 +2129,23 @@ public class ConnectionQueryServicesImpl extends 
DelegateQueryServices implement
         return cfNames;
     }
 
-    private int getTTLForEmptyCf(byte[] emptyCf, byte[] tableNameBytes, 
HTableDescriptor tableDescriptor) throws SQLException {
-        if (tableDescriptor == null) {
-            tableDescriptor = getTableDescriptor(tableNameBytes);
-        }
-        return tableDescriptor.getFamily(emptyCf).getTimeToLive();
+    private static int getTTL(PTable table, HTableDescriptor tableDesc, 
Integer newTTL) throws SQLException {
+        // If we're setting TTL now, then use that value. Otherwise, use empty 
column family value
+        int ttl = newTTL != null ? newTTL 
+                : 
tableDesc.getFamily(SchemaUtil.getEmptyColumnFamily(table)).getTimeToLive();
+        return ttl;
     }
     
-    private void setTTLToEmptyCFTTL(Map<String, Map<String, Object>> 
familyProps, PTable table, 
-            HTableDescriptor tableDesc) throws SQLException {
+    private static void setTTLForNewCFs(Map<String, Map<String, Object>> 
familyProps, PTable table, 
+            HTableDescriptor tableDesc, Integer newTTL) throws SQLException {
         if (!familyProps.isEmpty()) {
-            int emptyCFTTL = 
getTTLForEmptyCf(SchemaUtil.getEmptyColumnFamily(table), 
table.getPhysicalName().getBytes(), tableDesc);
-            for (String family : familyProps.keySet()) {
-                Map<String, Object> props = familyProps.get(family) != null ? 
familyProps.get(family) : new HashMap<String, Object>();
-                props.put(TTL, emptyCFTTL);
+            int ttl = getTTL(table, tableDesc, newTTL);
+            for (Map.Entry<String, Map<String, Object>> entry : 
familyProps.entrySet()) {
+                Map<String, Object> props = entry.getValue();
+                if (props == null) {
+                    props = new HashMap<String, Object>();
+                }
+                props.put(TTL, ttl);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/59ba25a5/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 4020736..770fcc0 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
@@ -194,8 +194,8 @@ import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.ReadOnlyProps;
 import org.apache.phoenix.util.ScanUtil;
 import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TransactionUtil;
 import org.apache.phoenix.util.StringUtil;
+import org.apache.phoenix.util.TransactionUtil;
 import org.apache.phoenix.util.UpgradeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -208,6 +208,8 @@ import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.common.primitives.Ints;
 
+import co.cask.tephra.TxConstants;
+
 public class MetaDataClient {
     private static final Logger logger = 
LoggerFactory.getLogger(MetaDataClient.class);
 
@@ -1717,7 +1719,14 @@ public class MetaDataClient {
                     transactional = transactionalProp;
                 }
             }
-            tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, 
Boolean.valueOf(transactional));
+            tableProps.put(PhoenixDatabaseMetaData.TRANSACTIONAL, 
transactional);
+            if (transactional) {
+                // If TTL set, use Tephra TTL property name instead
+                Object ttl = commonFamilyProps.remove(HColumnDescriptor.TTL);
+                if (ttl != null) {
+                    commonFamilyProps.put(TxConstants.PROPERTY_TTL, ttl);
+                }
+            }
             
             boolean sharedTable = statement.getTableType() == PTableType.VIEW 
|| indexId != null;
             if (transactional) { 
@@ -2786,7 +2795,7 @@ public class MetaDataClient {
                     }
 
                     // Only update client side cache if we aren't adding a PK 
column to a table with indexes or 
-                    // transitioning a table from.
+                    // transitioning a table from non transactional to 
transactional.
                     // We could update the cache manually then too, it'd just 
be a pain.
                     if (table.getIndexes().isEmpty() || (numPkColumnsAdded==0 
&& !nonTxToTx)) {
                                                connection.addColumn(

http://git-wip-us.apache.org/repos/asf/phoenix/blob/59ba25a5/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
index 7e0f5a7..0cef1a0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTableImpl.java
@@ -31,8 +31,6 @@ import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
-import co.cask.tephra.TxConstants;
-
 import org.apache.hadoop.hbase.Cell;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.client.Delete;
@@ -79,6 +77,8 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.sun.istack.NotNull;
 
+import co.cask.tephra.TxConstants;
+
 /**
  *
  * Base class for PTable implementors.  Provides abstraction for
@@ -241,7 +241,7 @@ public class PTableImpl implements PTable {
                 sequenceNumber, table.getPKName(), table.getBucketNum(), 
columns, table.getParentSchemaName(), table.getParentTableName(),
                 table.getIndexes(), isImmutableRows, table.getPhysicalNames(), 
table.getDefaultFamilyName(), table.getViewStatement(),
                 isWalDisabled, isMultitenant, storeNulls, table.getViewType(), 
table.getViewIndexId(), table.getIndexType(), table.getTableStats(),
-                table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), 
table.isTransactional());
+                table.getBaseColumnCount(), table.rowKeyOrderOptimizable(), 
isTransactional);
     }
     
     public static PTableImpl makePTable(PTable table, PIndexState state) 
throws SQLException {

Reply via email to