use of org.apache.geode.SystemConnectException in project geode by apache.
the class LocatorJUnitTest method testNoThreadLeftBehind.
@Test
public void testNoThreadLeftBehind() throws Exception {
Properties dsprops = new Properties();
dsprops.setProperty(MCAST_PORT, "0");
dsprops.setProperty(JMX_MANAGER_START, "false");
dsprops.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = true;
int threadCount = Thread.activeCount();
try {
locator = Locator.startLocatorAndDS(port, new File(""), dsprops);
locator.stop();
fail("expected an exception");
} catch (SystemConnectException expected) {
for (int i = 0; i < 10; i++) {
if (threadCount < Thread.activeCount()) {
Thread.sleep(1000);
}
}
if (threadCount < Thread.activeCount()) {
OSProcess.printStacks(0);
fail("expected " + threadCount + " threads or fewer but found " + Thread.activeCount() + ". Check log file for a thread dump.");
}
} finally {
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
}
}
use of org.apache.geode.SystemConnectException in project geode by apache.
the class JGroupsMessenger method start.
@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
// create the configuration XML string for JGroups
String properties = this.jgStackConfig;
long start = System.currentTimeMillis();
// start the jgroups channel and establish the membership ID
boolean reconnecting = false;
try {
Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
if (oldChannel != null) {
logger.debug("Reusing JGroups channel from previous system", properties);
myChannel = (JChannel) oldChannel;
// scrub the old channel
ViewId vid = new ViewId(new JGAddress(), 0);
View jgv = new View(vid, new ArrayList<>());
this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
UUID logicalAddress = (UUID) myChannel.getAddress();
if (logicalAddress instanceof JGAddress) {
((JGAddress) logicalAddress).setVmViewId(-1);
}
reconnecting = true;
} else {
logger.debug("JGroups configuration: {}", properties);
checkForIPv6();
InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
myChannel = new JChannel(is);
}
} catch (Exception e) {
throw new GemFireConfigException("unable to create jgroups channel", e);
}
// give the stats to the jchannel statistics recorder
StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
if (sr != null) {
sr.setServices(services);
}
Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
transport.setMessenger(this);
nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
try {
myChannel.setReceiver(null);
myChannel.setReceiver(new JGroupsReceiver());
if (!reconnecting) {
// apache g***** (whatever we end up calling it)
myChannel.connect("AG");
}
} catch (Exception e) {
myChannel.close();
throw new SystemConnectException("unable to create jgroups channel", e);
}
if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
throw new SystemConnectException("failing for test");
}
establishLocalAddress();
logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
use of org.apache.geode.SystemConnectException 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();
}
}
use of org.apache.geode.SystemConnectException in project geode by apache.
the class GMSJoinLeave method attemptToJoin.
/**
* send a join request and wait for a reply. Process the reply. This may throw a
* SystemConnectException or an AuthenticationFailedException
*
* @return true if the attempt succeeded, false if it timed out
*/
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "WA_NOT_IN_LOOP")
boolean attemptToJoin() {
SearchState state = searchState;
// send a join request to the coordinator and wait for a response
InternalDistributedMember coord = state.possibleCoordinator;
if (state.alreadyTried.contains(coord)) {
logger.info("Probable coordinator is still {} - waiting for a join-response", coord);
} else {
logger.info("Attempting to join the distributed system through coordinator " + coord + " using address " + this.localAddress);
int port = services.getHealthMonitor().getFailureDetectionPort();
JoinRequestMessage req = new JoinRequestMessage(coord, this.localAddress, services.getAuthenticator().getCredentials(coord), port, services.getMessenger().getRequestId());
// services.getMessenger().send(req, state.view);
services.getMessenger().send(req);
}
JoinResponseMessage response;
try {
response = waitForJoinResponse();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
}
if (response == null) {
if (!isJoined) {
logger.debug("received no join response");
}
return isJoined;
}
logger.debug("received join response {}", response);
joinResponse[0] = null;
String failReason = response.getRejectionMessage();
if (failReason != null) {
if (failReason.contains("Rejecting the attempt of a member using an older version") || failReason.contains("15806")) {
throw new SystemConnectException(failReason);
} else if (failReason.contains("Failed to find credentials")) {
throw new AuthenticationRequiredException(failReason);
}
throw new GemFireSecurityException(failReason);
}
// there is no way we can rech here right now
throw new RuntimeException("Join Request Failed with response " + joinResponse[0]);
}
use of org.apache.geode.SystemConnectException in project geode by apache.
the class InternalDistributedSystem method initialize.
/**
* Initializes this connection to a distributed system with the current configuration state.
*/
private void initialize() {
if (this.originalConfig.getLocators().equals("")) {
if (this.originalConfig.getMcastPort() != 0) {
throw new GemFireConfigException("The " + LOCATORS + " attribute can not be empty when the " + MCAST_PORT + " attribute is non-zero.");
} else {
// no distribution
this.isLoner = true;
}
}
this.config = new RuntimeDistributionConfigImpl(this);
if (!this.isLoner) {
this.attemptingToReconnect = (reconnectAttemptCounter > 0);
}
try {
SocketCreatorFactory.setDistributionConfig(config);
AlertAppender.getInstance().onConnect(this);
// LOG: create LogWriterAppender(s) if log-file or security-log-file is specified
final boolean hasLogFile = this.config.getLogFile() != null && !this.config.getLogFile().equals(new File(""));
final boolean hasSecurityLogFile = this.config.getSecurityLogFile() != null && !this.config.getSecurityLogFile().equals(new File(""));
LogService.configureLoggers(hasLogFile, hasSecurityLogFile);
if (hasLogFile || hasSecurityLogFile) {
// main log file
if (hasLogFile) {
// if log-file then create logWriterAppender
this.logWriterAppender = LogWriterAppenders.getOrCreateAppender(LogWriterAppenders.Identifier.MAIN, this.isLoner, this.config, true);
}
// security log file
if (hasSecurityLogFile) {
// if security-log-file then create securityLogWriterAppender
this.securityLogWriterAppender = LogWriterAppenders.getOrCreateAppender(LogWriterAppenders.Identifier.SECURITY, this.isLoner, this.config, false);
} else {
// let security route to regular log-file or stdout
}
}
// getSecurityLogWriter
if (this.logWriter == null) {
this.logWriter = LogWriterFactory.createLogWriterLogger(this.isLoner, false, this.config, true);
this.logWriter.fine("LogWriter is created.");
}
if (this.securityLogWriter == null) {
// LOG: whole new LogWriterLogger instance for security
this.securityLogWriter = LogWriterFactory.createLogWriterLogger(this.isLoner, true, this.config, false);
this.securityLogWriter.fine("SecurityLogWriter is created.");
}
Services.setLogWriter(this.logWriter);
Services.setSecurityLogWriter(this.securityLogWriter);
this.clock = new DSClock(this.isLoner);
if (this.attemptingToReconnect && logger.isDebugEnabled()) {
logger.debug("This thread is initializing a new DistributedSystem in order to reconnect to other members");
}
// bridge server and will need to enforce the member limit
if (Boolean.getBoolean(InternalLocator.FORCE_LOCATOR_DM_TYPE)) {
this.locatorDMTypeForced = true;
}
// Initialize the Diffie-Hellman and public/private keys
try {
HandShake.initCertsMap(this.config.getSecurityProps());
HandShake.initPrivateKey(this.config.getSecurityProps());
HandShake.initDHKeys(this.config);
} catch (Exception ex) {
throw new GemFireSecurityException(LocalizedStrings.InternalDistributedSystem_PROBLEM_IN_INITIALIZING_KEYS_FOR_CLIENT_AUTHENTICATION.toLocalizedString(), ex);
}
final long offHeapMemorySize = OffHeapStorage.parseOffHeapMemorySize(getConfig().getOffHeapMemorySize());
this.offHeapStore = OffHeapStorage.createOffHeapStorage(this, offHeapMemorySize, this);
// Note: this can only happen on a linux system
if (getConfig().getLockMemory()) {
// This calculation is not exact, but seems fairly close. So far we have
// not loaded much into the heap and the current RSS usage is already
// included the available memory calculation.
long avail = LinuxProcFsStatistics.getAvailableMemory(logger);
long size = offHeapMemorySize + Runtime.getRuntime().totalMemory();
if (avail < size) {
if (ALLOW_MEMORY_LOCK_WHEN_OVERCOMMITTED) {
logger.warn(LocalizedMessage.create(LocalizedStrings.InternalDistributedSystem_MEMORY_OVERCOMMIT_WARN, size - avail));
} else {
throw new IllegalStateException(LocalizedStrings.InternalDistributedSystem_MEMORY_OVERCOMMIT.toLocalizedString(avail, size));
}
}
logger.info("Locking memory. This may take a while...");
GemFireCacheImpl.lockMemory();
logger.info("Finished locking memory.");
}
try {
startInitLocator();
} catch (InterruptedException e) {
throw new SystemConnectException("Startup has been interrupted", e);
}
synchronized (this.isConnectedMutex) {
this.isConnected = true;
}
if (!this.isLoner) {
try {
if (this.quorumChecker != null) {
this.quorumChecker.suspend();
}
this.dm = DistributionManager.create(this);
// fix bug #46324
if (InternalLocator.hasLocator()) {
InternalLocator locator = InternalLocator.getLocator();
getDistributionManager().addHostedLocators(getDistributedMember(), InternalLocator.getLocatorStrings(), locator.isSharedConfigurationEnabled());
}
} finally {
if (this.dm == null && this.quorumChecker != null) {
this.quorumChecker.resume();
}
setDisconnected();
}
} else {
this.dm = new LonerDistributionManager(this, this.logWriter);
}
Assert.assertTrue(this.dm != null);
Assert.assertTrue(this.dm.getSystem() == this);
try {
this.id = this.dm.getChannelId();
} catch (DistributedSystemDisconnectedException e) {
// but during startup we should instead throw a SystemConnectException
throw new SystemConnectException(LocalizedStrings.InternalDistributedSystem_DISTRIBUTED_SYSTEM_HAS_DISCONNECTED.toLocalizedString(), e);
}
synchronized (this.isConnectedMutex) {
this.isConnected = true;
}
if (attemptingToReconnect && (this.startedLocator == null)) {
try {
startInitLocator();
} catch (InterruptedException e) {
throw new SystemConnectException("Startup has been interrupted", e);
}
}
try {
endInitLocator();
} catch (IOException e) {
throw new GemFireIOException("Problem finishing a locator service start", e);
}
if (!statsDisabled) {
// to fix bug 42527 we need a sampler
// even if sampling is not enabled.
this.sampler = new GemFireStatSampler(this);
this.sampler.start();
}
if (this.logWriterAppender != null) {
LogWriterAppenders.startupComplete(LogWriterAppenders.Identifier.MAIN);
}
if (this.securityLogWriterAppender != null) {
LogWriterAppenders.startupComplete(LogWriterAppenders.Identifier.SECURITY);
}
// this.logger.info("ds created", new RuntimeException("DEBUG: STACK"));
// Log any instantiators that were registered before the log writer
// was created
InternalInstantiator.logInstantiators();
} catch (RuntimeException ex) {
this.config.close();
throw ex;
}
resourceListeners = new CopyOnWriteArrayList<ResourceEventsListener>();
this.reconnected = this.attemptingToReconnect;
this.attemptingToReconnect = false;
}
Aggregations