Search in sources :

Example 1 with AbstractByteOrderedPartitioner

use of org.apache.cassandra.dht.AbstractByteOrderedPartitioner in project titan by thinkaurelius.

the class CassandraThriftStoreManager method getLocalKeyPartition.

@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
    CTConnection conn = null;
    IPartitioner partitioner = getCassandraPartitioner();
    if (!(partitioner instanceof AbstractByteOrderedPartitioner))
        throw new UnsupportedOperationException("getLocalKeyPartition() only supported by byte ordered partitioner.");
    Token.TokenFactory tokenFactory = partitioner.getTokenFactory();
    try {
        // Resist the temptation to describe SYSTEM_KS.  It has no ring.
        // Instead, we'll create our own keyspace (or check that it exists), then describe it.
        ensureKeyspaceExists(keySpaceName);
        conn = pool.borrowObject(keySpaceName);
        List<TokenRange> ranges = conn.getClient().describe_ring(keySpaceName);
        List<KeyRange> keyRanges = new ArrayList<KeyRange>(ranges.size());
        for (TokenRange range : ranges) {
            if (!NetworkUtil.hasLocalAddress(range.endpoints))
                continue;
            keyRanges.add(CassandraHelper.transformRange(tokenFactory.fromString(range.start_token), tokenFactory.fromString(range.end_token)));
        }
        return keyRanges;
    } catch (Exception e) {
        throw CassandraThriftKeyColumnValueStore.convertException(e);
    } finally {
        pool.returnObjectUnsafe(keySpaceName, conn);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) AbstractByteOrderedPartitioner(org.apache.cassandra.dht.AbstractByteOrderedPartitioner) KeyRange(com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TException(org.apache.thrift.TException) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Aggregations

BackendException (com.thinkaurelius.titan.diskstorage.BackendException)1 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)1 KeyRange (com.thinkaurelius.titan.diskstorage.keycolumnvalue.KeyRange)1 ArrayList (java.util.ArrayList)1 AbstractByteOrderedPartitioner (org.apache.cassandra.dht.AbstractByteOrderedPartitioner)1 IPartitioner (org.apache.cassandra.dht.IPartitioner)1 Token (org.apache.cassandra.dht.Token)1 TException (org.apache.thrift.TException)1