Search in sources :

Example 1 with HeartbeatMessage

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

the class GMSHealthMonitorJUnitTest method testBeSickAndPlayDead.

@Test
public void testBeSickAndPlayDead() throws Exception {
    NetView v = new NetView(mockMembers.get(0), 2, mockMembers);
    gmsHealthMonitor.installView(v);
    gmsHealthMonitor.beSick();
    // a sick member will not respond to a heartbeat request
    HeartbeatRequestMessage req = new HeartbeatRequestMessage(mockMembers.get(0), 10);
    req.setSender(mockMembers.get(0));
    gmsHealthMonitor.processMessage(req);
    verify(messenger, never()).send(isA(HeartbeatMessage.class));
    // a sick member will not record a heartbeat from another member
    HeartbeatMessage hb = new HeartbeatMessage(-1);
    hb.setSender(mockMembers.get(0));
    gmsHealthMonitor.processMessage(hb);
    assertTrue(gmsHealthMonitor.memberTimeStamps.get(hb.getSender()) == null);
    // a sick member will not take action on a Suspect message from another member
    SuspectMembersMessage smm = mock(SuspectMembersMessage.class);
    Error err = new AssertionError("expected suspect message to be ignored");
    when(smm.getMembers()).thenThrow(err);
    when(smm.getSender()).thenThrow(err);
    when(smm.getDSFID()).thenCallRealMethod();
    gmsHealthMonitor.processMessage(smm);
}
Also used : HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) NetView(org.apache.geode.distributed.internal.membership.NetView) HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage) SuspectMembersMessage(org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage) 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 2 with HeartbeatMessage

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

the class GMSHealthMonitor method processHeartbeatRequest.

private void processHeartbeatRequest(HeartbeatRequestMessage m) {
    this.stats.incHeartbeatRequestsReceived();
    if (this.isStopping || this.playingDead) {
        return;
    }
    // only respond if the intended recipient is this member
    InternalDistributedMember me = localAddress;
    if (me.getVmViewId() >= 0 && m.getTarget().equals(me)) {
        HeartbeatMessage hm = new HeartbeatMessage(m.getRequestId());
        hm.setRecipient(m.getSender());
        Set<InternalDistributedMember> membersNotReceivedMsg = services.getMessenger().send(hm);
        this.stats.incHeartbeatsSent();
        if (membersNotReceivedMsg != null && membersNotReceivedMsg.contains(m.getSender())) {
            logger.debug("Unable to send heartbeat to member: {}", m.getSender());
        }
    } else {
        logger.debug("Ignoring heartbeat request intended for {}.  My ID is {}", m.getTarget(), me);
    }
}
Also used : HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Example 3 with HeartbeatMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage 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 4 with HeartbeatMessage

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

the class GMSHealthMonitorJUnitTest method testCheckIfAvailableWithSimulatedHeartBeat.

@Test
public void testCheckIfAvailableWithSimulatedHeartBeat() {
    NetView v = installAView();
    InternalDistributedMember memberToCheck = mockMembers.get(1);
    HeartbeatMessage fakeHeartbeat = new HeartbeatMessage();
    fakeHeartbeat.setSender(memberToCheck);
    when(messenger.send(any(HeartbeatRequestMessage.class))).then(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            gmsHealthMonitor.processMessage(fakeHeartbeat);
            return null;
        }
    });
    boolean retVal = gmsHealthMonitor.checkIfAvailable(memberToCheck, "Not responding", true);
    assertTrue("CheckIfAvailable should have return true", retVal);
}
Also used : Answer(org.mockito.stubbing.Answer) HeartbeatMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetView(org.apache.geode.distributed.internal.membership.NetView) HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage) 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)

Aggregations

HeartbeatMessage (org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 NetView (org.apache.geode.distributed.internal.membership.NetView)3 HeartbeatRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage)2 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 CancelException (org.apache.geode.CancelException)1 SuspectMembersMessage (org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage)1 SuspectRequest (org.apache.geode.distributed.internal.membership.gms.messages.SuspectRequest)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1