cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r800573 - in /incubator/cassandra/trunk: conf/ src/java/org/apache/cassandra/db/marshal/
Date Mon, 03 Aug 2009 21:27:05 GMT
Author: jbellis
Date: Mon Aug  3 21:27:04 2009
New Revision: 800573

URL: http://svn.apache.org/viewvc?rev=800573&view=rev
Log:
Rename UUIDType to LexicalUUIDType and add TimeUUIDType.
patch by jbellis; reviewed by Michael Koziarski for CASSANDRA-334

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
      - copied, changed from r800561, incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
Removed:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java
Modified:
    incubator/cassandra/trunk/conf/storage-conf.xml
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java

Modified: incubator/cassandra/trunk/conf/storage-conf.xml
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/conf/storage-conf.xml?rev=800573&r1=800572&r2=800573&view=diff
==============================================================================
--- incubator/cassandra/trunk/conf/storage-conf.xml (original)
+++ incubator/cassandra/trunk/conf/storage-conf.xml Mon Aug  3 21:27:04 2009
@@ -54,13 +54,20 @@
                  The CompareWith attribute tells Cassandra how to sort the columns
                  for slicing operations.  For backwards compatibility, the default 
                  is to use AsciiType, which is probably NOT what you want.
-                 Other options are BytesType, UTF8Type, UUIDType, and LongType.
+                 Other options are BytesType, UTF8Type, LexicalUUIDType, TimeUUIDType, and
LongType.
                  You can also specify the fully-qualified class name to a class
                  of your choice implementing org.apache.cassandra.db.marshal.IType.
 
                  SuperColumns have a similar CompareSubcolumnsWith attribute.
 
-                 (So to get the closest approximation to 0.3-style supercolumns,
+                 ByteType: simple sort by byte value.  No validation is performed.
+                 AsciiType: like BytesType, but validates that the input can be parsed as
US-ASCII.
+                 UTF8Type: A string encoded as UTF8
+                 LongType: A 64bit long
+                 LexicalUUIDType: a 128bit UUID, compared lexically (by byte value)
+                 TimeUUIDType: a 128bit version 1 UUID, compared by timestamp
+
+                 (To get the closest approximation to 0.3-style supercolumns,
                  you would use CompareWith=UTF8Type CompareSubcolumnsWith=LongType.)
 
                  if FlushPeriodInMinutes is configured and positive, it will be

Copied: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
(from r800561, incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java)
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java?p2=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java&p1=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java&r1=800561&r2=800573&rev=800573&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UUIDType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
Mon Aug  3 21:27:04 2009
@@ -3,9 +3,9 @@
 import java.util.UUID;
 import java.nio.ByteBuffer;
 
-public class UUIDType extends AbstractType
+public class LexicalUUIDType extends AbstractType
 {
-    private UUID getUUID(byte[] bytes)
+    static UUID getUUID(byte[] bytes)
     {
         ByteBuffer bb = ByteBuffer.wrap(bytes);
         return new UUID(bb.getLong(), bb.getLong());
@@ -27,6 +27,10 @@
 
     public String getString(byte[] bytes)
     {
+        if (bytes.length != 16)
+        {
+            throw new MarshalException("UUIDs must be exactly 16 bytes");
+        }
         return getUUID(bytes).toString();
     }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java?rev=800573&r1=800572&r2=800573&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java Mon Aug
 3 21:27:04 2009
@@ -23,6 +23,10 @@
 
     public String getString(byte[] bytes)
     {
+        if (bytes.length != 8)
+        {
+            throw new MarshalException("A long is exactly 8 bytes");
+        }
         return String.valueOf(ByteBuffer.wrap(bytes).getLong());
     }
 }

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java?rev=800573&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java (added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java Mon
Aug  3 21:27:04 2009
@@ -0,0 +1,28 @@
+package org.apache.cassandra.db.marshal;
+
+import java.util.UUID;
+import java.nio.ByteBuffer;
+
+public class TimeUUIDType extends AbstractType
+{
+    public int compare(byte[] o1, byte[] o2)
+    {
+        long t1 = LexicalUUIDType.getUUID(o1).timestamp();
+        long t2 = LexicalUUIDType.getUUID(o2).timestamp();
+        return t1 < t2 ? -1 : (t1 > t2 ? 1 : 0);
+    }
+
+    public String getString(byte[] bytes)
+    {
+        if (bytes.length != 16)
+        {
+            throw new MarshalException("UUIDs must be exactly 16 bytes");
+        }
+        UUID uuid = LexicalUUIDType.getUUID(bytes);
+        if (uuid.version() != 1)
+        {
+            throw new MarshalException("TimeUUID only makes sense with version 1 UUIDs");
+        }
+        return uuid.toString();
+    }
+}



Mime
View raw message