mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3161 - Race condition in ActiveMQ Journal Checkpoint worker thread cleanup leads to multiple running instances
patch applied with thanks, one small mod, left un synced check in store(..) such that locking only occurs if thread needs a restart git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1063710 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
029c1e3e28
commit
62c6c8f8d8
|
@ -213,6 +213,7 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar
|
||||||
private boolean checksumJournalFiles = false;
|
private boolean checksumJournalFiles = false;
|
||||||
private int databaseLockedWaitDelay = DEFAULT_DATABASE_LOCKED_WAIT_DELAY;
|
private int databaseLockedWaitDelay = DEFAULT_DATABASE_LOCKED_WAIT_DELAY;
|
||||||
protected boolean forceRecoverIndex = false;
|
protected boolean forceRecoverIndex = false;
|
||||||
|
private final Object checkpointThreadLock = new Object();
|
||||||
|
|
||||||
public MessageDatabase() {
|
public MessageDatabase() {
|
||||||
}
|
}
|
||||||
|
@ -273,6 +274,15 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startCheckpoint() {
|
private void startCheckpoint() {
|
||||||
|
synchronized (checkpointThreadLock) {
|
||||||
|
boolean start = false;
|
||||||
|
if (checkpointThread == null) {
|
||||||
|
start = true;
|
||||||
|
} else if (!checkpointThread.isAlive()) {
|
||||||
|
start = true;
|
||||||
|
LOG.info("KahaDB: Recovering checkpoint thread after death");
|
||||||
|
}
|
||||||
|
if (start) {
|
||||||
checkpointThread = new Thread("ActiveMQ Journal Checkpoint Worker") {
|
checkpointThread = new Thread("ActiveMQ Journal Checkpoint Worker") {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -301,11 +311,13 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar
|
||||||
brokerService.handleIOException(ioe);
|
brokerService.handleIOException(ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
checkpointThread.setDaemon(true);
|
checkpointThread.setDaemon(true);
|
||||||
checkpointThread.start();
|
checkpointThread.start();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void open() throws IOException {
|
public void open() throws IOException {
|
||||||
if( opened.compareAndSet(false, true) ) {
|
if( opened.compareAndSet(false, true) ) {
|
||||||
|
@ -378,7 +390,9 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar
|
||||||
this.indexLock.writeLock().unlock();
|
this.indexLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
journal.close();
|
journal.close();
|
||||||
|
synchronized (checkpointThreadLock) {
|
||||||
checkpointThread.join();
|
checkpointThread.join();
|
||||||
|
}
|
||||||
lockFile.unlock();
|
lockFile.unlock();
|
||||||
lockFile=null;
|
lockFile=null;
|
||||||
}
|
}
|
||||||
|
@ -761,7 +775,6 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar
|
||||||
this.indexLock.writeLock().unlock();
|
this.indexLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
if (!checkpointThread.isAlive()) {
|
if (!checkpointThread.isAlive()) {
|
||||||
LOG.info("KahaDB: Recovering checkpoint thread after exception");
|
|
||||||
startCheckpoint();
|
startCheckpoint();
|
||||||
}
|
}
|
||||||
if (after != null) {
|
if (after != null) {
|
||||||
|
|
Loading…
Reference in New Issue