Menu

database auto activation problem

Help
2012-02-08
2012-09-28
  • Ashish Rawat

    Ashish Rawat - 2012-02-08

    Hi All (Paul),

    I have a setup with 2 tomcats and 3 HSQLDB databases being accessed through
    Hibernate and HA-JDBC. Here is my ha-jdbc config xml

    <ha-jdbc>
    <distributable/>
    <sync id="full" class="net.sf.hajdbc.sync.FullSynchronizationStrategy">
    <property name="fetchSize">1000</property>
    <property name="maxBatchSize">100</property>
    </sync>
    <cluster balancer="round-robin" meta-data-cache="none" failure-detect-="" schedule="* * * ? * *" auto-activate-schedule="* * * ? * *" dialect="HSQLDB" default-sync="full" transact<br="">ion-mode="serial">
    <database id="database1">
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:hsql://node1:9010/rubix</url>
    <user>sa</user>
    <password></password>
    </database>
    <database id="database2">
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:hsql://node2t:9010/rubix</url>
    <user>sa</user>
    <password></password>
    </database>
    <database id="database3">
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:hsql://node1:9011/rubix</url>
    <user>sa</user>
    <password></password>
    </database>
    </cluster>
    </ha-jdbc>

    The problem I am facing is that if I bring down database1 and database2 while
    database3 is still running, and then bring up database2, then auto-activate-
    schedule does not activate database2 till database1 is also brought up.
    Similarly, if any of database 1or database2 is down and then database3 is
    brought down and then back up, then it is never activated automatically.

    In short, it seems that a database which comes lower in the ha-jdbc XML
    requires all databases above it to be active before it can be activated. Is it
    some policy or some problem with my configuration. Please help!

    Regards,
    Ashish

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-08

    Just to clarify...my observation is solely based on auto-activation of
    database nodes. Manual activation using jconsole is working fine

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-08

    I had a look at the code and I think there is some problem here:

    class AutoActivationTask implements Runnable
    {
    /
    @see java.lang.Runnable#run()
    /
    @Override
    public void run()
    {
    for (String databaseId: AbstractDatabaseCluster.this.getInactiveDatabases())
    {
    AbstractDatabaseCluster.this.activate(databaseId);
    }
    }
    }

    In case database1 and database2 are down and database2 is brought up, then the
    list of inactive databases include database1 and database1. This code tries to
    activate database1 first but an exception is thrown since database1 is down
    and therefore database2 is never activated. Database2 will be activated only
    when database1 is active.

    Paul,
    Could you please verify if my reading into this code is right and if this is
    indeed a bug?

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-08

    Correct. We need to catch any exception thrown during activate, log it, and
    continue.
    I'll fix this today.

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-09

    Hi Paul,

    I checked out the latest code today from svn repository. Initially the class
    src/main/java/net/sf/hajdbc/util/Objects.java was not compiling because the
    return value from some methods was not <T> as mentioned in method signature. I
    modified the files and compiled into ha-jdbc-2.1-SNAPSHOT.jar. But when I use
    it in my setup, then I get the following exception:

    java.sql.SQLException: No suitable driver found for jdbc:ha-jdbc:pool:cluster1
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProv
    iderImpl.getConnection(DriverManagerConnectionProviderImpl.java:171)
    at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepa
    re(SuppliedConnectionProviderConnectionHelper.java:50)
    at
    org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52)
    at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:346)
    at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:283)

    It appears that there is no code to register the Driver class with
    DriverManager in 2.1, whereas it was there in 2.0.x as below

    static
    {
    try
    {
    DriverManager.registerDriver(new Driver());
    }
    catch (SQLException e)
    {
    logger.error(Messages.getMessage(Messages.DRIVER_REGISTER_FAILED,
    Driver.class.getName()), e);
    }
    }

    Please advice how to register this new Driver class and make it work with
    Hibernate.
    As of now I am trying to configure ha-jdbc with the following settings in
    hibernate.cfg.xml:

    <property name="connection.driver_class">net.sf.hajdbc.pool.sql.PoolingDriver</property>
    <property name="connection.url">jdbc:ha-jdbc:cluster1</property>

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-09

    A small correction, the hibernate setting is
    <property name="connection.driver_class">net.sf.hajdbc.pool.sql.Driver</property>
    <property name="connection.url">jdbc:ha-jdbc:cluster1</property>

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-09

    After adding the static block to register the Driver, at least the "No
    suitable driver found" error has gone away, now I have run into troubles with
    my XML configuration.

    Paul,
    Could you please advice if 2.1 is not ready for use because this all was
    working fine for me with 2.0.x till I found the issue with activation of
    nodes. Should I try to fix that issue in 2.0.x code only instead moving to
    2.1. Please reply asap, I am losing a lot of time in trying to make 2.1 work.

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-09

    The code in trunk requires Java 1.6. In Java 1.6, JDBC drivers are loaded via
    ServiceLoader (see META-INF/services/java.sql.Driver) - and no longer need to
    perform explicit DriverManager registration.
    (I'll checkout the compilation issue with Objects.java - I suspect there's a
    file that I neglected to commit).

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-09

    2.1 is still a work in progress (as you can see), so I'd recommend sticking
    with branches/2.0 unless you have time to spare.
    Out of curiosity, what issues are you having with your XML configuration? I'm
    not aware of any bugs in that part of the code in svn trunk. Note there are
    schema changes between 2.0 and 2.1.

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-09

    BTW - I did a clean checkout and compile from svn trunk and I don't see the
    compiler error you mentioned. Which jdk are you using?

     
  • Ashish Rawat

    Ashish Rawat - 2012-02-10

    Thanks for your reply.

    I have java 1.6 update 23, but I will cross-check to see why I am having
    Driver registration and compilation issues if I am already running java 1.6.
    The XML issue I was referring to is only because of the schema change, I will
    modify the ha-jdbc XML accordingly if I continue to use 2.1.

    Could you please let me know if you are still doing bug fixing in branches/2.0
    and have you fixed the activation issue in branches/2.0?
    (On a separate note, is there a way I could contribute to this project?)

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-10

    Make sure that the generated jar contains the META-
    INF/services/java.sql.Driver file. Without this, the DriverManager service
    loader won't find the ha-jdbc jar. Are you bundling HA-JDBC in your
    application? or did you put the jar in $CATALINA_HOME/lib or similar?

    I am doing bug fixes on branches/2.0. I haven't ported the auto-activate fix,
    but I'll do that now. As far as contributing, the best way to do that is to
    find bugs and send me your patches. I plan to migrate the source code from
    subversion to git soon, which should make contributing to HA-JDBC easier,
    especially for people that want to contribute larger changes and features.

     
  • Paul Ferraro

    Paul Ferraro - 2012-02-16

    BTW - I migrated the source code repository to github over the weekend:
    https://github.com/ha-jdbc/ha-jdbc

     

Log in to post a comment.