cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1170342 - in /cassandra/branches/cassandra-1.0.0: CHANGES.txt src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
Date Tue, 13 Sep 2011 20:59:07 GMT
Author: jbellis
Date: Tue Sep 13 20:59:07 2011
New Revision: 1170342

URL: http://svn.apache.org/viewvc?rev=1170342&view=rev
Log:
copy buffers from mmap'd source so we don't segfault if the source is unmapped before we're
done with it
patch by jbellis; tested by brandonwilliams for CASSANDRA-3179

Modified:
    cassandra/branches/cassandra-1.0.0/CHANGES.txt
    cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java

Modified: cassandra/branches/cassandra-1.0.0/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/CHANGES.txt?rev=1170342&r1=1170341&r2=1170342&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0.0/CHANGES.txt Tue Sep 13 20:59:07 2011
@@ -14,7 +14,7 @@
  * optimize away seek when compacting wide rows (CASSANDRA-2879)
  * single-pass streaming (CASSANDRA-2677, 3003)
  * use reference counting for deleting sstables instead of relying on GC
-   (CASSANDRA-2521)
+   (CASSANDRA-2521, 3179)
  * store hints as serialized mutations instead of pointers to data row
    (CASSANDRA-2045)
  * store hints in the coordinator node instead of in the closest replica 

Modified: cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java?rev=1170342&r1=1170341&r2=1170342&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
(original)
+++ cassandra/branches/cassandra-1.0.0/src/java/org/apache/cassandra/io/util/MappedFileDataInput.java
Tue Sep 13 20:59:07 2011
@@ -25,6 +25,8 @@ import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 public class MappedFileDataInput extends AbstractDataInput implements FileDataInput
 {
     private final MappedByteBuffer buffer;
@@ -117,11 +119,18 @@ public class MappedFileDataInput extends
             throw new IOException(String.format("mmap segment underflow; remaining is %d
but %d requested",
                                                 remaining, length));
 
+        if (length == 0)
+            return ByteBufferUtil.EMPTY_BYTE_BUFFER;
+
         ByteBuffer bytes = buffer.duplicate();
         bytes.position(buffer.position() + position).limit(buffer.position() + position +
length);
         position += length;
 
-        return bytes;
+        // we have to copy the data in case we unreference the underlying sstable.  See CASSANDRA-3179
+        ByteBuffer clone = ByteBuffer.allocate(bytes.remaining());
+        clone.put(bytes);
+        clone.flip();
+        return clone;
     }
 
     @Override



Mime
View raw message