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