Menu

auto deactivation disabled

Help
2013-02-03
2013-02-04
  • Bhupesh Goel

    Bhupesh Goel - 2013-02-03

    Hi paul,

    I have a 2 node setup consisting of 2 separate instances of HA-JDBC part of two different tomcat. Each instance of HA-JDBC is connected to same set of 2 HSQL DBs. In my setup if i bring down one instance of tomcat as well as HSQL DB in same node then it doesn't get deactivated in other node. I am not using local tag in database config. Shouldn't down HSQL be deactivated in other node HA-JDBC instance? If this behavior is intentional then is there a way i can enforce deactivation in two node setup.

     
  • Paul Ferraro

    Paul Ferraro - 2013-02-03

    You need to add <distributable/> to your ha-jdbc configuration file. See the "Distributed capabilities" section of the docs.

     

    Last edit: Paul Ferraro 2013-02-03
    • Bhupesh Goel

      Bhupesh Goel - 2013-02-04

      I am using distributable tag as well. Even then it doesn't get deactivated.

       
  • Paul Ferraro

    Paul Ferraro - 2013-02-04

    OK - so let me see if I fully understand your scenario...
    You have 2 tomcat nodes, each with an HSQLDB instance. When you shutdown one tomcat instance, the HSQLDB for that node is not getting deactivated, correct?

    Currently, HA-JDBC will only deactivate a database if:
    a. it tries to use it and it is unresponsive (lazy detection)
    b. an failure-detect-schedule is configured (eager detection)

    So, as you can see, we never deactivate database as part of a lifecycle of a cluster. However, I think you raise a good point. Upon shutdown, it would make sense for HA-JDBC to deactivate all "local" databases - since these will be detected and deactivated by remote nodes eventually.

     
  • Paul Ferraro

    Paul Ferraro - 2013-02-04

    OK - I just added this logic to master. However, there is no universal mechanism for HA-JDBC to detect when your server is shutting down (except in order to leverage this functionality, you'll need to add a lifecycle listener to your Tomcat instances that triggers shutdown of your HA-JDBC cluster when your server or context shuts down.

    Let's assume that we want to add a listener at the server level. In this case, you would add the following to your server.xml:
    e.g.

    <Server>
        <Listener class="org.myorg.DriverDatabaseClusterLifecycleListener" cluster="mycluster"/>
        <Service>...</Service>
    </Server>
    

    DriverDatabaseClusterLifecycleListener would look something like:

    package org.myorg;
    
    public class DriverDatabaseClusterLifecycleListener implements org.apache.catalina.LifecycleListener
    {
        private String cluster;
    
        public void lifecycleEvent(org.apache.catalina.LifecycleEvent event)
        {
            if (event.getLifecycle().getState() == LifecycleState.STOPPED)
            {
                net.sf.hajdbc.sql.Driver driver = (net.sf.hajdbc.sql.Driver) java.sql.DriverManager.getDriver("jdbc:ha-jdbc:" + this.cluster);
                try
                {
                    driver.stop(this.cluster);
                }
                catch (java.sql.SQLException e)
                {
                    // Log the exception
                }
            }
        }
    
        public void setCluster(String cluster)
        {
            this.cluster = cluster;
        }
    }
    
     
  • Bhupesh Goel

    Bhupesh Goel - 2013-02-04

    paul,

    there is slight change in the scenario you described above. When i shutdown one tomcat instance as well as kill HSQLDB on same node, killed HSQLDB is not getting deactivated in other node HA-JDBC. I am using ha-jdbc v2.0.16.

     
  • Paul Ferraro

    Paul Ferraro - 2013-02-04

    HA-JDBC 2.0.x does not automatically deactivate database when you shutdown your server. I just added this logic to 2.1 (in master).

    The code I posted above is for HA-JDBC 2.1. I highly recommend upgrading...

    The equivalent listener logic in 2.0.x would involve unregistering the relevant mbeans from the mbean server (there is no public stop() method on the HA-JDBC driver in 2.0.x).

     
  • Bhupesh Goel

    Bhupesh Goel - 2013-02-04

    Paul,

    i guess you didn't get my scenerio. let us say we have distributed setup of tomcat_1 and tomcat_2 in node 1 and node 2. Same way we have hsql_1, hsql_2. When i kill tomcat_2 and hsql_2 in 2nd node then ha-jdbc instance in tomcat_1 doesnt deactivate hsql_2 and shows both hsql_1 and hsql_2 as active. I am not using local attribute with database. So, ideally ha-jdbc in tomcat_1 should deactivate hsql_2.

    I guess it has to do something with 1 node cluster. There is a check in ha-jdbc code where if number of remote nodes in cluster is zero then ha-jdbc skip deactivation step altogether.

     

Log in to post a comment.