use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeave method processLeaveRequest.
/**
* Process a Leave request from another member. This may cause this member to become the new
* membership coordinator. If this is the coordinator a new view will be triggered.
*
* @param incomingRequest the request to be processed
*/
private void processLeaveRequest(LeaveRequestMessage incomingRequest) {
logger.info("received leave request from {} for {}", incomingRequest.getSender(), incomingRequest.getMemberID());
NetView v = currentView;
if (v == null) {
recordViewRequest(incomingRequest);
return;
}
InternalDistributedMember mbr = incomingRequest.getMemberID();
if (logger.isDebugEnabled()) {
logger.debug("JoinLeave.processLeaveRequest invoked. isCoordinator=" + isCoordinator + "; isStopping=" + isStopping + "; cancelInProgress=" + services.getCancelCriterion().isCancelInProgress());
}
if (!v.contains(mbr) && mbr.getVmViewId() < v.getViewId()) {
logger.debug("ignoring leave request from old member");
return;
}
if (incomingRequest.getMemberID().equals(this.localAddress)) {
logger.info("I am being told to leave the distributed system by {}", incomingRequest.getSender());
forceDisconnect(incomingRequest.getReason());
return;
}
if (!isCoordinator && !isStopping && !services.getCancelCriterion().isCancelInProgress()) {
logger.debug("Checking to see if I should become coordinator");
NetView check = new NetView(v, v.getViewId() + 1);
check.remove(incomingRequest.getMemberID());
synchronized (removedMembers) {
check.removeAll(removedMembers);
check.addCrashedMembers(removedMembers);
}
synchronized (leftMembers) {
leftMembers.add(mbr);
check.removeAll(leftMembers);
}
if (check.getCoordinator().equals(localAddress)) {
synchronized (viewInstallationLock) {
becomeCoordinator(incomingRequest.getMemberID());
}
}
} else {
if (!isStopping && !services.getCancelCriterion().isCancelInProgress()) {
recordViewRequest(incomingRequest);
this.viewProcessor.processLeaveRequest(incomingRequest.getMemberID());
this.prepareProcessor.processLeaveRequest(incomingRequest.getMemberID());
}
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeave method processViewMessage.
private void processViewMessage(final InstallViewMessage m) {
NetView view = m.getView();
// If our current view doesn't contaion sender then we wanrt to ignore that view.
if (currentView != null && !currentView.contains(m.getSender())) {
// this may happen when we locator re-join and it take over coordinator's responsibility.
if (this.preparedView == null || !this.preparedView.contains(m.getSender())) {
logger.info("Ignoring the view {} from member {}, which is not in my current view {} ", view, m.getSender(), currentView);
return;
}
}
if (currentView != null && view.getViewId() < currentView.getViewId()) {
// ignore old views
ackView(m);
return;
}
boolean viewContainsMyUnjoinedAddress = false;
if (!this.isJoined) {
// should install the view so join() can finish its work
for (InternalDistributedMember mbr : view.getMembers()) {
if (localAddress.compareTo(mbr) == 0) {
viewContainsMyUnjoinedAddress = true;
break;
}
}
}
if (m.isPreparing()) {
if (this.preparedView != null && this.preparedView.getViewId() >= view.getViewId()) {
services.getMessenger().send(new ViewAckMessage(m.getSender(), this.preparedView));
} else {
this.preparedView = view;
if (viewContainsMyUnjoinedAddress) {
// this will notifyAll the joinResponse
installView(view);
}
ackView(m);
}
} else {
// !preparing
if (isJoined && currentView != null && !view.contains(this.localAddress)) {
logger.fatal("This member is no longer in the membership view. My ID is {} and the new view is {}", localAddress, view);
forceDisconnect("This node is no longer in the membership view");
} else {
if (isJoined || viewContainsMyUnjoinedAddress) {
installView(view);
}
if (!m.isRebroadcast()) {
// no need to ack a rebroadcast view
ackView(m);
}
}
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeave method findCoordinator.
/**
* This contacts the locators to find out who the current coordinator is. All locators are
* contacted. If they don't agree then we choose the oldest coordinator and return it.
*/
private boolean findCoordinator() {
SearchState state = searchState;
assert this.localAddress != null;
// the coordinator
if (!state.hasContactedAJoinedLocator && state.view != null) {
return findCoordinatorFromView();
}
String dhalgo = services.getConfig().getDistributionConfig().getSecurityUDPDHAlgo();
FindCoordinatorRequest request = new FindCoordinatorRequest(this.localAddress, state.alreadyTried, state.viewId, services.getMessenger().getPublicKey(localAddress), services.getMessenger().getRequestId(), dhalgo);
Set<InternalDistributedMember> possibleCoordinators = new HashSet<InternalDistributedMember>();
Set<InternalDistributedMember> coordinatorsWithView = new HashSet<InternalDistributedMember>();
long giveUpTime = System.currentTimeMillis() + ((long) services.getConfig().getLocatorWaitTime() * 1000L);
int connectTimeout = (int) services.getConfig().getMemberTimeout() * 2;
boolean anyResponses = false;
logger.debug("sending {} to {}", request, locators);
state.hasContactedAJoinedLocator = false;
state.locatorsContacted = 0;
do {
for (InetSocketAddress addr : locators) {
try {
Object o = tcpClientWrapper.sendCoordinatorFindRequest(addr, request, connectTimeout);
FindCoordinatorResponse response = (o instanceof FindCoordinatorResponse) ? (FindCoordinatorResponse) o : null;
if (response != null) {
if (response.getRejectionMessage() != null) {
throw new GemFireConfigException(response.getRejectionMessage());
}
setCoordinatorPublicKey(response);
state.locatorsContacted++;
if (!state.hasContactedAJoinedLocator && response.getSenderId() != null && response.getSenderId().getVmViewId() >= 0) {
logger.debug("Locator's address indicates it is part of a distributed system " + "so I will not become membership coordinator on this attempt to join");
state.hasContactedAJoinedLocator = true;
}
if (response.getCoordinator() != null) {
anyResponses = true;
NetView v = response.getView();
int viewId = v == null ? -1 : v.getViewId();
if (viewId > state.viewId) {
state.viewId = viewId;
state.view = v;
state.registrants.clear();
if (response.getRegistrants() != null) {
state.registrants.addAll(response.getRegistrants());
}
}
if (viewId > -1) {
coordinatorsWithView.add(response.getCoordinator());
}
possibleCoordinators.add(response.getCoordinator());
}
}
} catch (IOException | ClassNotFoundException problem) {
}
}
} while (!anyResponses && System.currentTimeMillis() < giveUpTime);
if (possibleCoordinators.isEmpty()) {
return false;
}
if (coordinatorsWithView.size() > 0) {
// lets check current coordinators in view only
possibleCoordinators = coordinatorsWithView;
}
Iterator<InternalDistributedMember> it = possibleCoordinators.iterator();
if (possibleCoordinators.size() == 1) {
state.possibleCoordinator = it.next();
} else {
InternalDistributedMember oldest = it.next();
while (it.hasNext()) {
InternalDistributedMember candidate = it.next();
if (oldest.compareTo(candidate) > 0) {
oldest = candidate;
}
}
state.possibleCoordinator = oldest;
}
InternalDistributedMember coord = null;
boolean coordIsNoob = true;
for (; it.hasNext(); ) {
InternalDistributedMember mbr = it.next();
if (!state.alreadyTried.contains(mbr)) {
boolean mbrIsNoob = (mbr.getVmViewId() < 0);
if (mbrIsNoob) {
// member has not yet joined
if (coordIsNoob && (coord == null || coord.compareTo(mbr) > 0)) {
coord = mbr;
}
} else {
// member has already joined
if (coordIsNoob || mbr.getVmViewId() > coord.getVmViewId()) {
coord = mbr;
coordIsNoob = false;
}
}
}
}
return true;
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSJoinLeave method remove.
@Override
public void remove(InternalDistributedMember m, String reason) {
NetView v = this.currentView;
services.getCancelCriterion().checkCancelInProgress(null);
if (v != null && v.contains(m)) {
Set<InternalDistributedMember> filter = new HashSet<>();
filter.add(m);
RemoveMemberMessage msg = new RemoveMemberMessage(v.getPreferredCoordinators(filter, getMemberID(), 5), m, reason);
msg.setSender(this.localAddress);
processRemoveRequest(msg);
if (!this.isCoordinator) {
msg.resetRecipients();
msg.setRecipients(v.getPreferredCoordinators(Collections.emptySet(), localAddress, 10));
services.getMessenger().send(msg);
}
} else {
RemoveMemberMessage msg = new RemoveMemberMessage(m, m, reason);
services.getMessenger().send(msg);
}
}
use of org.apache.geode.distributed.internal.membership.NetView in project geode by apache.
the class GMSMembershipManager method join.
/**
* Joins the distributed system
*
* @throws GemFireConfigException - configuration error
* @throws SystemConnectException - problem joining
*/
private void join() {
services.setShutdownCause(null);
services.getCancelCriterion().cancel(null);
latestViewWriteLock.lock();
try {
try {
// added for bug #44373
this.isJoining = true;
// connect
long start = System.currentTimeMillis();
boolean ok = services.getJoinLeave().join();
if (!ok) {
throw new GemFireConfigException("Unable to join the distributed system. " + "Operation either timed out, was stopped or Locator does not exist.");
}
long delta = System.currentTimeMillis() - start;
logger.info(LogMarker.DISTRIBUTION, LocalizedMessage.create(LocalizedStrings.GroupMembershipService_JOINED_TOOK__0__MS, delta));
NetView initialView = services.getJoinLeave().getView();
latestView = new NetView(initialView, initialView.getViewId());
listener.viewInstalled(latestView);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
if (ex.getCause() != null && ex.getCause().getCause() instanceof SystemConnectException) {
throw (SystemConnectException) (ex.getCause().getCause());
}
throw new DistributionException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_JOINING.toLocalizedString(), ex);
} finally {
this.isJoining = false;
}
} finally {
latestViewWriteLock.unlock();
}
}
Aggregations