Search in sources :

Example 1 with SystemConnectException

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;
    }
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) File(java.io.File) SystemConnectException(org.apache.geode.SystemConnectException) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with SystemConnectException

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);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Example 3 with SystemConnectException

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();
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) NetView(org.apache.geode.distributed.internal.membership.NetView) DistributionException(org.apache.geode.distributed.internal.DistributionException) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) TimeoutException(java.util.concurrent.TimeoutException) ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException) SystemConnectException(org.apache.geode.SystemConnectException)

Example 4 with SystemConnectException

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]);
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) SystemConnectException(org.apache.geode.SystemConnectException)

Example 5 with SystemConnectException

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;
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheXmlException(org.apache.geode.cache.CacheXmlException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ManagementException(org.apache.geode.management.ManagementException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) GemFireStatSampler(org.apache.geode.internal.statistics.GemFireStatSampler) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireConfigException(org.apache.geode.GemFireConfigException) GemFireIOException(org.apache.geode.GemFireIOException) File(java.io.File) SystemConnectException(org.apache.geode.SystemConnectException)

Aggregations

SystemConnectException (org.apache.geode.SystemConnectException)11 GemFireConfigException (org.apache.geode.GemFireConfigException)6 IOException (java.io.IOException)5 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)5 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)5 CancelException (org.apache.geode.CancelException)4 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)4 GemFireIOException (org.apache.geode.GemFireIOException)3 File (java.io.File)2 NotSerializableException (java.io.NotSerializableException)2 ServerSocket (java.net.ServerSocket)2 UnknownHostException (java.net.UnknownHostException)2 Properties (java.util.Properties)2 ToDataException (org.apache.geode.ToDataException)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2 CacheXmlException (org.apache.geode.cache.CacheXmlException)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 DistributionException (org.apache.geode.distributed.internal.DistributionException)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)2