Пример #1
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());
  }
Пример #2
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);
   }
 }
Пример #3
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));
  }
Пример #4
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;
  }