diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java index 88bd1e7b6f..4f976c289a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/KahaDBStore.java @@ -520,8 +520,10 @@ public class KahaDBStore extends MessageDatabase implements PersistenceAdapter { try { pageFile.tx().execute(new Transaction.Closure() { public void execute(Transaction tx) throws Exception { - StoredDestination sd = getStoredDestination(dest, tx); - sd.orderIndex.resetCursorPosition();} + StoredDestination sd = getExistingStoredDestination(dest, tx); + if (sd != null) { + sd.orderIndex.resetCursorPosition();} + } }); } catch (Exception e) { LOG.error("Failed to reset batching",e); diff --git a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java index 8918b0d4a6..90a9628ed5 100644 --- a/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java +++ b/activemq-core/src/main/java/org/apache/activemq/store/kahadb/MessageDatabase.java @@ -1392,6 +1392,16 @@ public class MessageDatabase extends ServiceSupport implements BrokerServiceAwar return rc; } + + protected StoredDestination getExistingStoredDestination(KahaDestination destination, Transaction tx) throws IOException { + String key = key(destination); + StoredDestination rc = storedDestinations.get(key); + if (rc == null && metadata.destinations.containsKey(tx, key)) { + rc = getStoredDestination(destination, tx); + } + return rc; + } + /** * @param tx * @param key diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/region/DestinationRemoveRestartTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/region/DestinationRemoveRestartTest.java index fd97f87cc8..06011fe6f7 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/region/DestinationRemoveRestartTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/region/DestinationRemoveRestartTest.java @@ -24,7 +24,7 @@ import org.apache.activemq.command.ActiveMQDestination; // from https://issues.apache.org/activemq/browse/AMQ-2216 public class DestinationRemoveRestartTest extends CombinationTestSupport { private final static String destinationName = "TEST"; - public byte destinationType; + public byte destinationType = ActiveMQDestination.QUEUE_TYPE; BrokerService broker; @Override @@ -36,6 +36,7 @@ public class DestinationRemoveRestartTest extends CombinationTestSupport { BrokerService broker = new BrokerService(); broker.setUseJmx(false); broker.setPersistent(true); + broker.setDeleteAllMessagesOnStartup(true); broker.start(); return broker; }