dev@shoal.java.net

Re: [Shoal-Dev] GroupLeader Test

From: Shreedhar Ganapathy <Shreedhar.Ganapathy_at_Sun.COM>
Date: Sat, 31 May 2008 09:32:36 -0700

Hi Leehui
Thanks for digging deeper on this.
In your test, are you seeing that master discovery is not completed with
a assigned master even after 10 seconds? Are you just using two members
and seeing this ?

The Master discovery timeout can be customized by specifying the
ServiceProviderConfigurationKeys.DISCOVERY_TIMEOUT as the key and a
timeout value in milliseconds.

Passing in this key value pair through a Properties object when starting
the GMS module will cause the MasterNode object to be instantiated with
this discovery timeout.

By default, the ClusterManager uses 5 seconds as the discovery timeout
for master node assignment. Look in ClusterManager's constructor and
this method in ClusterManager:
private long getDiscoveryTimeout(Map props) {
long discTimeout = 5000;
if (props != null && !props.isEmpty()) {
Object dt = props.get(JxtaConfigConstants.DISCOVERY_TIMEOUT.toString());
if (dt != null) {
discTimeout = Long.parseLong((String) dt);
}
}
return discTimeout;
}

There is certainly scope to make incremental improvements to the master
node state management, for example, notifying when discovery is finished.

Thanks
Shreedhar


leehui wrote:
> Hi Bongjae Chang,
>
> Thank you for your reply.
>
> I modified the code for com.sun.enterprise.shoal.groupleadertest.GroupLeaderTest. I set the thread sleep time to 10s , then run the test code. The results is the same as what you said. I have the same opinion with you about the group leader test. You can see GroupLeaderTest. Just because I set the thread sleep time to 2s, I didn't get true from the second invocation of groupHandle.isGroupLeader(). So I said that the second invocation of groupHandle.isGroupLeader() should return true in master node.
>
> I have another question about group leader. Can shoal or jxta provide a notification to notify the application that the MasterDiscovery process had finished? Waiting 10 or more seconds for finishing MasterDiscovery process maybe not good.
>
> Best regards!
> --
> leehui
> 2008-05-31
>
> -------------------------------------------------------------
> 发件人:Bongjae Chang
> 发送日期:2008-05-30 22:24:22
> 收件人:dev_at_shoal.dev.java.net
> 抄送:
> 主题:Re: [Shoal-Dev] GroupLeader Test
>
>
> Hi. leehui. This is old issue. But I have another opinion about this. I am sorry for replying too late.
>
> first,
> --------------------------
> Shreedhar Ganapathy wrote:
> The join() call is a blocking call in that it returns only after group
> join has occurred. So you should be able to call GroupHandle's apis
> without any waiting.
> --------------------------
> --> I could not agree Shreedhar Ganapathy's comment. When join() is called, MasterDiscovery's logic is executed at new thread. So GroupHandle.isGroupLeader() and GroupHandle.getGroupLeader() API is not safe.
>
>
> --------------------------
> leehui wrote:
> "Why isGroupLeader() returns false? I think it should return true"
> --------------------------
> --> I think GroupHandle.isGroupLeader() have meaning when all members agree or after finishing MasterDiscovery.
> Before finishing MasterDiscovery, We can not know who is group leader. So, I think isGroupLeader() can return false before finishing MasterDiscovery.
> At the following sample code, GroupHandler.isGroupLeader() returns false for a while. But after finishing MasterDiscovery (MasterAssigned == true, "every group member first elects himself as group leader"), GroupHandler.isGroupLeader() returns true if there is only one member.
>
> ...
> while( true ) {
> System.out.println(groupHandle.isGroupLeader());
> System.out.println(groupHandle.getGroupLeader());
>
> try {
> Thread.sleep(2000);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> }
> ...
>
> GroupHandle.isGroupLeader() will call ClusterManager.isMaster() finally. see following code.
> --------------------------
> ClusterManager.java
> ...
> public boolean isMaster() {
> return clusterViewManager.isMaster() && masterNode.isMasterAssigned();
> }
> --------------------------
>
> I think GroupHandler.getGroupLeader() is strange instead.
> I think if master is not assigned(e.g. before finishing MasterDiscovery, masterNode.isMasterAssigned() == false), GroupHandler.getGroupLeader() must not return own name. e.g. return unknown state?
>
> Thanks.
> --
> Bongjae Chang
>
>
> ----- Original Message -----
> From: "leehui" <leehui70_at_gmail.com>
> To: "dev" <dev_at_shoal.dev.java.net>
> Sent: Wednesday, April 30, 2008 3:55 PM
> Subject: [Shoal-Dev] GroupLeader Test
>
>
>
>> Hi,
>>
>> I write a simple class to test shoal's GroupLeader functions. The codes like this:
>>
>> import java.util.UUID;
>>
>> import com.sun.enterprise.ee.cms.core.GMSException;
>> import com.sun.enterprise.ee.cms.core.GMSFactory;
>> import com.sun.enterprise.ee.cms.core.GroupHandle;
>> import com.sun.enterprise.ee.cms.core.GroupManagementService;
>> import com.sun.enterprise.ee.cms.core.GroupManagementService.MemberType;
>>
>>
>> public class SimpleTest {
>>
>> /**
>> * @param args
>> */
>> public static void main(String[] args) {
>>
>>
>> String serverToken = UUID.randomUUID().toString();
>> GroupManagementService gms = (GroupManagementService) GMSFactory.startGMSModule(serverToken, "DemoGroup", MemberType.CORE, null);
>> try {
>> gms.join();
>> } catch (GMSException e) {
>> e.printStackTrace();
>> }
>>
>> GroupHandle groupHandle = gms.getGroupHandle();
>> System.out.println(groupHandle.isGroupLeader());
>> System.out.println(groupHandle.getGroupLeader());
>>
>> try {
>> Thread.sleep(2000);
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>>
>> System.out.println(groupHandle.isGroupLeader());
>> System.out.println(groupHandle.getGroupLeader());
>>
>>
>> }
>>
>> }
>>
>> When I run it, the console prints:
>>
>> false
>> e2fed556-ff76-4a38-9645-c1f6160dc07f
>> 2008-4-30 14:29:33 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
>> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
>> 1: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>>
>> 2008-4-30 14:29:33 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
>> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
>> false
>> e2fed556-ff76-4a38-9645-c1f6160dc07f
>>
>> (1) Why isGroupLeader() returns false? I think it should return true.
>>
>>
>> Then, I start another instance of SimpleTest, the console prints:
>>
>> false
>> 836f3c91-a20a-4edf-a13c-326028990a8e
>> 2008-4-30 14:29:46 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
>> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
>> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
>>
>> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
>> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
>> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
>> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
>> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
>> 2: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>>
>> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
>> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
>> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
>> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
>> 1: MemberId: 836f3c91-a20a-4edf-a13c-326028990a8e, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A428F46CA05A349DBA7A9B02FEBDB344803
>> 2: MemberId: e2fed556-ff76-4a38-9645-c1f6160dc07f, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49AE78AB5C0E6B94A499134E1DEA803497203
>>
>> 2008-4-30 14:29:47 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
>> 信息: Analyzing new membership snapshot received as part of event : ADD_EVENT
>> false
>> e2fed556-ff76-4a38-9645-c1f6160dc07f
>>
>> (2) The first isGroupLeader() prints false. I think it should be true. Just like my question (1).
>> (3) Form above console's info, it seems that every group member first elects himself as group leader, then communicate others to update group leader' info.
>> As there is no change notification of group leader, I think it may be better to return the true group leader after gms.join(). Otherwise, the shoal should
>> provide some callbacks. Am I right?
>>
>> When you run SimpleTest serveral times, the console may prints:
>>
>> false
>> Exception in thread "main" java.lang.NullPointerException
>> at com.sun.enterprise.ee.cms.impl.jxta.GroupCommunicationProviderImpl.getGroupLeader(GroupCommunicationProviderImpl.java:281)
>> at com.sun.enterprise.ee.cms.impl.jxta.GroupHandleImpl.getGroupLeader(GroupHandleImpl.java:398)
>> at SimpleTest.main(SimpleTest.java:28)
>> 2008-4-30 14:51:16 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow getMemberTokens
>> 信息: GMS View Change Received for group DemoGroup : Members in view for (before change analysis) are :
>> 1: MemberId: ab6418c9-84bc-49a8-af4c-d6e5b6127de4, MemberType: CORE, Address: urn:jxta:uuid-289CBAB1836A4A009242B36E1509E49A1B75978AE67A4B04A022C83142739EC103
>>
>> 2008-4-30 14:51:16 com.sun.enterprise.ee.cms.impl.jxta.ViewWindow newViewObserved
>> 信息: Analyzing new membership snapshot received as part of event : MASTER_CHANGE_EVENT
>>
>> (4) This exception occurs occasionally. But I don't know when and why it occurs. How to handle it?
>>
>> (5) Does shoal plan to expose MASTER_CHANGE_EVENT callback in future?
>>
>> Thank you in advance for your reply.
>>
>> --------------
>> leehui
>> 2008-04-30
>>
>>