Menu

HSQLDB clustering issue

Help
Fashimpaur
2013-07-15
2013-07-18
  • Fashimpaur

    Fashimpaur - 2013-07-15

    I am having issue connecting an HSQLDB cluster and am looking for your assistance.

    I have implemented the following DB configuration in my Java Code.

    @SuppressWarnings({ "unchecked", "rawtypes" })
    private void setupDbCluster() {
    
        // Cluster Database definitions
        DriverDatabase db1 = new DriverDatabase();
        db1.setId("db1");
        db1.setLocation(gJdbcPrimaryConnect);
        db1.setUser(gDbUser);
        db1.setPassword(gDbPass);
        db1.setActive(true);
    
        DriverDatabase db2 = new DriverDatabase();
        db2.setId("db2");
        db2.setLocation(gJdbcSecondaryConnect);
        db2.setUser(gDbUser);
        db2.setPassword(gDbPass);
        db2.setActive(true);
    
        // Cluster Configuration
        DriverDatabaseClusterConfiguration config = new DriverDatabaseClusterConfiguration();
        config.setDatabases(Arrays.asList(db1,db2));
        config.setDialectFactory(new HSQLDBDialectFactory());
        config.setDatabaseMetaDataCacheFactory(new SimpleDatabaseMetaDataCacheFactory());
        config.setStateManagerFactory(new SimpleStateManagerFactory());
        config.setDispatcherFactory(new JGroupsCommandDispatcherFactory());
    
        // register configuration
        Enumeration<java.sql.Driver> drivers = DriverManager.getDrivers();
        while (drivers.hasMoreElements()) {
            java.sql.Driver driver = drivers.nextElement();
            if (driver instanceof Driver) {
                ((Driver) driver).getConfigurationFactories().put(gClusterID, new SimpleDatabaseClusterConfigurationFactory(config));
            }
        }
    }
    

    The primary and secondary location String values are in the form jdbc:hsqldb:hsql://<ip address>/<alias>.

    The server comes up and I can see logged a cluster lock and a cluster state.

    When an entry is attempted to be written into either database, there is nothing written to the opposite db. Am I missing any configuration steps that should make this work?

    Also note the section where the drivers are being added to the ConfigurationFactories. I am using JDK1.6 in eclipse Juno and it would not allow me to use the for(Driver d : DriverManager.getDrivers()) as was shown in the example in the wiki. Additionally, it would not allow me to specify it as "New SimpleDatabaseClusterConfigurationFactory<Driver,DriverDatabase>(config) because it gave error that the constructor was not found. I am only using the jarfiles locally.

    Please help as this is important to getting our DB to have high availability.

    Dennis

     

    Last edit: Fashimpaur 2013-07-15
  • Fashimpaur

    Fashimpaur - 2013-07-15

    Each server running the application has a copy of the HSQLDB. The configuration file for both machines currently have the location of DB1 pointing to the first server and DB2 pointing to the second server.

     

    Last edit: Fashimpaur 2013-07-15
  • Paul Ferraro

    Paul Ferraro - 2013-07-18

    What do you mean by: "When an entry is attempted to be written into either database, there is nothing written to the opposite db." How are you writing an entry into the database? Can you attach the relevant JDBC client code that you are using to obtain connections?

     
  • Fashimpaur

    Fashimpaur - 2013-07-18

    Getting the connection, I do the following:

    Connection conn = DriverManager.getConnection("jdbc:ha-jdbc:" + gClusterId, gDbUser, gDbPass);
    

    gClusterId is set to the same value on both machines.
    gJdbcPrimaryConnect is "jdbc:hsqldb:hsql://<main_server_ip_address>/xdb" on both servers.
    gJdbcSecondaryConnect is "jdbc:hsqldb:hsql://<second_server_ip_address>/xdb" on both servers.

    What I mean is, I start the main db server on one machine followed by the secondary on a friend's machine on the same network. Then I start my webapp on the primary machine followed by the secondary on the friend's machine.

    When the primary webapp receives a post to put information in the db, it gets written in the primary db but the secondary db does not reflect the same information. It does not seem to be sync'd with the primary such that they do not really seem clustered and communicating.

     
  • Paul Ferraro

    Paul Ferraro - 2013-07-18

    Can you verify the cluster state on each machine? To do this, look for the appropriate mbeans in JConsole while the app is running on each machine. By setting a command dispatcher factory to JGroupsCommandDispatcherFactory, you've indicated that your servers should keep their cluster state in sync (so that each server has a consistent view of which databases are active). If everything is working correctly, JConsole should report the activeDatabases as [db1, db2] on each server.

     
  • Fashimpaur

    Fashimpaur - 2013-07-18

    Where do I find JConsole? For testing purposes, I am starting each db from a cmd prompt and the webapp is launched using Eclipse Juno.

     
  • Paul Ferraro

    Paul Ferraro - 2013-07-18

    It doesn't have to be jconsole - any JMX console will work. jconsole is available from the jdk of either openjdk or oracle's jdk.

     

Log in to post a comment.