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