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);
}
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);
}
}
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);
}
}
}
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);
}
Aggregations