Skip to content

Commit

Permalink
[SPARK-32034][SQL] Port HIVE-14817: Shutdown the SessionManager timeo…
Browse files Browse the repository at this point in the history
…utChecker thread properly upon shutdown
  • Loading branch information
yaooqinn committed Jun 19, 2020
1 parent 6fe3bf6 commit 1907832
Showing 1 changed file with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,20 @@ public synchronized void start() {
}
}

private final Object timeoutCheckerLock = new Object();

private void startTimeoutChecker() {
final long interval = Math.max(checkInterval, 3000L); // minimum 3 seconds
Runnable timeoutChecker = new Runnable() {
final Runnable timeoutChecker = new Runnable() {
@Override
public void run() {
for (sleepInterval(interval); !shutdown; sleepInterval(interval)) {
sleepFor(interval);
while (!shutdown) {
long current = System.currentTimeMillis();
for (HiveSession session : new ArrayList<HiveSession>(handleToSession.values())) {
if (shutdown) {
break;
}
if (sessionTimeout > 0 && session.getLastAccessTime() + sessionTimeout <= current
&& (!checkOperation || session.getNoOperationTime() > sessionTimeout)) {
SessionHandle handle = session.getSessionHandle();
Expand All @@ -170,24 +176,35 @@ public void run() {
session.closeExpiredOperations();
}
}
sleepFor(interval);
}
}

private void sleepInterval(long interval) {
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
// ignore
private void sleepFor(long interval) {
synchronized (timeoutCheckerLock) {
try {
timeoutCheckerLock.wait(interval);
} catch (InterruptedException e) {
// Ignore, and break.
}
}
}
};
backgroundOperationPool.execute(timeoutChecker);
}

private void shutdownTimeoutChecker() {
shutdown = true;
synchronized (timeoutCheckerLock) {
timeoutCheckerLock.notify();
}
}

@Override
public synchronized void stop() {
super.stop();
shutdown = true;
shutdownTimeoutChecker();
if (backgroundOperationPool != null) {
backgroundOperationPool.shutdown();
long timeout = hiveConf.getTimeVar(
Expand Down

0 comments on commit 1907832

Please sign in to comment.