Hazelcast Client API to determine which node is the master

1,700 views
Skip to first unread message

Patel Parimal

unread,
Nov 3, 2014, 7:32:27 AM11/3/14
to haze...@googlegroups.com
Hi,

I am using Hazelcast 3.3 community edition.

I want to perform map get/put operations by deciding master node of cluster.

So is there any API which can be used to determine whether this node is the master? Something like:


Set<Member> members = instance.getCluster().getMembers();

for (Member member : members) {
      if(member.isMaster()){
        // execute some task on member
return;
      }
}

Thanks.

Noctarius

unread,
Nov 3, 2014, 7:34:16 AM11/3/14
to haze...@googlegroups.com
Hi Patel,

Hazelcast clusters do not really have a master node but the oldest member has some special responsibilities. The oldest member is always the first member in the set.

Chris
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/d7f856fe-af7a-45e6-a4f3-5ad49e6cf4f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Patel Parimal

unread,
Nov 3, 2014, 7:46:32 AM11/3/14
to haze...@googlegroups.com
Thanks for the quick response.

Here are the couple of questions related to current post:

1) Will all the requests from client be sent to oldest cluster member or any load balancing mechanism is being used ?

2) If at all possible, can we get the guaranteed behaviour that all the requests from client be sent to oldest cluster member ?

Thanks.

Noctarius

unread,
Nov 3, 2014, 7:52:30 AM11/3/14
to haze...@googlegroups.com
Smart clients send all requests to the corresponding key owners and non-key-operations are send round-robin. Dummy clients send all requests to round-robin members.

To force connections to go a single node you would have to implement your own "load balancer" (com.hazelcast.client.LoadBalancer). What is the purpose of sending everything to the "master"?

Chris
--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.

Patel Parimal

unread,
Nov 3, 2014, 8:08:45 AM11/3/14
to haze...@googlegroups.com
For testing purposes I have set partition count to 1. So in a 2 node cluster, second node will serve as backup node.

Most operations are key-operations using hazelcast predicate queries.

The purpose of sending everything to the "master" is to gain performance improvement by avoiding serialization/deserialization among member nodes.

You have mentioned "Smart clients". I am using hazelcast 3.3 client, so it is a smart client right ? or we need to configure it ?

Moreover can you guide me to configure my own "load balancer" (com.hazelcast.client.LoadBalancer) ?

Thanks a lot.

Noctarius

unread,
Nov 3, 2014, 8:21:07 AM11/3/14
to haze...@googlegroups.com
Yes smart client is enabled by default, so in theory all requests should go the the partition owner anyways (it is not necessarily the oldest member!). To configure your own load balancer you have to manually change the load balancer on the ClientConfig instance before creation of the client.

ClientConfig clientConfig = new XmlClientConfigBuilder().build();
clientConfig.setLoadBalancer(new MyLoadBalancer());
HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);

Patel Parimal

unread,
Nov 3, 2014, 8:40:39 AM11/3/14
to haze...@googlegroups.com
Currently with hazelcast-spring-3.3.xsd schema, supported load-balancers using spring xml configuration are "round-robin" and "random".
<hz:client>
        .. 
        ..
<hz:load-balancer type="round-robin" />
        <!-- <hz:load-balancer type="random" /> -->
</hz:client>

The approach you have suggested is for programmatical configuration, to do the same using spring IoC can I go for something like this ?

<hz:load-balancer type="custom" ref="myLoadBalancerBean" />

Thanks.

Noctarius

unread,
Nov 3, 2014, 8:46:32 AM11/3/14
to haze...@googlegroups.com
Nope, sorry. At the moment there is no way to set a custom loadbalancer using XML (neither our own config file nor Spring namespace), at least not as far as I know.

M. Sancar Koyunlu

unread,
Nov 3, 2014, 8:51:30 AM11/3/14
to haze...@googlegroups.com
Hi Patel, 
Can you create an issue on github regarding custom load balancer configuration via xml and spring?
Thanks.
Sancar

Patel Parimal

unread,
Nov 3, 2014, 8:59:51 AM11/3/14
to haze...@googlegroups.com
Thanks Christoph.

Patel Parimal

unread,
Nov 3, 2014, 9:00:05 AM11/3/14
to haze...@googlegroups.com
Thanks Christoph.
Reply all
Reply to author
Forward
0 new messages