use of org.apache.geode.distributed.internal.membership.NetView 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);
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class DistributionManager method getViewMembers.
public List<InternalDistributedMember> getViewMembers() {
NetView result = null;
DistributionChannel ch = this.channel;
if (ch != null) {
MembershipManager mgr = ch.getMembershipManager();
if (mgr != null) {
result = mgr.getView();
}
}
if (result == null) {
result = new NetView();
}
return result.getMembers();
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class DistributionManager method startThreads.
/**
* Need to do this outside the constructor so that the child constructor can finish.
*/
protected void startThreads() {
// fix for bug 33362
this.system.setDM(this);
if (this.memberEventThread != null)
this.memberEventThread.start();
try {
// And the distinguished guests today are...
NetView v = membershipManager.getView();
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_INITIAL_MEMBERSHIPMANAGER_VIEW___0, printView(v)));
// Add them all to our view
Iterator<InternalDistributedMember> it = v.getMembers().iterator();
while (it.hasNext()) {
addNewMember(it.next());
}
// Figure out who the elder is...
// ShutdownException could be thrown here
selectElder();
} catch (Exception ex) {
throw new InternalGemFireException(LocalizedStrings.DistributionManager_COULD_NOT_PROCESS_INITIAL_VIEW.toLocalizedString(), ex);
}
try {
getWaitingThreadPool().execute(new Runnable() {
public void run() {
// call in background since it might need to send a reply
// and we are not ready to send messages until startup is finished
isStartupThread.set(Boolean.TRUE);
readyForMessages();
}
});
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionManager_UNCAUGHT_EXCEPTION_CALLING_READYFORMESSAGES), t);
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class DistributionManager method waitForElder.
/**
* Waits until elder if newElder or newElder is no longer a member
*
* @return true if newElder is the elder; false if he is no longer a member or we are the elder.
*/
public boolean waitForElder(final InternalDistributedMember desiredElder) {
MembershipListener l = null;
try {
// desiredElder.getVmKind() != DistributionManager.ADMIN_ONLY_DM_TYPE);
synchronized (this.elderMonitor) {
while (true) {
if (closeInProgress)
return false;
InternalDistributedMember currentElder = this.elder;
// currentElder.getVmKind() != DistributionManager.ADMIN_ONLY_DM_TYPE);
if (desiredElder.equals(currentElder)) {
return true;
}
if (!isCurrentMember(desiredElder)) {
// no longer present
return false;
}
if (this.myid.equals(currentElder)) {
// elder so don't let them wait anymore.
return false;
}
if (l == null) {
l = new MembershipListener() {
public void memberJoined(InternalDistributedMember theId) {
// nothing needed
}
public void memberDeparted(InternalDistributedMember theId, boolean crashed) {
if (desiredElder.equals(theId)) {
notifyElderChangeWaiters();
}
}
public void memberSuspect(InternalDistributedMember id, InternalDistributedMember whoSuspected, String reason) {
}
public void viewInstalled(NetView view) {
}
public void quorumLost(Set<InternalDistributedMember> failures, List<InternalDistributedMember> remaining) {
}
};
addMembershipListener(l);
}
logger.info(LocalizedMessage.create(LocalizedStrings.DistributionManager_CHANGING_ELDER_FROM_0_TO_1, new Object[] { currentElder, desiredElder }));
elderChangeWait();
}
// while true
}
} finally {
if (l != null) {
removeMembershipListener(l);
}
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSMembershipManager method addSurpriseMember.
/**
* Logic for handling a direct connection event (message received from a member not in the view).
* Does not employ the startup queue.
* <p>
* Must be called with {@link #latestViewLock} held. Waits until there is a stable view. If the
* member has already been added, simply returns; else adds the member.
*
* @param dm the member joining
*/
public boolean addSurpriseMember(DistributedMember dm) {
final InternalDistributedMember member = (InternalDistributedMember) dm;
boolean warn = false;
latestViewWriteLock.lock();
try {
// other means.
if (latestView.contains(member)) {
return true;
}
if (surpriseMembers.containsKey(member)) {
return true;
}
if (member.getVmViewId() < 0) {
logger.warn("adding a surprise member that has not yet joined the distributed system: " + member, new Exception("stack trace"));
}
if (latestView.getViewId() > member.getVmViewId()) {
// tell the process that it should shut down distribution.
// Run in a separate thread so we don't hold the view lock during the request. Bug #44995
new Thread(Thread.currentThread().getThreadGroup(), "Removing shunned GemFire node " + member) {
@Override
public void run() {
// fix for bug #42548
// this is an old member that shouldn't be added
logger.warn(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_Invalid_Surprise_Member, new Object[] { member, latestView }));
requestMemberRemoval(member, "this member is no longer in the view but is initiating connections");
}
}.start();
addShunnedMember(member);
return false;
}
// Adding him to this set ensures we won't remove him if a new
// view comes in and he's still not visible.
surpriseMembers.put(member, Long.valueOf(System.currentTimeMillis()));
if (shutdownInProgress()) {
// Force disconnect, esp. the TCPConduit
String msg = LocalizedStrings.GroupMembershipService_THIS_DISTRIBUTED_SYSTEM_IS_SHUTTING_DOWN.toLocalizedString();
if (directChannel != null) {
try {
directChannel.closeEndpoint(member, msg);
} catch (DistributedSystemDisconnectedException e) {
// ignore - happens during shutdown
}
}
// for good luck
destroyMember(member, msg);
// allow during shutdown
return true;
}
if (isShunned(member)) {
warn = true;
surpriseMembers.remove(member);
} else {
// Ensure that the member is accounted for in the view
// Conjure up a new view including the new member. This is necessary
// because we are about to tell the listener about a new member, so
// the listener should rightfully expect that the member is in our
// membership view.
// However, we put the new member at the end of the list. This
// should ensure he's not chosen as an elder.
// This will get corrected when he finally shows up in the
// view.
NetView newMembers = new NetView(latestView, latestView.getViewId());
newMembers.add(member);
latestView = newMembers;
}
} finally {
latestViewWriteLock.unlock();
}
if (warn) {
// fix for bug #41538 - deadlock while alerting
logger.warn(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_IGNORING_SURPRISE_CONNECT_FROM_SHUNNED_MEMBER_0, member));
} else {
listener.newMemberConnected(member);
}
return !warn;
}
Aggregations