示例#1
0
 KSMetaData(
     String name,
     Class<? extends AbstractReplicationStrategy> strategyClass,
     Map<String, String> strategyOptions,
     boolean durableWrites,
     Iterable<CFMetaData> cfDefs) {
   this.name = name;
   this.strategyClass = strategyClass == null ? NetworkTopologyStrategy.class : strategyClass;
   this.strategyOptions = strategyOptions;
   Map<String, CFMetaData> cfmap = new HashMap<String, CFMetaData>();
   for (CFMetaData cfm : cfDefs) cfmap.put(cfm.cfName, cfm);
   this.cfMetaData = Collections.unmodifiableMap(cfmap);
   this.durableWrites = durableWrites;
 }
示例#2
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;
  }
示例#3
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;
  }
示例#4
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();
 }
示例#5
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;
  }
示例#6
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());
 }
示例#7
0
 public static Map<String, String> optsWithRF(final Integer rf) {
   Map<String, String> ret = new HashMap<String, String>();
   ret.put("replication_factor", rf.toString());
   return ret;
 }