Repository: phoenix
Updated Branches:
  refs/heads/txn ba952bc7c -> 8387bf03f


code review feedback


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

Branch: refs/heads/txn
Commit: 8387bf03f65c58e408189769f6b89455e85d1306
Parents: ba952bc
Author: Thomas D'Silva <[email protected]>
Authored: Wed Nov 18 12:56:04 2015 -0800
Committer: Thomas D'Silva <[email protected]>
Committed: Wed Nov 18 12:56:04 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/end2end/index/IndexIT.java   |   2 +-
 .../phoenix/end2end/index/MutableIndexIT.java   |   2 +-
 .../org/apache/phoenix/rpc/UpdateCacheIT.java   | 108 +++++++---------
 .../phoenix/rpc/UpdateCacheWithScnIT.java       |  41 +++++++
 .../org/apache/phoenix/tx/TransactionIT.java    |  26 ++--
 .../apache/phoenix/tx/TxPointInTimeQueryIT.java |   7 +-
 .../org/apache/phoenix/tx/UpdateCacheIT.java    | 122 -------------------
 .../apache/phoenix/tx/UpdateCacheWithScnIT.java |  41 -------
 .../apache/phoenix/schema/MetaDataClient.java   |  13 +-
 9 files changed, 117 insertions(+), 245 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
index 4eebddc..a1be7bc 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexIT.java
@@ -882,4 +882,4 @@ public class IndexIT extends BaseHBaseManagedTimeIT {
         } 
     }
     
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
index 127c988..93a4741 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexIT.java
@@ -599,4 +599,4 @@ public class MutableIndexIT extends BaseHBaseManagedTimeIT {
         }
     }
 
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
index b7f880a..98932e1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheIT.java
@@ -20,9 +20,8 @@ package org.apache.phoenix.rpc;
 import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
 import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
+import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Matchers.isNull;
@@ -30,33 +29,26 @@ import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import java.math.BigDecimal;
 import java.sql.Connection;
-import java.sql.Date;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.util.Map;
 import java.util.Properties;
 
 import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
-import org.apache.phoenix.end2end.Shadower;
 import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
 import org.apache.phoenix.query.ConnectionQueryServices;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.PName;
 import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-import com.google.common.collect.Maps;
-
 /**
  * Verifies the number of rpcs calls from {@link MetaDataClient} updateCache() 
  * for transactional and non-transactional tables.
@@ -68,86 +60,76 @@ public class UpdateCacheIT extends BaseHBaseManagedTimeIT {
     @Before
     public void setUp() throws SQLException {
         ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE);
+        ensureTableCreated(getUrl(), TRANSACTIONAL_DATA_TABLE);
     }
 
-       @BeforeClass
-    @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class)
-    public static void doSetup() throws Exception {
-        Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
-        setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+    @Test
+    public void testUpdateCacheForTxnTable() throws Exception {
+        helpTestUpdateCache(true, null);
     }
-       
-       public static void validateRowKeyColumns(ResultSet rs, int i) throws 
SQLException {
-               assertTrue(rs.next());
-               assertEquals(rs.getString(1), "varchar" + String.valueOf(i));
-               assertEquals(rs.getString(2), "char" + String.valueOf(i));
-               assertEquals(rs.getInt(3), i);
-               assertEquals(rs.getInt(4), i);
-               assertEquals(rs.getBigDecimal(5), new BigDecimal(i*0.5d));
-               Date date = new Date(DateUtil.parseDate("2015-01-01 
00:00:00").getTime() + (i - 1) * NUM_MILLIS_IN_DAY);
-               assertEquals(rs.getDate(6), date);
-       }
-       
-       public static void setRowKeyColumns(PreparedStatement stmt, int i) 
throws SQLException {
-        // insert row
-        stmt.setString(1, "varchar" + String.valueOf(i));
-        stmt.setString(2, "char" + String.valueOf(i));
-        stmt.setInt(3, i);
-        stmt.setLong(4, i);
-        stmt.setBigDecimal(5, new BigDecimal(i*0.5d));
-        Date date = new Date(DateUtil.parseDate("2015-01-01 
00:00:00").getTime() + (i - 1) * NUM_MILLIS_IN_DAY);
-        stmt.setDate(6, date);
+    
+    @Test
+    public void testUpdateCacheForNonTxnTable() throws Exception {
+        helpTestUpdateCache(false, null);
     }
        
-       @Test
-       public void testUpdateCache() throws Exception {
-               String fullTableName = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + MUTABLE_INDEX_DATA_TABLE;
+       public static void helpTestUpdateCache(boolean isTransactional, Long 
scn) throws Exception {
+           String tableName = isTransactional ? TRANSACTIONAL_DATA_TABLE : 
MUTABLE_INDEX_DATA_TABLE;
+           String fullTableName = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + tableName;
                String selectSql = "SELECT * FROM "+fullTableName;
                // use a spyed ConnectionQueryServices so we can verify calls 
to getTable
                ConnectionQueryServices connectionQueryServices = 
Mockito.spy(driver.getConnectionQueryServices(getUrl(), 
PropertiesUtil.deepCopy(TEST_PROPERTIES)));
                Properties props = new Properties();
                props.putAll(PhoenixEmbeddedDriver.DEFFAULT_PROPS.asMap());
+               if (scn!=null) {
+            props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(scn));
+        }
                Connection conn = connectionQueryServices.connect(getUrl(), 
props);
                try {
                        conn.setAutoCommit(false);
-                       ResultSet rs = 
conn.createStatement().executeQuery(selectSql);
-               assertFalse(rs.next());
-               reset(connectionQueryServices);
-               
                String upsert = "UPSERT INTO " + fullTableName + "(varchar_pk, 
char_pk, int_pk, long_pk, decimal_pk, date_pk) VALUES(?, ?, ?, ?, ?, ?)";
                PreparedStatement stmt = conn.prepareStatement(upsert);
                        // upsert three rows
-               setRowKeyColumns(stmt, 1);
+               TestUtil.setRowKeyColumns(stmt, 1);
                        stmt.execute();
-                       setRowKeyColumns(stmt, 2);
+                       TestUtil.setRowKeyColumns(stmt, 2);
                        stmt.execute();
-                       setRowKeyColumns(stmt, 3);
+                       TestUtil.setRowKeyColumns(stmt, 3);
                        stmt.execute();
                        conn.commit();
-                       // verify only one rpc to getTable occurs after commit 
is called
-                       verify(connectionQueryServices, 
times(1)).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(MUTABLE_INDEX_DATA_TABLE)), anyLong(), anyLong());
-                       reset(connectionQueryServices);
+                       // verify only one rpc to fetch table metadata, 
+            verify(connectionQueryServices).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(tableName)), anyLong(), anyLong());
+            reset(connectionQueryServices);
+            
+            if (scn!=null) {
+                // advance scn so that we can see the data we just upserted
+                props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(scn+2));
+                conn = connectionQueryServices.connect(getUrl(), props);
+            }
                        
-                       rs = conn.createStatement().executeQuery(selectSql);
-                       validateRowKeyColumns(rs, 1);
-                       validateRowKeyColumns(rs, 2);
-                       validateRowKeyColumns(rs, 3);
+            ResultSet rs = conn.createStatement().executeQuery(selectSql);
+                       TestUtil.validateRowKeyColumns(rs, 1);
+                       TestUtil.validateRowKeyColumns(rs, 2);
+                       TestUtil.validateRowKeyColumns(rs, 3);
                assertFalse(rs.next());
                
                rs = conn.createStatement().executeQuery(selectSql);
-               validateRowKeyColumns(rs, 1);
-               validateRowKeyColumns(rs, 2);
-               validateRowKeyColumns(rs, 3);
+               TestUtil.validateRowKeyColumns(rs, 1);
+               TestUtil.validateRowKeyColumns(rs, 2);
+               TestUtil.validateRowKeyColumns(rs, 3);
                assertFalse(rs.next());
                
                rs = conn.createStatement().executeQuery(selectSql);
-               validateRowKeyColumns(rs, 1);
-               validateRowKeyColumns(rs, 2);
-               validateRowKeyColumns(rs, 3);
+               TestUtil.validateRowKeyColumns(rs, 1);
+               TestUtil.validateRowKeyColumns(rs, 2);
+               TestUtil.validateRowKeyColumns(rs, 3);
                assertFalse(rs.next());
-               conn.commit();
-               // there should be one rpc to getTable per query
-               verify(connectionQueryServices, 
times(3)).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(MUTABLE_INDEX_DATA_TABLE)), anyLong(), anyLong());
+               
+               // for non-transactional tables without a scn : verify one rpc 
to getTable occurs *per* query
+            // for non-transactional tables with a scn : verify *only* one rpc 
occurs
+            // for transactional tables : verify *only* one rpc occurs
+            int numRpcs = isTransactional || scn!=null ? 1 : 3; 
+            verify(connectionQueryServices, 
times(numRpcs)).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(tableName)), anyLong(), anyLong());
                }
         finally {
                conn.close();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
new file mode 100644
index 0000000..dbc7fd1
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/rpc/UpdateCacheWithScnIT.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.rpc;
+
+import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
+
+import org.apache.phoenix.end2end.BaseClientManagedTimeIT;
+import org.junit.Before;
+import org.junit.Test;
+
+public class UpdateCacheWithScnIT extends BaseClientManagedTimeIT {
+       
+       protected long ts;
+
+       @Before
+       public void initTable() throws Exception {
+               ts = nextTimestamp();
+               ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE, ts);
+       }
+       
+       @Test
+       public void testUpdateCacheWithScn() throws Exception {
+               UpdateCacheIT.helpTestUpdateCache(false, ts+2);
+       }
+
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/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 1482701..d0e8db5 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
@@ -1,11 +1,19 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE
- * file distributed with this work for additional information regarding 
copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the "License"); you may not 
use this file except in compliance with the
- * License. You may obtain a copy of the License at 
http://www.apache.org/licenses/LICENSE-2.0 Unless required by
- * applicable law or agreed to in writing, software distributed under the 
License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language
- * governing permissions and limitations under the License.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.apache.phoenix.tx;
 
@@ -48,11 +56,11 @@ import org.apache.phoenix.util.TestUtil;
 import org.junit.Before;
 import org.junit.Test;
 
-import com.google.common.collect.Lists;
-
 import co.cask.tephra.TxConstants;
 import co.cask.tephra.hbase11.coprocessor.TransactionProcessor;
 
+import com.google.common.collect.Lists;
+
 public class TransactionIT extends BaseHBaseManagedTimeIT {
        
        private static final String FULL_TABLE_NAME = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + TRANSACTIONAL_DATA_TABLE;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/tx/TxPointInTimeQueryIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxPointInTimeQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxPointInTimeQueryIT.java
index 8a4f376..a3b3aa2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxPointInTimeQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxPointInTimeQueryIT.java
@@ -48,8 +48,7 @@ public class TxPointInTimeQueryIT extends 
BaseClientManagedTimeIT {
                props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
                try (Connection conn = DriverManager.getConnection(getUrl(), 
props);) {
                        try {
-                               conn.createStatement()
-                                               .execute(
+                               conn.createStatement().execute(
                                                                "CREATE TABLE t 
(k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true");
                                fail();
                        } catch (SQLException e) {
@@ -57,7 +56,7 @@ public class TxPointInTimeQueryIT extends 
BaseClientManagedTimeIT {
                                                
SQLExceptionCode.CANNOT_START_TRANSACTION_WITH_SCN_SET
                                                                
.getErrorCode(), e.getErrorCode());
                        }
-               }
-       }
+        }
+    }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheIT.java
deleted file mode 100644
index 19f3395..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheIT.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.apache.phoenix.tx;
-
-import static org.apache.phoenix.util.TestUtil.INDEX_DATA_SCHEMA;
-import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.TRANSACTIONAL_DATA_TABLE;
-import static org.junit.Assert.assertFalse;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Matchers.isNull;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Properties;
-
-import org.apache.phoenix.end2end.BaseHBaseManagedTimeIT;
-import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
-import org.apache.phoenix.query.ConnectionQueryServices;
-import org.apache.phoenix.query.QueryConstants;
-import org.apache.phoenix.schema.MetaDataClient;
-import org.apache.phoenix.schema.PName;
-import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- * Verifies the number of rpcs calls from {@link MetaDataClient} updateCache() 
- * for transactional and non-transactional tables.
- */
-public class UpdateCacheIT extends BaseHBaseManagedTimeIT {
-
-    @Before
-    public void setUp() throws SQLException {
-        ensureTableCreated(getUrl(), TRANSACTIONAL_DATA_TABLE);
-        ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE);
-    }
-
-       @Test
-       public void testUpdateCacheForTxnTable() throws Exception {
-               helpTestUpdateCache(true, null);
-       }
-       
-       @Test
-       public void testUpdateCacheForNonTxnTable() throws Exception {
-               helpTestUpdateCache(false, null);
-       }
-       
-       public static void helpTestUpdateCache(boolean isTransactional, Long 
scn) throws Exception {
-               String tableName = isTransactional ? TRANSACTIONAL_DATA_TABLE : 
MUTABLE_INDEX_DATA_TABLE;
-               String fullTableName = INDEX_DATA_SCHEMA + 
QueryConstants.NAME_SEPARATOR + tableName;
-               String selectSql = "SELECT * FROM "+fullTableName;
-               // use a spyed ConnectionQueryServices so we can verify calls 
to getTable
-               ConnectionQueryServices connectionQueryServices = 
Mockito.spy(driver.getConnectionQueryServices(getUrl(), 
PropertiesUtil.deepCopy(TEST_PROPERTIES)));
-               Properties props = new Properties();
-               props.putAll(PhoenixEmbeddedDriver.DEFFAULT_PROPS.asMap());
-               if (scn!=null) {
-                       props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(scn));
-               }
-               Connection conn = connectionQueryServices.connect(getUrl(), 
props);
-               try {
-                       conn.setAutoCommit(false);
-               String upsert = "UPSERT INTO " + fullTableName + "(varchar_pk, 
char_pk, int_pk, long_pk, decimal_pk, date_pk) VALUES(?, ?, ?, ?, ?, ?)";
-               PreparedStatement stmt = conn.prepareStatement(upsert);
-                       // upsert three rows
-               TestUtil.setRowKeyColumns(stmt, 1);
-                       stmt.execute();
-                       TestUtil.setRowKeyColumns(stmt, 2);
-                       stmt.execute();
-                       TestUtil.setRowKeyColumns(stmt, 3);
-                       stmt.execute();
-                       conn.commit();
-                       // for non txn tables verify only one rpc to fetch 
table metadata, 
-                       // for txn tables the table will already be present in 
the cache because MetaDataClient.createTableInternal starts a txn 
-//                     if (!isTransactional) {
-                               
verify(connectionQueryServices).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(tableName)), anyLong(), anyLong());
-                               reset(connectionQueryServices);
-//                     }
-                       
-                       if (scn!=null) {
-                               // advance scn so that we can see the data we 
just upserted
-                               props.put(PhoenixRuntime.CURRENT_SCN_ATTRIB, 
Long.toString(scn+2));
-                               conn = 
connectionQueryServices.connect(getUrl(), props);
-                       }
-                       
-                       ResultSet rs = 
conn.createStatement().executeQuery(selectSql);
-                       TestUtil.validateRowKeyColumns(rs, 1);
-                       TestUtil.validateRowKeyColumns(rs, 2);
-                       TestUtil.validateRowKeyColumns(rs, 3);
-               assertFalse(rs.next());
-               
-               rs = conn.createStatement().executeQuery(selectSql);
-               TestUtil.validateRowKeyColumns(rs, 1);
-               TestUtil.validateRowKeyColumns(rs, 2);
-               TestUtil.validateRowKeyColumns(rs, 3);
-               assertFalse(rs.next());
-               
-               rs = conn.createStatement().executeQuery(selectSql);
-               TestUtil.validateRowKeyColumns(rs, 1);
-               TestUtil.validateRowKeyColumns(rs, 2);
-               TestUtil.validateRowKeyColumns(rs, 3);
-               assertFalse(rs.next());
-               
-               // for non-transactional tables without a scn : verify one rpc 
to getTable occurs *per* query
-               // for non-transactional tables with a scn : verify *only* one 
rpc occurs
-                       // for transactional tables : verify *only* one rpc 
occurs
-               int numRpcs = isTransactional || scn!=null ? 1 : 3; 
-               verify(connectionQueryServices, 
times(numRpcs)).getTable((PName)isNull(), 
eq(PVarchar.INSTANCE.toBytes(INDEX_DATA_SCHEMA)), 
eq(PVarchar.INSTANCE.toBytes(tableName)), anyLong(), anyLong());
-               }
-        finally {
-               conn.close();
-        }
-       }
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheWithScnIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheWithScnIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheWithScnIT.java
deleted file mode 100644
index 7fad3ad..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/UpdateCacheWithScnIT.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.tx;
-
-import static org.apache.phoenix.util.TestUtil.MUTABLE_INDEX_DATA_TABLE;
-
-import org.apache.phoenix.end2end.BaseClientManagedTimeIT;
-import org.junit.Before;
-import org.junit.Test;
-
-public class UpdateCacheWithScnIT extends BaseClientManagedTimeIT {
-       
-       protected long ts;
-
-       @Before
-       public void initTable() throws Exception {
-               ts = nextTimestamp();
-               ensureTableCreated(getUrl(), MUTABLE_INDEX_DATA_TABLE, ts);
-       }
-       
-       @Test
-       public void testUpdateCacheWithScn() throws Exception {
-               UpdateCacheIT.helpTestUpdateCache(false, ts+2);
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8387bf03/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 412e050..34d0e16 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
@@ -200,6 +200,8 @@ import org.apache.phoenix.util.UpgradeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import co.cask.tephra.TxConstants;
+
 import com.google.common.base.Objects;
 import com.google.common.collect.Iterators;
 import com.google.common.collect.ListMultimap;
@@ -208,8 +210,6 @@ 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);
 
@@ -1706,8 +1706,13 @@ public class MetaDataClient {
             
             boolean sharedTable = statement.getTableType() == PTableType.VIEW 
|| indexId != null;
             if (transactional) { 
-                // FIXME: remove once Tephra handles storing multiple versions 
of a cell value, 
-               // and allows ignoring empty key values for an operation
+                // Tephra uses an empty value cell as its delete marker, so we 
need to turn on
+                // storeNulls for transactional tables.
+                // If we use regular column delete markers (which is what non 
transactional tables
+                // use), then they get converted
+                // on the server, but this can mess up our secondary index 
code as the changes get
+                // committed prior to the
+                // maintenance code being able to see the prior state to 
update the rows correctly.
                if (Boolean.FALSE.equals(storeNullsProp)) {
                        throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.STORE_NULLS_MUST_BE_TRUE_FOR_TRANSACTIONAL)
                        .setSchemaName(schemaName).setTableName(tableName)

Reply via email to