use of org.apache.cassandra.locator.ReplicaPlan in project cassandra by apache.
the class AbstractReadExecutor method executeAsync.
/**
* send the initial set of requests
*/
public void executeAsync() {
EndpointsForToken selected = replicaPlan().contacts();
EndpointsForToken fullDataRequests = selected.filter(Replica::isFull, initialDataRequestCount);
makeFullDataRequests(fullDataRequests);
makeTransientDataRequests(selected.filterLazily(Replica::isTransient));
makeDigestRequests(selected.filterLazily(r -> r.isFull() && !fullDataRequests.contains(r)));
}
use of org.apache.cassandra.locator.ReplicaPlan in project cassandra by apache.
the class AbstractReadExecutor method getReadExecutor.
/**
* @return an executor appropriate for the configured speculative read policy
*/
public static AbstractReadExecutor getReadExecutor(SinglePartitionReadCommand command, ConsistencyLevel consistencyLevel, long queryStartNanoTime) throws UnavailableException {
Keyspace keyspace = Keyspace.open(command.metadata().keyspace);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(command.metadata().id);
SpeculativeRetryPolicy retry = cfs.metadata().params.speculativeRetry;
ReplicaPlan.ForTokenRead replicaPlan = ReplicaPlans.forRead(keyspace, command.partitionKey().getToken(), consistencyLevel, retry);
// 11980: Disable speculative retry if using EACH_QUORUM in order to prevent miscounting DC responses
if (retry.equals(NeverSpeculativeRetryPolicy.INSTANCE) || consistencyLevel == ConsistencyLevel.EACH_QUORUM)
return new NeverSpeculatingReadExecutor(cfs, command, replicaPlan, queryStartNanoTime, false);
// Handle this separately so it can record failed attempts to speculate due to lack of replicas
if (replicaPlan.contacts().size() == replicaPlan.candidates().size()) {
boolean recordFailedSpeculation = consistencyLevel != ConsistencyLevel.ALL;
return new NeverSpeculatingReadExecutor(cfs, command, replicaPlan, queryStartNanoTime, recordFailedSpeculation);
}
if (retry.equals(AlwaysSpeculativeRetryPolicy.INSTANCE))
return new AlwaysSpeculatingReadExecutor(cfs, command, replicaPlan, queryStartNanoTime);
else
// PERCENTILE or CUSTOM.
return new SpeculatingReadExecutor(cfs, command, replicaPlan, queryStartNanoTime);
}
use of org.apache.cassandra.locator.ReplicaPlan in project cassandra by apache.
the class DataResolver method resolve.
public PartitionIterator resolve() {
// We could get more responses while this method runs, which is ok (we're happy to ignore any response not here
// at the beginning of this method), so grab the response count once and use that through the method.
Collection<Message<ReadResponse>> messages = responses.snapshot();
assert !any(messages, msg -> msg.payload.isDigestResponse());
E replicas = replicaPlan().candidates().select(transform(messages, Message::from), false);
// If requested, inspect each response for a digest of the replica's repaired data set
RepairedDataTracker repairedDataTracker = trackRepairedStatus ? new RepairedDataTracker(getRepairedDataVerifier(command)) : null;
if (repairedDataTracker != null) {
messages.forEach(msg -> {
if (msg.payload.mayIncludeRepairedDigest() && replicas.byEndpoint().get(msg.from()).isFull()) {
repairedDataTracker.recordDigest(msg.from(), msg.payload.repairedDataDigest(), msg.payload.isRepairedDigestConclusive());
}
});
}
if (!needsReplicaFilteringProtection()) {
ResolveContext context = new ResolveContext(replicas);
return resolveWithReadRepair(context, i -> shortReadProtectedResponse(i, context), UnaryOperator.identity(), repairedDataTracker);
}
return resolveWithReplicaFilteringProtection(replicas, repairedDataTracker);
}
use of org.apache.cassandra.locator.ReplicaPlan 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()));
}
Aggregations