Search in sources :

Example 1 with QueryController

use of org.apache.cassandra.index.sasi.plan.QueryController 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

ColumnIndex (org.apache.cassandra.index.sasi.conf.ColumnIndex)1 IndexMemtable (org.apache.cassandra.index.sasi.memory.IndexMemtable)1 QueryController (org.apache.cassandra.index.sasi.plan.QueryController)1 Pair (org.apache.cassandra.utils.Pair)1