Search in sources :

Example 26 with Replica

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));
}
Also used : ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) HashMap(java.util.HashMap) Mutation(org.apache.cassandra.db.Mutation) Replica(org.apache.cassandra.locator.Replica) Test(org.junit.Test)

Example 27 with Replica

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));
}
Also used : ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) 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 28 with Replica

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());
}
Also used : AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Test(org.junit.Test)

Example 29 with Replica

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));
        }
    }
}
Also used : Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica)

Example 30 with Replica

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();
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Replica(org.apache.cassandra.locator.Replica)

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