use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class TokenRange method create.
public static TokenRange create(Token.TokenFactory tokenFactory, Range<Token> range, List<InetAddressAndPort> endpoints, boolean withPorts) {
List<EndpointDetails> details = new ArrayList<>(endpoints.size());
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
for (InetAddressAndPort ep : endpoints) details.add(new EndpointDetails(ep, StorageService.instance.getNativeaddress(ep, withPorts), snitch.getDatacenter(ep), snitch.getRack(ep)));
return new TokenRange(tokenFactory, range, details);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class BatchlogManagerTest method setUp.
@Before
public void setUp() throws Exception {
TokenMetadata metadata = StorageService.instance.getTokenMetadata();
InetAddressAndPort localhost = InetAddressAndPort.getByName("127.0.0.1");
metadata.updateNormalToken(Util.token("A"), localhost);
metadata.updateHostId(UUIDGen.getTimeUUID(), localhost);
Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.BATCHES).truncateBlocking();
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class RangeStreamer method useStrictSourcesForRanges.
/**
* @param strat AbstractReplicationStrategy of keyspace to check
* @return true when the node is bootstrapping, useStrictConsistency is true and # of nodes in the cluster is more than # of replica
*/
private boolean useStrictSourcesForRanges(AbstractReplicationStrategy strat) {
boolean res = useStrictConsistency && tokens != null;
if (res) {
int nodes = 0;
if (strat instanceof NetworkTopologyStrategy) {
ImmutableMultimap<String, InetAddressAndPort> dc2Nodes = metadata.getDC2AllEndpoints(snitch);
NetworkTopologyStrategy ntps = (NetworkTopologyStrategy) strat;
for (String dc : dc2Nodes.keySet()) nodes += ntps.getReplicationFactor(dc).allReplicas > 0 ? dc2Nodes.get(dc).size() : 0;
} else
nodes = metadata.getSizeOfAllEndpoints();
res = nodes > strat.getReplicationFactor().allReplicas;
}
return res;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class RangeStreamer method getOptimizedWorkMap.
/**
* Optimized version that also outputs the final work map
*/
private static Multimap<InetAddressAndPort, FetchReplica> getOptimizedWorkMap(EndpointsByReplica rangesWithSources, Collection<SourceFilter> sourceFilters, String keyspace) {
// For now we just aren't going to use the optimized range fetch map with transient replication to shrink
// the surface area to test and introduce bugs.
// In the future it's possible we could run it twice once for full ranges with only full replicas
// and once with transient ranges and all replicas. Then merge the result.
EndpointsByRange.Builder unwrapped = new EndpointsByRange.Builder();
for (Map.Entry<Replica, Replica> entry : rangesWithSources.flattenEntries()) {
Replicas.temporaryAssertFull(entry.getValue());
unwrapped.put(entry.getKey().range(), entry.getValue());
}
EndpointsByRange unwrappedView = unwrapped.build();
RangeFetchMapCalculator calculator = new RangeFetchMapCalculator(unwrappedView, sourceFilters, keyspace);
Multimap<InetAddressAndPort, Range<Token>> rangeFetchMapMap = calculator.getRangeFetchMap();
logger.info("Output from RangeFetchMapCalculator for keyspace {}", keyspace);
validateRangeFetchMap(unwrappedView, rangeFetchMapMap, keyspace);
// Need to rewrap as Replicas
Multimap<InetAddressAndPort, FetchReplica> wrapped = HashMultimap.create();
for (Map.Entry<InetAddressAndPort, Range<Token>> entry : rangeFetchMapMap.entries()) {
Replica toFetch = null;
for (Replica r : rangesWithSources.keySet()) {
if (r.range().equals(entry.getValue())) {
if (toFetch != null)
throw new AssertionError(String.format("There shouldn't be multiple replicas for range %s, replica %s and %s here", r.range(), r, toFetch));
toFetch = r;
}
}
if (toFetch == null)
throw new AssertionError("Shouldn't be possible for the Replica we fetch to be null here");
// Committing the cardinal sin of synthesizing a Replica, but it's ok because we assert earlier all of them
// are full and optimized range fetch map doesn't support transient replication yet.
wrapped.put(entry.getKey(), new FetchReplica(toFetch, fullReplica(entry.getKey(), entry.getValue())));
}
return wrapped;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class RangeStreamer method convertPreferredEndpointsToWorkMap.
/**
* The preferred endpoint list is the wrong format because it is keyed by Replica (this node) rather than the source
* endpoint we will fetch from which streaming wants.
*/
public static Multimap<InetAddressAndPort, FetchReplica> convertPreferredEndpointsToWorkMap(EndpointsByReplica preferredEndpoints) {
Multimap<InetAddressAndPort, FetchReplica> workMap = HashMultimap.create();
for (Map.Entry<Replica, EndpointsForRange> e : preferredEndpoints.entrySet()) {
for (Replica source : e.getValue()) {
assert (e.getKey()).isSelf();
assert !source.isSelf();
workMap.put(source.endpoint(), new FetchReplica(e.getKey(), source));
}
}
logger.debug("Work map {}", workMap);
return workMap;
}
Aggregations