Search in sources :

Example 16 with EndpointsForToken

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

the class HintsService method writeForAllReplicas.

/**
 * Write a hint for all replicas. Used to re-dispatch hints whose destination is either missing or no longer correct.
 */
void writeForAllReplicas(Hint hint) {
    String keyspaceName = hint.mutation.getKeyspaceName();
    Token token = hint.mutation.key().getToken();
    EndpointsForToken replicas = ReplicaLayout.forTokenWriteLiveAndDown(Keyspace.open(keyspaceName), token).all();
    // judicious use of streams: eagerly materializing probably cheaper
    // than performing filters / translations 2x extra via Iterables.filter/transform
    List<UUID> hostIds = replicas.stream().filter(replica -> StorageProxy.shouldHint(replica, false)).map(replica -> StorageService.instance.getHostIdForEndpoint(replica.endpoint())).collect(Collectors.toList());
    write(hostIds, hint);
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) ScheduledExecutors(org.apache.cassandra.concurrent.ScheduledExecutors) StorageMetrics(org.apache.cassandra.metrics.StorageMetrics) ScheduledFuture(java.util.concurrent.ScheduledFuture) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Iterables.transform(com.google.common.collect.Iterables.transform) File(org.apache.cassandra.io.util.File) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Supplier(java.util.function.Supplier) Token(org.apache.cassandra.dht.Token) Clock(org.apache.cassandra.utils.Clock) Map(java.util.Map) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Keyspace(org.apache.cassandra.db.Keyspace) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) StorageService(org.apache.cassandra.service.StorageService) UUID(java.util.UUID) UnknownHostException(java.net.UnknownHostException) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IFailureDetector(org.apache.cassandra.gms.IFailureDetector) UncheckedInterruptedException(org.apache.cassandra.utils.concurrent.UncheckedInterruptedException) List(java.util.List) ParameterizedClass(org.apache.cassandra.config.ParameterizedClass) StorageProxy(org.apache.cassandra.service.StorageProxy) Future(org.apache.cassandra.utils.concurrent.Future) MBeanWrapper(org.apache.cassandra.utils.MBeanWrapper) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ReplicaLayout(org.apache.cassandra.locator.ReplicaLayout) Iterables.filter(com.google.common.collect.Iterables.filter) FailureDetector(org.apache.cassandra.gms.FailureDetector) Collections(java.util.Collections) HintedHandoffMetrics(org.apache.cassandra.metrics.HintedHandoffMetrics) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Token(org.apache.cassandra.dht.Token) UUID(java.util.UUID)

Example 17 with EndpointsForToken

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

the class WriteResponseHandlerTransientTest method checkPendingReplicasAreNotFiltered.

@Test
public void checkPendingReplicasAreNotFiltered() {
    EndpointsForToken natural = EndpointsForToken.of(dummy.getToken(), full(EP1), full(EP2), trans(EP3), full(EP5));
    EndpointsForToken pending = EndpointsForToken.of(dummy.getToken(), full(EP4), trans(EP6));
    ReplicaLayout.ForTokenWrite layout = new ReplicaLayout.ForTokenWrite(ks.getReplicationStrategy(), natural, pending);
    ReplicaPlan.ForTokenWrite replicaPlan = ReplicaPlans.forWrite(ks, ConsistencyLevel.QUORUM, layout, layout, ReplicaPlans.writeAll);
    Assert.assertTrue(Iterables.elementsEqual(EndpointsForRange.of(full(EP4), trans(EP6)), replicaPlan.pending()));
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) ReplicaLayout(org.apache.cassandra.locator.ReplicaLayout) Test(org.junit.Test)

Example 18 with EndpointsForToken

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

the class WriteResponseHandlerTransientTest method checkSpeculationContext.

@Test
public void checkSpeculationContext() {
    EndpointsForToken all = replicas(full(EP1), full(EP2), trans(EP3), full(EP4), full(EP5), trans(EP6));
    // in happy path, transient replica should be classified as a backup
    assertSpeculationReplicas(expected(all, replicas(full(EP1), full(EP2), full(EP4), full(EP5))), all, dead());
    // full replicas must always be in the contact list, and will occur first
    assertSpeculationReplicas(expected(replicas(full(EP1), trans(EP3), full(EP4), trans(EP6)), replicas(full(EP1), full(EP2), full(EP4), full(EP5), trans(EP3), trans(EP6))), all, dead(EP2, EP5));
    // only one transient used as backup
    assertSpeculationReplicas(expected(replicas(full(EP1), trans(EP3), full(EP4), full(EP5), trans(EP6)), replicas(full(EP1), full(EP2), full(EP4), full(EP5), trans(EP3))), all, dead(EP2));
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Test(org.junit.Test)

Example 19 with EndpointsForToken

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

the class DigestResolverTest method digestMismatch.

@Test
public void digestMismatch() {
    SinglePartitionReadCommand command = SinglePartitionReadCommand.fullPartitionRead(cfm, nowInSec, dk);
    EndpointsForToken targetReplicas = EndpointsForToken.of(dk.getToken(), full(EP1), full(EP2));
    DigestResolver resolver = new DigestResolver(command, plan(ConsistencyLevel.QUORUM, targetReplicas), 0);
    PartitionUpdate response1 = update(row(1000, 4, 4), row(1000, 5, 5)).build();
    PartitionUpdate response2 = update(row(2000, 4, 5)).build();
    Assert.assertFalse(resolver.isDataPresent());
    resolver.preprocess(response(command, EP2, iter(response1), true));
    resolver.preprocess(response(command, EP1, iter(response2), false));
    Assert.assertTrue(resolver.isDataPresent());
    Assert.assertFalse(resolver.responsesMatch());
    Assert.assertFalse(resolver.hasTransientResponse());
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Example 20 with EndpointsForToken

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

the class DigestResolverTest method noRepairNeeded.

@Test
public void noRepairNeeded() {
    SinglePartitionReadCommand command = SinglePartitionReadCommand.fullPartitionRead(cfm, nowInSec, dk);
    EndpointsForToken targetReplicas = EndpointsForToken.of(dk.getToken(), full(EP1), full(EP2));
    DigestResolver resolver = new DigestResolver(command, plan(ConsistencyLevel.QUORUM, targetReplicas), 0);
    PartitionUpdate response = update(row(1000, 4, 4), row(1000, 5, 5)).build();
    Assert.assertFalse(resolver.isDataPresent());
    resolver.preprocess(response(command, EP2, iter(response), true));
    resolver.preprocess(response(command, EP1, iter(response), false));
    Assert.assertTrue(resolver.isDataPresent());
    Assert.assertTrue(resolver.responsesMatch());
    assertPartitionsEqual(filter(iter(response)), resolver.getData());
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) Test(org.junit.Test)

Aggregations

EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)21 Test (org.junit.Test)9 SinglePartitionReadCommand (org.apache.cassandra.db.SinglePartitionReadCommand)8 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)8 Token (org.apache.cassandra.dht.Token)8 Replica (org.apache.cassandra.locator.Replica)6 ReplicaPlan (org.apache.cassandra.locator.ReplicaPlan)5 Keyspace (org.apache.cassandra.db.Keyspace)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 ReplicaLayout (org.apache.cassandra.locator.ReplicaLayout)4 UncheckedInterruptedException (org.apache.cassandra.utils.concurrent.UncheckedInterruptedException)4 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)3 IMutation (org.apache.cassandra.db.IMutation)3 Mutation (org.apache.cassandra.db.Mutation)3 ReadFailureException (org.apache.cassandra.exceptions.ReadFailureException)3