Search in sources :

Example 21 with Replica

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

Example 22 with Replica

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

Example 23 with Replica

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

Example 24 with Replica

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

Example 25 with Replica

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

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