Using Sequoia with GlassFish
Sequoia is a open source database clustering middleware that allows any Java application to transparentlyaccess a cluster of databases through JDBC.No code change is required to enable an application to
have failover, replication capabilities.
This demo will have the modified sample application from Netbeans, deployed in GlassFish,
interacting with Sequoia controller for database operations. The only change needed in the sample is to
configure the properties of jdbc-connection-pool to interact with Sequoia controller.
Bundles used :
GlassFish v2 build 38Sequoia 2.10.6
Netbeans 5.5.1 beta
Setup :
Install GlassFish & NetbeansGlassFish server can be registered through Netbeans > Runtime > Servers > Sun Java System Application Server
![]() |
Installation of Sequoia :
Extract the downloaded bundle and set the environment variable SEQUOIA_HOME to the installation (extracted) directory.Sequoia has sample configurations for various modes. This demo will modify and use the "hsqldb-raidb1-distribution-1.xml"
available in SEQUOIA_HOME/config/virtualdatabases to work with JavaDB bundled with GlassFish.
Sequoia Controller :
Controller is responsible for delegating the requests to underlying databases that are transparent to the application.Behind the scenes, sequoia will log the requests in a recovery table that will be used during recovery of a failed node
(database). The entire setup can be distributed ie., Application, Sequoia controller, databases to store the application data,
database to store the recovery log can all be distribued. Controller will load balance the read operations (queries) to one
of the database nodes and will replicate the write operations (create, drop, insert, delete, update) to all the database nodes.
Configuration of virtual database:
Virtual database represents the configuration of individual database nodes, recovery db node and has credentials for applicationto connect to controller.
copy "hsqldb-raidb1-distribution-1.xml" as "hetero-raidb1-distribution-1.xml"
Change VirtualDatabase name to "heterodb"
Set the "admin" password of AuthenticationManager to "adminadmin" [To do controller operations]
Set the virtualuser login of AuthenticationManager to "jdbc" and password to "jdbc" [For applications to interact with Sequoia]
For this demo, Derby is used in embedded mode.
Configuring individual database nodes for data replication :
|
<DatabaseBackend name="localhost1"
driver="org.apache.derby.jdbc.EmbeddedDriver"
url="jdbc:derby:heterodb1;Password=APP;User=APP;databaseName=heterodb1;create=true;"
connectionTestStatement="select count(*) from sys.systables"> <ConnectionManager vLogin="jdbc" rLogin="APP" rPassword="APP"> <VariablePoolConnectionManager initPoolSize="10" minPoolSize="5" maxPoolSize="50" idleTimeout="30" waitTimeout="10"/> </ConnectionManager> </DatabaseBackend> <DatabaseBackend name="localhost2" driver="org.apache.derby.jdbc.EmbeddedDriver" url="jdbc:derby:heterodb2;Password=APP;User=APP;databaseName=heterodb2;create=true;" connectionTestStatement="select count(*) from sys.systables"> <ConnectionManager vLogin="jdbc" rLogin="APP" rPassword="APP"> <VariablePoolConnectionManager initPoolSize="10" minPoolSize="5" maxPoolSize="50" idleTimeout="30" waitTimeout="10"/> </ConnectionManager> </DatabaseBackend> |
Configuring recovery log table :
|
<RecoveryLog driver="org.apache.derby.jdbc.EmbeddedDriver" url="jdbc:derby:recoverydb1;Password=APP;User=APP;databaseName=recoverydb1;create=true;" login="APP" password="APP"> <RecoveryLogTable tableName="RECOVERY" logIdColumnType="BIGINT" vloginColumnType="VARCHAR (500) " sqlColumnType="VARCHAR(500)" extraStatementDefinition=",PRIMARY KEY (log_id)"/> <CheckpointTable tableName="CHECKPOINT" checkpointNameColumnType="VARCHAR(500) "/> <BackendTable tableName="BACKEND" databaseNameColumnType="VARCHAR(500) " backendNameColumnType="VARCHAR(500) " checkpointNameColumnType="VARCHAR(500) "/> <DumpTable tableName="DUMP" dumpNameColumnType="VARCHAR(500) " dumpDateColumnType="TIMESTAMP" dumpPathColumnType="VARCHAR(500) " dumpFormatColumnType="VARCHAR(500) " checkpointNameColumnType="VARCHAR(500) " backendNameColumnType="VARCHAR(500) " tablesColumnType="VARCHAR(500) "/> </RecoveryLog> |
Configuring the Backuper :
Backuper is used to take complete backup of a node (backend) and can be used to create a new backend ortransfer the backup to another controller to bring back the controller from failure.
Above sample configration uses Derby's Embedded driver and hence setting Derby Embedded backuper.
|
<Backup> <Backuper backuperName="DerbyEmbeddedBackuper" className="org.continuent.sequoia.controller.backup.backupers.DerbyEmbeddedBackuper" options="zip=true"/> </Backup> |
Complete virtual database configuration file can be downloaded from here and copied to SEQUOIA_HOME/config/virtualdatbases
Copy the JavaDB driver (derby.jar available in GlassFish_Install_Dir/javadb/lib) to $SEQUOIA_HOME/drivers so that they
are available for Sequoia controller.
Controller configuration :
Configuration file sample is available at SEQUOIA_HOME/config/controllercopy "controller-distributed-1.xml" to "hetero-distributed-1.xml" and set the virtual database to use.
| <VirtualDatabase configFile="hetero-raidb1-distribution-1.xml" virtualDatabaseName="heterodb" autoEnableBackends="true"/> |
Complete controller configuration file can be downloaded from here and copied to SEQUOIA_HOME/config/controller
Starting the Sequoia controller :
SEQUOIA_HOME/bin/controller.sh -f config/controller/hetero-distributed-1.xml
20:31:21,629 INFO controller.core.Controller Sequoia controller (2.10.6) |
Initializing the nodes using the Sequoia console:
SEQUOIA_HOME/bin/console.sh
Launching the Sequoia controller console |
Now both the nodes are initialized and can serve for replication.
Sample application :
Start Netbeans, Create a new project > Samples > Enterprise > CustomerCMP

select the jdbc-connection-pool

and change the configuration (DataSource Classname, Properties) to point to sequoia controller

For GlassFish to talk to Sequoia controller, copy the Sequoia jdbc-driver from $SEQUOIA_HOME/drivers/sequoia-driver.jar to
GLASSFISH_HOME/domains/domain/lib/ext
All the set up is done to build & deploy the application to GlassFish.
From Netbeans, build & deploy the sample application. This will build the project, generate .ear file, start GlassFish,
create connection pools, deploy the application to GlassFish
Once the deployment is successful, run project from Netbeans.
Netbeans will open the browser with the web-application's URL.

Customer CMP application :
Simple application where customer details can be captured.
Create a new customer and ensure that the entries are persisted, through the "search" option provided in the application.

Now, to check the fail-over functionality, disable one of the node (backend) through Sequoia console.
heterodb(admin) > disable localhost2 |
Sequoia Controller will have similar logs :
22:33:13,236 INFO controller.RequestManager.heterodb All activity is suspended for heterodb |
Create another customer and ensure that the entries are persisted. [Behind the scenes, localhost1 alone will have
the entries and localhost2 is disabled/down]

Now disable localhost1 and enable localhost2
heterodb(admin) > disable localhost1 |
Access the application, search for customers of last name "Prasath"

There will not be any change in behavior of the application.
Behind the scenes, when localhost2 is enabled, all the entries will be persisted into localhost2 from recovery log's last
known checkpoint and ensure transparent failover & replication.
Multiple controllers :
It is possible to have more than one controller for a virtual database. In such a case, URL for the application will be,for eg : jdbc:sequoia://127.0.0.1:25322,127.0.0.1:25323/heterodb
Controller-2, virtual database configured similar to as shown above. Backends can be localhost3, localhost4.
Complete controller-2, virtual database file , configuration file can be copied to SEQUOIA_HOME/config/virtualdatabase, SEQUOIA_HOME/config/controller respectively.
With 2 controllers available, it is possible to shutdown an controller as a whole for maintenance. In case one of the controller
fails (eg, controller-2), sequoia driver will use the other and ensures availability. Backup can be taken on controller-1,
transferred to controller-2 and nodes can be restored.
Steps in brief :
Disable the backends of controller-2Add new customers using the application.
Take database dump of localhost1.
localhost:1090 > admin
|
Bring back controller-2
heterodb(admin) > show controllers |
Transfer the backup from controller-1 to controller-2 :
heterodb(admin) > transfer dump localhost1.bkp 127.0.0.1:1091 nocopy |
heterodb(admin) > restore backend localhost3 localhost1.bkp.2 |
Disable controller-1
heterodb(admin) > disable localhost2
|
Access the application, customers added when controller-2 was disabled will be visible via controller-2.
References :
GlassFish
Sequoia - Tutorial
Sequoia - Installation Guide
Sequoia - Administration Guide
Netbeans
Technorati Tags: glassfish
