Wrong targets come to LoadBalancePolicy
kkrivopustov Apr 20, 2007 12:56 AMHello
I'm using cluster on JBoss 4.0.4.GA and I want to implement a custom load-balancing policy. Unfortunately I faced a problem with the wrong list of targets in FamilyClusterInfo. Below I'll try to explain the situation.
I have 2 EJB3 stateless beans FooBean and BarBean annotated with @Clustered(partition = "ShamrockPartition", loadBalancePolicy = MyLoadBalancePolicy.class)
The policy is simple:
public class MyLoadBalancePolicy extends FirstAvailableIdenticalAllProxies { public Object chooseTarget(FamilyClusterInfo clusterFamily) { return super.chooseTarget(clusterFamily); } public Object chooseTarget(FamilyClusterInfo clusterFamily, Invocation routingDecision) { System.out.println("Family: " + clusterFamily.getFamilyName() + ", View: " + clusterFamily.getCurrentViewId() + ", Targets: " + clusterFamily.getTargets()); return super.chooseTarget(clusterFamily, routingDecision); } }
I deploy application onto 2 servers and then start them. A client is simply invokes each bean many times consequently. Here is the output:
Family: FooBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/]] iteration 0 success Family: FooBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/]] iteration 1 success Family: FooBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/]] iteration 2 success
As you can see, there is always wrong targets for bean BarBean. If I restart servers, the situation changes, but usually one of the beans or both have wrong targets.
The only thing which help is hot redeploy of the application, after that all beans have correct targets.
I've investigated a little and found that method FamilyClusterInfoImpl.updateClusterInfo() is executed with correct targets after each bean invocation and it updates the FamilyClusterInfo.
But when FamilyClusterInfo is obtained from ClusteringTargetsRepository, it is updated again by old incorrect values. If I comment out the line (comment "should not happen: possible if redeploy after undeploy fails" is not mine)
family.updateClusterInfo (targets, viewId); // should not happen: possible if redeploy after undeploy fails
everithing works fine and client output looks correct:
Family: FooBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: 0, Targets: [InvokerLocator [socket://192.168.3.71:3873/]] iteration 0 success Family: FooBeansocketShamrockPartition, View: -1211536571, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: -1211536571, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] iteration 1 success Family: FooBeansocketShamrockPartition, View: -1211536571, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] Family: BarBeansocketShamrockPartition, View: -1211536571, Targets: [InvokerLocator [socket://192.168.3.71:3873/], InvokerLocator [socket://192.168.3.65:3873/]] iteration 2 success
I will appreciate very much any information regarding this...
Konstantin