Search in sources :

Example 41 with Replica

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

the class ServerTestUtils method daemonInitialization.

/**
 * Call DatabaseDescriptor.daemonInitialization ensuring that the snitch used returns fixed values for the tests
 */
public static void daemonInitialization() {
    DatabaseDescriptor.daemonInitialization();
    // Register an EndpointSnitch which returns fixed values for test.
    DatabaseDescriptor.setEndpointSnitch(new AbstractEndpointSnitch() {

        @Override
        public String getRack(InetAddressAndPort endpoint) {
            return RACK1;
        }

        @Override
        public String getDatacenter(InetAddressAndPort endpoint) {
            if (remoteAddrs.contains(endpoint))
                return DATA_CENTER_REMOTE;
            return DATA_CENTER;
        }

        @Override
        public int compareEndpoints(InetAddressAndPort target, Replica a1, Replica a2) {
            return 0;
        }
    });
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) AbstractEndpointSnitch(org.apache.cassandra.locator.AbstractEndpointSnitch) Replica(org.apache.cassandra.locator.Replica)

Example 42 with Replica

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

the class RangeFetchMapCalculator method addEndpoints.

/**
 * Create edges with infinite capacity b/w range vertex and all its source endpoints which clear the filters
 * @param capacityGraph The Capacity graph on which changes are made
 * @param rangeVertex The range for which we need to add all its source endpoints
 * @param localDCCheck Should add source endpoints from local DC only
 * @return If we were able to add atleast one source for this range after applying filters to endpoints
 */
private boolean addEndpoints(MutableCapacityGraph<Vertex, Integer> capacityGraph, RangeVertex rangeVertex, boolean localDCCheck) {
    boolean sourceFound = false;
    Replicas.temporaryAssertFull(rangesWithSources.get(rangeVertex.getRange()));
    for (Replica replica : rangesWithSources.get(rangeVertex.getRange())) {
        if (passFilters(replica, localDCCheck)) {
            sourceFound = true;
            // if we pass filters, it means that we don't filter away localhost and we can count it as a source:
            if (replica.isSelf())
                // but don't add localhost to the graph to avoid streaming locally
                continue;
            final Vertex endpointVertex = new EndpointVertex(replica.endpoint());
            capacityGraph.insertVertex(rangeVertex);
            capacityGraph.insertVertex(endpointVertex);
            capacityGraph.addEdge(rangeVertex, endpointVertex, Integer.MAX_VALUE);
        }
    }
    return sourceFound;
}
Also used : Replica(org.apache.cassandra.locator.Replica)

Example 43 with Replica

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

the class RangeStreamer method addRanges.

/**
 * Add ranges to be streamed for given keyspace.
 *
 * @param keyspaceName keyspace name
 * @param replicas ranges to be streamed
 */
public void addRanges(String keyspaceName, ReplicaCollection<?> replicas) {
    Keyspace keyspace = Keyspace.open(keyspaceName);
    AbstractReplicationStrategy strat = keyspace.getReplicationStrategy();
    if (strat instanceof LocalStrategy) {
        logger.info("Not adding ranges for Local Strategy keyspace={}", keyspaceName);
        return;
    }
    boolean useStrictSource = useStrictSourcesForRanges(strat);
    EndpointsByReplica fetchMap = calculateRangesToFetchWithPreferredEndpoints(replicas, keyspace, useStrictSource);
    for (Map.Entry<Replica, Replica> entry : fetchMap.flattenEntries()) logger.info("{}: range {} exists on {} for keyspace {}", description, entry.getKey(), entry.getValue(), keyspaceName);
    Multimap<InetAddressAndPort, FetchReplica> workMap;
    // transient replicas.
    if (useStrictSource || strat == null || strat.getReplicationFactor().allReplicas == 1 || strat.getReplicationFactor().hasTransientReplicas()) {
        workMap = convertPreferredEndpointsToWorkMap(fetchMap);
    } else {
        workMap = getOptimizedWorkMap(fetchMap, sourceFilters, keyspaceName);
    }
    if (toFetch.put(keyspaceName, workMap) != null)
        throw new IllegalArgumentException("Keyspace is already added to fetch map");
    if (logger.isTraceEnabled()) {
        for (Map.Entry<InetAddressAndPort, Collection<FetchReplica>> entry : workMap.asMap().entrySet()) {
            for (FetchReplica r : entry.getValue()) logger.trace("{}: range source {} local range {} for keyspace {}", description, r.remote, r.local, keyspaceName);
        }
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) LocalStrategy(org.apache.cassandra.locator.LocalStrategy) Replica.fullReplica(org.apache.cassandra.locator.Replica.fullReplica) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Keyspace(org.apache.cassandra.db.Keyspace) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ReplicaCollection(org.apache.cassandra.locator.ReplicaCollection) Collection(java.util.Collection) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) Map(java.util.Map) HashMap(java.util.HashMap)

Example 44 with Replica

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

the class RangeCommandIterator method query.

/**
 * Queries the provided sub-range.
 *
 * @param replicaPlan the subRange to query.
 * @param isFirst in the case where multiple queries are sent in parallel, whether that's the first query on
 * that batch or not. The reason it matters is that whe paging queries, the command (more specifically the
 * {@code DataLimits}) may have "state" information and that state may only be valid for the first query (in
 * that it's the query that "continues" whatever we're previously queried).
 */
private SingleRangeResponse query(ReplicaPlan.ForRangeRead replicaPlan, boolean isFirst) {
    PartitionRangeReadCommand rangeCommand = command.forSubRange(replicaPlan.range(), isFirst);
    // If enabled, request repaired data tracking info from full replicas, but
    // only if there are multiple full replicas to compare results from.
    boolean trackRepairedStatus = DatabaseDescriptor.getRepairedDataTrackingForRangeReadsEnabled() && replicaPlan.contacts().filter(Replica::isFull).size() > 1;
    ReplicaPlan.SharedForRangeRead sharedReplicaPlan = ReplicaPlan.shared(replicaPlan);
    ReadRepair<EndpointsForRange, ReplicaPlan.ForRangeRead> readRepair = ReadRepair.create(command, sharedReplicaPlan, queryStartNanoTime);
    DataResolver<EndpointsForRange, ReplicaPlan.ForRangeRead> resolver = new DataResolver<>(rangeCommand, sharedReplicaPlan, readRepair, queryStartNanoTime, trackRepairedStatus);
    ReadCallback<EndpointsForRange, ReplicaPlan.ForRangeRead> handler = new ReadCallback<>(resolver, rangeCommand, sharedReplicaPlan, queryStartNanoTime);
    if (replicaPlan.contacts().size() == 1 && replicaPlan.contacts().get(0).isSelf()) {
        Stage.READ.execute(new StorageProxy.LocalReadRunnable(rangeCommand, handler, trackRepairedStatus));
    } else {
        for (Replica replica : replicaPlan.contacts()) {
            Tracing.trace("Enqueuing request to {}", replica);
            ReadCommand command = replica.isFull() ? rangeCommand : rangeCommand.copyAsTransientQuery(replica);
            Message<ReadCommand> message = command.createMessage(trackRepairedStatus && replica.isFull());
            MessagingService.instance().sendWithCallback(message, replica.endpoint(), handler);
        }
    }
    return new SingleRangeResponse(resolver, handler, readRepair);
}
Also used : ReplicaPlan(org.apache.cassandra.locator.ReplicaPlan) PartitionRangeReadCommand(org.apache.cassandra.db.PartitionRangeReadCommand) StorageProxy(org.apache.cassandra.service.StorageProxy) ReadCommand(org.apache.cassandra.db.ReadCommand) PartitionRangeReadCommand(org.apache.cassandra.db.PartitionRangeReadCommand) Replica(org.apache.cassandra.locator.Replica) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) ReadCallback(org.apache.cassandra.service.reads.ReadCallback) DataResolver(org.apache.cassandra.service.reads.DataResolver)

Example 45 with Replica

use of org.apache.cassandra.locator.Replica 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)

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