Example usage for org.apache.cassandra.service StorageService instance

List of usage examples for org.apache.cassandra.service StorageService instance

Introduction

In this page you can find the example usage for org.apache.cassandra.service StorageService instance.

Prototype

StorageService instance

To view the source code for org.apache.cassandra.service StorageService instance.

Click Source Link

Usage

From source file:CassandraStorageClient.java

License:Apache License

public static void init() throws IOException {
    FBUtilities.tryMlockall();//from w  ww.j a v a 2s.com
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            if (e instanceof OutOfMemoryError) {
                System.exit(100);
            }
        }
    });
    for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(Table.SYSTEM_TABLE).values())
        ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_TABLE, cfm.cfName);
    try {
        SystemTable.checkHealth();
    } catch (ConfigurationException e) {
        System.exit(100);
    }

    // load keyspace descriptions.
    try {
        DatabaseDescriptor.loadSchemas();
    } catch (IOException e) {
        System.exit(100);
    }

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

    // initialize keyspaces
    for (String table : DatabaseDescriptor.getTables()) {
        Table.open(table);
    }

    // replay the log if necessary and check for compaction candidates
    CommitLog.recover();
    CompactionManager.instance.checkAllColumnFamilies();

    UUID currentMigration = DatabaseDescriptor.getDefsVersion();
    UUID lastMigration = Migration.getLastMigrationId();
    if ((lastMigration != null) && (lastMigration.timestamp() > currentMigration.timestamp())) {
        MigrationManager.applyMigrations(currentMigration, lastMigration);
    }

    SystemTable.purgeIncompatibleHints();
    StorageService.instance.initClient(); // <-- Start a client, not server, so we don't try and keep data for ourselves.
}

From source file:CassandraStorageClient.java

License:Apache License

public static void close() {
    try {//  w  w w.j  a  v  a2  s. c o m
        // Sleep just in case the number of keys we send over is small
        Thread.sleep(3 * 1000);
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
    StorageService.instance.stopClient();
}

From source file:ClientOnlyExample.java

License:Apache License

private static void startClient() throws Exception {
    StorageService.instance.initClient();
    // sleep for a bit so that gossip can do its thing.
    try {// w w  w.ja va  2s  .  c  o m
        Thread.sleep(10000L);
    } catch (Exception ex) {
        throw new AssertionError(ex);
    }
}

From source file:ClientOnlyExample.java

License:Apache License

/**
 * First, bring one or more nodes up. Then run ClientOnlyExample with these VM arguments:
 *
 * -Xmx1G/*from ww  w.  j  a v a  2 s . co m*/
 * -Dcassandra.config=/Users/gary/cassandra/conf/cassandra.yaml (optional, will first look for cassandra.yaml on classpath)
 *
 * Pass "write" or "read" into the program to exercise the various methods.
 *
 * Caveats:
 *
 * 1.  Much of cassandra is not reentrant.  That is, you can't spin a client up, down, then back up in the same jvm.
 * 2.  Because of the above, you still need to force-quit the process. StorageService.stopClient() doesn't (can't)
 *     spin everything down.
 */
public static void main(String args[]) throws Exception {
    startClient();
    setupKeyspace(createConnection());
    testWriting();
    logger.info("Writing is done. Sleeping, then will try to read.");
    try {
        Thread.currentThread().sleep(10000);
    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    }

    testReading();

    // no need to do this:
    // StorageService.instance().decommission();
    // do this instead:
    StorageService.instance.stopClient();
    System.exit(0); // the only way to really stop the process.
}

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

public void reloadConfiguration() throws ConfigurationException {
    HashMap<InetAddress, String[]> reloadedMap = new HashMap<InetAddress, String[]>();
    String DC_PROPERTY = "dc";
    String RACK_PROPERTY = "rack";
    String PUBLIC_IP_PROPERTY = "publicip";
    String PRIVATE_IP_PROPERTY = "privateip";

    Properties properties = new Properties();
    InputStream stream = null;/*from w w  w .jav  a  2 s  . com*/
    try {
        stream = getClass().getClassLoader().getResourceAsStream(SNITCH_PROPERTIES_FILENAME);
        properties.load(stream);
    } catch (Exception e) {
        throw new ConfigurationException("Unable to read " + SNITCH_PROPERTIES_FILENAME, e);
    } finally {
        FileUtils.closeQuietly(stream);
    }

    datacenter = properties.getProperty(DC_PROPERTY);
    rack = properties.getProperty(RACK_PROPERTY);
    private_ip = checkNotNull(properties.getProperty(PRIVATE_IP_PROPERTY), "%s in %s", PRIVATE_IP_PROPERTY,
            SNITCH_PROPERTIES_FILENAME);
    String public_ip_str = checkNotNull(properties.getProperty(PUBLIC_IP_PROPERTY), "%s in %s",
            PUBLIC_IP_PROPERTY, SNITCH_PROPERTIES_FILENAME);
    try {
        public_ip = InetAddress.getByName(public_ip_str);
    } catch (UnknownHostException e) {
        throw new ConfigurationException("Unknown host " + public_ip_str, e);
    }

    logger.debug("CustomSnitch reloaded, using datacenter: " + datacenter + ", rack: " + rack + ", publicip: "
            + public_ip + ", privateip: " + private_ip);

    if (StorageService.instance != null) // null check tolerates circular dependency; see CASSANDRA-4145
        StorageService.instance.getTokenMetadata().invalidateCaches();

    if (gossipStarted)
        StorageService.instance.gossipSnitchInfo();
}

From source file:brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch.java

License:Apache License

@Override
public void gossiperStarting() {
    super.gossiperStarting();
    Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP,
            StorageService.instance.valueFactory.internalIP(private_ip));
    Gossiper.instance.register(this);
}

From source file:com.btoddb.trellis.cassandra.CassandraLocalApi.java

License:Apache License

/**
 * @see com.btoddb.trellis.cassandra.KeyLocatorService#getNodesForKey(java.lang.String,
 *      java.nio.ByteBuffer)/* ww  w .  ja  v a2  s .  c  o  m*/
 */
@Override
public List<InetAddress> getNodesForKey(String keyspaceName, ByteBuffer key) {
    List<InetAddress> hostList = StorageService.instance.getNaturalEndpoints(keyspaceName, key);
    return hostList;
}

From source file:com.btoddb.trellis.cassandra.CassandraLocalApi.java

License:Apache License

/**
 * @see com.btoddb.trellis.cassandra.NodeManagement#isNodeReachable(java.net.InetAddress)
 *//*from www .  j  av a 2 s  .  c o  m*/
@Override
public boolean isNodeReachable(InetAddress host) {
    List<String> unreachableNodes = StorageService.instance.getUnreachableNodes();
    if (null == unreachableNodes || unreachableNodes.isEmpty()) {
        return true;
    } else {
        return unreachableNodes.contains(host.getHostAddress());
    }
}

From source file:com.btoddb.trellis.cassandra.CassandraLocalApi.java

License:Apache License

@Override
public List<String> getLiveNodes() {
    return StorageService.instance.getLiveNodes();
}

From source file:com.btoddb.trellis.cassandra.CassandraLocalApi.java

License:Apache License

@Override
public List<String> getUnreachableNodes() {
    return StorageService.instance.getUnreachableNodes();
}