use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelStillConnectedAfterStopWhileReconnectingDS.
@Test
public void testChannelStillConnectedAfterStopWhileReconnectingDS() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(false).when(services).isShutdownDueToForcedDisconnect();
doReturn(false).when(services).isAutoReconnectEnabled();
doReturn(true).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.stop();
assertTrue(messenger.myChannel.isConnected());
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class LocatorDUnitTest method testForceDisconnectAndPeerShutdownCause.
/**
* test lead member failure and normal coordinator shutdown with network partition detection
* enabled.
* <p>
* Start one locators with admin distributed systems, then start two regular distributed members.
* <p>
* We kill the lead member and demonstrate that the other members continue to operate normally.
* <p>
* We then shut down the group coordinator and observe the second locator pick up the job and the
* remaining member continues to operate normally.
*/
// disabled on trunk - should be reenabled on cedar_dev_Oct12
// this test leaves a CloserThread around forever that logs "pausing" messages every 500 ms
@Test
public void testForceDisconnectAndPeerShutdownCause() throws Exception {
disconnectAllFromDS();
Host host = Host.getHost(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM locvm = host.getVM(3);
Locator locator = null;
int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
final int port1 = ports[0];
this.port1 = port1;
final int port2 = ports[1];
DistributedTestUtils.deleteLocatorStateFile(port1, port2);
final String host0 = NetworkUtils.getServerHostName(host);
final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
final Properties properties = new Properties();
properties.put(MCAST_PORT, "0");
properties.put(LOCATORS, locators);
properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "true");
properties.put(DISABLE_AUTO_RECONNECT, "true");
properties.put(MEMBER_TIMEOUT, "2000");
properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
addDSProps(properties);
try {
final String uname = getUniqueName();
File logFile = new File("");
locator = Locator.startLocatorAndDS(port1, logFile, properties);
DistributedSystem sys = locator.getDistributedSystem();
locvm.invoke(() -> {
File lf = new File("");
try {
Locator.startLocatorAndDS(port2, lf, properties);
} catch (IOException ios) {
org.apache.geode.test.dunit.Assert.fail("Unable to start locator2", ios);
}
});
Object[] connectArgs = new Object[] { properties };
SerializableRunnable crashSystem = new SerializableRunnable("Crash system") {
public void run() {
DistributedSystem msys = InternalDistributedSystem.getAnyInstance();
msys.getLogWriter().info("<ExpectedException action=add>service failure</ExpectedException>");
msys.getLogWriter().info("<ExpectedException action=add>org.apache.geode.ConnectException</ExpectedException>");
msys.getLogWriter().info("<ExpectedException action=add>org.apache.geode.ForcedDisconnectException</ExpectedException>");
msys.getLogWriter().info("<ExpectedException action=add>Possible loss of quorum</ExpectedException>");
hook = new TestHook();
MembershipManagerHelper.getMembershipManager(msys).registerTestHook(hook);
try {
MembershipManagerHelper.crashDistributedSystem(msys);
} finally {
hook.reset();
}
}
};
assertTrue(MembershipManagerHelper.getLeadMember(sys) == null);
final DistributedMember mem1 = (DistributedMember) vm1.invoke(this.getClass(), "getDistributedMember", connectArgs);
final DistributedMember mem2 = (DistributedMember) vm2.invoke(this.getClass(), "getDistributedMember", connectArgs);
assertEquals(mem1, MembershipManagerHelper.getLeadMember(sys));
assertEquals(sys.getDistributedMember(), MembershipManagerHelper.getCoordinator(sys));
// crash the lead vm. Should be okay. it should hang in test hook thats
// why call is asynchronous.
// vm1.invokeAsync(crashSystem);
assertTrue("Distributed system should not have disconnected", isSystemConnected());
assertTrue("Distributed system should not have disconnected", vm2.invoke(() -> LocatorDUnitTest.isSystemConnected()));
assertTrue("Distributed system should not have disconnected", locvm.invoke(() -> LocatorDUnitTest.isSystemConnected()));
vm2.invokeAsync(crashSystem);
// 4 x the member-timeout
Wait.pause(1000);
// request member removal for first peer from second peer.
vm2.invoke(new SerializableRunnable("Request Member Removal") {
@Override
public void run() {
DistributedSystem msys = InternalDistributedSystem.getAnyInstance();
MembershipManager mmgr = MembershipManagerHelper.getMembershipManager(msys);
// ForceDisconnectException.
try {
msys.getLogWriter().info("<ExpectedException action=add>Membership: requesting removal of </ExpectedException>");
mmgr.requestMemberRemoval(mem1, "test reasons");
msys.getLogWriter().info("<ExpectedException action=remove>Membership: requesting removal of </ExpectedException>");
fail("It should have thrown exception in requestMemberRemoval");
} catch (DistributedSystemDisconnectedException e) {
Throwable cause = e.getCause();
assertTrue("This should have been ForceDisconnectException but found " + cause, cause instanceof ForcedDisconnectException);
} finally {
hook.reset();
}
}
});
} finally {
if (locator != null) {
locator.stop();
}
locvm.invoke(() -> stopLocator());
assertTrue("locator is not stopped", Locator.getLocators().isEmpty());
}
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class GMSMembershipManager method forceDisconnect.
@Override
public void forceDisconnect(final String reason) {
if (GMSMembershipManager.this.shutdownInProgress || isJoining()) {
// probably a race condition
return;
}
setShutdown();
final Exception shutdownCause = new ForcedDisconnectException(reason);
// cache the exception so it can be appended to ShutdownExceptions
services.setShutdownCause(shutdownCause);
services.getCancelCriterion().cancel(reason);
AlertAppender.getInstance().shuttingDown();
if (!inhibitForceDisconnectLogging) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_SERVICE_FAILURE_0, reason), shutdownCause);
}
if (!services.getConfig().getDistributionConfig().getDisableAutoReconnect()) {
saveCacheXmlForReconnect();
}
Thread reconnectThread = new Thread(() -> {
// stop server locators immediately since they may not have correct
// information. This has caused client failures in bridge/wan
// network-down testing
InternalLocator loc = (InternalLocator) Locator.getLocator();
if (loc != null) {
loc.stop(true, !services.getConfig().getDistributionConfig().getDisableAutoReconnect(), false);
}
uncleanShutdown(reason, shutdownCause);
});
reconnectThread.setName("DisconnectThread");
reconnectThread.setDaemon(false);
reconnectThread.start();
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessenger method send.
private Set<InternalDistributedMember> send(DistributionMessage msg, boolean reliably) {
// perform the same jgroups messaging as in 8.2's GMSMembershipManager.send() method
// BUT: when marshalling messages we need to include the version of the product and
// localAddress at the beginning of the message. These should be used in the receiver
// code to create a versioned input stream, read the sender address, then read the message
// and set its sender address
DMStats theStats = services.getStatistics();
NetView oldView = this.view;
if (!myChannel.isConnected()) {
logger.info("JGroupsMessenger channel is closed - messaging is not possible");
throw new DistributedSystemDisconnectedException("Distributed System is shutting down");
}
filterOutgoingMessage(msg);
// the message's processor if necessary
if ((msg instanceof DirectReplyMessage) && msg.isDirectAck() && msg.getProcessorId() <= 0) {
((DirectReplyMessage) msg).registerProcessor();
}
InternalDistributedMember[] destinations = msg.getRecipients();
boolean allDestinations = msg.forAll();
boolean useMcast = false;
if (services.getConfig().getTransport().isMcastEnabled()) {
if (msg.getMulticast() || allDestinations) {
useMcast = services.getManager().isMulticastAllowed();
}
}
if (logger.isDebugEnabled() && reliably) {
String recips = useMcast ? "multicast" : Arrays.toString(msg.getRecipients());
logger.debug("sending via JGroups: [{}] recipients: {}", msg, recips);
}
JGAddress local = this.jgAddress;
if (useMcast) {
long startSer = theStats.startMsgSerialization();
Message jmsg = createJGMessage(msg, local, Version.CURRENT_ORDINAL);
theStats.endMsgSerialization(startSer);
Exception problem;
try {
jmsg.setTransientFlag(TransientFlag.DONT_LOOPBACK);
if (!reliably) {
jmsg.setFlag(Message.Flag.NO_RELIABILITY);
}
theStats.incSentBytes(jmsg.getLength());
logger.trace("Sending JGroups message: {}", jmsg);
myChannel.send(jmsg);
} catch (Exception e) {
logger.debug("caught unexpected exception", e);
Throwable cause = e.getCause();
if (cause instanceof ForcedDisconnectException) {
problem = (Exception) cause;
} else {
problem = e;
}
if (services.getShutdownCause() != null) {
Throwable shutdownCause = services.getShutdownCause();
// problem.
if (shutdownCause instanceof ForcedDisconnectException) {
problem = (Exception) shutdownCause;
} else {
Throwable ne = problem;
while (ne.getCause() != null) {
ne = ne.getCause();
}
ne.initCause(services.getShutdownCause());
}
}
final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
// services.getManager().membershipFailure(channelClosed, problem);
throw new DistributedSystemDisconnectedException(channelClosed, problem);
}
} else // useMcast
{
// ! useMcast
int len = destinations.length;
// explicit list of members
List<GMSMember> calculatedMembers;
// == calculatedMembers.len
int calculatedLen;
if (len == 1 && destinations[0] == DistributionMessage.ALL_RECIPIENTS) {
// send to all
// Grab a copy of the current membership
NetView v = services.getJoinLeave().getView();
// Construct the list
calculatedLen = v.size();
calculatedMembers = new LinkedList<GMSMember>();
for (int i = 0; i < calculatedLen; i++) {
InternalDistributedMember m = (InternalDistributedMember) v.get(i);
calculatedMembers.add((GMSMember) m.getNetMember());
}
} else // send to all
{
// send to explicit list
calculatedLen = len;
calculatedMembers = new LinkedList<GMSMember>();
for (int i = 0; i < calculatedLen; i++) {
calculatedMembers.add((GMSMember) destinations[i].getNetMember());
}
}
// send to explicit list
Int2ObjectOpenHashMap<Message> messages = new Int2ObjectOpenHashMap<>();
long startSer = theStats.startMsgSerialization();
boolean firstMessage = true;
for (GMSMember mbr : calculatedMembers) {
short version = mbr.getVersionOrdinal();
if (!messages.containsKey(version)) {
Message jmsg = createJGMessage(msg, local, version);
messages.put(version, jmsg);
if (firstMessage) {
theStats.incSentBytes(jmsg.getLength());
firstMessage = false;
}
}
}
theStats.endMsgSerialization(startSer);
Collections.shuffle(calculatedMembers);
int i = 0;
for (GMSMember mbr : calculatedMembers) {
JGAddress to = new JGAddress(mbr);
short version = mbr.getVersionOrdinal();
Message jmsg = messages.get(version);
Exception problem = null;
try {
Message tmp = (i < (calculatedLen - 1)) ? jmsg.copy(true) : jmsg;
if (!reliably) {
jmsg.setFlag(Message.Flag.NO_RELIABILITY);
}
tmp.setDest(to);
tmp.setSrc(this.jgAddress);
logger.trace("Unicasting to {}", to);
myChannel.send(tmp);
} catch (Exception e) {
problem = e;
}
if (problem != null) {
Throwable cause = services.getShutdownCause();
if (cause != null) {
// problem.
if (cause instanceof ForcedDisconnectException) {
problem = (Exception) cause;
} else {
Throwable ne = problem;
while (ne.getCause() != null) {
ne = ne.getCause();
}
ne.initCause(cause);
}
}
final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
// services.getManager().membershipFailure(channelClosed, problem);
throw new DistributedSystemDisconnectedException(channelClosed, problem);
}
}
// send individually
}
// (i.e., left the view), we signal it here.
if (msg.forAll()) {
return Collections.emptySet();
}
Set<InternalDistributedMember> result = new HashSet<>();
NetView newView = this.view;
if (newView != null && newView != oldView) {
for (InternalDistributedMember d : destinations) {
if (!newView.contains(d)) {
logger.debug("messenger: member has left the view: {} view is now {}", d, newView);
result.add(d);
}
}
}
return result;
}
use of org.apache.geode.ForcedDisconnectException in project geode by apache.
the class JGroupsMessengerJUnitTest method testChannelClosedAfterEmergencyCloseForcedDisconnectWithoutAutoReconnect.
@Test
public void testChannelClosedAfterEmergencyCloseForcedDisconnectWithoutAutoReconnect() throws Exception {
initMocks(false);
doCallRealMethod().when(services).setShutdownCause(any(ForcedDisconnectException.class));
doCallRealMethod().when(services).getShutdownCause();
doCallRealMethod().when(services).emergencyClose();
doReturn(true).when(services).isShutdownDueToForcedDisconnect();
doReturn(false).when(services).isAutoReconnectEnabled();
doReturn(false).when(manager).isReconnectingDS();
services.setShutdownCause(new ForcedDisconnectException("Test Forced Disconnect"));
assertTrue(messenger.myChannel.isConnected());
messenger.emergencyClose();
assertFalse(messenger.myChannel.isConnected());
}
Aggregations