Esempio n. 1
0
  void doStatusCheck() {
    long now = System.currentTimeMillis();

    Set<InetAddress> eps = endpointStateMap_.keySet();
    for (InetAddress endpoint : eps) {
      if (endpoint.equals(localEndpoint_)) continue;

      FailureDetector.instance.interpret(endpoint);
      EndpointState epState = endpointStateMap_.get(endpoint);
      if (epState != null) {
        long duration = now - epState.getUpdateTimestamp();

        if (StorageService.instance.getTokenMetadata().isMember(endpoint))
          epState.setHasToken(true);
        // check if this is a fat client. fat clients are removed automatically from
        // gosip after FatClientTimeout
        if (!epState.getHasToken()
            && !epState.isAlive()
            && !justRemovedEndpoints_.containsKey(endpoint)
            && (duration > FatClientTimeout_)) {
          logger_.info(
              "FatClient "
                  + endpoint
                  + " has been silent for "
                  + FatClientTimeout_
                  + "ms, removing from gossip");
          removeEndpoint(
              endpoint); // will put it in justRemovedEndpoints to respect quarantine delay
          evictFromMembership(endpoint); // can get rid of the state immediately
        }

        if (!epState.isAlive() && (duration > aVeryLongTime_)) {
          evictFromMembership(endpoint);
        }
      }
    }

    if (!justRemovedEndpoints_.isEmpty()) {
      Map<InetAddress, Long> copy = new HashMap<InetAddress, Long>(justRemovedEndpoints_);
      for (Map.Entry<InetAddress, Long> entry : copy.entrySet()) {
        if ((now - entry.getValue()) > QUARANTINE_DELAY) {
          if (logger_.isDebugEnabled())
            logger_.debug(
                QUARANTINE_DELAY + " elapsed, " + entry.getKey() + " gossip quarantine over");
          justRemovedEndpoints_.remove(entry.getKey());
        }
      }
    }
  }
Esempio n. 2
0
  /** Start the gossiper with the generation # retrieved from the System table */
  public void start(InetAddress localEndpoint, int generationNbr) {
    localEndpoint_ = localEndpoint;
    /* Get the seeds from the config and initialize them. */
    Set<InetAddress> seedHosts = DatabaseDescriptor.getSeeds();
    for (InetAddress seed : seedHosts) {
      if (seed.equals(localEndpoint)) continue;
      seeds_.add(seed);
    }

    /* initialize the heartbeat state for this localEndpoint */
    EndpointState localState = endpointStateMap_.get(localEndpoint_);
    if (localState == null) {
      HeartBeatState hbState = new HeartBeatState(generationNbr);
      localState = new EndpointState(hbState);
      localState.isAlive(true);
      localState.isAGossiper(true);
      endpointStateMap_.put(localEndpoint_, localState);
    }

    // notify snitches that Gossiper is about to start
    DatabaseDescriptor.getEndpointSnitch().gossiperStarting();

    scheduledGossipTask =
        StorageService.scheduledTasks.scheduleWithFixedDelay(
            new GossipTask(),
            Gossiper.intervalInMillis_,
            Gossiper.intervalInMillis_,
            TimeUnit.MILLISECONDS);
  }
Esempio n. 3
0
 void markAlive(InetAddress addr, EndpointState localState) {
   if (logger_.isTraceEnabled()) logger_.trace("marking as alive {}", addr);
   if (!localState.isAlive()) {
     isAlive(addr, localState, true);
     logger_.info("InetAddress {} is now UP", addr);
   }
 }
Esempio n. 4
0
 /**
  * This method is part of IFailureDetectionEventListener interface. This is invoked by the Failure
  * Detector when it convicts an end point.
  *
  * <p>param @ endpoint end point that is convicted.
  */
 public void convict(InetAddress endpoint) {
   EndpointState epState = endpointStateMap_.get(endpoint);
   if (epState.isAlive()) {
     logger_.info("InetAddress {} is now dead.", endpoint);
     isAlive(endpoint, epState, false);
   }
 }
Esempio n. 5
0
 /** This should *only* be used for testing purposes. */
 public void initializeNodeUnsafe(InetAddress addr, int generationNbr) {
   /* initialize the heartbeat state for this localEndpoint */
   EndpointState localState = endpointStateMap_.get(addr);
   if (localState == null) {
     HeartBeatState hbState = new HeartBeatState(generationNbr);
     localState = new EndpointState(hbState);
     localState.isAlive(true);
     localState.isAGossiper(true);
     endpointStateMap_.put(addr, localState);
   }
 }
Esempio n. 6
0
 /** Add an endpoint we knew about previously, but whose state is unknown */
 public void addSavedEndpoint(InetAddress ep) {
   EndpointState epState = endpointStateMap_.get(ep);
   if (epState == null) {
     epState = new EndpointState(new HeartBeatState(0));
     epState.isAlive(false);
     epState.isAGossiper(true);
     epState.setHasToken(true);
     endpointStateMap_.put(ep, epState);
     unreachableEndpoints_.put(ep, System.currentTimeMillis());
   }
 }
Esempio n. 7
0
 void isAlive(InetAddress addr, EndpointState epState, boolean value) {
   epState.isAlive(value);
   if (value) {
     liveEndpoints_.add(addr);
     unreachableEndpoints_.remove(addr);
     for (IEndpointStateChangeSubscriber subscriber : subscribers_)
       subscriber.onAlive(addr, epState);
   } else {
     liveEndpoints_.remove(addr);
     unreachableEndpoints_.put(addr, System.currentTimeMillis());
     for (IEndpointStateChangeSubscriber subscriber : subscribers_)
       subscriber.onDead(addr, epState);
   }
   if (epState.isAGossiper()) return;
   epState.isAGossiper(true);
 }