Example usage for org.apache.cassandra.db.commitlog CommitLog instance

List of usage examples for org.apache.cassandra.db.commitlog CommitLog instance

Introduction

In this page you can find the example usage for org.apache.cassandra.db.commitlog CommitLog instance.

Prototype

CommitLog instance

To view the source code for org.apache.cassandra.db.commitlog CommitLog instance.

Click Source Link

Usage

From source file:com.btoddb.flume.sinks.cassandra.EmbeddedServerHelper.java

License:Apache License

public static void cleanupAndLeaveDirs() throws IOException {
    mkdirs();/*from   ww w  .  j  a  va2  s  . c  o  m*/
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this brings it back to safe state
}

From source file:com.savoirtech.bundles.cassandra.AbstractCassandraDaemon.java

License:Apache License

/**
 * This is a hook for concrete daemons to initialize themselves suitably.
 * <p/>/*ww  w . j  a va  2  s.  c o  m*/
 * Subclasses should override this to finish the job (listening on ports, etc.)
 *
 * @throws java.io.IOException
 */
protected void setup() {
    logger.info("JVM vendor/version: {}/{}", System.getProperty("java.vm.name"),
            System.getProperty("java.version"));
    logger.info("Heap size: {}/{}", Runtime.getRuntime().totalMemory(), Runtime.getRuntime().maxMemory());
    logger.info("Classpath: {}", System.getProperty("java.class.path"));
    CLibrary.tryMlockall();

    listenPort = DatabaseDescriptor.getRpcPort();
    listenAddr = DatabaseDescriptor.getRpcAddress();

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            exceptions.incrementAndGet();
            logger.error("Exception in thread " + t, e);
            for (Throwable e2 = e; e2 != null; e2 = e2.getCause()) {
                // some code, like FileChannel.map, will wrap an OutOfMemoryError in another exception
                if (e2 instanceof OutOfMemoryError) {
                    System.exit(100);
                }
            }
        }
    });

    // check all directories(data, commitlog, saved cache) for existence and permission
    Iterable<String> dirs = Iterables.concat(Arrays.asList(DatabaseDescriptor.getAllDataFileLocations()),
            Arrays.asList(new String[] { DatabaseDescriptor.getCommitLogLocation(),
                    DatabaseDescriptor.getSavedCachesLocation() }));
    for (String dataDir : dirs) {
        logger.debug("Checking directory {}", dataDir);
        File dir = new File(dataDir);
        if (dir.exists()) {
            assert dir.isDirectory() && dir.canRead() && dir.canWrite() && dir.canExecute() : String
                    .format("Directory %s is not accessible.", dataDir);
        }
    }

    // Migrate sstables from pre-#2749 to the correct location
    if (Directories.sstablesNeedsMigration()) {
        Directories.migrateSSTables();
    }

    if (CacheService.instance == null) // should never happen
    {
        throw new RuntimeException("Failed to initialize Cache Service.");
    }

    // check the system table to keep user from shooting self in foot by changing partitioner, cluster name, etc.
    // we do a one-off scrub of the system table first; we can't load the list of the rest of the tables,
    // until system table is opened.
    for (CFMetaData cfm : Schema.instance.getTableMetaData(Table.SYSTEM_KS).values()) {
        ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_KS, cfm.cfName);
    }
    try {
        SystemTable.checkHealth();
    } catch (ConfigurationException e) {
        logger.error("Fatal exception during initialization", e);
        System.exit(100);
    }

    // load keyspace descriptions.
    try {
        DatabaseDescriptor.loadSchemas();
    } catch (IOException e) {
        logger.error("Fatal exception during initialization", e);
        System.exit(100);
    }

    // clean up debris in the rest of the tables
    for (String table : Schema.instance.getTables()) {
        for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values()) {
            ColumnFamilyStore.scrubDataDirectories(table, cfm.cfName);
        }
    }

    // initialize keyspaces
    for (String table : Schema.instance.getTables()) {
        if (logger.isDebugEnabled()) {
            logger.debug("opening keyspace " + table);
        }
        Table.open(table);
    }

    if (CacheService.instance.keyCache.size() > 0) {
        logger.info("completed pre-loading ({} keys) key cache.", CacheService.instance.keyCache.size());
    }

    if (CacheService.instance.rowCache.size() > 0) {
        logger.info("completed pre-loading ({} keys) row cache.", CacheService.instance.rowCache.size());
    }

    try {
        GCInspector.instance.start();
    } catch (Throwable t) {
        logger.warn("Unable to start GCInspector (currently only supported on the Sun JVM)");
    }

    // replay the log if necessary
    try {
        CommitLog.instance.recover();
    } catch (IOException e) {
        logger.error("Fatal configuration error", e);
        System.err.println(e.getMessage()
                + "\nFatal configuration error; unable to start server.  See log for stacktrace.");
        System.exit(1);
    }

    SystemTable.finishStartup();

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

    Mx4jTool.maybeLoad();
}

From source file:com.stratio.decision.unit.engine.action.CassandraServer.java

License:Apache License

private static void cleanupAndLeaveDirs() throws IOException {
    mkdirs();//from  w ww .  j  av a 2 s.  c o  m
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(true); // cleanup screws w/ CommitLog, this
    // brings it back to safe state
}

From source file:com.stratio.deep.cassandra.embedded.CassandraServer.java

License:Apache License

private static void cleanupAndLeaveDirs() throws IOException {
    mkdirs();//from  ww w .j  a  v a2 s.c  o m
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this
    // brings it back to safe state
}

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

License:Apache License

/**
 * Override the default setup process to speed up bootstrap
 *
 * - disable JMX/*w w  w . ja va2  s.com*/
 * - 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();
}

From source file:io.datalayer.cassandra.support.AosEmbeddedCassandra.java

License:Apache License

public static void cleanupAndLeaveDirs() throws IOException {
    mkdirs();//from w w  w  . j  a  v  a  2s  .  c om
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this
                                      // brings it back to safe state
}

From source file:me.tango.cassandra.bench.SchemaLoader.java

License:Apache License

public static void prepareServer() {
    // Cleanup first
    // cleanupAndLeaveDirs();

    CommitLog.instance.allocator.enableReserveSegmentCreation();

    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            logger.error("Fatal exception in thread " + t, e);
        }/*from  w ww .j a  v a  2  s. co  m*/
    });

    Keyspace.setInitialized();
}

From source file:me.tango.cassandra.bench.SchemaLoader.java

License:Apache License

public static void cleanupAndLeaveDirs() {
    mkdirs();/*from  ww w .  ja v  a  2s .co  m*/
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this brings it back to safe state
}

From source file:net.dataforte.cassandra.pool.EmbeddedServerHelper.java

License:Open Source License

public static void cleanupAndLeaveDirs() throws IOException {
    mkdirs();//from w  ww.  j a v a2s .  c  o  m
    cleanup();
    mkdirs();
    CommitLog.instance.resetUnsafe(); // cleanup screws w/ CommitLog, this
    // brings it back to safe state
}

From source file:org.normandra.CassandraTestUtil.java

License:Apache License

private static void clearAndReset() throws IOException {
    clear();
    DatabaseDescriptor.createAllDirectories();
    CommitLog.instance.resetUnsafe(true);
}