Monday, October 1, 2012

HA Singleton, Cluster Wide Singleton as MBean in JBoss 5, part 1/3

Document  Version 1.0

   Copyright © 2012-2013 beijing.beijing.012@gmail.com


Keywords:
JBoss HA  Service, HA Singleton, JBoss Cluster, load migration, load distribution, HA Service deployment



What is HA Singleton?


We know that singletons are the kind of instances or services that exists only once in an application context. When you write a singleton, deploy it in your server, you will get only one instance of this singleton on the server.

The singleton mentioned above is actually class-loader wide singleton,  i.e. one instance per class-loader. In case of high availabile cluster, when the above singleton is deployed in cluster, there will be one singleton instance in each cluster-node.

But there are cases where we need cluster-wide singleton. For example, in a clustered auction system,
bid orders can come from different node, but the process which deals with the final trading settelment should run only once in the whole cluster. When the node on which the singleton service fails, another node will start  an singleton service automatically. Such singleton is so called cluster-wide singleton, i.e. HA singleton.


We will now take JBoss as example to show how to implement a HA singleton.


JBoss supports deployment of singleton as HA singleton. There are generally 2 ways to deplyoment HA singleton on JBoss

  • option1: just put deployment archive under "../deploy-singleton/ ", and the deployment service bekomes a HA singleton. Disadvantages of this way are, no hot-deployment support, in case of node failure, service startup time takes longer...
  • option 2: deploy service as MBean. MBean support hot deployment. Singleton MBean will be deployment on all nodes,  but provides service only on one node. 

We take the second option, and show how to deploy a MBean as HA singleton:
We will configure and run a 2-nodes JBoss cluster
We will write a simple MBean.
We will deploy the MBean as HA singlleton.


Configure and run a 2-nodes JBoss cluster

Download JBoss  5.1.0_GA from www.boss.org (http://sourceforge.net/projects/jboss/files/JBoss/JBoss-5.1.0.GA).  Extract the file to some location, we will name it JBOSS_HOME hereafter.

In the extracted JBoss directory goto JBOSS_HOME/server/, create 2 new folders directly here:

node1
node2

Copy all files in JBOSS_HOME/server/all into node1.
Copy all files in JBOSS_HOME/server/all into node2.

Now we have a JBoss cluster with two nodes ready to run.


Start node1:


./run.sh -c node1 -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=1



When you have followed the above steps, you will see in the console like these:


09:57:56,551 INFO  [GroupMember] I am (127.0.0.1:56944)
09:57:56,551 INFO  [GroupMember] New Members : 1 ([127.0.0.1:56944])
09:57:56,551 INFO  [GroupMember] All Members : 1 ([127.0.0.1:56944])
09:57:56,556 INFO  [STDOUT] 

.......
09:58:03,364 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8180
09:58:03,377 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8109
09:58:03,382 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 25s:474ms

The node1 is now started.


Start node2:


./run.sh -c node2 -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=2


You will see in the console lines like these:

|1] [127.0.0.1:56944, 127.0.0.1:55687], old view is null
10:01:57,587 INFO  [GroupMember] I am (127.0.0.1:55687)
10:01:57,587 INFO  [GroupMember] New Members : 2 ([127.0.0.1:56944, 127.0.0.1:55687])
10:01:57,587 INFO  [GroupMember] All Members : 2 ([127.0.0.1:56944, 127.0.0.1:55687])
10:01:57,629 INFO  [STDOUT] 
.....

10:01:59,745 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8280
10:01:59,756 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8209
10:01:59,762 INFO  [ServerImpl] JBoss (Microcontainer) [5.1.0.GA (build: SVNTag=JBoss_5_1_0_GA date=200905221634)] Started in 17s:400ms


The second node is started, and it joined the cluster.



                  

1 comment: