Search in sources :

Example 1 with VersionedApplicationState

use of org.apache.cassandra.distributed.shared.VersionedApplicationState 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)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1 DistributedTestSnitch.toCassandraInetAddressAndPort (org.apache.cassandra.distributed.impl.DistributedTestSnitch.toCassandraInetAddressAndPort)1 VersionedApplicationState (org.apache.cassandra.distributed.shared.VersionedApplicationState)1 ApplicationState (org.apache.cassandra.gms.ApplicationState)1 EndpointState (org.apache.cassandra.gms.EndpointState)1 VersionedValue (org.apache.cassandra.gms.VersionedValue)1 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)1 StorageService (org.apache.cassandra.service.StorageService)1