Search in sources :

Example 6 with EndpointsByReplica

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

the class BootstrapTransientTest method testRangeStreamerRangesToFetch.

@Test
public void testRangeStreamerRangesToFetch() throws Exception {
    EndpointsByReplica expectedResult = new EndpointsByReplica(ImmutableMap.of(transientReplica(address05, range10_20), endpoints(transientReplica(address02, range10_20)), fullReplica(address05, range20_30), endpoints(transientReplica(address03, range20_30), fullReplica(address04, range20_30)), fullReplica(address05, range30_40), endpoints(transientReplica(address04, range30_10), fullReplica(address02, range30_10))));
    invokeCalculateRangesToFetchWithPreferredEndpoints(toFetch, constructTMDs(), expectedResult);
}
Also used : EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Test(org.junit.Test)

Example 7 with EndpointsByReplica

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

the class StorageServiceTest method testGetChangedReplicasForLeaving.

@Test
public void testGetChangedReplicasForLeaving() throws Exception {
    TokenMetadata tmd = new TokenMetadata();
    tmd.updateNormalToken(threeToken, aAddress);
    tmd.updateNormalToken(sixToken, bAddress);
    tmd.updateNormalToken(nineToken, cAddress);
    tmd.updateNormalToken(elevenToken, dAddress);
    tmd.updateNormalToken(oneToken, eAddress);
    tmd.addLeavingEndpoint(aAddress);
    AbstractReplicationStrategy strat = simpleStrategy(tmd);
    EndpointsByReplica result = StorageService.getChangedReplicasForLeaving("StorageServiceTest", aAddress, tmd, strat);
    System.out.println(result);
    EndpointsByReplica.Builder expectedResult = new EndpointsByReplica.Builder();
    expectedResult.put(new Replica(aAddress, aRange, true), new Replica(cAddress, new Range<>(oneToken, sixToken), true));
    expectedResult.put(new Replica(aAddress, aRange, true), new Replica(dAddress, new Range<>(oneToken, sixToken), false));
    expectedResult.put(new Replica(aAddress, eRange, true), new Replica(bAddress, eRange, true));
    expectedResult.put(new Replica(aAddress, eRange, true), new Replica(cAddress, eRange, false));
    expectedResult.put(new Replica(aAddress, dRange, false), new Replica(bAddress, dRange, false));
    assertMultimapEqualsIgnoreOrder(result, expectedResult.build());
}
Also used : AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Range(org.apache.cassandra.dht.Range) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) Test(org.junit.Test)

Example 8 with EndpointsByReplica

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

EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)8 Replica (org.apache.cassandra.locator.Replica)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)5 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)4 Collection (java.util.Collection)3 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)3 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)3 Test (org.junit.Test)3 Iterables (com.google.common.collect.Iterables)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Keyspace (org.apache.cassandra.db.Keyspace)2 SystemKeyspace (org.apache.cassandra.db.SystemKeyspace)2 Range (org.apache.cassandra.dht.Range)2 EndpointsByRange (org.apache.cassandra.locator.EndpointsByRange)2 IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)2 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)2