You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2021/11/12 08:55:35 UTC
[phoenix] branch 5.1 updated: PHOENIX-6586 Set
NORMALIZATION_ENABLED to false on salted tables
This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 5.1
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push:
new 712babc PHOENIX-6586 Set NORMALIZATION_ENABLED to false on salted tables
712babc is described below
commit 712babcddd078a0e0b15d3510226ef615ed4a197
Author: Istvan Toth <st...@apache.org>
AuthorDate: Thu Nov 4 15:48:27 2021 +0100
PHOENIX-6586 Set NORMALIZATION_ENABLED to false on salted tables
---
.../org/apache/phoenix/end2end/CreateTableIT.java | 58 ++++++++++++++++++++++
.../apache/phoenix/exception/SQLExceptionCode.java | 3 +-
.../phoenix/query/ConnectionQueryServicesImpl.java | 10 ++++
.../org/apache/phoenix/schema/MetaDataClient.java | 6 +++
4 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
index 3f62343..fd48e5f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java
@@ -45,6 +45,7 @@ import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.ipc.PhoenixRpcSchedulerFactory;
import org.apache.hadoop.hbase.regionserver.BloomType;
import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
@@ -1187,6 +1188,63 @@ public class CreateTableIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testNormalizerIsDisbledForSalted() throws Exception {
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+
+ String mtTableName = generateUniqueName();
+ String mtViewName = generateUniqueName();
+ String mtIndexName = generateUniqueName();
+
+ String conflictTableName = generateUniqueName();
+
+ String ddl =
+ "create table " + tableName + " ( id integer PRIMARY KEY," + " col1 integer,"
+ + " col2 bigint" + " ) SALT_BUCKETS=4";
+ String indexDdl =
+ "create index IF NOT EXISTS " + indexName + " on " + tableName + " (col2)";
+ String mtDdl =
+ "CREATE TABLE " + mtTableName + " (TenantId UNSIGNED_INT NOT NULL ,"
+ + " Id UNSIGNED_INT NOT NULL ," + " val VARCHAR, "
+ + " CONSTRAINT pk PRIMARY KEY(TenantId, Id) "
+ + " ) MULTI_TENANT=true, SALT_BUCKETS=4";
+ String mtViewDdl =
+ "CREATE VIEW " + mtViewName + "(view_column CHAR(15)) AS " + " SELECT * FROM "
+ + mtTableName + " WHERE val='L' ";
+ String mtIndexDdl = "CREATE INDEX " + mtIndexName + " on " + mtViewName + " (view_column) ";
+
+ String confictDdl =
+ "create table " + conflictTableName + " ( id integer PRIMARY KEY,"
+ + " col1 integer," + " col2 bigint" + " ) SALT_BUCKETS=4, "
+ + TableDescriptorBuilder.NORMALIZATION_ENABLED + "=true";
+
+ Properties props = new Properties();
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute(ddl);
+ conn.createStatement().execute(indexDdl);
+ conn.createStatement().execute(mtDdl);
+ conn.createStatement().execute(mtViewDdl);
+ conn.createStatement().execute(mtIndexDdl);
+
+ Admin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin();
+ assertEquals("false", admin.getDescriptor(TableName.valueOf(tableName))
+ .getValue(TableDescriptorBuilder.NORMALIZATION_ENABLED));
+ assertEquals("false", admin.getDescriptor(TableName.valueOf(indexName))
+ .getValue(TableDescriptorBuilder.NORMALIZATION_ENABLED));
+ assertEquals("false", admin.getDescriptor(TableName.valueOf(mtTableName))
+ .getValue(TableDescriptorBuilder.NORMALIZATION_ENABLED));
+ assertEquals("false", admin.getDescriptor(TableName.valueOf("_IDX_" + mtTableName))
+ .getValue(TableDescriptorBuilder.NORMALIZATION_ENABLED));
+
+ try {
+ conn.createStatement().execute(confictDdl);
+ fail("Should have thrown an exception");
+ } catch (Exception e) {
+ assertTrue(e instanceof SQLException);
+ }
+ }
+
public static long verifyLastDDLTimestamp(String dataTableFullName, long startTS, Connection conn) throws SQLException {
long endTS = EnvironmentEdgeManager.currentTimeMillis();
//Now try the PTable API
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 17157db..0a9c961 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
@@ -259,13 +259,14 @@ public enum SQLExceptionCode {
INVALID_BUCKET_NUM(1021, "42Y80", "Salt bucket numbers should be with 1 and 256."),
NO_SPLITS_ON_SALTED_TABLE(1022, "42Y81", "Should not specify split points on salted table with default row key order."),
SALT_ONLY_ON_CREATE_TABLE(1024, "42Y82", "Salt bucket number may only be specified when creating a table."),
+ NO_NORMALIZER_ON_SALTED_TABLE(1147, "42Y86", "Should not enable normalizer on salted table."),
SET_UNSUPPORTED_PROP_ON_ALTER_TABLE(1025, "42Y83", "Unsupported property set in ALTER TABLE command."),
CANNOT_ADD_NOT_NULLABLE_COLUMN(1038, "42Y84", "Only nullable columns may be added for a pre-existing table."),
NO_MUTABLE_INDEXES(1026, "42Y85", "Mutable secondary indexes are only supported for HBase version " + MetaDataUtil.decodeHBaseVersionAsString(MetaDataProtocol.MUTABLE_SI_VERSION_THRESHOLD) + " and above."),
INVALID_INDEX_STATE_TRANSITION(1028, "42Y87", "Invalid index state transition."),
INVALID_MUTABLE_INDEX_CONFIG(1029, "42Y88", "Mutable secondary indexes must have the "
+ IndexManagementUtil.WAL_EDIT_CODEC_CLASS_KEY + " property set to "
- + IndexManagementUtil.INDEX_WAL_EDIT_CODEC_CLASS_NAME + " in the hbase-sites.xml of every region server."),
+ + IndexManagementUtil.INDEX_WAL_EDIT_CODEC_CLASS_NAME + " in the hbase-sites.xml of every region server."),
CANNOT_CREATE_DEFAULT(1031, "42Y90", "Cannot create column with a stateful default value."),
CANNOT_CREATE_DEFAULT_ROWTIMESTAMP(1032, "42Y90", "Cannot create ROW_TIMESTAMP column with a default value."),
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 88ca0a6..9664210 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
@@ -1430,6 +1430,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
PBoolean.INSTANCE.toObject(newDesc.build().getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) {
newDesc.setRegionSplitPolicyClassName(IndexRegionSplitPolicy.class.getName());
}
+ if (props.get(PhoenixDatabaseMetaData.SALT_BUCKETS) != null
+ && (Integer) (props.get(PhoenixDatabaseMetaData.SALT_BUCKETS)) > 0) {
+ if (props.get(TableDescriptorBuilder.NORMALIZATION_ENABLED) != null
+ && (Boolean)(props.get(TableDescriptorBuilder.NORMALIZATION_ENABLED))) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_NORMALIZER_ON_SALTED_TABLE)
+ .setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalTableName))
+ .setTableName(SchemaUtil.getTableNameFromFullName(physicalTableName)).build().buildException();
+ }
+ newDesc.setNormalizationEnabled(false);
+ }
try {
if (splits == null) {
admin.createTable(newDesc.build());
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 31f43d0..32270ab 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
@@ -1749,6 +1749,12 @@ public class MetaDataClient {
if (dataTable.getDefaultFamilyName() != null && dataTable.getType() != PTableType.VIEW && !allocateIndexId) {
statement.getProps().put("", new Pair<String,Object>(DEFAULT_COLUMN_FAMILY_NAME,dataTable.getDefaultFamilyName().getString()));
}
+ // While SALT_BUCKETS would get copied in SYSCAT automatically, we need to add this
+ // explicitly so that the normalizer disabler logic can trigger later
+ if (dataTable.getBucketNum() != null && dataTable.getBucketNum() > 0
+ && TableProperty.SALT_BUCKETS.getValue(tableProps) == null) {
+ tableProps.put(SALT_BUCKETS, dataTable.getBucketNum());
+ }
PrimaryKeyConstraint pk = FACTORY.primaryKey(null, allPkColumns);
tableProps.put(MetaDataUtil.DATA_TABLE_NAME_PROP_NAME, dataTable.getName().getString());
CreateTableStatement tableStatement = FACTORY.createTable(indexTableName, statement.getProps(), columnDefs, pk, statement.getSplitNodes(), PTableType.INDEX, statement.ifNotExists(), null, null, statement.getBindCount(), null);