cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1045230 - in /cassandra/branches/cassandra-0.7: CHANGES.txt src/java/org/apache/cassandra/utils/ByteBufferUtil.java
Date Mon, 13 Dec 2010 16:56:16 GMT
Author: jbellis
Date: Mon Dec 13 16:56:16 2010
New Revision: 1045230

URL: http://svn.apache.org/viewvc?rev=1045230&view=rev
Log:
make ByteBufferUtil.clone thread-safe
patch by tjake and jbellis for CASSANDRA-1847

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1045230&r1=1045229&r2=1045230&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Mon Dec 13 16:56:16 2010
@@ -8,6 +8,7 @@ dev
  * cli defaults to bytestype for subcomparator when creating
    column families (CASSANDRA-1835)
  * unregister index MBeans when index is dropped (CASSANDRA-1843)
+ * make ByteBufferUtil.clone thread-safe (CASSANDRA-1847)
 
 
 0.7.0-rc2

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java?rev=1045230&r1=1045229&r2=1045230&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
Mon Dec 13 16:56:16 2010
@@ -101,11 +101,26 @@ public class ByteBufferUtil
     
     public static ByteBuffer clone(ByteBuffer o)
     {
+        assert o != null;
+        
+        if (o.remaining() == 0)
+            return FBUtilities.EMPTY_BYTE_BUFFER;
+          
         ByteBuffer clone = ByteBuffer.allocate(o.remaining());
-        o.mark();
-        clone.put(o);
-        o.reset();
-        clone.flip();
+
+        if (o.isDirect())
+        {
+            for (int i = o.position(); i < o.limit(); i++)
+            {
+                clone.put(o.get(i));
+            }
+            clone.flip();
+        }
+        else
+        {
+            System.arraycopy(o.array(), o.arrayOffset() + o.position(), clone.array(), 0,
o.remaining());
+        }
+
         return clone;
     }
 }



Mime
View raw message