Skip to content
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

[SPARK-32034][SQL] Port HIVE-14817: Shutdown the SessionManager timeoutChecker thread properly upon shutdown #28870

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed because we did it in shutdownTimeoutChecker function.
HIVE-14817 removed this, too.

shutdownTimeoutChecker();
if (backgroundOperationPool != null) {
backgroundOperationPool.shutdown();
long timeout = hiveConf.getTimeVar(
Expand Down
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed because we did it in shutdownTimeoutChecker function.
HIVE-14817 removed this, too.

shutdownTimeoutChecker();
if (backgroundOperationPool != null) {
backgroundOperationPool.shutdown();
long timeout = hiveConf.getTimeVar(
Expand Down