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