activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [2/2] activemq-artemis git commit: ARTEMIS-1762 JdbcNodeManager shouldn't be used if no HA is configured
Date Tue, 27 Mar 2018 14:10:42 GMT
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.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/b89fa74f
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/b89fa74f
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/b89fa74f

Branch: refs/heads/master
Commit: b89fa74f8ab431bfae06dff4a680ffebb5a0dd36
Parents: caa1964
Author: Francesco Nigro <nigro.fra@gmail.com>
Authored: Thu Mar 22 15:51:42 2018 +0100
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Mar 27 10:10:35 2018 -0400

----------------------------------------------------------------------
 .../core/server/impl/ActiveMQServerImpl.java    | 20 +++++++++---
 .../config/impl/HAPolicyConfigurationTest.java  | 19 +++++++++++
 .../database-store-no-hapolicy-config.xml       | 33 ++++++++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b89fa74f/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 bcbbca1..1b4b0d1 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());
       }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b89fa74f/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/b89fa74f/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..61a6a84
--- /dev/null
+++ b/artemis-server/src/test/resources/database-store-no-hapolicy-config.xml
@@ -0,0 +1,33 @@
+<!--
+  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>
+            <jdbc-driver-class-name>org.apache.derby.jdbc.EmbeddedDriver</jdbc-driver-class-name>
+         </database-store>
+      </store>
+   </core>
+</configuration>


Mime
View raw message