title: Java application connecting to MariaDB servers using Pacemaker
body: <p>I'm trying to test out MariaDB, Galera, and Corosync/Pacemaker to understand clustering with high-availability using CentOS 7 servers. The cluster size I am using for testing is 3 servers to prevent quorum issues for the most part. My tests and application are written in Java.</p>
  
  <p>I have the clustering part down; it works in an active-active configuration and runs just fine. As well, I have HA set up using Pacemaker and corosync. I've done many tests with it in failing the slaves or bringing them up during the run. As well, I've written to all three at run-time regardless of if it was the master connection or one of the child connections. When I try to test the Master going down during run-time (to simulate a power outage, server crash, or whatever in the data center), the application immediately stops running. I get a <code>java.net.SocketException</code> error and the application closes with the other two connections being shut down successfully. I've used both the <code>kill</code> and <code>stop</code> commands in the terminal to test and see if it'll work (just in the off chance it would).</p>
  
  <p><strong>JDBC URL String</strong></p>
  
  <p>Below is the part of the code that connects the application to the cluster. It connects correctly and does work until I cause the first master to go down; the other two going down does not affect this.</p>
  
  <pre><code>public void connections() {
          try {
              bigConnec = DriverManager.getConnection(
                      "jdbc:mariadb:sequential:failover:loadbalance://"
                      + "10.32.18.90,10.32.18.91,10.32.18.92/"+DB+"?autoReconnect=true&amp;failOverReadOnly=false"
                              + "&amp;retriesAllDown=120", 
                      "root", "PASS");
              bigConnec.setAutoCommit(false);
  
          } catch(SQLException e) {
              System.err.println("Unable to connect to any one of the three servers! \n" + e);
              System.exit(1);
          }
          ...
  }
  </code></pre>
  
  <p>There are three other connections made to each individual server so I can pull information more easily from them; that is what the ellipses indicate. The servers will exchange which is the "primary" node but the application will not connect to the next node in the list.</p>
  
  <p>I feel like the issue is in the way I have my URL set up because everything works outside of the cluster. As well, nothing happens during testing when I shut down the child nodes. The most that happens is I'll get a warning that the URL lost connection to either or both of them. Is there a way to configure the URL in such a way to allow automatic failover to the next available node in the string or do I have to go about it some other way using individual connection URLs and Objects (or an array of Connection objects) or <strike>black magic and pixie dust that really only SysAdmins know</strike> some other way I have yet to try?</p>
  
  <p><strong>What I Have Tried</strong></p>
  
  <ul>
  <li>How to make MaxScale High Available with Corosync/Pacemaker (MariaDB Article)</li>
  <li>Failover and High availability with MariaDB Connector/J (MariaDB Documentation)</li>
  <li>What is the right MariaDB Galera jdbc URL properties for loadbalance (Stack Overflow)</li>
  <li>HA Proxy Configuration with MariaDB Galera cluster (Stack Overflow)</li>
  <li>Configuring Server Failover (MySQL Documentation)</li>
  <li>Advanced Load-balancing and Failover Configuration (MySQL Documentation)</li>
  </ul>
  
  <p><strong><em>TL;DR</em></strong></p>
  
  <p>Problem: Java application is not automatically failing over despite being flagged for failover and sequential support in the JDBC URL (see <em>JDBC URL String</em>). Everything works with corosync and Pacemaker but I cannot get the Java application to transfer to the next available node to act as the primary connection when the current one goes down.</p>
  
  <p>Question: Is the issue in the URL? A follow-up to that is, if so, would it be better to use three separate connections and use the first valid one or is there something I can do to allow the application to automatically rollover to the next available connection in the current URL?</p>
  
  <p><strong>Software/Equipment</strong></p>
  
  <ul>
  <li>MariaDB 10.1.24</li>
  <li>corosync 2.4.0</li>
  <li>Pacemaker 1.1.15</li>
  <li>CentOS 7</li>
  <li>Java 8 / Eclipse Neon.3 / Eclipse 4.6.3</li>
  <li>MariaDB Connector/J 2.0.1</li>
  </ul>
  
  <p>If there is any more information you need, please do tell me in the comments and I'll update this as soon as I can!</p>