use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class BootstrapTransientTest method endpoints.
public EndpointsForRange endpoints(Replica... replicas) {
assert replicas.length > 0;
Range<Token> range = replicas[0].range();
EndpointsForRange.Builder builder = EndpointsForRange.builder(range);
for (Replica r : replicas) {
assert r.range().equals(range);
builder.add(r);
}
return builder.build();
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class StorageProxyTest method shouldHintTest.
private void shouldHintTest(Consumer<Replica> test) throws Exception {
InetAddressAndPort testEp = InetAddressAndPort.getByName("192.168.1.1");
Replica replica = full(testEp);
StorageService.instance.getTokenMetadata().updateHostId(UUID.randomUUID(), testEp);
EndpointState state = new EndpointState(new HeartBeatState(0, 0));
Gossiper.runInGossipStageBlocking(() -> Gossiper.instance.markDead(replica.endpoint(), state));
try {
test.accept(replica);
} finally {
StorageService.instance.getTokenMetadata().removeEndpoint(testEp);
}
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class ActiveRepairServiceTest method testGetNeighborsTimesTwoInSpecifiedHosts.
@Test
public void testGetNeighborsTimesTwoInSpecifiedHosts() throws Throwable {
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
// generate rf*2 nodes, and ensure that only neighbors specified by the hosts are returned
addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor().allReplicas);
AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
List<InetAddressAndPort> expected = new ArrayList<>();
for (Replica replicas : ars.getAddressReplicas().get(FBUtilities.getBroadcastAddressAndPort())) {
expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicas.range()).endpoints());
}
expected.remove(FBUtilities.getBroadcastAddressAndPort());
Collection<String> hosts = Arrays.asList(FBUtilities.getBroadcastAddressAndPort().getHostAddressAndPort(), expected.get(0).getHostAddressAndPort());
Iterable<Range<Token>> ranges = StorageService.instance.getLocalReplicas(KEYSPACE5).ranges();
assertEquals(expected.get(0), ActiveRepairService.getNeighbors(KEYSPACE5, ranges, ranges.iterator().next(), null, hosts).endpoints().iterator().next());
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class ActiveRepairServiceTest method testGetNeighborsTimesTwoInLocalDC.
@Test
public void testGetNeighborsTimesTwoInLocalDC() throws Throwable {
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
// generate rf*2 nodes, and ensure that only neighbors specified by the ARS are returned
addTokens(2 * Keyspace.open(KEYSPACE5).getReplicationStrategy().getReplicationFactor().allReplicas);
AbstractReplicationStrategy ars = Keyspace.open(KEYSPACE5).getReplicationStrategy();
Set<InetAddressAndPort> expected = new HashSet<>();
for (Replica replica : ars.getAddressReplicas().get(FBUtilities.getBroadcastAddressAndPort())) {
expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replica.range()).endpoints());
}
expected.remove(FBUtilities.getBroadcastAddressAndPort());
// remove remote endpoints
TokenMetadata.Topology topology = tmd.cloneOnlyTokenMap().getTopology();
HashSet<InetAddressAndPort> localEndpoints = Sets.newHashSet(topology.getDatacenterEndpoints().get(DatabaseDescriptor.getLocalDataCenter()));
expected = Sets.intersection(expected, localEndpoints);
Iterable<Range<Token>> ranges = StorageService.instance.getLocalReplicas(KEYSPACE5).ranges();
Set<InetAddressAndPort> neighbors = new HashSet<>();
for (Range<Token> range : ranges) {
neighbors.addAll(ActiveRepairService.getNeighbors(KEYSPACE5, ranges, range, Arrays.asList(DatabaseDescriptor.getLocalDataCenter()), null).endpoints());
}
assertEquals(expected, neighbors);
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class DiagEventsBlockingReadRepairTest method additionalMutationRequired.
@Test
public void additionalMutationRequired() {
Mutation repair1 = mutation(cell2);
Mutation repair2 = mutation(cell1);
// check that the correct repairs are calculated
Map<Replica, Mutation> repairs = new HashMap<>();
repairs.put(replica1, repair1);
repairs.put(replica2, repair2);
ReplicaPlan.ForTokenWrite writePlan = repairPlan(replicas, EndpointsForRange.copyOf(Lists.newArrayList(repairs.keySet())));
DiagnosticPartitionReadRepairHandler handler = createRepairHandler(repairs, writePlan);
Assert.assertTrue(handler.updatesByEp.isEmpty());
// check that the correct mutations are sent
handler.sendInitialRepairs();
Assert.assertEquals(2, handler.updatesByEp.size());
Assert.assertEquals(repair1.toString(), handler.updatesByEp.get(target1));
Assert.assertEquals(repair2.toString(), handler.updatesByEp.get(target2));
// check that a combined mutation is speculatively sent to the 3rd target
handler.updatesByEp.clear();
handler.maybeSendAdditionalWrites(0, TimeUnit.NANOSECONDS);
Assert.assertEquals(1, handler.updatesByEp.size());
Assert.assertEquals(resolved.toString(), handler.updatesByEp.get(target3));
// check repairs stop blocking after receiving 2 acks
Assert.assertFalse(getCurrentRepairStatus(handler));
handler.ack(target1);
Assert.assertFalse(getCurrentRepairStatus(handler));
handler.ack(target3);
Assert.assertTrue(getCurrentRepairStatus(handler));
}
Aggregations