-
1. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
belaban Jun 3, 2006 10:22 AM (in response to brian.stansberry)where's the list of nodes of the cluster from which you pick a singleton, e.g. ?
Address pickSingleton(Collection nodes) ? -
2. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
brian.stansberry Jun 3, 2006 11:13 AM (in response to brian.stansberry)I was thingking the policy has access to the HAPartition and DRM and knows the service name, so it can find out who the nodes are. So, reduce the coupling between the singleton and the policy by not making the singleton responsible for providing the topology.
But, the singleton is going to ask the policy who's been elected because it got a notification of a topology change, so it makes sense to pass the topology.
If the singleton provides the topology, then I'd say:
Address pickSingleton(List nodes)
List because order is important to most policies.
I like getting Address back instead of boolean -- that way the singleton knows who the master is. I'd keep a boolean version as well though, as a convenience, i.e.
public boolean isElectedSingleton(List node) {
return pickSingleton(nodes).equals(partition.getLocalAddress());
} -
3. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
alexfu.novell Jun 16, 2006 4:30 PM (in response to brian.stansberry)OK.
I will have an abstract class
org.jboss.ha.singleton.HASingletonElectionPolicyBase
and one implementation class
org.jboss.ha.singleton.HASingletonElectionPolicySimple which elects the master node based on attribute "position" defined in the MBean descriptor. Here is how position is defined:* The value will be divided by partition size and only remainder will be used. * * Let's say partition size is n: * 0 means the first oldest node. * 1 means the 2nd oldest node. * ... * n-1 means the nth oldest node. * * -1 means the youngest node. * -2 means the 2nd youngest node. * ... * -n means the nth youngest node.
The interfaces will change slightly to be consistent with ClusterPartition:InetAddress pickSingleton(Vector nodes);
Also this one without parameter may remain by calling ClusterPartition.getCurrentView() to get the Vector of nodes./** * Conducts an election and returns whether the managed singleton * is the master. */ public boolean isElectedMaster() { return pickSingleton(this.mPartition.getCurrentView()). equals(this.mPartition.getNodeAddress()); }
I haven't figured out how to do unit test on this but am working on it. -
4. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
brian.stansberry Jun 18, 2006 8:19 PM (in response to brian.stansberry)"AlexFu.Novell" wrote:
one implementation class
org.jboss.ha.singleton.HASingletonElectionPolicySimple which elects the master node based on attribute "position" defined in the MBean descriptor. Here is how position is defined
Good. If "position" is undefined, it should default to 0, which is the current behavior.
The interfaces will change slightly to be consistent with ClusterPartition:InetAddress pickSingleton(Vector nodes);
The return type should be org.jboss.cluster.ha.framework.interfaces.ClusterNode -- the contents of the Vector are actually ClusterNode objects.I haven't figured out how to do unit test on this but am working on it.
Take a look at org.jboss.test.cluster.test.DRMTestCase.testIsMasterReplica() and others in that class -- it uses a mock HAPartition that doesn't actually communicate over the network; the test driver then programatically changes the view.
Another approach is to implement http://jira.jboss.com/jira/browse/JBAS-2560 -
5. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
alexfu.novell Jun 30, 2006 4:39 PM (in response to brian.stansberry)The code change has been checked in. The sample configuration can be found at: testsuite/src/resources/ha/electionpolicy/META-INF/jboss-service.xml.
A HASingleton mbean will look like this:<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>jboss:service=${jboss.partition.name:DefaultPartition}</depends> <depends>jboss.examples:service=HASingletonMBeanExample_1</depends> <depends optional-attribute-name="HASingletonElectionPolicyMBean" proxy-type="attribute">jboss.examples:service=HASingletonMBeanExample-HASingletonElectionPolicySimple_1</depends> <attribute name="PartitionName">${jboss.partition.name:DefaultPartition}</attribute> <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>
-
6. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
brian.stansberry Jun 30, 2006 5:54 PM (in response to brian.stansberry)Great. Thanks :-)
If the user doesn't inject an HASingletonElectionPolicy, will HASingletonController default to creating an instance of HASingletonPolicySimple with a position of 0? -
7. Re: JBAS-2499 Configurable Policy to Elect HASingleton Maste
alexfu.novell Jul 1, 2006 9:38 PM (in response to brian.stansberry)No. It doesn't create a default HASingletonElectionPolicySimple. But it will use the old logic so the behavior should be equivalent to HASingletonElectionPolicySimple with position of 0.
This situation is tested in the unit test."bstansberry@jboss.com" wrote:
If the user doesn't inject an HASingletonElectionPolicy, will HASingletonController default to creating an instance of HASingletonPolicySimple with a position of 0?