Search in sources :

Example 6 with EndpointState

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;
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) EndpointState(org.apache.cassandra.gms.EndpointState) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) InetAddress(java.net.InetAddress)

Example 7 with EndpointState

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);
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue)

Example 8 with EndpointState

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(", ", "[", "]")));
            }
        }));
    };
}
Also used : Level(org.apache.cassandra.simulator.Debug.Level) EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) LoggerFactory(org.slf4j.LoggerFactory) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) Gossiper(org.apache.cassandra.gms.Gossiper) ActionListener.runAfter(org.apache.cassandra.simulator.ActionListener.runAfter) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) ActionListener.recursive(org.apache.cassandra.simulator.ActionListener.recursive) Int32Type(org.apache.cassandra.db.marshal.Int32Type) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Map(java.util.Map) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) INFO(org.apache.cassandra.simulator.Action.Modifier.INFO) SimulatedTime(org.apache.cassandra.simulator.systems.SimulatedTime) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Nullable(javax.annotation.Nullable) Keyspace(org.apache.cassandra.db.Keyspace) Logger(org.slf4j.Logger) FBUtilities(org.apache.cassandra.utils.FBUtilities) EnumMap(java.util.EnumMap) Predicate(java.util.function.Predicate) BufferDecoratedKey(org.apache.cassandra.db.BufferDecoratedKey) TriFunction(org.apache.cassandra.distributed.api.IIsolatedExecutor.TriFunction) Ballots.paxosDebugInfo(org.apache.cassandra.simulator.paxos.Ballots.paxosDebugInfo) StorageService(org.apache.cassandra.service.StorageService) WAKEUP(org.apache.cassandra.simulator.Action.Modifier.WAKEUP) EventType(org.apache.cassandra.simulator.Debug.EventType) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) LOG(org.apache.cassandra.simulator.Debug.Info.LOG) TableMetadata(org.apache.cassandra.schema.TableMetadata) Function.identity(java.util.function.Function.identity) ActionListener.runAfterAndTransitivelyAfter(org.apache.cassandra.simulator.ActionListener.runAfterAndTransitivelyAfter) Cluster(org.apache.cassandra.distributed.Cluster) ReplicaLayout(org.apache.cassandra.locator.ReplicaLayout) EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort)

Example 9 with EndpointState

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);
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

EndpointState (org.apache.cassandra.gms.EndpointState)9 VersionedValue (org.apache.cassandra.gms.VersionedValue)4 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)4 StorageService (org.apache.cassandra.service.StorageService)3 InetSocketAddress (java.net.InetSocketAddress)2 Collectors (java.util.stream.Collectors)2 Cluster (org.apache.cassandra.distributed.Cluster)2 DistributedTestSnitch.toCassandraInetAddressAndPort (org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort)2 ApplicationState (org.apache.cassandra.gms.ApplicationState)2 Gossiper (org.apache.cassandra.gms.Gossiper)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Iterables (com.google.common.collect.Iterables)1 Futures (com.google.common.util.concurrent.Futures)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 ByteBuffer (java.nio.ByteBuffer)1