cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r793054 - in /incubator/cassandra/trunk/src/java/org/apache/cassandra/db: Memtable.java Table.java TimeFilter.java filter/SSTableNamesIterator.java filter/SSTableTimeIterator.java filter/TimeQueryFilter.java
Date Fri, 10 Jul 2009 17:49:07 GMT
Author: jbellis
Date: Fri Jul 10 17:49:06 2009
New Revision: 793054

URL: http://svn.apache.org/viewvc?rev=793054&view=rev
Log:
add TimeQueryFilter; remove old TimeFilter.
patch by jbellis; reviewed by Jun Rao for CASSANDRA-287

Added:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableTimeIterator.java
      - copied, changed from r793053, incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/TimeQueryFilter.java
Removed:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/TimeFilter.java
Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java?rev=793054&r1=793053&r2=793054&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Memtable.java Fri Jul 10 17:49:06
2009
@@ -365,9 +365,8 @@
 
     public ColumnIterator getNamesIterator(final NamesQueryFilter filter)
     {
-        ColumnFamily cf = columnFamilies_.get(filter.key);
+        final ColumnFamily cf = columnFamilies_.get(filter.key);
         final ColumnFamily columnFamily = cf == null ? ColumnFamily.create(table_, filter.getColumnFamilyName())
: cf.cloneMeShallow();
-        final Map<String, IColumn> columnsContainer = cf == null ? null : cf.getColumns();
 
         return new SimpleAbstractColumnIterator()
         {
@@ -381,14 +380,14 @@
 
             protected IColumn computeNext()
             {
-                if (columnsContainer == null)
+                if (cf == null)
                 {
                     return endOfData();
                 }
                 while (iter.hasNext())
                 {
                     current = iter.next();
-                    IColumn column = columnsContainer.get(current);
+                    IColumn column = cf.getColumn(current);
                     if (column != null)
                         return column;
                 }
@@ -397,6 +396,38 @@
         };
     }
 
+    public ColumnIterator getTimeIterator(final TimeQueryFilter filter)
+    {
+        final ColumnFamily cf = columnFamilies_.get(filter.key);
+        final ColumnFamily columnFamily = cf == null ? ColumnFamily.create(table_, filter.getColumnFamilyName())
: cf.cloneMeShallow();
+
+        return new SimpleAbstractColumnIterator()
+        {
+            private Iterator<IColumn> iter = cf == null ? null : cf.getAllColumns().iterator();
+
+            public ColumnFamily getColumnFamily()
+            {
+                return columnFamily;
+            }
+
+            protected IColumn computeNext()
+            {
+                if (iter == null)
+                {
+                    return endOfData();
+                }
+                while (iter.hasNext())
+                {
+                    IColumn column = iter.next();
+                    if (column.timestamp() < filter.since)
+                        break;
+                    return column;
+                }
+                return endOfData();
+            }
+        };
+    }
+
     void clearUnsafe()
     {
         columnFamilies_.clear();

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java?rev=793054&r1=793053&r2=793054&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/Table.java Fri Jul 10 17:49:06
2009
@@ -46,6 +46,7 @@
 import org.apache.cassandra.db.filter.QueryFilter;
 import org.apache.cassandra.db.filter.SliceQueryFilter;
 import org.apache.cassandra.db.filter.NamesQueryFilter;
+import org.apache.cassandra.db.filter.TimeQueryFilter;
 
 import org.apache.log4j.Logger;
 
@@ -550,19 +551,10 @@
         return row;
     }
     
-    public Row getRow(String key, String cf, long sinceTimeStamp) throws IOException
+    public Row getRow(String key, String columnFamilyColumn, long sinceTimeStamp) throws
IOException
     {
-        Row row = new Row(table_, key);
-        String[] values = RowMutation.getColumnAndColumnFamily(cf);
-        ColumnFamilyStore cfStore = columnFamilyStores_.get(values[0]);
-        long start1 = System.currentTimeMillis();
-        assert cfStore != null : "Column family " + cf + " has not been defined";
-        ColumnFamily columnFamily = cfStore.getColumnFamily(key, cf, new TimeFilter(sinceTimeStamp));
-        if ( columnFamily != null )
-            row.addColumnFamily(columnFamily);
-        long timeTaken = System.currentTimeMillis() - start1;
-        dbAnalyticsSource_.updateReadStatistics(timeTaken);
-        return row;
+        QueryFilter filter = new TimeQueryFilter(key, columnFamilyColumn, sinceTimeStamp);
+        return getRow(key, filter);
     }
 
     /**

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=793054&r1=793053&r2=793054&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 Jul 10 17:49:06 2009
@@ -21,8 +21,11 @@
         this.columns = columns;
         SSTableReader ssTable = SSTableReader.open(filename);
         DataInputBuffer buffer = ssTable.next(key, cfName, columns);
-        cf = ColumnFamily.serializer().deserialize(buffer);
-        iter = cf.getAllColumns().iterator();
+        if (buffer.getLength() > 0)
+        {
+            cf = ColumnFamily.serializer().deserialize(buffer);
+            iter = cf.getAllColumns().iterator();
+        }
     }
 
     public ColumnFamily getColumnFamily()

Copied: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableTimeIterator.java
(from r793053, 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/SSTableTimeIterator.java?p2=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableTimeIterator.java&p1=incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/SSTableNamesIterator.java&r1=793053&r2=793054&rev=793054&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/SSTableTimeIterator.java
Fri Jul 10 17:49:06 2009
@@ -1,28 +1,30 @@
 package org.apache.cassandra.db.filter;
 
-import java.io.IOException;
-import java.util.SortedSet;
 import java.util.Iterator;
+import java.io.IOException;
 
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.io.SSTableReader;
 import org.apache.cassandra.io.DataInputBuffer;
+import org.apache.cassandra.io.IndexHelper;
 
-public class SSTableNamesIterator extends SimpleAbstractColumnIterator
+public class SSTableTimeIterator extends SimpleAbstractColumnIterator
 {
     private ColumnFamily cf;
     private Iterator<IColumn> iter;
-    public final SortedSet<String> columns;
+    public final long since;
 
-    // TODO make this actually iterate so we don't have to read + deserialize + filter data
that we don't need due to merging other sstables
-    public SSTableNamesIterator(String filename, String key, String cfName, SortedSet<String>
columns) throws IOException
+    public SSTableTimeIterator(String filename, String key, String cfName, long since) throws
IOException
     {
-        this.columns = columns;
+        this.since = since;
         SSTableReader ssTable = SSTableReader.open(filename);
-        DataInputBuffer buffer = ssTable.next(key, cfName, columns);
-        cf = ColumnFamily.serializer().deserialize(buffer);
-        iter = cf.getAllColumns().iterator();
+        DataInputBuffer buffer = ssTable.next(key, cfName, null, new IndexHelper.TimeRange(since,
Long.MAX_VALUE));
+        if (buffer.getLength() > 0)
+        {
+            cf = ColumnFamily.serializer().deserialize(buffer);
+            iter = cf.getAllColumns().iterator();
+        }
     }
 
     public ColumnFamily getColumnFamily()
@@ -37,8 +39,9 @@
         while (iter.hasNext())
         {
             IColumn c = iter.next();
-            if (columns.contains(c.name()))
-                return c;
+            if (c.timestamp() < since)
+                break;
+            return c;
         }
         return endOfData();
     }

Added: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/TimeQueryFilter.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/TimeQueryFilter.java?rev=793054&view=auto
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/TimeQueryFilter.java
(added)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/filter/TimeQueryFilter.java
Fri Jul 10 17:49:06 2009
@@ -0,0 +1,54 @@
+package org.apache.cassandra.db.filter;
+
+import java.io.IOException;
+import java.util.Comparator;
+
+import org.apache.cassandra.db.*;
+import org.apache.cassandra.io.SSTableReader;
+import org.apache.cassandra.utils.ReducingIterator;
+
+public class TimeQueryFilter extends QueryFilter
+{
+    public final long since;
+
+    public TimeQueryFilter(String key, String columnFamilyColumn, long since)
+    {
+        super(key, columnFamilyColumn);
+        this.since = since;
+    }
+
+    public ColumnIterator getMemColumnIterator(Memtable memtable)
+    {
+        return memtable.getTimeIterator(this);
+    }
+
+    public ColumnIterator getSSTableColumnIterator(SSTableReader sstable) throws IOException
+    {
+        return new SSTableTimeIterator(sstable.getFilename(), key, getColumnFamilyName(),
since);
+    }
+
+    @Override
+    public Comparator<IColumn> getColumnComparator()
+    {
+        return ColumnComparatorFactory.timestampComparator_;
+    }
+
+    public void collectColumns(ColumnFamily returnCF, ReducingIterator<IColumn> reducedColumns)
+    {
+        for (IColumn column : reducedColumns)
+        {
+            returnCF.addColumn(column);
+        }
+    }
+
+    public void filterSuperColumn(SuperColumn superColumn)
+    {
+        for (IColumn column : superColumn.getSubColumns())
+        {
+            if (column.timestamp() < since)
+            {
+                superColumn.remove(column.name());
+            }
+        }
+    }
+}



Mime
View raw message