-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-29520: Add configuration to enable/disable ACID functionality in Hive Metastore #6416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -614,6 +614,26 @@ private static final Path getDefaultPath(IHMSHandler hmsHandler, Database db, St | |
|
|
||
| } | ||
|
|
||
| private void transformToExternalIfAcidNotSupported(Table table) throws MetaException { | ||
| Map<String, String> params = table.getParameters(); | ||
| boolean isSupportAcid = MetastoreConf.getBoolVar(hmsHandler.getConf(), | ||
| ConfVars.METASTORE_SUPPORT_ACID); | ||
| if (!isSupportAcid) { | ||
| if (Boolean.parseBoolean(params.get(TABLE_IS_TRANSACTIONAL))) { | ||
| throw new MetaException("ACID tables are not permitted when the " | ||
| + ConfVars.METASTORE_SUPPORT_ACID.getHiveName() + " property is set to false"); | ||
| } | ||
| if (TableType.MANAGED_TABLE.name().equals(table.getTableType())) { | ||
| table.setTableType(TableType.EXTERNAL_TABLE.toString()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we translate the manage table to external just by changing the table type, the table data wouldn't be deleted when the table dropped, as the following params are missing:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is intentionally done. When the acid functionality is disabled, they are purely external tables. They are not manged tables transalated to external ones.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this means all tables' data cannot be removed upon dropping the table, until we drop these table files directly, is it supposed? |
||
| } | ||
| if (TableType.EXTERNAL_TABLE.name().equals(table.getTableType())) { | ||
| params.put(HiveMetaHook.EXTERNAL, "TRUE"); | ||
| } | ||
| params.remove(TABLE_IS_TRANSACTIONAL); | ||
| params.remove(TABLE_TRANSACTIONAL_PROPERTIES); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Table transformCreateTable(Table table, List<String> processorCapabilities, String processorId) throws MetaException { | ||
| if (!defaultCatalog.equalsIgnoreCase(table.getCatName())) { | ||
|
|
@@ -628,6 +648,7 @@ public Table transformCreateTable(Table table, List<String> processorCapabilitie | |
| if (params == null) { | ||
| params = new HashMap<>(); | ||
| } | ||
| transformToExternalIfAcidNotSupported(newTable); | ||
| String tableType = newTable.getTableType(); | ||
| String dbName = table.getDbName(); | ||
| Database db = null; | ||
|
|
@@ -673,8 +694,8 @@ public Table transformCreateTable(Table table, List<String> processorCapabilitie | |
| throw new MetaException("Processor has no capabilities, cannot create an ACID table."); | ||
| } | ||
|
|
||
| newTable = validateTablePaths(table); | ||
| if (MetaStoreUtils.isInsertOnlyTableParam(table.getParameters())) { // MICRO_MANAGED Tables | ||
| validateTablePaths(newTable); | ||
| if (MetaStoreUtils.isInsertOnlyTableParam(newTable.getParameters())) { // MICRO_MANAGED Tables | ||
| if (processorCapabilities.contains(HIVEMANAGEDINSERTWRITE)) { | ||
| LOG.debug("Processor has required capabilities to be able to create INSERT-only tables"); | ||
| return newTable; | ||
|
|
@@ -694,7 +715,7 @@ public Table transformCreateTable(Table table, List<String> processorCapabilitie | |
| } | ||
| } else if (TableType.EXTERNAL_TABLE.name().equals(tableType)) { | ||
| LOG.debug("Table to be created is of type " + tableType); | ||
| newTable = validateTablePaths(table); | ||
| validateTablePaths(newTable); | ||
| } | ||
| LOG.info("Transformer returning table:" + newTable.toString()); | ||
| return newTable; | ||
|
|
@@ -734,7 +755,7 @@ public Table transformAlterTable(Table oldTable, Table newTable, List<String> pr | |
| LOG.info("Starting translation for Alter table for processor " + processorId + " with " + processorCapabilities | ||
| + " on table " + newTable.getTableName()); | ||
|
|
||
|
|
||
| transformToExternalIfAcidNotSupported(newTable); | ||
| if (tableLocationChanged(oldTable, newTable)) { | ||
| validateTablePaths(newTable); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /* | ||
| * 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.hadoop.hive.metastore; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest; | ||
| import org.apache.hadoop.hive.metastore.api.MetaException; | ||
| import org.apache.hadoop.hive.metastore.api.Table; | ||
| import org.apache.hadoop.hive.metastore.client.builder.DatabaseBuilder; | ||
| import org.apache.hadoop.hive.metastore.client.builder.TableBuilder; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars; | ||
| import org.apache.hadoop.util.StringUtils; | ||
| import org.apache.thrift.TException; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.jupiter.api.Assertions; | ||
|
|
||
| import static org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.TABLE_IS_TRANSACTIONAL; | ||
|
|
||
| /** | ||
| * Tests to verify metastore without acid support. | ||
| */ | ||
| @Category(MetastoreUnitTest.class) | ||
| public class TestNoAcidSupport { | ||
| private static Configuration conf; | ||
| private static HiveMetaStoreClient client; | ||
| private static final String DB_NAME = "TestNoAcidSupport"; | ||
| private static final String TABLE_NAME = "t"; | ||
|
|
||
| @BeforeClass | ||
| public static void beforeTests() throws Exception { | ||
| conf = MetastoreConf.newMetastoreConf(); | ||
| MetastoreConf.setBoolVar(conf, ConfVars.METASTORE_SUPPORT_ACID, false); | ||
| client = new HiveMetaStoreClient(conf); | ||
| client.dropDatabase(DB_NAME, true, true, true); | ||
| new DatabaseBuilder().setName(DB_NAME).create(client, conf); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void afterTests() throws Exception { | ||
| try { | ||
| client.dropDatabase(DB_NAME, true, true, true); | ||
| client.close(); | ||
| } catch (Throwable e) { | ||
| System.err.println(StringUtils.stringifyException(e)); | ||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| @After | ||
| public void afterTest() throws TException { | ||
| client.dropTable(DB_NAME, TABLE_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateAcidTable() { | ||
| Exception exception = Assertions.assertThrows(MetaException.class, () -> { | ||
| new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME) | ||
| .addCol("i", ColumnType.INT_TYPE_NAME) | ||
| .setType(TableType.MANAGED_TABLE.name()) | ||
| .addTableParam(TABLE_IS_TRANSACTIONAL, "true") | ||
| .create(client, conf); | ||
| }); | ||
| Assertions.assertTrue(exception.getMessage().contains("ACID tables are not permitted when the " + | ||
| ConfVars.METASTORE_SUPPORT_ACID.getHiveName() + " property is set to false")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateManagedTableChangeToExternal() throws Exception { | ||
| new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME) | ||
| .addCol("i", ColumnType.INT_TYPE_NAME) | ||
| .setType(TableType.MANAGED_TABLE.name()) | ||
| .create(client, conf); | ||
| Table t = client.getTable(DB_NAME, TABLE_NAME); | ||
| Assertions.assertEquals(TableType.EXTERNAL_TABLE.name(), t.getTableType()); | ||
| Assertions.assertTrue(Boolean.parseBoolean(t.getParameters().get(HiveMetaHook.EXTERNAL))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateExternalTable() throws Exception { | ||
| new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME) | ||
| .addCol("i", ColumnType.INT_TYPE_NAME) | ||
| .setType(TableType.EXTERNAL_TABLE.name()) | ||
| .create(client, conf); | ||
| Table t = client.getTable(DB_NAME, TABLE_NAME); | ||
| Assertions.assertEquals(TableType.EXTERNAL_TABLE.name(), t.getTableType()); | ||
| Assertions.assertTrue(Boolean.parseBoolean(t.getParameters().get(HiveMetaHook.EXTERNAL))); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAlterToManagedTable() throws Exception { | ||
| new TableBuilder().setDbName(DB_NAME).setTableName(TABLE_NAME) | ||
| .addCol("i", ColumnType.INT_TYPE_NAME) | ||
| .setType(TableType.EXTERNAL_TABLE.name()) | ||
| .create(client, conf); | ||
| Table t = client.getTable(DB_NAME, TABLE_NAME); | ||
| Assertions.assertEquals(TableType.EXTERNAL_TABLE.name(), t.getTableType()); | ||
| t.setTableType(TableType.MANAGED_TABLE.name()); | ||
| t.getParameters().put(TABLE_IS_TRANSACTIONAL, "true"); | ||
| Exception exception = Assertions.assertThrows(MetaException.class, () -> { | ||
| client.alter_table(DB_NAME, TABLE_NAME, t); | ||
| }); | ||
| Assertions.assertTrue(exception.getMessage().contains("ACID tables are not permitted when the " + | ||
| ConfVars.METASTORE_SUPPORT_ACID.getHiveName() + " property is set to false")); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we throw the exception since we are able to transform a managed transactional table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not allow transactional tables when acid is disabled on HMS. Throwing exception to engine as an indication of it.