use of org.apache.cassandra.db.filter.IFilter in project eiger by wlloyd.
the class ColumnFamilyStore method filter.
public List<Row> filter(AbstractScanIterator rowIterator, ExtendedFilter filter) {
List<Row> rows = new ArrayList<Row>();
int columnsCount = 0;
try {
while (rowIterator.hasNext() && rows.size() < filter.maxRows() && columnsCount < filter.maxColumns()) {
// get the raw columns requested, and additional columns for the expressions if necessary
Row rawRow = rowIterator.next();
ColumnFamily data = rawRow.cf;
// roughtly
IFilter extraFilter = filter.getExtraFilter(data);
if (extraFilter != null) {
QueryPath path = new QueryPath(columnFamily);
ColumnFamily cf = filter.cfs.getColumnFamily(new QueryFilter(rawRow.key, path, extraFilter));
if (cf != null)
data.addAll(cf, HeapAllocator.instance);
}
if (!filter.isSatisfiedBy(data))
continue;
logger.debug("{} satisfies all filter expressions", data);
// cut the resultset back to what was requested, if necessary
data = filter.prune(data);
rows.add(new Row(rawRow.key, data));
if (data != null)
columnsCount += data.getLiveColumnCount();
// Update the underlying filter to avoid querying more columns per slice than necessary
filter.updateColumnsLimit(columnsCount);
}
return rows;
} finally {
try {
rowIterator.close();
} catch (IOException e) {
throw new IOError(e);
}
}
}
use of org.apache.cassandra.db.filter.IFilter in project eiger by wlloyd.
the class HintedHandOffManager method scheduleAllDeliveries.
/**
* Attempt delivery to any node for which we have hints. Necessary since we can generate hints even for
* nodes which are never officially down/failed.
*/
private void scheduleAllDeliveries() {
if (logger_.isDebugEnabled())
logger_.debug("Started scheduleAllDeliveries");
ColumnFamilyStore hintStore = Table.open(Table.SYSTEM_TABLE).getColumnFamilyStore(HINTS_CF);
IPartitioner p = StorageService.getPartitioner();
RowPosition minPos = p.getMinimumToken().minKeyBound();
Range<RowPosition> range = new Range<RowPosition>(minPos, minPos, p);
IFilter filter = new NamesQueryFilter(ImmutableSortedSet.<ByteBuffer>of());
List<Row> rows = hintStore.getRangeSlice(null, range, Integer.MAX_VALUE, filter, null);
for (Row row : rows) {
Token<?> token = StorageService.getPartitioner().getTokenFactory().fromByteArray(row.key.key);
InetAddress target = StorageService.instance.getTokenMetadata().getEndpoint(token);
scheduleHintDelivery(target);
}
if (logger_.isDebugEnabled())
logger_.debug("Finished scheduleAllDeliveries");
}
use of org.apache.cassandra.db.filter.IFilter in project eiger by wlloyd.
the class StreamingTransferTest method testTransferTable.
@Test
public void testTransferTable() throws Exception {
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed1");
List<String> keys = createAndTransfer(table, cfs, new Mutator() {
public void mutate(String key, String col, long timestamp) throws Exception {
long val = key.hashCode();
RowMutation rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes(key));
ColumnFamily cf = ColumnFamily.create(table.name, cfs.columnFamily);
cf.addColumn(column(col, "v", timestamp));
cf.addColumn(new Column(ByteBufferUtil.bytes("birthdate"), ByteBufferUtil.bytes(val), timestamp));
rm.add(cf);
logger.debug("Applying row to transfer " + rm);
rm.apply();
}
});
// confirm that the secondary index was recovered
for (String key : keys) {
long val = key.hashCode();
IPartitioner p = StorageService.getPartitioner();
IndexExpression expr = new IndexExpression(ByteBufferUtil.bytes("birthdate"), IndexOperator.EQ, ByteBufferUtil.bytes(val));
List<IndexExpression> clause = Arrays.asList(expr);
IFilter filter = new IdentityQueryFilter();
Range<RowPosition> range = Util.range("", "");
List<Row> rows = cfs.search(clause, range, 100, filter);
assertEquals(1, rows.size());
assert rows.get(0).key.key.equals(ByteBufferUtil.bytes(key));
}
}
use of org.apache.cassandra.db.filter.IFilter in project eiger by wlloyd.
the class CleanupTest method testCleanupWithIndexes.
@Test
public void testCleanupWithIndexes() throws IOException, ExecutionException, InterruptedException {
Table table = Table.open(TABLE1);
ColumnFamilyStore cfs = table.getColumnFamilyStore(CF1);
assertEquals(cfs.indexManager.getIndexedColumns().iterator().next(), COLUMN);
List<Row> rows;
// insert data and verify we get it back w/ range query
fillCF(cfs, LOOPS);
rows = Util.getRangeSlice(cfs);
assertEquals(LOOPS, rows.size());
SecondaryIndex index = cfs.indexManager.getIndexForColumn(COLUMN);
long start = System.currentTimeMillis();
while (!index.isIndexBuilt(COLUMN) && System.currentTimeMillis() < start + 10000) Thread.sleep(10);
// verify we get it back w/ index query too
IndexExpression expr = new IndexExpression(COLUMN, IndexOperator.EQ, VALUE);
List<IndexExpression> clause = Arrays.asList(expr);
IFilter filter = new IdentityQueryFilter();
IPartitioner p = StorageService.getPartitioner();
Range<RowPosition> range = Util.range("", "");
rows = table.getColumnFamilyStore(CF1).search(clause, range, Integer.MAX_VALUE, filter);
assertEquals(LOOPS, rows.size());
// we don't allow cleanup when the local host has no range to avoid wipping up all data when a node has not join the ring.
// So to make sure cleanup erase everything here, we give the localhost the tiniest possible range.
TokenMetadata tmd = StorageService.instance.getTokenMetadata();
byte[] tk1 = new byte[1], tk2 = new byte[1];
tk1[0] = 2;
tk2[0] = 1;
tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1"));
tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2"));
CompactionManager.instance.performCleanup(cfs, new NodeId.OneShotRenewer());
// row data should be gone
rows = Util.getRangeSlice(cfs);
assertEquals(0, rows.size());
// not only should it be gone but there should be no data on disk, not even tombstones
assert cfs.getSSTables().isEmpty();
// 2ary indexes should result in no results, too (although tombstones won't be gone until compacted)
rows = cfs.search(clause, range, Integer.MAX_VALUE, filter);
assertEquals(0, rows.size());
}
use of org.apache.cassandra.db.filter.IFilter in project eiger by wlloyd.
the class RangeSliceVerbHandler method executeLocally.
static List<Row> executeLocally(RangeSliceCommand command) throws ExecutionException, InterruptedException {
ColumnFamilyStore cfs = Table.open(command.keyspace).getColumnFamilyStore(command.column_family);
IFilter columnFilter = QueryFilter.getFilter(command.predicate, cfs.getComparator());
if (cfs.indexManager.hasIndexFor(command.row_filter))
return cfs.search(command.row_filter, command.range, command.maxResults, columnFilter, command.maxIsColumns);
else
return cfs.getRangeSlice(command.super_column, command.range, command.maxResults, columnFilter, command.row_filter, command.maxIsColumns);
}
Aggregations