cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r802073 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra: db/ColumnIndexer.java db/filter/SSTableNamesIterator.java db/filter/SSTableSliceIterator.java db/filter/SliceQueryFilter.java io/IndexHelper.java
Date Fri, 07 Aug 2009 16:24:12 GMT
Author: jbellis
Date: Fri Aug  7 16:24:12 2009
New Revision: 802073

URL: http://svn.apache.org/viewvc?rev=802073&view=rev
Log:
move comparator out of IndexInfo
patch by jbellis; reviewed by Jun Rao for CASSANDRA-332

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIndexer.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIndexer.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIndexer.java?rev=802073&r1=802072&r2=802073&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIndexer.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnIndexer.java Fri Aug
 7 16:24:12 2009
@@ -129,7 +129,7 @@
             /* if we hit the column index size that we have to index after, go ahead and
index it. */
             if (endPosition - startPosition >= DatabaseDescriptor.getColumnIndexSize())
             {
-                IndexHelper.IndexInfo cIndexInfo = new IndexHelper.IndexInfo(firstColumn.name(),
column.name(), startPosition, endPosition - startPosition, null);
+                IndexHelper.IndexInfo cIndexInfo = new IndexHelper.IndexInfo(firstColumn.name(),
column.name(), startPosition, endPosition - startPosition);
                 indexList.add(cIndexInfo);
                 indexSizeInBytes += cIndexInfo.serializedSize();
                 firstColumn = null;
@@ -138,7 +138,7 @@
         // the last column may have fallen on an index boundary already.  if not, index it
explicitly.
         if (indexList.isEmpty() || comparator.compare(indexList.get(indexList.size() - 1).lastName,
column.name()) != 0)
         {
-            IndexHelper.IndexInfo cIndexInfo = new IndexHelper.IndexInfo(firstColumn.name(),
column.name(), startPosition, endPosition - startPosition, null);
+            IndexHelper.IndexInfo cIndexInfo = new IndexHelper.IndexInfo(firstColumn.name(),
column.name(), startPosition, endPosition - startPosition);
             indexList.add(cIndexInfo);
             indexSizeInBytes += cIndexInfo.serializedSize();
         }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java?rev=802073&r1=802072&r2=802073&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
Fri Aug  7 16:24:12 2009
@@ -5,7 +5,9 @@
 
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.IColumn;
+import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.io.*;
+import org.apache.cassandra.config.DatabaseDescriptor;
 
 public class SSTableNamesIterator extends SimpleAbstractColumnIterator
 {
@@ -37,16 +39,17 @@
             /* Read the bloom filter summarizing the columns */
             IndexHelper.defreezeBloomFilter(file);
 
-            List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(ssTable.getTableName(),
cfName, file);
+            List<IndexHelper.IndexInfo> indexList = IndexHelper.deserializeIndex(file);
 
             cf = ColumnFamily.serializer().deserializeEmpty(file);
             file.readInt(); // column count
 
             /* get the various column ranges we have to read */
-            SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>();
+            AbstractType comparator = DatabaseDescriptor.getComparator(SSTable.parseTableName(filename),
cfName);
+            SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>(IndexHelper.getComparator(comparator));
             for (byte[] name : columns)
             {
-                ranges.add(indexList.get(IndexHelper.indexFor(name, indexList)));
+                ranges.add(indexList.get(IndexHelper.indexFor(name, indexList, comparator)));
             }
 
             /* seek to the correct offset to the data */

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java?rev=802073&r1=802072&r2=802073&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableSliceIterator.java
Fri Aug  7 16:24:12 2009
@@ -3,8 +3,6 @@
 import java.util.*;
 import java.io.IOException;
 
-import org.apache.commons.lang.ArrayUtils;
-
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.marshal.AbstractType;
@@ -20,12 +18,11 @@
     protected boolean isAscending;
     private byte[] startColumn;
     private int curColumnIndex;
-    private ColumnFamily curCF = null;
     private ArrayList<IColumn> curColumns = new ArrayList<IColumn>();
     private ColumnGroupReader reader;
     private AbstractType comparator;
 
-    public SSTableSliceIterator(String filename, String key, String cfName, AbstractType
comparator, byte[] startColumn, boolean isAscending)
+    public SSTableSliceIterator(String filename, String key, AbstractType comparator, byte[]
startColumn, boolean isAscending)
     throws IOException
     {
         this.isAscending = isAscending;
@@ -33,10 +30,9 @@
 
         /* Morph key into actual key based on the partition type. */
         String decoratedKey = ssTable.getPartitioner().decorateKey(key);
-        AbstractType comparator1 = DatabaseDescriptor.getComparator(ssTable.getTableName(),
cfName);
         long position = ssTable.getPosition(decoratedKey);
         if (position >= 0)
-            reader = new ColumnGroupReader(ssTable.getFilename(), decoratedKey, cfName, comparator1,
startColumn, isAscending, position);
+            reader = new ColumnGroupReader(ssTable.getFilename(), decoratedKey, comparator,
startColumn, isAscending, position);
         this.comparator = comparator;
         this.startColumn = startColumn;
         curColumnIndex = isAscending ? 0 : -1;
@@ -64,8 +60,6 @@
 
     private void getColumnsFromBuffer() throws IOException
     {
-        if (curCF == null)
-            curCF = reader.getEmptyColumnFamily().cloneMeShallow();
         curColumns.clear();
         while (true)
         {
@@ -84,7 +78,7 @@
 
     public ColumnFamily getColumnFamily()
     {
-        return curCF;
+        return reader.getEmptyColumnFamily();
     }
 
     protected IColumn computeNext()
@@ -135,9 +129,6 @@
      */
     public static class ColumnGroupReader
     {
-        private String key_;
-        private String cfName_;
-        private AbstractType comparator_;
         private boolean isAscending_;
         private ColumnFamily emptyColumnFamily;
 
@@ -147,27 +138,18 @@
         private BufferedRandomAccessFile file_;
         private Queue<IColumn> blockColumns = new ArrayDeque<IColumn>();
 
-        public ColumnGroupReader(String filename, String key, String cfName, AbstractType
comparator, byte[] startColumn, boolean isAscending, long position) throws IOException
+        public ColumnGroupReader(String filename, String key, AbstractType comparator, byte[]
startColumn, boolean isAscending, long position) throws IOException
         {
             this.file_ = new BufferedRandomAccessFile(filename, "r");
-            this.cfName_ = cfName;
-            this.comparator_ = comparator;
-            this.key_ = key;
             this.isAscending_ = isAscending;
-            init(startColumn, position);
-        }
 
-        private void init(byte[] startColumn, long position) throws IOException
-        {
             file_.seek(position);
             String keyInDisk = file_.readUTF();
-            assert keyInDisk.equals(key_);
+            assert keyInDisk.equals(key);
 
             file_.readInt(); // row size
             IndexHelper.skipBloomFilter(file_);
-
-            /* read the index */
-            indexList_ = IndexHelper.deserializeIndex(SSTableReader.parseTableName(file_.getPath()),
cfName_, file_);
+            indexList_ = IndexHelper.deserializeIndex(file_);
 
             /* need to do two things here.
              * 1. move the file pointer to the beginning of the list of stored columns
@@ -184,10 +166,7 @@
             }
             else
             {
-                int index = Collections.binarySearch(indexList_, new IndexHelper.IndexInfo(startColumn,
startColumn, 0, 0, comparator_));
-                curRangeIndex_ = index < 0 ? -1 * (index + 1): index;
-                if (curRangeIndex_ < 0)
-                    curRangeIndex_ = 0;
+                curRangeIndex_ = IndexHelper.indexFor(startColumn, indexList_, comparator);
             }
         }
 
@@ -201,29 +180,24 @@
             return blockColumns.poll();
         }
 
-        private boolean getBlockFromCurIndex() throws IOException
+        public boolean getNextBlock() throws IOException
         {
             if (curRangeIndex_ < 0 || curRangeIndex_ >= indexList_.size())
                 return false;
-            IndexHelper.IndexInfo curColPostion = indexList_.get(curRangeIndex_);
 
             /* seek to the correct offset to the data, and calculate the data size */
+            IndexHelper.IndexInfo curColPostion = indexList_.get(curRangeIndex_);
             file_.seek(columnStartPosition_ + curColPostion.offset);
             while (file_.getFilePointer() < columnStartPosition_ + curColPostion.offset
+ curColPostion.width)
             {
                 blockColumns.add(emptyColumnFamily.getColumnSerializer().deserialize(file_));
             }
-            return true;
-        }
 
-        public boolean getNextBlock() throws IOException
-        {
-            boolean result = getBlockFromCurIndex();
             if (isAscending_)
                 curRangeIndex_++;
             else
                 curRangeIndex_--;
-            return result;
+            return true;
         }
 
         public void close() throws IOException

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java?rev=802073&r1=802072&r2=802073&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
(original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SliceQueryFilter.java
Fri Aug  7 16:24:12 2009
@@ -33,7 +33,7 @@
 
     public ColumnIterator getSSTableColumnIterator(SSTableReader sstable, AbstractType comparator)
throws IOException
     {
-        return new SSTableSliceIterator(sstable.getFilename(), key, getColumnFamilyName(),
comparator, start, isAscending);
+        return new SSTableSliceIterator(sstable.getFilename(), key, comparator, start, isAscending);
     }
 
     public void filterSuperColumn(SuperColumn superColumn, int gcBefore)

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java?rev=802073&r1=802072&r2=802073&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/IndexHelper.java Fri Aug  7
16:24:12 2009
@@ -89,16 +89,15 @@
      * Deserialize the index into a structure and return the number of bytes read.
      * @throws IOException
      */
-	public static ArrayList<IndexInfo> deserializeIndex(String tableName, String cfName,
RandomAccessFile in) throws IOException
+	public static ArrayList<IndexInfo> deserializeIndex(RandomAccessFile in) throws IOException
 	{
         ArrayList<IndexInfo> indexList = new ArrayList<IndexInfo>();
 
 		int columnIndexSize = in.readInt();
         long start = in.getFilePointer();
-        AbstractType comparator = DatabaseDescriptor.getComparator(tableName, cfName);
         while (in.getFilePointer() < start + columnIndexSize)
         {
-            indexList.add(IndexInfo.deserialize(in, comparator));
+            indexList.add(IndexInfo.deserialize(in));
         }
         assert in.getFilePointer() == start + columnIndexSize;
 
@@ -121,33 +120,37 @@
         return BloomFilter.serializer().deserialize(bufIn);
     }
 
-    public static int indexFor(byte[] name, List<IndexInfo> indexList)
+    public static int indexFor(byte[] name, List<IndexInfo> indexList, AbstractType
comparator)
     {
-        IndexInfo target = new IndexInfo(name, name, 0, 0, indexList.get(0).comparator);
-        int index = Collections.binarySearch(indexList, target);
+        IndexInfo target = new IndexInfo(name, name, 0, 0);
+        int index = Collections.binarySearch(indexList, target, getComparator(comparator));
         return index < 0 ? -1 * (index + 1) : index;
     }
 
-    public static class IndexInfo implements Comparable<IndexInfo>
+    public static Comparator<IndexInfo> getComparator(final AbstractType nameComparator)
+    {
+        return new Comparator<IndexInfo>()
+        {
+            public int compare(IndexInfo o1, IndexInfo o2)
+            {
+                return nameComparator.compare(o1.lastName, o2.lastName);
+            }
+        };
+    }
+
+    public static class IndexInfo
     {
         public final long width;
         public final byte[] lastName;
-        private AbstractType comparator;
         public final byte[] firstName;
         public final long offset;
 
-        public IndexInfo(byte[] firstName, byte[] lastName, long offset, long width, AbstractType
comparator)
+        public IndexInfo(byte[] firstName, byte[] lastName, long offset, long width)
         {
             this.firstName = firstName;
             this.lastName = lastName;
             this.offset = offset;
             this.width = width;
-            this.comparator = comparator;
-        }
-
-        public int compareTo(IndexInfo rhs)
-        {
-            return comparator.compare(lastName, rhs.lastName);
         }
 
         public void serialize(DataOutputStream dos) throws IOException
@@ -163,9 +166,9 @@
             return 2 + firstName.length + 2 + lastName.length + 8 + 8;
         }
 
-        public static IndexInfo deserialize(RandomAccessFile dis, AbstractType comparator)
throws IOException
+        public static IndexInfo deserialize(RandomAccessFile dis) throws IOException
         {
-            return new IndexInfo(ColumnSerializer.readName(dis), ColumnSerializer.readName(dis),
dis.readLong(), dis.readLong(), comparator);
+            return new IndexInfo(ColumnSerializer.readName(dis), ColumnSerializer.readName(dis),
dis.readLong(), dis.readLong());
         }
     }
 



Mime
View raw message