5
0
mirror of https://github.com/apache/sqoop.git synced 2025-05-07 04:40:28 +08:00

SQOOP-2396: Sqoop2: Race condition in purge/update threads on Server shutdown

(Dian Fu via Jarek Jarcec Cecho)
This commit is contained in:
Jarek Jarcec Cecho 2015-11-18 08:06:49 -08:00
parent 4f0e28625a
commit 190b78fcb8

View File

@ -139,6 +139,16 @@ public static void setInstance(JobManager newInstance) {
*/
private UpdateThread updateThread = null;
/**
* Lock for purge thread.
*/
private Object purgeThreadLock = new Object();
/**
* Lock for update thread.
*/
private Object updateThreadLock = new Object();
/**
* Synchronization variable between threads.
*/
@ -196,6 +206,7 @@ public synchronized void destroy() {
running = false;
synchronized(purgeThreadLock) {
try {
purgeThread.interrupt();
purgeThread.join();
@ -203,7 +214,9 @@ public synchronized void destroy() {
// TODO(jarcec): Do I want to wait until it actually finish here?
LOG.error("Interrupted joining purgeThread");
}
}
synchronized(updateThreadLock) {
try {
updateThread.interrupt();
updateThread.join();
@ -211,6 +224,7 @@ public synchronized void destroy() {
// TODO(jarcec): Do I want to wait until it actually finish here?
LOG.error("Interrupted joining updateThread");
}
}
if (submissionEngine != null) {
submissionEngine.destroy();
@ -763,11 +777,15 @@ public void run() {
try {
LOG.info("Purging old submissions");
Date threshold = new Date((new Date()).getTime() - purgeThreshold);
synchronized(purgeThreadLock) {
RepositoryManager.getInstance().getRepository()
.purgeSubmissions(threshold);
}
Thread.sleep(purgeSleep);
} catch (InterruptedException e) {
LOG.debug("Purge thread interrupted", e);
} catch (SqoopException ex) {
LOG.error("Purge thread encountered exception", ex);
}
}
@ -787,6 +805,7 @@ public void run() {
try {
LOG.debug("Updating running submissions");
synchronized(updateThreadLock) {
// Let's get all running submissions from repository to check them out
List<MSubmission> unfinishedSubmissions =
RepositoryManager.getInstance().getRepository()
@ -795,10 +814,12 @@ public void run() {
for (MSubmission submission : unfinishedSubmissions) {
updateSubmission(submission);
}
}
Thread.sleep(updateSleep);
} catch (InterruptedException e) {
LOG.debug("Purge thread interrupted", e);
LOG.debug("Update thread interrupted", e);
} catch (SqoopException ex) {
LOG.error("Update thread encountered exception", ex);
}
}