About This Blog

This blog contains some information about Java programming strongly connected to making web pages, and JEE applications.

26 January 2008 - 18:24Sequoia tests

"Sequoia is a transparent middleware solution offering clustering, load balancing and failover services for any database."

As in current company we have a lot of troubles with MySQL master-slave architecture, I did a small research to find alternative solution. So first solution which I found is Sequoia - to test it I installed two fresh FreeBSD systems with only mysql servers installed, both were configured same. I let to connect from local network, and start prepare another machine to host Sequoia.

I downloaded sequoia-2.10.9-bin.tar.gz, from download section of http://sequoia.continuent.org/HomePage, and start to setup on host machine. First we need to setup path to Sequoia directory e.g. export SEQUOIA_HOME=/home/ghost/sequoia-2.10.9-bin/. Next I had to copy mysql-connector.jar into drivers directory on Sequoia home.

First small problem I have reached was exception at InetAddress.getLocalHost(), it simple occurs when hostname was not set or set but not placed in /etc/hosts file (e.g. line "127.0.0.1 heaven heaven.my.domain" not found). After that I have controller installed, next step was setting up mysql virtual database, so I added to controller config:

 
<VirtualDatabase configFile="mysql.xml" virtualDatabaseName="myDB" autoEnableBackends="force" />
 

In mysql.xml I have configured two databases separately with only different names and URL's:

 
<DatabaseBackend name="10.0.0.10" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://10.0.0.10:3306/sequoia" connectionTestStatement="select 1">
    <ConnectionManager vLogin="user" rLogin="ghost" rPassword="ghost*1">
        <SimpleConnectionManager />
    </ConnectionManager>
</DatabaseBackend>
<DatabaseBackend name="10.0.0.11" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://10.0.0.11:3306/sequoia" connectionTestStatement="select 1">
    <ConnectionManager vLogin="user" rLogin="ghost" rPassword="ghost*1">
        <SimpleConnectionManager />
    </ConnectionManager>
</DatabaseBackend>
 

After successful launching last thing to do was creating simple client and check what databases would have after this step. Of course everything was great, both databases had same records, controller did great job.

 
package com.jreactor;
 
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Random;
 
public class SequoiaSimpleTest {
 
	private final static String JDBCURL = "jdbc:sequoia://127.0.0.1:25322/myDB?user=user&password=";
 
	static Connection connection;
 
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
 
		Class.forName("org.continuent.sequoia.driver.Driver");
 
		connection= DriverManager.getConnection(JDBCURL);
 
		Statement statement = connection.createStatement();
 
		String sql;
		sql = "drop table TestTableA";
		statement.execute(sql);
 
		sql = "create table TestTableA (id int(11) auto_increment primary key, name varchar(255))";
		statement.execute(sql);
 
		for(int i = 0; i < 10; i++) {
			new SequoiaSimpleTest().new SomeInserts(i).start();
		}
	}
 
	class SomeInserts extends Thread {
		private int threadId;
 
		public SomeInserts(int threadId) {
			this.threadId = threadId;
		}
 
		public void run() {
			try {
				StringBuilder sb;
				PreparedStatement statement2 = connection.prepareStatement("insert into TestTableA values (null, ?)");
				Random random = new Random(1000000);
				for(int i = 0; i < 1000; i++) {
					sb = new StringBuilder();
					sb.append(threadId);
					sb.append(" - ");
					sb.append(random.nextInt());
					statement2.setString(1, sb.toString());
					statement2.execute();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
}
 

No Comments | Tags: Sequoia, databases