[jboss-dev-forums] [Design of Clustering on JBoss] - Re: HA election policy

bstansberry@jboss.com do-not-reply at jboss.com
Mon Nov 10 15:30:28 EST 2008


Following is an extract from a config file used in a test case. It illustrates the usage in 4.x:


  | <?xml version="1.0" encoding="UTF-8"?>
  | <!DOCTYPE server>
  | <server>
  |    <!-- First HASingleton, Election policy is to choose the oldest node as master -->
  |    <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
  |           name="jboss.examples:service=HASingletonMBeanExample_1">
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_1">
  |      <attribute name="Position">0</attribute>
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonController" 
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_1">
  |       
  |       <depends optional-attribute-name="ClusterPartition"
  |          proxy-type="attribute">jboss:service=DefaultPartition</depends>
  |       <depends>jboss.examples:service=HASingletonMBeanExample_1</depends>
  |       <depends optional-attribute-name="ElectionPolicy"
  |          proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_1</depends>
  |       <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_1</attribute>
  |       <attribute name="TargetStartMethod">startSingleton</attribute>
  |       <attribute name="TargetStopMethod">stopSingleton</attribute>
  |       <attribute name="TargetStopMethodArgument">true</attribute>
  |    </mbean>
  | 
  |    <!-- Second HASingleton, Election policy is to choose the youngest node as master -->
  |    <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
  |           name="jboss.examples:service=HASingletonMBeanExample_2">
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_2">
  |      <attribute name="Position">-1</attribute>
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonController" 
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_2">
  |       
  |       <depends optional-attribute-name="ClusterPartition"
  |          proxy-type="attribute">jboss:service=DefaultPartition</depends>
  |       <depends>jboss.examples:service=HASingletonMBeanExample_2</depends>
  |       <depends optional-attribute-name="ElectionPolicy"
  |          proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_2</depends>
  |       <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_2</attribute>
  |       <attribute name="TargetStartMethod">startSingleton</attribute>
  |       <attribute name="TargetStopMethod">stopSingleton</attribute>
  |       <attribute name="TargetStopMethodArgument">true</attribute>
  |    </mbean>
  | 
  |    <!-- Third HASingleton, Election policy is to choose the 2nd oldest node as master -->
  |    <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
  |           name="jboss.examples:service=HASingletonMBeanExample_3">
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonElectionPolicySimple"
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_3">
  |      <attribute name="Position">1</attribute>
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonController" 
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_3">
  |       
  |       <depends optional-attribute-name="ClusterPartition"
  |          proxy-type="attribute">jboss:service=DefaultPartition</depends>
  |       <depends>jboss.examples:service=HASingletonMBeanExample_3</depends>
  |       <depends optional-attribute-name="ElectionPolicy"
  |          proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_3</depends>
  |       <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_3</attribute>
  |       <attribute name="TargetStartMethod">startSingleton</attribute>
  |       <attribute name="TargetStopMethod">stopSingleton</attribute>
  |       <attribute name="TargetStopMethodArgument">true</attribute>
  |    </mbean>
  | 
  |    <!-- Fourth HASingleton, No election policy defined. By default, the oldest node is selected -->
  |    <mbean code="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
  |           name="jboss.examples:service=HASingletonMBeanExample_4">
  |    </mbean>
  | 
  |    <mbean code="org.jboss.ha.singleton.HASingletonController" 
  |           name="jboss.examples:service=HASingletonMBeanExample-HASingletonController_4">
  |       
  |       <depends optional-attribute-name="ClusterPartition"
  |          proxy-type="attribute">jboss:service=DefaultPartition</depends>
  |       <depends>jboss.examples:service=HASingletonMBeanExample_4</depends>
  |       <attribute name="TargetName">jboss.examples:service=HASingletonMBeanExample_4</attribute>
  |       <attribute name="TargetStartMethod">startSingleton</attribute>
  |       <attribute name="TargetStopMethod">stopSingleton</attribute>
  |       <attribute name="TargetStopMethodArgument">true</attribute>
  |    </mbean>
  | </server>
  | 

There are four sets of beans above. Basically, in each set there is a mbean service being controlled, an mbean that implements the HASingletonElectionPolicy interfacr to conduct the election as to who is master, and an HASingletonController that calls on the election policy and starts/stops the service being controlled.

In 4.x we ship a single implementation of HASingletonElectionPolicy, org.jboss.ha.singleton.HASingletonElectionPolicySimple.  This implementation takes a single configuration element "Position", which specifies the ordinal position in the current cluster topology of the node that should be master. 0 == first, -1 == last, 1 == second, -2 == second from last, etc.  Cluster topology means, for example, you have nodes A, B, C that have a service deployed, and they started in that order, so the cluster topology for the service would be {A, B, C}.  So, position 0 would be A, position -1 would be C, position 1 or -2 would be B. The implementation uses a modulus, so position 3 would be A, 4 would be B etc.

If no policy is specified, as in the last set of beans above, the default is to use HASingletonElectionPolicySimple with a position of 0.

You can create your own implementation of HASingletonElectionPolicy and we provide a base class to start from org.jboss.ha.singleton.HASingletonElectionPolicyBase.

Note that in AS 5, the HASingletonElectionPolicy interface is changed (simplified/rationalized), with the HASingletonElectionPolicyBase class eliminated. HASingletonElectionPolicySimple still works as described above. The AS also ships with a new policy impl, PreferredMasterElectionPolicy.  This is an extension of HASingletonElectionPolicySimple that adds a new configuration property "preferredMaster" that lets you specify that you want a particular node to be the master if it is available.  Following illustrates its use.  (Note that here the config is using the JBoss Microcontainer config format rather than the legacy -service.xml format. The legacy format still works, though):


  |    <!-- 5th HASingleton, PreferredMaster set to 192.168.0.10:1099. If not available, fallback election policy is to choose the oldest node as master -->
  |    <bean class="org.jboss.ha.singleton.examples.HASingletonMBeanExample" 
  |           name="HASingletonMBeanExample_5">
  |       <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.examples:service=HASingletonMBeanExample_5", exposedInterface=org.jboss.ha.singleton.examples.HASingletonMBeanExampleMBean.class, registerDirectly=true)</annotation>
  |    </bean>
  | 
  |    <bean class="org.jboss.ha.singleton.PreferredMasterElectionPolicy"
  |           name="PreferredMasterElectionPolicy_1">
  |      <property name="position">0</property>
  |      <property name="preferredMaster">192.168.0.10:1099</property>
  |    </bean>
  | 
  |    <bean class="org.jboss.ha.singleton.HASingletonController" 
  |           name="HASingletonController_5">
  |       
  |       <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:service=HASingletonController_5", exposedInterface=org.jboss.ha.singleton.HASingletonControllerMBean.class, registerDirectly=true)</annotation>       
  |       
  |       <property name="clusterPartition"><inject bean="HAPartition"/></property>
  |       <property name="electionPolicy"><inject bean="PreferredMasterElectionPolicy_1"/></property>
  |       <property name="target"><inject bean="HASingletonMBeanExample_5"/></property>
  |       <property name="targetStartMethod">startSingleton</property>
  |       <property name="targetStopMethod">stopSingleton</property>
  |       <property name="targetStopMethodArgument">true</property>
  |    </bean>

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4188269#4188269

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4188269



More information about the jboss-dev-forums mailing list