cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1064186 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/dht/ src/java/org/apache/cassandra/hadoop/ src/java/org/apache/cassandra/io/ src/java/org/apache/cassandra/utils/
Date Thu, 27 Jan 2011 16:36:51 GMT
Author: jbellis
Date: Thu Jan 27 16:36:51 2011
New Revision: 1064186

URL: http://svn.apache.org/viewvc?rev=1064186&view=rev
Log:
fix possibleByteBuffer race conditions
patch by slebresne; reviewed by jbellis for CASSANDRA-2066

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/SerDeUtils.java
    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=1064186&r1=1064185&r2=1064186&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Thu Jan 27 16:36:51 2011
@@ -3,6 +3,7 @@
  * add JVM shutdownhook to sync commitlog (CASSANDRA-1919)
  * allow nodes to be up without being part of  normal traffic (CASSANDRA-1951)
  * fix CLI "show keyspaces" with null options on NTS (CASSANDRA-2049)
+ * fix possible ByteBuffer race conditions (CASSANDRA-2066)
 
 
 0.7.1

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=1064186&r1=1064185&r2=1064186&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/dht/RandomPartitioner.java
Thu Jan 27 16:36:51 2011
@@ -98,11 +98,7 @@ public class RandomPartitioner implement
 
         public Token<BigInteger> fromByteArray(ByteBuffer bytes)
         {
-            byte[] b = new byte[bytes.remaining()];
-            bytes.get(b);
-            bytes.rewind();
-            
-            return new BigIntegerToken(new BigInteger(b));
+            return new BigIntegerToken(new BigInteger(ByteBufferUtil.getArray(bytes)));
         }
 
         public String toString(Token<BigInteger> bigIntegerToken)

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java?rev=1064186&r1=1064185&r2=1064186&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java
Thu Jan 27 16:36:51 2011
@@ -40,7 +40,7 @@ import org.apache.hadoop.mapreduce.TaskA
 import org.apache.thrift.TException;
 import org.apache.thrift.transport.TSocket;
 
-import static org.apache.cassandra.io.SerDeUtils.copy;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 /**
  * The <code>ColumnFamilyRecordWriter</code> maps the output &lt;key, value&gt;
@@ -169,7 +169,7 @@ implements org.apache.hadoop.mapred.Reco
             org.apache.cassandra.avro.SlicePredicate apred = amut.deletion.predicate;
             if (amut.deletion.super_column != null)
                 // super column
-                deletion.setSuper_column(copy(amut.deletion.super_column));
+                deletion.setSuper_column(ByteBufferUtil.getArray(amut.deletion.super_column));
             else if (apred.column_names != null)
             {
                 // column names

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/SerDeUtils.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/SerDeUtils.java?rev=1064186&r1=1064185&r2=1064186&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/SerDeUtils.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/SerDeUtils.java Thu
Jan 27 16:36:51 2011
@@ -45,14 +45,6 @@ public final class SerDeUtils
     // unbuffered decoders
     private final static DecoderFactory DIRECT_DECODERS = new DecoderFactory().configureDirectDecoder(true);
 
-    public static byte[] copy(ByteBuffer buff)
-    {
-        byte[] bytes = new byte[buff.remaining()];
-        buff.get(bytes);
-        buff.rewind();
-        return bytes;
-    }
-
 	/**
      * Deserializes a single object based on the given Schema.
      * @param writer writer's schema

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=1064186&r1=1064185&r2=1064186&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
Thu Jan 27 16:36:51 2011
@@ -135,7 +135,12 @@ public class ByteBufferUtil
     public static byte[] getArray(ByteBuffer b, int start, int length)
     {
         if (b.hasArray())
-            return Arrays.copyOfRange(b.array(), start + b.arrayOffset(), start + length
+ b.arrayOffset());
+        {
+            if (b.arrayOffset() == 0 && start == 0 && length == b.array().length)
+                return b.array();
+            else
+                return Arrays.copyOfRange(b.array(), start + b.arrayOffset(), start + length
+ b.arrayOffset());
+        }
 
         byte[] bytes = new byte[length];
 



Mime
View raw message