Search in sources :

Example 21 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class MemberHealthEvaluator method checkCacheRequiredRolesMeet.

/**
   * The function keeps updating the health of the cache based on roles required by the regions and
   * their reliability policies.
   */
private void checkCacheRequiredRolesMeet(List status) {
    try {
        InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
        CachePerfStats cPStats = cache.getCachePerfStats();
        if (cPStats.getReliableRegionsMissingFullAccess() > 0) {
            // health is okay.
            int numRegions = cPStats.getReliableRegionsMissingFullAccess();
            status.add(okayHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_BUT_ARE_CONFIGURED_FOR_FULL_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingLimitedAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingLimitedAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITH_LIMITED_ACCESS.toLocalizedString(numRegions)));
        } else if (cPStats.getReliableRegionsMissingNoAccess() > 0) {
            // health is poor
            int numRegions = cPStats.getReliableRegionsMissingNoAccess();
            status.add(poorHealth(LocalizedStrings.MemberHealthEvaluator_THERE_ARE_0_REGIONS_MISSING_REQUIRED_ROLES_AND_CONFIGURED_WITHOUT_ACCESS.toLocalizedString(numRegions)));
        }
    } catch (CancelException ignore) {
    }
}
Also used : CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) InternalCache(org.apache.geode.internal.cache.InternalCache) CancelException(org.apache.geode.CancelException)

Example 22 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class DistributionManager method sendShutdownMessage.

/**
   * Sends the shutdown message. Not all DistributionManagers need to do this.
   */
protected void sendShutdownMessage() {
    if (getDMType() == ADMIN_ONLY_DM_TYPE && Locator.getLocators().size() == 0) {
        // If two locators are simultaneously shut down this may not occur.
        return;
    }
    ShutdownMessage m = new ShutdownMessage();
    InternalDistributedMember theId = this.getDistributionManagerId();
    m.setDistributionManagerId(theId);
    Set allOthers = new HashSet(getViewMembers());
    allOthers.remove(getDistributionManagerId());
    // ReplyProcessor21 rp = new ReplyProcessor21(this, allOthers);
    // m.setProcessorId(rp.getProcessorId());
    // m.setMulticast(system.getConfig().getMcastPort() != 0);
    m.setRecipients(allOthers);
    // Address recipient = (Address) m.getRecipient();
    if (logger.isTraceEnabled()) {
        logger.trace("{} Sending {} to {}", this.getDistributionManagerId(), m, m.getRecipientsDescription());
    }
    try {
        // m.resetTimestamp(); // nanotimers across systems don't match
        long startTime = DistributionStats.getStatTime();
        channel.send(m.getRecipients(), m, this, stats);
        this.stats.incSentMessages(1L);
        if (DistributionStats.enableClockStats) {
            stats.incSentMessagesTime(DistributionStats.getStatTime() - startTime);
        }
    } catch (CancelException e) {
        logger.debug("CancelException caught sending shutdown: {}", e.getMessage(), e);
    } catch (Exception ex2) {
        logger.fatal(LocalizedMessage.create(LocalizedStrings.DistributionManager_WHILE_SENDING_SHUTDOWN_MESSAGE), ex2);
    } finally {
        // Even if the message wasn't sent, *lie* about it, so that
        // everyone believes that message distribution is done.
        this.shutdownMsgSent = true;
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException) IncompatibleSystemException(org.apache.geode.IncompatibleSystemException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) InternalGemFireException(org.apache.geode.InternalGemFireException) InvalidDeltaException(org.apache.geode.InvalidDeltaException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) NoSuchElementException(java.util.NoSuchElementException) NotSerializableException(java.io.NotSerializableException) UnknownHostException(java.net.UnknownHostException) ReenteredConnectException(org.apache.geode.internal.tcp.ReenteredConnectException) ToDataException(org.apache.geode.ToDataException) HashSet(java.util.HashSet)

Example 23 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class ConnectionFactoryImpl method createClientToServerConnection.

public Connection createClientToServerConnection(Set excludedServers) throws GemFireSecurityException {
    final Set origExcludedServers = excludedServers;
    excludedServers = new HashSet(excludedServers);
    Set blackListedServers = blackList.getBadServers();
    excludedServers.addAll(blackListedServers);
    Connection conn = null;
    // long startTime = System.currentTimeMillis();
    RuntimeException fatalException = null;
    boolean tryBlackList = true;
    do {
        ServerLocation server = source.findServer(excludedServers);
        if (server == null) {
            if (tryBlackList) {
                // Nothing worked! Let's try without the blacklist.
                tryBlackList = false;
                int size = excludedServers.size();
                excludedServers.removeAll(blackListedServers);
                // make sure we didn't remove any of the ones that the caller set not to use
                excludedServers.addAll(origExcludedServers);
                if (excludedServers.size() < size) {
                    // We are able to remove some exclusions, so lets give this another whirl.
                    continue;
                }
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Source was unable to locate any servers");
            }
            if (fatalException != null) {
                throw fatalException;
            }
            return null;
        }
        try {
            conn = createClientToServerConnection(server, false);
        } catch (CancelException e) {
            // propagate this up immediately
            throw e;
        } catch (GemFireSecurityException e) {
            // propagate this up immediately
            throw e;
        } catch (GatewayConfigurationException e) {
            // propagate this up immediately
            throw e;
        } catch (ServerRefusedConnectionException srce) {
            fatalException = srce;
            if (logger.isDebugEnabled()) {
                logger.debug("ServerRefusedConnectionException attempting to connect to {}", server, srce);
            }
        } catch (Exception e) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.ConnectException_COULD_NOT_CONNECT_TO_0, server), e);
        }
        excludedServers.add(server);
    } while (conn == null);
    // }
    return conn;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) Set(java.util.Set) HashSet(java.util.HashSet) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) CancelException(org.apache.geode.CancelException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) HashSet(java.util.HashSet)

Example 24 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class ConnectionFactoryImpl method createClientToServerConnection.

public Connection createClientToServerConnection(ServerLocation location, boolean forQueue) throws GemFireSecurityException {
    ConnectionImpl connection = new ConnectionImpl(this.ds, this.cancelCriterion);
    FailureTracker failureTracker = blackList.getFailureTracker(location);
    boolean initialized = false;
    try {
        HandShake connHandShake = new HandShake(handshake);
        connection.connect(endpointManager, location, connHandShake, socketBufferSize, handShakeTimeout, readTimeout, getCommMode(forQueue), this.gatewaySender, this.socketCreator);
        failureTracker.reset();
        connection.setHandShake(connHandShake);
        authenticateIfRequired(connection);
        initialized = true;
    } catch (GemFireConfigException e) {
        throw e;
    } catch (CancelException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GemFireSecurityException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GatewayConfigurationException e) {
        // propagate this up, don't retry
        throw e;
    } catch (ServerRefusedConnectionException src) {
        // propagate this up, don't retry
        logger.warn(LocalizedMessage.create(LocalizedStrings.AutoConnectionSourceImpl_COULD_NOT_CREATE_A_NEW_CONNECTION_TO_SERVER_0, src.getMessage()));
        testFailedConnectionToServer = true;
        throw src;
    } catch (Exception e) {
        if (e.getMessage() != null && (e.getMessage().equals("Connection refused") || e.getMessage().equals("Connection reset"))) {
            // print an exception
            if (logger.isDebugEnabled()) {
                logger.debug("Unable to connect to {}: connection refused", location);
            }
        } else {
            // print a warning with the exception stack trace
            logger.warn(LocalizedMessage.create(LocalizedStrings.ConnectException_COULD_NOT_CONNECT_TO_0, location), e);
        }
        testFailedConnectionToServer = true;
    } finally {
        if (!initialized) {
            connection.destroy();
            failureTracker.addFailure();
            connection = null;
        }
    }
    return connection;
}
Also used : HandShake(org.apache.geode.internal.cache.tier.sockets.HandShake) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) CancelException(org.apache.geode.CancelException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 25 with CancelException

use of org.apache.geode.CancelException in project geode by apache.

the class HostStatSampler method run.

/**
   * This service's main loop
   */
@Override
public void run() {
    final boolean isDebugEnabled_STATISTICS = logger.isTraceEnabled(LogMarker.STATISTICS);
    if (isDebugEnabled_STATISTICS) {
        logger.trace(LogMarker.STATISTICS, "HostStatSampler started");
    }
    boolean latchCountedDown = false;
    try {
        initSpecialStats();
        this.sampleCollector = new SampleCollector(this);
        this.sampleCollector.initialize(this, timer.getTime(), new MainWithChildrenRollingFileHandler());
        this.statSamplerInitializedLatch.countDown();
        latchCountedDown = true;
        timer.reset();
        // subtract getNanoRate from lastTS to force a quick initial sample
        long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate();
        while (!stopRequested()) {
            SystemFailure.checkFailure();
            if (Thread.currentThread().isInterrupted()) {
                break;
            }
            final long nanosBeforeSleep = timer.getLastResetTime();
            final long nanosToDelay = nanosLastTimeStamp + getNanoRate();
            delay(nanosToDelay);
            nanosLastTimeStamp = timer.getLastResetTime();
            if (!stopRequested() && isSamplingEnabled()) {
                final long nanosTimeStamp = timer.getLastResetTime();
                final long nanosElapsedSleeping = nanosTimeStamp - nanosBeforeSleep;
                checkElapsedSleepTime(nanosElapsedSleeping);
                if (stopRequested())
                    break;
                sampleSpecialStats(false);
                if (stopRequested())
                    break;
                checkListeners();
                if (stopRequested())
                    break;
                this.sampleCollector.sample(nanosTimeStamp);
                final long nanosSpentWorking = timer.reset();
                accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping);
            } else if (!stopRequested() && !isSamplingEnabled()) {
                // fixes bug 42527
                sampleSpecialStats(true);
            }
        }
    } catch (InterruptedException ex) {
    // Silently exit
    } catch (CancelException ex) {
    // Silently exit
    } catch (RuntimeException ex) {
        logger.fatal(LogMarker.STATISTICS, ex.getMessage(), ex);
        throw ex;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Error ex) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        logger.fatal(LogMarker.STATISTICS, ex.getMessage(), ex);
        throw ex;
    } finally {
        try {
            closeSpecialStats();
            if (this.sampleCollector != null) {
                this.sampleCollector.close();
            }
        } finally {
            if (!latchCountedDown) {
                // Make sure the latch gets counted down since
                // other threads wait for this to indicate that
                // the sampler is initialized.
                this.statSamplerInitializedLatch.countDown();
            }
        }
        if (isDebugEnabled_STATISTICS) {
            logger.trace(LogMarker.STATISTICS, "HostStatSampler stopped");
        }
    }
}
Also used : CancelException(org.apache.geode.CancelException) MainWithChildrenRollingFileHandler(org.apache.geode.internal.io.MainWithChildrenRollingFileHandler)

Aggregations

CancelException (org.apache.geode.CancelException)135 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)46 IOException (java.io.IOException)40 ReplyException (org.apache.geode.distributed.internal.ReplyException)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CacheClosedException (org.apache.geode.cache.CacheClosedException)23 Region (org.apache.geode.cache.Region)22 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 Set (java.util.Set)16 Cache (org.apache.geode.cache.Cache)16 CacheException (org.apache.geode.cache.CacheException)16 HashSet (java.util.HashSet)15 Iterator (java.util.Iterator)15 QueryException (org.apache.geode.cache.query.QueryException)15 ArrayList (java.util.ArrayList)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)13 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13