Search in sources :

Example 61 with Replica

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());
}
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) Test(org.junit.Test)

Example 62 with Replica

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

Example 63 with Replica

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

Example 64 with Replica

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));
}
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 65 with Replica

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());
}
Also used : 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)

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