Esempio n. 1
0
  public RowMutation toSchema(long timestamp) {
    RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, SystemTable.getSchemaKSKey(name));
    ColumnFamily cf = rm.addOrGet(SystemTable.SCHEMA_KEYSPACES_CF);

    cf.addColumn(Column.create(name, timestamp, "name"));
    cf.addColumn(Column.create(durableWrites, timestamp, "durable_writes"));
    cf.addColumn(Column.create(strategyClass.getName(), timestamp, "strategy_class"));
    cf.addColumn(Column.create(json(strategyOptions), timestamp, "strategy_options"));

    for (CFMetaData cfm : cfMetaData.values()) cfm.toSchema(rm, timestamp);

    return rm;
  }
Esempio n. 2
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(name)
       .append(", rep strategy:")
       .append(strategyClass.getSimpleName())
       .append("{")
       .append(StringUtils.join(cfMetaData.values(), ", "))
       .append("}")
       .append(", durable_writes: ")
       .append(durableWrites);
   return sb.toString();
 }
Esempio n. 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;
  }
Esempio n. 4
0
  /**
   * Deserialize ColumnFamilies from low-level schema representation, all of them belong to the same
   * keyspace
   *
   * @param row
   * @return map containing name of the ColumnFamily and it's metadata for faster lookup
   */
  public static Map<String, CFMetaData> deserializeColumnFamilies(Row row) {
    if (row.cf == null) return Collections.emptyMap();

    Map<String, CFMetaData> cfms = new HashMap<String, CFMetaData>();
    UntypedResultSet results =
        QueryProcessor.resultify("SELECT * FROM system.schema_columnfamilies", row);
    for (UntypedResultSet.Row result : results) {
      CFMetaData cfm = CFMetaData.fromSchema(result);
      cfms.put(cfm.cfName, cfm);
    }

    for (CFMetaData cfm : cfms.values()) {
      Row columnRow = ColumnDefinition.readSchema(cfm.ksName, cfm.cfName);
      for (ColumnDefinition cd : ColumnDefinition.fromSchema(columnRow, cfm))
        cfm.column_metadata.put(cd.name, cd);
    }

    return cfms;
  }
Esempio n. 5
0
 /**
  * Deserialize Keyspace with nested ColumnFamilies
  *
  * @param serializedKs Keyspace in serialized form
  * @param serializedCFs Collection of the serialized ColumnFamilies
  * @return deserialized keyspace with cf_defs
  * @throws IOException if deserialization failed
  */
 public static KSMetaData fromSchema(Row serializedKs, Row serializedCFs) throws IOException {
   Map<String, CFMetaData> cfs = deserializeColumnFamilies(serializedCFs);
   return fromSchema(serializedKs, cfs.values());
 }