Search in sources :

Example 1 with IFilter

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);
        }
    }
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IFilter(org.apache.cassandra.db.filter.IFilter)

Example 2 with IFilter

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");
}
Also used : IFilter(org.apache.cassandra.db.filter.IFilter) Range(org.apache.cassandra.dht.Range) NamesQueryFilter(org.apache.cassandra.db.filter.NamesQueryFilter) InetAddress(java.net.InetAddress) IPartitioner(org.apache.cassandra.dht.IPartitioner)

Example 3 with IFilter

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));
    }
}
Also used : IndexExpression(org.apache.cassandra.thrift.IndexExpression) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) IFilter(org.apache.cassandra.db.filter.IFilter) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 4 with IFilter

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());
}
Also used : IndexExpression(org.apache.cassandra.thrift.IndexExpression) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) IdentityQueryFilter(org.apache.cassandra.db.columniterator.IdentityQueryFilter) SecondaryIndex(org.apache.cassandra.db.index.SecondaryIndex) IFilter(org.apache.cassandra.db.filter.IFilter) BytesToken(org.apache.cassandra.dht.BytesToken) NodeId(org.apache.cassandra.utils.NodeId) IPartitioner(org.apache.cassandra.dht.IPartitioner) Test(org.junit.Test)

Example 5 with IFilter

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);
}
Also used : IFilter(org.apache.cassandra.db.filter.IFilter) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Aggregations

IFilter (org.apache.cassandra.db.filter.IFilter)5 IPartitioner (org.apache.cassandra.dht.IPartitioner)3 IdentityQueryFilter (org.apache.cassandra.db.columniterator.IdentityQueryFilter)2 IndexExpression (org.apache.cassandra.thrift.IndexExpression)2 Test (org.junit.Test)2 InetAddress (java.net.InetAddress)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 NamesQueryFilter (org.apache.cassandra.db.filter.NamesQueryFilter)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 QueryPath (org.apache.cassandra.db.filter.QueryPath)1 SecondaryIndex (org.apache.cassandra.db.index.SecondaryIndex)1 BytesToken (org.apache.cassandra.dht.BytesToken)1 Range (org.apache.cassandra.dht.Range)1 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)1 NodeId (org.apache.cassandra.utils.NodeId)1