public static ReplicationParams fromMap(Map<String, String> map) {
   Map<String, String> options = new HashMap<>(map);
   String className = options.remove(CLASS);
   Class<? extends AbstractReplicationStrategy> klass =
       AbstractReplicationStrategy.getClass(className);
   return new ReplicationParams(klass, options);
 }
 public void validate(String name) {
   // Attempt to instantiate the ARS, which will throw a ConfigurationException if the options
   // aren't valid.
   TokenMetadata tmd = StorageService.instance.getTokenMetadata();
   IEndpointSnitch eps = DatabaseDescriptor.getEndpointSnitch();
   AbstractReplicationStrategy.validateReplicationStrategy(name, klass, tmd, eps, options);
 }
예제 #3
0
  // For new user created keyspaces (through CQL)
  public static KSMetaData newKeyspace(
      String name, String strategyName, Map<String, String> options) throws ConfigurationException {
    Class<? extends AbstractReplicationStrategy> cls =
        AbstractReplicationStrategy.getClass(strategyName);
    if (cls.equals(LocalStrategy.class))
      throw new ConfigurationException(
          "Unable to use given strategy class: LocalStrategy is reserved for internal use.");

    return new KSMetaData(name, cls, options, true, Collections.<CFMetaData>emptyList());
  }
예제 #4
0
    public void bootstrap()
    {
        if (logger.isDebugEnabled())
            logger.debug("Beginning bootstrap process");

        RangeStreamer streamer = new RangeStreamer(tokenMetadata, tokens, address, "Bootstrap");
        streamer.addSourceFilter(new RangeStreamer.FailureDetectorSourceFilter(FailureDetector.instance));

        for (String keyspaceName : Schema.instance.getNonSystemKeyspaces())
        {
            AbstractReplicationStrategy strategy = Keyspace.open(keyspaceName).getReplicationStrategy();
            streamer.addRanges(keyspaceName, strategy.getPendingAddressRanges(tokenMetadata, tokens, address));
        }

        try
        {
            streamer.fetchAsync().get();
            StorageService.instance.finishBootstrapping();
        }
    }
예제 #5
0
 /**
  * Deserialize only Keyspace attributes without nested ColumnFamilies
  *
  * @param row Keyspace attributes in serialized form
  * @return deserialized keyspace without cf_defs
  * @throws IOException if deserialization failed
  */
 public static KSMetaData fromSchema(Row row, Iterable<CFMetaData> cfms) throws IOException {
   UntypedResultSet.Row result =
       QueryProcessor.resultify("SELECT * FROM system.schema_keyspaces", row).one();
   try {
     return new KSMetaData(
         result.getString("name"),
         AbstractReplicationStrategy.getClass(result.getString("strategy_class")),
         fromJsonMap(result.getString("strategy_options")),
         result.getBoolean("durable_writes"),
         cfms);
   } catch (ConfigurationException e) {
     throw new RuntimeException(e);
   }
 }
예제 #6
0
  public static KSMetaData fromThrift(KsDef ksd, CFMetaData... cfDefs)
      throws ConfigurationException {
    Class<? extends AbstractReplicationStrategy> cls =
        AbstractReplicationStrategy.getClass(ksd.strategy_class);
    if (cls.equals(LocalStrategy.class))
      throw new ConfigurationException(
          "Unable to use given strategy class: LocalStrategy is reserved for internal use.");

    return new KSMetaData(
        ksd.name,
        cls,
        ksd.strategy_options == null
            ? Collections.<String, String>emptyMap()
            : ksd.strategy_options,
        ksd.durable_writes,
        Arrays.asList(cfDefs));
  }
예제 #7
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;
  }