Search in sources :

Example 66 with Replica

use of org.apache.cassandra.locator.Replica in project cassandra by apache.

the class ReadRepairTest 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(target1, mutation(cell1));
    Replica remote1 = full(InetAddressAndPort.getByName("10.0.0.1"));
    Replica remote2 = full(InetAddressAndPort.getByName("10.0.0.2"));
    repairs.put(remote1, mutation(cell1));
    EndpointsForRange participants = EndpointsForRange.of(target1, target2, remote1, remote2);
    EndpointsForRange targets = EndpointsForRange.of(target1, target2);
    InstrumentedReadRepairHandler handler = createRepairHandler(repairs, participants, targets);
    handler.sendInitialRepairs();
    Assert.assertEquals(2, handler.mutationsSent.size());
    Assert.assertTrue(handler.mutationsSent.containsKey(target1.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(target1.endpoint());
    Assert.assertEquals(0, handler.waitingOn());
    Assert.assertTrue(getCurrentRepairStatus(handler));
}
Also used : HashMap(java.util.HashMap) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Mutation(org.apache.cassandra.db.Mutation) Replica(org.apache.cassandra.locator.Replica) Test(org.junit.Test)

Example 67 with Replica

use of org.apache.cassandra.locator.Replica in project cassandra by apache.

the class ReadRepairTest method mutationsArentSentToInSyncNodes.

/**
 * If we didn't send a repair to a replica because there wasn't a diff with the
 * resolved column family, we shouldn't send it a speculative mutation
 */
@Test
public void mutationsArentSentToInSyncNodes() throws Exception {
    Mutation repair1 = mutation(cell2);
    Map<Replica, Mutation> repairs = new HashMap<>();
    repairs.put(target1, repair1);
    // check that the correct initial mutations are sent out
    InstrumentedReadRepairHandler handler = createRepairHandler(repairs, targets, EndpointsForRange.of(target1, target2));
    handler.sendInitialRepairs();
    Assert.assertEquals(1, handler.mutationsSent.size());
    Assert.assertTrue(handler.mutationsSent.containsKey(target1.endpoint()));
    // check that speculative mutations aren't sent to target2
    handler.mutationsSent.clear();
    handler.maybeSendAdditionalWrites(0, TimeUnit.NANOSECONDS);
    Assert.assertEquals(1, handler.mutationsSent.size());
    Assert.assertTrue(handler.mutationsSent.containsKey(target3.endpoint()));
}
Also used : HashMap(java.util.HashMap) Mutation(org.apache.cassandra.db.Mutation) Replica(org.apache.cassandra.locator.Replica) Test(org.junit.Test)

Example 68 with Replica

use of org.apache.cassandra.locator.Replica in project cassandra by apache.

the class ReadRepairTest method onlyBlockOnQuorum.

@Test
public void onlyBlockOnQuorum() {
    Map<Replica, Mutation> repairs = new HashMap<>();
    repairs.put(target1, mutation(cell1));
    repairs.put(target2, mutation(cell2));
    repairs.put(target3, mutation(cell3));
    Assert.assertEquals(3, repairs.size());
    EndpointsForRange replicas = EndpointsForRange.of(target1, target2, target3);
    InstrumentedReadRepairHandler handler = createRepairHandler(repairs, replicas, replicas);
    handler.sendInitialRepairs();
    Assert.assertFalse(getCurrentRepairStatus(handler));
    handler.ack(target1.endpoint());
    Assert.assertFalse(getCurrentRepairStatus(handler));
    // here we should stop blocking, even though we've sent 3 repairs
    handler.ack(target2.endpoint());
    Assert.assertTrue(getCurrentRepairStatus(handler));
}
Also used : HashMap(java.util.HashMap) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Mutation(org.apache.cassandra.db.Mutation) Replica(org.apache.cassandra.locator.Replica) Test(org.junit.Test)

Example 69 with Replica

use of org.apache.cassandra.locator.Replica in project cassandra by apache.

the class ReadRepairTest 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(target1, repair1);
    repairs.put(target2, repair2);
    InstrumentedReadRepairHandler<?, ?> handler = createRepairHandler(repairs, targets, EndpointsForRange.of(target1, target2));
    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.endpoint()));
    assertMutationEqual(repair2, handler.mutationsSent.get(target2.endpoint()));
    // 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.endpoint()));
    // check repairs stop blocking after receiving 2 acks
    Assert.assertFalse(getCurrentRepairStatus(handler));
    handler.ack(target1.endpoint());
    Assert.assertFalse(getCurrentRepairStatus(handler));
    handler.ack(target3.endpoint());
    Assert.assertTrue(getCurrentRepairStatus(handler));
}
Also used : HashMap(java.util.HashMap) Mutation(org.apache.cassandra.db.Mutation) Replica(org.apache.cassandra.locator.Replica) Test(org.junit.Test)

Aggregations

Replica (org.apache.cassandra.locator.Replica)69 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)24 Token (org.apache.cassandra.dht.Token)22 Test (org.junit.Test)20 HashMap (java.util.HashMap)18 Mutation (org.apache.cassandra.db.Mutation)15 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)15 Range (org.apache.cassandra.dht.Range)14 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)13 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)12 Keyspace (org.apache.cassandra.db.Keyspace)11 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)11 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)11 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)10 Collection (java.util.Collection)8 Map (java.util.Map)8 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)8 ReplicaPlan (org.apache.cassandra.locator.ReplicaPlan)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)6