use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSJoinLeave method installView.
public void installView(NetView newView) {
synchronized (viewInstallationLock) {
if (currentView != null && currentView.getViewId() >= newView.getViewId()) {
// old view - ignore it
return;
}
logger.info("received new view: {}\nold view is: {}", newView, currentView);
if (currentView == null && !this.isJoined) {
boolean found = false;
for (InternalDistributedMember mbr : newView.getMembers()) {
if (this.localAddress.equals(mbr)) {
found = true;
this.birthViewId = mbr.getVmViewId();
this.localAddress.setVmViewId(this.birthViewId);
GMSMember me = (GMSMember) this.localAddress.getNetMember();
me.setBirthViewId(birthViewId);
break;
}
}
if (!found) {
logger.info("rejecting view (not yet joined)");
return;
}
}
if (isJoined && isNetworkPartition(newView, true)) {
if (quorumRequired) {
Set<InternalDistributedMember> crashes = newView.getActualCrashedMembers(currentView);
forceDisconnect(LocalizedStrings.Network_partition_detected.toLocalizedString(crashes.size(), crashes));
return;
}
}
previousView = currentView;
currentView = newView;
preparedView = null;
lastConflictingView = null;
services.installView(newView);
if (!isJoined) {
logger.debug("notifying join thread");
isJoined = true;
synchronized (joinResponse) {
joinResponse.notifyAll();
}
}
if (!newView.getCreator().equals(this.localAddress)) {
if (newView.shouldBeCoordinator(this.localAddress)) {
becomeCoordinator();
} else if (this.isCoordinator) {
// stop being coordinator
stopCoordinatorServices();
this.isCoordinator = false;
}
}
if (!this.isCoordinator) {
// resend these
synchronized (viewRequests) {
for (Iterator<DistributionMessage> it = viewRequests.iterator(); it.hasNext(); ) {
DistributionMessage m = it.next();
if (m instanceof JoinRequestMessage) {
if (currentView.contains(((JoinRequestMessage) m).getMemberID())) {
it.remove();
}
} else if (m instanceof LeaveRequestMessage) {
if (!currentView.contains(((LeaveRequestMessage) m).getMemberID())) {
it.remove();
}
} else if (m instanceof RemoveMemberMessage) {
if (!currentView.contains(((RemoveMemberMessage) m).getMemberID())) {
it.remove();
}
}
}
}
}
}
synchronized (removedMembers) {
removeMembersFromCollectionIfNotInView(removedMembers, currentView);
}
synchronized (leftMembers) {
removeMembersFromCollectionIfNotInView(leftMembers, currentView);
}
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSJoinLeave method started.
@Override
public void started() {
this.localAddress = services.getMessenger().getMemberID();
GMSMember mbr = (GMSMember) this.localAddress.getNetMember();
if (services.getConfig().areLocatorsPreferredAsCoordinators()) {
boolean preferred = false;
if (services.getLocator() != null || Locator.hasLocator() || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty() || localAddress.getVmKind() == DistributionManager.LOCATOR_DM_TYPE) {
logger.info("This member is hosting a locator will be preferred as a membership coordinator");
preferred = true;
}
mbr.setPreferredForCoordinator(preferred);
} else {
mbr.setPreferredForCoordinator(true);
}
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class JGroupsMessenger method handleJGroupsIOException.
/**
* If JGroups is unable to send a message it may mean that the network is down. If so we need to
* initiate suspect processing on the recipient.
* <p>
* see Transport._send()
*/
@SuppressWarnings("UnusedParameters")
public void handleJGroupsIOException(IOException e, Address dest) {
if (services.getManager().shutdownInProgress()) {
// shutdown
return;
}
if (addressesWithIoExceptionsProcessed.contains(dest)) {
return;
}
addressesWithIoExceptionsProcessed.add(dest);
NetView v = this.view;
JGAddress jgMbr = (JGAddress) dest;
if (jgMbr != null && v != null) {
List<InternalDistributedMember> members = v.getMembers();
InternalDistributedMember recipient = null;
for (InternalDistributedMember mbr : members) {
GMSMember gmsMbr = ((GMSMember) mbr.getNetMember());
if (jgMbr.getUUIDLsbs() == gmsMbr.getUuidLSBs() && jgMbr.getUUIDMsbs() == gmsMbr.getUuidMSBs() && jgMbr.getVmViewId() == gmsMbr.getVmViewId()) {
recipient = mbr;
break;
}
}
if (recipient != null) {
services.getHealthMonitor().suspect(recipient, "Unable to send messages to this member via JGroups");
}
}
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class ClientCacheFactoryJUnitTest method testOldClientIDDeserialization.
@Test
public void testOldClientIDDeserialization() throws Exception {
// during a HandShake a clientID is read w/o knowing the client's
// version
cc = new ClientCacheFactory().create();
GemFireCacheImpl gfc = (GemFireCacheImpl) cc;
InternalDistributedMember memberID = (InternalDistributedMember) cc.getDistributedSystem().getDistributedMember();
GMSMember gmsID = (GMSMember) memberID.getNetMember();
memberID.setVersionObjectForTest(Version.GFE_82);
assertEquals(Version.GFE_82, memberID.getVersionObject());
ClientProxyMembershipID clientID = ClientProxyMembershipID.getClientId(memberID);
HeapDataOutputStream out = new HeapDataOutputStream(Version.GFE_82);
DataSerializer.writeObject(clientID, out);
DataInputStream in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
ClientProxyMembershipID newID = DataSerializer.readObject(in);
InternalDistributedMember newMemberID = (InternalDistributedMember) newID.getDistributedMember();
assertEquals(Version.GFE_82, newMemberID.getVersionObject());
assertEquals(Version.GFE_82, newID.getClientVersion());
GMSMember newGmsID = (GMSMember) newMemberID.getNetMember();
assertEquals(0, newGmsID.getUuidLSBs());
assertEquals(0, newGmsID.getUuidMSBs());
gmsID.setUUID(new UUID(1234l, 5678l));
memberID.setVersionObjectForTest(Version.CURRENT);
clientID = ClientProxyMembershipID.getClientId(memberID);
out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(clientID, out);
in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
newID = DataSerializer.readObject(in);
newMemberID = (InternalDistributedMember) newID.getDistributedMember();
assertEquals(Version.CURRENT, newMemberID.getVersionObject());
assertEquals(Version.CURRENT, newID.getClientVersion());
newGmsID = (GMSMember) newMemberID.getNetMember();
assertEquals(gmsID.getUuidLSBs(), newGmsID.getUuidLSBs());
assertEquals(gmsID.getUuidMSBs(), newGmsID.getUuidMSBs());
}
use of org.apache.geode.distributed.internal.membership.gms.GMSMember in project geode by apache.
the class GMSHealthMonitor method doTCPCheckMember.
// Package protected for testing purposes
boolean doTCPCheckMember(InternalDistributedMember suspectMember, Socket clientSocket) {
try {
if (clientSocket.isConnected()) {
clientSocket.setSoTimeout((int) services.getConfig().getMemberTimeout());
InputStream in = clientSocket.getInputStream();
DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
GMSMember gmbr = (GMSMember) suspectMember.getNetMember();
writeMemberToStream(gmbr, out);
this.stats.incFinalCheckRequestsSent();
this.stats.incTcpFinalCheckRequestsSent();
logger.debug("Connected to suspect member - reading response");
int b = in.read();
if (logger.isDebugEnabled()) {
logger.debug("Received {}", (b == OK ? "OK" : (b == ERROR ? "ERROR" : "unknown response: " + b)));
}
if (b >= 0) {
this.stats.incFinalCheckResponsesReceived();
this.stats.incTcpFinalCheckResponsesReceived();
}
if (b == OK) {
TimeStamp ts = memberTimeStamps.get(suspectMember);
if (ts != null) {
ts.setTime(System.currentTimeMillis());
}
return true;
} else {
// received ERROR
return false;
}
} else {
// cannot establish TCP connection with suspect member
return false;
}
} catch (SocketTimeoutException e) {
logger.debug("Final check TCP/IP connection timed out for suspect member {}", suspectMember);
return false;
} catch (IOException e) {
logger.trace("Unexpected exception", e);
}
return false;
}
Aggregations