fix "Can't Modify Index Name" problem on CF update

patch by Pavel Yaskevich; reviewed by Yuki Morishita for CASSANDRA-4439
This commit is contained in:
Pavel Yaskevich 2012-07-17 17:18:46 +03:00
parent 7c982717a3
commit 202f3940dc
3 changed files with 31 additions and 0 deletions

View File

@ -14,6 +14,7 @@
* change nanoTime() to currentTimeInMillis() in schema related code (CASSANDRA-4432)
* add a token generation tool (CASSANDRA-3709)
* Fix LCS bug with sstable containing only 1 row (CASSANDRA-4411)
* fix "Can't Modify Index Name" problem on CF update (CASSANDRA-4439)
Merged from 1.0:
* allow dropping columns shadowed by not-yet-expired supercolumn or row
tombstones in PrecompactedRow (CASSANDRA-4396)

View File

@ -862,6 +862,28 @@ public final class CFMetaData
*/
public void addDefaultIndexNames() throws ConfigurationException
{
// if this is ColumnFamily update we need to add previously defined index names to the existing columns first
Integer cfId = Schema.instance.getId(ksName, cfName);
if (cfId != null)
{
CFMetaData cfm = Schema.instance.getCFMetaData(cfId);
for (Map.Entry<ByteBuffer, ColumnDefinition> entry : column_metadata.entrySet())
{
ColumnDefinition newDef = entry.getValue();
if (!cfm.column_metadata.containsKey(entry.getKey()) || newDef.getIndexType() == null)
continue;
String oldIndexName = cfm.column_metadata.get(entry.getKey()).getIndexName();
if (newDef.getIndexName() != null && !oldIndexName.equals(newDef.getIndexName()))
throw new ConfigurationException("Can't modify index name: was '" + oldIndexName + "' changed to '" + newDef.getIndexName() + "'.");
newDef.setIndexName(oldIndexName);
}
}
Set<String> existingNames = existingIndexNames(null);
for (ColumnDefinition column : column_metadata.values())
{

View File

@ -39,6 +39,14 @@ public class CliTest extends SchemaLoader
// please add new statements here so they could be auto-runned by this test.
private String[] statements = {
"use TestKeySpace;",
"create column family SecondaryIndicesWithoutIdxName" +
" with comparator = UTF8Type" +
" and default_validation_class = UTF8Type" +
" and column_metadata = [{column_name: profileId, validation_class: UTF8Type, index_type: KEYS}];",
"update column family SecondaryIndicesWithoutIdxName" +
" with column_metadata = " +
"[{column_name: profileId, validation_class: UTF8Type, index_type: KEYS}," +
"{column_name: postedDate, validation_class: LongType}];",
"create column family 123 with comparator=UTF8Type and column_metadata=[{ column_name:world, validation_class:IntegerType, index_type:0, index_name:IdxName }, " +
"{ column_name:world2, validation_class:LongType, index_type:KEYS, index_name:LongIdxName}, " +
"{ column_name:617070, validation_class:UTF8Type, index_type:KEYS }, " +