cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1153157 - in /cassandra/trunk: ./ contrib/ interface/thrift/gen-java/org/apache/cassandra/thrift/ src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/compaction/ src/java/org/apache/cassandra/db/context/ src/java/org/apache/...
Date Tue, 02 Aug 2011 15:05:53 GMT
Author: slebresne
Date: Tue Aug  2 15:05:50 2011
New Revision: 1153157

URL: http://svn.apache.org/viewvc?rev=1153157&view=rev
Log:
merge from 0.8

Modified:
    cassandra/trunk/   (props changed)
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/contrib/   (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java 
 (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java   (props
changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java
  (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java
  (props changed)
    cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java
  (props changed)
    cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
    cassandra/trunk/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
    cassandra/trunk/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java
    cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java
    cassandra/trunk/src/java/org/apache/cassandra/utils/NodeId.java
    cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/CounterMutationTest.java

Propchange: cassandra/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7:1026516-1151306
 /cassandra/branches/cassandra-0.7.0:1053690-1055654
-/cassandra/branches/cassandra-0.8:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0:1125021-1130369
 /cassandra/branches/cassandra-0.8.1:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3:1051699-1053689

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Tue Aug  2 15:05:50 2011
@@ -45,6 +45,7 @@
  * fix throwing exception with batch mutation of counter super columns
    (CASSANDRA-2949)
  * ignore system tables during repair (CASSANDRA-2979)
+ * fix assertion error during compaction of counter CFs (CASSANDRA-2968)
 
 
 0.8.2

Propchange: cassandra/trunk/contrib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/contrib:922689-1052356,1052358-1053452,1053454,1053456-1068009
 /cassandra/branches/cassandra-0.7/contrib:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/contrib:1053690-1055654
-/cassandra/branches/cassandra-0.8/contrib:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/contrib:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/contrib:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/contrib:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/contrib:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/Cassandra.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/Column.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/InvalidRequestException.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/NotFoundException.java:1051699-1053689

Propchange: cassandra/trunk/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 15:05:50 2011
@@ -1,7 +1,7 @@
 /cassandra/branches/cassandra-0.6/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:922689-1052356,1052358-1053452,1053454,1053456-1131291
 /cassandra/branches/cassandra-0.7/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1026516-1151306
 /cassandra/branches/cassandra-0.7.0/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1053690-1055654
-/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870
+/cassandra/branches/cassandra-0.8/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1090934-1125013,1125019-1152110,1152265,1152793,1152795,1152870,1153156
 /cassandra/branches/cassandra-0.8.0/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1125021-1130369
 /cassandra/branches/cassandra-0.8.1/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1101014-1125018
 /cassandra/tags/cassandra-0.7.0-rc3/interface/thrift/gen-java/org/apache/cassandra/thrift/SuperColumn.java:1051699-1053689

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/SystemTable.java Tue Aug  2 15:05:50
2011
@@ -404,9 +404,8 @@ public class SystemTable
      * table)
      * @param newNodeId the new current local node id to record
      */
-    public static void writeCurrentLocalNodeId(NodeId oldNodeId, NodeId newNodeId)
+    public static void writeCurrentLocalNodeId(NodeId oldNodeId, NodeId newNodeId, long now)
     {
-        long now = System.currentTimeMillis();
         ByteBuffer ip = ByteBuffer.wrap(FBUtilities.getBroadcastAddress().getAddress());
 
         ColumnFamily cf = ColumnFamily.create(Table.SYSTEM_TABLE, NODE_ID_CF);
@@ -441,7 +440,7 @@ public class SystemTable
         ColumnFamily cf = table.getColumnFamilyStore(NODE_ID_CF).getColumnFamily(filter);
 
         NodeId previous = null;
-        for (IColumn c : cf.getReverseSortedColumns())
+        for (IColumn c : cf)
         {
             if (previous != null)
                 l.add(new NodeId.NodeIdRecord(previous, c.timestamp()));

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/compaction/LazilyCompactedRow.java Tue
Aug  2 15:05:50 2011
@@ -192,7 +192,7 @@ public class LazilyCompactedRow extends 
             assert container != null;
             IColumn reduced = container.iterator().next();
             ColumnFamily purged = shouldPurge ? ColumnFamilyStore.removeDeleted(container,
controller.gcBefore) : container;
-            if (purged != null && purged.metadata().getDefaultValidator().isCommutative())
+            if (shouldPurge && purged != null && purged.metadata().getDefaultValidator().isCommutative())
             {
                 CounterColumn.removeOldShards(purged, controller.gcBefore);
             }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/compaction/PrecompactedRow.java Tue Aug
 2 15:05:50 2011
@@ -82,8 +82,9 @@ public class PrecompactedRow extends Abs
                 cf.addAll(thisCF);
             }
         }
-        compactedCf = controller.shouldPurge(key) ? ColumnFamilyStore.removeDeleted(cf, controller.gcBefore)
: cf;
-        if (compactedCf != null && compactedCf.metadata().getDefaultValidator().isCommutative())
+        boolean shouldPurge = controller.shouldPurge(key);
+        compactedCf = shouldPurge ? ColumnFamilyStore.removeDeleted(cf, controller.gcBefore)
: cf;
+        if (shouldPurge && compactedCf != null && compactedCf.metadata().getDefaultValidator().isCommutative())
         {
             CounterColumn.removeOldShards(compactedCf, controller.gcBefore);
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/context/CounterContext.java Tue Aug 
2 15:05:50 2011
@@ -21,6 +21,8 @@ import java.nio.ByteBuffer;
 import java.security.MessageDigest;
 import java.util.*;
 
+import org.apache.log4j.Logger;
+
 import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.db.DBConstants;
 import org.apache.cassandra.utils.ByteBufferUtil;
@@ -65,6 +67,8 @@ public class CounterContext implements I
     private static final int COUNT_LENGTH = DBConstants.longSize;
     private static final int STEP_LENGTH = NodeId.LENGTH + CLOCK_LENGTH + COUNT_LENGTH;
 
+    private static final Logger logger = Logger.getLogger(CounterContext.class);
+
     // Time in ms since a node id has been renewed before we consider using it
     // during a merge
     private static final long MIN_MERGE_DELAY = 5 * 60 * 1000; // should be aplenty
@@ -524,6 +528,8 @@ public class CounterContext implements I
             if (now - currRecord.timestamp < MIN_MERGE_DELAY)
                 return context;
 
+            assert !currRecord.id.equals(NodeId.getLocalId());
+
             int c = state.getNodeId().compareTo(currRecord.id);
             if (c == 0)
             {
@@ -539,6 +545,8 @@ public class CounterContext implements I
                 }
                 else
                 {
+                    assert !foundState.getNodeId().equals(state.getNodeId());
+
                     // Found someone to merge it to
                     int nbDelta = foundState.isDelta() ? 1 : 0;
                     nbDelta += state.isDelta() ? 1 : 0;
@@ -585,20 +593,24 @@ public class CounterContext implements I
         int hlength = headerLength(context);
         ContextState state = new ContextState(context, hlength);
         int removedBodySize = 0, removedHeaderSize = 0;
+        boolean forceFixing = false;
         while (state.hasRemaining())
         {
             long clock = state.getClock();
-            if (clock < 0 && -((int)(clock / 1000)) < gcBefore)
+            if (clock < 0 && -((int)(clock / 1000)) < gcBefore && (state.getCount()
== 0 || !state.isDelta()))
             {
-                assert state.getCount() == 0;
                 removedBodySize += STEP_LENGTH;
                 if (state.isDelta())
                     removedHeaderSize += HEADER_ELT_LENGTH;
             }
+            else if (clock < 0 && state.getCount() != 0 && state.isDelta())
+            {
+                forceFixing = true;
+            }
             state.moveToNext();
         }
 
-        if (removedBodySize == 0)
+        if (removedBodySize == 0 && !forceFixing)
             return context;
 
         int newSize = context.remaining() - removedHeaderSize - removedBodySize;
@@ -608,16 +620,31 @@ public class CounterContext implements I
         ContextState cleaned = new ContextState(cleanedContext, newHlength);
 
         state.reset();
+        long toAddBack = 0;
         while (state.hasRemaining())
         {
             long clock = state.getClock();
-            if (clock > 0 || -((int)(clock / 1000)) >= gcBefore)
+            if (!(clock < 0 && -((int)(clock / 1000)) < gcBefore &&
(state.getCount() == 0 || !state.isDelta())))
             {
-                state.copyTo(cleaned);
+                if (clock < 0 && state.getCount() != 0 && state.isDelta())
+                {
+                    // we should not get there, but we have been creating problematic context
prior to #2968
+                    if (state.getNodeId().equals(NodeId.getLocalId()))
+                        throw new RuntimeException("Merged counter shard with a count !=
0 (likely due to #2968). You need to restart this node with -Dcassandra.renew_counter_id=true
to fix.");
+
+                    // we will "fix" it, but log a message
+                    logger.info("Collectable old shard with a count != 0. Will fix.");
+                    cleaned.writeElement(state.getNodeId(), clock - 1L, 0, true);
+                    toAddBack += state.getCount();
+                }
+                else
+                {
+                    state.copyTo(cleaned);
+                }
             }
             state.moveToNext();
         }
-        return cleanedContext;
+        return toAddBack == 0 ? cleanedContext : merge(cleanedContext, create(toAddBack));
     }
 
     /**

Modified: cassandra/trunk/src/java/org/apache/cassandra/utils/NodeId.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/NodeId.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/NodeId.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/NodeId.java Tue Aug  2 15:05:50 2011
@@ -197,7 +197,7 @@ public class NodeId implements Comparabl
                 // no recorded local node id, generating a new one and saving it
                 id = generate();
                 logger.info("No saved local node id, using newly generated: {}", id);
-                SystemTable.writeCurrentLocalNodeId(null, id);
+                SystemTable.writeCurrentLocalNodeId(null, id, System.currentTimeMillis());
                 current = new AtomicReference<NodeId>(id);
                 olds = new CopyOnWriteArrayList();
             }
@@ -213,7 +213,7 @@ public class NodeId implements Comparabl
         {
             NodeId newNodeId = generate();
             NodeId old = current.get();
-            SystemTable.writeCurrentLocalNodeId(old, newNodeId);
+            SystemTable.writeCurrentLocalNodeId(old, newNodeId, now);
             current.set(newNodeId);
             olds.add(new NodeIdRecord(old, now));
         }
@@ -230,6 +230,18 @@ public class NodeId implements Comparabl
             this.timestamp = timestamp;
         }
 
+        @Override
+        public boolean equals(Object o)
+        {
+            if (this == o)
+                return true;
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            NodeIdRecord otherRecord = (NodeIdRecord)o;
+            return id.equals(otherRecord.id) && timestamp == otherRecord.timestamp;
+        }
+
         public String toString()
         {
             return String.format("(%s, %d)", id.toString(), timestamp);

Modified: cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/SchemaLoader.java Tue Aug  2 15:05:50 2011
@@ -137,7 +137,8 @@ public class SchemaLoader
                                                  st,
                                                  bytes,
                                                  null)
-                                                 .defaultValidator(CounterColumnType.instance),
+                                                 .defaultValidator(CounterColumnType.instance)
+                                                 .mergeShardsChance(1.0),
                                   new CFMetaData(ks1,
                                                  "SuperCounter1",
                                                  su,

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/CounterMutationTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/CounterMutationTest.java?rev=1153157&r1=1153156&r2=1153157&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/CounterMutationTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/CounterMutationTest.java Tue Aug  2
15:05:50 2011
@@ -18,9 +18,13 @@
 package org.apache.cassandra.db;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.List;
 
 import org.junit.Test;
+import static org.junit.Assert.fail;
 
+import org.apache.cassandra.db.context.CounterContext;
 import org.apache.cassandra.db.filter.*;
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.thrift.*;
@@ -107,5 +111,61 @@ public class CounterMutationTest extends
         assert sc2.getSubColumns().size() == 1;
         assert sc2.getSubColumn(bytes("Column2")) != null;
     }
+
+    @Test
+    public void testGetOldShardFromSystemTable() throws IOException
+    {
+        // Renewing a bunch of times and checking we get the same thing from
+        // the system table that what is in memory
+        NodeId.renewLocalId();
+        NodeId.renewLocalId();
+        NodeId.renewLocalId();
+
+        List<NodeId.NodeIdRecord> inMem = NodeId.getOldLocalNodeIds();
+        List<NodeId.NodeIdRecord> onDisk = SystemTable.getOldLocalNodeIds();
+
+        assert inMem.equals(onDisk);
+    }
+
+    @Test
+    public void testRemoveOldShardFixCorrupted() throws IOException
+    {
+        CounterContext ctx = CounterContext.instance();
+
+        // Check that corrupted context created prior to #2968 are fixed by removeOldShards
+        NodeId id1 = NodeId.getLocalId();
+        NodeId.renewLocalId();
+        NodeId id2 = NodeId.getLocalId();
+
+        ContextState state = ContextState.allocate(3, 2);
+        state.writeElement(NodeId.fromInt(1), 1, 4, false);
+        state.writeElement(id1, 3, 2, true);
+        state.writeElement(id2, -System.currentTimeMillis(), 5, true); // corrupted!
+
+        assert ctx.total(state.context) == 11;
+
+        try
+        {
+            ctx.removeOldShards(state.context, Integer.MAX_VALUE);
+            fail("RemoveOldShards should throw an exception if the current id is non-sensical");
+        }
+        catch (RuntimeException e) {}
+
+        NodeId.renewLocalId();
+        ByteBuffer cleaned = ctx.removeOldShards(state.context, Integer.MAX_VALUE);
+        assert ctx.total(cleaned) == 11;
+
+        // Check it is not corrupted anymore
+        ContextState state2 = new ContextState(cleaned);
+        while (state2.hasRemaining())
+        {
+            assert state2.getClock() >= 0 || state2.getCount() == 0;
+            state2.moveToNext();
+        }
+
+        // Check that if we merge old and clean on another node, we keep the right count
+        ByteBuffer onRemote = ctx.merge(ctx.clearAllDelta(state.context), ctx.clearAllDelta(cleaned));
+        assert ctx.total(onRemote) == 11;
+    }
 }
 



Mime
View raw message