use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.
the class RangeStreamer method getAllRangesWithStrictSourcesFor.
/**
* Get a map of all ranges and the source that will be cleaned up once this bootstrapped node is added for the given ranges.
* For each range, the list should only contain a single source. This allows us to consistently migrate data without violating
* consistency.
*
* @throws java.lang.IllegalStateException when there is no source to get data streamed, or more than 1 source found.
*/
private Multimap<Range<Token>, InetAddress> getAllRangesWithStrictSourcesFor(String keyspace, Collection<Range<Token>> desiredRanges) {
assert tokens != null;
AbstractReplicationStrategy strat = Keyspace.open(keyspace).getReplicationStrategy();
// Active ranges
TokenMetadata metadataClone = metadata.cloneOnlyTokenMap();
Multimap<Range<Token>, InetAddress> addressRanges = strat.getRangeAddresses(metadataClone);
// Pending ranges
metadataClone.updateNormalTokens(tokens, address);
Multimap<Range<Token>, InetAddress> pendingRangeAddresses = strat.getRangeAddresses(metadataClone);
// Collects the source that will have its range moved to the new node
Multimap<Range<Token>, InetAddress> rangeSources = ArrayListMultimap.create();
for (Range<Token> desiredRange : desiredRanges) {
for (Map.Entry<Range<Token>, Collection<InetAddress>> preEntry : addressRanges.asMap().entrySet()) {
if (preEntry.getKey().contains(desiredRange)) {
Set<InetAddress> oldEndpoints = Sets.newHashSet(preEntry.getValue());
Set<InetAddress> newEndpoints = Sets.newHashSet(pendingRangeAddresses.get(desiredRange));
// So we need to be careful to only be strict when endpoints == RF
if (oldEndpoints.size() == strat.getReplicationFactor()) {
oldEndpoints.removeAll(newEndpoints);
assert oldEndpoints.size() == 1 : "Expected 1 endpoint but found " + oldEndpoints.size();
}
rangeSources.put(desiredRange, oldEndpoints.iterator().next());
}
}
// Validate
Collection<InetAddress> addressList = rangeSources.get(desiredRange);
if (addressList == null || addressList.isEmpty())
throw new IllegalStateException("No sources found for " + desiredRange);
if (addressList.size() > 1)
throw new IllegalStateException("Multiple endpoints found for " + desiredRange);
InetAddress sourceIp = addressList.iterator().next();
EndpointState sourceState = Gossiper.instance.getEndpointStateForEndpoint(sourceIp);
if (Gossiper.instance.isEnabled() && (sourceState == null || !sourceState.isAlive()))
throw new RuntimeException("A node required to move the data consistently is down (" + sourceIp + "). " + "If you wish to move the data from a potentially inconsistent replica, restart the node with -Dcassandra.consistent.rangemovement=false");
}
return rangeSources;
}
use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.
the class DynamicEndpointSnitch method getSeverity.
private double getSeverity(InetAddressAndPort endpoint) {
EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
if (state == null)
return 0.0;
VersionedValue event = state.getApplicationState(ApplicationState.SEVERITY);
if (event == null)
return 0.0;
return Double.parseDouble(event.value);
}
use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.
the class Debug method debugGossip.
private Consumer<Action> debugGossip(Cluster cluster) {
return ignore -> {
cluster.forEach(i -> i.unsafeRunOnThisThread(() -> {
for (InetAddressAndPort ep : Gossiper.instance.getLiveMembers()) {
EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(ep);
logger.warn("Gossip {}: {} {}", ep, epState.isAlive(), epState.states().stream().map(e -> e.getKey().toString() + "=(" + e.getValue().value + ',' + e.getValue().version + ')').collect(Collectors.joining(", ", "[", "]")));
}
}));
};
}
use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.
the class Utils method currentToken.
static Token currentToken() {
EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(getBroadcastAddressAndPort());
VersionedValue value = epState.getApplicationState(ApplicationState.TOKENS);
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(value.toBytes()))) {
return TokenSerializer.deserialize(getPartitioner(), in).iterator().next();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations