Skip to content

remove HiveConf and Configuration from thread-local after conection to h... #24

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

Open
wants to merge 1 commit into
base: shark-0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected synchronized RawStore initialValue() {

// Thread local configuration is needed as many threads could make changes
// to the conf using the connection hook
private final ThreadLocal<Configuration> threadLocalConf =
private static final ThreadLocal<Configuration> threadLocalConf =
new ThreadLocal<Configuration>() {
@Override
protected synchronized Configuration initialValue() {
Expand Down Expand Up @@ -319,6 +319,11 @@ private Configuration getConf() {
return conf;
}

public static void cleanThreadLocal() {
threadLocalConf.remove();
LOG.debug("removed current Configuration instance from thread-local var");
}

/**
* Get a cached RawStore.
*
Expand Down
2 changes: 1 addition & 1 deletion ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.apache.hadoop.hive.metastore.api.HiveObjectRef;
import org.apache.hadoop.hive.metastore.api.HiveObjectType;
import org.apache.hadoop.hive.metastore.api.Index;
import org.apache.hadoop.hive.metastore.api.InvalidObjectException;
import org.apache.hadoop.hive.metastore.api.InvalidOperationException;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
Expand Down Expand Up @@ -178,6 +177,7 @@ public static Hive get() throws HiveException {

public static void closeCurrent() {
hiveDB.remove();
LOG.debug("removed current metastore.Hive instance from thread-local var");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,4 +748,10 @@ public void addLocalMapRedErrors(String id, List<String> localMapRedErrors) {
public void setLocalMapRedErrors(Map<String, List<String>> localMapRedErrors) {
this.localMapRedErrors = localMapRedErrors;
}

public static void cleanThreadLocal() {
tss.remove();
Log LOG = LogFactory.getLog(SessionState.class.getName());
LOG.debug("removed current SessionState instance from thread-local var");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.common.ServerUtils;
import org.apache.hadoop.hive.common.LogUtils;
import org.apache.hadoop.hive.common.LogUtils.LogInitializationException;
import org.apache.hadoop.hive.common.ServerUtils;
import org.apache.hadoop.hive.common.cli.CommonCliOptions;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.metastore.HiveMetaStore;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.Schema;
import org.apache.hadoop.hive.ql.CommandNeedRetryException;
import org.apache.hadoop.hive.ql.Driver;
import org.apache.hadoop.hive.ql.metadata.Hive;
import org.apache.hadoop.hive.ql.plan.api.QueryPlan;
import org.apache.hadoop.hive.ql.processors.CommandProcessor;
import org.apache.hadoop.hive.ql.processors.CommandProcessorFactory;
Expand All @@ -61,8 +62,7 @@
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportFactory;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import com.facebook.fb303.fb_status;

/**
Expand Down Expand Up @@ -227,6 +227,9 @@ public void clean() {
if (session.getTmpOutputFile() != null) {
session.getTmpOutputFile().delete();
}
SessionState.cleanThreadLocal();
Hive.closeCurrent();
HiveMetaStore.HMSHandler.cleanThreadLocal();
pipeIn = null;
}

Expand Down