cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [7/10] git commit: avoid seg faults during compaction patch by Vijay; reviewed by jbellis for CASSANDRA-4111
Date Wed, 04 Apr 2012 17:06:50 GMT
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/030d4718
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/030d4718
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/030d4718

Branch: refs/heads/trunk
Commit: 030d4718e5596884c766b6e3e5b1c54fe23f6dd8
Parents: 031e894
Author: Vijay Parthasarathy <vijay2win@gmail.com>
Authored: Tue Apr 3 12:26:01 2012 -0700
Committer: Vijay Parthasarathy <vijay2win@gmail.com>
Committed: Tue Apr 3 12:33:03 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/030d4718/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;


Mime
View raw message