Search in sources :

Example 1 with EndpointState

use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.

the class DynamicEndpointSnitch method getSeverity.

private double getSeverity(InetAddress 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 2 with EndpointState

use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.

the class GossipTest method nodeDownDuringMove.

@Test
public void nodeDownDuringMove() throws Throwable {
    int liveCount = 1;
    try (Cluster cluster = Cluster.build(2 + liveCount).withConfig(config -> config.with(NETWORK).with(GOSSIP)).createWithoutStarting()) {
        int fail = liveCount + 1;
        int late = fail + 1;
        for (int i = 1; i <= liveCount; ++i) cluster.get(i).startup();
        cluster.get(fail).startup();
        Collection<String> expectTokens = cluster.get(fail).callsOnInstance(() -> StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()).stream().map(Object::toString).collect(Collectors.toList())).call();
        InetSocketAddress failAddress = cluster.get(fail).broadcastAddress();
        // wait for NORMAL state
        for (int i = 1; i <= liveCount; ++i) {
            cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
                EndpointState ep;
                InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
                while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("NORMAL")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(10L));
            }).accept(failAddress);
        }
        // set ourselves to MOVING, and wait for it to propagate
        cluster.get(fail).runOnInstance(() -> {
            Token token = Iterables.getFirst(StorageService.instance.getTokenMetadata().getTokens(FBUtilities.getBroadcastAddressAndPort()), null);
            Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS_WITH_PORT, StorageService.instance.valueFactory.moving(token));
        });
        for (int i = 1; i <= liveCount; ++i) {
            cluster.get(i).acceptsOnInstance((InetSocketAddress address) -> {
                EndpointState ep;
                InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
                while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || (ep.getApplicationState(ApplicationState.STATUS_WITH_PORT) == null || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING"))) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
            }).accept(failAddress);
        }
        cluster.get(fail).shutdown(false).get();
        cluster.get(late).startup();
        cluster.get(late).acceptsOnInstance((InetSocketAddress address) -> {
            EndpointState ep;
            InetAddressAndPort endpoint = toCassandraInetAddressAndPort(address);
            while (null == (ep = Gossiper.instance.getEndpointStateForEndpoint(endpoint)) || !ep.getApplicationState(ApplicationState.STATUS_WITH_PORT).value.startsWith("MOVING")) LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100L));
        }).accept(failAddress);
        Collection<String> tokens = cluster.get(late).appliesOnInstance((InetSocketAddress address) -> StorageService.instance.getTokenMetadata().getTokens(toCassandraInetAddressAndPort(address)).stream().map(Object::toString).collect(Collectors.toList())).apply(failAddress);
        Assert.assertEquals(expectTokens, tokens);
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) MethodDelegation(net.bytebuddy.implementation.MethodDelegation) ByteBuddy(net.bytebuddy.ByteBuddy) ElementMatchers.takesArguments(net.bytebuddy.matcher.ElementMatchers.takesArguments) PendingRangeCalculatorService(org.apache.cassandra.service.PendingRangeCalculatorService) Gossiper(org.apache.cassandra.gms.Gossiper) ClusterUtils.runAndWaitForLogs(org.apache.cassandra.distributed.shared.ClusterUtils.runAndWaitForLogs) Token(org.apache.cassandra.dht.Token) StreamResultFuture(org.apache.cassandra.streaming.StreamResultFuture) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) NETWORK(org.apache.cassandra.distributed.api.Feature.NETWORK) ApplicationState(org.apache.cassandra.gms.ApplicationState) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) ElementMatchers.named(net.bytebuddy.matcher.ElementMatchers.named) java.util.concurrent(java.util.concurrent) org.apache.cassandra.distributed.api(org.apache.cassandra.distributed.api) Collection(java.util.Collection) StorageService(org.apache.cassandra.service.StorageService) Test(org.junit.Test) ClassLoadingStrategy(net.bytebuddy.dynamic.loading.ClassLoadingStrategy) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) LockSupport(java.util.concurrent.locks.LockSupport) Futures(com.google.common.util.concurrent.Futures) StreamPlan(org.apache.cassandra.streaming.StreamPlan) Closeable(java.io.Closeable) Cluster(org.apache.cassandra.distributed.Cluster) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) GOSSIP(org.apache.cassandra.distributed.api.Feature.GOSSIP) EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) Cluster(org.apache.cassandra.distributed.Cluster) Token(org.apache.cassandra.dht.Token) ClusterUtils.getLocalToken(org.apache.cassandra.distributed.shared.ClusterUtils.getLocalToken) Test(org.junit.Test)

Example 3 with EndpointState

use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.

the class MigrationCoordinator method shouldPullFromEndpoint.

@VisibleForTesting
protected boolean shouldPullFromEndpoint(InetAddressAndPort endpoint) {
    if (endpoint.equals(FBUtilities.getBroadcastAddressAndPort()))
        return false;
    EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
    if (state == null)
        return false;
    final String releaseVersion = state.getApplicationState(ApplicationState.RELEASE_VERSION).value;
    final String ourMajorVersion = FBUtilities.getReleaseVersionMajor();
    if (!releaseVersion.startsWith(ourMajorVersion)) {
        logger.debug("Not pulling schema from {} because release version in Gossip is not major version {}, it is {}", endpoint, ourMajorVersion, releaseVersion);
        return false;
    }
    if (!MessagingService.instance().versions.knows(endpoint)) {
        logger.debug("Not pulling schema from {} because their messaging version is unknown", endpoint);
        return false;
    }
    if (MessagingService.instance().versions.getRaw(endpoint) != MessagingService.current_version) {
        logger.debug("Not pulling schema from {} because their schema format is incompatible", endpoint);
        return false;
    }
    if (Gossiper.instance.isGossipOnlyMember(endpoint)) {
        logger.debug("Not pulling schema from {} because it's a gossip only member", endpoint);
        return false;
    }
    return true;
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with EndpointState

use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.

the class GossipHelper method changeGossipState.

/**
 * Changes gossip state of the `peer` on `target`
 */
public static void changeGossipState(IInvokableInstance target, IInstance peer, List<VersionedApplicationState> newState) {
    InetSocketAddress addr = peer.broadcastAddress();
    UUID hostId = peer.config().hostId();
    int netVersion = peer.getMessagingVersion();
    target.runOnInstance(() -> {
        InetAddressAndPort endpoint = toCassandraInetAddressAndPort(addr);
        StorageService storageService = StorageService.instance;
        Gossiper.runInGossipStageBlocking(() -> {
            EndpointState state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
            if (state == null) {
                Gossiper.instance.initializeNodeUnsafe(endpoint, hostId, netVersion, 1);
                state = Gossiper.instance.getEndpointStateForEndpoint(endpoint);
                if (state.isAlive() && !Gossiper.instance.isDeadState(state))
                    Gossiper.instance.realMarkAlive(endpoint, state);
            }
            for (VersionedApplicationState value : newState) {
                ApplicationState as = toApplicationState(value);
                VersionedValue vv = toVersionedValue(value);
                state.addApplicationState(as, vv);
                storageService.onChange(endpoint, as, vv);
            }
        });
    });
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) VersionedValue(org.apache.cassandra.gms.VersionedValue) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) DistributedTestSnitch.toCassandraInetAddressAndPort(org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort) InetSocketAddress(java.net.InetSocketAddress) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) VersionedApplicationState(org.apache.cassandra.distributed.shared.VersionedApplicationState) ApplicationState(org.apache.cassandra.gms.ApplicationState) UUID(java.util.UUID) StorageService(org.apache.cassandra.service.StorageService)

Example 5 with EndpointState

use of org.apache.cassandra.gms.EndpointState in project cassandra by apache.

the class StorageProxyTest method shouldHintTest.

private void shouldHintTest(Consumer<Replica> test) throws Exception {
    InetAddressAndPort testEp = InetAddressAndPort.getByName("192.168.1.1");
    Replica replica = full(testEp);
    StorageService.instance.getTokenMetadata().updateHostId(UUID.randomUUID(), testEp);
    EndpointState state = new EndpointState(new HeartBeatState(0, 0));
    Gossiper.runInGossipStageBlocking(() -> Gossiper.instance.markDead(replica.endpoint(), state));
    try {
        test.accept(replica);
    } finally {
        StorageService.instance.getTokenMetadata().removeEndpoint(testEp);
    }
}
Also used : EndpointState(org.apache.cassandra.gms.EndpointState) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) HeartBeatState(org.apache.cassandra.gms.HeartBeatState) Replica(org.apache.cassandra.locator.Replica)

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