From 9e8f0203015dd842ecc0804231da9a62ed3b02ec Mon Sep 17 00:00:00 2001 From: gtully Date: Thu, 10 Dec 2015 14:24:03 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6005 - have plist whack it existing state on start. Start the temp store after the primary persistence adapter which does the locking (cherry picked from commit 768fa17085ac938441915a82987c99b37ac52515) --- .../apache/activemq/broker/BrokerService.java | 41 ++++++------------- .../store/kahadb/plist/PListStoreImpl.java | 1 + .../FilePendingMessageCursorTestSupport.java | 3 +- .../KahaDBFilePendingMessageCursorTest.java | 1 + 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java index 0c582a4795..a89949085c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -665,6 +665,19 @@ public class BrokerService implements Service { } getPersistenceAdapter().start(); + getTempDataStore(); + if (tempDataStore != null) { + try { + // start after we have the store lock + tempDataStore.start(); + } catch (Exception e) { + RuntimeException exception = new RuntimeException( + "Failed to start temp data store: " + tempDataStore, e); + LOG.error(exception.getLocalizedMessage(), e); + throw exception; + } + } + getJobSchedulerStore(); if (jobSchedulerStore != null) { try { @@ -1717,32 +1730,11 @@ public class BrokerService implements Service { throw new RuntimeException(e); } - boolean result = true; - boolean empty = true; try { - File directory = getTmpDataDirectory(); - if (directory.exists() && directory.isDirectory()) { - File[] files = directory.listFiles(); - if (files != null && files.length > 0) { - empty = false; - for (int i = 0; i < files.length; i++) { - File file = files[i]; - if (!file.isDirectory()) { - result &= file.delete(); - } - } - } - } - if (!empty) { - String str = result ? "Successfully deleted" : "Failed to delete"; - LOG.info("{} temporary storage", str); - } - String clazz = "org.apache.activemq.store.kahadb.plist.PListStoreImpl"; this.tempDataStore = (PListStore) getClass().getClassLoader().loadClass(clazz).newInstance(); this.tempDataStore.setDirectory(getTmpDataDirectory()); configureService(tempDataStore); - this.tempDataStore.start(); } catch (Exception e) { throw new RuntimeException(e); } @@ -1757,13 +1749,6 @@ public class BrokerService implements Service { public void setTempDataStore(PListStore tempDataStore) { this.tempDataStore = tempDataStore; configureService(tempDataStore); - try { - tempDataStore.start(); - } catch (Exception e) { - RuntimeException exception = new RuntimeException("Failed to start provided temp data store: " + tempDataStore, e); - LOG.error(exception.getLocalizedMessage(), e); - throw exception; - } } public int getPersistenceThreadPriority() { diff --git a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/plist/PListStoreImpl.java b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/plist/PListStoreImpl.java index 33012ba11d..8c2ece237f 100644 --- a/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/plist/PListStoreImpl.java +++ b/activemq-kahadb-store/src/main/java/org/apache/activemq/store/kahadb/plist/PListStoreImpl.java @@ -276,6 +276,7 @@ public class PListStoreImpl extends ServiceSupport implements BrokerServiceAware this.directory = new File(IOHelper.getDefaultDataDirectory() + File.pathSeparator + "delayedDB"); } IOHelper.mkdirs(this.directory); + IOHelper.deleteChildren(this.directory); lock(); this.journal = new Journal(); this.journal.setDirectory(directory); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java index ac341a2ad3..57f3a86087 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/region/cursors/FilePendingMessageCursorTestSupport.java @@ -39,7 +39,7 @@ public class FilePendingMessageCursorTestSupport { @After public void stopBroker() throws Exception { if (brokerService != null) { - brokerService.getTempDataStore().stop(); + brokerService.stop(); } } @@ -48,6 +48,7 @@ public class FilePendingMessageCursorTestSupport { brokerService.setUseJmx(false); SystemUsage usage = brokerService.getSystemUsage(); usage.getTempUsage().setLimit(1025*1024*15); + brokerService.start(); // put something in the temp store to on demand initialise it PList dud = brokerService.getTempDataStore().getPList("dud"); diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/plist/KahaDBFilePendingMessageCursorTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/plist/KahaDBFilePendingMessageCursorTest.java index 5a3b318d7e..ce4a8ed0e1 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/plist/KahaDBFilePendingMessageCursorTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/plist/KahaDBFilePendingMessageCursorTest.java @@ -44,6 +44,7 @@ public class KahaDBFilePendingMessageCursorTest extends FilePendingMessageCursor String body = new String(new byte[1024]); Destination destination = new Queue(brokerService, new ActiveMQQueue("Q"), null, new DestinationStatistics(), null); + brokerService.start(); underTest = new FilePendingMessageCursor(brokerService.getBroker(), "test", false); underTest.setSystemUsage(usage);