Merge branch 'cassandra-2.2' into cassandra-3.0
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/aa21bd29 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/aa21bd29 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/aa21bd29 Branch: refs/heads/trunk Commit: aa21bd295adcaeb4899d0800a184508ab2997bfd Parents: 9a78608 a68f8bd Author: Aleksey Yeschenko <alek...@apache.org> Authored: Tue Nov 17 16:52:16 2015 +0000 Committer: Aleksey Yeschenko <alek...@apache.org> Committed: Tue Nov 17 16:52:16 2015 +0000 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../cassandra/cql3/statements/AlterTableStatement.java | 3 +++ .../cassandra/cql3/validation/operations/AlterTest.java | 8 ++++++++ 3 files changed, 12 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/aa21bd29/CHANGES.txt ---------------------------------------------------------------------- diff --cc CHANGES.txt index 13647cc,fb8f89a..b68cf0d --- a/CHANGES.txt +++ b/CHANGES.txt @@@ -9,9 -3,19 +9,10 @@@ Merged from 2.2 * Fix SimpleDateType type compatibility (CASSANDRA-10027) * (Hadoop) fix splits calculation (CASSANDRA-10640) * (Hadoop) ensure that Cluster instances are always closed (CASSANDRA-10058) - * (cqlsh) show partial trace if incomplete after max_trace_wait (CASSANDRA-7645) - * Use most up-to-date version of schema for system tables (CASSANDRA-10652) - * Deprecate memory_allocator in cassandra.yaml (CASSANDRA-10581,10628) - * Expose phi values from failure detector via JMX and tweak debug - and trace logging (CASSANDRA-9526) - * Fix RangeNamesQueryPager (CASSANDRA-10509) - * Deprecate Pig support (CASSANDRA-10542) - * Reduce contention getting instances of CompositeType (CASSANDRA-10433) Merged from 2.1: + * Forbid compact clustering column type changes in ALTER TABLE (CASSANDRA-8879) * Reject incremental repair with subrange repair (CASSANDRA-10422) * Add a nodetool command to refresh size_estimates (CASSANDRA-9579) - * Shutdown compaction in drain to prevent leak (CASSANDRA-10079) * Invalidate cache after stream receive task is completed (CASSANDRA-10341) * Reject counter writes in CQLSSTableWriter (CASSANDRA-10258) * Remove superfluous COUNTER_MUTATION stage mapping (CASSANDRA-10605) http://git-wip-us.apache.org/repos/asf/cassandra/blob/aa21bd29/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java index 879f618,7f2fe3a..a9b9d37 --- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java @@@ -332,50 -286,6 +332,53 @@@ public class AlterTableStatement extend return true; } + private static void validateAlter(CFMetaData cfm, ColumnDefinition def, AbstractType<?> validatorType) + { + switch (def.kind) + { + case PARTITION_KEY: + if (validatorType instanceof CounterColumnType) + throw new InvalidRequestException(String.format("counter type is not supported for PRIMARY KEY part %s", def.name)); + + AbstractType<?> currentType = cfm.getKeyValidatorAsClusteringComparator().subtype(def.position()); + if (!validatorType.isValueCompatibleWith(currentType)) + throw new ConfigurationException(String.format("Cannot change %s from type %s to type %s: types are incompatible.", + def.name, + currentType.asCQL3Type(), + validatorType.asCQL3Type())); + break; + case CLUSTERING: ++ if (!cfm.isCQLTable()) ++ throw new InvalidRequestException(String.format("Cannot alter clustering column %s in a non-CQL3 table", def.name)); ++ + AbstractType<?> oldType = cfm.comparator.subtype(def.position()); + // Note that CFMetaData.validateCompatibility already validate the change we're about to do. However, the error message it + // sends is a bit cryptic for a CQL3 user, so validating here for a sake of returning a better error message + // Do note that we need isCompatibleWith here, not just isValueCompatibleWith. + if (!validatorType.isCompatibleWith(oldType)) + { + throw new ConfigurationException(String.format("Cannot change %s from type %s to type %s: types are not order-compatible.", + def.name, + oldType.asCQL3Type(), + validatorType.asCQL3Type())); + } + break; + case REGULAR: + case STATIC: + // Thrift allows to change a column validator so CFMetaData.validateCompatibility will let it slide + // if we change to an incompatible type (contrarily to the comparator case). But we don't want to + // allow it for CQL3 (see #5882) so validating it explicitly here. We only care about value compatibility + // though since we won't compare values (except when there is an index, but that is validated by + // ColumnDefinition already). + if (!validatorType.isValueCompatibleWith(def.type)) + throw new ConfigurationException(String.format("Cannot change %s from type %s to type %s: types are incompatible.", + def.name, + def.type.asCQL3Type(), + validatorType.asCQL3Type())); + break; + } + } + public String toString() { return String.format("AlterTableStatement(name=%s, type=%s, column=%s, validator=%s)", http://git-wip-us.apache.org/repos/asf/cassandra/blob/aa21bd29/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java ---------------------------------------------------------------------- diff --cc test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java index 2451c48,2cc8a18..9f8bea2 --- a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java +++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java @@@ -21,13 -21,11 +21,14 @@@ import org.apache.cassandra.cql3.CQLTes import org.apache.cassandra.db.ColumnFamilyStore; import org.apache.cassandra.db.Keyspace; import org.apache.cassandra.exceptions.ConfigurationException; + import org.apache.cassandra.exceptions.InvalidRequestException; import org.apache.cassandra.exceptions.SyntaxException; +import org.apache.cassandra.schema.SchemaKeyspace; +import org.junit.Assert; import org.junit.Test; +import static java.lang.String.format; import static org.junit.Assert.assertEquals; public class AlterTest extends CQLTester @@@ -304,16 -219,10 +305,23 @@@ "ALTER TABLE %s ALTER c1 TYPE date;"); } + private void assertThrowsConfigurationException(String errorMsg, String alterStmt) throws Throwable + { + try + { + execute(alterStmt); + Assert.fail("Query should be invalid but no error was thrown. Query is: " + alterStmt); + } + catch (ConfigurationException e) + { + assertEquals(errorMsg, e.getMessage()); + } + } ++ + @Test // tests CASSANDRA-8879 + public void testAlterClusteringColumnTypeInCompactTable() throws Throwable + { + createTable("CREATE TABLE %s (key blob, column1 blob, value blob, PRIMARY KEY ((key), column1)) WITH COMPACT STORAGE"); + assertInvalidThrow(InvalidRequestException.class, "ALTER TABLE %s ALTER column1 TYPE ascii"); + } }