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