Example #1
0
  /*
      This method is used to figure the state that the Gossiper has but Gossipee doesn't. The delta digests
      and the delta state are built up.
  */
  void examineGossiper(
      List<GossipDigest> gDigestList,
      List<GossipDigest> deltaGossipDigestList,
      Map<InetAddress, EndpointState> deltaEpStateMap) {
    for (GossipDigest gDigest : gDigestList) {
      int remoteGeneration = gDigest.getGeneration();
      int maxRemoteVersion = gDigest.getMaxVersion();
      /* Get state associated with the end point in digest */
      EndpointState epStatePtr = endpointStateMap_.get(gDigest.getEndpoint());
      /*
          Here we need to fire a GossipDigestAckMessage. If we have some data associated with this endpoint locally
          then we follow the "if" path of the logic. If we have absolutely nothing for this endpoint we need to
          request all the data for this endpoint.
      */
      if (epStatePtr != null) {
        int localGeneration = epStatePtr.getHeartBeatState().getGeneration();
        /* get the max version of all keys in the state associated with this endpoint */
        int maxLocalVersion = getMaxEndpointStateVersion(epStatePtr);
        if (remoteGeneration == localGeneration && maxRemoteVersion == maxLocalVersion) continue;

        if (remoteGeneration > localGeneration) {
          /* we request everything from the gossiper */
          requestAll(gDigest, deltaGossipDigestList, remoteGeneration);
        }
        if (remoteGeneration < localGeneration) {
          /* send all data with generation = localgeneration and version > 0 */
          sendAll(gDigest, deltaEpStateMap, 0);
        }
        if (remoteGeneration == localGeneration) {
          /*
              If the max remote version is greater then we request the remote endpoint send us all the data
              for this endpoint with version greater than the max version number we have locally for this
              endpoint.
              If the max remote version is lesser, then we send all the data we have locally for this endpoint
              with version greater than the max remote version.
          */
          if (maxRemoteVersion > maxLocalVersion) {
            deltaGossipDigestList.add(
                new GossipDigest(gDigest.getEndpoint(), remoteGeneration, maxLocalVersion));
          }
          if (maxRemoteVersion < maxLocalVersion) {
            /* send all data with generation = localgeneration and version > maxRemoteVersion */
            sendAll(gDigest, deltaEpStateMap, maxRemoteVersion);
          }
        }
      } else {
        /* We are here since we have no data for this endpoint locally so request everything. */
        requestAll(gDigest, deltaGossipDigestList, remoteGeneration);
      }
    }
  }
  static List<GossipDigest> deserialize(DataInputStream dis) throws IOException {
    int size = dis.readInt();
    List<GossipDigest> gDigests = new ArrayList<GossipDigest>();

    for (int i = 0; i < size; ++i) {
      if (dis.available() == 0) {
        logger_.info("Remaining bytes zero. Stopping deserialization of GossipDigests.");
        break;
      }

      GossipDigest gDigest = GossipDigest.serializer().deserialize(dis);
      gDigests.add(gDigest);
    }
    return gDigests;
  }
  static boolean serialize(List<GossipDigest> gDigestList, DataOutputStream dos)
      throws IOException {
    boolean bVal = true;
    int size = gDigestList.size();
    dos.writeInt(size);

    int estimate = 0;
    for (GossipDigest gDigest : gDigestList) {
      if (Gossiper.MAX_GOSSIP_PACKET_SIZE - dos.size() < estimate) {
        logger_.info("@@@@ Breaking out to respect the MTU size in GD @@@@");
        bVal = false;
        break;
      }
      int pre = dos.size();
      GossipDigest.serializer().serialize(gDigest, dos);
      int post = dos.size();
      estimate = post - pre;
    }
    return bVal;
  }
Example #4
0
 /* Send all the data with version greater than maxRemoteVersion */
 void sendAll(
     GossipDigest gDigest, Map<InetAddress, EndpointState> deltaEpStateMap, int maxRemoteVersion) {
   EndpointState localEpStatePtr =
       getStateForVersionBiggerThan(gDigest.getEndpoint(), maxRemoteVersion);
   if (localEpStatePtr != null) deltaEpStateMap.put(gDigest.getEndpoint(), localEpStatePtr);
 }
Example #5
0
 /* Request all the state for the endpoint in the gDigest */
 void requestAll(
     GossipDigest gDigest, List<GossipDigest> deltaGossipDigestList, int remoteGeneration) {
   /* We are here since we have no data for this endpoint locally so request everthing. */
   deltaGossipDigestList.add(new GossipDigest(gDigest.getEndpoint(), remoteGeneration, 0));
   if (logger_.isTraceEnabled()) logger_.trace("requestAll for " + gDigest.getEndpoint());
 }