Skip to content

Commit

Permalink
HIVE-2833 Fix test failures caused by HIVE-2716
Browse files Browse the repository at this point in the history
(Kevin Wilfong via namit)



git-svn-id: https://svn.apache.org/repos/asf/hive/trunk@1296946 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Namit Jain committed Mar 5, 2012
1 parent 580dce3 commit ee93db3
Show file tree
Hide file tree
Showing 6 changed files with 642 additions and 24 deletions.
Expand Up @@ -241,8 +241,8 @@ private boolean init() throws MetaException {
"hive.metastore.checkForDefaultDb", true);
String alterHandlerName = hiveConf.get("hive.metastore.alter.impl",
HiveAlterHandler.class.getName());
alterHandler = (AlterHandler) ReflectionUtils.newInstance(getClass(
alterHandlerName, AlterHandler.class), hiveConf);
alterHandler = (AlterHandler) ReflectionUtils.newInstance(MetaStoreUtils.getClass(
alterHandlerName), hiveConf);
wh = new Warehouse(hiveConf);

createDefaultDB();
Expand Down Expand Up @@ -310,10 +310,8 @@ private RawStore newRawStore() throws MetaException {
LOG.info(addPrefix("Opening raw store with implemenation class:"
+ rawStoreClassName));
Configuration conf = getConf();
RawStore ms = (RawStore) ReflectionUtils.newInstance(getClass(rawStoreClassName,
RawStore.class), conf);

return RetryingRawStore.getProxy(hiveConf, conf, ms, threadLocalId.get());
return RetryingRawStore.getProxy(hiveConf, conf, rawStoreClassName, threadLocalId.get());
}

private void createDefaultDB_core(RawStore ms) throws MetaException, InvalidObjectException {
Expand Down Expand Up @@ -350,15 +348,6 @@ private void createDefaultDB() throws MetaException {

}

private Class<?> getClass(String rawStoreClassName, Class<?> class1)
throws MetaException {
try {
return Class.forName(rawStoreClassName, true, classLoader);
} catch (ClassNotFoundException e) {
throw new MetaException(rawStoreClassName + " class not found");
}
}

private void logInfo(String m) {
LOG.info(threadLocalId.get().toString() + ": " + m);
logAuditEvent(m);
Expand Down
Expand Up @@ -1015,4 +1015,13 @@ public static void checkOrSetPrimaryRegionName(StorageDescriptor sd, Configurati
sd.setPrimaryRegionName(defaultRegionName);
}
}

public static Class<?> getClass(String rawStoreClassName)
throws MetaException {
try {
return Class.forName(rawStoreClassName, true, JavaUtils.getClassLoader());
} catch (ClassNotFoundException e) {
throw new MetaException(rawStoreClassName + " class not found");
}
}
}
Expand Up @@ -50,22 +50,28 @@ public class RetryingRawStore implements InvocationHandler {
private final HiveConf hiveConf;
private final Configuration conf; // thread local conf from HMS

protected RetryingRawStore(HiveConf hiveConf, Configuration conf, RawStore base, int id)
throws MetaException {
this.base = base;
protected RetryingRawStore(HiveConf hiveConf, Configuration conf,
Class<? extends RawStore> rawStoreClass, int id) throws MetaException {
this.conf = conf;
this.hiveConf = hiveConf;
this.id = id;

// This has to be called before initializing the instance of RawStore
init();

this.base = (RawStore) ReflectionUtils.newInstance(rawStoreClass, conf);
}

public static RawStore getProxy(HiveConf hiveConf, Configuration conf, RawStore base, int id)
throws MetaException {
public static RawStore getProxy(HiveConf hiveConf, Configuration conf, String rawStoreClassName,
int id) throws MetaException {

Class<? extends RawStore> baseClass = (Class<? extends RawStore>) MetaStoreUtils.getClass(
rawStoreClassName);

RetryingRawStore handler = new RetryingRawStore(hiveConf, conf, base, id);
RetryingRawStore handler = new RetryingRawStore(hiveConf, conf, baseClass, id);

return (RawStore) Proxy.newProxyInstance(RetryingRawStore.class.getClassLoader()
, base.getClass().getInterfaces(), handler);
, baseClass.getInterfaces(), handler);
}

private void init() throws MetaException {
Expand All @@ -74,9 +80,9 @@ private void init() throws MetaException {
retryLimit = HiveConf.getIntVar(hiveConf,
HiveConf.ConfVars.METASTOREATTEMPTS);
// Using the hook on startup ensures that the hook always has priority
// over settings in *.xml. We can use hiveConf as only a single thread
// will be calling the constructor.
updateConnectionURL(hiveConf, null);
// over settings in *.xml. The thread local conf needs to be used because at this point
// it has already been initialized using hiveConf.
updateConnectionURL(getConf(), null);
}

private void initMS() {
Expand Down
@@ -0,0 +1,45 @@
/**
* 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.hooks.JDOConnectionURLHook;

/**
*
* DummyJdoConnectionUrlHook.
*
* An implementation of JDOConnectionURLHook which simply returns CORRECT_URL when
* getJdoConnectionUrl is called.
*/
public class DummyJdoConnectionUrlHook implements JDOConnectionURLHook {

public static final String initialUrl = "BAD_URL";
public static final String newUrl = "CORRECT_URL";

@Override
public String getJdoConnectionUrl(Configuration conf) throws Exception {
return newUrl;
}

@Override
public void notifyBadConnectionUrl(String url) {
}

}

0 comments on commit ee93db3

Please sign in to comment.