Search in sources :

Example 1 with DelayingShutdownHook

use of ch.qos.logback.core.hook.DelayingShutdownHook in project cassandra by apache.

the class StorageService method initServer.

public synchronized void initServer(int delay) throws ConfigurationException {
    logger.info("Cassandra version: {}", FBUtilities.getReleaseVersionString());
    logger.info("CQL supported versions: {} (default: {})", StringUtils.join(ClientState.getCQLSupportedVersion(), ", "), ClientState.DEFAULT_CQL_VERSION);
    logger.info("Native protocol supported versions: {} (default: {})", StringUtils.join(ProtocolVersion.supportedVersions(), ", "), ProtocolVersion.CURRENT);
    try {
        // Ensure StorageProxy is initialized on start-up; see CASSANDRA-3797.
        Class.forName("org.apache.cassandra.service.StorageProxy");
        // also IndexSummaryManager, which is otherwise unreferenced
        Class.forName("org.apache.cassandra.io.sstable.IndexSummaryManager");
    } catch (ClassNotFoundException e) {
        throw new AssertionError(e);
    }
    // daemon threads, like our executors', continue to run while shutdown hooks are invoked
    drainOnShutdown = NamedThreadFactory.createThread(new WrappedRunnable() {

        @Override
        public void runMayThrow() throws InterruptedException, ExecutionException, IOException {
            drain(true);
            if (FBUtilities.isWindows)
                WindowsTimer.endTimerPeriod(DatabaseDescriptor.getWindowsTimerInterval());
            // Cleanup logback
            DelayingShutdownHook logbackHook = new DelayingShutdownHook();
            logbackHook.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
            logbackHook.run();
        }
    }, "StorageServiceShutdownHook");
    Runtime.getRuntime().addShutdownHook(drainOnShutdown);
    replacing = isReplacing();
    if (!Boolean.parseBoolean(System.getProperty("cassandra.start_gossip", "true"))) {
        logger.info("Not starting gossip as requested.");
        // load ring state in preparation for starting gossip later
        loadRingState();
        initialized = true;
        return;
    }
    prepareToJoin();
    // Has to be called after the host id has potentially changed in prepareToJoin().
    try {
        CacheService.instance.counterCache.loadSavedAsync().get();
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        logger.warn("Error loading counter cache", t);
    }
    if (joinRing) {
        joinTokenRing(delay);
    } else {
        Collection<Token> tokens = SystemKeyspace.getSavedTokens();
        if (!tokens.isEmpty()) {
            tokenMetadata.updateNormalTokens(tokens, FBUtilities.getBroadcastAddress());
            // order is important here, the gossiper can fire in between adding these two states.  It's ok to send TOKENS without STATUS, but *not* vice versa.
            List<Pair<ApplicationState, VersionedValue>> states = new ArrayList<Pair<ApplicationState, VersionedValue>>();
            states.add(Pair.create(ApplicationState.TOKENS, valueFactory.tokens(tokens)));
            states.add(Pair.create(ApplicationState.STATUS, valueFactory.hibernate(true)));
            Gossiper.instance.addLocalApplicationStates(states);
        }
        logger.info("Not joining ring as requested. Use JMX (StorageService->joinRing()) to initiate ring joining");
    }
    initialized = true;
}
Also used : DelayingShutdownHook(ch.qos.logback.core.hook.DelayingShutdownHook)

Aggregations

DelayingShutdownHook (ch.qos.logback.core.hook.DelayingShutdownHook)1