cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1060854 - in /cassandra/branches/cassandra-0.7: src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/columniterator/ src/java/org/apache/cassandra/db/filter/ src/java/org/apache/cassandra/io/sstable/ src/java/org/apache/cassa...
Date Wed, 19 Jan 2011 16:37:22 GMT
Author: jbellis
Date: Wed Jan 19 16:37:21 2011
New Revision: 1060854

URL: http://svn.apache.org/viewvc?rev=1060854&view=rev
Log:
move read methods from FBU to BBU
patch by slebresne; reviewed by jbellis for CASSANDRA-2009

Modified:
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnSerializer.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/Row.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutation.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SuperColumn.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/WriteResponse.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableSliceIterator.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/filter/QueryPath.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/KeyIterator.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTable.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/ByteBufferUtil.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
    cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnSerializer.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnSerializer.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnSerializer.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnSerializer.java
Wed Jan 19 16:37:21 2011
@@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory;
 
 import org.apache.cassandra.io.ICompactSerializer2;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.FBUtilities;
 
 public class ColumnSerializer implements ICompactSerializer2<IColumn>
 {
@@ -64,7 +63,7 @@ public class ColumnSerializer implements
 
     public Column deserialize(DataInput dis) throws IOException
     {
-        ByteBuffer name = FBUtilities.readShortByteArray(dis);
+        ByteBuffer name = ByteBufferUtil.readWithShortLength(dis);
         if (name.remaining() <= 0)
             throw new CorruptColumnException("invalid column name length " + name.remaining());
 
@@ -74,7 +73,7 @@ public class ColumnSerializer implements
             int ttl = dis.readInt();
             int expiration = dis.readInt();
             long ts = dis.readLong();
-            ByteBuffer value = FBUtilities.readByteArray(dis);
+            ByteBuffer value = ByteBufferUtil.readWithLength(dis);
             if ((int) (System.currentTimeMillis() / 1000 ) > expiration)
             {
                 // the column is now expired, we can safely return a simple
@@ -92,7 +91,7 @@ public class ColumnSerializer implements
         else
         {
             long ts = dis.readLong();
-            ByteBuffer value = FBUtilities.readByteArray(dis);
+            ByteBuffer value = ByteBufferUtil.readWithLength(dis);
             return (b & DELETION_MASK) == 0
                    ? new Column(name, value, ts)
                    : new DeletedColumn(name, value, ts);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/Row.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/Row.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/Row.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/Row.java Wed Jan 19
16:37:21 2011
@@ -28,7 +28,6 @@ import org.slf4j.LoggerFactory;
 import org.apache.cassandra.io.ICompactSerializer;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.FBUtilities;
 
 public class Row
 {
@@ -71,7 +70,7 @@ class RowSerializer implements ICompactS
 
     public Row deserialize(DataInputStream dis) throws IOException
     {
-        return new Row(StorageService.getPartitioner().decorateKey(FBUtilities.readShortByteArray(dis)),
+        return new Row(StorageService.getPartitioner().decorateKey(ByteBufferUtil.readWithShortLength(dis)),
                        ColumnFamily.serializer().deserialize(dis));
     }
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutation.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutation.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutation.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutation.java Wed
Jan 19 16:37:21 2011
@@ -392,7 +392,7 @@ class RowMutationSerializer implements I
     public RowMutation deserialize(DataInputStream dis) throws IOException
     {
         String table = dis.readUTF();
-        ByteBuffer key = FBUtilities.readShortByteArray(dis);
+        ByteBuffer key = ByteBufferUtil.readWithShortLength(dis);
         Map<Integer, ColumnFamily> modifications = defreezeTheMaps(dis);
         return new RowMutation(table, key, modifications);
     }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/RowMutationVerbHandler.java
Wed Jan 19 16:37:21 2011
@@ -59,7 +59,7 @@ public class RowMutationVerbHandler impl
                 DataInputStream dis = new DataInputStream(new ByteArrayInputStream(hintedBytes));
                 while (dis.available() > 0)
                 {
-                    ByteBuffer addressBytes = FBUtilities.readShortByteArray(dis);
+                    ByteBuffer addressBytes = ByteBufferUtil.readWithShortLength(dis);
                     if (logger_.isDebugEnabled())
                         logger_.debug("Adding hint for " + InetAddress.getByName(ByteBufferUtil.string(addressBytes,
Charsets.UTF_8)));
                     RowMutation hintedMutation = new RowMutation(Table.SYSTEM_TABLE, addressBytes);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
Wed Jan 19 16:37:21 2011
@@ -99,14 +99,14 @@ class SliceByNamesReadCommandSerializer 
     {
         boolean isDigest = dis.readBoolean();
         String table = dis.readUTF();
-        ByteBuffer key = FBUtilities.readShortByteArray(dis);
+        ByteBuffer key = ByteBufferUtil.readWithShortLength(dis);
         QueryPath columnParent = QueryPath.deserialize(dis);
 
         int size = dis.readInt();
         List<ByteBuffer> columns = new ArrayList<ByteBuffer>();
         for (int i = 0; i < size; ++i)
         {
-            columns.add(FBUtilities.readShortByteArray(dis));
+            columns.add(ByteBufferUtil.readWithShortLength(dis));
         }
         SliceByNamesReadCommand rm = new SliceByNamesReadCommand(table, key, columnParent,
columns);
         rm.setDigestQuery(isDigest);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceFromReadCommand.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
Wed Jan 19 16:37:21 2011
@@ -100,10 +100,10 @@ class SliceFromReadCommandSerializer ext
     {
         boolean isDigest = dis.readBoolean();
         SliceFromReadCommand rm = new SliceFromReadCommand(dis.readUTF(),
-                                                           FBUtilities.readShortByteArray(dis),
+                                                           ByteBufferUtil.readWithShortLength(dis),
                                                            QueryPath.deserialize(dis),
-                                                           FBUtilities.readShortByteArray(dis),
-                                                           FBUtilities.readShortByteArray(dis),
+                                                           ByteBufferUtil.readWithShortLength(dis),
+                                                           ByteBufferUtil.readWithShortLength(dis),
                                                            dis.readBoolean(),
                                                            dis.readInt());
         rm.setDigestQuery(isDigest);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SuperColumn.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SuperColumn.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SuperColumn.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/SuperColumn.java Wed
Jan 19 16:37:21 2011
@@ -351,7 +351,7 @@ class SuperColumnSerializer implements I
 
     public IColumn deserialize(DataInput dis) throws IOException
     {
-        ByteBuffer name = FBUtilities.readShortByteArray(dis);
+        ByteBuffer name = ByteBufferUtil.readWithShortLength(dis);
         int localDeleteTime = dis.readInt();
         if (localDeleteTime != Integer.MIN_VALUE && localDeleteTime <= 0)
         {

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/WriteResponse.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/WriteResponse.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/WriteResponse.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/WriteResponse.java Wed
Jan 19 16:37:21 2011
@@ -89,7 +89,7 @@ public class WriteResponse 
         public WriteResponse deserialize(DataInputStream dis) throws IOException
         {
             String table = dis.readUTF();
-            ByteBuffer key = FBUtilities.readShortByteArray(dis);
+            ByteBuffer key = ByteBufferUtil.readWithShortLength(dis);
             boolean status = dis.readBoolean();
             return new WriteResponse(table, key, status);
         }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableNamesIterator.java
Wed Jan 19 16:37:21 2011
@@ -39,8 +39,8 @@ import org.apache.cassandra.io.sstable.S
 import org.apache.cassandra.io.util.FileDataInput;
 import org.apache.cassandra.io.util.FileMark;
 import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.Filter;
-import org.apache.cassandra.utils.FBUtilities;
 
 public class SSTableNamesIterator extends SimpleAbstractColumnIterator implements IColumnIterator
 {
@@ -65,7 +65,7 @@ public class SSTableNamesIterator extend
         {
             DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                              sstable.descriptor,
-                                                             FBUtilities.readShortByteArray(file));
+                                                             ByteBufferUtil.readWithShortLength(file));
             assert keyInDisk.equals(key) : String.format("%s != %s in %s", keyInDisk, key,
file.getPath());
             SSTableReader.readRowSize(file, sstable.descriptor);
             read(sstable, file);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableSliceIterator.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableSliceIterator.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableSliceIterator.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/SSTableSliceIterator.java
Wed Jan 19 16:37:21 2011
@@ -32,7 +32,7 @@ import org.apache.cassandra.db.Decorated
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.io.util.FileDataInput;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 /**
  *  A Column Iterator over SSTable
@@ -54,7 +54,7 @@ public class SSTableSliceIterator implem
         {
             DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                              sstable.descriptor,
-                                                             FBUtilities.readShortByteArray(fileToClose));
+                                                             ByteBufferUtil.readWithShortLength(fileToClose));
             assert keyInDisk.equals(key)
                    : String.format("%s != %s in %s", keyInDisk, key, fileToClose.getPath());
             SSTableReader.readRowSize(fileToClose, sstable.descriptor);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/filter/QueryPath.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/filter/QueryPath.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/filter/QueryPath.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/filter/QueryPath.java
Wed Jan 19 16:37:21 2011
@@ -29,7 +29,6 @@ import java.nio.ByteBuffer;
 import org.apache.cassandra.thrift.ColumnParent;
 import org.apache.cassandra.thrift.ColumnPath;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.FBUtilities;
 
 public class QueryPath
 {
@@ -92,8 +91,8 @@ public class QueryPath
     public static QueryPath deserialize(DataInputStream din) throws IOException
     {
         String cfName = din.readUTF();
-        ByteBuffer scName = FBUtilities.readShortByteArray(din);
-        ByteBuffer cName = FBUtilities.readShortByteArray(din);
+        ByteBuffer scName = ByteBufferUtil.readWithShortLength(din);
+        ByteBuffer cName = ByteBufferUtil.readWithShortLength(din);
         return new QueryPath(cfName.isEmpty() ? null : cfName, 
                              scName.remaining() == 0 ? null : scName, 
                              cName.remaining() == 0 ? null : cName);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/IndexHelper.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
Wed Jan 19 16:37:21 2011
@@ -178,7 +178,7 @@ public class IndexHelper
 
         public static IndexInfo deserialize(FileDataInput dis) throws IOException
         {
-            return new IndexInfo(FBUtilities.readShortByteArray(dis), FBUtilities.readShortByteArray(dis),
dis.readLong(), dis.readLong());
+            return new IndexInfo(ByteBufferUtil.readWithShortLength(dis), ByteBufferUtil.readWithShortLength(dis),
dis.readLong(), dis.readLong());
         }
     }
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/KeyIterator.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/KeyIterator.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/KeyIterator.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/KeyIterator.java
Wed Jan 19 16:37:21 2011
@@ -32,7 +32,7 @@ import com.google.common.collect.Abstrac
 import org.apache.cassandra.db.DecoratedKey;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
 import org.apache.cassandra.service.StorageService;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class KeyIterator extends AbstractIterator<DecoratedKey> implements Iterator<DecoratedKey>,
Closeable
 {
@@ -61,7 +61,7 @@ public class KeyIterator extends Abstrac
         {
             if (in.isEOF())
                 return endOfData();
-            DecoratedKey key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
FBUtilities.readShortByteArray(in));
+            DecoratedKey key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
ByteBufferUtil.readWithShortLength(in));
             in.readLong(); // skip data position
             return key;
         }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTable.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTable.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTable.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTable.java
Wed Jan 19 16:37:21 2011
@@ -34,8 +34,8 @@ import org.apache.cassandra.config.CFMet
 import org.apache.cassandra.dht.IPartitioner;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
 import org.apache.cassandra.io.util.FileUtils;
+import org.apache.cassandra.utils.ByteBufferUtil;
 import org.apache.cassandra.utils.EstimatedHistogram;
-import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
 
 /**
@@ -209,7 +209,7 @@ public abstract class SSTable
         while (dataPosition < BYTES_CAP && keys < SAMPLES_CAP)
         {
             dfile.seek(dataPosition);
-            FBUtilities.skipShortByteArray(dfile);
+            ByteBufferUtil.skipShortLength(dfile);
             long dataSize = SSTableReader.readRowSize(dfile, desc);
             dataPosition = dfile.getFilePointer() + dataSize;
             keys++;
@@ -226,7 +226,7 @@ public abstract class SSTable
         int keys = 0;
         while (ifile.getFilePointer() < BYTES_CAP && keys < SAMPLES_CAP)
         {
-            FBUtilities.skipShortByteArray(ifile);
+            ByteBufferUtil.skipShortLength(ifile);
             ifile.skipBytes(8);
             keys++;
         }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableReader.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableReader.java
Wed Jan 19 16:37:21 2011
@@ -296,8 +296,8 @@ public class SSTableReader extends SSTab
 
                 boolean shouldAddEntry = indexSummary.shouldAddEntry();
                 ByteBuffer key = (ByteBuffer) ((shouldAddEntry || cacheLoading || recreatebloom)
-                             ? FBUtilities.readShortByteArray(input)
-                             : FBUtilities.skipShortByteArray(input));
+                             ? ByteBufferUtil.readWithShortLength(input)
+                             : ByteBufferUtil.skipShortLength(input));
                 long dataPosition = input.readLong();
                 if (key != null)
                 {
@@ -469,7 +469,7 @@ public class SSTableReader extends SSTab
                 while (!input.isEOF())
                 {
                     // read key & data position from index entry
-                    DecoratedKey indexDecoratedKey = decodeKey(partitioner, descriptor, FBUtilities.readShortByteArray(input));
+                    DecoratedKey indexDecoratedKey = decodeKey(partitioner, descriptor, ByteBufferUtil.readWithShortLength(input));
                     long dataPosition = input.readLong();
 
                     int comparison = indexDecoratedKey.compareTo(decoratedKey);

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableScanner.java
Wed Jan 19 16:37:21 2011
@@ -33,7 +33,7 @@ import org.apache.cassandra.db.Decorated
 import org.apache.cassandra.db.columniterator.IColumnIterator;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 
 public class SSTableScanner implements Iterator<IColumnIterator>, Closeable
@@ -169,7 +169,7 @@ public class SSTableScanner implements I
 
                 DecoratedKey key = SSTableReader.decodeKey(sstable.partitioner,
                                                            sstable.descriptor,
-                                                           FBUtilities.readShortByteArray(file));
+                                                           ByteBufferUtil.readWithShortLength(file));
                 long dataSize = SSTableReader.readRowSize(file, sstable.descriptor);
                 long dataStart = file.getFilePointer();
                 finishedAt = dataStart + dataSize;

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/io/sstable/SSTableWriter.java
Wed Jan 19 16:37:21 2011
@@ -288,7 +288,7 @@ public class SSTableWriter extends SSTab
                 long rowPosition = 0;
                 while (rowPosition < dfile.length())
                 {
-                    key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
FBUtilities.readShortByteArray(dfile));
+                    key = SSTableReader.decodeKey(StorageService.getPartitioner(), desc,
ByteBufferUtil.readWithShortLength(dfile));
                     iwriter.afterAppend(key, rowPosition);
 
                     long dataSize = SSTableReader.readRowSize(dfile, desc);

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=1060854&r1=1060853&r2=1060854&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
Wed Jan 19 16:37:21 2011
@@ -18,13 +18,16 @@
  */
 package org.apache.cassandra.utils;
 
+import java.io.DataInput;
 import java.io.DataOutput;
+import java.io.EOFException;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 
+import org.apache.cassandra.io.util.FileDataInput;
 import org.apache.commons.lang.ArrayUtils;
 
 /**
@@ -268,6 +271,68 @@ public class ByteBufferUtil
         }
     }
 
+    public static ByteBuffer readWithLength(DataInput in) throws IOException
+    {
+        int length = in.readInt();
+        if (length < 0)
+        {
+            throw new IOException("Corrupt (negative) value length encountered");
+        }
+
+        return ByteBufferUtil.read(in, length);
+    }
+
+    /* @return An unsigned short in an integer. */
+    private static int readShortLength(DataInput in) throws IOException
+    {
+        int length = (in.readByte() & 0xFF) << 8;
+        return length | (in.readByte() & 0xFF);
+    }
+
+    /**
+     * @param in data input
+     * @return An unsigned short in an integer.
+     * @throws IOException if an I/O error occurs.
+     */
+    public static ByteBuffer readWithShortLength(DataInput in) throws IOException
+    {
+        return ByteBufferUtil.read(in, readShortLength(in));
+    }
+
+    /**
+     * @param in data input
+     * @return null
+     * @throws IOException if an I/O error occurs.
+     */
+    public static void skipShortLength(DataInput in) throws IOException
+    {
+        int skip = readShortLength(in);
+        while (skip > 0)
+        {
+            int skipped = in.skipBytes(skip);
+            if (skipped == 0) throw new EOFException();
+            skip -= skipped;
+        }
+    }
+
+    private static ByteBuffer read(DataInput in, int length) throws IOException
+    {
+        ByteBuffer array;
+
+        if (in instanceof FileDataInput)
+        {
+            array = ((FileDataInput) in).readBytes(length);
+        }
+        else
+        {
+            byte[] buff = new byte[length];
+            in.readFully(buff);
+            array = ByteBuffer.wrap(buff);
+        }
+
+        return array;
+    }
+
     /**
      * Convert a byte buffer to an integer.
      * Does not change the byte buffer position.
@@ -289,4 +354,5 @@ public class ByteBufferUtil
     {
         return ByteBuffer.allocate(8).putLong(0, n);
     }
+
 }

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/utils/FBUtilities.java
Wed Jan 19 16:37:21 2011
@@ -37,7 +37,6 @@ import java.util.concurrent.atomic.Atomi
 
 import com.google.common.base.Charsets;
 import com.google.common.base.Joiner;
-import org.apache.cassandra.io.util.FileDataInput;
 import org.apache.commons.collections.iterators.CollatingIterator;
 import org.apache.commons.lang.ArrayUtils;
 import org.slf4j.Logger;
@@ -237,51 +236,6 @@ public class FBUtilities
     	return result;
 	}
 
-    public static ByteBuffer readByteArray(DataInput in) throws IOException
-    {
-        int length = in.readInt();
-        if (length < 0)
-        {
-            throw new IOException("Corrupt (negative) value length encountered");
-        }
-
-        return readDataBytes(in, length);
-    }
-
-    /* @return An unsigned short in an integer. */
-    private static int readShortLength(DataInput in) throws IOException
-    {
-        int length = (in.readByte() & 0xFF) << 8;
-        return length | (in.readByte() & 0xFF);
-    }
-
-    /**
-     * @param in data input
-     * @return An unsigned short in an integer.
-     * @throws IOException if an I/O error occurs.
-     */
-    public static ByteBuffer readShortByteArray(DataInput in) throws IOException
-    {
-        return readDataBytes(in, readShortLength(in));
-    }
-
-    /**
-     * @param in data input
-     * @return null
-     * @throws IOException if an I/O error occurs.
-     */
-    public static byte[] skipShortByteArray(DataInput in) throws IOException
-    {
-        int skip = readShortLength(in);
-        while (skip > 0)
-        {
-            int skipped = in.skipBytes(skip);
-            if (skipped == 0) throw new EOFException();
-            skip -= skipped;
-        }
-        return null;
-    }
-
     public static byte[] hexToBytes(String str)
     {
         if (str.length() % 2 == 1)
@@ -637,24 +591,6 @@ public class FBUtilities
         return field;
     }
 
-    private static ByteBuffer readDataBytes(DataInput in, int length) throws IOException
-    {
-        ByteBuffer array;
-
-        if (in instanceof FileDataInput)
-        {
-            array = ((FileDataInput) in).readBytes(length);
-        }
-        else
-        {
-            byte[] buff = new byte[length];
-            in.readFully(buff);
-            array = ByteBuffer.wrap(buff);
-        }
-
-        return array;
-    }
-
     public static InputStream inputStream(ByteBuffer bytes)
     {
         final ByteBuffer copy = ByteBufferUtil.clone(bytes);

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java (original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/db/TableTest.java Wed
Jan 19 16:37:21 2011
@@ -42,7 +42,6 @@ import org.apache.cassandra.db.marshal.L
 import org.apache.cassandra.io.sstable.IndexHelper;
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
-import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.ByteBufferUtil;
 
 
@@ -405,7 +404,7 @@ public class TableTest extends CleanupHe
         long position = sstable.getPosition(key, SSTableReader.Operator.EQ);
         BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.getFilename(),
"r");
         file.seek(position);
-        assert FBUtilities.readShortByteArray(file).equals(key.key);
+        assert ByteBufferUtil.readWithShortLength(file).equals(key.key);
         SSTableReader.readRowSize(file, sstable.descriptor);
         IndexHelper.skipBloomFilter(file);
         ArrayList<IndexHelper.IndexInfo> indexes = IndexHelper.deserializeIndex(file);

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableReaderTest.java
Wed Jan 19 16:37:21 2011
@@ -39,7 +39,6 @@ import org.apache.cassandra.io.util.File
 import org.apache.cassandra.io.util.MmappedSegmentedFile;
 import org.apache.cassandra.service.StorageService;
 import org.apache.cassandra.utils.ByteBufferUtil;
-import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.utils.Pair;
 
 import org.apache.cassandra.Util;
@@ -120,7 +119,7 @@ public class SSTableReaderTest extends C
             FileDataInput file = sstable.getFileDataInput(dk, DatabaseDescriptor.getIndexedReadBufferSizeInKB()
* 1024);
             DecoratedKey keyInDisk = SSTableReader.decodeKey(sstable.partitioner,
                                                              sstable.descriptor,
-                                                             FBUtilities.readShortByteArray(file));
+                                                             ByteBufferUtil.readWithShortLength(file));
             assert keyInDisk.equals(dk) : String.format("%s != %s in %s", keyInDisk, dk,
file.getPath());
         }
 

Modified: cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java?rev=1060854&r1=1060853&r2=1060854&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java
(original)
+++ cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/io/sstable/SSTableTest.java
Wed Jan 19 16:37:21 2011
@@ -27,7 +27,7 @@ import org.junit.Test;
 
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.io.util.BufferedRandomAccessFile;
-import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.ByteBufferUtil;
 
 public class SSTableTest extends CleanupHelper
 {
@@ -52,7 +52,7 @@ public class SSTableTest extends Cleanup
     {
         BufferedRandomAccessFile file = new BufferedRandomAccessFile(sstable.getFilename(),
"r");
         file.seek(sstable.getPosition(sstable.partitioner.decorateKey(key), SSTableReader.Operator.EQ));
-        assert key.equals(FBUtilities.readShortByteArray(file));
+        assert key.equals(ByteBufferUtil.readWithShortLength(file));
         int size = (int)SSTableReader.readRowSize(file, sstable.descriptor);
         byte[] bytes2 = new byte[size];
         file.readFully(bytes2);
@@ -84,7 +84,7 @@ public class SSTableTest extends Cleanup
         for (ByteBuffer key : keys)
         {
             file.seek(sstable.getPosition(sstable.partitioner.decorateKey(key), SSTableReader.Operator.EQ));
-            assert key.equals( FBUtilities.readShortByteArray(file));
+            assert key.equals( ByteBufferUtil.readWithShortLength(file));
             int size = (int)SSTableReader.readRowSize(file, sstable.descriptor);
             byte[] bytes2 = new byte[size];
             file.readFully(bytes2);



Mime
View raw message