You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2019/03/28 23:58:48 UTC
[phoenix] branch 4.14-HBase-1.4 updated: PHOENIX-5207 Create index
if not exists fails incorrectly if table has 'maxIndexesPerTable' indexes
already
This is an automated email from the ASF dual-hosted git repository.
tdsilva pushed a commit to branch 4.14-HBase-1.4
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.14-HBase-1.4 by this push:
new a66d1a4 PHOENIX-5207 Create index if not exists fails incorrectly if table has 'maxIndexesPerTable' indexes already
a66d1a4 is described below
commit a66d1a4fd2be9c860eecb301822ab5406c92dda4
Author: Abhishek Singh Chouhan <ab...@gmail.com>
AuthorDate: Mon Mar 25 18:11:27 2019 -0700
PHOENIX-5207 Create index if not exists fails incorrectly if table has 'maxIndexesPerTable' indexes already
---
.../apache/phoenix/end2end/index/BaseIndexIT.java | 39 ++++++++++++++++++++++
.../phoenix/coprocessor/MetaDataEndpointImpl.java | 19 ++++++-----
2 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
index f914256..f677cd8 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/BaseIndexIT.java
@@ -42,6 +42,7 @@ import java.util.List;
import java.util.Properties;
import java.util.Random;
+import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.HConstants;
@@ -66,6 +67,8 @@ import org.apache.phoenix.jdbc.PhoenixStatement;
import org.apache.phoenix.parse.NamedTableNode;
import org.apache.phoenix.parse.TableName;
import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableImpl;
import org.apache.phoenix.schema.PTableKey;
@@ -1212,5 +1215,41 @@ public abstract class BaseIndexIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testMaxIndexesPerTable() throws SQLException {
+ String tableName = "TBL_" + generateUniqueName();
+ String indexName = "IND_" + generateUniqueName();
+ String fullTableName = SchemaUtil.getTableName(TestUtil.DEFAULT_SCHEMA_NAME, tableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ Configuration conf =
+ conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration();
+ int maxIndexes =
+ conf.getInt(QueryServices.MAX_INDEXES_PER_TABLE,
+ QueryServicesOptions.DEFAULT_MAX_INDEXES_PER_TABLE);
+ conn.createStatement()
+ .execute("CREATE TABLE " + fullTableName
+ + " (k VARCHAR NOT NULL PRIMARY KEY, \"V1\" VARCHAR, \"v2\" VARCHAR)"
+ + tableDDLOptions);
+ for (int i = 0; i < maxIndexes; i++) {
+ conn.createStatement().execute("CREATE " + (localIndex ? "LOCAL " : "") + "INDEX "
+ + indexName + i + " ON " + fullTableName + "(\"v2\") INCLUDE (\"V1\")");
+ }
+ try {
+ conn.createStatement()
+ .execute("CREATE " + (localIndex ? "LOCAL " : "") + "INDEX " + indexName
+ + maxIndexes + " ON " + fullTableName
+ + "(\"v2\") INCLUDE (\"V1\")");
+ fail("Expected exception TOO_MANY_INDEXES");
+ } catch (SQLException e) {
+ assertEquals(e.getErrorCode(), SQLExceptionCode.TOO_MANY_INDEXES.getErrorCode());
+ }
+ conn.createStatement()
+ .execute("CREATE " + (localIndex ? "LOCAL " : "") + "INDEX IF NOT EXISTS "
+ + indexName + "0" + " ON " + fullTableName
+ + "(\"v2\") INCLUDE (\"V1\")");
+ }
+ }
+
}
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 b35b27e..ea43581 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
@@ -1618,13 +1618,6 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
done.run(builder.build());
return;
}
- // make sure we haven't gone over our threshold for indexes on this table.
- if (execeededIndexQuota(tableType, parentTable)) {
- builder.setReturnCode(MetaDataProtos.MutationCode.TOO_MANY_INDEXES);
- builder.setMutationTime(EnvironmentEdgeManager.currentTimeMillis());
- done.run(builder.build());
- return;
- }
long parentTableSeqNumber;
if (tableType == PTableType.VIEW && viewPhysicalTableRow != null && request.hasClientVersion()) {
// Starting 4.5, the client passes the sequence number of the physical table in the table metadata.
@@ -1671,7 +1664,17 @@ public class MetaDataEndpointImpl extends MetaDataProtocol implements Coprocesso
return;
}
}
-
+
+ if (parentTableName != null) {
+ // make sure we haven't gone over our threshold for indexes on this table.
+ if (execeededIndexQuota(tableType, parentTable)) {
+ builder.setReturnCode(MetaDataProtos.MutationCode.TOO_MANY_INDEXES);
+ builder.setMutationTime(EnvironmentEdgeManager.currentTimeMillis());
+ done.run(builder.build());
+ return;
+ }
+ }
+
// Add cell for ROW_KEY_ORDER_OPTIMIZABLE = true, as we know that new tables
// conform the correct row key. The exception is for a VIEW, which the client
// sends over depending on its base physical table.