Search in sources :

Example 26 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class AbstractReplicationAwareTokenAllocatorTest method addOwnership.

private static void addOwnership(ReplicationAwareTokenAllocator<Unit> t, Token current, Token next, Map<Unit, Double> ownership) {
    TestReplicationStrategy ts = (TestReplicationStrategy) t.strategy;
    double size = current.size(next);
    Token representative = t.partitioner.midpoint(current, next);
    for (Unit n : ts.getReplicas(representative, t.sortedTokens)) {
        Double v = ownership.get(n);
        ownership.put(n, v != null ? v + size : size);
    }
}
Also used : Token(org.apache.cassandra.dht.Token)

Example 27 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class MerkleTree method initHelper.

private Hashable initHelper(Token left, Token right, byte depth, byte max) {
    if (depth == max)
        // we've reached the leaves
        return new Leaf();
    Token midpoint = partitioner.midpoint(left, right);
    if (midpoint.equals(left) || midpoint.equals(right))
        return new Leaf();
    Hashable lchild = initHelper(left, midpoint, inc(depth), max);
    Hashable rchild = initHelper(midpoint, right, inc(depth), max);
    return new Inner(midpoint, lchild, rchild);
}
Also used : Token(org.apache.cassandra.dht.Token)

Example 28 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class MerkleTrees method hash.

@VisibleForTesting
public byte[] hash(Range<Token> range) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    boolean hashed = false;
    try {
        for (Range<Token> rt : merkleTrees.keySet()) {
            if (rt.intersects(range)) {
                byte[] bytes = merkleTrees.get(rt).hash(range);
                if (bytes != null) {
                    baos.write(bytes);
                    hashed = true;
                }
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to append merkle tree hash to result");
    }
    return hashed ? baos.toByteArray() : null;
}
Also used : Token(org.apache.cassandra.dht.Token) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 29 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class PendingRangesBench method searchTokenForOldPendingRanges.

@Benchmark
public void searchTokenForOldPendingRanges(final Blackhole bh) {
    int randomToken = ThreadLocalRandom.current().nextInt(maxToken * 10 + 5);
    Token searchToken = new RandomPartitioner.BigIntegerToken(Integer.toString(randomToken));
    Set<InetAddress> endpoints = new HashSet<>();
    for (Map.Entry<Range<Token>, Collection<InetAddress>> entry : oldPendingRanges.asMap().entrySet()) {
        if (entry.getKey().contains(searchToken))
            endpoints.addAll(entry.getValue());
    }
    bh.consume(endpoints);
}
Also used : Collection(java.util.Collection) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) InetAddress(java.net.InetAddress) Map(java.util.Map) HashSet(java.util.HashSet)

Example 30 with Token

use of org.apache.cassandra.dht.Token in project cassandra by apache.

the class PendingRangesBench method searchToken.

@Benchmark
public void searchToken(final Blackhole bh) {
    int randomToken = ThreadLocalRandom.current().nextInt(maxToken * 10 + 5);
    Token searchToken = new RandomPartitioner.BigIntegerToken(Integer.toString(randomToken));
    bh.consume(pendingRangeMaps.pendingEndpointsFor(searchToken));
}
Also used : Token(org.apache.cassandra.dht.Token)

Aggregations

Token (org.apache.cassandra.dht.Token)173 Range (org.apache.cassandra.dht.Range)73 InetAddress (java.net.InetAddress)66 Test (org.junit.Test)65 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)27 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)27 IPartitioner (org.apache.cassandra.dht.IPartitioner)26 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)23 ArrayList (java.util.ArrayList)16 UUID (java.util.UUID)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)15 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)14 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)9 IOException (java.io.IOException)8 ByteBuffer (java.nio.ByteBuffer)8 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)8 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)8 Set (java.util.Set)7 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)7 HashSet (java.util.HashSet)6