Search in sources :

Example 6 with CompactionInterruptedException

use of org.apache.cassandra.db.compaction.CompactionInterruptedException in project cassandra by apache.

the class IndexSummaryManagerTest method testCancelIndex.

@Test
public void testCancelIndex() throws Exception {
    String ksname = KEYSPACE1;
    // index interval of 8, no key caching
    String cfname = CF_STANDARDLOWiINTERVAL;
    Keyspace keyspace = Keyspace.open(ksname);
    final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname);
    final int numSSTables = 4;
    int numRows = 256;
    createSSTables(ksname, cfname, numSSTables, numRows);
    final List<SSTableReader> sstables = new ArrayList<>(cfs.getLiveSSTables());
    for (SSTableReader sstable : sstables) sstable.overrideReadMeter(new RestorableMeter(100.0, 100.0));
    final long singleSummaryOffHeapSpace = sstables.get(0).getIndexSummaryOffHeapSize();
    // everything should get cut in half
    final AtomicReference<CompactionInterruptedException> exception = new AtomicReference<>();
    // barrier to control when redistribution runs
    final CountDownLatch barrier = new CountDownLatch(1);
    Thread t = NamedThreadFactory.createThread(new Runnable() {

        public void run() {
            try {
                // Don't leave enough space for even the minimal index summaries
                try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.UNKNOWN)) {
                    IndexSummaryManager.redistributeSummaries(new ObservableRedistribution(Collections.EMPTY_LIST, of(cfs.metadata.id, txn), singleSummaryOffHeapSpace, barrier));
                }
            } catch (CompactionInterruptedException ex) {
                exception.set(ex);
            } catch (IOException ignored) {
            }
        }
    });
    t.start();
    while (CompactionManager.instance.getActiveCompactions() == 0 && t.isAlive()) Thread.sleep(1);
    // to ensure that the stop condition check in IndexSummaryRedistribution::redistributeSummaries
    // is made *after* the halt request is made to the CompactionManager, don't allow the redistribution
    // to proceed until stopCompaction has been called.
    CompactionManager.instance.stopCompaction("INDEX_SUMMARY");
    // allows the redistribution to proceed
    barrier.countDown();
    t.join();
    assertNotNull("Expected compaction interrupted exception", exception.get());
    assertTrue("Expected no active compactions", CompactionMetrics.getCompactions().isEmpty());
    Set<SSTableReader> beforeRedistributionSSTables = new HashSet<>(sstables);
    Set<SSTableReader> afterCancelSSTables = new HashSet<>(cfs.getLiveSSTables());
    Set<SSTableReader> disjoint = Sets.symmetricDifference(beforeRedistributionSSTables, afterCancelSSTables);
    assertTrue(String.format("Mismatched files before and after cancelling redistribution: %s", Joiner.on(",").join(disjoint)), disjoint.isEmpty());
    validateData(cfs, numRows);
}
Also used : CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) RestorableMeter(org.apache.cassandra.metrics.RestorableMeter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Example 7 with CompactionInterruptedException

use of org.apache.cassandra.db.compaction.CompactionInterruptedException in project cassandra by apache.

the class CrcCheckChanceTest method testDropDuringCompaction.

@Test
public void testDropDuringCompaction() throws Throwable {
    CompactionManager.instance.disableAutoCompaction();
    //Start with crc_check_chance of 99%
    createTable("CREATE TABLE %s (p text, c text, v text, s text static, PRIMARY KEY (p, c)) WITH compression = {'sstable_compression': 'LZ4Compressor', 'crc_check_chance' : 0.99}");
    ColumnFamilyStore cfs = Keyspace.open(CQLTester.KEYSPACE).getColumnFamilyStore(currentTable());
    //Write a few SSTables then Compact, and drop
    for (int i = 0; i < 100; i++) {
        execute("INSERT INTO %s(p, c, v, s) values (?, ?, ?, ?)", "p1", "k1", "v1", "sv1");
        execute("INSERT INTO %s(p, c, v) values (?, ?, ?)", "p1", "k2", "v2");
        execute("INSERT INTO %s(p, s) values (?, ?)", "p2", "sv2");
        cfs.forceBlockingFlush();
    }
    DatabaseDescriptor.setCompactionThroughputMbPerSec(1);
    List<Future<?>> futures = CompactionManager.instance.submitMaximal(cfs, CompactionManager.getDefaultGcBefore(cfs, FBUtilities.nowInSeconds()), false);
    execute("DROP TABLE %s");
    try {
        FBUtilities.waitOnFutures(futures);
    } catch (Throwable t) {
        if (!(t.getCause() instanceof ExecutionException) || !(t.getCause().getCause() instanceof CompactionInterruptedException))
            throw t;
    }
}
Also used : CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

CompactionInterruptedException (org.apache.cassandra.db.compaction.CompactionInterruptedException)7 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)4 IOException (java.io.IOException)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 ArrayList (java.util.ArrayList)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Keyspace (org.apache.cassandra.db.Keyspace)1 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)1 ColumnIndex (org.apache.cassandra.index.sasi.conf.ColumnIndex)1 PerSSTableIndexWriter (org.apache.cassandra.index.sasi.disk.PerSSTableIndexWriter)1 FSReadError (org.apache.cassandra.io.FSReadError)1 KeyIterator (org.apache.cassandra.io.sstable.KeyIterator)1 SSTableIdentityIterator (org.apache.cassandra.io.sstable.SSTableIdentityIterator)1