Repository: cassandra Updated Branches: refs/heads/trunk 7dff15011 -> 87ea6bc91
Fix PartitionUpdate.rowCount patch by slebresne; reviewed by iamaleksey for CASSANDRA-9746 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/87ea6bc9 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/87ea6bc9 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/87ea6bc9 Branch: refs/heads/trunk Commit: 87ea6bc9138a4354ccdd2860463cec3e0e55e90f Parents: 7dff150 Author: Sylvain Lebresne <[email protected]> Authored: Mon Jul 13 12:23:41 2015 +0200 Committer: Sylvain Lebresne <[email protected]> Committed: Mon Jul 13 12:23:41 2015 +0200 ---------------------------------------------------------------------- CHANGES.txt | 2 +- .../db/partitions/PartitionUpdate.java | 7 ++ .../validation/entities/RowBuilderTest.java | 69 ----------------- .../entities/RowUpdateBuilderTest.java | 79 ++++++++++++++++++++ 4 files changed, 87 insertions(+), 70 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/87ea6bc9/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index b978c59..17d8f8a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,7 +1,7 @@ 3.0 * 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) + * Storage engine refactor (CASSANDRA-8099, 9743, 9746) * 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/87ea6bc9/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java b/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java index a1ee239..670b1ae 100644 --- a/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java +++ b/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java @@ -331,6 +331,13 @@ public class PartitionUpdate extends AbstractPartitionData implements Sorting.So isSorted = false; } + @Override + public int rowCount() + { + maybeSort(); + return super.rowCount(); + } + /** * Returns an iterator that iterators over the rows of this update in clustering order. * <p> http://git-wip-us.apache.org/repos/asf/cassandra/blob/87ea6bc9/test/unit/org/apache/cassandra/cql3/validation/entities/RowBuilderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/RowBuilderTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/RowBuilderTest.java deleted file mode 100644 index 7ab71b1..0000000 --- a/test/unit/org/apache/cassandra/cql3/validation/entities/RowBuilderTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.cassandra.cql3.validation.entities; - -import org.junit.Test; - -import org.apache.cassandra.cql3.CQLTester; -import org.apache.cassandra.db.Mutation; -import org.apache.cassandra.db.RowUpdateBuilder; -import org.apache.cassandra.db.partitions.PartitionUpdate; -import org.apache.cassandra.db.marshal.AsciiType; -import org.apache.cassandra.service.StorageService; -import org.apache.cassandra.utils.FBUtilities; - -public class RowBuilderTest extends CQLTester -{ - @Test - public void testAddListEntry() throws Throwable - { - createTable("CREATE TABLE %s (" - + "pk text," - + "ck text," - + "l1 list<int>," - + "l2 list<int>," - + "PRIMARY KEY ((pk), ck))"); - - long timestamp = FBUtilities.timestampMicros(); - - Mutation mutation = new Mutation(keyspace(), StorageService.getPartitioner().decorateKey(AsciiType.instance.fromString("test"))); - addToMutation("row1", timestamp, mutation); - addToMutation("row2", timestamp, mutation); - - for (PartitionUpdate update : mutation.getPartitionUpdates()) - update.iterator(); - - mutation.apply(); - - assertRowCount(execute("SELECT ck FROM %s"), 2); - } - - private void addToMutation(String typeName, long timestamp, Mutation mutation) - { - RowUpdateBuilder adder = new RowUpdateBuilder(getCurrentColumnFamilyStore().metadata, timestamp, mutation) - .clustering(typeName); - - for (int i = 0; i < 2; i++) - { - adder.addListEntry("l1", i) - .addListEntry("l2", i); - } - - adder.build(); - } -} http://git-wip-us.apache.org/repos/asf/cassandra/blob/87ea6bc9/test/unit/org/apache/cassandra/cql3/validation/entities/RowUpdateBuilderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/cql3/validation/entities/RowUpdateBuilderTest.java b/test/unit/org/apache/cassandra/cql3/validation/entities/RowUpdateBuilderTest.java new file mode 100644 index 0000000..afe2455 --- /dev/null +++ b/test/unit/org/apache/cassandra/cql3/validation/entities/RowUpdateBuilderTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cassandra.cql3.validation.entities; + +import org.junit.Test; + +import org.apache.cassandra.Util; +import org.apache.cassandra.cql3.CQLTester; +import org.apache.cassandra.db.Mutation; +import org.apache.cassandra.db.RowUpdateBuilder; +import org.apache.cassandra.utils.FBUtilities; + +// see CASSANDRA-9743, CASSANDRA-9746 +public class RowUpdateBuilderTest extends CQLTester +{ + @Test + public void testAddListEntryDurable() throws Throwable + { + testAddListEntry(false); + } + + @Test + public void testAddListEntryTransient() throws Throwable + { + testAddListEntry(true); + } + + public void testAddListEntry(boolean skipCommitLog) throws Throwable + { + createTable("CREATE TABLE %s (" + + "pk text," + + "ck text," + + "l1 list<int>," + + "l2 list<int>," + + "PRIMARY KEY ((pk), ck))"); + + long timestamp = FBUtilities.timestampMicros(); + + Mutation mutation = new Mutation(keyspace(), Util.dk("test")); + addToMutation("row1", timestamp, mutation); + addToMutation("row2", timestamp, mutation); + + if (skipCommitLog) + mutation.applyUnsafe(); + else + mutation.apply(); + + assertRowCount(execute("SELECT ck FROM %s"), 2); + } + + private void addToMutation(String typeName, long timestamp, Mutation mutation) + { + RowUpdateBuilder adder = new RowUpdateBuilder(getCurrentColumnFamilyStore().metadata, timestamp, mutation) + .clustering(typeName); + + for (int i = 0; i < 2; i++) + { + adder.addListEntry("l1", i) + .addListEntry("l2", i); + } + + adder.build(); + } +} \ No newline at end of file
