From 3b8da88989f680fca0ef178312c017a6d0b14ff2 Mon Sep 17 00:00:00 2001 From: Francesco Nigro Date: Thu, 22 Mar 2018 15:51:42 +0100 Subject: [PATCH] ARTEMIS-1762 JdbcNodeManager shouldn't be used if no HA is configured It forces to use InVMNodeManager when no HA option is selected with JDBC persistence and includes the checks that the only valid JDBC HA options are SHARED_STORE_MASTER and SHARED_STORE_SLAVE. --- .../core/server/impl/ActiveMQServerImpl.java | 20 ++++++++--- .../impl/HAPolicyConfigurationTest.java | 19 +++++++++++ .../database-store-no-hapolicy-config.xml | 33 +++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 artemis-server/src/test/resources/database-store-no-hapolicy-config.xml 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 bcbbca1bee..1b4b0d1e81 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 @@ -63,6 +63,7 @@ import org.apache.activemq.artemis.core.config.ConfigurationUtils; import org.apache.activemq.artemis.core.config.CoreAddressConfiguration; 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; @@ -438,11 +439,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()); } 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 7bae74e249..4d9bf75ea4 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,8 +42,24 @@ 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"); 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 0000000000..61a6a84ea9 --- /dev/null +++ b/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml @@ -0,0 +1,33 @@ + + + + + + jdbc:derby:target/derby/database-store;create=true + BINDINGS + MESSAGE + LARGE_MESSAGE + PAGE_STORE + org.apache.derby.jdbc.EmbeddedDriver + + + +