cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xe...@apache.org
Subject [1/2] git commit: Fix RowIndexEntry to report correct serializedSize patch by Pavel Yaskevich; reviewed by Aleksey Yeschenko for CASSANDRA-7948
Date Thu, 18 Sep 2014 05:35:09 GMT
Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 ad89d4437 -> 8026163de


Fix RowIndexEntry to report correct serializedSize
patch by Pavel Yaskevich; reviewed by Aleksey Yeschenko for CASSANDRA-7948


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/85aa794e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/85aa794e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/85aa794e

Branch: refs/heads/cassandra-2.1
Commit: 85aa794e1f7ff4323a6dde0b088e0cb9e1dd3f21
Parents: 05920cb
Author: Pavel Yaskevich <xedin@apache.org>
Authored: Tue Sep 16 16:33:44 2014 -0700
Committer: Pavel Yaskevich <xedin@apache.org>
Committed: Wed Sep 17 22:19:21 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/db/RowIndexEntry.java  | 14 ++++-
 .../apache/cassandra/db/RowIndexEntryTest.java  | 64 ++++++++++++++++++++
 3 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/85aa794e/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 3ee938a..58c6647 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -11,6 +11,7 @@
  * Always send Paxos commit to all replicas (CASSANDRA-7479)
  * Make disruptor_thrift_server invocation pool configurable (CASSANDRA-7594)
  * Make repair no-op when RF=1 (CASSANDRA-7864)
+ * Fix RowIndexEntry to report correct serializedSize (CASSANDRA-7948)
 Merged from 1.2:
  * Don't index tombstones (CASSANDRA-7828)
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85aa794e/src/java/org/apache/cassandra/db/RowIndexEntry.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/RowIndexEntry.java b/src/java/org/apache/cassandra/db/RowIndexEntry.java
index cfc7cf1..cdafd5d 100644
--- a/src/java/org/apache/cassandra/db/RowIndexEntry.java
+++ b/src/java/org/apache/cassandra/db/RowIndexEntry.java
@@ -45,7 +45,19 @@ public class RowIndexEntry implements IMeasurableMemory
 
     public int serializedSize()
     {
-        return TypeSizes.NATIVE.sizeof(position) + promotedSize();
+        int size = TypeSizes.NATIVE.sizeof(position) + TypeSizes.NATIVE.sizeof(promotedSize());
+
+        if (isIndexed())
+        {
+            List<IndexHelper.IndexInfo> index = columnsIndex();
+
+            size += DeletionTime.serializer.serializedSize(deletionTime(), TypeSizes.NATIVE);
+            size += TypeSizes.NATIVE.sizeof(index.size());
+            for (IndexHelper.IndexInfo info : index)
+                size += info.serializedSize(TypeSizes.NATIVE);
+        }
+
+        return size;
     }
 
     protected int promotedSize()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/85aa794e/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java b/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
new file mode 100644
index 0000000..9728f1f
--- /dev/null
+++ b/test/unit/org/apache/cassandra/db/RowIndexEntryTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.db;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+import org.apache.cassandra.SchemaLoader;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.io.util.DataOutputBuffer;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
+import org.junit.Test;
+
+public class RowIndexEntryTest extends SchemaLoader
+{
+    @Test
+    public void testSerializedSize() throws IOException
+    {
+        final RowIndexEntry simple = new RowIndexEntry(123);
+
+        DataOutputBuffer buffer = new DataOutputBuffer();
+        RowIndexEntry.serializer.serialize(simple, buffer);
+
+        Assert.assertEquals(buffer.size(), simple.serializedSize());
+
+        buffer = new DataOutputBuffer();
+        ColumnFamily cf = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1");
+        ColumnIndex columnIndex = new ColumnIndex.Builder(cf, ByteBufferUtil.bytes("a"),
new DataOutputBuffer())
+        {{
+            int idx = 0, size = 0;
+            Column column;
+            do
+            {
+                column = new Column(ByteBufferUtil.bytes("c" + idx++), ByteBufferUtil.bytes("v"),
FBUtilities.timestampMicros());
+                size += column.serializedSize(TypeSizes.NATIVE);
+
+                add(column);
+            }
+            while (size < DatabaseDescriptor.getColumnIndexSize() * 3);
+
+        }}.build();
+
+        RowIndexEntry withIndex = RowIndexEntry.create(0xdeadbeef, DeletionTime.LIVE, columnIndex);
+
+        RowIndexEntry.serializer.serialize(withIndex, buffer);
+        Assert.assertEquals(buffer.size(), withIndex.serializedSize());
+    }
+}


Mime
View raw message