Post

3 followers Follow
0
Avatar

UniversalMembershipListenerAdapter Working

Hi,

I'm using in my system a UniversalMembershipListenerAdapter, a in my Pool Connection I added two locators, each locator has a server.
When I start my application I watched that the method memberJoined is invoked with a event of each server, then if I stoped the 2 server I watched that the method memberCrashed is called for a event of each server, but then when I started the 2 server , I watch a only event of memberJoined for one server.

This is ok?

Juan Manuel Romera Ferrio

Please sign in to leave a comment.

7 comments

0
Avatar

This is probably ok, but I'll confirm with a test. Is your client actively doing puts or inactive? Is it subscription-enabled? Are you setting min-connections in the pool?

Barry Oglesby 0 votes
0
Avatar

It's subscription-enabled and min-connections is the value by default. My problems it's that I use the UniversalMembershipListenerAdapter to know if my clients are connect to at least one of servers, but with this behavior my implementation does not work in a rigth way. There is another way to know if the client is connected to the server

Juan Manuel Romera Ferrio 0 votes
0
Avatar

In my test, the client is only connecting to one of the two servers. This client doesn't do anything but start and create a cache with a subscription-enabled pool. The UniversalMembershipListenerAdapter memberJoined callback is triggered by either the pool being prefilled (1 minimum connection by default) or the subscription connection being created. When I kill the server the client is connected to, the UniversalMembershipListenerAdapter memberCrashed callback is triggered by the subscription connection being lost. This is the correct behavior since the client doesn't necessarily connect to both servers. You say you want to know if a client is connected to at least one of the servers. This is telling you exactly that, so I'm a bit confused. Are yo expecting the client to connect to all the servers?

Barry Oglesby 0 votes
0
Avatar

No, the idea is that my client is connected to at least one of the servers, but I'm having problems with the UniversalMembershipListenerAdapter, because sometimes when I stop the servers and I start again the memberJoined is not called and I'm using this logic, with the memberJoined is called I add in a list the member when crash i removed, then if the list is empty my client is not connected, but I'm looking for other way to resolve that.

Juan Manuel Romera Ferrio 0 votes
0
Avatar

It seems like there are a few possibilities.

One is that the client didn't disconnect when the server crashed. Are you seeing the memberCrashed event when the server stops in the cases where you don't see the memberJoined event when it restarts? If not, then the client never disconnected from the server, so it doesn't know to reconnect.

If you're seeing the memberCrashed event when the server leaves, but not the memberJoined event when it starts again, then either the client didn't reconnect, or it did but the callback was not invoked.

Can you do some thread dumps in the client after the server leaves, then again after the server restarts. I'm really looking for these in the context when the memberJoined event doesn't happen.

Barry Oglesby 0 votes
0
Avatar

Barry,

I'm trying to analyze this using the stats. In the PoolStats of the client's stats there is one called servers that show the number of servers discovered.In this graph I see a variation between the values ​​(2, 1, 0 ).

Comparing with the logs where I see events memberCrashed and memberLeft, I see in a specific time this:

09:17:17,563 memberLeft-> 172.29.10.232
09:35:53,823 memberCrashed-> 172.29.10.231

And in the stats in this interval, I only see that in 09:17:17,563 the servers down from 2 to 1, but event of memberCrashed is not reflected.

What's mean that?

I can get the value of current servers of stats from API ?

Juan Manuel Romera Ferrio 0 votes
0
Avatar

I see the behavior you're seeing. It only happens in certain circumstances though. I think it depends on which connection detects the serverCrashed event. I'll have to look more at that. In the meantime, here is some code you can use to track connections from the client to each server using ClientStats.

When I add this thread to my client, I see:

After starting the client:
Server 192.168.2.8:52783 connection count has increased from 0 to 1
Server 192.168.2.8:52798 connection count has increased from 0 to 1

After doing puts:
Server 192.168.2.8:52783 connection count has increased from 1 to 2
Server 192.168.2.8:52783 connection count has decreased from 2 to 1

After killing one server:
Server 192.168.2.8:52783 connection count has increased from 1 to 2
Server 192.168.2.8:52798 connection count has decreased from 1 to 0

After killing the other server:
Server 192.168.2.8:52783 connection count has decreased from 2 to 0

So in this test, the connections to each server progressed like:

Server 192.168.2.8:52783 0->1->2->1->2->0
Server 192.168.2.8:52798 0->1->0

import com.gemstone.gemfire.Statistics;
import com.gemstone.gemfire.StatisticsType;

import com.gemstone.gemfire.distributed.DistributedSystem;

private void launchServerCountUsingClientStatisticsThread() {
final DistributedSystem ds = this.cache.getDistributedSystem();
Thread thread = new Thread(
new Runnable() {

        private Map<String,Integer> previousConnectionCounts = new HashMap<String,Integer>();
        public void run() {
            while (true) {
                Statistics[] clientStatistics = getClientStats();
                for (Statistics statistics : clientStatistics) {
                    String server = statistics.getTextId().replace("ClientStats-pool-", "");
                    Integer previousConnectionCount = this.previousConnectionCounts.get(server);
                    if (previousConnectionCount == null) {
                        previousConnectionCount = 0;
                        this.previousConnectionCounts.put(server, previousConnectionCount);
                    }
                    int currentConnectionCount = getClientConnections(statistics);
                    if (currentConnectionCount != previousConnectionCount) {
                        StringBuilder builder = new StringBuilder();
                        builder
                            .append("Server ")
                            .append(server)
                            .append(" connection count has ")
                            .append(currentConnectionCount > previousConnectionCount ? "increased" : "decreased")
                            .append(" from ")
                            .append(previousConnectionCount)
                            .append(" to ")
                            .append(currentConnectionCount);
                        System.out.println(builder.toString());
                        this.previousConnectionCounts.put(server, currentConnectionCount);
                    }
                }
                try {Thread.sleep(2000);} catch (InterruptedException e) {}
            }
        }

        private Statistics[] getClientStats() {
            StatisticsType type = ds.findType("ClientStats");
            return ds.findStatisticsByType(type);
        }

        private int getClientConnections(Statistics statistics) {
            return statistics.getInt("connections");
        }
    });
thread.setDaemon(true);
thread.start();

}

Barry Oglesby 0 votes