Search in sources :

Example 1 with SuspectRequest

use of org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest in project geode by apache.

the class GMSHealthMonitor method recordSuspectRequests.

/***
   * This method make sure that records suspectRequest. We need to make sure this on preferred
   * coordinators, as elder coordinator might be in suspected list next.
   */
private void recordSuspectRequests(List<SuspectRequest> sMembers, NetView cv) {
    // record suspect requests
    Set<SuspectRequest> viewVsMembers;
    synchronized (viewVsSuspectedMembers) {
        viewVsMembers = viewVsSuspectedMembers.get(cv);
        if (viewVsMembers == null) {
            viewVsMembers = new HashSet<>();
            viewVsSuspectedMembers.put(cv, viewVsMembers);
        }
        for (SuspectRequest sr : sMembers) {
            viewVsMembers.add(sr);
        }
    }
}
Also used : SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest)

Example 2 with SuspectRequest

use of org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest in project geode by apache.

the class GMSHealthMonitor method initiateSuspicion.

private void initiateSuspicion(InternalDistributedMember mbr, String reason) {
    if (services.getJoinLeave().isMemberLeaving(mbr)) {
        return;
    }
    SuspectRequest sr = new SuspectRequest(mbr, reason);
    List<SuspectRequest> sl = new ArrayList<>();
    sl.add(sr);
    sendSuspectRequest(sl);
}
Also used : ArrayList(java.util.ArrayList) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest)

Example 3 with SuspectRequest

use of org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest in project geode by apache.

the class GMSHealthMonitorJUnitTest method testRemoveMemberCalledAfterDoingFinalCheckOnCoordinator.

/***
   * Send remove member message after doing final check for coordinator, ping timeout This test
   * trying to remove coordinator
   */
@Test
public void testRemoveMemberCalledAfterDoingFinalCheckOnCoordinator() throws Exception {
    NetView v = new NetView(mockMembers.get(0), 2, mockMembers);
    // preferred coordinators are 0 and 1
    // next preferred coordinator
    when(messenger.getMemberID()).thenReturn(mockMembers.get(1));
    gmsHealthMonitor.started();
    gmsHealthMonitor.installView(v);
    Thread.sleep(memberTimeout / GMSHealthMonitor.LOGICAL_INTERVAL);
    ArrayList<InternalDistributedMember> recipient = new ArrayList<InternalDistributedMember>();
    recipient.add(mockMembers.get(0));
    recipient.add(mockMembers.get(1));
    ArrayList<SuspectRequest> as = new ArrayList<SuspectRequest>();
    // removing
    SuspectRequest sr = new SuspectRequest(mockMembers.get(0), "Not Responding");
    // coordinator
    as.add(sr);
    SuspectMembersMessage sm = new SuspectMembersMessage(recipient, as);
    // member 4 sends suspect message
    sm.setSender(mockMembers.get(myAddressIndex + 1));
    gmsHealthMonitor.processMessage(sm);
    // this happens after final check, ping timeout = 1000 ms
    Thread.sleep(memberTimeout + 200);
    verify(joinLeave, atLeastOnce()).remove(any(InternalDistributedMember.class), any(String.class));
    Assert.assertTrue(gmsHealthMonitor.getStats().getSuspectsReceived() > 0);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) SuspectMembersMessage(org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with SuspectRequest

use of org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest in project geode by apache.

the class GMSHealthMonitor method processSuspectMembersRequest.

/**
   * Process a Suspect request from another member. This may cause this member to become the new
   * membership coordinator. it will to final check on that member and then it will send remove
   * request for that member
   */
private void processSuspectMembersRequest(SuspectMembersMessage incomingRequest) {
    this.stats.incSuspectsReceived();
    NetView cv = currentView;
    if (cv == null) {
        return;
    }
    List<SuspectRequest> sMembers = incomingRequest.getMembers();
    InternalDistributedMember sender = incomingRequest.getSender();
    int viewId = sender.getVmViewId();
    if (cv.getViewId() >= viewId && !cv.contains(incomingRequest.getSender())) {
        logger.info("Membership ignoring suspect request for " + incomingRequest + " from non-member " + incomingRequest.getSender());
        services.getJoinLeave().remove(sender, "this process is initiating suspect processing but is no longer a member");
        return;
    }
    // take care of any suspicion of this member by sending a heartbeat back
    if (!playingDead) {
        for (Iterator<SuspectRequest> it = incomingRequest.getMembers().iterator(); it.hasNext(); ) {
            SuspectRequest req = it.next();
            if (req.getSuspectMember().equals(localAddress)) {
                HeartbeatMessage message = new HeartbeatMessage(-1);
                message.setRecipient(sender);
                try {
                    services.getMessenger().send(message);
                    this.stats.incHeartbeatsSent();
                    it.remove();
                } catch (CancelException e) {
                    return;
                }
            }
        }
    }
    if (cv.getCoordinator().equals(localAddress)) {
        for (SuspectRequest req : incomingRequest.getMembers()) {
            logger.info("received suspect message from {} for {}: {}", sender, req.getSuspectMember(), req.getReason());
        }
        checkIfAvailable(sender, sMembers, cv);
    } else // coordinator ends
    {
        NetView check = new NetView(cv, cv.getViewId() + 1);
        ArrayList<SuspectRequest> smbr = new ArrayList<>();
        synchronized (viewVsSuspectedMembers) {
            recordSuspectRequests(sMembers, cv);
            Set<SuspectRequest> viewVsMembers = viewVsSuspectedMembers.get(cv);
            for (final SuspectRequest sr : viewVsMembers) {
                check.remove(sr.getSuspectMember());
                smbr.add(sr);
            }
        }
        InternalDistributedMember coordinator = check.getCoordinator();
        if (coordinator != null && coordinator.equals(localAddress)) {
            // new coordinator
            for (SuspectRequest req : incomingRequest.getMembers()) {
                logger.info("received suspect message from {} for {}: {}", sender, req.getSuspectMember(), req.getReason());
            }
            checkIfAvailable(sender, smbr, cv);
        } else {
            recordSuspectRequests(sMembers, cv);
        }
    }
}
Also used : HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) CancelException(org.apache.geode.CancelException) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest)

Example 5 with SuspectRequest

use of org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest in project geode by apache.

the class GMSHealthMonitor method start.

public void start() {
    scheduler = Executors.newScheduledThreadPool(1, r -> {
        Thread th = new Thread(Services.getThreadGroup(), r, "Geode Failure Detection Scheduler");
        th.setDaemon(true);
        return th;
    });
    checkExecutor = Executors.newCachedThreadPool(new ThreadFactory() {

        final AtomicInteger threadIdx = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            int id = threadIdx.getAndIncrement();
            Thread th = new Thread(Services.getThreadGroup(), r, "Geode Failure Detection thread " + id);
            th.setDaemon(true);
            return th;
        }
    });
    Monitor m = this.new Monitor(memberTimeout);
    long delay = memberTimeout / LOGICAL_INTERVAL;
    monitorFuture = scheduler.scheduleAtFixedRate(m, delay, delay, TimeUnit.MILLISECONDS);
    // suspectRequestCollectorThread = this.new RequestCollector<SuspectRequest>("Geode Suspect
    // Message Collector", Services.getThreadGroup(), suspectRequests,
    // new Callback<SuspectRequest>() {
    // @Override
    // public void process(List<SuspectRequest> requests) {
    // GMSHealthMonitor.this.sendSuspectRequest(requests);
    //
    // }
    // }, MEMBER_SUSPECT_COLLECTION_INTERVAL);
    // suspectRequestCollectorThread.setDaemon(true);
    // suspectRequestCollectorThread.start()
    serverSocketExecutor = Executors.newCachedThreadPool(new ThreadFactory() {

        final AtomicInteger threadIdx = new AtomicInteger();

        @Override
        public Thread newThread(Runnable r) {
            int id = threadIdx.getAndIncrement();
            Thread th = new Thread(Services.getThreadGroup(), r, "Geode Failure Detection Server thread " + id);
            th.setDaemon(true);
            return th;
        }
    });
}
Also used : Arrays(java.util.Arrays) ScheduledFuture(java.util.concurrent.ScheduledFuture) Enumeration(java.util.Enumeration) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Timer(java.util.Timer) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) DataOutputStream(java.io.DataOutputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) DistributedMember(org.apache.geode.distributed.DistributedMember) CancelException(org.apache.geode.CancelException) TimerTask(java.util.TimerTask) ThreadFactory(java.util.concurrent.ThreadFactory) UUID(org.jgroups.util.UUID) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Version(org.apache.geode.internal.Version) Set(java.util.Set) SecurableCommunicationChannel(org.apache.geode.internal.security.SecurableCommunicationChannel) Collectors(java.util.stream.Collectors) NetView(org.apache.geode.distributed.internal.membership.NetView) Executors(java.util.concurrent.Executors) Services(org.apache.geode.distributed.internal.membership.gms.Services) SuspectRequest(org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DataInputStream(java.io.DataInputStream) HealthMonitor(org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor) Socket(java.net.Socket) SocketCreatorFactory(org.apache.geode.internal.net.SocketCreatorFactory) HashMap(java.util.HashMap) ConnectionWatcher(org.apache.geode.internal.ConnectionWatcher) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) HEARTBEAT_RESPONSE(org.apache.geode.internal.DataSerializableFixedID.HEARTBEAT_RESPONSE) SUSPECT_MEMBERS_MESSAGE(org.apache.geode.internal.DataSerializableFixedID.SUSPECT_MEMBERS_MESSAGE) HashSet(java.util.HashSet) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) SystemConnectException(org.apache.geode.SystemConnectException) SocketTimeoutException(java.net.SocketTimeoutException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) GemFireConfigException(org.apache.geode.GemFireConfigException) ExecutorService(java.util.concurrent.ExecutorService) OutputStream(java.io.OutputStream) HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage) Iterator(java.util.Iterator) DMStats(org.apache.geode.distributed.internal.DMStats) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) HEARTBEAT_REQUEST(org.apache.geode.internal.DataSerializableFixedID.HEARTBEAT_REQUEST) SuspectMembersMessage(org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage) Collections(java.util.Collections) InputStream(java.io.InputStream) ThreadFactory(java.util.concurrent.ThreadFactory) HealthMonitor(org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

SuspectRequest (org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest)9 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)7 ArrayList (java.util.ArrayList)6 NetView (org.apache.geode.distributed.internal.membership.NetView)5 SuspectMembersMessage (org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage)5 CancelException (org.apache.geode.CancelException)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 HashSet (java.util.HashSet)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 GemFireConfigException (org.apache.geode.GemFireConfigException)2 SystemConnectException (org.apache.geode.SystemConnectException)2 HeartbeatMessage (org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1