cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1137553 - in /cassandra/trunk/src/java/org/apache/cassandra/db: ColumnSerializer.java CounterColumn.java ExpiringColumn.java
Date Mon, 20 Jun 2011 09:05:03 GMT
Author: slebresne
Date: Mon Jun 20 09:05:02 2011
New Revision: 1137553

URL: http://svn.apache.org/viewvc?rev=1137553&view=rev
Log:
Move column creation logic into factory methods
patch by stuhood; reviewed by slebresne for CASSANDRA-2679

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java
    cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java
    cassandra/trunk/src/java/org/apache/cassandra/db/ExpiringColumn.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java?rev=1137553&r1=1137552&r2=1137553&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java Mon Jun 20 09:05:02
2011
@@ -96,9 +96,7 @@ public class ColumnSerializer implements
             long timestampOfLastDelete = dis.readLong();
             long ts = dis.readLong();
             ByteBuffer value = ByteBufferUtil.readWithLength(dis);
-            if (fromRemote)
-                value = CounterContext.instance().clearAllDelta(value);
-            return new CounterColumn(name, value, ts, timestampOfLastDelete);
+            return CounterColumn.create(name, value, ts, timestampOfLastDelete, fromRemote);
         }
         else if ((b & EXPIRATION_MASK) != 0)
         {
@@ -106,19 +104,7 @@ public class ColumnSerializer implements
             int expiration = dis.readInt();
             long ts = dis.readLong();
             ByteBuffer value = ByteBufferUtil.readWithLength(dis);
-            if (expiration < expireBefore)
-            {
-                // the column is now expired, we can safely return a simple
-                // tombstone
-                ByteBuffer bytes = ByteBuffer.allocate(4);
-                bytes.putInt(expiration);
-                bytes.rewind();
-                return new DeletedColumn(name, bytes, ts);
-            }
-            else
-            {
-                return new ExpiringColumn(name, value, ts, ttl, expiration);
-            }
+            return ExpiringColumn.create(name, value, ts, ttl, expiration, expireBefore);
         }
         else
         {

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java?rev=1137553&r1=1137552&r2=1137553&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/CounterColumn.java Mon Jun 20 09:05:02
2011
@@ -69,6 +69,13 @@ public class CounterColumn extends Colum
         this.timestampOfLastDelete = timestampOfLastDelete;
     }
 
+    public static CounterColumn create(ByteBuffer name, ByteBuffer value, long timestamp,
long timestampOfLastDelete, boolean fromRemote)
+    {
+        if (fromRemote)
+            value = CounterContext.instance().clearAllDelta(value);
+        return new CounterColumn(name, value, timestamp, timestampOfLastDelete);
+    }
+
     public long timestampOfLastDelete()
     {
         return timestampOfLastDelete;

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ExpiringColumn.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ExpiringColumn.java?rev=1137553&r1=1137552&r2=1137553&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ExpiringColumn.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ExpiringColumn.java Mon Jun 20 09:05:02
2011
@@ -57,6 +57,15 @@ public class ExpiringColumn extends Colu
         this.localExpirationTime = localExpirationTime;
     }
 
+    /** @return Either a DeletedColumn, or an ExpiringColumn. */
+    public static Column create(ByteBuffer name, ByteBuffer value, long timestamp, int timeToLive,
int localExpirationTime, int expireBefore)
+    {
+        if (localExpirationTime >= expireBefore)
+            return new ExpiringColumn(name, value, timestamp, timeToLive, localExpirationTime);
+        // the column is now expired, we can safely return a simple tombstone
+        return new DeletedColumn(name, localExpirationTime, timestamp);
+    }
+
     public int getTimeToLive()
     {
         return timeToLive;



Mime
View raw message