PHOENIX-4890 Prevent local indexes from being created on Omid transactional 
tables


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

Branch: refs/heads/omid2
Commit: 7b5a49a5d16d8d1a975d13107f7068d1de21c1c0
Parents: caa6939
Author: James Taylor <[email protected]>
Authored: Mon Oct 1 08:16:53 2018 -0700
Committer: James Taylor <[email protected]>
Committed: Mon Oct 1 08:16:53 2018 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/index/ImmutableIndexIT.java |  1 -
 .../end2end/index/LocalImmutableTxIndexIT.java  |  1 -
 .../end2end/index/LocalMutableTxIndexIT.java    |  1 -
 .../end2end/index/MutableIndexFailureIT.java    | 12 +++++++---
 .../MutableIndexFailureWithNamespaceIT.java     |  1 -
 .../end2end/index/txn/MutableRollbackIT.java    |  2 +-
 .../phoenix/end2end/index/txn/RollbackIT.java   |  1 -
 .../end2end/index/txn/TxWriteFailureIT.java     |  2 +-
 .../org/apache/phoenix/tx/TransactionIT.java    | 23 ++++++++++++++++++++
 .../org/apache/phoenix/tx/TxCheckpointIT.java   |  1 -
 .../phoenix/exception/SQLExceptionCode.java     |  1 +
 .../apache/phoenix/schema/MetaDataClient.java   |  5 +++++
 .../transaction/PhoenixTransactionProvider.java |  1 +
 13 files changed, 41 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
index 881c540..d676051 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexIT.java
@@ -122,7 +122,6 @@ public class ImmutableIndexIT extends 
BaseUniqueNamesOwnClusterIT {
                     { false, true, "TEPHRA", false }, { false, true, "TEPHRA", 
true },
                                { true, false, null, false }, { true, false, 
null, true },
                     { true, true, "TEPHRA", false }, { true, true, "TEPHRA", 
true },
-                    { true, true, "OMID", false }, 
                 }), 2);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
index c1221eb..176b36f 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalImmutableTxIndexIT.java
@@ -34,7 +34,6 @@ public class LocalImmutableTxIndexIT extends BaseIndexIT {
         return TestUtil.filterTxParamData(
                 Arrays.asList(new Object[][] {
                     { true, false, "TEPHRA", false }, { true, false, "TEPHRA", 
true },
-                    { true, false, "OMID", false }
                }), 2);
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
index c723dfe..d1b7f53 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/LocalMutableTxIndexIT.java
@@ -34,7 +34,6 @@ public class LocalMutableTxIndexIT extends BaseIndexIT {
         return TestUtil.filterTxParamData(
                 Arrays.asList(new Object[][] {
                     { true, true, "TEPHRA", false }, { true, true, "TEPHRA", 
true },
-                    { true, true, "OMID", false },
                }), 2);
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
index f09901e..f166b6d 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureIT.java
@@ -66,6 +66,8 @@ import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.schema.SortOrder;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
+import org.apache.phoenix.transaction.TransactionFactory;
 import org.apache.phoenix.util.IndexScrutiny;
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
@@ -103,6 +105,7 @@ public class MutableIndexFailureIT extends BaseTest {
     private String fullIndexName;
 
     private final boolean transactional;
+    private final PhoenixTransactionProvider transactionProvider;
     private final boolean localIndex;
     private final String tableDDLOptions;
     private final boolean isNamespaceMapped;
@@ -118,6 +121,8 @@ public class MutableIndexFailureIT extends BaseTest {
 
     public MutableIndexFailureIT(String transactionProvider, boolean 
localIndex, boolean isNamespaceMapped, Boolean disableIndexOnWriteFailure, 
boolean failRebuildTask, Boolean throwIndexWriteFailure) {
         this.transactional = transactionProvider != null;
+        this.transactionProvider = transactionProvider == null ? null :
+            
TransactionFactory.getTransactionProvider(TransactionFactory.Provider.valueOf(transactionProvider));
         this.localIndex = localIndex;
         this.tableDDLOptions = " SALT_BUCKETS=2, COLUMN_ENCODED_BYTES=NONE" + 
(transactional ? 
(",TRANSACTIONAL=true,TRANSACTION_PROVIDER='"+transactionProvider+"'") : "") 
                 + (disableIndexOnWriteFailure == null ? "" : (", " + 
PhoenixIndexFailurePolicy.DISABLE_INDEX_ON_WRITE_FAILURE + "=" + 
disableIndexOnWriteFailure))
@@ -184,8 +189,6 @@ public class MutableIndexFailureIT extends BaseTest {
                     { "TEPHRA", true, true, false, false, null},
                     { "TEPHRA", false, false, false, false, null},
                     { "TEPHRA", false, true, false, false, null},
-                    { "OMID", true, false, false, false, null},
-                    { "OMID", true, true, false, false, null},
                     { "OMID", false, false, false, false, null},
                     { "OMID", false, true, false, false, null},
     
@@ -266,7 +269,10 @@ public class MutableIndexFailureIT extends BaseTest {
             // Create other index which should be local/global if the other 
index is global/local to
             // check the drop index.
             conn.createStatement().execute(
-                    "CREATE "  + (!localIndex ? "LOCAL " : "") + " INDEX " + 
secondIndexName + " ON " + fullTableName + " (v2) INCLUDE (v1)");
+                    "CREATE "  + ((!localIndex && 
+                            (transactionProvider == null 
+                            || 
!transactionProvider.isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX)))
 
+                            ? "LOCAL " : "") + " INDEX " + secondIndexName + " 
ON " + fullTableName + " (v2) INCLUDE (v1)");
             conn.createStatement().execute(
                     "CREATE " + (localIndex ? "LOCAL " : "") + " INDEX " + 
thirdIndexName + " ON " + fullTableName + " (v1) INCLUDE (v2)");
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
index d5f7bd1..c6975ab 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/MutableIndexFailureWithNamespaceIT.java
@@ -72,7 +72,6 @@ public class MutableIndexFailureWithNamespaceIT extends 
MutableIndexFailureIT {
                 { "OMID", false, true, true, false, null},
                 { null, true, true, true, false, null},
                 { "TEPHRA", true, true, null, false, null},
-                { "OMID", true, true, null, false, null},
                 { null, false, true, true, true, null},
                 { null, false, true, false, true, false},
                 } 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
index 40c6cab..f807a2b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/MutableRollbackIT.java
@@ -57,7 +57,7 @@ public class MutableRollbackIT extends 
ParallelStatsDisabledIT {
     public static Collection<Object[]> data() {
         return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {     
             { false, "TEPHRA"}, { true, "TEPHRA"},
-            { false, "OMID"}, { true, "OMID"},
+            { false, "OMID"}, 
             }),1);
     }
        

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
index 4b5fa09..ff9f14b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/RollbackIT.java
@@ -70,7 +70,6 @@ public class RollbackIT extends ParallelStatsDisabledIT {
                  { false, false, "TEPHRA" }, { false, true, "TEPHRA"  },
                  { true, false, "TEPHRA"  }, { true, true, "TEPHRA"  },
                  { false, false, "OMID" }, { false, true, "OMID"  },
-                 { true, false, "OMID"  }, { true, true, "OMID"  },
            }),2);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
index 70ea133..1ce5fc4 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/txn/TxWriteFailureIT.java
@@ -97,7 +97,7 @@ public class TxWriteFailureIT extends 
BaseUniqueNamesOwnClusterIT {
     public static Collection<Object[]> data() {
         return TestUtil.filterTxParamData(Arrays.asList(new Object[][] {
                  { false, false, "TEPHRA" }, { false, true, "TEPHRA" }, { 
true, false, "TEPHRA" }, { true, true, "TEPHRA" },
-                 { false, false, "OMID" }, { false, true, "OMID" }, { true, 
false, "OMID" }, { true, true, "OMID" },
+                 { false, false, "OMID" }, { false, true, "OMID" }, 
            }), 2);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/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 1a8cb19..b1866db 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
@@ -61,6 +61,7 @@ import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTableKey;
 import org.apache.phoenix.transaction.PhoenixTransactionContext;
+import org.apache.phoenix.transaction.PhoenixTransactionProvider;
 import org.apache.phoenix.transaction.PhoenixTransactionProvider.Feature;
 import org.apache.phoenix.transaction.TransactionFactory;
 import org.apache.phoenix.util.EnvironmentEdgeManager;
@@ -130,6 +131,7 @@ public class TransactionIT  extends ParallelStatsDisabledIT 
{
             throw new DoNotRetryIOException();
         }
     }
+    
     @Test
     public void testWithMixOfTxProviders() throws Exception {
         // No sense in running the test with every providers, so just run it 
with the default one
@@ -176,6 +178,27 @@ public class TransactionIT  extends 
ParallelStatsDisabledIT {
     }
     
     @Test
+    public void testPreventLocalIndexCreation() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            for (TransactionFactory.Provider provider : 
TransactionFactory.Provider.values()) {
+                if (provider.runTests() && 
provider.getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX))
 {
+                    String tableName = generateUniqueName();
+                    conn.createStatement().execute(
+                            "CREATE TABLE " + tableName + " (k VARCHAR NOT 
NULL PRIMARY KEY, v1 VARCHAR) TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + 
provider + "'");
+                    String indexName = generateUniqueName();
+                    try {
+                        conn.createStatement().execute("CREATE LOCAL INDEX " + 
indexName + "_IDX ON " + tableName + " (v1) INCLUDE(v2)");
+                        fail();
+                    } catch (SQLException e) {
+                        
assertEquals(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE.getErrorCode(),
 e.getErrorCode());
+                    }
+                }
+            }
+        }
+    }
+
+    @Test
     public void testQueryWithSCN() throws Exception {
         String tableName = generateUniqueName();
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
index 9c49a5e..f8946e5 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TxCheckpointIT.java
@@ -84,7 +84,6 @@ public class TxCheckpointIT extends ParallelStatsDisabledIT {
                 { false, false, false, "TEPHRA" }, { false, false, true, 
"TEPHRA" }, { false, true, false, "TEPHRA" }, { false, true, true, "TEPHRA" },
                 { true, false, false, "TEPHRA" }, { true, false, true, 
"TEPHRA" }, { true, true, false, "TEPHRA" }, { true, true, true, "TEPHRA" },
                 { false, false, false, "OMID" }, { false, true, false, "OMID" 
}, 
-                { true, false, false, "OMID" }, { true, true, false, "OMID" },
            }),3);
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 61a4a08..c0a81ec 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -302,6 +302,7 @@ public enum SQLExceptionCode {
     UNSUPPORTED_STORAGE_FORMAT_FOR_TXN_PROVIDER(1095, "44A26", "Only 
ONE_CELL_PER_COLUMN storage scheme is supported for"),
     CANNOT_SWITCH_TXN_PROVIDERS(1096, "44A27", "Cannot switch transaction 
providers."),
     TTL_UNSUPPORTED_FOR_TXN_TABLE(10947, "44A28", "TTL is not supported for"),
+    CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE(10948, "44A29", "Local indexes 
cannot be created for"),
 
     /** Sequence related */
     SEQUENCE_ALREADY_EXIST(1200, "42Z00", "Sequence already exists.", new 
Factory() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/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 44b0a47..d7c38d0 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
@@ -1547,6 +1547,11 @@ public class MetaDataClient {
                         throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_INDEX_ON_MUTABLE_TABLE_WITH_ROWTIMESTAMP).setTableName(indexTableName.getTableName()).build().buildException();
                     }
                 }
+                if (dataTable.isTransactional() 
+                        && isLocalIndex 
+                        && 
dataTable.getTransactionProvider().getTransactionProvider().isUnsupported(PhoenixTransactionProvider.Feature.ALLOW_LOCAL_INDEX))
 {
+                    throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE).setMessage(dataTable.getTransactionProvider().name()).setTableName(indexTableName.getTableName()).build().buildException();
+                }
                 int posOffset = 0;
                 List<PColumn> pkColumns = dataTable.getPKColumns();
                 Set<RowKeyColumnExpression> unusedPkColumns;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7b5a49a5/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
index a3954c1..72424fb 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/transaction/PhoenixTransactionProvider.java
@@ -33,6 +33,7 @@ public interface PhoenixTransactionProvider {
         
COLUMN_ENCODING(SQLExceptionCode.UNSUPPORTED_COLUMN_ENCODING_FOR_TXN_PROVIDER),
         MAINTAIN_LOCAL_INDEX_ON_SERVER(null),
         SET_TTL(SQLExceptionCode.TTL_UNSUPPORTED_FOR_TXN_TABLE),
+        
ALLOW_LOCAL_INDEX(SQLExceptionCode.CANNOT_CREATE_LOCAL_INDEX_FOR_TXN_TABLE)
         ;
         
         private final SQLExceptionCode code;

Reply via email to