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; }
/** * 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; }
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; }
@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(); }
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; }
/** * 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()); }
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; }