Merge branch 'cassandra-2.1' into trunk

This commit is contained in:
Sylvain Lebresne 2014-02-24 10:05:54 +01:00
commit 3b45d004c5
8 changed files with 36 additions and 7 deletions

View File

@ -7,6 +7,7 @@
* Fix ABTC NPE (CASSANDRA-6692)
* Allow nodetool to use a file or prompt for password (CASSANDRA-6660)
* Fix AIOOBE when concurrently accessing ABSC (CASSANDRA-6742)
* Fix assertion error in ALTER TYPE RENAME (CASSANDRA-6705)
2.1.0-beta1

View File

@ -109,7 +109,7 @@ public class AlterTableStatement extends SchemaAlteringStatement
if (cfm.isSuper())
throw new InvalidRequestException("Cannot use collection types with Super column family");
cfm.comparator = cfm.comparator.addCollection(columnName, (CollectionType)type);
cfm.comparator = cfm.comparator.addOrUpdateCollection(columnName, (CollectionType)type);
}
Integer componentIndex = cfm.comparator.isCompound() ? cfm.comparator.clusteringPrefixSize() : null;
@ -186,6 +186,13 @@ public class AlterTableStatement extends SchemaAlteringStatement
def.type.asCQL3Type(),
validator));
// For collections, if we alter the type, we need to update the comparator too since it includes
// the type too (note that isValueCompatibleWith above has validated that the need type don't really
// change the underlying sorting order, but we still don't want to have a discrepancy between the type
// in the comparator and the one in the ColumnDefinition as that would be dodgy).
if (validator.getType() instanceof CollectionType)
cfm.comparator = cfm.comparator.addOrUpdateCollection(def.name, (CollectionType)validator.getType());
break;
}
// In any case, we update the column definition

View File

@ -167,6 +167,10 @@ public abstract class AlterTypeStatement extends SchemaAlteringStatement
case CLUSTERING_COLUMN:
cfm.comparator = CellNames.fromAbstractType(updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated), cfm.comparator.isDense());
break;
default:
// If it's a collection, we still want to modify the comparator because the collection is aliased in it
if (def.type instanceof CollectionType)
cfm.comparator = CellNames.fromAbstractType(updateWith(cfm.comparator.asAbstractType(), keyspace, toReplace, updated), cfm.comparator.isDense());
}
return true;
}

View File

@ -198,7 +198,7 @@ public abstract class AbstractCellNameType extends AbstractCType implements Cell
throw new UnsupportedOperationException();
}
public CellNameType addCollection(ColumnIdentifier columnName, CollectionType newCollection)
public CellNameType addOrUpdateCollection(ColumnIdentifier columnName, CollectionType newCollection)
{
throw new UnsupportedOperationException();
}

View File

@ -99,10 +99,10 @@ public interface CellNameType extends CType
public ColumnToCollectionType collectionType();
/**
* Return the new type obtained by adding the new collection type for the provided column name
* Return the new type obtained by adding/updating to the new collection type for the provided column name
* to this type.
*/
public CellNameType addCollection(ColumnIdentifier columnName, CollectionType newCollection);
public CellNameType addOrUpdateCollection(ColumnIdentifier columnName, CollectionType newCollection);
/**
* Returns a new CellNameType that is equivalent to this one but with one

View File

@ -122,7 +122,7 @@ public class CompoundSparseCellNameType extends AbstractCompoundCellNameType
}
@Override
public CellNameType addCollection(ColumnIdentifier columnName, CollectionType newCollection)
public CellNameType addOrUpdateCollection(ColumnIdentifier columnName, CollectionType newCollection)
{
return new WithCollection(clusteringType, ColumnToCollectionType.getInstance(Collections.singletonMap(columnName.bytes, newCollection)), internedIds);
}
@ -244,7 +244,7 @@ public class CompoundSparseCellNameType extends AbstractCompoundCellNameType
}
@Override
public CellNameType addCollection(ColumnIdentifier columnName, CollectionType newCollection)
public CellNameType addOrUpdateCollection(ColumnIdentifier columnName, CollectionType newCollection)
{
Map<ByteBuffer, CollectionType> newMap = new HashMap<>(collectionType.defined);
newMap.put(columnName.bytes, newCollection);

View File

@ -94,6 +94,22 @@ public abstract class CollectionType<T> extends AbstractType<T>
valueComparator().validate(bytes);
}
@Override
public boolean isCompatibleWith(AbstractType<?> previous)
{
if (this == previous)
return true;
if (!getClass().equals(previous.getClass()))
return false;
CollectionType tprev = (CollectionType) previous;
// The name is part of the Cell name, so we need sorting compatibility, i.e. isCompatibleWith().
// But value is the Cell value, so isValueCompatibleWith() is enough
return this.nameComparator().isCompatibleWith(tprev.nameComparator())
&& this.valueComparator().isValueCompatibleWith(tprev.valueComparator());
}
public boolean isCollection()
{
return true;

View File

@ -121,7 +121,8 @@ public class ColumnToCollectionType extends AbstractType<ByteBuffer>
// We are compatible if we have all the definitions previous have (but we can have more).
for (Map.Entry<ByteBuffer, CollectionType> entry : prev.defined.entrySet())
{
if (!entry.getValue().isCompatibleWith(defined.get(entry.getKey())))
CollectionType newType = defined.get(entry.getKey());
if (newType == null || !newType.isCompatibleWith(entry.getValue()))
return false;
}
return true;