You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by al...@apache.org on 2015/11/17 17:53:48 UTC
[1/3] cassandra git commit: Forbid compact clustering column type
changes in ALTER TABLE
Repository: cassandra
Updated Branches:
refs/heads/cassandra-3.0 9a7860819 -> aa21bd295
Forbid compact clustering column type changes in ALTER TABLE
patch by Aleksey Yeschenko; reviewed by Sylvain Lebresne for
CASSANDRA-8879
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5414950d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5414950d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5414950d
Branch: refs/heads/cassandra-3.0
Commit: 5414950d6a42a2f7d41dec6427cbf210dd7d99af
Parents: a8e8a67
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed Nov 11 18:45:50 2015 +0000
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Tue Nov 17 16:44:37 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/5414950d/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b6b394a..eea14c8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
2.1.12
+ * 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)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5414950d/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index 9d07459..44bc2bc 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -182,6 +182,9 @@ public class AlterTableStatement extends SchemaAlteringStatement
}
break;
case CLUSTERING_COLUMN:
+ if (!cfm.isCQL3Table())
+ throw new InvalidRequestException(String.format("Cannot alter clustering column %s in a non-CQL3 table", columnName));
+
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
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5414950d/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
index cc7d2a4..a6aad87 100644
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
@@ -21,6 +21,7 @@ import org.apache.cassandra.cql3.CQLTester;
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.junit.Test;
@@ -198,4 +199,11 @@ public class AlterTest extends CQLTester
assertInvalidSyntaxMessage("no viable alternative at input 'WITH'", stmt);
}
}
+
+ @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");
+ }
}
[2/3] cassandra git commit: Merge branch 'cassandra-2.1' into
cassandra-2.2
Posted by al...@apache.org.
Merge branch 'cassandra-2.1' into cassandra-2.2
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/a68f8bd7
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/a68f8bd7
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/a68f8bd7
Branch: refs/heads/cassandra-3.0
Commit: a68f8bd700666e87877993107ad1b20ed957c8a8
Parents: 99b82db 5414950
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Tue Nov 17 16:47:41 2015 +0000
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Tue Nov 17 16:47:41 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/a68f8bd7/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index f5d3416,eea14c8..fb8f89a
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,17 -1,5 +1,18 @@@
-2.1.12
+2.2.4
+ * Don't do anticompaction after subrange repair (CASSANDRA-10422)
+ * 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)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a68f8bd7/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/a68f8bd7/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
index 566c0ea,a6aad87..2cc8a18
--- a/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/operations/AlterTest.java
@@@ -201,20 -200,10 +202,27 @@@ public class AlterTest extends CQLTeste
}
}
+ /**
+ * tests CASSANDRA-10027
+ */
+ @Test
+ public void testAlterColumnTypeToDate() throws Throwable
+ {
+ createTable("CREATE TABLE %s (key int PRIMARY KEY, c1 int);");
+ execute("INSERT INTO %s (key, c1) VALUES (1,1);");
+ execute("ALTER TABLE %s ALTER c1 TYPE date;");
+ assertRows(execute("SELECT * FROM %s"), row(1, 1));
+
+ createTable("CREATE TABLE %s (key int PRIMARY KEY, c1 varint);");
+ execute("INSERT INTO %s (key, c1) VALUES (1,1);");
+ assertInvalidMessage("Cannot change c1 from type varint to type date: types are incompatible.",
+ "ALTER TABLE %s ALTER c1 TYPE date;");
+ }
++
+ @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");
+ }
}
[3/3] cassandra git commit: Merge branch 'cassandra-2.2' into
cassandra-3.0
Posted by al...@apache.org.
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/cassandra-3.0
Commit: aa21bd295adcaeb4899d0800a184508ab2997bfd
Parents: 9a78608 a68f8bd
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Tue Nov 17 16:52:16 2015 +0000
Committer: Aleksey Yeschenko <al...@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");
+ }
}