-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-12679: Allow users to be able to specify an implementation of IMetaStoreClient via HiveConf #4444
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
HIVE-12679: Allow users to be able to specify an implementation of IMetaStoreClient via HiveConf #4444
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 |
|---|---|---|
|
|
@@ -114,6 +114,7 @@ | |
| import org.apache.hadoop.hive.metastore.api.SourceTable; | ||
| import org.apache.hadoop.hive.metastore.api.UpdateTransactionalStatsRequest; | ||
| import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; | ||
| import org.apache.hadoop.hive.metastore.conf.MetastoreConf; | ||
| import org.apache.hadoop.hive.ql.ddl.table.AlterTableType; | ||
| import org.apache.hadoop.hive.ql.io.HdfsUtils; | ||
| import org.apache.hadoop.hive.metastore.HiveMetaException; | ||
|
|
@@ -123,7 +124,6 @@ | |
| import org.apache.hadoop.hive.metastore.HiveMetaStoreUtils; | ||
| import org.apache.hadoop.hive.metastore.IMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.PartitionDropOptions; | ||
| import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.SynchronizedMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.TableType; | ||
| import org.apache.hadoop.hive.metastore.Warehouse; | ||
|
|
@@ -236,6 +236,7 @@ | |
| import org.apache.hadoop.mapred.InputFormat; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import org.apache.hadoop.util.StringUtils; | ||
| import org.apache.hadoop.util.ReflectionUtils; | ||
| import org.apache.hive.common.util.HiveVersionInfo; | ||
| import org.apache.thrift.TException; | ||
| import org.apache.thrift.TApplicationException; | ||
|
|
@@ -5700,11 +5701,26 @@ public HiveMetaHook getHook( | |
| } | ||
| }; | ||
|
|
||
| if (conf.getBoolVar(ConfVars.METASTORE_FASTPATH)) { | ||
| return new SessionHiveMetaStoreClient(conf, hookLoader, allowEmbedded); | ||
| } else { | ||
| return RetryingMetaStoreClient.getProxy(conf, hookLoader, metaCallTimeMap, | ||
| SessionHiveMetaStoreClient.class.getName(), allowEmbedded); | ||
| return createMetaStoreClientFactory(conf) | ||
| .createMetaStoreClient(conf, hookLoader, allowEmbedded, metaCallTimeMap); | ||
| } | ||
|
|
||
| private static HiveMetaStoreClientFactory createMetaStoreClientFactory(HiveConf conf) throws | ||
| MetaException { | ||
| String metaStoreClientFactoryClassName = MetastoreConf.getVar(conf, | ||
| MetastoreConf.ConfVars.METASTORE_CLIENT_FACTORY_CLASS); | ||
|
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. I think instead of providing a custom factory, you need to supply the custom client impl (
Contributor
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. Agreed! The code will be clearer if we instantiate the client impl in a single factory, maybe just named
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. @deniskuzZ @wecharyu Thanks for your opinions. Let me clarify your suggestions first. This is my understanding.
I would also say the relation between I don't have strong opinions, and to be honest, I could be misunderstanding your suggestion. Please feel free to give me your thoughts. I am willing to follow that advice!
Contributor
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. I think we just need
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. Thanks. I think there are 3 existing patterns.
I have not come up with a very smart way to resolve the combination... It could be likely to be like this but I'd say there is a better way.
Contributor
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. Can we simplify the match pattern as follows? String className = MetastoreConf.getVar(conf, MetastoreConf.ConfVars.METASTORE_CLIENT_CLASS);
if (conf.getBoolVar(ConfVars.METASTORE_FASTPATH)) {
return HiveMetaStoreClientFactory.create(...);
} else {
return RetryingMetaStoreClient.getProxy(conf, hookLoader, metaCallTimeMap, className, allowEmbedded);
}
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. I have two thoughts.
|
||
|
|
||
| try { | ||
| Class<? extends HiveMetaStoreClientFactory> factoryClass = | ||
| conf.getClassByName(metaStoreClientFactoryClassName) | ||
| .asSubclass(HiveMetaStoreClientFactory.class); | ||
| return ReflectionUtils.newInstance(factoryClass, conf); | ||
| } catch (Exception e) { | ||
| String errorMessage = String.format( | ||
| "Unable to instantiate a metastore client factory %s due to: %s", | ||
| metaStoreClientFactoryClassName, e); | ||
| LOG.error(errorMessage, e); | ||
| throw new MetaException(errorMessage); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * 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.ql.metadata; | ||
|
|
||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import org.apache.hadoop.hive.conf.HiveConf; | ||
| import org.apache.hadoop.hive.metastore.HiveMetaHookLoader; | ||
| import org.apache.hadoop.hive.metastore.IMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.api.MetaException; | ||
|
|
||
| /** | ||
| * Abstract factory that defines an interface for other factories that produce concrete | ||
| * MetaStoreClient objects. | ||
| * | ||
| */ | ||
| public interface HiveMetaStoreClientFactory { | ||
|
|
||
| /** | ||
| * A method for producing IMetaStoreClient objects. | ||
| * | ||
| * The implementation returned by this method must throw a MetaException if allowEmbedded = true | ||
| * and it does not support embedded mode. | ||
| * | ||
| * @param conf | ||
| * Hive Configuration. | ||
| * @param hookLoader | ||
| * Hook for handling events related to tables. | ||
| * @param allowEmbedded | ||
| * Flag indicating the implementation must run in-process, e.g. for unit testing or | ||
| * "fast path". | ||
| * @param metaCallTimeMap | ||
| * A container for storing entry and exit timestamps of IMetaStoreClient method | ||
| * invocations. | ||
| * @return IMetaStoreClient An implementation of IMetaStoreClient. | ||
| * @throws MetaException if this method fails to create IMetaStoreClient | ||
| */ | ||
| IMetaStoreClient createMetaStoreClient(HiveConf conf, HiveMetaHookLoader hookLoader, | ||
| boolean allowEmbedded, ConcurrentHashMap<String, Long> metaCallTimeMap) throws MetaException; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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.ql.metadata; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkNotNull; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import org.apache.hadoop.hive.conf.HiveConf; | ||
| import org.apache.hadoop.hive.conf.HiveConf.ConfVars; | ||
| import org.apache.hadoop.hive.metastore.HiveMetaHookLoader; | ||
| import org.apache.hadoop.hive.metastore.IMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.RetryingMetaStoreClient; | ||
| import org.apache.hadoop.hive.metastore.api.MetaException; | ||
|
|
||
| /** | ||
| * Default MetaStoreClientFactory for Hive which produces SessionHiveMetaStoreClient objects. | ||
| * | ||
| */ | ||
| public final class SessionHiveMetaStoreClientFactory implements HiveMetaStoreClientFactory { | ||
|
|
||
| @Override | ||
| public IMetaStoreClient createMetaStoreClient(HiveConf conf, HiveMetaHookLoader hookLoader, | ||
| boolean allowEmbedded, | ||
| ConcurrentHashMap<String, Long> metaCallTimeMap) throws MetaException { | ||
|
|
||
| checkNotNull(conf, "conf cannot be null!"); | ||
| checkNotNull(hookLoader, "hookLoader cannot be null!"); | ||
| checkNotNull(metaCallTimeMap, "metaCallTimeMap cannot be null!"); | ||
|
|
||
| if (conf.getBoolVar(ConfVars.METASTORE_FASTPATH)) { | ||
| return new SessionHiveMetaStoreClient(conf, hookLoader, allowEmbedded); | ||
| } else { | ||
| return RetryingMetaStoreClient.getProxy(conf, hookLoader, metaCallTimeMap, | ||
| SessionHiveMetaStoreClient.class.getName(), allowEmbedded); | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
could we avoid new factory object creation on every new client request?