cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1026200 [7/11] - in /cassandra/trunk: ./ interface/ interface/thrift/gen-java/org/apache/cassandra/thrift/ src/java/org/apache/cassandra/auth/ src/java/org/apache/cassandra/avro/ src/java/org/apache/cassandra/cli/ src/java/org/apache/cassa...
Date Fri, 22 Oct 2010 03:23:31 GMT
Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryPath.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryPath.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryPath.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryPath.java Fri Oct 22 03:23:26 2010
@@ -21,24 +21,23 @@ package org.apache.cassandra.db.filter;
  */
 
 
+import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
-import java.io.DataInputStream;
-
-import org.apache.commons.lang.ArrayUtils;
+import java.nio.ByteBuffer;
 
 import org.apache.cassandra.thrift.ColumnParent;
 import org.apache.cassandra.thrift.ColumnPath;
-import org.apache.cassandra.db.ColumnSerializer;
 import org.apache.cassandra.utils.FBUtilities;
+import org.apache.commons.lang.ArrayUtils;
 
 public class QueryPath
 {
     public final String columnFamilyName;
-    public final byte[] superColumnName;
-    public final byte[] columnName;
+    public final ByteBuffer superColumnName;
+    public final ByteBuffer columnName;
 
-    public QueryPath(String columnFamilyName, byte[] superColumnName, byte[] columnName)
+    public QueryPath(String columnFamilyName, ByteBuffer superColumnName, ByteBuffer columnName)
     {
         this.columnFamilyName = columnFamilyName;
         this.superColumnName = superColumnName;
@@ -50,7 +49,7 @@ public class QueryPath
         this(columnParent.column_family, columnParent.super_column, null);
     }
 
-    public QueryPath(String columnFamilyName, byte[] superColumnName)
+    public QueryPath(String columnFamilyName, ByteBuffer superColumnName)
     {
         this(columnFamilyName, superColumnName, null);
     }
@@ -65,7 +64,7 @@ public class QueryPath
         this(column_path.column_family, column_path.super_column, column_path.column);
     }
 
-    public static QueryPath column(byte[] columnName)
+    public static QueryPath column(ByteBuffer columnName)
     {
         return new QueryPath(null, null, columnName);
     }
@@ -83,18 +82,20 @@ public class QueryPath
     public void serialize(DataOutputStream dos) throws IOException
     {
         assert !"".equals(columnFamilyName);
-        assert superColumnName == null || superColumnName.length > 0;
-        assert columnName == null || columnName.length > 0;
+        assert superColumnName == null || superColumnName.remaining() > 0;
+        assert columnName == null || columnName.remaining() > 0;
         dos.writeUTF(columnFamilyName == null ? "" : columnFamilyName);
-        FBUtilities.writeShortByteArray(superColumnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY : superColumnName, dos);
-        FBUtilities.writeShortByteArray(columnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY : columnName, dos);
+        FBUtilities.writeShortByteArray(superColumnName == null ? FBUtilities.EMPTY_BYTE_BUFFER : superColumnName, dos);
+        FBUtilities.writeShortByteArray(columnName == null ? FBUtilities.EMPTY_BYTE_BUFFER : columnName, dos);
     }
 
     public static QueryPath deserialize(DataInputStream din) throws IOException
     {
         String cfName = din.readUTF();
-        byte[] scName = FBUtilities.readShortByteArray(din);
-        byte[] cName = FBUtilities.readShortByteArray(din);
-        return new QueryPath(cfName.isEmpty() ? null : cfName, scName.length == 0 ? null : scName, cName.length == 0 ? null : cName);
+        ByteBuffer scName = FBUtilities.readShortByteArray(din);
+        ByteBuffer cName = FBUtilities.readShortByteArray(din);
+        return new QueryPath(cfName.isEmpty() ? null : cfName, 
+                             scName.remaining() == 0 ? null : scName, 
+                             cName.remaining() == 0 ? null : cName);
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java Fri Oct 22 03:23:26 2010
@@ -21,32 +21,40 @@ package org.apache.cassandra.db.filter;
  */
 
 
-import java.util.*;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.commons.collections.comparators.ReverseComparator;
-import org.apache.commons.collections.iterators.ReverseListIterator;
-import org.apache.commons.collections.IteratorUtils;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.IColumn;
+import org.apache.cassandra.db.IColumnContainer;
+import org.apache.cassandra.db.Memtable;
+import org.apache.cassandra.db.SuperColumn;
 import org.apache.cassandra.db.columniterator.IColumnIterator;
 import org.apache.cassandra.db.columniterator.SSTableSliceIterator;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.io.util.FileDataInput;
-import org.apache.cassandra.db.*;
-import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.commons.collections.IteratorUtils;
+import org.apache.commons.collections.comparators.ReverseComparator;
+import org.apache.commons.collections.iterators.ReverseListIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class SliceQueryFilter implements IFilter
 {
     private static Logger logger = LoggerFactory.getLogger(SliceQueryFilter.class);
 
-    public final byte[] start;
-    public final byte[] finish;
+    public final ByteBuffer start;
+    public final ByteBuffer finish;
     public final boolean reversed;
     public final int count;
 
-    public SliceQueryFilter(byte[] start, byte[] finish, boolean reversed, int count)
+    public SliceQueryFilter(ByteBuffer start, ByteBuffer finish, boolean reversed, int count)
     {
         this.start = start;
         this.finish = finish;
@@ -86,7 +94,7 @@ public class SliceQueryFilter implements
         }
 
         // iterate until we get to the "real" start column
-        Comparator<byte[]> comparator = reversed ? superColumn.getComparator().getReverseComparator() : superColumn.getComparator();
+        Comparator<ByteBuffer> comparator = reversed ? superColumn.getComparator().getReverseComparator() : superColumn.getComparator();
         while (subcolumns.hasNext())
         {
             IColumn column = subcolumns.next();
@@ -121,11 +129,11 @@ public class SliceQueryFilter implements
                 logger.debug(String.format("collecting %s of %s: %s",
                                            liveColumns, count, column.getString(comparator)));
 
-            if (finish.length > 0
+            if (finish.remaining() > 0
                 && ((!reversed && comparator.compare(column.name(), finish) > 0))
                     || (reversed && comparator.compare(column.name(), finish) < 0))
                 break;
-
+ 
             // only count live columns towards the `count` criteria
             if (!column.isMarkedForDelete()
                 && (!container.isMarkedForDelete()

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AbstractType.java Fri Oct 22 03:23:26 2010
@@ -21,41 +21,42 @@ package org.apache.cassandra.db.marshal;
  */
 
 
-import java.util.Comparator;
+import java.nio.ByteBuffer;
 import java.util.Collection;
+import java.util.Comparator;
 
 import org.apache.cassandra.db.IColumn;
 
 /**
- * Specifies a Comparator for a specific type of byte[].
+ * Specifies a Comparator for a specific type of ByteBuffer.
  *
- * Note that empty byte[] are used to represent "start at the beginning"
+ * Note that empty ByteBuffer are used to represent "start at the beginning"
  * or "stop at the end" arguments to get_slice, so the Comparator
  * should always handle those values even if they normally do not
- * represent a valid byte[] for the type being compared.
+ * represent a valid ByteBuffer for the type being compared.
  */
-public abstract class AbstractType implements Comparator<byte[]>
+public abstract class AbstractType implements Comparator<ByteBuffer>
 {
     /** get a string representation of the bytes suitable for log messages */
-    public abstract String getString(byte[] bytes);
+    public abstract String getString(ByteBuffer bytes);
 
     /** validate that the byte array is a valid sequence for the type we are supposed to be comparing */
-    public void validate(byte[] bytes)
+    public void validate(ByteBuffer bytes)
     {
         getString(bytes);
     }
 
-    public Comparator<byte[]> getReverseComparator()
+    public Comparator<ByteBuffer> getReverseComparator()
     {
-        return new Comparator<byte[]>()
+        return new Comparator<ByteBuffer>()
         {
-            public int compare(byte[] o1, byte[] o2)
+            public int compare(ByteBuffer o1, ByteBuffer o2)
             {
-                if (o1.length == 0)
+                if (o1.remaining() == 0)
                 {
-                    return o2.length == 0 ? 0 : -1;
+                    return o2.remaining() == 0 ? 0 : -1;
                 }
-                if (o2.length == 0)
+                if (o2.remaining() == 0)
                 {
                     return 1;
                 }
@@ -66,10 +67,10 @@ public abstract class AbstractType imple
     }
 
     /** convenience method */
-    public String getString(Collection<byte[]> names)
+    public String getString(Collection<ByteBuffer> names)
     {
         StringBuilder builder = new StringBuilder();
-        for (byte[] name : names)
+        for (ByteBuffer name : names)
         {
             builder.append(getString(name)).append(",");
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/AsciiType.java Fri Oct 22 03:23:26 2010
@@ -22,6 +22,7 @@ package org.apache.cassandra.db.marshal;
 
 
 import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
 
 public class AsciiType extends BytesType
 {
@@ -30,11 +31,11 @@ public class AsciiType extends BytesType
     AsciiType() {} // singleton
 
     @Override
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
         try
         {
-            return new String(bytes, "US-ASCII");
+            return new String(bytes.array(),bytes.position()+bytes.arrayOffset(),bytes.remaining(), "US-ASCII");
         }
         catch (UnsupportedEncodingException e)
         {

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/BytesType.java Fri Oct 22 03:23:26 2010
@@ -21,8 +21,9 @@ package org.apache.cassandra.db.marshal;
  */
 
 
-import java.util.Arrays;
+import java.nio.ByteBuffer;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 
 public class BytesType extends AbstractType
@@ -31,12 +32,17 @@ public class BytesType extends AbstractT
 
     BytesType() {} // singleton
     
-    public int compare(byte[] o1, byte[] o2)
+    public int compare(ByteBuffer o1, ByteBuffer o2)
     {
-        return FBUtilities.compareByteArrays(o1, o2);
+        if(null == o1){
+            if(null == o2) return 0;
+            else return -1;
+        }
+              
+        return ByteBufferUtil.compare(o1, o2);
     }
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
         return FBUtilities.bytesToHex(bytes);
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/IntegerType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/IntegerType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/IntegerType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/IntegerType.java Fri Oct 22 03:23:26 2010
@@ -19,20 +19,22 @@
 
 package org.apache.cassandra.db.marshal;
 
+import java.nio.ByteBuffer;
+
 public final class IntegerType extends AbstractType
 {
     public static final IntegerType instance = new IntegerType();
 
-    private static int findMostSignificantByte(byte[] bytes)
+    private static int findMostSignificantByte(ByteBuffer bytes)
     {
-        int len = bytes.length - 1;
+        int len = bytes.remaining() - 1;
         int i = 0;
         for (; i < len; i++)
         {
-            byte b0 = bytes[i];
+            byte b0 = bytes.array()[bytes.position()+bytes.arrayOffset()+i];
             if (b0 != 0 && b0 != -1)
                 break;
-            byte b1 = bytes[i + 1];
+            byte b1 = bytes.array()[bytes.position()+bytes.arrayOffset()+ i + 1];
             if (b0 == 0 && b1 != 0)
             {
                 if (b1 > 0)
@@ -51,10 +53,10 @@ public final class IntegerType extends A
 
     IntegerType() {/* singleton */}
 
-    public int compare(byte[] lhs, byte[] rhs)
+    public int compare(ByteBuffer lhs, ByteBuffer rhs)
     {
-        int lhsLen = lhs.length;
-        int rhsLen = rhs.length;
+        int lhsLen = lhs.remaining();
+        int rhsLen = rhs.remaining();
 
         if (lhsLen == 0)
             return rhsLen == 0 ? 0 : -1;
@@ -68,8 +70,8 @@ public final class IntegerType extends A
         int lhsLenDiff = lhsLen - lhsMsbIdx;
         int rhsLenDiff = rhsLen - rhsMsbIdx;
 
-        byte lhsMsb = lhs[lhsMsbIdx];
-        byte rhsMsb = rhs[rhsMsbIdx];
+        byte lhsMsb = lhs.array()[lhs.position()+lhs.arrayOffset()+lhsMsbIdx];
+        byte rhsMsb = rhs.array()[rhs.position()+rhs.arrayOffset()+rhsMsbIdx];
 
         /*         +    -
          *      -----------
@@ -99,8 +101,8 @@ public final class IntegerType extends A
         // remaining bytes are compared unsigned
         while (lhsMsbIdx < lhsLen)
         {
-            lhsMsb = lhs[lhsMsbIdx++];
-            rhsMsb = rhs[rhsMsbIdx++];
+            lhsMsb = lhs.array()[lhs.position()+lhs.arrayOffset()+lhsMsbIdx++];
+            rhsMsb = rhs.array()[rhs.position()+rhs.arrayOffset()+rhsMsbIdx++];
             if (lhsMsb != rhsMsb)
                 return (lhsMsb & 0xFF) - (rhsMsb & 0xFF);
         }
@@ -109,13 +111,13 @@ public final class IntegerType extends A
     }
 
     @Override
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
         if (bytes == null)
             return "null";
-        if (bytes.length == 0)
+        if (bytes.remaining() == 0)
             return "empty";
 
-        return new java.math.BigInteger(bytes).toString(10);
+        return new java.math.BigInteger(bytes.array()).toString(10);
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LexicalUUIDType.java Fri Oct 22 03:23:26 2010
@@ -24,25 +24,26 @@ package org.apache.cassandra.db.marshal;
 import java.util.UUID;
 import java.nio.ByteBuffer;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
+
 public class LexicalUUIDType extends AbstractType
 {
     public static final LexicalUUIDType instance = new LexicalUUIDType();
 
     LexicalUUIDType() {} // singleton
 
-    static UUID getUUID(byte[] bytes)
+    static UUID getUUID(ByteBuffer bytes)
     {
-        ByteBuffer bb = ByteBuffer.wrap(bytes);
-        return new UUID(bb.getLong(), bb.getLong());
+        return new UUID(bytes.getLong(bytes.position()+bytes.arrayOffset()), bytes.getLong(bytes.position()+bytes.arrayOffset()));
     }
 
-    public int compare(byte[] o1, byte[] o2)
+    public int compare(ByteBuffer o1, ByteBuffer o2)
     {
-        if (o1.length == 0)
+        if (o1.remaining() == 0)
         {
-            return o2.length == 0 ? 0 : -1;
+            return o2.remaining() == 0 ? 0 : -1;
         }
-        if (o2.length == 0)
+        if (o2.remaining() == 0)
         {
             return 1;
         }
@@ -50,13 +51,13 @@ public class LexicalUUIDType extends Abs
         return getUUID(o1).compareTo(getUUID(o2));
     }
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
-        if (bytes.length == 0)
+        if (bytes.remaining() == 0)
         {
             return "";
         }
-        if (bytes.length != 16)
+        if (bytes.remaining() != 16)
         {
             throw new MarshalException("UUIDs must be exactly 16 bytes");
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LocalByPartionerType.java Fri Oct 22 03:23:26 2010
@@ -19,6 +19,8 @@
 
 package org.apache.cassandra.db.marshal;
 
+import java.nio.ByteBuffer;
+
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.dht.Token;
 
@@ -33,12 +35,12 @@ public class LocalByPartionerType<T exte
         this.partitioner = partitioner;
     }
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
         return null;
     }
 
-    public int compare(byte[] o1, byte[] o2)
+    public int compare(ByteBuffer o1, ByteBuffer o2)
     {
         return partitioner.decorateKey(o1).compareTo(partitioner.decorateKey(o2));
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/LongType.java Fri Oct 22 03:23:26 2010
@@ -23,7 +23,7 @@ package org.apache.cassandra.db.marshal;
 
 import java.nio.ByteBuffer;
 
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class LongType extends AbstractType
 {
@@ -31,33 +31,37 @@ public class LongType extends AbstractTy
 
     LongType() {} // singleton
 
-    public int compare(byte[] o1, byte[] o2)
+    public int compare(ByteBuffer o1, ByteBuffer o2)
     {
-        if (o1.length == 0)
+        if (o1.remaining() == 0)
         {
-            return o2.length == 0 ? 0 : -1;
+            return o2.remaining() == 0 ? 0 : -1;
         }
-        if (o2.length == 0)
+        if (o2.remaining() == 0)
         {
             return 1;
         }
 
-        int diff = o1[0] - o2[0];
+        int diff = o1.array()[o1.position()+o1.arrayOffset()] - o2.array()[o2.position()+o2.arrayOffset()];
         if (diff != 0)
             return diff;
-        return FBUtilities.compareByteArrays(o1, o2);
+        
+       
+        return ByteBufferUtil.compare(o1, o2);
     }
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
-        if (bytes.length == 0)
+        if (bytes.remaining() == 0)
         {
             return "";
         }
-        if (bytes.length != 8)
+        if (bytes.remaining() != 8)
         {
-            throw new MarshalException("A long is exactly 8 bytes");
+            throw new MarshalException("A long is exactly 8 bytes: "+bytes.remaining());
         }
-        return String.valueOf(ByteBuffer.wrap(bytes).getLong());
+        
+        
+        return String.valueOf(bytes.getLong(bytes.position()+bytes.arrayOffset()));
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/TimeUUIDType.java Fri Oct 22 03:23:26 2010
@@ -21,7 +21,9 @@ package org.apache.cassandra.db.marshal;
  */
 
 
+import java.nio.ByteBuffer;
 import java.util.UUID;
+
 import org.apache.cassandra.utils.FBUtilities;
 
 public class TimeUUIDType extends AbstractType
@@ -30,48 +32,51 @@ public class TimeUUIDType extends Abstra
 
     TimeUUIDType() {} // singleton
 
-    public int compare(byte[] o1, byte[] o2)
+    public int compare(ByteBuffer o1, ByteBuffer o2)
     {
-        if (o1.length == 0)
+        if (o1.remaining() == 0)
         {
-            return o2.length == 0 ? 0 : -1;
+            return o2.remaining() == 0 ? 0 : -1;
         }
-        if (o2.length == 0)
+        if (o2.remaining() == 0)
         {
             return 1;
         }
         int res = compareTimestampBytes(o1, o2);
         if (res != 0)
             return res;
-        return FBUtilities.compareByteArrays(o1, o2);
+        return o1.compareTo(o2);
     }
 
-    private static int compareTimestampBytes(byte[] o1, byte[] o2)
+    private static int compareTimestampBytes(ByteBuffer o1, ByteBuffer o2)
     {
-        int d = (o1[6] & 0xF) - (o2[6] & 0xF);
+        int o1Pos = o1.position()+o1.arrayOffset();
+        int o2Pos = o2.position()+o2.arrayOffset();
+        
+        int d = (o1.array()[o1Pos+6] & 0xF) - (o2.array()[o2Pos+6] & 0xF);
         if (d != 0) return d;
-        d = (o1[7] & 0xFF) - (o2[7] & 0xFF);
+        d = (o1.array()[o1Pos+7] & 0xFF) - (o2.array()[o2Pos+7] & 0xFF);
         if (d != 0) return d;
-        d = (o1[4] & 0xFF) - (o2[4] & 0xFF);
+        d = (o1.array()[o1Pos+4] & 0xFF) - (o2.array()[o2Pos+4] & 0xFF);
         if (d != 0) return d;
-        d = (o1[5] & 0xFF) - (o2[5] & 0xFF);
+        d = (o1.array()[o1Pos+5] & 0xFF) - (o2.array()[o2Pos+5] & 0xFF);
         if (d != 0) return d;
-        d = (o1[0] & 0xFF) - (o2[0] & 0xFF);
+        d = (o1.array()[o1Pos+0] & 0xFF) - (o2.array()[o2Pos+0] & 0xFF);
         if (d != 0) return d;
-        d = (o1[1] & 0xFF) - (o2[1] & 0xFF);
+        d = (o1.array()[o1Pos+1] & 0xFF) - (o2.array()[o2Pos+1] & 0xFF);
         if (d != 0) return d;
-        d = (o1[2] & 0xFF) - (o2[2] & 0xFF);
+        d = (o1.array()[o1Pos+2] & 0xFF) - (o2.array()[o2Pos+2] & 0xFF);
         if (d != 0) return d;
-        return (o1[3] & 0xFF) - (o2[3] & 0xFF);
+        return (o1.array()[o1Pos+3] & 0xFF) - (o2.array()[o2Pos+3] & 0xFF);
     }
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
-        if (bytes.length == 0)
+        if (bytes.remaining() == 0)
         {
             return "";
         }
-        if (bytes.length != 16)
+        if (bytes.remaining() != 16)
         {
             throw new MarshalException("UUIDs must be exactly 16 bytes");
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/marshal/UTF8Type.java Fri Oct 22 03:23:26 2010
@@ -20,7 +20,7 @@ package org.apache.cassandra.db.marshal;
  * 
  */
 
-import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.util.Arrays;
 
@@ -32,7 +32,7 @@ public class UTF8Type extends BytesType
 
     UTF8Type() {} // singleton
 
-    public String getString(byte[] bytes)
+    public String getString(ByteBuffer bytes)
     {
         try
         {
@@ -40,7 +40,7 @@ public class UTF8Type extends BytesType
         }
         catch (CharacterCodingException e)
         {
-            throw new MarshalException("invalid UTF8 bytes " + Arrays.toString(bytes));
+            throw new MarshalException("invalid UTF8 bytes " + Arrays.toString(bytes.array()));
         }
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/Migration.java Fri Oct 22 03:23:26 2010
@@ -71,8 +71,8 @@ public abstract class Migration
     public static final String NAME_VALIDATOR_REGEX = "\\w+";
     public static final String MIGRATIONS_CF = "Migrations";
     public static final String SCHEMA_CF = "Schema";
-    public static final byte[] MIGRATIONS_KEY = "Migrations Key".getBytes(UTF_8);
-    public static final byte[] LAST_MIGRATION_KEY = "Last Migration".getBytes(UTF_8);
+    public static final ByteBuffer MIGRATIONS_KEY = ByteBuffer.wrap("Migrations Key".getBytes(UTF_8));
+    public static final ByteBuffer LAST_MIGRATION_KEY = ByteBuffer.wrap("Last Migration".getBytes(UTF_8));
     
     protected RowMutation rm;
     protected UUID newVersion;
@@ -111,15 +111,15 @@ public abstract class Migration
         if (!clientMode)
         {
             long now = System.currentTimeMillis();
-            byte[] buf = serialize();
+            ByteBuffer buf = serialize();
             RowMutation migration = new RowMutation(Table.SYSTEM_TABLE, MIGRATIONS_KEY);
-            migration.add(new QueryPath(MIGRATIONS_CF, null, UUIDGen.decompose(newVersion)), buf, now);
+            migration.add(new QueryPath(MIGRATIONS_CF, null, ByteBuffer.wrap(UUIDGen.decompose(newVersion))), buf, now);
             migration.apply();
             
             // note that we're storing this in the system table, which is not replicated
             logger.debug("Applying migration " + newVersion.toString());
             migration = new RowMutation(Table.SYSTEM_TABLE, LAST_MIGRATION_KEY);
-            migration.add(new QueryPath(SCHEMA_CF, null, LAST_MIGRATION_KEY), UUIDGen.decompose(newVersion), now);
+            migration.add(new QueryPath(SCHEMA_CF, null, LAST_MIGRATION_KEY), ByteBuffer.wrap(UUIDGen.decompose(newVersion)), now);
             migration.apply();
 
             // if we fail here, there will be schema changes in the CL that will get replayed *AFTER* the schema is loaded.
@@ -218,17 +218,17 @@ public abstract class Migration
         long now = System.currentTimeMillis();
         // add a column for each keyspace
         for (KSMetaData ksm : ksms)
-            rm.add(new QueryPath(SCHEMA_CF, null, ksm.name.getBytes(UTF_8)), SerDeUtils.serialize(ksm.deflate()), now);
+            rm.add(new QueryPath(SCHEMA_CF, null, ByteBuffer.wrap(ksm.name.getBytes(UTF_8))), SerDeUtils.serialize(ksm.deflate()), now);
         // add the schema
         rm.add(new QueryPath(SCHEMA_CF,
                              null,
                              DefsTable.DEFINITION_SCHEMA_COLUMN_NAME),
-                             org.apache.cassandra.avro.KsDef.SCHEMA$.toString().getBytes(UTF_8),
+                             ByteBuffer.wrap(org.apache.cassandra.avro.KsDef.SCHEMA$.toString().getBytes(UTF_8)),
                              now);
         return rm;
     }
         
-    public byte[] serialize() throws IOException
+    public ByteBuffer serialize() throws IOException
     {
         // super deflate
         org.apache.cassandra.db.migration.avro.Migration mi = new org.apache.cassandra.db.migration.avro.Migration();
@@ -256,7 +256,7 @@ public abstract class Migration
         return SerDeUtils.serializeWithSchema(mi);
     }
 
-    public static Migration deserialize(byte[] bytes) throws IOException
+    public static Migration deserialize(ByteBuffer bytes) throws IOException
     {
         // deserialize
         org.apache.cassandra.db.migration.avro.Migration mi = SerDeUtils.deserializeWithSchema(bytes, new org.apache.cassandra.db.migration.avro.Migration());
@@ -276,8 +276,8 @@ public abstract class Migration
         }
         
         // super inflate
-        migration.lastVersion = UUIDGen.makeType1UUID(mi.old_version.bytes());
-        migration.newVersion = UUIDGen.makeType1UUID(mi.new_version.bytes());
+        migration.lastVersion = UUIDGen.makeType1UUID(ByteBuffer.wrap(mi.old_version.bytes()));
+        migration.newVersion = UUIDGen.makeType1UUID(ByteBuffer.wrap(mi.new_version.bytes()));
         try
         {
             migration.rm = RowMutation.serializer().deserialize(SerDeUtils.createDataInputStream(mi.row_mutation));
@@ -297,14 +297,14 @@ public abstract class Migration
         DecoratedKey dkey = StorageService.getPartitioner().decorateKey(MIGRATIONS_KEY);
         Table defs = Table.open(Table.SYSTEM_TABLE);
         ColumnFamilyStore cfStore = defs.getColumnFamilyStore(Migration.MIGRATIONS_CF);
-        QueryFilter filter = QueryFilter.getSliceFilter(dkey, new QueryPath(MIGRATIONS_CF), UUIDGen.decompose(start), UUIDGen.decompose(end), false, 1000);
+        QueryFilter filter = QueryFilter.getSliceFilter(dkey, new QueryPath(MIGRATIONS_CF), ByteBuffer.wrap(UUIDGen.decompose(start)), ByteBuffer.wrap(UUIDGen.decompose(end)), false, 1000);   
         ColumnFamily cf = cfStore.getColumnFamily(filter);
         return cf.getSortedColumns();
     }
     
-    public static byte[] toUTF8Bytes(UUID version)
+    public static ByteBuffer toUTF8Bytes(UUID version)
     {
-        return version.toString().getBytes(UTF_8);
+        return ByteBuffer.wrap(version.toString().getBytes(UTF_8));
     }
     
     public static boolean isLegalName(String s)

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/migration/UpdateColumnFamily.java Fri Oct 22 03:23:26 2010
@@ -1,17 +1,22 @@
 package org.apache.cassandra.db.migration;
 
-import org.apache.cassandra.config.*;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cassandra.config.CFMetaData;
+import org.apache.cassandra.config.ColumnDefinition;
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.KSMetaData;
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.SystemTable;
 import org.apache.cassandra.db.Table;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.UUIDGen;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -84,9 +89,9 @@ public class UpdateColumnFamily extends 
             table.reloadCf(newCfm.cfId);
 
             // clean up obsolete index data files
-            for (Map.Entry<byte[], ColumnDefinition> entry : oldCfm.column_metadata.entrySet())
+            for (Map.Entry<ByteBuffer, ColumnDefinition> entry : oldCfm.column_metadata.entrySet())
             {
-                byte[] column = entry.getKey();
+                ByteBuffer column = entry.getKey();
                 ColumnDefinition def = entry.getValue();
                 if (def.index_type != null
                     && (!newCfm.column_metadata.containsKey(column) || newCfm.column_metadata.get(column).index_type == null))

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/AbstractByteOrderedPartitioner.java Fri Oct 22 03:23:26 2010
@@ -19,17 +19,14 @@
 package org.apache.cassandra.dht;
 
 import java.math.BigInteger;
-import java.text.Collator;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Locale;
 import java.util.Random;
 
-import org.apache.commons.lang.ArrayUtils;
-
 import org.apache.cassandra.db.DecoratedKey;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
+import org.apache.commons.lang.ArrayUtils;
 
 public abstract class AbstractByteOrderedPartitioner implements IPartitioner<BytesToken>
 {
@@ -37,21 +34,45 @@ public abstract class AbstractByteOrdere
     
     public static final BigInteger BYTE_MASK = new BigInteger("255");
 
-    public DecoratedKey<BytesToken> decorateKey(byte[] key)
+    public DecoratedKey<BytesToken> decorateKey(ByteBuffer key)
     {
         return new DecoratedKey<BytesToken>(getToken(key), key);
     }
     
-    public DecoratedKey<BytesToken> convertFromDiskFormat(byte[] key)
+    public DecoratedKey<BytesToken> convertFromDiskFormat(ByteBuffer key)
     {
         return new DecoratedKey<BytesToken>(getToken(key), key);
     }
 
-    public BytesToken midpoint(BytesToken ltoken, BytesToken rtoken)
+    public BytesToken midpoint(Token ltoken, Token rtoken)
     {
-        int sigbytes = Math.max(ltoken.token.length, rtoken.token.length);
-        BigInteger left = bigForBytes(ltoken.token, sigbytes);
-        BigInteger right = bigForBytes(rtoken.token, sigbytes);
+        int ll,rl;
+        ByteBuffer lb,rb;
+        
+        if(ltoken.token instanceof byte[])
+        {
+            ll = ((byte[])ltoken.token).length;
+            lb = ByteBuffer.wrap(((byte[])ltoken.token));
+        }
+        else
+        {
+            ll = ((ByteBuffer)ltoken.token).remaining();
+            lb = (ByteBuffer)ltoken.token;
+        }
+        
+        if(rtoken.token instanceof byte[])
+        {
+            rl = ((byte[])rtoken.token).length;
+            rb = ByteBuffer.wrap(((byte[])rtoken.token));
+        }
+        else
+        {
+            rl = ((ByteBuffer)rtoken.token).remaining();
+            rb = (ByteBuffer)rtoken.token;
+        }
+        int sigbytes = Math.max(ll, rl);
+        BigInteger left = bigForBytes(lb, sigbytes);
+        BigInteger right = bigForBytes(rb, sigbytes);
 
         Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(left, right, 8*sigbytes);
         return new BytesToken(bytesForBig(midpair.left, sigbytes, midpair.right));
@@ -61,14 +82,23 @@ public abstract class AbstractByteOrdere
      * Convert a byte array containing the most significant of 'sigbytes' bytes
      * representing a big-endian magnitude into a BigInteger.
      */
-    private BigInteger bigForBytes(byte[] bytes, int sigbytes)
+    private BigInteger bigForBytes(ByteBuffer bytes, int sigbytes)
     {
-        if (bytes.length != sigbytes)
+        byte[] b = new byte[sigbytes];
+        
+        // append zeros
+        Arrays.fill(b, (byte) 0);
+        
+        if (bytes.remaining() != sigbytes)
+        {                     
+            System.arraycopy(bytes.array(), bytes.position()+bytes.arrayOffset(), b, 0, bytes.remaining());
+        } 
+        else
         {
-            // append zeros
-            bytes = Arrays.copyOf(bytes, sigbytes);
+            System.arraycopy(bytes.array(), bytes.position()+bytes.arrayOffset(), b, 0, sigbytes);
         }
-        return new BigInteger(1, bytes);
+        
+        return new BigInteger(1, b);
     }
 
     /**
@@ -108,19 +138,19 @@ public abstract class AbstractByteOrdere
     }
 
     private final Token.TokenFactory<byte[]> tokenFactory = new Token.TokenFactory<byte[]>() {
-        public byte[] toByteArray(Token<byte[]> bytesToken)
+        public ByteBuffer toByteArray(Token<byte[]> bytesToken)
         {
-            return bytesToken.token;
+            return ByteBuffer.wrap(bytesToken.token);
         }
 
-        public Token<byte[]> fromByteArray(byte[] bytes)
+        public Token<byte[]> fromByteArray(ByteBuffer bytes)
         {
             return new BytesToken(bytes);
         }
 
         public String toString(Token<byte[]> bytesToken)
         {
-            return FBUtilities.bytesToHex(bytesToken.token);
+            return FBUtilities.bytesToHex(ByteBuffer.wrap(bytesToken.token));
         }
 
         public Token<byte[]> fromString(String string)
@@ -139,5 +169,5 @@ public abstract class AbstractByteOrdere
         return true;
     }
 
-    public abstract BytesToken getToken(byte[] key);
+    public abstract BytesToken getToken(ByteBuffer key);
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/ByteOrderedPartitioner.java Fri Oct 22 03:23:26 2010
@@ -18,11 +18,13 @@
 
 package org.apache.cassandra.dht;
 
+import java.nio.ByteBuffer;
+
 public class ByteOrderedPartitioner extends AbstractByteOrderedPartitioner
 {
-    public BytesToken getToken(byte[] key)
+    public BytesToken getToken(ByteBuffer key)
     {
-        if (key.length == 0)
+        if (key.remaining() == 0)
             return MINIMUM;
         return new BytesToken(key);
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/BytesToken.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/BytesToken.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/BytesToken.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/BytesToken.java Fri Oct 22 03:23:26 2010
@@ -18,28 +18,54 @@
 */
 package org.apache.cassandra.dht;
 
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.FBUtilities;
 
 public class BytesToken extends Token<byte[]>
 {
-    public BytesToken(byte... token)
+	public BytesToken(ByteBuffer token)
+	{
+		super(convertByteBuffer(token));
+	}
+	
+    public BytesToken(byte[] token)
     {
         super(token);
     }
     
+    private static byte[] convertByteBuffer(ByteBuffer token)
+    {
+    	if(token.position() == 0 && token.arrayOffset() == 0 && 
+    			   token.limit() == token.capacity())
+    	{
+    		return token.array();
+    	}
+    	else
+    	{
+    		token.mark();
+    		byte[] buf = new byte[token.remaining()];
+    		token.get(buf);
+    		token.reset();
+    				
+    		return buf;
+    	} 	
+    }
+    
     @Override
     public String toString()
     {
-        return "Token(bytes[" + FBUtilities.bytesToHex(token) + "])";
+        return "Token(bytes[" + FBUtilities.bytesToHex(ByteBuffer.wrap(token)) + "])";
     }
 
     @Override
     public int compareTo(Token<byte[]> o)
-    {
-        return FBUtilities.compareByteArrays(token, o.token);
+    {   
+        return FBUtilities.compareByteArrays(token, o.token, 0, 0, token.length, o.token.length);
     }
+    
 
     @Override
     public int hashCode()
@@ -56,6 +82,7 @@ public class BytesToken extends Token<by
         if (!(obj instanceof BytesToken))
             return false;
         BytesToken other = (BytesToken) obj;
+           
         return Arrays.equals(token, other.token);
     }
 

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/CollatingOrderPreservingPartitioner.java Fri Oct 22 03:23:26 2010
@@ -18,27 +18,20 @@
 
 package org.apache.cassandra.dht;
 
-import java.math.BigInteger;
+import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
 import java.text.Collator;
-import java.util.Arrays;
-import java.util.Comparator;
 import java.util.Locale;
-import java.util.Random;
 
-import org.apache.commons.lang.ArrayUtils;
-
-import org.apache.cassandra.db.DecoratedKey;
 import org.apache.cassandra.utils.FBUtilities;
-import org.apache.cassandra.utils.Pair;
 
 public class CollatingOrderPreservingPartitioner extends AbstractByteOrderedPartitioner
 {
     static final Collator collator = Collator.getInstance(new Locale("en", "US"));
 
-    public BytesToken getToken(byte[] key)
+    public BytesToken getToken(ByteBuffer key)
     {
-        if (key.length == 0)
+        if (key.remaining() == 0)
             return MINIMUM;
 
         String skey;
@@ -50,6 +43,6 @@ public class CollatingOrderPreservingPar
         {
             throw new RuntimeException("The provided key was not UTF8 encoded.", e);
         }
-        return new BytesToken(collator.getCollationKey(skey).toByteArray());
+        return new BytesToken(ByteBuffer.wrap(collator.getCollationKey(skey).toByteArray()));
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/IPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/IPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/IPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/IPartitioner.java Fri Oct 22 03:23:26 2010
@@ -18,7 +18,7 @@
 
 package org.apache.cassandra.dht;
 
-import java.util.Comparator;
+import java.nio.ByteBuffer;
 
 import org.apache.cassandra.db.DecoratedKey;
 
@@ -31,7 +31,7 @@ public interface IPartitioner<T extends 
      * @param key On disk representation 
      * @return DecoratedKey object
      */
-    public DecoratedKey<T> convertFromDiskFormat(byte[] key);
+    public DecoratedKey<T> convertFromDiskFormat(ByteBuffer key);
     
     /**
      * Transform key to object representation of the on-disk format.
@@ -39,7 +39,7 @@ public interface IPartitioner<T extends 
      * @param key the raw, client-facing key
      * @return decorated version of key
      */
-    public DecoratedKey<T> decorateKey(byte[] key);
+    public DecoratedKey<T> decorateKey(ByteBuffer key);
 
     /**
      * Calculate a Token representing the approximate "middle" of the given
@@ -47,7 +47,7 @@ public interface IPartitioner<T extends 
      *
      * @return The approximate midpoint between left and right.
      */
-    public T midpoint(T left, T right);
+    public Token midpoint(Token left, Token right);
 
 	/**
 	 * @return The minimum possible Token in the range that is being partitioned.
@@ -59,7 +59,7 @@ public interface IPartitioner<T extends 
      * (This is NOT a method to create a Token from its string representation;
      * for that, use TokenFactory.fromString.)
      */
-    public T getToken(byte[] key);
+    public T getToken(ByteBuffer key);
 
     /**
      * @return a randomly generated token

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/LocalPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/LocalPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/LocalPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/LocalPartitioner.java Fri Oct 22 03:23:26 2010
@@ -19,10 +19,12 @@
 
 package org.apache.cassandra.dht;
 
-import org.apache.commons.lang.ArrayUtils;
+import java.nio.ByteBuffer;
 
 import org.apache.cassandra.db.DecoratedKey;
 import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.utils.FBUtilities;
+import org.apache.commons.lang.ArrayUtils;
 
 public class LocalPartitioner implements IPartitioner<LocalToken>
 {
@@ -33,27 +35,27 @@ public class LocalPartitioner implements
         this.comparator = comparator;
     }
 
-    public DecoratedKey<LocalToken> convertFromDiskFormat(byte[] key)
+    public DecoratedKey<LocalToken> convertFromDiskFormat(ByteBuffer key)
     {
         return decorateKey(key);
     }
 
-    public DecoratedKey<LocalToken> decorateKey(byte[] key)
+    public DecoratedKey<LocalToken> decorateKey(ByteBuffer key)
     {
         return new DecoratedKey<LocalToken>(getToken(key), key);
     }
 
-    public LocalToken midpoint(LocalToken left, LocalToken right)
+    public Token midpoint(Token left, Token right)
     {
         throw new UnsupportedOperationException();
     }
 
     public LocalToken getMinimumToken()
     {
-        return new LocalToken(comparator, ArrayUtils.EMPTY_BYTE_ARRAY);
+        return new LocalToken(comparator, FBUtilities.EMPTY_BYTE_BUFFER);
     }
 
-    public LocalToken getToken(byte[] key)
+    public LocalToken getToken(ByteBuffer key)
     {
         return new LocalToken(comparator, key);
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/LocalToken.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/LocalToken.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/LocalToken.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/LocalToken.java Fri Oct 22 03:23:26 2010
@@ -18,16 +18,17 @@
 */
 package org.apache.cassandra.dht;
 
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
-public class LocalToken extends Token<byte[]>
+public class LocalToken extends Token<ByteBuffer>
 {
     private final AbstractType comparator;
 
-    public LocalToken(AbstractType comparator, byte... token)
+    public LocalToken(AbstractType comparator, ByteBuffer token)
     {
         super(token);
         this.comparator = comparator;
@@ -40,7 +41,7 @@ public class LocalToken extends Token<by
     }
 
     @Override
-    public int compareTo(Token<byte[]> o)
+    public int compareTo(Token<ByteBuffer> o)
     {
         return comparator.compare(token, o.token);
     }
@@ -49,7 +50,7 @@ public class LocalToken extends Token<by
     public int hashCode()
     {
         final int prime = 31;
-        return prime + Arrays.hashCode(token);
+        return prime + token.hashCode();
     }
 
     @Override
@@ -60,7 +61,7 @@ public class LocalToken extends Token<by
         if (!(obj instanceof LocalToken))
             return false;
         LocalToken other = (LocalToken) obj;
-        return Arrays.equals(token, other.token);
+        return ByteBufferUtil.equals(token, other.token);
     }
 
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/OrderPreservingPartitioner.java Fri Oct 22 03:23:26 2010
@@ -20,12 +20,10 @@ package org.apache.cassandra.dht;
 
 import java.io.UnsupportedEncodingException;
 import java.math.BigInteger;
+import java.nio.ByteBuffer;
 import java.nio.charset.CharacterCodingException;
-import java.util.Arrays;
-import java.util.Comparator;
 import java.util.Random;
 
-import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.DecoratedKey;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
@@ -36,21 +34,21 @@ public class OrderPreservingPartitioner 
 
     public static final BigInteger CHAR_MASK = new BigInteger("65535");
 
-    public DecoratedKey<StringToken> decorateKey(byte[] key)
+    public DecoratedKey<StringToken> decorateKey(ByteBuffer key)
     {
         return new DecoratedKey<StringToken>(getToken(key), key);
     }
     
-    public DecoratedKey<StringToken> convertFromDiskFormat(byte[] key)
+    public DecoratedKey<StringToken> convertFromDiskFormat(ByteBuffer key)
     {
         return new DecoratedKey<StringToken>(getToken(key), key);
     }
 
-    public StringToken midpoint(StringToken ltoken, StringToken rtoken)
+    public StringToken midpoint(Token ltoken, Token rtoken)
     {
-        int sigchars = Math.max(ltoken.token.length(), rtoken.token.length());
-        BigInteger left = bigForString(ltoken.token, sigchars);
-        BigInteger right = bigForString(rtoken.token, sigchars);
+        int sigchars = Math.max(((StringToken)ltoken).token.length(), ((StringToken)rtoken).token.length());
+        BigInteger left = bigForString(((StringToken)ltoken).token, sigchars);
+        BigInteger right = bigForString(((StringToken)rtoken).token, sigchars);
 
         Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(left, right, 16*sigchars);
         return new StringToken(stringForBig(midpair.left, sigchars, midpair.right));
@@ -112,11 +110,11 @@ public class OrderPreservingPartitioner 
     }
 
     private final Token.TokenFactory<String> tokenFactory = new Token.TokenFactory<String>() {
-        public byte[] toByteArray(Token<String> stringToken)
+        public ByteBuffer toByteArray(Token<String> stringToken)
         {
             try
             {
-                return stringToken.token.getBytes("UTF-8");
+                return ByteBuffer.wrap(stringToken.token.getBytes("UTF-8"));
             }
             catch (UnsupportedEncodingException e)
             {
@@ -124,11 +122,11 @@ public class OrderPreservingPartitioner 
             }
         }
 
-        public Token<String> fromByteArray(byte[] bytes)
+        public Token<String> fromByteArray(ByteBuffer bytes)
         {
             try
             {
-                return new StringToken(new String(bytes, "UTF-8"));
+                return new StringToken(new String(bytes.array(),bytes.position()+bytes.arrayOffset(),bytes.limit(), "UTF-8"));
             }
             catch (UnsupportedEncodingException e)
             {
@@ -157,7 +155,7 @@ public class OrderPreservingPartitioner 
         return true;
     }
 
-    public StringToken getToken(byte[] key)
+    public StringToken getToken(ByteBuffer key)
     {
         String skey;
         try

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/RandomPartitioner.java Fri Oct 22 03:23:26 2010
@@ -18,7 +18,10 @@
 
 package org.apache.cassandra.dht;
 
+import static com.google.common.base.Charsets.UTF_8;
+
 import java.math.BigInteger;
+import java.nio.ByteBuffer;
 import java.util.Arrays;
 
 import org.apache.cassandra.db.DecoratedKey;
@@ -26,8 +29,6 @@ import org.apache.cassandra.utils.FBUtil
 import org.apache.cassandra.utils.GuidGenerator;
 import org.apache.cassandra.utils.Pair;
 
-import static com.google.common.base.Charsets.UTF_8;
-
 /**
  * This class generates a BigIntegerToken using MD5 hash.
  */
@@ -39,18 +40,18 @@ public class RandomPartitioner implement
 
     private static final byte DELIMITER_BYTE = ":".getBytes()[0];
 
-    public DecoratedKey<BigIntegerToken> decorateKey(byte[] key)
+    public DecoratedKey<BigIntegerToken> decorateKey(ByteBuffer key)
     {
         return new DecoratedKey<BigIntegerToken>(getToken(key), key);
     }
     
-    public DecoratedKey<BigIntegerToken> convertFromDiskFormat(byte[] fromdisk)
+    public DecoratedKey<BigIntegerToken> convertFromDiskFormat(ByteBuffer fromdisk)
     {
         // find the delimiter position
         int splitPoint = -1;
-        for (int i = 0; i < fromdisk.length; i++)
+        for (int i = fromdisk.position()+fromdisk.arrayOffset(); i < fromdisk.limit(); i++)
         {
-            if (fromdisk[i] == DELIMITER_BYTE)
+            if (fromdisk.array()[i] == DELIMITER_BYTE)
             {
                 splitPoint = i;
                 break;
@@ -59,14 +60,14 @@ public class RandomPartitioner implement
         assert splitPoint != -1;
 
         // and decode the token and key
-        String token = new String(fromdisk, 0, splitPoint, UTF_8);
-        byte[] key = Arrays.copyOfRange(fromdisk, splitPoint + 1, fromdisk.length);
-        return new DecoratedKey<BigIntegerToken>(new BigIntegerToken(token), key);
+        String token = new String(fromdisk.array(), fromdisk.position()+fromdisk.arrayOffset(), splitPoint, UTF_8);
+        byte[] key = Arrays.copyOfRange(fromdisk.array(), splitPoint + 1, fromdisk.limit());
+        return new DecoratedKey<BigIntegerToken>(new BigIntegerToken(token), ByteBuffer.wrap(key));
     }
 
-    public BigIntegerToken midpoint(BigIntegerToken ltoken, BigIntegerToken rtoken)
+    public Token midpoint(Token ltoken, Token rtoken)
     {
-        Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(ltoken.token, rtoken.token, 127);
+        Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(((BigIntegerToken)ltoken).token, ((BigIntegerToken)rtoken).token, 127);
         // discard the remainder
         return new BigIntegerToken(midpair.left);
     }
@@ -78,21 +79,25 @@ public class RandomPartitioner implement
 
     public BigIntegerToken getRandomToken()
     {
-        BigInteger token = FBUtilities.md5hash(GuidGenerator.guid().getBytes());
+        BigInteger token = FBUtilities.md5hash(GuidGenerator.guidAsBytes());
         if ( token.signum() == -1 )
             token = token.multiply(BigInteger.valueOf(-1L));
         return new BigIntegerToken(token);
     }
 
     private final Token.TokenFactory<BigInteger> tokenFactory = new Token.TokenFactory<BigInteger>() {
-        public byte[] toByteArray(Token<BigInteger> bigIntegerToken)
+        public ByteBuffer toByteArray(Token<BigInteger> bigIntegerToken)
         {
-            return bigIntegerToken.token.toByteArray();
+            return ByteBuffer.wrap(bigIntegerToken.token.toByteArray());
         }
 
-        public Token<BigInteger> fromByteArray(byte[] bytes)
+        public Token<BigInteger> fromByteArray(ByteBuffer bytes)
         {
-            return new BigIntegerToken(new BigInteger(bytes));
+            byte[] b = new byte[bytes.remaining()];
+            bytes.get(b);
+            bytes.rewind();
+            
+            return new BigIntegerToken(new BigInteger(b));
         }
 
         public String toString(Token<BigInteger> bigIntegerToken)
@@ -116,9 +121,9 @@ public class RandomPartitioner implement
         return false;
     }
 
-    public BigIntegerToken getToken(byte[] key)
+    public BigIntegerToken getToken(ByteBuffer key)
     {
-        if (key.length == 0)
+        if (key.remaining() == 0)
             return MINIMUM;
         return new BigIntegerToken(FBUtilities.md5hash(key));
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/Range.java Fri Oct 22 03:23:26 2010
@@ -19,11 +19,17 @@
 package org.apache.cassandra.dht;
 
 import java.io.Serializable;
-import java.util.*;
-
-import org.apache.commons.lang.ObjectUtils;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
 
 import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.utils.FBUtilities;
+import org.apache.commons.lang.ObjectUtils;
 
 /**
  * A representation of the range that a node is responsible for on the DHT ring.
@@ -65,7 +71,7 @@ public class Range extends AbstractBound
             /*
              * This is the range (a, b] where a < b. 
              */
-            return (bi.compareTo(left) > 0 && right.compareTo(bi) >= 0);
+            return ( compare(bi,left) > 0 && compare(right,bi) >= 0);
         }
     }
 
@@ -81,13 +87,13 @@ public class Range extends AbstractBound
         boolean thatwraps = isWrapAround(that.left, that.right);
         if (thiswraps == thatwraps)
         {
-            return left.compareTo(that.left) <= 0 && that.right.compareTo(right) <= 0;
+            return compare(left,that.left) <= 0 && compare(that.right,right) <= 0;
         }
         else if (thiswraps)
         {
             // wrapping might contain non-wrapping
             // that is contained if both its tokens are in one of our wrap segments
-            return left.compareTo(that.left) <= 0 || that.right.compareTo(right) <= 0;
+            return compare(left,that.left) <= 0 || compare(that.right,right) <= 0;
         }
         else
         {
@@ -207,7 +213,44 @@ public class Range extends AbstractBound
      */
     public static boolean isWrapAround(Token left, Token right)
     {
-        return left.compareTo(right) >= 0;
+       return compare(left,right) >= 0;           
+    }
+    
+    public static int compare(Token left, Token right){
+        byte[] l,r;
+        int lo,ll,ro,rl;
+        
+        if(left.token instanceof byte[])
+        {
+            l  = (byte[]) left.token;
+            lo = 0;
+            ll = l.length;
+        }
+        else if(left.token instanceof ByteBuffer)
+        {
+            l  = ((ByteBuffer)left.token).array();
+            lo = ((ByteBuffer)left.token).position()+((ByteBuffer)left.token).arrayOffset();
+            ll = ((ByteBuffer)left.token).limit();
+        }else{
+            //Handles other token types
+            return left.compareTo(right);
+        }
+            
+        if(right.token instanceof byte[])
+        {
+            r  = (byte[]) right.token;
+            ro = 0;
+            rl = r.length;
+        }
+        else
+        {
+            r  = ((ByteBuffer)right.token).array();
+            ro = ((ByteBuffer)right.token).position()+((ByteBuffer)right.token).arrayOffset();
+            rl = ((ByteBuffer)right.token).limit();
+        }
+       
+            
+        return FBUtilities.compareByteArrays(l, r, lo, ro, ll, rl);
     }
     
     public int compareTo(Range rhs)
@@ -222,7 +265,7 @@ public class Range extends AbstractBound
         if ( isWrapAround(rhs.left, rhs.right) )
             return 1;
         
-        return right.compareTo(rhs.right);
+        return compare(right,rhs.right);
     }
     
 
@@ -246,7 +289,7 @@ public class Range extends AbstractBound
         if (!(o instanceof Range))
             return false;
         Range rhs = (Range)o;
-        return left.equals(rhs.left) && right.equals(rhs.right);
+        return compare(left,rhs.left) == 0 && compare(right,rhs.right) == 0;
     }
     
     public String toString()

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/StringToken.java Fri Oct 22 03:23:26 2010
@@ -18,7 +18,6 @@
 */
 package org.apache.cassandra.dht;
 
-import org.apache.cassandra.service.StorageService;
 
 public class StringToken extends Token<String>
 {

Modified: cassandra/trunk/src/java/org/apache/cassandra/dht/Token.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/dht/Token.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/dht/Token.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/dht/Token.java Fri Oct 22 03:23:26 2010
@@ -22,6 +22,7 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
 import java.io.Serializable;
+import java.nio.ByteBuffer;
 
 import org.apache.cassandra.io.ICompactSerializer2;
 import org.apache.cassandra.service.StorageService;
@@ -36,7 +37,7 @@ public abstract class Token<T> implement
         return serializer;
     }
 
-    T token;
+    public final T token;
 
     protected Token(T token)
     {
@@ -68,8 +69,8 @@ public abstract class Token<T> implement
 
     public static abstract class TokenFactory<T>
     {
-        public abstract byte[] toByteArray(Token<T> token);
-        public abstract Token<T> fromByteArray(byte[] bytes);
+        public abstract ByteBuffer toByteArray(Token<T> token);
+        public abstract Token<T> fromByteArray(ByteBuffer bytes);
         public abstract String toString(Token<T> token); // serialize as string, not necessarily human-readable
         public abstract Token<T> fromString(String string); // deserialize
     }
@@ -79,9 +80,9 @@ public abstract class Token<T> implement
         public void serialize(Token token, DataOutput dos) throws IOException
         {
             IPartitioner p = StorageService.getPartitioner();
-            byte[] b = p.getTokenFactory().toByteArray(token);
-            dos.writeInt(b.length);
-            dos.write(b);
+            ByteBuffer b = p.getTokenFactory().toByteArray(token);
+            dos.writeInt(b.remaining());
+            dos.write(b.array(),b.position()+b.arrayOffset(),b.remaining());
         }
 
         public Token deserialize(DataInput dis) throws IOException
@@ -90,7 +91,7 @@ public abstract class Token<T> implement
             int size = dis.readInt();
             byte[] bytes = new byte[size];
             dis.readFully(bytes);
-            return p.getTokenFactory().fromByteArray(bytes);
+            return p.getTokenFactory().fromByteArray(ByteBuffer.wrap(bytes));
         }
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyInputFormat.java Fri Oct 22 03:23:26 2010
@@ -23,29 +23,36 @@ package org.apache.cassandra.hadoop;
 
 import java.io.IOException;
 import java.net.InetAddress;
-import java.util.*;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.SortedMap;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.thrift.Cassandra;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.thrift.TokenRange;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.mapreduce.*;
+import org.apache.hadoop.mapreduce.InputFormat;
+import org.apache.hadoop.mapreduce.InputSplit;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TSocket;
 import org.apache.thrift.transport.TTransport;
 import org.apache.thrift.transport.TTransportException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Hadoop InputFormat allowing map/reduce against Cassandra rows within one ColumnFamily.
@@ -64,7 +71,7 @@ import org.apache.thrift.transport.TTran
  *
  * The default split size is 64k rows.
  */
-public class ColumnFamilyInputFormat extends InputFormat<byte[], SortedMap<byte[], IColumn>>
+public class ColumnFamilyInputFormat extends InputFormat<ByteBuffer, SortedMap<ByteBuffer, IColumn>>
 {
     private static final Logger logger = LoggerFactory.getLogger(StorageService.class);
     
@@ -227,7 +234,7 @@ public class ColumnFamilyInputFormat ext
         return map;
     }
 
-    public RecordReader<byte[], SortedMap<byte[], IColumn>> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException
+    public RecordReader<ByteBuffer, SortedMap<ByteBuffer, IColumn>> createRecordReader(InputSplit inputSplit, TaskAttemptContext taskAttemptContext) throws IOException, InterruptedException
     {
         return new ColumnFamilyRecordReader();
     }

Modified: cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java Fri Oct 22 03:23:26 2010
@@ -24,18 +24,30 @@ package org.apache.cassandra.hadoop;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.*;
-
-import com.google.common.collect.AbstractIterator;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
 
 import org.apache.cassandra.auth.SimpleAuthenticator;
-
 import org.apache.cassandra.config.ConfigurationException;
-import org.apache.cassandra.db.*;
+import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.dht.IPartitioner;
-import org.apache.cassandra.thrift.*;
+import org.apache.cassandra.thrift.AuthenticationRequest;
+import org.apache.cassandra.thrift.Cassandra;
+import org.apache.cassandra.thrift.CfDef;
 import org.apache.cassandra.thrift.Column;
+import org.apache.cassandra.thrift.ColumnOrSuperColumn;
+import org.apache.cassandra.thrift.ColumnParent;
+import org.apache.cassandra.thrift.ConsistencyLevel;
+import org.apache.cassandra.thrift.KeyRange;
+import org.apache.cassandra.thrift.KeySlice;
+import org.apache.cassandra.thrift.KsDef;
+import org.apache.cassandra.thrift.SlicePredicate;
 import org.apache.cassandra.thrift.SuperColumn;
 import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
@@ -48,11 +60,13 @@ import org.apache.thrift.protocol.TBinar
 import org.apache.thrift.transport.TFramedTransport;
 import org.apache.thrift.transport.TSocket;
 
-public class ColumnFamilyRecordReader extends RecordReader<byte[], SortedMap<byte[], IColumn>>
+import com.google.common.collect.AbstractIterator;
+
+public class ColumnFamilyRecordReader extends RecordReader<ByteBuffer, SortedMap<ByteBuffer, IColumn>>
 {
     private ColumnFamilySplit split;
     private RowIterator iter;
-    private Pair<byte[], SortedMap<byte[], IColumn>> currentRow;
+    private Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> currentRow;
     private SlicePredicate predicate;
     private int totalRowCount; // total number of rows to fetch
     private int batchRowCount; // fetch this many per batch
@@ -71,12 +85,12 @@ public class ColumnFamilyRecordReader ex
         }
     }
     
-    public byte[] getCurrentKey()
+    public ByteBuffer getCurrentKey()
     {
         return currentRow.left;
     }
 
-    public SortedMap<byte[], IColumn> getCurrentValue()
+    public SortedMap<ByteBuffer, IColumn> getCurrentValue()
     {
         return currentRow.right;
     }
@@ -172,7 +186,7 @@ public class ColumnFamilyRecordReader ex
         return split.getLocations()[0];
     }
 
-    private class RowIterator extends AbstractIterator<Pair<byte[], SortedMap<byte[], IColumn>>>
+    private class RowIterator extends AbstractIterator<Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>>>
     {
         private List<KeySlice> rows;
         private String startToken;
@@ -255,7 +269,7 @@ public class ColumnFamilyRecordReader ex
                 
                 // prepare for the next slice to be read
                 KeySlice lastRow = rows.get(rows.size() - 1);
-                byte[] rowkey = lastRow.getKey();
+                ByteBuffer rowkey = lastRow.key;
                 startToken = partitioner.getTokenFactory().toString(partitioner.getToken(rowkey));
             }
             catch (Exception e)
@@ -273,7 +287,7 @@ public class ColumnFamilyRecordReader ex
         }
 
         @Override
-        protected Pair<byte[], SortedMap<byte[], IColumn>> computeNext()
+        protected Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>> computeNext()
         {
             maybeInit();
             if (rows == null)
@@ -281,13 +295,13 @@ public class ColumnFamilyRecordReader ex
             
             totalRead++;
             KeySlice ks = rows.get(i++);
-            SortedMap<byte[], IColumn> map = new TreeMap<byte[], IColumn>(comparator);
+            SortedMap<ByteBuffer, IColumn> map = new TreeMap<ByteBuffer, IColumn>(comparator);
             for (ColumnOrSuperColumn cosc : ks.columns)
             {
                 IColumn column = unthriftify(cosc);
                 map.put(column.name(), column);
             }
-            return new Pair<byte[], SortedMap<byte[], IColumn>>(ks.key, map);
+            return new Pair<ByteBuffer, SortedMap<ByteBuffer, IColumn>>(ks.key, map);
         }
 
         private IColumn unthriftify(ColumnOrSuperColumn cosc)

Modified: cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordWriter.java Fri Oct 22 03:23:26 2010
@@ -120,8 +120,7 @@ implements org.apache.hadoop.mapred.Reco
     @Override
     public void write(ByteBuffer keybuff, List<org.apache.cassandra.avro.Mutation> value) throws IOException
     {
-        byte[] key = copy(keybuff);
-        Range range = ringCache.getRange(key);
+        Range range = ringCache.getRange(keybuff);
 
         // get the client for the given range, or create a new one
         RangeClient client = clients.get(range);
@@ -134,7 +133,7 @@ implements org.apache.hadoop.mapred.Reco
         }
 
         for (org.apache.cassandra.avro.Mutation amut : value)
-            client.put(new Pair<byte[],Mutation>(key, avroToThrift(amut)));
+            client.put(new Pair<ByteBuffer,Mutation>(keybuff, avroToThrift(amut)));
     }
 
     /**
@@ -155,7 +154,7 @@ implements org.apache.hadoop.mapred.Reco
             else
             {
                 // super column
-                byte[] scolname = copy(acosc.super_column.name);
+                ByteBuffer scolname = acosc.super_column.name;
                 List<Column> scolcols = new ArrayList<Column>(acosc.super_column.columns.size());
                 for (org.apache.cassandra.avro.Column acol : acosc.super_column.columns)
                     scolcols.add(avroToThrift(acol));
@@ -174,9 +173,9 @@ implements org.apache.hadoop.mapred.Reco
             else if (apred.column_names != null)
             {
                 // column names
-                List<byte[]> names = new ArrayList<byte[]>(apred.column_names.size());
+                List<ByteBuffer> names = new ArrayList<ByteBuffer>(apred.column_names.size());
                 for (ByteBuffer name : apred.column_names)
-                    names.add(copy(name));
+                    names.add(name);
                 deletion.setPredicate(new SlicePredicate().setColumn_names(names));
             }
             else
@@ -190,12 +189,12 @@ implements org.apache.hadoop.mapred.Reco
 
     private SliceRange avroToThrift(org.apache.cassandra.avro.SliceRange asr)
     {
-        return new SliceRange(copy(asr.start), copy(asr.finish), asr.reversed, asr.count);
+        return new SliceRange(asr.start, asr.finish, asr.reversed, asr.count);
     }
 
     private Column avroToThrift(org.apache.cassandra.avro.Column acol)
     {
-        return new Column(copy(acol.name), copy(acol.value), acol.timestamp);
+        return new Column(acol.name, acol.value, acol.timestamp);
     }
 
     /**
@@ -241,7 +240,7 @@ implements org.apache.hadoop.mapred.Reco
         private final List<InetAddress> endpoints;
         private final String columnFamily = ConfigHelper.getOutputColumnFamily(conf);
         // A bounded queue of incoming mutations for this range
-        private final BlockingQueue<Pair<byte[], Mutation>> queue = new ArrayBlockingQueue<Pair<byte[],Mutation>>(queueSize);
+        private final BlockingQueue<Pair<ByteBuffer, Mutation>> queue = new ArrayBlockingQueue<Pair<ByteBuffer,Mutation>>(queueSize);
 
         private volatile boolean run = true;
         private volatile IOException lastException;
@@ -262,7 +261,7 @@ implements org.apache.hadoop.mapred.Reco
         /**
          * enqueues the given value to Cassandra
          */
-        public void put(Pair<byte[],Mutation> value) throws IOException
+        public void put(Pair<ByteBuffer,Mutation> value) throws IOException
         {
             while (true)
             {
@@ -306,7 +305,7 @@ implements org.apache.hadoop.mapred.Reco
             outer:
             while (run || !queue.isEmpty())
             {
-                Pair<byte[], Mutation> mutation;
+                Pair<ByteBuffer, Mutation> mutation;
                 try
                 {
                     mutation = queue.take();
@@ -317,7 +316,7 @@ implements org.apache.hadoop.mapred.Reco
                     continue;
                 }
 
-                Map<byte[], Map<String, List<Mutation>>> batch = new HashMap<byte[], Map<String, List<Mutation>>>();
+                Map<ByteBuffer, Map<String, List<Mutation>>> batch = new HashMap<ByteBuffer, Map<String, List<Mutation>>>();
                 while (batch.size() < batchThreshold)
                 {
                     Map<String, List<Mutation>> subBatch = Collections.singletonMap(columnFamily, Arrays.asList(mutation.right));

Modified: cassandra/trunk/src/java/org/apache/cassandra/hadoop/ConfigHelper.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/hadoop/ConfigHelper.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/hadoop/ConfigHelper.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/hadoop/ConfigHelper.java Fri Oct 22 03:23:26 2010
@@ -20,6 +20,8 @@ package org.apache.cassandra.hadoop;
  * 
  */
 
+import java.nio.ByteBuffer;
+
 import org.apache.cassandra.config.ConfigurationException;
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.thrift.SlicePredicate;
@@ -164,7 +166,7 @@ public class ConfigHelper
         TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
         try
         {
-            return FBUtilities.bytesToHex(serializer.serialize(predicate));
+            return FBUtilities.bytesToHex(ByteBuffer.wrap(serializer.serialize(predicate)));
         }
         catch (TException e)
         {

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/LazilyCompactedRow.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/LazilyCompactedRow.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/LazilyCompactedRow.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/LazilyCompactedRow.java Fri Oct 22 03:23:26 2010
@@ -193,7 +193,7 @@ public class LazilyCompactedRow extends 
         @Override
         protected boolean isEqual(IColumn o1, IColumn o2)
         {
-            return Arrays.equals(o1.name(), o2.name());
+            return o1.name().equals(o2.name());
         }
 
         public void reduce(IColumn current)

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/SerDeUtils.java Fri Oct 22 03:23:26 2010
@@ -61,9 +61,9 @@ public final class SerDeUtils
      * @param ob An empty object to deserialize into (must not be null).
      * @throws IOException
      */
-    public static <T extends SpecificRecord> T deserialize(Schema writer, byte[] bytes, T ob) throws IOException
+    public static <T extends SpecificRecord> T deserialize(Schema writer, ByteBuffer bytes, T ob) throws IOException
     {
-        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(bytes, null);
+        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(bytes.array(),bytes.position()+bytes.arrayOffset(),bytes.remaining(), null);
         SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
         reader.setExpected(ob.getSchema());
         return reader.read(ob, dec);
@@ -73,14 +73,14 @@ public final class SerDeUtils
      * Serializes a single object.
      * @param o Object to serialize
      */
-    public static <T extends SpecificRecord> byte[] serialize(T o) throws IOException
+    public static <T extends SpecificRecord> ByteBuffer serialize(T o) throws IOException
     {
         OutputBuffer buff = new OutputBuffer();
         BinaryEncoder enc = new BinaryEncoder(buff);
         SpecificDatumWriter<T> writer = new SpecificDatumWriter<T>(o.getSchema());
         writer.write(o, enc);
         enc.flush();
-        return buff.asByteArray();
+        return ByteBuffer.wrap(buff.asByteArray());
     }
 
 	/**
@@ -89,9 +89,9 @@ public final class SerDeUtils
      * @param bytes Array to deserialize from
      * @throws IOException
      */
-    public static <T extends SpecificRecord> T deserializeWithSchema(byte[] bytes, T ob) throws IOException
+    public static <T extends SpecificRecord> T deserializeWithSchema(ByteBuffer bytes, T ob) throws IOException
     {
-        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(bytes, null);
+        BinaryDecoder dec = DIRECT_DECODERS.createBinaryDecoder(bytes.array(),bytes.position()+bytes.arrayOffset(), bytes.remaining(), null);
         Schema writer = Schema.parse(dec.readString(new Utf8()).toString());
         SpecificDatumReader<T> reader = new SpecificDatumReader<T>(writer);
         reader.setExpected(ob.getSchema());
@@ -103,7 +103,7 @@ public final class SerDeUtils
      * more efficient to store the Schema independently.
      * @param o Object to serialize
      */
-    public static <T extends SpecificRecord> byte[] serializeWithSchema(T o) throws IOException
+    public static <T extends SpecificRecord> ByteBuffer serializeWithSchema(T o) throws IOException
     {
         OutputBuffer buff = new OutputBuffer();
         BinaryEncoder enc = new BinaryEncoder(buff);
@@ -111,7 +111,7 @@ public final class SerDeUtils
         SpecificDatumWriter<T> writer = new SpecificDatumWriter<T>(o.getSchema());
         writer.write(o, enc);
         enc.flush();
-        return buff.asByteArray();
+        return ByteBuffer.wrap(buff.asByteArray());
     }
 
     /**

Modified: cassandra/trunk/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/io/sstable/IndexHelper.java?rev=1026200&r1=1026199&r2=1026200&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/io/sstable/IndexHelper.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/io/sstable/IndexHelper.java Fri Oct 22 03:23:26 2010
@@ -18,14 +18,23 @@
 
 package org.apache.cassandra.io.sstable;
 
-import java.io.*;
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.DataInput;
+import java.io.DataInputStream;
+import java.io.DataOutput;
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 
 import org.apache.cassandra.db.marshal.AbstractType;
-import org.apache.cassandra.utils.BloomFilter;
-import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.io.util.FileDataInput;
 import org.apache.cassandra.io.util.FileMark;
+import org.apache.cassandra.utils.BloomFilter;
+import org.apache.cassandra.utils.FBUtilities;
 
 /**
  * Provides helper to serialize, deserialize and use column indexes.
@@ -102,9 +111,9 @@ public class IndexHelper
      * the index of the IndexInfo in which @name will be found.
      * If the index is @indexList.size(), the @name appears nowhere.
      */
-    public static int indexFor(byte[] name, List<IndexInfo> indexList, AbstractType comparator, boolean reversed)
+    public static int indexFor(ByteBuffer name, List<IndexInfo> indexList, AbstractType comparator, boolean reversed)
     {
-        if (name.length == 0 && reversed)
+        if (name.remaining() == 0 && reversed)
             return indexList.size() - 1;
         IndexInfo target = new IndexInfo(name, name, 0, 0);
         int index = Collections.binarySearch(indexList, target, getComparator(comparator));
@@ -125,11 +134,11 @@ public class IndexHelper
     public static class IndexInfo
     {
         public final long width;
-        public final byte[] lastName;
-        public final byte[] firstName;
+        public final ByteBuffer lastName;
+        public final ByteBuffer firstName;
         public final long offset;
 
-        public IndexInfo(byte[] firstName, byte[] lastName, long offset, long width)
+        public IndexInfo(ByteBuffer firstName, ByteBuffer lastName, long offset, long width)
         {
             this.firstName = firstName;
             this.lastName = lastName;
@@ -147,7 +156,7 @@ public class IndexHelper
 
         public int serializedSize()
         {
-            return 2 + firstName.length + 2 + lastName.length + 8 + 8;
+            return 2 + firstName.remaining() + 2 + lastName.remaining() + 8 + 8;
         }
 
         public static IndexInfo deserialize(FileDataInput dis) throws IOException



Mime
View raw message