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/07/23 11:14:59 UTC
cassandra git commit: Fix dropping static compact columns via Thrift
Repository: cassandra
Updated Branches:
refs/heads/trunk 07b89d451 -> c0400b312
Fix dropping static compact columns via Thrift
patch by Aleksey Yeschenko; reviewed by Sylvain Lebresne for
CASSANDRA-9867
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/c0400b31
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/c0400b31
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/c0400b31
Branch: refs/heads/trunk
Commit: c0400b312be6f6a15e6dce092b7758ca149a4a7e
Parents: 07b89d4
Author: Aleksey Yeschenko <al...@apache.org>
Authored: Wed Jul 22 19:59:37 2015 +0300
Committer: Aleksey Yeschenko <al...@apache.org>
Committed: Thu Jul 23 12:16:07 2015 +0300
----------------------------------------------------------------------
CHANGES.txt | 3 +-
.../apache/cassandra/schema/SchemaKeyspace.java | 10 +--
.../cassandra/cql3/ThriftCompatibilityTest.java | 71 ++++++++++++++------
3 files changed, 58 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0400b31/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7277140..67566fb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,7 +3,8 @@
* Metrics should use up to date nomenclature (CASSANDRA-9448)
* Change CREATE/ALTER TABLE syntax for compression (CASSANDRA-8384)
* Cleanup crc and adler code for java 8 (CASSANDRA-9650)
- * Storage engine refactor (CASSANDRA-8099, 9743, 9746, 9759, 9781, 9808, 9825, 9848, 9705, 9859)
+ * Storage engine refactor (CASSANDRA-8099, 9743, 9746, 9759, 9781, 9808, 9825, 9848,
+ 9705, 9859, 9867)
* Update Guava to 18.0 (CASSANDRA-9653)
* Bloom filter false positive ratio is not honoured (CASSANDRA-8413)
* New option for cassandra-stress to leave a ratio of columns null (CASSANDRA-9522)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0400b31/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
index 2eb0ac0..2bc7b0c 100644
--- a/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
+++ b/src/java/org/apache/cassandra/schema/SchemaKeyspace.java
@@ -885,10 +885,12 @@ public final class SchemaKeyspace
{
// Thrift only knows about the REGULAR ColumnDefinition type, so don't consider other type
// are being deleted just because they are not here.
- if (fromThrift && column.kind != ColumnDefinition.Kind.REGULAR) // TODO FIXME
- continue;
-
- dropColumnFromSchemaMutation(oldTable, column, timestamp, mutation);
+ if (!fromThrift ||
+ column.kind == ColumnDefinition.Kind.REGULAR ||
+ (newTable.isStaticCompactTable() && column.kind == ColumnDefinition.Kind.STATIC))
+ {
+ dropColumnFromSchemaMutation(oldTable, column, timestamp, mutation);
+ }
}
// newly added columns
http://git-wip-us.apache.org/repos/asf/cassandra/blob/c0400b31/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java b/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
index c65c625..ff2af56 100644
--- a/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
+++ b/test/unit/org/apache/cassandra/cql3/ThriftCompatibilityTest.java
@@ -17,59 +17,49 @@
*/
package org.apache.cassandra.cql3;
+import java.util.Arrays;
import java.util.Collections;
-import org.junit.BeforeClass;
import org.junit.Test;
+import com.sun.org.apache.xerces.internal.impl.xs.models.CMNodeFactory;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.Schema;
import org.apache.cassandra.db.marshal.BytesType;
import org.apache.cassandra.db.marshal.Int32Type;
import org.apache.cassandra.db.marshal.UTF8Type;
import org.apache.cassandra.schema.KeyspaceParams;
+import org.apache.cassandra.service.MigrationManager;
import org.apache.cassandra.thrift.CfDef;
import org.apache.cassandra.thrift.ColumnDef;
import org.apache.cassandra.thrift.ThriftConversion;
import org.apache.cassandra.utils.ByteBufferUtil;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.apache.cassandra.utils.ByteBufferUtil.bytes;
public class ThriftCompatibilityTest extends SchemaLoader
{
- @BeforeClass
- public static void defineSchema() throws Exception
- {
- // The before class annotation of SchemaLoader will prepare the service so no need to do it here
- SchemaLoader.createKeyspace("thriftcompat", KeyspaceParams.simple(1), thriftCFM("thriftcompat", "JdbcInteger"));
- }
-
- public static CFMetaData thriftCFM(String keyspace, String table)
+ @Test // test for CASSANDRA-8178
+ public void testNonTextComparator() throws Throwable
{
ColumnDef column = new ColumnDef();
column.setName(bytes(42))
.setValidation_class(UTF8Type.instance.toString());
- CfDef cf = new CfDef(keyspace, table);
+ CfDef cf = new CfDef("thriftcompat", "JdbcInteger");
cf.setColumn_type("Standard")
.setComparator_type(Int32Type.instance.toString())
.setDefault_validation_class(UTF8Type.instance.toString())
.setKey_validation_class(BytesType.instance.toString())
.setColumn_metadata(Collections.singletonList(column));
- return ThriftConversion.fromThrift(cf);
- }
-
- private static UntypedResultSet execute(String query)
- {
- return QueryProcessor.executeInternal(query);
- }
+ SchemaLoader.createKeyspace("thriftcompat", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf));
- /** Test For CASSANDRA-8178 */
- @Test
- public void testNonTextComparator() throws Throwable
- {
// the comparator is IntegerType, and there is a column named 42 with a UTF8Type validation type
execute("INSERT INTO \"thriftcompat\".\"JdbcInteger\" (key, \"42\") VALUES (0x00000001, 'abc')");
execute("UPDATE \"thriftcompat\".\"JdbcInteger\" SET \"42\" = 'abc' WHERE key = 0x00000001");
@@ -80,4 +70,43 @@ public class ThriftCompatibilityTest extends SchemaLoader
assertEquals(ByteBufferUtil.bytes(1), row.getBytes("key"));
assertEquals("abc", row.getString("42"));
}
+
+ @Test // test for CASSANDRA-9867
+ public void testDropCompactStaticColumn()
+ {
+ ColumnDef column1 = new ColumnDef();
+ column1.setName(bytes(42))
+ .setValidation_class(UTF8Type.instance.toString());
+
+ ColumnDef column2 = new ColumnDef();
+ column2.setName(bytes(25))
+ .setValidation_class(UTF8Type.instance.toString());
+
+ CfDef cf = new CfDef("thriftks", "staticcompact");
+ cf.setColumn_type("Standard")
+ .setComparator_type(Int32Type.instance.toString())
+ .setDefault_validation_class(UTF8Type.instance.toString())
+ .setKey_validation_class(BytesType.instance.toString())
+ .setColumn_metadata(Arrays.asList(column1, column2));
+
+ SchemaLoader.createKeyspace("thriftks", KeyspaceParams.simple(1), ThriftConversion.fromThrift(cf));
+ CFMetaData cfm = Schema.instance.getCFMetaData("thriftks", "staticcompact");
+
+ // assert the both columns are in the metadata
+ assertTrue(cfm.getColumnMetadata().containsKey(bytes(42)));
+ assertTrue(cfm.getColumnMetadata().containsKey(bytes(25)));
+
+ // remove column2
+ cf.setColumn_metadata(Collections.singletonList(column1));
+ MigrationManager.announceColumnFamilyUpdate(ThriftConversion.fromThriftForUpdate(cf, cfm), true);
+
+ // assert that it's gone from metadata
+ assertTrue(cfm.getColumnMetadata().containsKey(bytes(42)));
+ assertFalse(cfm.getColumnMetadata().containsKey(bytes(25)));
+ }
+
+ private static UntypedResultSet execute(String query)
+ {
+ return QueryProcessor.executeInternal(query);
+ }
}