use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class MoveTransientTest method testResubtract.
@Test
public void testResubtract() {
Token oneToken = new RandomPartitioner.BigIntegerToken("0001");
Token tenToken = new RandomPartitioner.BigIntegerToken("0010");
Token fiveToken = new RandomPartitioner.BigIntegerToken("0005");
Range<Token> range_1_10 = new Range<>(oneToken, tenToken);
Range<Token> range_1_5 = new Range<>(oneToken, tenToken);
Range<Token> range_5_10 = new Range<>(fiveToken, tenToken);
RangesAtEndpoint singleRange = RangesAtEndpoint.of(new Replica(address01, range_1_10, true));
RangesAtEndpoint splitRanges = RangesAtEndpoint.of(new Replica(address01, range_1_5, true), new Replica(address01, range_5_10, true));
// forward
Pair<RangesAtEndpoint, RangesAtEndpoint> calculated = RangeRelocator.calculateStreamAndFetchRanges(singleRange, splitRanges);
assertTrue(calculated.left.toString(), calculated.left.isEmpty());
assertTrue(calculated.right.toString(), calculated.right.isEmpty());
// backward
calculated = RangeRelocator.calculateStreamAndFetchRanges(splitRanges, singleRange);
assertTrue(calculated.left.toString(), calculated.left.isEmpty());
assertTrue(calculated.right.toString(), calculated.right.isEmpty());
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class BlockingReadRepairTest 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(replica1, repair1);
// check that the correct initial mutations are sent out
InstrumentedReadRepairHandler handler = createRepairHandler(repairs, repairPlan(replicas, EndpointsForRange.of(replica1, replica2)));
handler.sendInitialRepairs();
Assert.assertEquals(1, handler.mutationsSent.size());
Assert.assertTrue(handler.mutationsSent.containsKey(target1));
// 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));
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class StorageServiceTest method setUp.
@Before
public void setUp() {
DatabaseDescriptor.daemonInitialization();
DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
IEndpointSnitch snitch = new AbstractEndpointSnitch() {
public int compareEndpoints(InetAddressAndPort target, Replica r1, Replica r2) {
return 0;
}
public String getRack(InetAddressAndPort endpoint) {
return "R1";
}
public String getDatacenter(InetAddressAndPort endpoint) {
return "DC1";
}
};
DatabaseDescriptor.setEndpointSnitch(snitch);
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class WriteResponseHandlerTransientTest method setupClass.
@BeforeClass
public static void setupClass() throws Throwable {
SchemaLoader.loadSchema();
DatabaseDescriptor.setTransientReplicationEnabledUnsafe(true);
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.1"));
metadata.updateHostId(UUID.randomUUID(), InetAddressAndPort.getByName("127.2.0.1"));
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 DC1;
else
return DC2;
}
public <C extends ReplicaCollection<? extends C>> C sortedByProximity(InetAddressAndPort address, C unsortedAddress) {
return unsortedAddress;
}
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("ks", KeyspaceParams.nts(DC1, "3/1", DC2, "3/1"), SchemaLoader.standardCFMD("ks", "tbl"));
ks = Keyspace.open("ks");
cfs = ks.getColumnFamilyStore("tbl");
dummy = DatabaseDescriptor.getPartitioner().getToken(ByteBufferUtil.bytes(0));
}
use of org.apache.cassandra.locator.Replica in project cassandra by apache.
the class ReadRepairTest method noAdditionalMutationRequired.
/**
* If we've received enough acks, we shouldn't send any additional mutations
*/
@Test
public void noAdditionalMutationRequired() throws Exception {
Map<Replica, Mutation> repairs = new HashMap<>();
repairs.put(target1, mutation(cell2));
repairs.put(target2, mutation(cell1));
EndpointsForRange replicas = EndpointsForRange.of(target1, target2);
InstrumentedReadRepairHandler handler = createRepairHandler(repairs, replicas, targets);
handler.sendInitialRepairs();
handler.ack(target1.endpoint());
handler.ack(target2.endpoint());
// both replicas have acked, we shouldn't send anything else out
handler.mutationsSent.clear();
handler.maybeSendAdditionalWrites(0, TimeUnit.NANOSECONDS);
Assert.assertTrue(handler.mutationsSent.isEmpty());
}
Aggregations