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 351546c3bc9edb69a435f04795b5ea6c3421f5b0..895faabbbc58bf89bceed6f3e0473a9bc6216bd5 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; @@ -78,7 +78,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 e2a7d7df3fc072ca7eb7addb1fff4378d592df77..2e6e847886b99fd2156c4b603951a84bd580e4b5 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -455,7 +455,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; @@ -468,7 +468,7 @@ public HiveConf getHiveConf() { } } - List getTransactionalListeners() { + List getTransactionalListeners() { return transactionalListeners; } @@ -542,7 +542,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 37327f8bd2ebf3f883fb3bd408d63f776b26406e..8f4ddfd6fbe466a85b7005560d0e027f3c24c68d 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreListenerNotifier.java @@ -39,6 +39,8 @@ import org.apache.hadoop.hive.metastore.events.DropTableEvent; import org.apache.hadoop.hive.metastore.events.InsertEvent; import org.apache.hadoop.hive.metastore.events.ListenerEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; @@ -51,6 +53,9 @@ */ @Private public class MetaStoreListenerNotifier { + + public static final Logger LOG = LoggerFactory.getLogger(MetaStoreListenerNotifier.class); + private interface EventNotifier { void notify(MetaStoreEventListener listener, ListenerEvent event) throws MetaException; } @@ -156,7 +161,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 { @@ -164,7 +169,16 @@ 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); + try { + notificationEvents.get(eventType).notify(listener, event); + } catch (Exception e) { + if (!(listener instanceof TransactionalMetaStoreEventListener)) { + LOG.warn("Exception encountered when notifying " + listener + " of " + + event + ". Logging and continuing: ", e); + } else { + throw e; + } + } } // Each listener called above might set a different parameter on the event. @@ -186,7 +200,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 { @@ -217,7 +231,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); + } + +}