use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class Gossiper method reloadSeeds.
/**
* JMX interface for triggering an update of the seed node list.
*/
public List<String> reloadSeeds() {
logger.trace("Triggering reload of seed node list");
// Get the new set in the same that buildSeedsList does
Set<InetAddressAndPort> tmp = new HashSet<>();
try {
for (InetAddressAndPort seed : DatabaseDescriptor.getSeeds()) {
if (seed.equals(getBroadcastAddressAndPort()))
continue;
tmp.add(seed);
}
}// Handle the error and return a null to indicate that there was a problem.
catch (Throwable e) {
JVMStabilityInspector.inspectThrowable(e);
logger.warn("Error while getting seed node list: {}", e.getLocalizedMessage());
return null;
}
if (tmp.size() == 0) {
logger.trace("New seed node list is empty. Not updating seed list.");
return getSeeds();
}
if (tmp.equals(seeds)) {
logger.trace("New seed node list matches the existing list.");
return getSeeds();
}
// Add the new entries
seeds.addAll(tmp);
// Remove the old entries
seeds.retainAll(tmp);
logger.trace("New seed node list after reload {}", seeds);
return getSeeds();
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class Gossiper method examineShadowState.
/**
* Used during a shadow round to collect the current state; this method clones the current state, no filtering
* is done.
*
* During the shadow round its desirable to return gossip state for remote instances that were created by this
* process also known as "empty", this is done for host replacement to be able to replace downed hosts that are
* in the ring but have no state in gossip (see CASSANDRA-16213).
*
* This method is different than {@link #examineGossiper(List, List, Map)} with respect to how "empty" states are
* dealt with; they are kept.
*/
Map<InetAddressAndPort, EndpointState> examineShadowState() {
logger.debug("Shadow request received, adding all states");
Map<InetAddressAndPort, EndpointState> map = new HashMap<>();
for (Entry<InetAddressAndPort, EndpointState> e : endpointStateMap.entrySet()) {
InetAddressAndPort endpoint = e.getKey();
EndpointState state = new EndpointState(e.getValue());
if (state.isEmptyWithoutStatus()) {
// We have no app states loaded for this endpoint, but we may well have
// some state persisted in the system keyspace. This can happen in the case
// of a full cluster bounce where one or more nodes fail to come up. As
// gossip state is transient, the peers which do successfully start will be
// aware of the failed nodes thanks to StorageService::initServer calling
// Gossiper.instance::addSavedEndpoint with every endpoint in TokenMetadata,
// which itself is populated from the system tables at startup.
// Here we know that a peer which is starting up and attempting to perform
// a shadow round of gossip. This peer is in one of two states:
// * it is replacing a down node, in which case it needs to learn the tokens
// of the down node and optionally its host id.
// * it needs to check that no other instance is already associated with its
// endpoint address and port.
// To support both of these cases, we can add the tokens and host id from
// the system table, if they exist. These are only ever persisted to the system
// table when the actual node to which they apply enters the UP/NORMAL state.
// This invariant will be preserved as nodes never persist or propagate the
// results of a shadow round, so this communication will be strictly limited
// to this node and the node performing the shadow round.
UUID hostId = SystemKeyspace.loadHostIds().get(endpoint);
if (null != hostId) {
state.addApplicationState(ApplicationState.HOST_ID, StorageService.instance.valueFactory.hostId(hostId));
}
Set<Token> tokens = SystemKeyspace.loadTokens().get(endpoint);
if (null != tokens && !tokens.isEmpty()) {
state.addApplicationState(ApplicationState.TOKENS, StorageService.instance.valueFactory.tokens(tokens));
}
}
map.put(endpoint, state);
}
return map;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class Gossiper method addLocalApplicationStateInternal.
private void addLocalApplicationStateInternal(ApplicationState state, VersionedValue value) {
assert taskLock.isHeldByCurrentThread();
InetAddressAndPort epAddr = getBroadcastAddressAndPort();
EndpointState epState = endpointStateMap.get(epAddr);
assert epState != null : "Can't find endpoint state for " + epAddr;
// Fire "before change" notifications:
doBeforeChangeNotifications(epAddr, epState, state, value);
// Notifications may have taken some time, so preventively raise the version
// of the new value, otherwise it could be ignored by the remote node
// if another value with a newer version was received in the meantime:
value = StorageService.instance.valueFactory.cloneWithHigherVersion(value);
// Add to local application state and fire "on change" notifications:
epState.addApplicationState(state, value);
doOnChangeNotifications(epAddr, state, value);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class Gossiper method getReleaseVersionsWithPort.
public Map<String, List<String>> getReleaseVersionsWithPort() {
Map<String, List<String>> results = new HashMap<>();
Iterable<InetAddressAndPort> allHosts = Iterables.concat(Gossiper.instance.getLiveMembers(), Gossiper.instance.getUnreachableMembers());
for (InetAddressAndPort host : allHosts) {
CassandraVersion version = getReleaseVersion(host);
String stringVersion = version == null ? "" : version.toString();
List<String> hosts = results.get(stringVersion);
if (hosts == null) {
hosts = new ArrayList<>();
results.put(stringVersion, hosts);
}
hosts.add(host.getHostAddressAndPort());
}
return results;
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class Gossiper method seenAnySeed.
public boolean seenAnySeed() {
for (Map.Entry<InetAddressAndPort, EndpointState> entry : endpointStateMap.entrySet()) {
if (seeds.contains(entry.getKey()))
return true;
try {
VersionedValue internalIp = entry.getValue().getApplicationState(ApplicationState.INTERNAL_IP);
VersionedValue internalIpAndPort = entry.getValue().getApplicationState(ApplicationState.INTERNAL_ADDRESS_AND_PORT);
InetAddressAndPort endpoint = null;
if (internalIpAndPort != null) {
endpoint = InetAddressAndPort.getByName(internalIpAndPort.value);
} else if (internalIp != null) {
endpoint = InetAddressAndPort.getByName(internalIp.value);
}
if (endpoint != null && seeds.contains(endpoint))
return true;
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
}
return false;
}
Aggregations