Search in sources :

Example 1 with HeartbeatRequestMessage

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

the class GMSHealthMonitor method constructHeartbeatRequestMessage.

private HeartbeatRequestMessage constructHeartbeatRequestMessage(final InternalDistributedMember mbr) {
    final int reqId = requestId.getAndIncrement();
    final HeartbeatRequestMessage hrm = new HeartbeatRequestMessage(mbr, reqId);
    hrm.setRecipient(mbr);
    return hrm;
}
Also used : HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage)

Example 2 with HeartbeatRequestMessage

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

the class GMSHealthMonitorJUnitTest method testHMServiceStarted.

@Test
public void testHMServiceStarted() throws IOException {
    InternalDistributedMember mbr = new InternalDistributedMember(SocketCreator.getLocalHost(), 12345);
    mbr.setVmViewId(1);
    when(messenger.getMemberID()).thenReturn(mbr);
    gmsHealthMonitor.started();
    NetView v = new NetView(mbr, 1, mockMembers);
    gmsHealthMonitor.processMessage(new HeartbeatRequestMessage(mbr, 1));
    verify(messenger, atLeastOnce()).send(any(HeartbeatMessage.class));
    Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatRequestsReceived());
    Assert.assertEquals(1, gmsHealthMonitor.getStats().getHeartbeatsSent());
}
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) 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)

Example 3 with HeartbeatRequestMessage

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

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

the class GMSHealthMonitor method doCheckMember.

/**
   * This method sends heartbeat request to other member and waits for member-timeout time for
   * response. If it doesn't see response then it returns false.
   */
private boolean doCheckMember(InternalDistributedMember member, boolean waitForResponse) {
    if (playingDead || beingSick) {
        // messages by returning true.
        return true;
    }
    long startTime = System.currentTimeMillis();
    logger.trace("Checking member {}", member);
    final HeartbeatRequestMessage hrm = constructHeartbeatRequestMessage(member);
    Response pingResp = null;
    if (waitForResponse) {
        pingResp = new Response();
        requestIdVsResponse.put(hrm.getRequestId(), pingResp);
    } else {
        hrm.clearRequestId();
    }
    try {
        Set<InternalDistributedMember> membersNotReceivedMsg = this.services.getMessenger().send(hrm);
        this.stats.incHeartbeatRequestsSent();
        if (membersNotReceivedMsg != null && membersNotReceivedMsg.contains(member)) {
            // member is not part of current view.
            logger.trace("Member {} is not part of current view.", member);
        } else if (waitForResponse) {
            synchronized (pingResp) {
                if (pingResp.getResponseMsg() == null) {
                    pingResp.wait(memberTimeout);
                }
                TimeStamp ts = memberTimeStamps.get(member);
                if (ts != null && ts.getTime() > startTime) {
                    return true;
                }
                if (pingResp.getResponseMsg() == null) {
                    if (isStopping) {
                        return true;
                    }
                    logger.trace("no heartbeat response received from {} and no recent activity", member);
                    return false;
                } else {
                    logger.trace("received heartbeat from {}", member);
                    this.stats.incHeartbeatsReceived();
                    if (ts != null) {
                        ts.setTime(System.currentTimeMillis());
                    }
                    return true;
                }
            }
        }
    } catch (InterruptedException e) {
        logger.debug("GMSHealthMonitor checking thread interrupted, while waiting for response from member: {} .", member);
    } finally {
        if (waitForResponse) {
            requestIdVsResponse.remove(hrm.getRequestId());
        }
    }
    return false;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HeartbeatRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage)

Aggregations

HeartbeatRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatRequestMessage)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 NetView (org.apache.geode.distributed.internal.membership.NetView)2 HeartbeatMessage (org.apache.geode.distributed.internal.membership.gms.messages.HeartbeatMessage)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 SuspectMembersMessage (org.apache.geode.distributed.internal.membership.gms.messages.SuspectMembersMessage)1