Search in sources :

Example 1 with KeyRange

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

the class Selector method newKeyRange.

/**
     * Create a new <code>KeyRange</code> instance.
     * @param startKey                        The inclusive start key of the range
     * @param finishKey                       The inclusive finish key of the range
     * @param maxKeyCount                     The maximum number of keys to be scanned
     * @return                                The new <code>KeyRange</code> instance
     */
public static KeyRange newKeyRange(Bytes startKey, Bytes finishKey, int maxKeyCount) {
    KeyRange keyRange = new KeyRange(maxKeyCount);
    keyRange.setStart_key(nullSafeGet(startKey));
    keyRange.setEnd_key(nullSafeGet(finishKey));
    return keyRange;
}
Also used : KeyRange(org.apache.cassandra.thrift.KeyRange)

Example 2 with KeyRange

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

the class ConfigHelper method setInputRange.

/**
     * Set the KeyRange to limit the rows.
     * @param conf Job configuration you are about to run
     */
public static void setInputRange(Configuration conf, String startToken, String endToken) {
    KeyRange range = new KeyRange().setStart_token(startToken).setEnd_token(endToken);
    conf.set(INPUT_KEYRANGE_CONFIG, keyRangeToString(range));
}
Also used : KeyRange(org.apache.cassandra.thrift.KeyRange)

Example 3 with KeyRange

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

the class ConfigHelper method keyRangeFromString.

private static KeyRange keyRangeFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    KeyRange keyRange = new KeyRange();
    try {
        deserializer.deserialize(keyRange, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return keyRange;
}
Also used : TException(org.apache.thrift.TException) TDeserializer(org.apache.thrift.TDeserializer) TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) KeyRange(org.apache.cassandra.thrift.KeyRange)

Example 4 with KeyRange

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

the class Selector method newKeyRingRange.

/**
     * Create a new <code>KeyRange</code> instance.
     * @param startFollowingKey                The exclusive start key of the ring range
     * @param finishKey                        The inclusive finish key of the range (can be less than <code>startFollowing</code>)
     * @param maxKeyCount                      The maximum number of keys to be scanned
     * @return                                 The new <code>KeyRange</code> instance
     */
public static KeyRange newKeyRingRange(String startFollowingKey, String finishKey, int maxKeyCount) {
    KeyRange keyRange = new KeyRange(maxKeyCount);
    keyRange.setStart_token(startFollowingKey);
    keyRange.setEnd_token(finishKey);
    return keyRange;
}
Also used : KeyRange(org.apache.cassandra.thrift.KeyRange)

Example 5 with KeyRange

use of org.apache.cassandra.thrift.KeyRange 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)

Aggregations

KeyRange (org.apache.cassandra.thrift.KeyRange)5 TException (org.apache.thrift.TException)2 IOException (java.io.IOException)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 Range (org.apache.cassandra.dht.Range)1 Token (org.apache.cassandra.dht.Token)1 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)1 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)1 TokenRange (org.apache.cassandra.thrift.TokenRange)1 Configuration (org.apache.hadoop.conf.Configuration)1 InputSplit (org.apache.hadoop.mapreduce.InputSplit)1 TDeserializer (org.apache.thrift.TDeserializer)1