createIdx.getColumnFamily()));
if (oldCfm == null)
throw new InvalidRequestException("No such column family: " + createIdx.getColumnFamily());
ByteBuffer columnName = createIdx.getColumnName().getByteBuffer();
ColumnDefinition columnDef = oldCfm.getColumn_metadata().get(columnName);
// Meta-data for this column already exists
if (columnDef != null)
{
// This column is already indexed, stop, drop, and roll.
if (columnDef.getIndexType() != null)
throw new InvalidRequestException("Index exists");
// Add index attrs to the existing definition
columnDef.setIndexName(createIdx.getIndexName());
columnDef.setIndexType(org.apache.cassandra.thrift.IndexType.KEYS);
}
// No meta-data, create a new column definition from scratch.
else
{
columnDef = new ColumnDefinition(columnName,
DatabaseDescriptor.getValueValidator(keyspace,
createIdx.getColumnFamily(),
columnName),
org.apache.cassandra.thrift.IndexType.KEYS,
createIdx.getIndexName());
}
CfDef cfamilyDef = CFMetaData.convertToAvro(oldCfm);
cfamilyDef.column_metadata.add(columnDef.deflate());
try
{
applyMigrationOnStage(new UpdateColumnFamily(cfamilyDef));
}