Search in sources :

Example 1 with EndpointDetails

use of org.apache.cassandra.thrift.EndpointDetails in project atlasdb by palantir.

the class CassandraVerifier method sanityCheckDatacenters.

static Set<String> sanityCheckDatacenters(CassandraClient client, CassandraKeyValueServiceConfig config) throws TException {
    Set<String> hosts = Sets.newHashSet();
    Multimap<String, String> dataCenterToRack = HashMultimap.create();
    List<String> existingKeyspaces = Lists.transform(client.describe_keyspaces(), KsDef::getName);
    if (!existingKeyspaces.contains(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE)) {
        client.system_add_keyspace(new KsDef(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE, CassandraConstants.SIMPLE_STRATEGY, ImmutableList.of()).setStrategy_options(ImmutableMap.of(CassandraConstants.REPLICATION_FACTOR_OPTION, "1")));
    }
    List<TokenRange> ring = client.describe_ring(CassandraConstants.SIMPLE_RF_TEST_KEYSPACE);
    for (TokenRange tokenRange : ring) {
        for (EndpointDetails details : tokenRange.getEndpoint_details()) {
            dataCenterToRack.put(details.datacenter, details.rack);
            hosts.add(details.host);
        }
    }
    if (dataCenterToRack.size() == 1) {
        String dc = dataCenterToRack.keySet().iterator().next();
        String rack = dataCenterToRack.values().iterator().next();
        if (dc.equals(CassandraConstants.DEFAULT_DC) && rack.equals(CassandraConstants.DEFAULT_RACK) && config.replicationFactor() > 1) {
            // We don't allow greater than RF=1 because they didn't set up their node topology
            logErrorOrThrow("The cassandra cluster is not set up to be datacenter and rack aware.  " + "Please set up Cassandra to use NetworkTopology and add corresponding snitch information " + "before running with a replication factor higher than 1. " + "If you're running in some sort of environment where nodes have no known correlated " + "failure patterns, you can set the 'ignoreNodeTopologyChecks' KVS config option.", config.ignoreNodeTopologyChecks());
        }
        if (dataCenterToRack.values().size() < config.replicationFactor() && hosts.size() > config.replicationFactor()) {
            logErrorOrThrow("The cassandra cluster only has one DC, " + "and is set up with less racks than the desired number of replicas, " + "and there are more hosts than the replication factor. " + "It is very likely that your rack configuration is incorrect and replicas " + "would not be placed correctly for the failure tolerance you want. " + "If you fully understand how NetworkTopology replica placement strategy will be placing " + "your replicas, feel free to set the 'ignoreNodeTopologyChecks' KVS config option.", config.ignoreNodeTopologyChecks());
        }
    }
    return dataCenterToRack.keySet();
}
Also used : TokenRange(org.apache.cassandra.thrift.TokenRange) KsDef(org.apache.cassandra.thrift.KsDef) EndpointDetails(org.apache.cassandra.thrift.EndpointDetails)

Aggregations

EndpointDetails (org.apache.cassandra.thrift.EndpointDetails)1 KsDef (org.apache.cassandra.thrift.KsDef)1 TokenRange (org.apache.cassandra.thrift.TokenRange)1