Search in sources :

Example 6 with CompactionInfo

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

the class ViewBuilder method getCompactionInfo.

public CompactionInfo getCompactionInfo() {
    long rangesLeft = 0, rangesTotal = 0;
    Token lastToken = prevToken;
    // has.
    for (Range<Token> range : StorageService.instance.getLocalRanges(baseCfs.keyspace.getName())) {
        rangesLeft++;
        rangesTotal++;
        // end of the method.
        if (lastToken == null || range.contains(lastToken))
            rangesLeft = 0;
    }
    return new CompactionInfo(baseCfs.metadata(), OperationType.VIEW_BUILD, rangesLeft, rangesTotal, "ranges", compactionId);
}
Also used : Token(org.apache.cassandra.dht.Token) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo)

Example 7 with CompactionInfo

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

the class SSTableTasksTable method data.

public DataSet data() {
    SimpleDataSet result = new SimpleDataSet(metadata());
    for (CompactionInfo task : CompactionManager.instance.getSSTableTasks()) {
        long completed = task.getCompleted();
        long total = task.getTotal();
        double completionRatio = total == 0L ? 1.0 : (((double) completed) / total);
        result.row(task.getKeyspace().orElse("*"), task.getTable().orElse("*"), task.getTaskId()).column(COMPLETION_RATIO, completionRatio).column(KIND, task.getTaskType().toString().toLowerCase()).column(PROGRESS, completed).column(SSTABLES, task.getSSTables().size()).column(TOTAL, total).column(UNIT, task.getUnit().toString().toLowerCase());
    }
    return result;
}
Also used : CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo)

Example 8 with CompactionInfo

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

the class IndexSummaryManagerTest method testCancelIndexHelper.

public void testCancelIndexHelper(Consumer<ColumnFamilyStore> cancelFunction) 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);
    cfs.disableAutoCompaction();
    final int numSSTables = 8;
    int numRows = 256;
    createSSTables(ksname, cfname, numSSTables, numRows);
    List<SSTableReader> allSSTables = new ArrayList<>(cfs.getLiveSSTables());
    List<SSTableReader> sstables = allSSTables.subList(0, 4);
    List<SSTableReader> compacting = allSSTables.subList(4, 8);
    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);
    CompactionInfo.Holder ongoingCompaction = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.UNKNOWN, 0, 0, UUID.randomUUID(), compacting);
        }

        public boolean isGlobal() {
            return false;
        }
    };
    try (LifecycleTransaction ignored = cfs.getTracker().tryModify(compacting, OperationType.UNKNOWN)) {
        CompactionManager.instance.active.beginCompaction(ongoingCompaction);
        Thread t = NamedThreadFactory.createAnonymousThread(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(of(cfs.metadata.id, txn), 0, singleSummaryOffHeapSpace, barrier));
                    }
                } catch (CompactionInterruptedException ex) {
                    exception.set(ex);
                } catch (IOException ignored) {
                }
            }
        });
        t.start();
        while (CompactionManager.instance.getActiveCompactions() < 2 && 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.
        cancelFunction.accept(cfs);
        // allows the redistribution to proceed
        barrier.countDown();
        t.join();
    } finally {
        CompactionManager.instance.active.finishCompaction(ongoingCompaction);
    }
    assertNotNull("Expected compaction interrupted exception", exception.get());
    assertTrue("Expected no active compactions", CompactionManager.instance.active.getCompactions().isEmpty());
    Set<SSTableReader> beforeRedistributionSSTables = new HashSet<>(allSSTables);
    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());
    assertOnDiskState(cfs, 8);
    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) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo)

Aggregations

CompactionInfo (org.apache.cassandra.db.compaction.CompactionInfo)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)6 Test (org.junit.Test)5 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 CQLTester (org.apache.cassandra.cql3.CQLTester)3 CompactionManager (org.apache.cassandra.db.compaction.CompactionManager)3 OperationType (org.apache.cassandra.db.compaction.OperationType)3 MockSchema (org.apache.cassandra.schema.MockSchema)3 BeforeClass (org.junit.BeforeClass)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ExecutorPlus (org.apache.cassandra.concurrent.ExecutorPlus)2 AbstractPendingRepairTest (org.apache.cassandra.db.compaction.AbstractPendingRepairTest)2 ToolRunner (org.apache.cassandra.tools.ToolRunner)2 Future (org.apache.cassandra.utils.concurrent.Future)2 Assertions (org.assertj.core.api.Assertions)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2