mirror of https://github.com/apache/cassandra
avoid optimization of not checking older memtable and SSTables if we find _an_ answer early on; it causes bugs
git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@788776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
479c1a40af
commit
f55dd06ec5
|
|
@ -276,18 +276,6 @@ class ColumnSerializer implements ICompactSerializer2<IColumn>
|
|||
if ( name.equals(columnName) )
|
||||
{
|
||||
column = defreeze(dis, name);
|
||||
if( filter instanceof IdentityFilter )
|
||||
{
|
||||
/*
|
||||
* If this is being called with identity filter
|
||||
* since a column name is passed in we know
|
||||
* that this is a final call
|
||||
* Hence if the column is found set the filter to done
|
||||
* so that we do not look for the column in further files
|
||||
*/
|
||||
IdentityFilter f = (IdentityFilter)filter;
|
||||
f.setDone();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -532,10 +532,6 @@ public final class ColumnFamily
|
|||
if(column != null)
|
||||
{
|
||||
cf.addColumn(column);
|
||||
if(filter.isDone())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cf;
|
||||
|
|
|
|||
|
|
@ -522,17 +522,12 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
List<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>();
|
||||
/* Get the ColumnFamily from Memtable */
|
||||
getColumnFamilyFromCurrentMemtable(key, columnFamilyColumn, filter, columnFamilies);
|
||||
if (columnFamilies.size() == 0 || !filter.isDone())
|
||||
{
|
||||
/* Check if MemtableManager has any historical information */
|
||||
getUnflushedColumnFamily(key, columnFamily_, columnFamilyColumn, filter, columnFamilies);
|
||||
}
|
||||
if (columnFamilies.size() == 0 || !filter.isDone())
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
getColumnFamilyFromDisk(key, columnFamilyColumn, columnFamilies, filter);
|
||||
diskReadStats_.add(System.currentTimeMillis() - start);
|
||||
}
|
||||
/* Check if MemtableManager has any historical information */
|
||||
getUnflushedColumnFamily(key, columnFamily_, columnFamilyColumn, filter, columnFamilies);
|
||||
long start = System.currentTimeMillis();
|
||||
getColumnFamilyFromDisk(key, columnFamilyColumn, columnFamilies, filter);
|
||||
diskReadStats_.add(System.currentTimeMillis() - start);
|
||||
|
||||
return columnFamilies;
|
||||
}
|
||||
|
||||
|
|
@ -574,10 +569,6 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
if (columnFamily != null)
|
||||
{
|
||||
columnFamilies.add(columnFamily);
|
||||
if (filter.isDone())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1417,8 +1408,6 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean
|
|||
if ( columnFamily != null )
|
||||
{
|
||||
columnFamilies.add(columnFamily);
|
||||
if( filter.isDone())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cassandra.db;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
|
@ -27,7 +27,6 @@ import org.apache.cassandra.io.SSTable;
|
|||
|
||||
public interface IFilter
|
||||
{
|
||||
public boolean isDone();
|
||||
public ColumnFamily filter(String cfName, ColumnFamily cf);
|
||||
public IColumn filter(IColumn column, DataInputStream dis) throws IOException;
|
||||
public DataInputBuffer next(String key, String cf, SSTable ssTable) throws IOException;
|
||||
|
|
|
|||
|
|
@ -28,42 +28,13 @@ import org.apache.cassandra.io.SSTable;
|
|||
|
||||
public class IdentityFilter implements IFilter
|
||||
{
|
||||
private boolean isDone_ = false;
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return isDone_;
|
||||
}
|
||||
|
||||
public ColumnFamily filter(String cfString, ColumnFamily columnFamily)
|
||||
{
|
||||
String[] values = RowMutation.getColumnAndColumnFamily(cfString);
|
||||
if( columnFamily == null )
|
||||
return columnFamily;
|
||||
|
||||
if (values.length == 2 && !columnFamily.isSuper())
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
if(columns.size() >= 1)
|
||||
isDone_ = true;
|
||||
}
|
||||
if (values.length == 3 && columnFamily.isSuper())
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
for(IColumn column : columns)
|
||||
{
|
||||
SuperColumn superColumn = (SuperColumn)column;
|
||||
Collection<IColumn> subColumns = superColumn.getSubColumns();
|
||||
if( subColumns.size() >= 1 )
|
||||
isDone_ = true;
|
||||
}
|
||||
}
|
||||
return columnFamily;
|
||||
}
|
||||
|
||||
public IColumn filter(IColumn column, DataInputStream dis) throws IOException
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return column;
|
||||
}
|
||||
|
||||
|
|
@ -71,18 +42,4 @@ public class IdentityFilter implements IFilter
|
|||
{
|
||||
return ssTable.next(key, cf);
|
||||
}
|
||||
|
||||
public void setDone()
|
||||
{
|
||||
isDone_ = true;
|
||||
}
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,13 +54,8 @@ public class NamesFilter implements IFilter
|
|||
{
|
||||
if ( names_.contains(column.name()) )
|
||||
{
|
||||
names_.remove(column.name());
|
||||
filteredCf.addColumn(column);
|
||||
}
|
||||
if( isDone() )
|
||||
{
|
||||
return filteredCf;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (values.length == 2 && columnFamily.isSuper())
|
||||
|
|
@ -76,13 +71,8 @@ public class NamesFilter implements IFilter
|
|||
{
|
||||
if ( names_.contains(subColumn.name()) )
|
||||
{
|
||||
names_.remove(subColumn.name());
|
||||
filteredSuperColumn.addColumn(subColumn);
|
||||
}
|
||||
if( isDone() )
|
||||
{
|
||||
return filteredCf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,24 +85,13 @@ public class NamesFilter implements IFilter
|
|||
|
||||
public IColumn filter(IColumn column, DataInputStream dis) throws IOException
|
||||
{
|
||||
String columnName = column.name();
|
||||
if ( names_.contains(columnName) )
|
||||
{
|
||||
names_.remove(columnName);
|
||||
}
|
||||
else
|
||||
if (!names_.contains(column.name()))
|
||||
{
|
||||
column = null;
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return names_.isEmpty();
|
||||
}
|
||||
|
||||
public DataInputBuffer next(String key, String cf, SSTable ssTable) throws IOException
|
||||
{
|
||||
return ssTable.next(key, cf, names_, null);
|
||||
|
|
|
|||
|
|
@ -33,14 +33,12 @@ public class RangeFilter implements IFilter
|
|||
{
|
||||
private final String colMin_;
|
||||
private final String colMax_;
|
||||
private boolean isDone_;
|
||||
int count_;
|
||||
|
||||
RangeFilter(String colMin, String colMax)
|
||||
{
|
||||
colMin_ = colMin;
|
||||
colMax_ = colMax;
|
||||
isDone_ = false;
|
||||
count_ = -1;
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +46,6 @@ public class RangeFilter implements IFilter
|
|||
{
|
||||
colMin_ = colMin;
|
||||
colMax_ = colMax;
|
||||
isDone_ = false;
|
||||
count_ = count;
|
||||
}
|
||||
|
||||
|
|
@ -57,28 +54,19 @@ public class RangeFilter implements IFilter
|
|||
if (cf == null)
|
||||
return null;
|
||||
|
||||
if (count_ == 0)
|
||||
{
|
||||
isDone_ = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
ColumnFamily filteredColumnFamily = cf.cloneMeShallow();
|
||||
|
||||
Collection<IColumn> columns = cf.getAllColumns();
|
||||
int i = 0;
|
||||
for (IColumn c : columns)
|
||||
{
|
||||
if ((count_ >= 0) && (i >= count_))
|
||||
break;
|
||||
if (c.name().compareTo(colMin_) >= 0
|
||||
&& c.name().compareTo(colMax_) <= 0)
|
||||
{
|
||||
filteredColumnFamily.addColumn(c);
|
||||
if (count_ > 0)
|
||||
count_--;
|
||||
if (count_==0)
|
||||
{
|
||||
isDone_ = true;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return filteredColumnFamily;
|
||||
|
|
@ -87,26 +75,15 @@ public class RangeFilter implements IFilter
|
|||
public IColumn filter(IColumn column, DataInputStream dis)
|
||||
throws IOException
|
||||
{
|
||||
if (column == null || isDone_)
|
||||
if (column == null)
|
||||
return null;
|
||||
|
||||
if (column.name().compareTo(colMin_) >= 0
|
||||
&& column.name().compareTo(colMax_) <= 0)
|
||||
{
|
||||
if (count_ > 0)
|
||||
count_--;
|
||||
if (count_ == 0)
|
||||
isDone_ = true;
|
||||
return column;
|
||||
} else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return isDone_;
|
||||
return null;
|
||||
}
|
||||
|
||||
public DataInputBuffer next(String key, String cf, SSTable ssTable)
|
||||
|
|
|
|||
|
|
@ -422,10 +422,6 @@ class SuperColumnSerializer implements ICompactSerializer2<IColumn>
|
|||
if(column != null)
|
||||
{
|
||||
superColumn.addColumn(column);
|
||||
if(filter.isDone())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return superColumn;
|
||||
|
|
|
|||
|
|
@ -36,12 +36,10 @@ import org.apache.cassandra.io.SSTable;
|
|||
class TimeFilter implements IFilter
|
||||
{
|
||||
private long timeLimit_;
|
||||
private boolean isDone_;
|
||||
|
||||
TimeFilter(long timeLimit)
|
||||
{
|
||||
timeLimit_ = timeLimit;
|
||||
isDone_ = false;
|
||||
}
|
||||
|
||||
public ColumnFamily filter(String cf, ColumnFamily columnFamily)
|
||||
|
|
@ -54,23 +52,17 @@ class TimeFilter implements IFilter
|
|||
if (values.length == 1 && !columnFamily.isSuper())
|
||||
{
|
||||
Collection<IColumn> columns = columnFamily.getAllColumns();
|
||||
int i = 0;
|
||||
for (IColumn column : columns)
|
||||
{
|
||||
if (column.timestamp() >= timeLimit_)
|
||||
{
|
||||
filteredCf.addColumn(column);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < columns.size())
|
||||
{
|
||||
isDone_ = true;
|
||||
}
|
||||
}
|
||||
else if (values.length == 2 && columnFamily.isSuper())
|
||||
{
|
||||
|
|
@ -87,23 +79,17 @@ class TimeFilter implements IFilter
|
|||
filteredSuperColumn.markForDeleteAt(column.getLocalDeletionTime(), column.getMarkedForDeleteAt());
|
||||
filteredCf.addColumn(filteredSuperColumn);
|
||||
Collection<IColumn> subColumns = superColumn.getSubColumns();
|
||||
int i = 0;
|
||||
for (IColumn subColumn : subColumns)
|
||||
{
|
||||
if (subColumn.timestamp() >= timeLimit_)
|
||||
{
|
||||
filteredSuperColumn.addColumn(subColumn);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < filteredSuperColumn.getColumnCount())
|
||||
{
|
||||
isDone_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -130,19 +116,12 @@ class TimeFilter implements IFilter
|
|||
dis.reset();
|
||||
if (timeStamp < timeLimit_)
|
||||
{
|
||||
isDone_ = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return isDone_;
|
||||
}
|
||||
|
||||
public DataInputBuffer next(String key, String cfName, SSTable ssTable) throws IOException
|
||||
{
|
||||
return ssTable.next(key, cfName, null, new IndexHelper.TimeRange(timeLimit_, Long.MAX_VALUE));
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ public class RangeFilterTest
|
|||
ColumnFamily filteredCf = f.filter(cf.name(), cf);
|
||||
|
||||
assertEquals(filteredCf.getColumnCount(),3);
|
||||
assertFalse(f.isDone());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -59,7 +58,6 @@ public class RangeFilterTest
|
|||
ColumnFamily filteredCf = f.filter(cf.name(), cf);
|
||||
|
||||
assertEquals(filteredCf.getColumnCount(),2);
|
||||
assertTrue(f.isDone());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -100,7 +98,6 @@ public class RangeFilterTest
|
|||
|
||||
col = filteredCf.getColumn("c");
|
||||
assertNotNull(col);
|
||||
assertFalse(f.isDone());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue