org.apache.cassandra.thrift.TokenRange Java Examples

The following examples show how to use org.apache.cassandra.thrift.TokenRange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * The same as {@code describeRing(String)} but converts TokenRange to the String for JMX compatibility
 *
 * @param keyspace The keyspace to fetch information about
 *
 * @return a List of TokenRange(s) converted to String for the given keyspace
 */
public List<String> describeRingJMX(String keyspace) throws IOException
{
    List<TokenRange> tokenRanges;
    try
    {
        tokenRanges = describeRing(keyspace);
    }
    catch (InvalidRequestException e)
    {
        throw new IOException(e.getMessage());
    }
    List<String> result = new ArrayList<>(tokenRanges.size());

    for (TokenRange tokenRange : tokenRanges)
        result.add(tokenRange.toString());

    return result;
}
 
Example #2
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 5 votes vote down vote up
private List<String> getAllServers(List<TokenRange> input) {
  HashMap<String, Integer> map = new HashMap<String, Integer>(input.size());
  for (TokenRange thisRange : input) {
    List<String> servers = thisRange.rpc_endpoints;
    for (String newServer : servers) {
      map.put(newServer, new Integer(1));
    }
  }

  return new ArrayList<String>(map.keySet());
}
 
Example #3
Source File: AbstractColumnFamilyInputFormat.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public SplitCallable(TokenRange tr, Configuration conf)
{
    this.range = tr;
    this.conf = conf;
}
 
Example #4
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * The same as {@code describeRing(String)} but considers only the part of the ring formed by nodes in the local DC.
 */
public List<TokenRange> describeLocalRing(String keyspace) throws InvalidRequestException
{
    return describeRing(keyspace, true);
}
 
Example #5
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private List<TokenRange> describeRing(String keyspace, boolean includeOnlyLocalDC) throws InvalidRequestException
{
    if (!Schema.instance.getKeyspaces().contains(keyspace))
        throw new InvalidRequestException("No such keyspace: " + keyspace);

    if (keyspace == null || Keyspace.open(keyspace).getReplicationStrategy() instanceof LocalStrategy)
        throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);

    List<TokenRange> ranges = new ArrayList<>();
    Token.TokenFactory tf = getPartitioner().getTokenFactory();

    Map<Range<Token>, List<InetAddress>> rangeToAddressMap =
            includeOnlyLocalDC
                    ? getRangeToAddressMapInLocalDC(keyspace)
                    : getRangeToAddressMap(keyspace);

    for (Map.Entry<Range<Token>, List<InetAddress>> entry : rangeToAddressMap.entrySet())
    {
        Range range = entry.getKey();
        List<InetAddress> addresses = entry.getValue();
        List<String> endpoints = new ArrayList<>(addresses.size());
        List<String> rpc_endpoints = new ArrayList<>(addresses.size());
        List<EndpointDetails> epDetails = new ArrayList<>(addresses.size());

        for (InetAddress endpoint : addresses)
        {
            EndpointDetails details = new EndpointDetails();
            details.host = endpoint.getHostAddress();
            details.datacenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint);
            details.rack = DatabaseDescriptor.getEndpointSnitch().getRack(endpoint);

            endpoints.add(details.host);
            rpc_endpoints.add(getRpcaddress(endpoint));

            epDetails.add(details);
        }

        TokenRange tr = new TokenRange(tf.toString(range.left.getToken()), tf.toString(range.right.getToken()), endpoints)
                                .setEndpoint_details(epDetails)
                                .setRpc_endpoints(rpc_endpoints);

        ranges.add(tr);
    }

    return ranges;
}
 
Example #6
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 4 votes vote down vote up
protected RingConnOption(List<TokenRange> servers) {
  this.servers = getAllServers(servers);
}
 
Example #7
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 4 votes vote down vote up
/**
 * Reset the servers in the ring.
 */
public void resetRing(List<TokenRange> servers) {
  this.servers = getAllServers(servers);
}
 
Example #8
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 4 votes vote down vote up
public RandomizerOption(List<TokenRange> rings) {
  super(rings);
  generator = new Random();
}
 
Example #9
Source File: CassandraProxyClient.java    From Hive-Cassandra with Apache License 2.0 4 votes vote down vote up
public RoundRobinOption(List<TokenRange> rings) {
  super(rings);
  lastUsedIndex = 0;
}
 
Example #10
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 2 votes vote down vote up
/**
 * The TokenRange for a given keyspace.
 *
 * @param keyspace The keyspace to fetch information about
 *
 * @return a List of TokenRange(s) for the given keyspace
 *
 * @throws InvalidRequestException if there is no ring information available about keyspace
 */
public List<TokenRange> describeRing(String keyspace) throws InvalidRequestException
{
    return describeRing(keyspace, false);
}