private void loadGossiperState() { assert Gossiper.instance != null; ReconnectableSnitchHelper pendingHelper = new ReconnectableSnitchHelper(this, myDC, preferLocal); Gossiper.instance.register(pendingHelper); pendingHelper = snitchHelperReference.getAndSet(pendingHelper); if (pendingHelper != null) Gossiper.instance.unregister(pendingHelper); } }
public void run() { if (logger.isTraceEnabled()) logger.trace("Disseminating load info ..."); Gossiper.instance.addLocalApplicationState(ApplicationState.LOAD, StorageService.instance.valueFactory.load(StorageMetrics.load.getCount())); } };
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); }
/** * The schema version to announce. * This will be either the "real" schema version including the {@code cdc} column, * if no node in the cluster is running at 3.0, or a 3.0 compatible * schema version, with the {@code cdc} column excluded, if at least one node is * running 3.0. * * @return "current" schema version */ public UUID getVersion() { return Gossiper.instance.isEnabled() && Gossiper.instance.isAnyNodeOn30() ? altVersion : version; }
public void doVerb(MessageIn message, int id) { if (!Gossiper.instance.isEnabled()) { logger.debug("Ignoring shutdown message from {} because gossip is disabled", message.from); return; } Gossiper.instance.markAsShutdown(message.from); }
public void onChange(InetAddress endpoint, ApplicationState state, VersionedValue value) { if (preferLocal && state == ApplicationState.INTERNAL_IP && !Gossiper.instance.isDeadState(Gossiper.instance.getEndpointStateForEndpoint(endpoint))) reconnect(endpoint, value); }
public void unsafeInitialize() throws ConfigurationException { initialized = true; gossipActive = true; Gossiper.instance.register(this); Gossiper.instance.start((int) (System.currentTimeMillis() / 1000)); // needed for node-ring gathering. Gossiper.instance.addLocalApplicationState(ApplicationState.NET_VERSION, valueFactory.networkVersion()); if (!MessagingService.instance().isListening()) MessagingService.instance().listen(); }
@Override public void gossiperStarting() { super.gossiperStarting(); Gossiper.instance.addLocalApplicationState(ApplicationState.INTERNAL_IP, StorageService.instance.valueFactory.internalIP(localPrivateAddress)); Gossiper.instance.register(new ReconnectableSnitchHelper(this, ec2region, true)); } }
public synchronized Collection<Token> prepareReplacementInfo() throws ConfigurationException { logger.info("Gathering node replacement information for {}", DatabaseDescriptor.getReplaceAddress()); if (!MessagingService.instance().isListening()) MessagingService.instance().listen(FBUtilities.getLocalAddress()); // make magic happen Gossiper.instance.doShadowRound(); UUID hostId = null; // now that we've gossiped at least once, we should be able to find the node we're replacing if (Gossiper.instance.getEndpointStateForEndpoint(DatabaseDescriptor.getReplaceAddress())== null) throw new RuntimeException("Cannot replace_address " + DatabaseDescriptor.getReplaceAddress() + " because it doesn't exist in gossip"); hostId = Gossiper.instance.getHostId(DatabaseDescriptor.getReplaceAddress()); try { VersionedValue tokensVersionedValue = Gossiper.instance.getEndpointStateForEndpoint(DatabaseDescriptor.getReplaceAddress()).getApplicationState(ApplicationState.TOKENS); if (tokensVersionedValue == null) throw new RuntimeException("Could not find tokens for " + DatabaseDescriptor.getReplaceAddress() + " to replace"); Collection<Token> tokens = TokenSerializer.deserialize(getPartitioner(), new DataInputStream(new ByteArrayInputStream(tokensVersionedValue.toBytes()))); SystemKeyspace.setLocalHostId(hostId); // use the replacee's host Id as our own so we receive hints, etc Gossiper.instance.resetEndpointStateMap(); // clean up since we have what we need return tokens; } catch (IOException e) { throw new RuntimeException(e); } }
public void doVerb(MessageIn<GossipDigestAck2> message, int id) { if (logger.isTraceEnabled()) { InetAddress from = message.from; logger.trace("Received a GossipDigestAck2Message from {}", from); } if (!Gossiper.instance.isEnabled()) { if (logger.isTraceEnabled()) logger.trace("Ignoring GossipDigestAck2Message because gossip is disabled"); return; } Map<InetAddress, EndpointState> remoteEpStateMap = message.payload.getEndpointStateMap(); /* Notify the Failure Detector */ Gossiper.instance.notifyFailureDetector(remoteEpStateMap); Gossiper.instance.applyStateLocally(remoteEpStateMap); } }
public void stopClient() { Gossiper.instance.unregister(this); Gossiper.instance.stop(); MessagingService.instance().shutdown(); // give it a second so that task accepted before the MessagingService shutdown gets submitted to the stage (to avoid RejectedExecutionException) Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); StageManager.shutdownNow(); }
/** * Start the gossiper with the generation number, preloading the map of application states before starting */ public void start(int generationNbr, Map<ApplicationState, VersionedValue> preloadLocalStates) { buildSeedsList(); /* initialize the heartbeat state for this localEndpoint */ maybeInitializeLocalState(generationNbr); EndpointState localState = endpointStateMap.get(FBUtilities.getBroadcastAddress()); localState.addApplicationStates(preloadLocalStates); //notify snitches that Gossiper is about to start DatabaseDescriptor.getEndpointSnitch().gossiperStarting(); if (logger.isTraceEnabled()) logger.trace("gossip started with generation {}", localState.getHeartBeatState().getGeneration()); scheduledGossipTask = executor.scheduleWithFixedDelay(new GossipTask(), Gossiper.intervalInMillis, Gossiper.intervalInMillis, TimeUnit.MILLISECONDS); }
/** * Handles switching the endpoint's state from REMOVING_TOKEN to REMOVED_TOKEN * This should only be called after advertiseRemoving * * @param endpoint * @param hostId */ public void advertiseTokenRemoved(InetAddress endpoint, UUID hostId) { EndpointState epState = endpointStateMap.get(endpoint); epState.updateTimestamp(); // make sure we don't evict it too soon epState.getHeartBeatState().forceNewerGenerationUnsafe(); long expireTime = computeExpireTime(); epState.addApplicationState(ApplicationState.STATUS, StorageService.instance.valueFactory.removedNonlocal(hostId, expireTime)); logger.info("Completing removal of {}", endpoint); addExpireTimeForEndpoint(endpoint, expireTime); endpointStateMap.put(endpoint, epState); // ensure at least one gossip round occurs before returning Uninterruptibles.sleepUninterruptibly(intervalInMillis * 2, TimeUnit.MILLISECONDS); }
Map<InetAddress, EndpointState> epStates = Gossiper.instance.doShadowRound(); localHostId = Gossiper.instance.getHostId(replaceAddress, epStates);
public synchronized void checkForEndpointCollision() throws ConfigurationException { logger.debug("Starting shadow gossip round to check for endpoint collision"); if (!MessagingService.instance().isListening()) MessagingService.instance().listen(FBUtilities.getLocalAddress()); Gossiper.instance.doShadowRound(); if (!Gossiper.instance.isSafeForBootstrap(FBUtilities.getBroadcastAddress())) { throw new RuntimeException(String.format("A node with address %s already exists, cancelling join. " + "Use cassandra.replace_address if you want to replace this node.", FBUtilities.getBroadcastAddress())); } if (RangeStreamer.useStrictConsistency && !allowSimultaneousMoves()) { for (Map.Entry<InetAddress, EndpointState> entry : Gossiper.instance.getEndpointStates()) { if (entry.getKey().equals(FBUtilities.getBroadcastAddress()) || entry.getValue().getApplicationState(ApplicationState.STATUS) == null) continue; String[] pieces = entry.getValue().getApplicationState(ApplicationState.STATUS).value.split(VersionedValue.DELIMITER_STR, -1); assert (pieces.length > 0); String state = pieces[0]; if (state.equals(VersionedValue.STATUS_BOOTSTRAPPING) || state.equals(VersionedValue.STATUS_LEAVING) || state.equals(VersionedValue.STATUS_MOVING)) throw new UnsupportedOperationException("Other bootstrapping/leaving/moving nodes detected, cannot bootstrap while cassandra.consistent.rangemovement is true"); } } Gossiper.instance.resetEndpointStateMap(); }
public UUID getHostId(InetAddress endpoint) { return getHostId(endpoint, endpointStateMap); }
private void publishX1(boolean force) throws JsonGenerationException, JsonMappingException, IOException { if (Gossiper.instance.isEnabled() || force) { if (searchEnabled.get()) { String newValue = jsonMapper.writerWithType(indexShardStateTypeReference).writeValueAsString(localShardStateMap); Gossiper.instance.addLocalApplicationState(ELASTIC_SHARDS_STATES, StorageService.instance.valueFactory.datacenter(newValue)); } else { // publish an empty map, so other nodes will see local shards UNASSIGNED. Gossiper.instance.addLocalApplicationState(ELASTIC_SHARDS_STATES, StorageService.instance.valueFactory.datacenter("{}")); } } }
public synchronized void registerParentRepairSession(UUID parentRepairSession, InetAddress coordinator, List<ColumnFamilyStore> columnFamilyStores, Collection<Range<Token>> ranges, boolean isIncremental, long timestamp, boolean isGlobal) { if (!registeredForEndpointChanges) { Gossiper.instance.register(this); FailureDetector.instance.registerFailureDetectionEventListener(this); registeredForEndpointChanges = true; } if (!parentRepairSessions.containsKey(parentRepairSession)) { parentRepairSessions.put(parentRepairSession, new ParentRepairSession(coordinator, columnFamilyStores, ranges, isIncremental, timestamp, isGlobal)); } }
private void leaveRing() { SystemKeyspace.setBootstrapState(SystemKeyspace.BootstrapState.NEEDS_BOOTSTRAP); tokenMetadata.removeEndpoint(FBUtilities.getBroadcastAddress()); PendingRangeCalculatorService.instance.update(); Gossiper.instance.addLocalApplicationState(ApplicationState.STATUS, valueFactory.left(getLocalTokens(),Gossiper.computeExpireTime())); int delay = Math.max(RING_DELAY, Gossiper.intervalInMillis * 2); logger.info("Announcing that I have left the ring for {}ms", delay); Uninterruptibles.sleepUninterruptibly(delay, TimeUnit.MILLISECONDS); }
@Override protected void doClose() { Gossiper.instance.unregister(this); }