I want to know the Gemfire/Geode cluster size (number of members in the ds) from the clients. What is the simplest way to know this. We can get this using Function Service, but i am looking for the easier solution.
How to know Gemfire/Geode cluster size from the client
367 views Asked by Rahul Diyewar AtThere are 5 answers
I haven't tried it yet, but I believe you can execute "cache.getDistributedSystem().getAllOtherMembers()" from the client cache after you connecting. Here's the javadoc for the "DistributedSystem" class: http://gemfire.docs.pivotal.io/latest/javadocs/japi/index.html. Cheers.
Another approach involves using JMX. If you have one or more JMX Managers running in your server cluster then you can have any JVM (including a loner GemFire client) connect as a JMX client and query its mbeans.
The mbean you're interested in is DistributedSystemMXBean. It exposes:
/**
* Returns the number of members in the distributed system.
*/
public int getMemberCount();
It also exposes various other methods for listing members, groups, locators, diskstores, etc. for the entire cluster. The javadocs show all of these attributes and operations: http://gemfire.docs.pivotal.io/latest/javadocs/japi/com/gemstone/gemfire/management/DistributedSystemMXBean.html
Yes, client runs in lonar distributed system thus cache.getDistributedSystem()
from client gives instance of lonar distributed system, which doesn't have information about server cluster.
One way of doing this is using geode region itself i.e. each server puts member-id an entry in some region, then retrieve the same information from the client.
Other way is using Function Service. Below is the code snippet for the same.
Define Function Adapter:
public class CountMemberFunction extends FunctionAdapter {
private static final long serialVersionUID = 1L;
@Override
public void execute(FunctionContext fc) {
Cache c = CacheFactory.getAnyInstance();
String member = c.getDistributedSystem().getDistributedMember().getId();
fc.getResultSender().lastResult(member);
}
@Override
public String getId() {
return getClass().getName();
}
}
Register it in server:
FunctionService.registerFunction(new CountMemberFunction());
Execute the function onServers from client:
Execution execution = FunctionService.onServers(gemCache);
ResultCollector rc = execution.execute(new CountMemberFunction());
List nodes = (List)rc.getResult();
println("Server nodes are " + nodes);
Urizen, As Rahul said, client is a "loner distributed system" which is connected to another distributed system (which has multiple servers, locators, peer members), executing "cache.getDistributedSystem.getAllOhterMembers" on client DS, will give you member info of client only and not of server side distributed system.
Rahul's code snippet will provide information about server members only not peer members available in DS.
IMO we need to change Rahul's code slightly to consider peer members, locators too.
And use onServer instead of onServers