}
public CFMetaData validate() throws ConfigurationException
{
if (!isNameValid(ksName))
throw new ConfigurationException(String.format("Keyspace name must not be empty, more than %s characters long, or contain non-alphanumeric-underscore characters (got \"%s\")", Schema.NAME_LENGTH, ksName));
if (!isNameValid(cfName))
throw new ConfigurationException(String.format("ColumnFamily name must not be empty, more than %s characters long, or contain non-alphanumeric-underscore characters (got \"%s\")", Schema.NAME_LENGTH, cfName));
if (cfType == null)
throw new ConfigurationException(String.format("Invalid column family type for %s", cfName));
if (cfType == ColumnFamilyType.Super)
{
if (subcolumnComparator == null)
throw new ConfigurationException(String.format("Missing subcolumn comparator for super column family %s", cfName));
}
else
{
if (subcolumnComparator != null)
throw new ConfigurationException(String.format("Subcolumn comparator (%s) is invalid for standard column family %s", subcolumnComparator, cfName));
}
if (comparator instanceof CounterColumnType)
throw new ConfigurationException("CounterColumnType is not a valid comparator");
if (subcolumnComparator instanceof CounterColumnType)
throw new ConfigurationException("CounterColumnType is not a valid sub-column comparator");
if (keyValidator instanceof CounterColumnType)
throw new ConfigurationException("CounterColumnType is not a valid key validator");
// Mixing counter with non counter columns is not supported (#2614)
if (defaultValidator instanceof CounterColumnType)
{
for (ColumnDefinition def : column_metadata.values())
if (!(def.getValidator() instanceof CounterColumnType))
throw new ConfigurationException("Cannot add a non counter column (" + getColumnDefinitionComparator(def).getString(def.name) + ") in a counter column family");
}
else
{
for (ColumnDefinition def : column_metadata.values())
if (def.getValidator() instanceof CounterColumnType)
throw new ConfigurationException("Cannot add a counter column (" + getColumnDefinitionComparator(def).getString(def.name) + ") in a non counter column family");
}
// check if any of the columns has name equal to the cf.key_alias
for (ColumnDefinition columndef : column_metadata.values())
{
for (ByteBuffer alias : keyAliases)
if (alias.equals(columndef.name))
throw new ConfigurationException("Cannot have key alias equals to a column name: " + UTF8Type.instance.compose(alias));
for (ByteBuffer alias : columnAliases)
if (alias.equals(columndef.name))
throw new ConfigurationException("Cannot have column alias equals to a column name: " + UTF8Type.instance.compose(alias));
if (valueAlias != null && valueAlias.equals(columndef.name))
throw new ConfigurationException("Cannot have value alias equals to a column name: " + UTF8Type.instance.compose(valueAlias));
}
for (ByteBuffer alias : keyAliases)
validateAlias(alias, "Key");
for (ByteBuffer alias : columnAliases)
validateAlias(alias, "Column");
validateAlias(valueAlias, "Value");
// initialize a set of names NOT in the CF under consideration
Set<String> indexNames = existingIndexNames(cfName);
for (ColumnDefinition c : column_metadata.values())
{
AbstractType<?> comparator = getColumnDefinitionComparator(c);
try
{
comparator.validate(c.name);
}
catch (MarshalException e)
{
throw new ConfigurationException(String.format("Column name %s is not valid for comparator %s",
ByteBufferUtil.bytesToHex(c.name), comparator));
}
if (c.getIndexType() == null)
{
if (c.getIndexName() != null)
throw new ConfigurationException("Index name cannot be set without index type");
}
else
{
if (cfType == ColumnFamilyType.Super)
throw new ConfigurationException("Secondary indexes are not supported on super column families");
if (!isIndexNameValid(c.getIndexName()))
throw new ConfigurationException("Illegal index name " + c.getIndexName());
// check index names against this CF _and_ globally
if (indexNames.contains(c.getIndexName()))
throw new ConfigurationException("Duplicate index name " + c.getIndexName());
indexNames.add(c.getIndexName());
if (c.getIndexType() == IndexType.CUSTOM)
{
if (c.getIndexOptions() == null || !c.getIndexOptions().containsKey(SecondaryIndex.CUSTOM_INDEX_OPTION_NAME))
throw new ConfigurationException("Required index option missing: " + SecondaryIndex.CUSTOM_INDEX_OPTION_NAME);
}
// This method validates the column metadata but does not intialize the index
SecondaryIndex.createInstance(null, c);
}
}
validateCompactionThresholds();
if (bloomFilterFpChance != null && bloomFilterFpChance == 0)
throw new ConfigurationException("Zero false positives is impossible; bloom filter false positive chance bffpc must be 0 < bffpc <= 1");
return this;
}