mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-6799 - IOExceptionHandler during the startup
This commit is contained in:
parent
4c986d102c
commit
c7291f1ecf
|
@ -51,7 +51,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(IOException exception) {
|
public void handle(IOException exception) {
|
||||||
if (ignoreAllErrors) {
|
if (!broker.isStarted() || ignoreAllErrors) {
|
||||||
allowIOResumption();
|
allowIOResumption();
|
||||||
LOG.info("Ignoring IO exception, " + exception, exception);
|
LOG.info("Ignoring IO exception, " + exception, exception);
|
||||||
return;
|
return;
|
||||||
|
@ -167,7 +167,9 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
protected void allowIOResumption() {
|
protected void allowIOResumption() {
|
||||||
try {
|
try {
|
||||||
broker.getPersistenceAdapter().allowIOResumption();
|
if (broker.getPersistenceAdapter() != null) {
|
||||||
|
broker.getPersistenceAdapter().allowIOResumption();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.warn("Failed to allow IO resumption", e);
|
LOG.warn("Failed to allow IO resumption", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,11 @@ public class DefaultIOExceptionHandlerTest {
|
||||||
|
|
||||||
underTest.setSystemExitOnShutdown(exitPlease);
|
underTest.setSystemExitOnShutdown(exitPlease);
|
||||||
underTest.setBrokerService(new BrokerService() {
|
underTest.setBrokerService(new BrokerService() {
|
||||||
|
@Override
|
||||||
|
public boolean isStarted() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
shutdownOnExitSet.set(isSystemExitOnShutdown());
|
shutdownOnExitSet.set(isSystemExitOnShutdown());
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class LeaseDatabaseLocker extends AbstractJDBCLocker {
|
||||||
+ e, e);
|
+ e, e);
|
||||||
}
|
}
|
||||||
if (handleStartException) {
|
if (handleStartException) {
|
||||||
lockable.getBrokerService().handleIOException(IOExceptionSupport.create(e));
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
close(statement);
|
close(statement);
|
||||||
|
|
|
@ -65,6 +65,8 @@ public class JDBCIOExceptionHandlerMockeryTest {
|
||||||
|
|
||||||
// simulate jdbc up between hasLock and checkpoint, so hasLock fails to verify
|
// simulate jdbc up between hasLock and checkpoint, so hasLock fails to verify
|
||||||
context.checking(new Expectations() {{
|
context.checking(new Expectations() {{
|
||||||
|
allowing(brokerService).isStarted();
|
||||||
|
will(returnValue(true));
|
||||||
allowing(brokerService).isRestartAllowed();
|
allowing(brokerService).isRestartAllowed();
|
||||||
will(returnValue(false));
|
will(returnValue(false));
|
||||||
allowing(brokerService).setSystemExitOnShutdown(with(false));
|
allowing(brokerService).setSystemExitOnShutdown(with(false));
|
||||||
|
|
|
@ -28,6 +28,7 @@ import javax.jms.Connection;
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.ft.SyncCreateDataSource;
|
import org.apache.activemq.broker.ft.SyncCreateDataSource;
|
||||||
|
import org.apache.activemq.bugs.embedded.ThreadExplorer;
|
||||||
import org.apache.activemq.util.IOHelper;
|
import org.apache.activemq.util.IOHelper;
|
||||||
import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
|
import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
|
||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
|
@ -101,6 +102,47 @@ public class JDBCIOExceptionHandlerTest {
|
||||||
return broker;
|
return broker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testStartWithDatabaseDown() throws Exception {
|
||||||
|
BrokerService broker = new BrokerService();
|
||||||
|
|
||||||
|
JDBCPersistenceAdapter jdbc = new JDBCPersistenceAdapter();
|
||||||
|
EmbeddedDataSource embeddedDataSource = (EmbeddedDataSource) jdbc.getDataSource();
|
||||||
|
// create a wrapper to EmbeddedDataSource to allow the connection be
|
||||||
|
// reestablished to derby db
|
||||||
|
dataSource = new ReconnectingEmbeddedDataSource(new SyncCreateDataSource(embeddedDataSource));
|
||||||
|
dataSource.stopDB();
|
||||||
|
jdbc.setDataSource(dataSource);
|
||||||
|
|
||||||
|
jdbc.setLockKeepAlivePeriod(1000l);
|
||||||
|
LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
|
||||||
|
leaseDatabaseLocker.setHandleStartException(true);
|
||||||
|
leaseDatabaseLocker.setLockAcquireSleepInterval(2000l);
|
||||||
|
jdbc.setLocker(leaseDatabaseLocker);
|
||||||
|
|
||||||
|
broker.setPersistenceAdapter(jdbc);
|
||||||
|
LeaseLockerIOExceptionHandler ioExceptionHandler = new LeaseLockerIOExceptionHandler();
|
||||||
|
ioExceptionHandler.setResumeCheckSleepPeriod(1000l);
|
||||||
|
ioExceptionHandler.setStopStartConnectors(true);
|
||||||
|
broker.setIoExceptionHandler(ioExceptionHandler);
|
||||||
|
try {
|
||||||
|
broker.start();
|
||||||
|
fail("Broker should have been stopped!");
|
||||||
|
} catch (Exception e) {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
assertTrue("Broker should have been stopped!", broker.isStopped());
|
||||||
|
Thread[] threads = ThreadExplorer.listThreads();
|
||||||
|
for (int i = 0; i < threads.length; i++) {
|
||||||
|
if (threads[i].getName().startsWith("IOExceptionHandler")) {
|
||||||
|
fail("IOExceptionHanlder still active");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
dataSource = null;
|
||||||
|
broker = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* run test without JMX enabled
|
* run test without JMX enabled
|
||||||
*/
|
*/
|
||||||
|
@ -223,6 +265,7 @@ public class JDBCIOExceptionHandlerTest {
|
||||||
} finally {
|
} finally {
|
||||||
LOG.debug("*** broker is stopping...");
|
LOG.debug("*** broker is stopping...");
|
||||||
broker.stop();
|
broker.stop();
|
||||||
|
broker.waitUntilStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue