use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class BlockingReadRepairTest method additionalMutationRequired.
@Test
public void additionalMutationRequired() throws Exception {
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())));
InstrumentedReadRepairHandler handler = createRepairHandler(repairs, writePlan);
Assert.assertTrue(handler.mutationsSent.isEmpty());
// check that the correct mutations are sent
handler.sendInitialRepairs();
Assert.assertEquals(2, handler.mutationsSent.size());
assertMutationEqual(repair1, handler.mutationsSent.get(target1));
assertMutationEqual(repair2, handler.mutationsSent.get(target2));
// check that a combined mutation is speculatively sent to the 3rd target
handler.mutationsSent.clear();
handler.maybeSendAdditionalWrites(0, TimeUnit.NANOSECONDS);
Assert.assertEquals(1, handler.mutationsSent.size());
assertMutationEqual(resolved, handler.mutationsSent.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));
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class BlockingReadRepairTest method remoteDCTest.
/**
* For dc local consistency levels, noop mutations and responses from remote dcs should not affect effective blockFor
*/
@Test
public void remoteDCTest() throws Exception {
Map<Replica, Mutation> repairs = new HashMap<>();
repairs.put(replica1, mutation(cell1));
Replica remote1 = ReplicaUtils.full(InetAddressAndPort.getByName("10.0.0.1"));
Replica remote2 = ReplicaUtils.full(InetAddressAndPort.getByName("10.0.0.2"));
repairs.put(remote1, mutation(cell1));
EndpointsForRange participants = EndpointsForRange.of(replica1, replica2, remote1, remote2);
ReplicaPlan.ForTokenWrite writePlan = repairPlan(replicaPlan(ks, ConsistencyLevel.LOCAL_QUORUM, participants));
InstrumentedReadRepairHandler handler = createRepairHandler(repairs, writePlan);
handler.sendInitialRepairs();
Assert.assertEquals(2, handler.mutationsSent.size());
Assert.assertTrue(handler.mutationsSent.containsKey(replica1.endpoint()));
Assert.assertTrue(handler.mutationsSent.containsKey(remote1.endpoint()));
Assert.assertEquals(1, handler.waitingOn());
Assert.assertFalse(getCurrentRepairStatus(handler));
handler.ack(remote1.endpoint());
Assert.assertEquals(1, handler.waitingOn());
Assert.assertFalse(getCurrentRepairStatus(handler));
handler.ack(replica1.endpoint());
Assert.assertEquals(0, handler.waitingOn());
Assert.assertTrue(getCurrentRepairStatus(handler));
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class StorageServiceTest method testGetChangedReplicasForLeaving.
@Test
public void testGetChangedReplicasForLeaving() throws Exception {
TokenMetadata tmd = new TokenMetadata();
tmd.updateNormalToken(threeToken, aAddress);
tmd.updateNormalToken(sixToken, bAddress);
tmd.updateNormalToken(nineToken, cAddress);
tmd.updateNormalToken(elevenToken, dAddress);
tmd.updateNormalToken(oneToken, eAddress);
tmd.addLeavingEndpoint(aAddress);
AbstractReplicationStrategy strat = simpleStrategy(tmd);
EndpointsByReplica result = StorageService.getChangedReplicasForLeaving("StorageServiceTest", aAddress, tmd, strat);
System.out.println(result);
EndpointsByReplica.Builder expectedResult = new EndpointsByReplica.Builder();
expectedResult.put(new Replica(aAddress, aRange, true), new Replica(cAddress, new Range<>(oneToken, sixToken), true));
expectedResult.put(new Replica(aAddress, aRange, true), new Replica(dAddress, new Range<>(oneToken, sixToken), false));
expectedResult.put(new Replica(aAddress, eRange, true), new Replica(bAddress, eRange, true));
expectedResult.put(new Replica(aAddress, eRange, true), new Replica(cAddress, eRange, false));
expectedResult.put(new Replica(aAddress, dRange, false), new Replica(bAddress, dRange, false));
assertMultimapEqualsIgnoreOrder(result, expectedResult.build());
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class StorageServiceTest method assertMultimapEqualsIgnoreOrder.
public static <K, C extends ReplicaCollection<? extends C>> void assertMultimapEqualsIgnoreOrder(ReplicaMultimap<K, C> a, ReplicaMultimap<K, C> b) {
if (!a.keySet().equals(b.keySet()))
fail(formatNeq(a, b));
for (K key : a.keySet()) {
C ac = a.get(key);
C bc = b.get(key);
if (ac.size() != bc.size())
fail(formatNeq(a, b));
for (Replica r : ac) {
if (!bc.contains(r))
fail(formatNeq(a, b));
}
}
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class LocalSessions method filterLocalRanges.
RangesAtEndpoint filterLocalRanges(String keyspace, Set<Range<Token>> ranges) {
RangesAtEndpoint localRanges = StorageService.instance.getLocalReplicas(keyspace);
RangesAtEndpoint.Builder builder = RangesAtEndpoint.builder(localRanges.endpoint());
for (Range<Token> range : ranges) {
for (Replica replica : localRanges) {
if (replica.range().equals(range)) {
builder.add(replica);
} else if (replica.contains(range)) {
builder.add(replica.decorateSubrange(range));
}
}
}
return builder.build();
}
Aggregations