cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r986097 - in /cassandra/trunk: CHANGES.txt src/java/org/apache/cassandra/db/marshal/LongType.java test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java
Date Mon, 16 Aug 2010 19:05:00 GMT
Author: jbellis
Date: Mon Aug 16 19:05:00 2010
New Revision: 986097

URL: http://svn.apache.org/viewvc?rev=986097&view=rev
Log:
faster LongType comparisons.  patch by Folke Behrens; reviewed by jbellis for CASSANDRA-1393

Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=986097&r1=986096&r2=986097&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Mon Aug 16 19:05:00 2010
@@ -9,6 +9,7 @@ dev
    to SimpleStrategy, DatacenterShardStrategy to NetworkTopologyStrategy,
    AbstractRackAwareSnitch to AbstractNetworkTopologySnitch (CASSANDRA-1392)
  * merge StorageProxy.mutate, mutateBlocking (CASSANDRA-1396)
+ * faster UUIDType, LongType comparisons (CASSANDRA-1368, 1393)
 
 
 0.7-beta1

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java?rev=986097&r1=986096&r2=986097&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java Mon Aug 16 19:05:00
2010
@@ -22,7 +22,8 @@ package org.apache.cassandra.db.marshal;
 
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
+
+import org.apache.cassandra.utils.FBUtilities;
 
 public class LongType extends AbstractType
 {
@@ -41,9 +42,10 @@ public class LongType extends AbstractTy
             return 1;
         }
 
-        long L1 = ByteBuffer.wrap(o1).getLong();
-        long L2 = ByteBuffer.wrap(o2).getLong();
-        return Long.valueOf(L1).compareTo(Long.valueOf(L2));
+        int diff = o1[0] - o2[0];
+        if (diff != 0)
+            return diff;
+        return FBUtilities.compareByteArrays(o1, o2);
     }
 
     public String getString(byte[] bytes)

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java?rev=986097&r1=986096&r2=986097&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/marshal/TypeCompareTest.java Mon Aug
16 19:05:00 2010
@@ -23,6 +23,8 @@ package org.apache.cassandra.db.marshal;
 
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.Random;
 import java.util.UUID;
 
 import org.apache.commons.lang.ArrayUtils;
@@ -69,6 +71,27 @@ public class TypeCompareTest
     }
 
     @Test
+    public void testLong()
+    {
+        Random rng = new Random();
+        byte[][] data = new byte[1000][];
+        for (int i = 0; i < data.length; i++)
+        {
+            data[i] = new byte[8];
+            rng.nextBytes(data[i]);
+        }
+
+        Arrays.sort(data, LongType.instance);
+
+        for (int i = 1; i < data.length; i++)
+        {
+            long l0 = ByteBuffer.wrap(data[i - 1]).getLong();
+            long l1 = ByteBuffer.wrap(data[i]).getLong();
+            assert l0 <= l1;
+        }
+    }
+
+    @Test
     public void testTimeUUID()
     {
         // two different UUIDs w/ the same timestamp



Mime
View raw message