Search in sources :

Example 1 with LocalStrategy

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

Aggregations

Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Keyspace (org.apache.cassandra.db.Keyspace)1 SystemKeyspace (org.apache.cassandra.db.SystemKeyspace)1 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)1 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 LocalStrategy (org.apache.cassandra.locator.LocalStrategy)1 Replica (org.apache.cassandra.locator.Replica)1 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)1 ReplicaCollection (org.apache.cassandra.locator.ReplicaCollection)1