Search in sources :

Example 1 with IndexMemtable

use of org.apache.cassandra.index.sasi.memory.IndexMemtable in project cassandra by apache.

the class ColumnIndex method searchMemtable.

public RangeIterator<Long, Token> searchMemtable(Expression e) {
    RangeIterator.Builder<Long, Token> builder = new RangeUnionIterator.Builder<>();
    builder.add(getCurrentMemtable().search(e));
    for (IndexMemtable memtable : getPendingMemtables()) builder.add(memtable.search(e));
    return builder.build();
}
Also used : RangeIterator(org.apache.cassandra.index.sasi.utils.RangeIterator) OnDiskIndexBuilder(org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder) Token(org.apache.cassandra.index.sasi.disk.Token) IndexMemtable(org.apache.cassandra.index.sasi.memory.IndexMemtable)

Example 2 with IndexMemtable

use of org.apache.cassandra.index.sasi.memory.IndexMemtable in project cassandra by apache.

the class SASIIndexTest method testIndexMemtableSwitching.

@Test
public void testIndexMemtableSwitching() throws Exception {
    // write some data but don't flush
    ColumnFamilyStore store = loadData(new HashMap<String, Pair<String, Integer>>() {

        {
            put("key1", Pair.create("Pavel", 14));
        }
    }, false);
    ColumnIndex index = ((SASIIndex) store.indexManager.getIndexByName(store.name + "_first_name")).getIndex();
    IndexMemtable beforeFlushMemtable = index.getCurrentMemtable();
    PartitionRangeReadCommand command = PartitionRangeReadCommand.create(store.metadata(), FBUtilities.nowInSeconds(), ColumnFilter.all(store.metadata()), RowFilter.NONE, DataLimits.NONE, DataRange.allData(store.getPartitioner()));
    QueryController controller = new QueryController(store, command, Integer.MAX_VALUE);
    org.apache.cassandra.index.sasi.plan.Expression expression = new org.apache.cassandra.index.sasi.plan.Expression(controller, index).add(Operator.LIKE_MATCHES, UTF8Type.instance.fromString("Pavel"));
    Assert.assertTrue(rangesSize(beforeFlushMemtable, expression) > 0);
    store.forceBlockingFlush();
    IndexMemtable afterFlushMemtable = index.getCurrentMemtable();
    Assert.assertNotSame(afterFlushMemtable, beforeFlushMemtable);
    Assert.assertEquals(rangesSize(afterFlushMemtable, expression), 0);
    Assert.assertEquals(0, index.getPendingMemtables().size());
    loadData(new HashMap<String, Pair<String, Integer>>() {

        {
            put("key2", Pair.create("Sam", 15));
        }
    }, false);
    expression = new org.apache.cassandra.index.sasi.plan.Expression(controller, index).add(Operator.LIKE_MATCHES, UTF8Type.instance.fromString("Sam"));
    beforeFlushMemtable = index.getCurrentMemtable();
    Assert.assertTrue(rangesSize(beforeFlushMemtable, expression) > 0);
    // let's emulate switching memtable and see if we can still read-data in "pending"
    index.switchMemtable(store.getTracker().getView().getCurrentMemtable());
    Assert.assertNotSame(index.getCurrentMemtable(), beforeFlushMemtable);
    Assert.assertEquals(1, index.getPendingMemtables().size());
    Assert.assertTrue(rangesSize(index, expression) > 0);
    // emulate "everything is flushed" notification
    index.discardMemtable(store.getTracker().getView().getCurrentMemtable());
    Assert.assertEquals(0, index.getPendingMemtables().size());
    Assert.assertEquals(rangesSize(index, expression), 0);
    // test discarding data from memtable
    loadData(new HashMap<String, Pair<String, Integer>>() {

        {
            put("key3", Pair.create("Jonathan", 16));
        }
    }, false);
    expression = new org.apache.cassandra.index.sasi.plan.Expression(controller, index).add(Operator.LIKE_MATCHES, UTF8Type.instance.fromString("Jonathan"));
    Assert.assertTrue(rangesSize(index, expression) > 0);
    index.switchMemtable();
    Assert.assertEquals(rangesSize(index, expression), 0);
}
Also used : ColumnIndex(org.apache.cassandra.index.sasi.conf.ColumnIndex) QueryController(org.apache.cassandra.index.sasi.plan.QueryController) IndexMemtable(org.apache.cassandra.index.sasi.memory.IndexMemtable) Pair(org.apache.cassandra.utils.Pair)

Aggregations

IndexMemtable (org.apache.cassandra.index.sasi.memory.IndexMemtable)2 ColumnIndex (org.apache.cassandra.index.sasi.conf.ColumnIndex)1 OnDiskIndexBuilder (org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder)1 Token (org.apache.cassandra.index.sasi.disk.Token)1 QueryController (org.apache.cassandra.index.sasi.plan.QueryController)1 RangeIterator (org.apache.cassandra.index.sasi.utils.RangeIterator)1 Pair (org.apache.cassandra.utils.Pair)1