Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (revision 1079575) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (working copy) @@ -51,13 +51,13 @@ import org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet; import org.apache.hadoop.hive.metastore.api.PrincipalType; import org.apache.hadoop.hive.metastore.api.PrivilegeBag; -import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo; import org.apache.hadoop.hive.metastore.api.Role; import org.apache.hadoop.hive.metastore.api.Table; import org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore; import org.apache.hadoop.hive.metastore.api.Type; import org.apache.hadoop.hive.metastore.api.UnknownDBException; import org.apache.hadoop.hive.metastore.api.UnknownTableException; +import org.apache.hadoop.hive.ql.metadata.HiveUtils; import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hadoop.hive.thrift.HadoopThriftAuthBridge; import org.apache.thrift.TException; @@ -80,6 +80,7 @@ private final HiveConf conf; private String tokenStrForm; private final boolean localMetaStore; + private final HiveMetaStoreListener listener; // for thrift connects private int retries = 5; @@ -101,6 +102,9 @@ } this.conf = conf; + + listener = HiveUtils.getMetaStoreListener(conf); + localMetaStore = conf.getBoolean("hive.metastore.local", false); if (localMetaStore) { // instantiate the metastore server handler directly instead of connecting @@ -286,7 +290,9 @@ public Partition add_partition(Partition new_part) throws InvalidObjectException, AlreadyExistsException, MetaException, TException { - return deepCopy(client.add_partition(new_part)); + Partition part = client.add_partition(new_part); + listener.onAddPartition(part); + return deepCopy(part); } /** @@ -351,6 +357,9 @@ } success = true; } finally { + if(success){ + listener.onCreateTable(tbl); + } if (!success && (hook != null)) { hook.rollbackCreateTable(tbl); } @@ -437,6 +446,8 @@ public boolean dropPartition(String db_name, String tbl_name, List part_vals, boolean deleteData) throws NoSuchObjectException, MetaException, TException { + Partition part = new Partition(part_vals, db_name, tbl_name, -1, -1, null, null); + listener.onDropPartition(part); return client.drop_partition(db_name, tbl_name, part_vals, deleteData); } @@ -497,11 +508,15 @@ if (hook != null) { hook.commitDropTable(tbl, deleteData); } + success = true; } catch (NoSuchObjectException e) { if (!ignoreUknownTab) { throw e; } } finally { + if(success){ + listener.onDropTable(tbl); + } if (!success && (hook != null)) { hook.rollbackDropTable(tbl); } @@ -582,7 +597,7 @@ return deepCopyPartitions( client.get_partitions_ps(db_name, tbl_name, part_vals, max_parts)); } - + @Override public List listPartitionsWithAuthInfo(String db_name, String tbl_name, short max_parts, String user_name, List group_names) @@ -648,7 +663,7 @@ List part_vals) throws NoSuchObjectException, MetaException, TException { return deepCopy(client.get_partition(db_name, tbl_name, part_vals)); } - + @Override public Partition getPartitionWithAuthInfo(String db_name, String tbl_name, List part_vals, String user_name, List group_names) @@ -1005,13 +1020,13 @@ public boolean drop_role(String roleName) throws MetaException, TException { return client.drop_role(roleName); } - + @Override public List list_roles(String principalName, PrincipalType principalType) throws MetaException, TException { return client.list_roles(principalName, principalType); } - + @Override public List listRoleNames() throws MetaException, TException { return client.get_role_names(); Index: metastore/src/java/org/apache/hadoop/hive/metastore/NoOpListener.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/NoOpListener.java (revision 0) +++ metastore/src/java/org/apache/hadoop/hive/metastore/NoOpListener.java (revision 0) @@ -0,0 +1,29 @@ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.Table; + +public class NoOpListener implements HiveMetaStoreListener { + + @Override + public void onAddPartition(Partition partition) throws MetaException { + + } + + @Override + public void onCreateTable(Table table) throws MetaException { + + } + + @Override + public void onDropPartition(Partition partition) throws MetaException { + + } + + @Override + public void onDropTable(Table table) throws MetaException { + + } + +} Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreListener.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreListener.java (revision 0) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreListener.java (revision 0) @@ -0,0 +1,17 @@ +package org.apache.hadoop.hive.metastore; + +import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.hive.metastore.api.Partition; +import org.apache.hadoop.hive.metastore.api.Table; + +public interface HiveMetaStoreListener { + + public void onCreateTable(Table table) throws MetaException; + + public void onDropTable(Table table) throws MetaException; + + public void onAddPartition(Partition partition) throws MetaException; + + public void onDropPartition(Partition partition) throws MetaException; + +} Index: common/src/java/org/apache/hadoop/hive/conf/HiveConf.java =================================================================== --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (revision 1079575) +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (working copy) @@ -31,6 +31,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.metastore.NoOpListener; import org.apache.hadoop.hive.shims.ShimLoader; import org.apache.hadoop.mapred.JobConf; import org.apache.hadoop.security.UserGroupInformation; @@ -379,6 +380,8 @@ // deployment. It has not been documented in hive-default.xml intentionally, this should be removed // once the feature is stable HIVE_MAPPER_CANNOT_SPAN_MULTIPLE_PARTITIONS("hive.mapper.cannot.span.multiple.partitions", false), + + HIVE_METASTORE_LISTENER("hive.metastore.listener", NoOpListener.class.getName()), ; Index: ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java (revision 1079575) +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/HiveUtils.java (working copy) @@ -23,6 +23,10 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hive.common.JavaUtils; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.conf.HiveConf.ConfVars; +import org.apache.hadoop.hive.metastore.HiveMetaStoreListener; +import org.apache.hadoop.hive.metastore.api.FieldSchema; +import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.hive.ql.index.HiveIndexHandler; import org.apache.hadoop.hive.ql.parse.AbstractSemanticAnalyzerHook; import org.apache.hadoop.hive.ql.security.HadoopDefaultAuthenticator; @@ -30,11 +34,10 @@ import org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider; import org.apache.hadoop.hive.ql.security.authorization.HiveAuthorizationProvider; import org.apache.hadoop.util.ReflectionUtils; -import org.apache.hadoop.hive.metastore.api.FieldSchema; /** * General collection of helper functions. - * + * */ public final class HiveUtils { @@ -136,7 +139,7 @@ public static HiveStorageHandler getStorageHandler( Configuration conf, String className) throws HiveException { - + if (className == null) { return null; } @@ -175,7 +178,7 @@ + e.getMessage(), e); } } - + @SuppressWarnings("unchecked") public static HiveAuthorizationProvider getAuthorizeProviderManager( Configuration conf, HiveAuthenticationProvider authenticator) throws HiveException { @@ -257,4 +260,16 @@ } return sb.toString(); } + + public static HiveMetaStoreListener getMetaStoreListener(HiveConf conf) + throws MetaException{ + + String listenerImpl = conf.getVar(ConfVars.HIVE_METASTORE_LISTENER); + try { + return (HiveMetaStoreListener)ReflectionUtils.newInstance( + Class.forName(listenerImpl, true, JavaUtils.getClassLoader()),conf); + } catch (ClassNotFoundException e) { + throw new MetaException(e.getMessage()); + } + } }