cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r771935 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/db: Column.java ColumnFamily.java ColumnFamilyStore.java SuperColumn.java
Date Tue, 05 May 2009 17:03:26 GMT
Author: jbellis
Date: Tue May  5 17:03:25 2009
New Revision: 771935

URL: http://svn.apache.org/viewvc?rev=771935&view=rev
Log:
tombstones take priority over non-tombstones w/ the same timestamp in supercolumn and column.
 this makes HH management deterministic.
patch by jbellis; reviewed by Jun Rao for CASSANDRA-34

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java?rev=771935&r1=771934&r2=771935&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java Tue May  5 17:03:25
2009
@@ -198,6 +198,17 @@
         assert isMarkedForDelete;
         return ByteBuffer.wrap(value).getInt();
     }
+
+    // note that we do not call this simply compareTo since it also makes sense to compare
Columns by name
+    public long comparePriority(Column o)
+    {
+        if (isMarkedForDelete)
+        {
+            // tombstone always wins ties.
+            return timestamp < o.timestamp ? -1 : 1;
+        }
+        return timestamp - o.timestamp;
+    }
 }
 
 class ColumnSerializer implements ICompactSerializer2<IColumn>
@@ -302,5 +313,6 @@
         int size = dis.readInt();
         dis.skip(size);
     }
+
 }
 

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java?rev=771935&r1=771934&r2=771935&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamily.java Tue May 
5 17:03:25 2009
@@ -266,7 +266,7 @@
             }
             else
             {
-                if (oldColumn.timestamp() <= column.timestamp())
+                if (((Column)oldColumn).comparePriority((Column)column) <= 0)
                 {
                     columns_.put(name, column);
                     size_.addAndGet(column.size());

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=771935&r1=771934&r2=771935&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue
May  5 17:03:25 2009
@@ -615,19 +615,25 @@
         if (cf == null)
             return null;
 
+        // in case of a timestamp tie, tombstones get priority over non-tombstones.
+        // we want this to be deterministic in general to avoid confusion;
+        // either way (tombstone or non- getting priority) would be fine,
+        // but we picked this way because it makes removing delivered hints
+        // easier for HintedHandoffManager.
         for (String cname : new ArrayList<String>(cf.getColumns().keySet()))
         {
             IColumn c = cf.getColumns().get(cname);
             if (c instanceof SuperColumn)
             {
                 long minTimestamp = Math.max(c.getMarkedForDeleteAt(), cf.getMarkedForDeleteAt());
-                // don't operate directly on the supercolumn, it could be the one in the
memtable
+                // don't operate directly on the supercolumn, it could be the one in the
memtable.
+                // instead, create a new SC and add in the subcolumns that qualify.
                 cf.remove(cname);
                 SuperColumn sc = new SuperColumn(cname);
                 sc.markForDeleteAt(c.getLocalDeletionTime(), c.getMarkedForDeleteAt());
                 for (IColumn subColumn : c.getSubColumns())
                 {
-                    if (subColumn.timestamp() >= minTimestamp)
+                    if (subColumn.timestamp() > minTimestamp)
                     {
                         if (!subColumn.isMarkedForDelete() || subColumn.getLocalDeletionTime()
> gcBefore)
                         {

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java?rev=771935&r1=771934&r2=771935&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java Tue May  5
17:03:25 2009
@@ -176,8 +176,8 @@
 
     public void addColumn(String name, IColumn column)
     {
-    	if ( column instanceof SuperColumn )
-    		throw new UnsupportedOperationException("A super column cannot hold other super columns.");
+    	if (!(column instanceof Column))
+    		throw new UnsupportedOperationException("A super column can only contain simple columns.");
     	IColumn oldColumn = columns_.get(name);
     	if ( oldColumn == null )
         {
@@ -186,7 +186,7 @@
         }
     	else
     	{
-    		if ( oldColumn.timestamp() <= column.timestamp() )
+    		if (((Column)oldColumn).comparePriority((Column)column) <= 0)
             {
     			columns_.put(name, column);
                 int delta = (-1)*oldColumn.size();



Mime
View raw message