Beispiel #1
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);
  }
Beispiel #2
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);
 }
Beispiel #3
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);
   }
 }
Beispiel #4
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());
   }
 }