diff --git hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java index 2a2cc7b6d66605da7c2968a3f7c4cee5d8f828c3..68d3cc10fdda06b7d23ac9aec2e1d844eaa6d555 100644 --- hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java +++ hcatalog/server-extensions/src/main/java/org/apache/hive/hcatalog/listener/DbNotificationListener.java @@ -29,11 +29,11 @@ import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler; -import org.apache.hadoop.hive.metastore.MetaStoreEventListener; import org.apache.hadoop.hive.metastore.MetaStoreEventListenerConstants; import org.apache.hadoop.hive.metastore.RawStore; import org.apache.hadoop.hive.metastore.RawStoreProxy; import org.apache.hadoop.hive.metastore.ReplChangeManager; +import org.apache.hadoop.hive.metastore.TransactionalMetaStoreEventListener; import org.apache.hadoop.hive.metastore.Warehouse; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.Function; @@ -87,7 +87,7 @@ * the database. Also, occasionally the thread needs to clean the database of old records. We * definitely don't want to do that as part of another metadata operation. */ -public class DbNotificationListener extends MetaStoreEventListener { +public class DbNotificationListener extends TransactionalMetaStoreEventListener { private static final Logger LOG = LoggerFactory.getLogger(DbNotificationListener.class.getName()); private static CleanerThread cleaner = null; diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java index ea90a8e4a2d8a79f4356818b11cdbf9eb870256d..28c3cfed6d74a0788fce889adb7de22db42f5c13 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java @@ -121,7 +121,7 @@ public void alterTable(RawStore msdb, Warehouse wh, String dbname, boolean success = false; boolean dataWasMoved = false; Table oldt = null; - List transactionalListeners = null; + List transactionalListeners = null; if (handler != null) { transactionalListeners = handler.getTransactionalListeners(); } @@ -377,7 +377,7 @@ public Partition alterPartition(final RawStore msdb, Warehouse wh, final String throws InvalidOperationException, InvalidObjectException, AlreadyExistsException, MetaException { boolean success = false; Partition oldPart = null; - List transactionalListeners = null; + List transactionalListeners = null; if (handler != null) { transactionalListeners = handler.getTransactionalListeners(); } @@ -599,7 +599,7 @@ public Partition alterPartition(final RawStore msdb, Warehouse wh, final String throws InvalidOperationException, InvalidObjectException, AlreadyExistsException, MetaException { List oldParts = new ArrayList(); List> partValsList = new ArrayList>(); - List transactionalListeners = null; + List transactionalListeners = null; if (handler != null) { transactionalListeners = handler.getTransactionalListeners(); } diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index b43b4df7cbaf278cd84d7e5e47e7b9669e1a61dc..acbef26f2bfcf5b14e5e1ed512d4b782b6d2217e 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -460,7 +460,7 @@ public HiveConf getHiveConf() { private AlterHandler alterHandler; private List preListeners; private List listeners; - private List transactionalListeners; + private List transactionalListeners; private List endFunctionListeners; private List initListeners; private Pattern partitionValidationPattern; @@ -473,7 +473,7 @@ public HiveConf getHiveConf() { } } - List getTransactionalListeners() { + List getTransactionalListeners() { return transactionalListeners; } @@ -547,7 +547,7 @@ public Object getValue() { hiveConf.getVar(HiveConf.ConfVars.METASTORE_EVENT_LISTENERS)); listeners.add(new SessionPropertiesListener(hiveConf)); listeners.add(new AcidEventListener(hiveConf)); - transactionalListeners = MetaStoreUtils.getMetaStoreListeners(MetaStoreEventListener.class,hiveConf, + transactionalListeners = MetaStoreUtils.getMetaStoreListeners(TransactionalMetaStoreEventListener.class,hiveConf, hiveConf.getVar(ConfVars.METASTORE_TRANSACTIONAL_EVENT_LISTENERS)); if (metrics != null) { listeners.add(new HMSMetricsListener(hiveConf, metrics)); diff --git metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java index 75dc89c7a225c42f256876492d798f6574d3fc01..331621ed2935b838dbd2f2564386e0d6c6f5dfa0 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java @@ -55,6 +55,7 @@ */ @Private public class MetaStoreListenerNotifier { + private interface EventNotifier { void notify(MetaStoreEventListener listener, ListenerEvent event) throws MetaException; } @@ -184,7 +185,7 @@ public void notify(MetaStoreEventListener listener, ListenerEvent event) throws * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ - public static Map notifyEvent(List listeners, + public static Map notifyEvent(List listeners, EventType eventType, ListenerEvent event) throws MetaException { @@ -192,7 +193,7 @@ public void notify(MetaStoreEventListener listener, ListenerEvent event) throws Preconditions.checkNotNull(event, "The event must not be null."); for (MetaStoreEventListener listener : listeners) { - notificationEvents.get(eventType).notify(listener, event); + notificationEvents.get(eventType).notify(listener, event); } // Each listener called above might set a different parameter on the event. @@ -214,7 +215,7 @@ public void notify(MetaStoreEventListener listener, ListenerEvent event) throws * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ - public static Map notifyEvent(List listeners, + public static Map notifyEvent(List listeners, EventType eventType, ListenerEvent event, EnvironmentContext environmentContext) throws MetaException { @@ -245,7 +246,7 @@ public void notify(MetaStoreEventListener listener, ListenerEvent event) throws * map if no parameters were updated or if no listeners were notified. * @throws MetaException If an error occurred while calling the listeners. */ - public static Map notifyEvent(List listeners, + public static Map notifyEvent(List listeners, EventType eventType, ListenerEvent event, EnvironmentContext environmentContext, diff --git metastore/src/java/org/apache/hadoop/hive/metastore/TransactionalMetaStoreEventListener.java metastore/src/java/org/apache/hadoop/hive/metastore/TransactionalMetaStoreEventListener.java new file mode 100644 index 0000000000000000000000000000000000000000..d7f1c644878d2f45c337536de76ba0d37029336b --- /dev/null +++ metastore/src/java/org/apache/hadoop/hive/metastore/TransactionalMetaStoreEventListener.java @@ -0,0 +1,39 @@ +/** + * 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; + +/** + * Special type of MetaStoreEventListener which should only be called in a transactional context + * and only if the transaction is successful. + * The events are expected to have a success status. + */ +public abstract class TransactionalMetaStoreEventListener extends MetaStoreEventListener { + + /** + * Constructor + * + * @param config + */ + public TransactionalMetaStoreEventListener(Configuration config) { + super(config); + } + +}