Search in sources :

Example 1 with TokenRange

use of org.apache.cassandra.thrift.TokenRange in project scale7-pelops by s7.

the class Cluster method refreshInternal.

private String[] refreshInternal(String keyspace) throws Exception {
    KeyspaceManager manager = Pelops.createKeyspaceManager(this);
    logger.debug("Fetching nodes using keyspace '{}'", keyspace);
    List<TokenRange> mappings = manager.getKeyspaceRingMappings(keyspace);
    Set<String> clusterNodes = new HashSet<String>();
    for (TokenRange tokenRange : mappings) {
        List<String> endPointList = tokenRange.getEndpoints();
        clusterNodes.addAll(endPointList);
    }
    Iterator<String> iterator = clusterNodes.iterator();
    while (iterator.hasNext()) {
        String node = iterator.next();
        logger.debug("Checking node '{}' against node filter", node);
        if (!nodeFilter.accept(node)) {
            logger.debug("Removing node '{}' as directed by node filter", node);
            iterator.remove();
        }
    }
    String[] nodes = clusterNodes.toArray(new String[clusterNodes.size()]);
    logger.debug("Final set of refreshed nodes: {}", Arrays.toString(nodes));
    return nodes;
}
Also used : TokenRange(org.apache.cassandra.thrift.TokenRange) HashSet(java.util.HashSet)

Example 2 with TokenRange

use of org.apache.cassandra.thrift.TokenRange in project whirr by apache.

the class CassandraServiceTest method testInstances.

@Test
public void testInstances() throws Exception {
    Set<String> endPoints = new HashSet<String>();
    for (Instance instance : cluster.getInstances()) {
        TSocket socket = new TSocket(instance.getPublicAddress().getHostAddress(), CassandraService.CLIENT_PORT);
        socket.open();
        TBinaryProtocol protocol = new TBinaryProtocol(socket);
        Cassandra.Client client = new Cassandra.Client(protocol);
        List<TokenRange> tr = client.describe_ring(KEYSPACE);
        for (TokenRange tokenRange : tr) {
            endPoints.addAll(tokenRange.endpoints);
        }
        socket.close();
    }
    for (Instance instance : cluster.getInstances()) {
        String address = instance.getPrivateAddress().getHostAddress();
        assertTrue(address + " not in cluster!", endPoints.remove(address));
    }
    assertTrue("Unknown node returned: " + endPoints.toString(), endPoints.isEmpty());
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) Instance(org.apache.whirr.service.Cluster.Instance) Cassandra(org.apache.cassandra.thrift.Cassandra) TokenRange(org.apache.cassandra.thrift.TokenRange) HashSet(java.util.HashSet) TSocket(org.apache.thrift.transport.TSocket) Test(org.junit.Test)

Example 3 with TokenRange

use of org.apache.cassandra.thrift.TokenRange in project eiger by wlloyd.

the class ColumnFamilyInputFormat method getSplits.

public List<InputSplit> getSplits(JobContext context) throws IOException {
    Configuration conf = context.getConfiguration();
    validateConfiguration(conf);
    // cannonical ranges and nodes holding replicas
    List<TokenRange> masterRangeNodes = getRangeMap(conf);
    keyspace = ConfigHelper.getInputKeyspace(context.getConfiguration());
    cfName = ConfigHelper.getInputColumnFamily(context.getConfiguration());
    // cannonical ranges, split into pieces, fetching the splits in parallel
    ExecutorService executor = Executors.newCachedThreadPool();
    List<InputSplit> splits = new ArrayList<InputSplit>();
    try {
        List<Future<List<InputSplit>>> splitfutures = new ArrayList<Future<List<InputSplit>>>();
        KeyRange jobKeyRange = ConfigHelper.getInputKeyRange(conf);
        IPartitioner partitioner = null;
        Range<Token> jobRange = null;
        if (jobKeyRange != null) {
            partitioner = ConfigHelper.getInputPartitioner(context.getConfiguration());
            assert partitioner.preservesOrder() : "ConfigHelper.setInputKeyRange(..) can only be used with a order preserving paritioner";
            assert jobKeyRange.start_key == null : "only start_token supported";
            assert jobKeyRange.end_key == null : "only end_token supported";
            jobRange = new Range<Token>(partitioner.getTokenFactory().fromString(jobKeyRange.start_token), partitioner.getTokenFactory().fromString(jobKeyRange.end_token), partitioner);
        }
        for (TokenRange range : masterRangeNodes) {
            if (jobRange == null) {
                // for each range, pick a live owner and ask it to compute bite-sized splits
                splitfutures.add(executor.submit(new SplitCallable(range, conf)));
            } else {
                Range<Token> dhtRange = new Range<Token>(partitioner.getTokenFactory().fromString(range.start_token), partitioner.getTokenFactory().fromString(range.end_token), partitioner);
                if (dhtRange.intersects(jobRange)) {
                    for (Range<Token> intersection : dhtRange.intersectionWith(jobRange)) {
                        range.start_token = partitioner.getTokenFactory().toString(intersection.left);
                        range.end_token = partitioner.getTokenFactory().toString(intersection.right);
                        // for each range, pick a live owner and ask it to compute bite-sized splits
                        splitfutures.add(executor.submit(new SplitCallable(range, conf)));
                    }
                }
            }
        }
        // wait until we have all the results back
        for (Future<List<InputSplit>> futureInputSplits : splitfutures) {
            try {
                splits.addAll(futureInputSplits.get());
            } catch (Exception e) {
                throw new IOException("Could not get input splits", e);
            }
        }
    } finally {
        executor.shutdownNow();
    }
    assert splits.size() > 0;
    Collections.shuffle(splits, new Random(System.nanoTime()));
    return splits;
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) KeyRange(org.apache.cassandra.thrift.KeyRange) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) TokenRange(org.apache.cassandra.thrift.TokenRange) KeyRange(org.apache.cassandra.thrift.KeyRange) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TException(org.apache.thrift.TException) IOException(java.io.IOException) Random(java.util.Random) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) TokenRange(org.apache.cassandra.thrift.TokenRange) ArrayList(java.util.ArrayList) List(java.util.List) InputSplit(org.apache.hadoop.mapreduce.InputSplit) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 4 with TokenRange

use of org.apache.cassandra.thrift.TokenRange in project eiger by wlloyd.

the class RingCache method refreshEndpointMap.

public void refreshEndpointMap() {
    try {
        Cassandra.Client client = ConfigHelper.getClientFromOutputAddressList(conf);
        List<TokenRange> ring = client.describe_ring(ConfigHelper.getOutputKeyspace(conf));
        rangeMap = ArrayListMultimap.create();
        for (TokenRange range : ring) {
            Token<?> left = partitioner.getTokenFactory().fromString(range.start_token);
            Token<?> right = partitioner.getTokenFactory().fromString(range.end_token);
            Range<Token> r = new Range<Token>(left, right, partitioner);
            for (String host : range.endpoints) {
                try {
                    rangeMap.put(r, InetAddress.getByName(host));
                } catch (UnknownHostException e) {
                    // host strings are IPs
                    throw new AssertionError(e);
                }
            }
        }
    } catch (InvalidRequestException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (TException e) {
        logger_.debug("Error contacting seed list" + ConfigHelper.getOutputInitialAddress(conf) + " " + e.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) UnknownHostException(java.net.UnknownHostException) Cassandra(org.apache.cassandra.thrift.Cassandra) Token(org.apache.cassandra.dht.Token) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) TokenRange(org.apache.cassandra.thrift.TokenRange) TokenRange(org.apache.cassandra.thrift.TokenRange) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException)

Aggregations

TokenRange (org.apache.cassandra.thrift.TokenRange)4 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Range (org.apache.cassandra.dht.Range)2 Token (org.apache.cassandra.dht.Token)2 Cassandra (org.apache.cassandra.thrift.Cassandra)2 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)2 TException (org.apache.thrift.TException)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 KeyRange (org.apache.cassandra.thrift.KeyRange)1 Configuration (org.apache.hadoop.conf.Configuration)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1