Search in sources :

Example 1 with ViewBuilderTask

use of org.apache.cassandra.db.view.ViewBuilderTask in project cassandra by apache.

the class ActiveCompactionsTest method testViewBuildTracking.

@Test
public void testViewBuildTracking() throws Throwable {
    createTable("CREATE TABLE %s (k1 int, c1 int , val int, PRIMARY KEY (k1, c1))");
    getCurrentColumnFamilyStore().disableAutoCompaction();
    for (int i = 0; i < 5; i++) {
        execute("INSERT INTO %s (k1, c1, val) VALUES (" + i + ", 2, 3)");
        getCurrentColumnFamilyStore().forceBlockingFlush();
    }
    execute(String.format("CREATE MATERIALIZED VIEW %s.view1 AS SELECT k1, c1, val FROM %s.%s WHERE k1 IS NOT NULL AND c1 IS NOT NULL AND val IS NOT NULL PRIMARY KEY (val, k1, c1)", keyspace(), keyspace(), currentTable()));
    View view = Iterables.getOnlyElement(getCurrentColumnFamilyStore().viewManager);
    Token token = DatabaseDescriptor.getPartitioner().getMinimumToken();
    ViewBuilderTask vbt = new ViewBuilderTask(getCurrentColumnFamilyStore(), view, new Range<>(token, token), token, 0);
    MockActiveCompactions mockActiveCompactions = new MockActiveCompactions();
    CompactionManager.instance.submitViewBuilder(vbt, mockActiveCompactions).get();
    assertTrue(mockActiveCompactions.finished);
    assertTrue(mockActiveCompactions.holder.getCompactionInfo().getSSTables().isEmpty());
    // this should stop for all compactions, even if it doesn't pick any sstables;
    assertTrue(mockActiveCompactions.holder.getCompactionInfo().shouldStop((sstable) -> false));
}
Also used : Arrays(java.util.Arrays) Iterables(com.google.common.collect.Iterables) CQLTester(org.apache.cassandra.cql3.CQLTester) TableId(org.apache.cassandra.schema.TableId) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) View(org.apache.cassandra.db.view.View) Future(java.util.concurrent.Future) Token(org.apache.cassandra.dht.Token) Map(java.util.Map) ViewBuilderTask(org.apache.cassandra.db.view.ViewBuilderTask) Index(org.apache.cassandra.index.Index) CacheService(org.apache.cassandra.service.CacheService) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) ExecutorService(java.util.concurrent.ExecutorService) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) FBUtilities(org.apache.cassandra.utils.FBUtilities) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertNotNull(org.junit.Assert.assertNotNull) SecondaryIndexBuilder(org.apache.cassandra.index.SecondaryIndexBuilder) Set(java.util.Set) AutoSavingCache(org.apache.cassandra.cache.AutoSavingCache) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Executors(java.util.concurrent.Executors) Sets(com.google.common.collect.Sets) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Assert.assertFalse(org.junit.Assert.assertFalse) IndexSummaryRedistribution(org.apache.cassandra.io.sstable.IndexSummaryRedistribution) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Token(org.apache.cassandra.dht.Token) ViewBuilderTask(org.apache.cassandra.db.view.ViewBuilderTask) View(org.apache.cassandra.db.view.View) Test(org.junit.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeUnit (java.util.concurrent.TimeUnit)1 AutoSavingCache (org.apache.cassandra.cache.AutoSavingCache)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 CQLTester (org.apache.cassandra.cql3.CQLTester)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 View (org.apache.cassandra.db.view.View)1 ViewBuilderTask (org.apache.cassandra.db.view.ViewBuilderTask)1