You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by pr...@apache.org on 2016/03/08 22:26:40 UTC
hive git commit: HIVE-13153: SessionID is appended to thread name
twice (Prasanth Jayachandran reviewed by Vikram Dixit, Sergey Shelukhin)
Repository: hive
Updated Branches:
refs/heads/master 87131d0c7 -> fe3012145
HIVE-13153: SessionID is appended to thread name twice (Prasanth Jayachandran reviewed by Vikram Dixit, Sergey Shelukhin)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/fe301214
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/fe301214
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/fe301214
Branch: refs/heads/master
Commit: fe3012145643679c738232e6b0e7382ab810cdf6
Parents: 87131d0
Author: Prasanth Jayachandran <j....@gmail.com>
Authored: Tue Mar 8 15:26:29 2016 -0600
Committer: Prasanth Jayachandran <j....@gmail.com>
Committed: Tue Mar 8 15:26:29 2016 -0600
----------------------------------------------------------------------
.../org/apache/hadoop/hive/cli/CliDriver.java | 7 ++++---
.../hadoop/hive/ql/session/SessionState.java | 22 ++++++++++++++++++++
.../service/cli/session/HiveSessionImpl.java | 17 ++-------------
3 files changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/fe301214/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
----------------------------------------------------------------------
diff --git a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
index e77b7f1..b6fe77c 100644
--- a/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
+++ b/cli/src/java/org/apache/hadoop/hive/cli/CliDriver.java
@@ -118,8 +118,8 @@ public class CliDriver {
CliSessionState ss = (CliSessionState) SessionState.get();
ss.setLastCommand(cmd);
- String callerInfo = ss.getConf().getLogIdVar(ss.getSessionId());
- Thread.currentThread().setName(callerInfo + " " + originalThreadName);
+ ss.updateThreadName();
+
// Flush the print stream, so it doesn't include output from the last command
ss.err.flush();
String cmd_trimmed = cmd.trim();
@@ -711,7 +711,8 @@ public class CliDriver {
SessionState.start(ss);
}
- Thread.currentThread().setName(conf.getLogIdVar(ss.getSessionId()) + " " + originalThreadName);
+ ss.updateThreadName();
+
// execute cli driver work
try {
return executeDriver(ss, conf, oproc);
http://git-wip-us.apache.org/repos/asf/hive/blob/fe301214/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
index 70b2bc0..109cd8c 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java
@@ -399,6 +399,28 @@ public class SessionState {
return (conf.getVar(HiveConf.ConfVars.HIVESESSIONID));
}
+ public void updateThreadName() {
+ final String sessionId = getSessionId();
+ final String logPrefix = getConf().getLogIdVar(sessionId);
+ final String currThreadName = Thread.currentThread().getName();
+ if (!currThreadName.contains(logPrefix)) {
+ final String newThreadName = logPrefix + " " + currThreadName;
+ LOG.info("Updating thread name to {}", newThreadName);
+ Thread.currentThread().setName(newThreadName);
+ }
+ }
+
+ public void resetThreadName() {
+ final String sessionId = getSessionId();
+ final String logPrefix = getConf().getLogIdVar(sessionId);
+ final String currThreadName = Thread.currentThread().getName();
+ if (currThreadName.contains(logPrefix)) {
+ final String[] names = currThreadName.split(logPrefix);
+ LOG.info("Resetting thread name to {}", names[names.length - 1]);
+ Thread.currentThread().setName(names[names.length - 1]);
+ }
+ }
+
/**
* Initialize the transaction manager. This is done lazily to avoid hard wiring one
* transaction manager at the beginning of the session.
http://git-wip-us.apache.org/repos/asf/hive/blob/fe301214/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
index 2e45e2d..8baecdf 100644
--- a/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
+++ b/service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java
@@ -330,10 +330,7 @@ public class HiveSessionImpl implements HiveSession {
lastAccessTime = System.currentTimeMillis();
}
// set the thread name with the logging prefix.
- String logPrefix = getHiveConf().getLogIdVar(sessionState.getSessionId());
- LOG.info(
- "Prefixing the thread name (" + Thread.currentThread().getName() + ") with " + logPrefix);
- Thread.currentThread().setName(logPrefix + Thread.currentThread().getName());
+ sessionState.updateThreadName();
Hive.set(sessionHive);
}
@@ -348,17 +345,7 @@ public class HiveSessionImpl implements HiveSession {
if (sessionState != null) {
// can be null in-case of junit tests. skip reset.
// reset thread name at release time.
- String[] names = Thread.currentThread().getName()
- .split(getHiveConf().getLogIdVar(sessionState.getSessionId()));
- String threadName = null;
- if (names.length > 1) {
- threadName = names[names.length - 1];
- } else if (names.length == 1) {
- threadName = names[0];
- } else {
- threadName = "";
- }
- Thread.currentThread().setName(threadName);
+ sessionState.resetThreadName();
}
SessionState.detachSession();