Search in sources :

Example 56 with Replica

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

the class MoveTest method assertRanges.

private static void assertRanges(RangesByEndpoint epReplicas, String endpoint, int... rangePairs) {
    if (rangePairs.length % 2 == 1)
        throw new RuntimeException("assertRanges argument count should be even");
    InetAddressAndPort ep = inet(endpoint);
    List<Replica> expected = new ArrayList<>(rangePairs.length / 2);
    for (int i = 0; i < rangePairs.length; i += 2) expected.add(replica(ep, rangePairs[i], rangePairs[i + 1]));
    RangesAtEndpoint actual = epReplicas.get(ep);
    assertEquals(expected.size(), actual.size());
    for (Replica replica : expected) if (!actual.contains(replica))
        assertEquals(RangesAtEndpoint.copyOf(expected), actual);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Replica(org.apache.cassandra.locator.Replica) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) RangesByEndpoint(org.apache.cassandra.locator.RangesByEndpoint)

Example 57 with Replica

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

the class WriteResponseHandlerTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Throwable {
    SchemaLoader.loadSchema();
    DatabaseDescriptor.setPartitionerUnsafe(Murmur3Partitioner.instance);
    // Register peers with expected DC for NetworkTopologyStrategy.
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    metadata.updateHostId(UUID.randomUUID(), InetAddressAndPort.getByName("127.1.0.255"));
    metadata.updateHostId(UUID.randomUUID(), InetAddressAndPort.getByName("127.2.0.255"));
    DatabaseDescriptor.setEndpointSnitch(new IEndpointSnitch() {

        public String getRack(InetAddressAndPort endpoint) {
            return null;
        }

        public String getDatacenter(InetAddressAndPort endpoint) {
            byte[] address = endpoint.getAddress().getAddress();
            if (address[1] == 1)
                return "datacenter1";
            else
                return "datacenter2";
        }

        public <C extends ReplicaCollection<? extends C>> C sortedByProximity(InetAddressAndPort address, C replicas) {
            return replicas;
        }

        public int compareEndpoints(InetAddressAndPort target, Replica a1, Replica a2) {
            return 0;
        }

        public void gossiperStarting() {
        }

        public boolean isWorthMergingForRangeQuery(ReplicaCollection<?> merged, ReplicaCollection<?> l1, ReplicaCollection<?> l2) {
            return false;
        }
    });
    DatabaseDescriptor.setBroadcastAddress(InetAddress.getByName("127.1.0.1"));
    SchemaLoader.createKeyspace("Foo", KeyspaceParams.nts("datacenter1", 3, "datacenter2", 3), SchemaLoader.standardCFMD("Foo", "Bar"));
    ks = Keyspace.open("Foo");
    cfs = ks.getColumnFamilyStore("Bar");
    targets = EndpointsForToken.of(DatabaseDescriptor.getPartitioner().getToken(ByteBufferUtil.bytes(0)), full("127.1.0.255"), full("127.1.0.254"), full("127.1.0.253"), full("127.2.0.255"), full("127.2.0.254"), full("127.2.0.253"));
    pending = EndpointsForToken.empty(DatabaseDescriptor.getPartitioner().getToken(ByteBufferUtil.bytes(0)));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Replica(org.apache.cassandra.locator.Replica) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) BeforeClass(org.junit.BeforeClass)

Example 58 with Replica

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

the class ActiveRepairServiceTest method testGetNeighborsTimesTwo.

@Test
public void testGetNeighborsTimesTwo() 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());
    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, null, 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 59 with Replica

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

the class MoveTransientTest method calculateStreamAndFetchRangesMoveForward.

private Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveForward() throws Exception {
    Range<Token> aPrimeRange = new Range<>(oneToken, fourToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, range_11_1, true), new Replica(address01, range_9_11, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    assertContentsIgnoreOrder(result.left);
    assertContentsIgnoreOrder(result.right, fullReplica(address01, threeToken, fourToken));
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) 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 60 with Replica

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

the class MoveTransientTest method calculateStreamAndFetchRangesMoveBackward.

private Pair<RangesAtEndpoint, RangesAtEndpoint> calculateStreamAndFetchRangesMoveBackward() throws Exception {
    Range<Token> aPrimeRange = new Range<>(oneToken, twoToken);
    RangesAtEndpoint updated = RangesAtEndpoint.of(new Replica(address01, aPrimeRange, true), new Replica(address01, range_11_1, true), new Replica(address01, range_9_11, false));
    Pair<RangesAtEndpoint, RangesAtEndpoint> result = RangeRelocator.calculateStreamAndFetchRanges(current, updated);
    // Moving backwards has no impact on any replica. We already fully replicate counter clockwise
    // The transient replica does transiently replicate slightly more, but that is addressed by cleanup
    assertContentsIgnoreOrder(result.left, fullReplica(address01, twoToken, threeToken));
    assertContentsIgnoreOrder(result.right);
    return result;
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) 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)

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