Search in sources :

Example 1 with IndexSummaryRedistribution

use of org.apache.cassandra.io.sstable.IndexSummaryRedistribution in project cassandra by apache.

the class ActiveCompactionsTest method testIndexSummaryRedistributionTracking.

@Test
public void testIndexSummaryRedistributionTracking() throws Throwable {
    createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))");
    getCurrentColumnFamilyStore().disableAutoCompaction();
    for (int i = 0; i < 5; i++) {
        execute("INSERT INTO %s (pk, ck, a, b) VALUES (" + i + ", 2, 3, 4)");
        getCurrentColumnFamilyStore().forceBlockingFlush();
    }
    Set<SSTableReader> sstables = getCurrentColumnFamilyStore().getLiveSSTables();
    try (LifecycleTransaction txn = getCurrentColumnFamilyStore().getTracker().tryModify(sstables, OperationType.INDEX_SUMMARY)) {
        Map<TableId, LifecycleTransaction> transactions = ImmutableMap.<TableId, LifecycleTransaction>builder().put(getCurrentColumnFamilyStore().metadata().id, txn).build();
        IndexSummaryRedistribution isr = new IndexSummaryRedistribution(transactions, 0, 1000);
        MockActiveCompactions mockActiveCompactions = new MockActiveCompactions();
        CompactionManager.instance.runIndexSummaryRedistribution(isr, mockActiveCompactions);
        assertTrue(mockActiveCompactions.finished);
        assertNotNull(mockActiveCompactions.holder);
        // index redistribution operates over all keyspaces/tables, we always cancel them
        assertTrue(mockActiveCompactions.holder.getCompactionInfo().getSSTables().isEmpty());
        assertTrue(mockActiveCompactions.holder.getCompactionInfo().shouldStop((sstable) -> false));
    }
}
Also used : TableId(org.apache.cassandra.schema.TableId) 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) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) IndexSummaryRedistribution(org.apache.cassandra.io.sstable.IndexSummaryRedistribution) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) Test(org.junit.Test)

Example 2 with IndexSummaryRedistribution

use of org.apache.cassandra.io.sstable.IndexSummaryRedistribution in project cassandra by apache.

the class DiskSpaceMetricsTest method indexDownsampleCancelLastSSTable.

private static void indexDownsampleCancelLastSSTable(ColumnFamilyStore cfs) {
    List<SSTableReader> sstables = Lists.newArrayList(cfs.getSSTables(SSTableSet.CANONICAL));
    LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN);
    Map<TableId, LifecycleTransaction> txns = ImmutableMap.of(cfs.metadata.id, txn);
    // fail on the last file (* 3 because we call isStopRequested 3 times for each sstable, and we should fail on the last)
    AtomicInteger countdown = new AtomicInteger(3 * sstables.size() - 1);
    IndexSummaryRedistribution redistribution = new IndexSummaryRedistribution(txns, 0, 0) {

        public boolean isStopRequested() {
            return countdown.decrementAndGet() == 0;
        }
    };
    try {
        IndexSummaryManager.redistributeSummaries(redistribution);
        Assert.fail("Should throw CompactionInterruptedException");
    } catch (CompactionInterruptedException e) {
    // trying to get this to happen
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            FBUtilities.closeAll(txns.values());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : TableId(org.apache.cassandra.schema.TableId) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) IndexSummaryRedistribution(org.apache.cassandra.io.sstable.IndexSummaryRedistribution) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) IOException(java.io.IOException) IOException(java.io.IOException) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException)

Example 3 with IndexSummaryRedistribution

use of org.apache.cassandra.io.sstable.IndexSummaryRedistribution in project cassandra by apache.

the class EntireSSTableStreamConcurrentComponentMutationTest method indexSummaryRedistribution.

private boolean indexSummaryRedistribution() throws IOException {
    long nonRedistributingOffHeapSize = 0;
    long memoryPoolBytes = 1024 * 1024;
    // rewrite index summary file with new min/max index interval
    TableMetadata origin = store.metadata();
    MigrationManager.announceTableUpdate(origin.unbuild().minIndexInterval(1).maxIndexInterval(2).build(), true);
    try (LifecycleTransaction txn = store.getTracker().tryModify(sstable, OperationType.INDEX_SUMMARY)) {
        IndexSummaryManager.redistributeSummaries(new IndexSummaryRedistribution(ImmutableMap.of(store.metadata().id, txn), nonRedistributingOffHeapSize, memoryPoolBytes));
    }
    // reset min/max index interval
    MigrationManager.announceTableUpdate(origin, true);
    return true;
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) IndexSummaryRedistribution(org.apache.cassandra.io.sstable.IndexSummaryRedistribution) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Aggregations

LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)3 IndexSummaryRedistribution (org.apache.cassandra.io.sstable.IndexSummaryRedistribution)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 TableId (org.apache.cassandra.schema.TableId)2 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 IOException (java.io.IOException)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 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1