Example usage for org.apache.cassandra.utils JVMStabilityInspector inspectThrowable

List of usage examples for org.apache.cassandra.utils JVMStabilityInspector inspectThrowable

Introduction

In this page you can find the example usage for org.apache.cassandra.utils JVMStabilityInspector inspectThrowable.

Prototype

public static void inspectThrowable(Throwable t) throws OutOfMemoryError 

Source Link

Document

Certain Throwables and Exceptions represent "Die" conditions for the server.

Usage

From source file:com.wenyu.cassandra.tools.SSTableLevelToZero.java

License:Apache License

/**
 * @param args a list of sstables whose metadata we are changing
 *///from   w  ww.ja v a2s.  co  m
public static void main(String[] args) throws IOException {
    PrintStream out = System.out;
    if (args.length < 3) {
        out.println("This command should be run with Cassandra stopped!");
        out.println("Usage: sstableleveltozero <keyspace> <columnfamily> <sstablefiles_fullpath>");
        System.exit(1);
    }

    // TODO several daemon threads will run from here.
    // So we have to explicitly call System.exit.
    try {
        // load keyspace descriptions.
        DatabaseDescriptor.loadSchemas();

        String keyspaceName = args[0];
        String columnfamily = args[1];
        String sstables = args[2];

        Set<String> sstableSet = new HashSet<>();
        for (String sstable : sstables.split(",")) {
            sstable = sstable.trim();
            if (sstable.length() == 0) {
                continue;
            }
            sstableSet.add(sstable);
        }

        // validate columnfamily
        if (Schema.instance.getCFMetaData(keyspaceName, columnfamily) == null) {
            System.err.println("ColumnFamily not found: " + keyspaceName + "/" + columnfamily);
            System.exit(1);
        }

        Keyspace keyspace = Keyspace.openWithoutSSTables(keyspaceName);
        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(columnfamily);
        boolean foundSSTable = false;
        for (Map.Entry<Descriptor, Set<Component>> sstable : cfs.directories.sstableLister().list()
                .entrySet()) {
            if (sstable.getValue().contains(Component.STATS)) {
                foundSSTable = true;
                Descriptor descriptor = sstable.getKey();

                StatsMetadata metadata = (StatsMetadata) descriptor.getMetadataSerializer()
                        .deserialize(descriptor, MetadataType.STATS);
                String path = descriptor.filenameFor(Component.DATA);
                if (metadata.sstableLevel > 0 && sstableSet.contains(path)) {
                    out.println("Changing level from " + metadata.sstableLevel + " to 0 on "
                            + descriptor.filenameFor(Component.DATA));
                    descriptor.getMetadataSerializer().mutateLevel(descriptor, 0);
                } else if (metadata.sstableLevel <= 0 && sstableSet.contains(path)) {
                    out.println("Skipped " + descriptor.filenameFor(Component.DATA)
                            + " since it is already on level 0");
                }
            }
        }

        if (!foundSSTable) {
            out.println("Found no sstables, did you give the correct keyspace/columnfamily?");
        }
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        t.printStackTrace();
        System.exit(1);
    }
    System.exit(0);
}

From source file:info.archinnov.achilles.embedded.AchillesCassandraDaemon.java

License:Apache License

/**
 * Override the default setup process to speed up bootstrap
 *
 * - disable JMX/*  ww w .  j  a  va2  s .  c o m*/
 * - disable legacy schema migration
 * - no pre-3.0 hints migration
 * - no pre-3.0 batch entries migration
 * - disable auto compaction on all keyspaces (your test data should fit in memory!!!)
 * - disable metrics
 * - disable GCInspector
 * - disable mlock
 * - disable Thrift server
 * - disable startup checks (Jemalloc, validLaunchDate, JMXPorts, JvmOptions, JnaInitialization, initSigarLibrary, dataDirs, SSTablesFormat, SystemKeyspaceState, Datacenter, Rack)
 * - disable materialized view rebuild (you should clean data folder between each test anyway)
 * - disable the SizeEstimatesRecorder (estimate SSTable size, who cares for unit testing ?)
 */
@Override
protected void setup() {
    // Delete any failed snapshot deletions on Windows - see CASSANDRA-9658
    if (FBUtilities.isWindows())
        WindowsFailedSnapshotTracker.deleteOldSnapshots();

    ThreadAwareSecurityManager.install();

    Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
        StorageMetrics.exceptions.inc();
        logger.error("Exception in thread {}", t, e);
        Tracing.trace("Exception in thread {}", t, e);
        for (Throwable e2 = e; e2 != null; e2 = e2.getCause()) {
            JVMStabilityInspector.inspectThrowable(e2);

            if (e2 instanceof FSError) {
                if (e2 != e) // make sure FSError gets logged exactly once.
                    logger.error("Exception in thread {}", t, e2);
                FileUtils.handleFSError((FSError) e2);
            }

            if (e2 instanceof CorruptSSTableException) {
                if (e2 != e)
                    logger.error("Exception in thread " + t, e2);
                FileUtils.handleCorruptSSTable((CorruptSSTableException) e2);
            }
        }
    });

    // Populate token metadata before flushing, for token-aware sstable partitioning (#6696)
    StorageService.instance.populateTokenMetadata();

    // load schema from disk
    Schema.instance.loadFromDisk();

    try {
        // clean up debris in the rest of the keyspaces
        for (String keyspaceName : Schema.instance.getKeyspaces()) {
            // Skip system as we've already cleaned it
            if (keyspaceName.equals(SystemKeyspace.NAME))
                continue;

            for (CFMetaData cfm : Schema.instance.getTablesAndViews(keyspaceName))
                ColumnFamilyStore.scrubDataDirectories(cfm);
        }
    } catch (StartupException startupEx) {
        logger.error("***** Startup exception : " + startupEx.getLocalizedMessage());
        throw new RuntimeException(startupEx);
    }

    Keyspace.setInitialized();

    // initialize keyspaces
    for (String keyspaceName : Schema.instance.getKeyspaces()) {
        if (logger.isDebugEnabled())
            logger.debug("opening keyspace {}", keyspaceName);
        // disable auto compaction until commit log replay ends
        for (ColumnFamilyStore cfs : Keyspace.open(keyspaceName).getColumnFamilyStores()) {
            for (ColumnFamilyStore store : cfs.concatWithIndexes()) {
                store.disableAutoCompaction();
            }
        }
    }

    try {
        loadRowAndKeyCacheAsync().get();
    } catch (Throwable t) {
        JVMStabilityInspector.inspectThrowable(t);
        logger.warn("Error loading key or row cache", t);
    }

    // replay the log if necessary
    try {
        CommitLog.instance.recover();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    // Re-populate token metadata after commit log recover (new peers might be loaded onto system keyspace #10293)
    StorageService.instance.populateTokenMetadata();

    SystemKeyspace.finishStartup();

    // start server internals
    StorageService.instance.registerDaemon(this);
    try {
        StorageService.instance.initServer();
    } catch (ConfigurationException e) {
        System.err.println(e.getMessage()
                + "\nFatal configuration error; unable to start server.  See log for stacktrace.");
        exitOrFail(1, "Fatal configuration error", e);
    }

    // Native transport
    nativeTransportService = new NativeTransportService();

    completeSetup();
}