Repository: phoenix
Updated Branches:
  refs/heads/txn 4f454a755 -> 657060b36


PHOENIX-1821 Addendum for implement mechanism to convert a table from non 
transactional to transactional


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

Branch: refs/heads/txn
Commit: 657060b36c354d49c8326eb8b2adb64af7102a09
Parents: 4f454a7
Author: James Taylor <[email protected]>
Authored: Thu Oct 29 00:22:59 2015 -0700
Committer: James Taylor <[email protected]>
Committed: Thu Oct 29 00:22:59 2015 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/tx/TransactionIT.java    | 36 +++-----------------
 .../coprocessor/MetaDataEndpointImpl.java       | 17 +++++++--
 .../apache/phoenix/schema/MetaDataClient.java   |  5 +--
 3 files changed, 21 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/657060b3/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 373ea99..878d2cf 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
@@ -22,8 +22,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
-
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTableInterface;
 import org.apache.hadoop.hbase.client.Put;
@@ -40,6 +38,8 @@ import org.apache.phoenix.util.TestUtil;
 import org.junit.Before;
 import org.junit.Test;
 
+import co.cask.tephra.hbase98.coprocessor.TransactionProcessor;
+
 public class TransactionIT extends BaseHBaseManagedTimeIT {
        
        private static final String FULL_TABLE_NAME = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + TRANSACTIONAL_DATA_TABLE;
@@ -252,7 +252,6 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
         conn.commit();
         
         conn.createStatement().execute("CREATE INDEX IDX ON NON_TX_TABLE(v)");
-        
         // Reset empty column value to an empty value like it is 
pre-transactions
         /** TODO: when TEPHRA-143 is fixed, comment this back in
         HTableInterface htable = 
conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes("NON_TX_TABLE"));
@@ -272,41 +271,15 @@ public class TransactionIT extends BaseHBaseManagedTimeIT 
{
 
         conn.createStatement().execute("UPSERT INTO NON_TX_TABLE VALUES (4, 
'c')");
         ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ 
NO_INDEX */ k FROM NON_TX_TABLE WHERE v IS NULL");
+        assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null, "NON_TX_TABLE")).isTransactional());
         assertTrue(rs.next());
         assertEquals(1,rs.getInt(1));
         assertFalse(rs.next());
         conn.commit();
         
         conn.createStatement().execute("UPSERT INTO NON_TX_TABLE VALUES (5, 
'd')");
-        rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ k 
FROM NON_TX_TABLE");
-        assertTrue(rs.next());
-        assertEquals(1,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(2,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(3,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(4,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(5,rs.getInt(1));
-        assertFalse(rs.next());
-        conn.rollback();
-        
-        rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ k 
FROM NON_TX_TABLE");
-        assertTrue(rs.next());
-        assertEquals(1,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(2,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(3,rs.getInt(1));
-        assertTrue(rs.next());
-        assertEquals(4,rs.getInt(1));
-        assertFalse(rs.next());
-        
-        /* TODO: this should succeed too (with SELECT going through index), 
but doesn't. Try again after TEPHRA-143 is fixed.
-         * It might be the case that we're still using an empty value for 
indexes.
-        conn.createStatement().execute("UPSERT INTO NON_TX_TABLE VALUES (5, 
'd')");
         rs = conn.createStatement().executeQuery("SELECT k FROM NON_TX_TABLE");
+        assertTrue(conn.unwrap(PhoenixConnection.class).getTable(new 
PTableKey(null, "IDX")).isTransactional());
         assertTrue(rs.next());
         assertEquals(1,rs.getInt(1));
         assertTrue(rs.next());
@@ -330,7 +303,6 @@ public class TransactionIT extends BaseHBaseManagedTimeIT {
         assertTrue(rs.next());
         assertEquals(4,rs.getInt(1));
         assertFalse(rs.next());
-        */
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/phoenix/blob/657060b3/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index ee724fc..48f4159 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -1279,13 +1279,24 @@ public class MetaDataEndpointImpl extends 
MetaDataProtocol implements Coprocesso
                                     // have the parent table lock at this 
point.
                                     for (PTable index : table.getIndexes()) {
                                         invalidateList.add(new 
ImmutableBytesPtr(SchemaUtil
-                                                .getTableKey(tenantId, 
index.getSchemaName()
-                                                        .getBytes(), 
index.getTableName()
-                                                        .getBytes())));
+                                                .getTableKey(tenantId, 
+                                                        
index.getSchemaName().getBytes(),
+                                                        
index.getTableName().getBytes())));
                                     }
                                 }
                                 continue;
                             }
+                        } else if (pkCount == COLUMN_NAME_INDEX &&
+                                   ! (Bytes.compareTo(schemaName, 
rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0 &&
+                                      Bytes.compareTo(tableName, 
rowKeyMetaData[TABLE_NAME_INDEX]) == 0 ) ) {
+                            // Invalidate any table with mutations
+                            // TODO: this likely means we don't need the above 
logic that
+                            // loops through the indexes if adding a PK 
column, since we'd
+                            // always have header rows for those.
+                            invalidateList.add(new ImmutableBytesPtr(SchemaUtil
+                                    .getTableKey(tenantId, 
+                                            rowKeyMetaData[SCHEMA_NAME_INDEX],
+                                            
rowKeyMetaData[TABLE_NAME_INDEX])));
                         }
                     }
                     return null;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/657060b3/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 1da3295..a992529 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
@@ -2351,9 +2351,10 @@ public class MetaDataClient {
                         return new MutationState(0,connection);
                     }
 
-                    // Only update client side cache if we aren't adding a PK 
column to a table with indexes.
+                    // Only update client side cache if we aren't adding a PK 
column to a table with indexes or 
+                    // transitioning a table from.
                     // We could update the cache manually then too, it'd just 
be a pain.
-                    if (numPkColumnsAdded==0 || table.getIndexes().isEmpty()) {
+                    if (table.getIndexes().isEmpty() || (numPkColumnsAdded==0 
&& !nonTxToTx)) {
                                                connection.addColumn(
                                                                tenantId,
                                                                
SchemaUtil.getTableName(schemaName, tableName),

Reply via email to