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