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);
}
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());
}
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);
}
}
}
Aggregations