SOLR-10376: Handle InterruptedException thrown by lock.lockInterruptibly() separately

This commit is contained in:
Shalin Shekhar Mangar 2017-04-28 11:48:14 +05:30
parent 12933ee4a7
commit 50fdf6ac7a

View File

@ -100,25 +100,34 @@ public class OverseerTriggerThread implements Runnable, Closeable {
while (true) { while (true) {
Map<String, AutoScaling.Trigger> copy = null; Map<String, AutoScaling.Trigger> copy = null;
try { try {
// this can throw InterruptedException and we don't want to unlock if it did, so we keep this outside
// of the try/finally block
updateLock.lockInterruptibly(); updateLock.lockInterruptibly();
if (znodeVersion == lastZnodeVersion) { try {
updated.await(); if (znodeVersion == lastZnodeVersion) {
updated.await();
// are we closed? // are we closed?
if (isClosed) break; if (isClosed) break;
// spurious wakeup? // spurious wakeup?
if (znodeVersion == lastZnodeVersion) continue; if (znodeVersion == lastZnodeVersion) continue;
lastZnodeVersion = znodeVersion; lastZnodeVersion = znodeVersion;
}
copy = new HashMap<>(activeTriggers);
} catch (InterruptedException e) {
// Restore the interrupted status
Thread.currentThread().interrupt();
log.warn("Interrupted", e);
break;
} finally {
updateLock.unlock();
} }
copy = new HashMap<>(activeTriggers);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Restore the interrupted status // Restore the interrupted status
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
log.warn("Interrupted", e); log.warn("Interrupted", e);
break; break;
} finally {
updateLock.unlock();
} }
Set<String> managedTriggerNames = scheduledTriggers.getScheduledTriggerNames(); Set<String> managedTriggerNames = scheduledTriggers.getScheduledTriggerNames();