mirror of https://github.com/apache/activemq.git
resolve https://issues.apache.org/activemq/browse/AMQ-2285 - pull file locking outside setting opened state so that an open does not ocurr unless the lock is available, sorts out Npe on shutdown
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@783384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a88a513e3c
commit
38b840a61f
|
@ -218,26 +218,25 @@ public class MessageDatabase {
|
|||
* @throws IOException
|
||||
*/
|
||||
public void open() throws IOException {
|
||||
File lockFileName = new File(directory, "lock");
|
||||
lockFile = new LockFile(lockFileName, true);
|
||||
if (failIfDatabaseIsLocked) {
|
||||
lockFile.lock();
|
||||
} else {
|
||||
while (true) {
|
||||
try {
|
||||
lockFile.lock();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked. Reason: " + e);
|
||||
try {
|
||||
Thread.sleep(DATABASE_LOCKED_WAIT_DELAY);
|
||||
} catch (InterruptedException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if( opened.compareAndSet(false, true) ) {
|
||||
File lockFileName = new File(directory, "lock");
|
||||
lockFile = new LockFile(lockFileName, true);
|
||||
if (failIfDatabaseIsLocked) {
|
||||
lockFile.lock();
|
||||
} else {
|
||||
while (true) {
|
||||
try {
|
||||
lockFile.lock();
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
LOG.info("Database "+lockFileName+" is locked... waiting " + (DATABASE_LOCKED_WAIT_DELAY / 1000) + " seconds for the database to be unlocked. Reason: " + e);
|
||||
try {
|
||||
Thread.sleep(DATABASE_LOCKED_WAIT_DELAY);
|
||||
} catch (InterruptedException e1) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getJournal().start();
|
||||
|
||||
loadPageFile();
|
||||
|
@ -312,7 +311,7 @@ public class MessageDatabase {
|
|||
|
||||
public void unload() throws IOException, InterruptedException {
|
||||
synchronized (indexMutex) {
|
||||
if( pageFile.isLoaded() ) {
|
||||
if( pageFile != null && pageFile.isLoaded() ) {
|
||||
metadata.state = CLOSED_STATE;
|
||||
metadata.firstInProgressTransactionLocation = getFirstInProgressTxLocation();
|
||||
|
||||
|
|
|
@ -17,11 +17,9 @@
|
|||
package org.apache.activemq.store.kahadb;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.apache.activemq.broker.BrokerFactory;
|
||||
import org.apache.activemq.broker.BrokerService;
|
||||
import org.apache.activemq.broker.BrokerTest;
|
||||
|
||||
|
|
Loading…
Reference in New Issue