cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r950074 - in /cassandra/trunk: src/java/org/apache/cassandra/db/ src/java/org/apache/cassandra/db/filter/ src/java/org/apache/cassandra/service/ test/unit/org/apache/cassandra/ test/unit/org/apache/cassandra/db/
Date Tue, 01 Jun 2010 13:43:36 GMT
Author: jbellis
Date: Tue Jun  1 13:43:36 2010
New Revision: 950074

URL: http://svn.apache.org/viewvc?rev=950074&view=rev
Log:
pass IFilter to getRangeRows instead of column names / slicerange.  patch by jbellis

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/IFilter.java
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/IdentityQueryFilter.java
    cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryFilter.java
    cassandra/trunk/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java
    cassandra/trunk/test/unit/org/apache/cassandra/Util.java
    cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue Jun  1 13:43:36
2010
@@ -860,11 +860,10 @@ public class ColumnFamilyStore implement
       * @param superColumn Super column to filter by
       * @param range Either a Bounds, which includes start key, or a Range, which does not.
       * @param maxResults Maximum rows to return
-      * @param sliceRange Information on how to slice columns
-      * @param columnNames Column names to filter by 
+      * @param columnFilter description of the columns we're interested in for each row
       * @return true if we found all keys we were looking for, otherwise false
      */
-    private boolean getRangeRows(List<Row> rows, byte[] superColumn, final AbstractBounds
range, int maxResults, SliceRange sliceRange, List<byte[]> columnNames)
+    private boolean getRangeRows(List<Row> rows, byte[] superColumn, final AbstractBounds
range, int maxResults, IFilter columnFilter)
     throws ExecutionException, InterruptedException
     {
         final DecoratedKey startWith = new DecoratedKey(range.left, (byte[])null);
@@ -873,13 +872,8 @@ public class ColumnFamilyStore implement
         final int gcBefore = CompactionManager.getDefaultGCBefore();
 
         final QueryPath queryPath =  new QueryPath(columnFamily_, superColumn, null);
-        final SortedSet<byte[]> columnNameSet = new TreeSet<byte[]>(getComparator());
-        if (columnNames != null)
-            columnNameSet.addAll(columnNames);
-
-        final QueryFilter filter = sliceRange == null ? QueryFilter.getNamesFilter(null,
queryPath, columnNameSet)
-                                                      : QueryFilter.getSliceFilter(null,
queryPath, sliceRange.start, sliceRange.finish, sliceRange.bitmasks, sliceRange.reversed,
sliceRange.count);
 
+        final QueryFilter filter = new QueryFilter(null, queryPath, columnFilter);
         Collection<Memtable> memtables = new ArrayList<Memtable>();
         memtables.add(getMemtableThreadSafe());
         memtables.addAll(memtablesPendingFlush);
@@ -929,30 +923,29 @@ public class ColumnFamilyStore implement
      * @param super_column
      * @param range: either a Bounds, which includes start key, or a Range, which does not.
      * @param keyMax maximum number of keys to process, regardless of startKey/finishKey
-     * @param sliceRange may be null if columnNames is specified. specifies contiguous columns
to return in what order.
-     * @param columnNames may be null if sliceRange is specified. specifies which columns
to return in what order.      @return list of key->list<column> tuples.
+     * @param columnFilter description of the columns we're interested in for each row
      * @throws ExecutionException
      * @throws InterruptedException
      */
-    public List<Row> getRangeSlice(byte[] super_column, final AbstractBounds range,
int keyMax, SliceRange sliceRange, List<byte[]> columnNames)
+    public List<Row> getRangeSlice(byte[] super_column, final AbstractBounds range,
int keyMax, IFilter columnFilter)
     throws ExecutionException, InterruptedException
     {
         List<Row> rows = new ArrayList<Row>();
         boolean completed;
         if ((range instanceof Bounds || !((Range)range).isWrapAround()))
         {
-            completed = getRangeRows(rows, super_column, range, keyMax, sliceRange, columnNames);
+            completed = getRangeRows(rows, super_column, range, keyMax, columnFilter);
         }
         else
         {
             // wrapped range
             Token min = StorageService.getPartitioner().getMinimumToken();
             Range first = new Range(range.left, min);
-            completed = getRangeRows(rows, super_column, first, keyMax, sliceRange, columnNames);
+            completed = getRangeRows(rows, super_column, first, keyMax, columnFilter);
             if (!completed && min.compareTo(range.right) < 0)
             {
                 Range second = new Range(min, range.right);
-                getRangeRows(rows, super_column, second, keyMax, sliceRange, columnNames);
+                getRangeRows(rows, super_column, second, keyMax, columnFilter);
             }
         }
 
@@ -1033,8 +1026,7 @@ public class ColumnFamilyStore implement
                 List<Row> result;
                 try
                 {
-                    SliceRange range = new SliceRange(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY,
false, ROWS);
-                    result = getRangeSlice(null, new Bounds(start, min), ROWS, range, null);
+                    result = getRangeSlice(null, new Bounds(start, min), ROWS, new IdentityQueryFilter());
                 }
                 catch (Exception e)
                 {

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/IFilter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/IFilter.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/IFilter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/IFilter.java Tue Jun  1 13:43:36
2010
@@ -35,7 +35,7 @@ import org.apache.cassandra.io.util.File
  * takes care of putting the two together if subcolumn filtering needs to be done, based
on the
  * querypath that it knows (but that IFilter implementations are oblivious to).
  */
-interface IFilter
+public interface IFilter
 {
     /**
      * returns an iterator that returns columns from the given memtable

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/IdentityQueryFilter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/IdentityQueryFilter.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/IdentityQueryFilter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/IdentityQueryFilter.java Tue Jun
 1 13:43:36 2010
@@ -25,7 +25,7 @@ import org.apache.commons.lang.ArrayUtil
 
 import org.apache.cassandra.db.SuperColumn;
 
-class IdentityQueryFilter extends SliceQueryFilter
+public class IdentityQueryFilter extends SliceQueryFilter
 {
     /**
      * Only for use in testing; will read entire CF into memory.

Modified: cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryFilter.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryFilter.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryFilter.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/db/filter/QueryFilter.java Tue Jun  1 13:43:36
2010
@@ -25,6 +25,8 @@ import java.util.*;
 
 import org.apache.cassandra.io.sstable.SSTableReader;
 import org.apache.cassandra.io.util.FileDataInput;
+import org.apache.cassandra.thrift.SlicePredicate;
+import org.apache.cassandra.thrift.SliceRange;
 import org.apache.cassandra.utils.ReducingIterator;
 import org.apache.cassandra.db.*;
 import org.apache.cassandra.db.marshal.AbstractType;
@@ -37,7 +39,7 @@ public class QueryFilter
     private final IFilter filter;
     private final IFilter superFilter;
 
-    protected QueryFilter(DecoratedKey key, QueryPath path, IFilter filter)
+    public QueryFilter(DecoratedKey key, QueryPath path, IFilter filter)
     {
         this.key = key;
         this.path = path;
@@ -178,6 +180,19 @@ public class QueryFilter
         return new QueryFilter(key, path, new NamesQueryFilter(columns));
     }
 
+    public static IFilter getFilter(SlicePredicate predicate, AbstractType comparator)
+    {
+        if (predicate.column_names != null)
+        {
+            final SortedSet<byte[]> columnNameSet = new TreeSet<byte[]>(comparator);
+            columnNameSet.addAll(predicate.column_names);
+            return new NamesQueryFilter(columnNameSet);
+        }
+
+        SliceRange range = predicate.slice_range;
+        return new SliceQueryFilter(range.start, range.finish, range.bitmasks, range.reversed,
range.count);
+    }
+
     /**
      * convenience method for creating a name filter matching a single column
      */

Modified: cassandra/trunk/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/service/RangeSliceVerbHandler.java Tue Jun
 1 13:43:36 2010
@@ -22,6 +22,7 @@ import org.apache.cassandra.db.ColumnFam
 import org.apache.cassandra.db.RangeSliceCommand;
 import org.apache.cassandra.db.RangeSliceReply;
 import org.apache.cassandra.db.Table;
+import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.net.IVerbHandler;
 import org.apache.cassandra.net.Message;
 import org.apache.cassandra.net.MessagingService;
@@ -42,8 +43,7 @@ public class RangeSliceVerbHandler imple
             RangeSliceReply reply = new RangeSliceReply(cfs.getRangeSlice(command.super_column,
                                                                           command.range,
                                                                           command.max_keys,
-                                                                          command.predicate.slice_range,
-                                                                          command.predicate.column_names));
+                                                                          QueryFilter.getFilter(command.predicate,
cfs.getComparator())));
             Message response = reply.getReply(message);
             if (logger.isDebugEnabled())
                 logger.debug("Sending " + reply+ " to " + message.getMessageId() + "@" +
message.getFrom());

Modified: cassandra/trunk/test/unit/org/apache/cassandra/Util.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/Util.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/Util.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/Util.java Tue Jun  1 13:43:36 2010
@@ -27,6 +27,7 @@ import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 
+import org.apache.cassandra.db.filter.IdentityQueryFilter;
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.commons.lang.ArrayUtils;
 
@@ -73,8 +74,7 @@ public class Util
         return cfs.getRangeSlice(null,
                                  new Bounds(min, min),
                                  10000,
-                                 new SliceRange(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY,
false, 10000),
-                                 null);
+                                 new IdentityQueryFilter());
     }
 
     /**

Modified: cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java?rev=950074&r1=950073&r2=950074&view=diff
==============================================================================
--- cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java (original)
+++ cassandra/trunk/test/unit/org/apache/cassandra/db/ColumnFamilyStoreTest.java Tue Jun 
1 13:43:36 2010
@@ -141,8 +141,7 @@ public class ColumnFamilyStoreTest exten
         List<Row> result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
                                              Util.range(p, "key15", "key1"),
                                              10,
-                                             null,
-                                             Arrays.asList("asdf".getBytes()));
+                                             new NamesQueryFilter("asdf".getBytes()));
         assertEquals(2, result.size());
     }
 
@@ -155,8 +154,7 @@ public class ColumnFamilyStoreTest exten
         List<Row> result = cfs.getRangeSlice(ArrayUtils.EMPTY_BYTE_ARRAY,
                                              Util.range(p, "key1", "key2"),
                                              10,
-                                             null,
-                                             Arrays.asList("asdf".getBytes()));
+                                             new NamesQueryFilter("asdf".getBytes()));
         assertEquals(1, result.size());
         assert Arrays.equals(result.get(0).key.key, "key2".getBytes());
     }



Mime
View raw message