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;
}
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));
}
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;
}
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;
}
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;
}
Aggregations