예제 #1
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);
    }
예제 #2
0
    public ThriftServerThread(
        InetAddress listenAddr,
        int listenPort,
        int listenBacklog,
        TProcessor processor,
        TTransportFactory transportFactory) {
      TServerFactory.Args args = new TServerFactory.Args();
      args.tProtocolFactory = new TBinaryProtocol.Factory(true, true);
      args.addr = new InetSocketAddress(listenAddr, listenPort);
      args.listenBacklog = listenBacklog;
      args.processor = processor;
      args.keepAlive = DatabaseDescriptor.getRpcKeepAlive();
      args.sendBufferSize = DatabaseDescriptor.getRpcSendBufferSize();
      args.recvBufferSize = DatabaseDescriptor.getRpcRecvBufferSize();
      args.inTransportFactory = transportFactory;
      args.outTransportFactory = transportFactory;

      serverEngine =
          new TServerCustomFactory(DatabaseDescriptor.getRpcServerType()).buildTServer(args);
    }
예제 #3
0
  public KSMetaData validate() throws ConfigurationException {
    if (!CFMetaData.isNameValid(name))
      throw new ConfigurationException(
          String.format(
              "Invalid keyspace name: shouldn't be empty nor more than %s characters long (got \"%s\")",
              Schema.NAME_LENGTH, name));

    // Attempt to instantiate the ARS, which will throw a ConfigException if the strategy_options
    // aren't fully formed
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    IEndpointSnitch eps = DatabaseDescriptor.getEndpointSnitch();
    AbstractReplicationStrategy.createReplicationStrategy(
        name, strategyClass, tmd, eps, strategyOptions);

    for (CFMetaData cfm : cfMetaData.values()) cfm.validate();

    return this;
  }
  public static void main(String args[]) {
    Config.setClientMode(true);
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
    SSTableLoader loader =
        new SSTableLoader(
            options.directory,
            new ExternalClient(
                options.hosts,
                options.rpcPort,
                options.user,
                options.passwd,
                options.transportFactory,
                options.storagePort,
                options.sslStoragePort,
                options.serverEncOptions),
            handler);
    DatabaseDescriptor.setStreamThroughputOutboundMegabitsPerSec(options.throttle);
    StreamResultFuture future = null;
    try {
      if (options.noProgress) future = loader.stream(options.ignores);
      else future = loader.stream(options.ignores, new ProgressIndicator());
    } catch (Exception e) {
      System.err.println(e.getMessage());
      if (e.getCause() != null) System.err.println(e.getCause());
      if (options.debug) e.printStackTrace(System.err);
      else System.err.println("Run with --debug to get full stack trace or --help to get help.");
      System.exit(1);
    }

    handler.output(String.format("Streaming session ID: %s", future.planId));

    try {
      future.get();
      System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
      System.err.println("Streaming to the following hosts failed:");
      System.err.println(loader.getFailedHosts());
      System.err.println(e);
      if (options.debug) e.printStackTrace(System.err);
      System.exit(1);
    }
  }
예제 #5
0
 protected TTransportFactory getTransportFactory() {
   int tFramedTransportSize = DatabaseDescriptor.getThriftFramedTransportSize();
   return new TFramedTransport.Factory(tFramedTransportSize);
 }
 protected void tearDown() {
   DatabaseDescriptor.setPartitioner(oldPartitioner);
 }
 protected void setUp() {
   oldPartitioner = DatabaseDescriptor.getPartitioner();
   DatabaseDescriptor.setPartitioner(new LengthPartitioner());
 }