Search in sources :

Example 11 with ReplicaPlan

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)));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Stage(org.apache.cassandra.concurrent.Stage) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) LoggerFactory(org.slf4j.LoggerFactory) ReadCommand(org.apache.cassandra.db.ReadCommand) DuplicateRowChecker(org.apache.cassandra.db.transform.DuplicateRowChecker) Message(org.apache.cassandra.net.Message) Iterables.all(com.google.common.collect.Iterables.all) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ReadRepair(org.apache.cassandra.service.reads.repair.ReadRepair) ReplicaCollection(org.apache.cassandra.locator.ReplicaCollection) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) ReplicaPlans(org.apache.cassandra.locator.ReplicaPlans) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) Keyspace(org.apache.cassandra.db.Keyspace) UnavailableException(org.apache.cassandra.exceptions.UnavailableException) LocalReadRunnable(org.apache.cassandra.service.StorageProxy.LocalReadRunnable) ConsistencyLevel(org.apache.cassandra.db.ConsistencyLevel) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) ReadTimeoutException(org.apache.cassandra.exceptions.ReadTimeoutException) ReadFailureException(org.apache.cassandra.exceptions.ReadFailureException) Tracing(org.apache.cassandra.tracing.Tracing) Collectors(java.util.stream.Collectors) Replica(org.apache.cassandra.locator.Replica) TraceState(org.apache.cassandra.tracing.TraceState) List(java.util.List) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) Preconditions(com.google.common.base.Preconditions) EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) Replica(org.apache.cassandra.locator.Replica)

Example 12 with ReplicaPlan

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);
}
Also used : ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 13 with ReplicaPlan

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);
}
Also used : Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) EmptyPartitionsDiscarder(org.apache.cassandra.db.transform.EmptyPartitionsDiscarder) UnaryOperator(java.util.function.UnaryOperator) ReadCommand(org.apache.cassandra.db.ReadCommand) Message(org.apache.cassandra.net.Message) ReadResponse(org.apache.cassandra.db.ReadResponse) RangeTombstoneMarker(org.apache.cassandra.db.rows.RangeTombstoneMarker) ArrayList(java.util.ArrayList) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Row(org.apache.cassandra.db.rows.Row) ReadRepair(org.apache.cassandra.service.reads.repair.ReadRepair) Endpoints(org.apache.cassandra.locator.Endpoints) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) RepairedDataTracker(org.apache.cassandra.service.reads.repair.RepairedDataTracker) PartitionIterators(org.apache.cassandra.db.partitions.PartitionIterators) FilteredPartitions(org.apache.cassandra.db.transform.FilteredPartitions) Index(org.apache.cassandra.index.Index) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Filter(org.apache.cassandra.db.transform.Filter) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) Collection(java.util.Collection) UnfilteredRowIterators(org.apache.cassandra.db.rows.UnfilteredRowIterators) List(java.util.List) DeletionTime(org.apache.cassandra.db.DeletionTime) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Transformation(org.apache.cassandra.db.transform.Transformation) UnfilteredPartitionIterators(org.apache.cassandra.db.partitions.UnfilteredPartitionIterators) TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) DataLimits(org.apache.cassandra.db.filter.DataLimits) RepairedDataVerifier(org.apache.cassandra.service.reads.repair.RepairedDataVerifier) Joiner(com.google.common.base.Joiner) RepairedDataTracker(org.apache.cassandra.service.reads.repair.RepairedDataTracker) Message(org.apache.cassandra.net.Message)

Example 14 with ReplicaPlan

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()));
}
Also used : EndpointsForToken(org.apache.cassandra.locator.EndpointsForToken) ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) ReplicaLayout(org.apache.cassandra.locator.ReplicaLayout) Test(org.junit.Test)

Aggregations

ReplicaPlan (org.apache.cassandra.locator.ReplicaPlan)14 Keyspace (org.apache.cassandra.db.Keyspace)7 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)6 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)6 IMutation (org.apache.cassandra.db.IMutation)5 Replica (org.apache.cassandra.locator.Replica)5 Token (org.apache.cassandra.dht.Token)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ConsistencyLevel (org.apache.cassandra.db.ConsistencyLevel)3 Mutation (org.apache.cassandra.db.Mutation)3 ReadCommand (org.apache.cassandra.db.ReadCommand)3 UnavailableException (org.apache.cassandra.exceptions.UnavailableException)3 List (java.util.List)2 CounterMutation (org.apache.cassandra.db.CounterMutation)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 PartitionRangeReadCommand (org.apache.cassandra.db.PartitionRangeReadCommand)2 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)2 CasWriteTimeoutException (org.apache.cassandra.exceptions.CasWriteTimeoutException)2