cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r934151 - in /cassandra/trunk/src/java/org/apache/cassandra: db/ db/filter/ io/sstable/ utils/
Date Wed, 14 Apr 2010 19:52:16 GMT
Author: gdusbabek
Date: Wed Apr 14 19:52:15 2010
New Revision: 934151

URL: http://svn.apache.org/viewvc?rev=934151&view=rev
Log:
extract read/write-Name. Patch by Stu Hood, reviewed by Gary Dusbabek. CASSANDRA-767

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
    cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java
    cassandra/trunk/src/java/org/apache/cassandra/db/DBConstants.java
    cassandra/trunk/src/java/org/apache/cassandra/db/IColumn.java
    cassandra/trunk/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
    cassandra/trunk/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
    cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryPath.java
    cassandra/trunk/src/java/org/apache/cassandra/io/sstable/IndexHelper.java
    cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/Column.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/Column.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/Column.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/Column.java Wed Apr 14 19:52:15 2010
@@ -132,18 +132,13 @@ public class Column implements IColumn
     {
         /*
          * Size of a column is =
-         *   size of a name (UtfPrefix + length of the string)
+         *   size of a name (short + length of the string)
          * + 1 byte to indicate if the column has been deleted
          * + 8 bytes for timestamp
          * + 4 bytes which basically indicates the size of the byte array
          * + entire byte array.
         */
-
-        /*
-           * We store the string as UTF-8 encoded, so when we calculate the length, it
-           * should be converted to UTF-8.
-           */
-        return IColumn.UtfPrefix_ + name.length + DBConstants.boolSize_ + DBConstants.tsSize_
+ DBConstants.intSize_ + value.length;
+        return DBConstants.shortSize_ + name.length + DBConstants.boolSize_ + DBConstants.tsSize_
+ DBConstants.intSize_ + value.length;
     }
 
     /*

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnSerializer.java Wed Apr 14 19:52:15
2010
@@ -28,37 +28,9 @@ import org.apache.cassandra.utils.FBUtil
 
 public class ColumnSerializer implements ICompactSerializer2<IColumn>
 {
-    public static void writeName(byte[] name, DataOutput out)
-    {
-        int length = name.length;
-        assert 0 <= length && length <= IColumn.MAX_NAME_LENGTH;
-        try
-        {
-            out.writeByte((length >> 8) & 0xFF);
-            out.writeByte(length & 0xFF);
-            out.write(name);
-        }
-        catch (IOException e)
-        {
-            throw new RuntimeException(e);
-        }
-    }
-
-    public static byte[] readName(DataInput in) throws IOException
-    {
-        int length = 0;
-        length |= (in.readByte() & 0xFF) << 8;
-        length |= in.readByte() & 0xFF;
-        if (!(0 <= length && length <= IColumn.MAX_NAME_LENGTH))
-            throw new IOException("Corrupt name length " + length);
-        byte[] bytes = new byte[length];
-        in.readFully(bytes);
-        return bytes;
-    }
-
     public void serialize(IColumn column, DataOutput dos)
     {
-        ColumnSerializer.writeName(column.name(), dos);
+        FBUtilities.writeShortByteArray(column.name(), dos);
         try
         {
             dos.writeBoolean(column.isMarkedForDelete());
@@ -73,7 +45,7 @@ public class ColumnSerializer implements
 
     public Column deserialize(DataInput dis) throws IOException
     {
-        byte[] name = ColumnSerializer.readName(dis);
+        byte[] name = FBUtilities.readShortByteArray(dis);
         boolean delete = dis.readBoolean();
         long ts = dis.readLong();
         int length = dis.readInt();

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/DBConstants.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/DBConstants.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/DBConstants.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/DBConstants.java Wed Apr 14 19:52:15
2010
@@ -23,5 +23,6 @@ class DBConstants
 	public static final int boolSize_ = 1;
 	public static final int intSize_ = 4;
 	public static final int longSize_ = 8;
+	public static final int shortSize_ = 2;
 	public static final int tsSize_ = 8;
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/IColumn.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/IColumn.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/IColumn.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/IColumn.java Wed Apr 14 19:52:15 2010
@@ -22,11 +22,11 @@ import java.util.Collection;
 import java.security.MessageDigest;
 
 import org.apache.cassandra.db.marshal.AbstractType;
+import org.apache.cassandra.utils.FBUtilities;
 
 public interface IColumn
 {
-    public static short UtfPrefix_ = 2;
-    public static final int MAX_NAME_LENGTH = 0xFFFF; // we use 2 bytes to hold length
+    public static final int MAX_NAME_LENGTH = FBUtilities.MAX_UNSIGNED_SHORT;
 
     public boolean isMarkedForDelete();
     public long getMarkedForDeleteAt();

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/SliceByNamesReadCommand.java Wed Apr
14 19:52:15 2010
@@ -24,6 +24,7 @@ import java.util.*;
 
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.thrift.ColumnParent;
+import org.apache.cassandra.utils.FBUtilities;
 import org.apache.cassandra.db.filter.QueryPath;
 
 public class SliceByNamesReadCommand extends ReadCommand
@@ -84,7 +85,7 @@ class SliceByNamesReadCommandSerializer 
         {
             for (byte[] cName : realRM.columnNames)
             {
-                ColumnSerializer.writeName(cName, dos);
+                FBUtilities.writeShortByteArray(cName, dos);
             }
         }
     }
@@ -101,7 +102,7 @@ class SliceByNamesReadCommandSerializer 
         List<byte[]> columns = new ArrayList<byte[]>();
         for (int i = 0; i < size; ++i)
         {
-            columns.add(ColumnSerializer.readName(dis));
+            columns.add(FBUtilities.readShortByteArray(dis));
         }
         SliceByNamesReadCommand rm = new SliceByNamesReadCommand(table, key, columnParent,
columns);
         rm.setDigestQuery(isDigest);

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/SliceFromReadCommand.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/SliceFromReadCommand.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/SliceFromReadCommand.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/SliceFromReadCommand.java Wed Apr 14
19:52:15 2010
@@ -26,6 +26,7 @@ import org.apache.cassandra.db.filter.Qu
 import org.apache.cassandra.db.filter.QueryPath;
 import org.apache.cassandra.thrift.ColumnParent;
 import org.apache.cassandra.utils.ByteArrayListSerializer;
+import org.apache.cassandra.utils.FBUtilities;
 
 public class SliceFromReadCommand extends ReadCommand
 {
@@ -116,8 +117,8 @@ class SliceFromReadCommandSerializer ext
         dos.writeUTF(realRM.table);
         dos.writeUTF(realRM.key);
         realRM.queryPath.serialize(dos);
-        ColumnSerializer.writeName(realRM.start, dos);
-        ColumnSerializer.writeName(realRM.finish, dos);
+        FBUtilities.writeShortByteArray(realRM.start, dos);
+        FBUtilities.writeShortByteArray(realRM.finish, dos);
         ByteArrayListSerializer.serialize(realRM.bitmasks, dos);
         dos.writeBoolean(realRM.reversed);
         dos.writeInt(realRM.count);
@@ -130,8 +131,8 @@ class SliceFromReadCommandSerializer ext
         SliceFromReadCommand rm = new SliceFromReadCommand(dis.readUTF(),
                                                            dis.readUTF(),
                                                            QueryPath.deserialize(dis),
-                                                           ColumnSerializer.readName(dis),
-                                                           ColumnSerializer.readName(dis),
+                                                           FBUtilities.readShortByteArray(dis),
+                                                           FBUtilities.readShortByteArray(dis),
                                                            ByteArrayListSerializer.deserialize(dis),
                                                            dis.readBoolean(), 
                                                            dis.readInt());

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java Wed Apr 14 19:52:15
2010
@@ -125,7 +125,7 @@ public class SuperColumn implements ICol
     	 * We need to keep the way we are calculating the column size in sync with the
     	 * way we are calculating the size for the column family serializer.
     	 */
-    	return IColumn.UtfPrefix_ + name_.length + DBConstants.intSize_ + DBConstants.longSize_
+ DBConstants.intSize_ + size();
+    	return DBConstants.shortSize_ + name_.length + DBConstants.intSize_ + DBConstants.longSize_
+ DBConstants.intSize_ + size();
     }
 
     public void remove(byte[] columnName)
@@ -299,7 +299,7 @@ class SuperColumnSerializer implements I
     public void serialize(IColumn column, DataOutput dos)
     {
     	SuperColumn superColumn = (SuperColumn)column;
-        ColumnSerializer.writeName(column.name(), dos);
+        FBUtilities.writeShortByteArray(column.name(), dos);
         try
         {
             dos.writeInt(superColumn.getLocalDeletionTime());
@@ -320,7 +320,7 @@ class SuperColumnSerializer implements I
 
     public IColumn deserialize(DataInput dis) throws IOException
     {
-        byte[] name = ColumnSerializer.readName(dis);
+        byte[] name = FBUtilities.readShortByteArray(dis);
         SuperColumn superColumn = new SuperColumn(name, comparator);
         int localDeleteTime = dis.readInt();
         if (localDeleteTime != Integer.MIN_VALUE && localDeleteTime <= 0)

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=934151&r1=934150&r2=934151&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 Wed Apr 14 19:52:15
2010
@@ -30,6 +30,7 @@ import org.apache.commons.lang.ArrayUtil
 import org.apache.cassandra.thrift.ColumnParent;
 import org.apache.cassandra.thrift.ColumnPath;
 import org.apache.cassandra.db.ColumnSerializer;
+import org.apache.cassandra.utils.FBUtilities;
 
 public class QueryPath
 {
@@ -85,15 +86,15 @@ public class QueryPath
         assert superColumnName == null || superColumnName.length > 0;
         assert columnName == null || columnName.length > 0;
         dos.writeUTF(columnFamilyName == null ? "" : columnFamilyName);
-        ColumnSerializer.writeName(superColumnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY
: superColumnName, dos);
-        ColumnSerializer.writeName(columnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY : columnName,
dos);
+        FBUtilities.writeShortByteArray(superColumnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY
: superColumnName, dos);
+        FBUtilities.writeShortByteArray(columnName == null ? ArrayUtils.EMPTY_BYTE_ARRAY
: columnName, dos);
     }
 
     public static QueryPath deserialize(DataInputStream din) throws IOException
     {
         String cfName = din.readUTF();
-        byte[] scName = ColumnSerializer.readName(din);
-        byte[] cName = ColumnSerializer.readName(din);
+        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);
     }
 }

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=934151&r1=934150&r2=934151&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 Wed Apr 14 19:52:15
2010
@@ -21,12 +21,11 @@ package org.apache.cassandra.io.sstable;
 import java.io.*;
 import java.util.*;
 
-import org.apache.cassandra.db.ColumnSerializer;
 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;
 
-
 /**
  * Provides helper to serialize, deserialize and use column indexes.
  */
@@ -138,8 +137,8 @@ public class IndexHelper
 
         public void serialize(DataOutput dos) throws IOException
         {
-            ColumnSerializer.writeName(firstName, dos);
-            ColumnSerializer.writeName(lastName, dos);
+            FBUtilities.writeShortByteArray(firstName, dos);
+            FBUtilities.writeShortByteArray(lastName, dos);
             dos.writeLong(offset);
             dos.writeLong(width);
         }
@@ -151,7 +150,7 @@ public class IndexHelper
 
         public static IndexInfo deserialize(FileDataInput dis) throws IOException
         {
-            return new IndexInfo(ColumnSerializer.readName(dis), ColumnSerializer.readName(dis),
dis.readLong(), dis.readLong());
+            return new IndexInfo(FBUtilities.readShortByteArray(dis), FBUtilities.readShortByteArray(dis),
dis.readLong(), dis.readLong());
         }
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java?rev=934151&r1=934150&r2=934151&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/utils/FBUtilities.java Wed Apr 14 19:52:15
2010
@@ -54,6 +54,8 @@ public class FBUtilities
 
     private static volatile InetAddress localInetAddress_;
 
+    public static final int MAX_UNSIGNED_SHORT = 0xFFFF;
+
     public static Charset UTF8;
     static
     {
@@ -307,6 +309,34 @@ public class FBUtilities
         out.write(bytes);
     }
 
+    public static void writeShortByteArray(byte[] name, DataOutput out)
+    {
+        int length = name.length;
+        assert 0 <= length && length <= MAX_UNSIGNED_SHORT;
+        try
+        {
+            out.writeByte((length >> 8) & 0xFF);
+            out.writeByte(length & 0xFF);
+            out.write(name);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public static byte[] readShortByteArray(DataInput in) throws IOException
+    {
+        int length = 0;
+        length |= (in.readByte() & 0xFF) << 8;
+        length |= in.readByte() & 0xFF;
+        if (!(0 <= length && length <= MAX_UNSIGNED_SHORT))
+            throw new IOException("Corrupt name length " + length);
+        byte[] bytes = new byte[length];
+        in.readFully(bytes);
+        return bytes;
+    }
+
     public static byte[] hexToBytes(String str)
     {
         assert str.length() % 2 == 0;



Mime
View raw message