cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1073847 - in /cassandra/branches/cassandra-0.7: ./ src/java/org/apache/cassandra/db/columniterator/ src/java/org/apache/cassandra/io/sstable/
Date Wed, 23 Feb 2011 17:54:44 GMT
Author: jbellis
Date: Wed Feb 23 17:54:43 2011
New Revision: 1073847

URL: http://svn.apache.org/viewvc?rev=1073847&view=rev
Log:
fix reversed slice queries on large rows
patch by slebresne; reviewed by jbellis for CASSANDRA-2212

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.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/io/sstable/IndexHelper.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1073847&r1=1073846&r2=1073847&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Wed Feb 23 17:54:43 2011
@@ -23,6 +23,7 @@
  * fix cache saving on Windows (CASSANDRA-2207)
  * add validateSchemaAgreement call + synchronization to schema
    modification operations (CASSANDRA-2222)
+ * fix for reversed slice queries on large rows (CASSANDRA-2212)
 
 
 0.7.2

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java?rev=1073847&r1=1073846&r2=1073847&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/columniterator/IndexedSliceReader.java
Wed Feb 23 17:54:43 2011
@@ -146,8 +146,6 @@ class IndexedSliceReader extends Abstrac
             file.readInt(); // column count
             this.mark = file.mark();
             curRangeIndex = IndexHelper.indexFor(startColumn, indexes, comparator, reversed);
-            if (reversed && curRangeIndex == indexes.size())
-                curRangeIndex--;
         }
 
         public boolean getNextBlock() throws IOException

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=1073847&r1=1073846&r2=1073847&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 Feb 23 17:54:43 2011
@@ -160,7 +160,7 @@ public class SSTableNamesIterator extend
 
         /* get the various column ranges we have to read */
         AbstractType comparator = metadata.comparator;
-        SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>(IndexHelper.getComparator(comparator));
+        SortedSet<IndexHelper.IndexInfo> ranges = new TreeSet<IndexHelper.IndexInfo>(IndexHelper.getComparator(comparator,
false));
         for (ByteBuffer name : filteredColumnNames)
         {
             int index = IndexHelper.indexFor(name, indexList, comparator, false);

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=1073847&r1=1073846&r2=1073847&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 Feb 23 17:54:43 2011
@@ -111,8 +111,7 @@ public class IndexHelper
     }
 
     /**
-     * the index of the IndexInfo in which @name will be found.
-     * If the index is @indexList.size(), the @name appears nowhere.
+     * The index of the IndexInfo in which a scan starting with @name should begin.
      *
      * @param name
      *         name of the index
@@ -133,19 +132,40 @@ public class IndexHelper
         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));
-        return index < 0 ? -1 * (index + 1) : index;
+        /*
+        Take the example from the unit test, and say your index looks like this:
+        [0..5][10..15][20..25]
+        and you look for the slice [13..17].
+
+        When doing forward slice, we we doing a binary search comparing 13 (the start of
the query)
+        to the lastName part of the index slot. You'll end up with the "first" slot, going
from left to right,
+        that may contain the start.
+
+        When doing a reverse slice, we do the same thing, only using as a start column the
end of the query,
+        i.e. 17 in this example, compared to the firstName part of the index slots.  bsearch
will give us the
+        first slot where firstName > start ([20..25] here), so we subtract an extra one
to get the slot just before.
+        */
+        int index = Collections.binarySearch(indexList, target, getComparator(comparator,
reversed));
+        return index < 0 ? -index - (reversed ? 2 : 1) : index;
     }
 
-    public static Comparator<IndexInfo> getComparator(final AbstractType nameComparator)
+    public static Comparator<IndexInfo> getComparator(final AbstractType nameComparator,
boolean reversed)
     {
-        return new Comparator<IndexInfo>()
-        {
-            public int compare(IndexInfo o1, IndexInfo o2)
-            {
-                return nameComparator.compare(o1.lastName, o2.lastName);
-            }
-        };
+        return reversed
+              ? new Comparator<IndexInfo>()
+                {
+                    public int compare(IndexInfo o1, IndexInfo o2)
+                    {
+                        return nameComparator.compare(o1.firstName, o2.firstName);
+                    }
+                }
+              : new Comparator<IndexInfo>()
+                {
+                    public int compare(IndexInfo o1, IndexInfo o2)
+                    {
+                        return nameComparator.compare(o1.lastName, o2.lastName);
+                    }
+                };
     }
 
     public static class IndexInfo



Mime
View raw message