public GossipingPropertyFileSnitch(int refreshPeriodInSeconds) throws ConfigurationException { snitchHelperReference = new AtomicReference<ReconnectableSnitchHelper>(); reloadConfiguration(); try { psnitch = new PropertyFileSnitch(); logger.info("Loaded {} for compatibility", PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME); } catch (ConfigurationException e) { logger.info( "Unable to load {}; compatibility mode disabled", PropertyFileSnitch.SNITCH_PROPERTIES_FILENAME); } try { Utils.resourceToFile(SnitchProperties.RACKDC_PROPERTY_FILENAME); Runnable runnable = new WrappedRunnable() { @Override protected void runMayThrow() throws ConfigurationException { reloadConfiguration(); } }; ResourceWatcher.watch( SnitchProperties.RACKDC_PROPERTY_FILENAME, runnable, refreshPeriodInSeconds * 1000); } catch (ConfigurationException ex) { logger.error( "{} found, but does not look like a plain file. Will not watch it for changes", SnitchProperties.RACKDC_PROPERTY_FILENAME); } }
public FailureDetector() { // Register this instance with JMX try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(this, new ObjectName(Utils.getJmxObjectName("FailureDetector"))); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public boolean isAlive(InetAddress ep) { if (ep.equals(Utils.getBroadcastAddress())) return true; EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(ep); // we could assert not-null, but having isAlive fail screws a node over so badly that // it's worth being defensive here so minor bugs don't cause disproportionate // badness. (See lealone-1463 for an example). if (epState == null) logger.error("unknown endpoint {}", ep); return epState != null && epState.isAlive(); }
@Override public void gossiperStarting() { super.gossiperStarting(); Gossiper.instance.addLocalApplicationState( ApplicationState.INTERNAL_IP, StorageService.VALUE_FACTORY.internalIP(Utils.getLocalAddress().getHostAddress())); reloadGossiperState(); gossipStarted = true; }
/** * Return the rack for which an endpoint resides in * * @param endpoint the endpoint to process * @return string of rack */ @Override public String getRack(InetAddress endpoint) { if (endpoint.equals(Utils.getBroadcastAddress())) return myRack; EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(endpoint); if (epState == null || epState.getApplicationState(ApplicationState.RACK) == null) { if (psnitch == null) { if (savedEndpoints == null) savedEndpoints = ClusterMetaData.loadDcRackInfo(); if (savedEndpoints.containsKey(endpoint)) return savedEndpoints.get(endpoint).get("rack"); return DEFAULT_RACK; } else return psnitch.getRack(endpoint); } return epState.getApplicationState(ApplicationState.RACK).value; }