cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bened...@apache.org
Subject [2/3] cassandra git commit: Cleanup cell equality
Date Wed, 18 Mar 2015 11:01:13 GMT
Cleanup cell equality

patch by benedict; reviewed by sylvain for CASSANDRA-8947


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

Branch: refs/heads/trunk
Commit: 69ffd1fa01dd9a5b7118cbcaf63dd2dffc1fa508
Parents: 8284964
Author: Benedict Elliott Smith <benedict@apache.org>
Authored: Wed Mar 18 11:00:29 2015 +0000
Committer: Benedict Elliott Smith <benedict@apache.org>
Committed: Wed Mar 18 11:00:29 2015 +0000

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../org/apache/cassandra/db/AbstractCell.java   |  3 +-
 .../apache/cassandra/db/BufferCounterCell.java  |  7 +---
 .../apache/cassandra/db/BufferDeletedCell.java  |  5 ---
 .../apache/cassandra/db/BufferExpiringCell.java | 13 ++----
 .../apache/cassandra/db/NativeCounterCell.java  |  8 +---
 .../apache/cassandra/db/NativeDeletedCell.java  |  6 ---
 .../apache/cassandra/db/NativeExpiringCell.java | 13 ++----
 test/unit/org/apache/cassandra/db/CellTest.java | 44 ++++++++++++++++++++
 9 files changed, 58 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 68df77e..2af8df6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.1.4
+ * Cleanup cell equality (CASSANDRA-8947)
  * Introduce intra-cluster message coalescing (CASSANDRA-8692)
  * DatabaseDescriptor throws NPE when rpc_interface is used (CASSANDRA-8839)
  * Don't check if an sstable is live for offline compactions (CASSANDRA-8841)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/AbstractCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/AbstractCell.java b/src/java/org/apache/cassandra/db/AbstractCell.java
index f27871f..37d483f 100644
--- a/src/java/org/apache/cassandra/db/AbstractCell.java
+++ b/src/java/org/apache/cassandra/db/AbstractCell.java
@@ -136,7 +136,8 @@ public abstract class AbstractCell implements Cell
 
     public boolean equals(Cell cell)
     {
-        return timestamp() == cell.timestamp() && name().equals(cell.name()) &&
value().equals(cell.value());
+        return timestamp() == cell.timestamp() && name().equals(cell.name()) &&
value().equals(cell.value())
+               && serializationFlags() == cell.serializationFlags();
     }
 
     public int hashCode()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/BufferCounterCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/BufferCounterCell.java b/src/java/org/apache/cassandra/db/BufferCounterCell.java
index bdd97a7..827182a 100644
--- a/src/java/org/apache/cassandra/db/BufferCounterCell.java
+++ b/src/java/org/apache/cassandra/db/BufferCounterCell.java
@@ -171,11 +171,6 @@ public class BufferCounterCell extends BufferCell implements CounterCell
     @Override
     public boolean equals(Cell cell)
     {
-        return cell instanceof CounterCell && equals((CounterCell) cell);
-    }
-
-    public boolean equals(CounterCell cell)
-    {
-        return super.equals(cell) && timestampOfLastDelete == cell.timestampOfLastDelete();
+        return super.equals(cell) && timestampOfLastDelete == ((CounterCell) cell).timestampOfLastDelete();
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/BufferDeletedCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/BufferDeletedCell.java b/src/java/org/apache/cassandra/db/BufferDeletedCell.java
index bcc170f..a38f322 100644
--- a/src/java/org/apache/cassandra/db/BufferDeletedCell.java
+++ b/src/java/org/apache/cassandra/db/BufferDeletedCell.java
@@ -107,11 +107,6 @@ public class BufferDeletedCell extends BufferCell implements DeletedCell
             throw new MarshalException("The local deletion time should not be negative");
     }
 
-    public boolean equals(Cell cell)
-    {
-        return timestamp() == cell.timestamp() && getLocalDeletionTime() == cell.getLocalDeletionTime()
&& name().equals(cell.name());
-    }
-
     @Override
     public void updateDigest(MessageDigest digest)
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/BufferExpiringCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/BufferExpiringCell.java b/src/java/org/apache/cassandra/db/BufferExpiringCell.java
index 347604a..25172c8 100644
--- a/src/java/org/apache/cassandra/db/BufferExpiringCell.java
+++ b/src/java/org/apache/cassandra/db/BufferExpiringCell.java
@@ -167,15 +167,10 @@ public class BufferExpiringCell extends BufferCell implements ExpiringCell
     @Override
     public boolean equals(Cell cell)
     {
-        return cell instanceof ExpiringCell && equals((ExpiringCell) cell);
-    }
-
-    public boolean equals(ExpiringCell cell)
-    {
-        // super.equals() returns false if o is not a CounterCell
-        return super.equals(cell)
-               && getLocalDeletionTime() == cell.getLocalDeletionTime()
-               && getTimeToLive() == cell.getTimeToLive();
+        if (!super.equals(cell))
+            return false;
+        ExpiringCell that = (ExpiringCell) cell;
+        return getLocalDeletionTime() == that.getLocalDeletionTime() && getTimeToLive()
== that.getTimeToLive();
     }
 
     /** @return Either a DeletedCell, or an ExpiringCell. */

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/NativeCounterCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/NativeCounterCell.java b/src/java/org/apache/cassandra/db/NativeCounterCell.java
index 3fe73ce..c16cc44 100644
--- a/src/java/org/apache/cassandra/db/NativeCounterCell.java
+++ b/src/java/org/apache/cassandra/db/NativeCounterCell.java
@@ -178,13 +178,9 @@ public class NativeCounterCell extends NativeCell implements CounterCell
         return SIZE;
     }
 
+    @Override
     public boolean equals(Cell cell)
     {
-        return cell instanceof CounterCell && equals((CounterCell) cell);
-    }
-
-    public boolean equals(CounterCell cell)
-    {
-        return super.equals(cell) && timestampOfLastDelete() == cell.timestampOfLastDelete();
+        return super.equals(cell) && timestampOfLastDelete() == ((CounterCell) cell).timestampOfLastDelete();
     }
 }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/NativeDeletedCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/NativeDeletedCell.java b/src/java/org/apache/cassandra/db/NativeDeletedCell.java
index e900635..6bdef43 100644
--- a/src/java/org/apache/cassandra/db/NativeDeletedCell.java
+++ b/src/java/org/apache/cassandra/db/NativeDeletedCell.java
@@ -106,12 +106,6 @@ public class NativeDeletedCell extends NativeCell implements DeletedCell
     }
 
     @Override
-    public boolean equals(Cell cell)
-    {
-        return timestamp() == cell.timestamp() && getLocalDeletionTime() == cell.getLocalDeletionTime()
&& name().equals(cell.name());
-    }
-
-    @Override
     public long unsharedHeapSizeExcludingData()
     {
         return SIZE;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/src/java/org/apache/cassandra/db/NativeExpiringCell.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/NativeExpiringCell.java b/src/java/org/apache/cassandra/db/NativeExpiringCell.java
index d97e080..6369536 100644
--- a/src/java/org/apache/cassandra/db/NativeExpiringCell.java
+++ b/src/java/org/apache/cassandra/db/NativeExpiringCell.java
@@ -152,15 +152,10 @@ public class NativeExpiringCell extends NativeCell implements ExpiringCell
 
     public boolean equals(Cell cell)
     {
-        return cell instanceof ExpiringCell && equals((ExpiringCell) cell);
-    }
-
-    protected boolean equals(ExpiringCell cell)
-    {
-        // super.equals() returns false if o is not a CounterCell
-        return super.equals(cell)
-                && getLocalDeletionTime() == cell.getLocalDeletionTime()
-                && getTimeToLive() == cell.getTimeToLive();
+        if (!super.equals(cell))
+            return false;
+        ExpiringCell that = (ExpiringCell) cell;
+        return getLocalDeletionTime() == that.getLocalDeletionTime() && getTimeToLive()
== that.getTimeToLive();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cassandra/blob/69ffd1fa/test/unit/org/apache/cassandra/db/CellTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/CellTest.java b/test/unit/org/apache/cassandra/db/CellTest.java
index 63d6f4c..493dbbf 100644
--- a/test/unit/org/apache/cassandra/db/CellTest.java
+++ b/test/unit/org/apache/cassandra/db/CellTest.java
@@ -21,6 +21,8 @@ package org.apache.cassandra.db;
  */
 
 
+import java.nio.ByteBuffer;
+
 import org.junit.Test;
 
 import junit.framework.Assert;
@@ -37,6 +39,29 @@ public class CellTest
     private static NativeAllocator allocator = new NativePool(Integer.MAX_VALUE, Integer.MAX_VALUE,
1f, null).newAllocator();
 
     @Test
+    public void testConflictingTypeEquality()
+    {
+        boolean[] tf = new boolean[]{ true, false };
+        for (boolean lhs : tf)
+        {
+            for (boolean rhs : tf)
+            {
+                // don't test equality for both sides native, as this is based on CellName
resolution
+                if (lhs && rhs)
+                    continue;
+                Cell a = expiring("a", "a", 1, 1, lhs);
+                Cell b = regular("a", "a", 1, rhs);
+                Assert.assertNotSame(a, b);
+                Assert.assertNotSame(b, a);
+                a = deleted("a", 1, 1, lhs);
+                b = regular("a", ByteBufferUtil.bytes(1), 1, rhs);
+                Assert.assertNotSame(a, b);
+                Assert.assertNotSame(b, a);
+            }
+        }
+    }
+
+    @Test
     public void testExpiringCellReconile()
     {
         // equal
@@ -94,4 +119,23 @@ public class CellTest
         return cell;
     }
 
+    private Cell regular(String name, ByteBuffer value, long timestamp, boolean nativeCell)
+    {
+        Cell cell = new BufferCell(Util.cellname(name), value, timestamp);
+        if (nativeCell)
+            cell = new NativeCell(allocator, order.getCurrent(), cell);
+        return cell;
+    }
+    private Cell regular(String name, String value, long timestamp, boolean nativeCell)
+    {
+        return regular(name, ByteBufferUtil.bytes(value), timestamp, nativeCell);
+    }
+
+    private Cell deleted(String name, int localDeletionTime, long timestamp, boolean nativeCell)
+    {
+        DeletedCell cell = new BufferDeletedCell(Util.cellname(name), localDeletionTime,
timestamp);
+        if (nativeCell)
+            cell = new NativeDeletedCell(allocator, order.getCurrent(), cell);
+        return cell;
+    }
 }


Mime
View raw message