ARTEMIS-1762 JdbcNodeManager shouldn't be used if no HA is configured (cherry picked from commit 3b8da88989f680fca0ef178312c017a6d0b14ff2)
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/717bc8f0 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/717bc8f0 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/717bc8f0 Branch: refs/heads/1.x Commit: 717bc8f09ab4e5cea4827c5f401af6abf7d91761 Parents: a9cfc08 Author: Francesco Nigro <[email protected]> Authored: Thu Mar 22 15:51:42 2018 +0100 Committer: Clebert Suconic <[email protected]> Committed: Wed Mar 28 11:54:15 2018 -0400 ---------------------------------------------------------------------- .../core/server/impl/ActiveMQServerImpl.java | 20 +++++++++--- .../config/impl/HAPolicyConfigurationTest.java | 19 +++++++++++ .../database-store-no-hapolicy-config.xml | 34 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/717bc8f0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index c1b20e3..1fdd5dd 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -57,6 +57,7 @@ import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.ConfigurationUtils; import org.apache.activemq.artemis.core.config.CoreQueueConfiguration; import org.apache.activemq.artemis.core.config.DivertConfiguration; +import org.apache.activemq.artemis.core.config.HAPolicyConfiguration; import org.apache.activemq.artemis.core.config.StoreConfiguration; import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl; import org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration; @@ -450,11 +451,22 @@ public class ActiveMQServerImpl implements ActiveMQServer { if (!configuration.isPersistenceEnabled()) { manager = new InVMNodeManager(replicatingBackup); } else if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) { - if (replicatingBackup) { - throw new IllegalArgumentException("replicatingBackup is not supported yet while using JDBC persistence"); + final HAPolicyConfiguration.TYPE haType = configuration.getHAPolicyConfiguration() == null ? null : configuration.getHAPolicyConfiguration().getType(); + if (haType == HAPolicyConfiguration.TYPE.SHARED_STORE_MASTER || haType == HAPolicyConfiguration.TYPE.SHARED_STORE_SLAVE) { + if (replicatingBackup) { + throw new IllegalArgumentException("replicatingBackup is not supported yet while using JDBC persistence"); + } + final DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) configuration.getStoreConfiguration(); + manager = JdbcNodeManager.with(dbConf, scheduledPool, executorFactory, shutdownOnCriticalIO); + } else if (haType == null || haType == HAPolicyConfiguration.TYPE.LIVE_ONLY) { + if (logger.isDebugEnabled()) { + logger.debug("Detected no Shared Store HA options on JDBC store: will use InVMNodeManager"); + } + //LIVE_ONLY should be the default HA option when HA isn't configured + manager = new InVMNodeManager(replicatingBackup); + } else { + throw new IllegalArgumentException("JDBC persistence allows only Shared Store HA options"); } - final DatabaseStorageConfiguration dbConf = (DatabaseStorageConfiguration) configuration.getStoreConfiguration(); - manager = JdbcNodeManager.with(dbConf, scheduledPool, executorFactory, shutdownOnCriticalIO); } else { manager = new FileLockNodeManager(directory, replicatingBackup, configuration.getJournalLockAcquisitionTimeout()); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/717bc8f0/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java index 7bae74e..4d9bf75 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/config/impl/HAPolicyConfigurationTest.java @@ -20,6 +20,8 @@ import java.util.List; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.FileDeploymentManager; +import org.apache.activemq.artemis.core.config.HAPolicyConfiguration; +import org.apache.activemq.artemis.core.config.StoreConfiguration; import org.apache.activemq.artemis.core.server.cluster.ha.ColocatedPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.HAPolicy; import org.apache.activemq.artemis.core.server.cluster.ha.LiveOnlyPolicy; @@ -31,6 +33,7 @@ import org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy import org.apache.activemq.artemis.core.server.impl.Activation; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; import org.apache.activemq.artemis.core.server.impl.ColocatedActivation; +import org.apache.activemq.artemis.core.server.impl.InVMNodeManager; import org.apache.activemq.artemis.core.server.impl.LiveOnlyActivation; import org.apache.activemq.artemis.core.server.impl.SharedNothingBackupActivation; import org.apache.activemq.artemis.core.server.impl.SharedNothingLiveActivation; @@ -39,9 +42,25 @@ import org.apache.activemq.artemis.core.server.impl.SharedStoreLiveActivation; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.junit.Test; +import static org.hamcrest.CoreMatchers.instanceOf; + public class HAPolicyConfigurationTest extends ActiveMQTestBase { @Test + public void shouldNotUseJdbcNodeManagerWithoutHAPolicy() throws Exception { + Configuration configuration = createConfiguration("database-store-no-hapolicy-config.xml"); + ActiveMQServerImpl server = new ActiveMQServerImpl(configuration); + assertEquals(StoreConfiguration.StoreType.DATABASE, server.getConfiguration().getStoreConfiguration().getStoreType()); + assertEquals(HAPolicyConfiguration.TYPE.LIVE_ONLY, server.getConfiguration().getHAPolicyConfiguration().getType()); + try { + server.start(); + assertThat(server.getNodeManager(), instanceOf(InVMNodeManager.class)); + } finally { + server.stop(); + } + } + + @Test public void liveOnlyTest() throws Exception { Configuration configuration = createConfiguration("live-only-hapolicy-config.xml"); ActiveMQServerImpl server = new ActiveMQServerImpl(configuration); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/717bc8f0/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml ---------------------------------------------------------------------- diff --git a/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml b/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml new file mode 100644 index 0000000..5a6984f --- /dev/null +++ b/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml @@ -0,0 +1,34 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<configuration + xmlns="urn:activemq" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="urn:activemq ../../main/resources/schema/artemis-server.xsd"> + <core xmlns="urn:activemq:core"> + <store> + <database-store> + <jdbc-connection-url>jdbc:derby:target/derby/database-store;create=true</jdbc-connection-url> + <bindings-table-name>BINDINGS</bindings-table-name> + <message-table-name>MESSAGE</message-table-name> + <large-message-table-name>LARGE_MESSAGE</large-message-table-name> + <page-store-table-name>PAGE_STORE</page-store-table-name> + <jms-bindings-table-name>JMS_BINDINGS</jms-bindings-table-name> + <jdbc-driver-class-name>org.apache.derby.jdbc.EmbeddedDriver</jdbc-driver-class-name> + </database-store> + </store> + </core> +</configuration>
