/** Compares our trees, and triggers repairs for any ranges that mismatch. */
      public void run() {
        InetAddress local = FBUtilities.getLocalAddress();

        // restore partitioners (in case we were serialized)
        if (ltree.partitioner() == null) ltree.partitioner(StorageService.getPartitioner());
        if (rtree.partitioner() == null) rtree.partitioner(StorageService.getPartitioner());

        // compare trees, and collect differences
        differences.addAll(MerkleTree.difference(ltree, rtree));

        // choose a repair method based on the significance of the difference
        String format =
            "Endpoints " + local + " and " + remote + " %s for " + cfname + " on " + range;
        if (differences.isEmpty()) {
          logger.info(String.format(format, "are consistent"));
          completed(remote, cfname);
          return;
        }

        // non-0 difference: perform streaming repair
        logger.info(String.format(format, "have " + differences.size() + " range(s) out of sync"));
        try {
          performStreamingRepair();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    public TreeRequest deserialize(DataInput dis, int version) throws IOException {
      String sessId = dis.readUTF();
      InetAddress endpoint = CompactEndpointSerializationHelper.deserialize(dis);
      CFPair cfpair = new CFPair(dis.readUTF(), dis.readUTF());
      Range<Token> range;
      if (version > MessagingService.VERSION_07)
        range = (Range<Token>) AbstractBounds.serializer().deserialize(dis, version);
      else
        range =
            new Range<Token>(
                StorageService.getPartitioner().getMinimumToken(),
                StorageService.getPartitioner().getMinimumToken());

      return new TreeRequest(sessId, endpoint, range, cfpair);
    }
Esempio n. 3
0
    /**
     * if initialtoken was specified, use that (split on comma).
     * otherwise, if num_tokens == 1, pick a token to assume half the load of the most-loaded node.
     * else choose num_tokens tokens at random
     */
    public static Collection<Token> getBootstrapTokens(final TokenMetadata metadata) throws ConfigurationException
    {
        Collection<String> initialTokens = DatabaseDescriptor.getInitialTokens();
        // if user specified tokens, use those
        if (initialTokens.size() > 0)
        {
            logger.debug("tokens manually specified as {}",  initialTokens);
            List<Token> tokens = new ArrayList<Token>(initialTokens.size());
            for (String tokenString : initialTokens)
            {
                Token token = StorageService.getPartitioner().getTokenFactory().fromString(tokenString);
                if (metadata.getEndpoint(token) != null)
                    throw new ConfigurationException("Bootstrapping to existing token " + tokenString + " is not allowed (decommission/removenode the old node first).");
                tokens.add(token);
            }
            return tokens;
        }

        int numTokens = DatabaseDescriptor.getNumTokens();
        if (numTokens < 1)
            throw new ConfigurationException("num_tokens must be >= 1");

        if (numTokens == 1)
            logger.warn("Picking random token for a single vnode.  You should probably add more vnodes; failing that, you should probably specify the token manually");

        return getRandomTokens(metadata, numTokens);
    }
Esempio n. 4
0
 public static Collection<Token> getRandomTokens(TokenMetadata metadata, int numTokens)
 {
     Set<Token> tokens = new HashSet<Token>(numTokens);
     while (tokens.size() < numTokens)
     {
         Token token = StorageService.getPartitioner().getRandomToken();
         if (metadata.getEndpoint(token) == null)
             tokens.add(token);
     }
     return tokens;
 }
  RangeNamesQueryPager(
      RangeSliceCommand command,
      ConsistencyLevel consistencyLevel,
      boolean localQuery,
      PagingState state) {
    this(command, consistencyLevel, localQuery);

    if (state != null) {
      lastReturnedKey = StorageService.getPartitioner().decorateKey(state.partitionKey);
      restoreState(state.remaining, true);
    }
  }
      /** Compares our trees, and triggers repairs for any ranges that mismatch. */
      public void run() {
        // restore partitioners (in case we were serialized)
        if (r1.tree.partitioner() == null) r1.tree.partitioner(StorageService.getPartitioner());
        if (r2.tree.partitioner() == null) r2.tree.partitioner(StorageService.getPartitioner());

        // compare trees, and collect differences
        differences.addAll(MerkleTree.difference(r1.tree, r2.tree));

        // choose a repair method based on the significance of the difference
        String format =
            String.format(
                "[repair #%s] Endpoints %s and %s %%s for %s",
                getName(), r1.endpoint, r2.endpoint, cfname);
        if (differences.isEmpty()) {
          logger.info(String.format(format, "are consistent"));
          completed(this);
          return;
        }

        // non-0 difference: perform streaming repair
        logger.info(String.format(format, "have " + differences.size() + " range(s) out of sync"));
        performStreamingRepair();
      }