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