You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by vi...@apache.org on 2012/04/03 21:30:58 UTC

git commit: avoid seg faults during compaction patch by Vijay; reviewed by jbellis for CASSANDRA-4111

Updated Branches:
  refs/heads/cassandra-1.1.0 e9917c479 -> f956569db


avoid seg faults during compaction
patch by Vijay; reviewed by jbellis for CASSANDRA-4111


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f956569d
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f956569d
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f956569d

Branch: refs/heads/cassandra-1.1.0
Commit: f956569dbd7848eadbe5e70b12fadb7e25e0fc4a
Parents: e9917c4
Author: Vijay Parthasarathy <vi...@gmail.com>
Authored: Tue Apr 3 12:26:01 2012 -0700
Committer: Vijay Parthasarathy <vi...@gmail.com>
Committed: Tue Apr 3 12:26:01 2012 -0700

----------------------------------------------------------------------
 .../apache/cassandra/cache/SerializingCache.java   |   16 +++++++++++++-
 1 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f956569d/src/java/org/apache/cassandra/cache/SerializingCache.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cache/SerializingCache.java b/src/java/org/apache/cassandra/cache/SerializingCache.java
index 4946fb0..275130c 100644
--- a/src/java/org/apache/cassandra/cache/SerializingCache.java
+++ b/src/java/org/apache/cassandra/cache/SerializingCache.java
@@ -205,11 +205,23 @@ public class SerializingCache<K, V> implements ICache<K, V>
         FreeableMemory mem = serialize(value);
         if (mem == null)
             return false; // out of memory.  never mind.
-        V oldValue = deserialize(old);
+
+        V oldValue;
+        // reference old guy before de-serializing
+        if (!old.reference())
+            return false; // we have already freed hence noop.
+        try
+        {
+             oldValue = deserialize(old);
+        }
+        finally
+        {
+            old.unreference();
+        }
         boolean success = oldValue.equals(oldToReplace) && map.replace(key, old, mem);
 
         if (success)
-            old.unreference();
+            old.unreference(); // so it will be eventually be cleaned
         else
             mem.unreference();
         return success;