You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by sl...@apache.org on 2015/07/07 12:23:13 UTC
cassandra git commit: Fix PartitionUpdate sorting/merging code
Repository: cassandra
Updated Branches:
refs/heads/trunk 43c27e99f -> 87c6daf6e
Fix PartitionUpdate sorting/merging code
patch by slebresne; reviewed by iamaleksey for CASSANDRA-9743
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/87c6daf6
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/87c6daf6
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/87c6daf6
Branch: refs/heads/trunk
Commit: 87c6daf6e3d64b532bcdca09f6de22c3b6f56bf7
Parents: 43c27e9
Author: Sylvain Lebresne <sy...@datastax.com>
Authored: Tue Jul 7 12:22:26 2015 +0200
Committer: Sylvain Lebresne <sy...@datastax.com>
Committed: Tue Jul 7 12:22:26 2015 +0200
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../db/partitions/AbstractPartitionData.java | 19 ++++++
.../db/partitions/PartitionUpdate.java | 4 +-
.../validation/entities/RowBuilderTest.java | 69 ++++++++++++++++++++
4 files changed, 91 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/87c6daf6/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 450138c..53beb26 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
3.0
+ * Storage engine refactor (CASSANDRA-8099, 9743)
* 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/87c6daf6/src/java/org/apache/cassandra/db/partitions/AbstractPartitionData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/partitions/AbstractPartitionData.java b/src/java/org/apache/cassandra/db/partitions/AbstractPartitionData.java
index 2fcd7b3..6775cf1 100644
--- a/src/java/org/apache/cassandra/db/partitions/AbstractPartitionData.java
+++ b/src/java/org/apache/cassandra/db/partitions/AbstractPartitionData.java
@@ -227,6 +227,25 @@ public abstract class AbstractPartitionData implements Partition, Iterable<Row>
data.swap(i, j);
}
+ protected void merge(int i, int j, int nowInSec)
+ {
+ data.merge(i, j, nowInSec);
+ if (livenessInfos.timestamp(i) > livenessInfos.timestamp(j))
+ livenessInfos.move(i, j);
+ if (deletions.supersedes(i, j))
+ deletions.move(i, j);
+ }
+
+ protected void move(int i, int j)
+ {
+ int cs = metadata.clusteringColumns().size();
+ for (int k = 0; k < cs; k++)
+ clusterings[j * cs + k] = clusterings[i * cs + k];
+ data.move(i, j);
+ livenessInfos.move(i, j);
+ deletions.move(i, j);
+ }
+
public int rowCount()
{
return rows;
http://git-wip-us.apache.org/repos/asf/cassandra/blob/87c6daf6/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 f4195c1..a1ee239 100644
--- a/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java
+++ b/src/java/org/apache/cassandra/db/partitions/PartitionUpdate.java
@@ -488,14 +488,14 @@ public class PartitionUpdate extends AbstractPartitionData implements Sorting.So
{
// current and previous are the same row. Merge current into previous
// (and so previous + 1 will be "free").
- data.merge(current, previous, nowInSec);
+ merge(current, previous, nowInSec);
}
else
{
// data[current] != [previous], so move current just after previous if needs be
++previous;
if (previous != current)
- data.move(current, previous);
+ move(current, previous);
}
}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/87c6daf6/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
new file mode 100644
index 0000000..7ab71b1
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/RowBuilderTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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();
+ }
+}