Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,10 @@ public void init(AtomicBoolean stop) throws Exception {
checkInterval = conf.getTimeVar(HiveConf.ConfVars.HIVE_COMPACTOR_CHECK_INTERVAL, TimeUnit.MILLISECONDS);
metricsEnabled = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.METRICS_ENABLED) &&
MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.METASTORE_ACIDMETRICS_EXT_ON);
boolean isSupportAcid = MetastoreConf.getBoolVar(conf, MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID);
optimizers = Arrays.stream(MetastoreConf.getTrimmedStringsVar(conf,
MetastoreConf.ConfVars.COMPACTOR_INITIATOR_TABLE_OPTIMIZERS))
.filter(e -> isSupportAcid || !e.equalsIgnoreCase(MetastoreConf.ACID_TABLE_OPTIMIZER_CLASS))
.map(this::instantiateTableOptimizer).toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public class MetastoreConf {
@VisibleForTesting
static final String HIVE_ALTER_HANDLE_CLASS =
"org.apache.hadoop.hive.metastore.HiveAlterHandler";
@VisibleForTesting
static final String MATERIALZIATIONS_REBUILD_LOCK_CLEANER_TASK_CLASS =
public static final String MATERIALZIATIONS_REBUILD_LOCK_CLEANER_TASK_CLASS =
"org.apache.hadoop.hive.metastore.MaterializationsRebuildLockCleanerTask";
@VisibleForTesting
static final String METASTORE_TASK_THREAD_CLASS =
Expand All @@ -86,24 +85,21 @@ public class MetastoreConf {
@VisibleForTesting
static final String EVENT_CLEANER_TASK_CLASS =
"org.apache.hadoop.hive.metastore.events.EventCleanerTask";
static final String ACID_METRICS_TASK_CLASS =
public static final String ACID_METRICS_TASK_CLASS =
"org.apache.hadoop.hive.metastore.metrics.AcidMetricService";
static final String ACID_METRICS_LOGGER_CLASS =
public static final String ACID_METRICS_LOGGER_CLASS =
"org.apache.hadoop.hive.metastore.metrics.AcidMetricLogger";
@VisibleForTesting
static final String METASTORE_DELEGATION_MANAGER_CLASS =
"org.apache.hadoop.hive.metastore.security.MetastoreDelegationTokenManager";
@VisibleForTesting
static final String ACID_HOUSEKEEPER_SERVICE_CLASS =
public static final String ACID_HOUSEKEEPER_SERVICE_CLASS =
"org.apache.hadoop.hive.metastore.txn.service.AcidHouseKeeperService";
@VisibleForTesting
static final String COMPACTION_HOUSEKEEPER_SERVICE_CLASS =
"org.apache.hadoop.hive.metastore.txn.service.CompactionHouseKeeperService";
@VisibleForTesting
static final String ACID_TXN_CLEANER_SERVICE_CLASS =
public static final String ACID_TXN_CLEANER_SERVICE_CLASS =
"org.apache.hadoop.hive.metastore.txn.service.AcidTxnCleanerService";
@VisibleForTesting
static final String ACID_OPEN_TXNS_COUNTER_SERVICE_CLASS =
public static final String ACID_OPEN_TXNS_COUNTER_SERVICE_CLASS =
"org.apache.hadoop.hive.metastore.txn.service.AcidOpenTxnsCounterService";
@VisibleForTesting
static final String ICEBERG_TABLE_SNAPSHOT_EXPIRY_SERVICE_CLASS =
Expand All @@ -112,6 +108,10 @@ public class MetastoreConf {
"metastore.authentication.ldap.userMembershipKey";
public static final String METASTORE_RETRYING_HANDLER_CLASS =
"org.apache.hadoop.hive.metastore.RetryingHMSHandler";
public static final String ACID_TABLE_OPTIMIZER_CLASS =
"org.apache.hadoop.hive.ql.txn.compactor.AcidTableOptimizer";
public static final String ICEBERG_TABLE_OPTIMIZER_CLASS =
"org.apache.iceberg.mr.hive.compaction.IcebergTableOptimizer";

private static final Map<String, ConfVars> metaConfs = new HashMap<>();
private static volatile URL hiveSiteURL = null;
Expand Down Expand Up @@ -662,8 +662,7 @@ public enum ConfVars {
"Enable table caching in the initiator. Currently the cache is cleaned after each cycle."),
COMPACTOR_INITIATOR_TABLE_OPTIMIZERS("compactor.table.optimizers",
"hive.compactor.table.optimizers",
"org.apache.hadoop.hive.ql.txn.compactor.AcidTableOptimizer," +
"org.apache.iceberg.mr.hive.compaction.IcebergTableOptimizer",
ACID_TABLE_OPTIMIZER_CLASS + "," + ICEBERG_TABLE_OPTIMIZER_CLASS,
"Comma separated list of table optimizers executed by compaction Initiator."),
COMPACTOR_WORKER_THREADS("metastore.compactor.worker.threads",
"hive.compactor.worker.threads", 0,
Expand Down Expand Up @@ -1987,6 +1986,8 @@ public enum ConfVars {
"The maximum non-native tables allowed per table type during collecting the summary."),
METADATA_SUMMARY_NONNATIVE_THREADS("hive.metatool.summary.nonnative.threads", "hive.metatool.summary.nonnative.threads", 20,
"Number of threads to be allocated for MetaToolTaskMetadataSummary for collecting the non-native table's summary."),
METASTORE_SUPPORT_ACID("metastore.support.acid", "hive.metastore.support.acid", true,
"Whether to support acid functionality in Hive metastore server."),

// These are all values that we put here just for testing
STR_TEST_ENTRY("test.str", "hive.test.str", "defaultval", "comment"),
Expand Down
5 changes: 5 additions & 0 deletions standalone-metastore/metastore-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.server</groupId>
<artifactId>apacheds-server-integ</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,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());
}
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())) {
Expand All @@ -629,6 +649,7 @@ public Table transformCreateTable(Table table, List<String> processorCapabilitie
if (params == null) {
params = new HashMap<>();
}
transformToExternalIfAcidNotSupported(newTable);
String tableType = newTable.getTableType();
String txnal = null;
String txn_properties = null;
Expand Down Expand Up @@ -682,8 +703,7 @@ public Table transformCreateTable(Table table, List<String> processorCapabilitie
throw new MetaException("Processor has no capabilities, cannot create an ACID table.");
}


newTable = validateTablePaths(table);
validateTablePaths(newTable);
if (isInsertAcid) { // MICRO_MANAGED Tables
if (processorCapabilities.contains(HIVEMANAGEDINSERTWRITE)) {
LOG.debug("Processor has required capabilities to be able to create INSERT-only tables");
Expand All @@ -704,7 +724,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;
Expand Down Expand Up @@ -744,7 +764,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,13 @@ public List<MetaStoreThread> getCompactorThreads() throws Exception {
compactors.add(initiator);
}
if (MetastoreConf.getBoolVar(configuration, MetastoreConf.ConfVars.COMPACTOR_CLEANER_ON)) {
MetaStoreThread cleaner = instantiateThread("org.apache.hadoop.hive.ql.txn.compactor.Cleaner");
compactors.add(cleaner);
if (MetastoreConf.getBoolVar(configuration, MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID)) {
MetaStoreThread cleaner = instantiateThread("org.apache.hadoop.hive.ql.txn.compactor.Cleaner");
compactors.add(cleaner);
} else {
HiveMetaStore.LOG.warn("Compactor Cleaner is turned On. But, automatic compaction cleaner will not run " +
"when the {} property is set to false.", MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID.getHiveName());
}
}
return compactors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import com.cronutils.utils.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import com.google.common.collect.ImmutableSet;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.metastore.HiveMetaStore;
import org.apache.hadoop.hive.metastore.MetastoreTaskThread;
Expand Down Expand Up @@ -69,6 +69,12 @@ public List<MetastoreTaskThread> getRemoteOnlyTasks() throws Exception {

Collection<String> taskNames =
MetastoreConf.getStringCollection(configuration, MetastoreConf.ConfVars.TASK_THREADS_REMOTE_ONLY);
if (!MetastoreConf.getBoolVar(configuration, MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID)) {
taskNames.removeAll(ImmutableSet.of(MetastoreConf.ACID_OPEN_TXNS_COUNTER_SERVICE_CLASS,
MetastoreConf.ACID_HOUSEKEEPER_SERVICE_CLASS,
MetastoreConf.ACID_TXN_CLEANER_SERVICE_CLASS,
MetastoreConf.MATERIALZIATIONS_REBUILD_LOCK_CLEANER_TASK_CLASS));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hive provides support for iceberg tables materialized views

}
for (String taskName : taskNames) {
if (CompactionHouseKeeperService.class.getName().equals(taskName) && !isCompactorEnabled) {
continue;
Expand All @@ -85,6 +91,10 @@ public List<MetastoreTaskThread> getAlwaysTasks() throws Exception {
List<MetastoreTaskThread> alwaysTasks = new ArrayList<>();
Collection<String> taskNames =
MetastoreConf.getStringCollection(configuration, MetastoreConf.ConfVars.TASK_THREADS_ALWAYS);
if (!MetastoreConf.getBoolVar(configuration, MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID)) {
taskNames.removeAll(ImmutableSet.of(MetastoreConf.ACID_METRICS_TASK_CLASS,
MetastoreConf.ACID_METRICS_LOGGER_CLASS));
}
for (String taskName : taskNames) {
MetastoreTaskThread task =
JavaUtils.newInstance(JavaUtils.getClass(taskName, MetastoreTaskThread.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ public CompactionHouseKeeperService() {

@Override
protected void initTasks(){
tasks = ImmutableMap.<FailableRunnable<MetaException>, String>builder()
.put(txnHandler::removeDuplicateCompletedTxnComponents,
"Cleaning duplicate COMPLETED_TXN_COMPONENTS entries")
.put(txnHandler::purgeCompactionHistory, "Cleaning obsolete compaction history entries")
.build();
ImmutableMap.Builder<FailableRunnable<MetaException>, String> taskBuilder =
ImmutableMap.<FailableRunnable<MetaException>, String>builder()
.put(txnHandler::purgeCompactionHistory, "Cleaning obsolete compaction history entries");
if (MetastoreConf.getBoolVar(getConf(), MetastoreConf.ConfVars.METASTORE_SUPPORT_ACID)) {
taskBuilder.put(txnHandler::removeDuplicateCompletedTxnComponents,
"Cleaning duplicate COMPLETED_TXN_COMPONENTS entries");
}
tasks = taskBuilder.build();
}

@Override
Expand Down
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"));
}
}
Loading