Search in sources :

Example 1 with LifecycleTransaction

use of org.apache.cassandra.db.lifecycle.LifecycleTransaction in project cassandra by apache.

the class TimeWindowCompactionStrategy method getNextBackgroundTask.

@Override
// transaction is closed by AbstractCompactionTask::execute
@SuppressWarnings("resource")
public AbstractCompactionTask getNextBackgroundTask(int gcBefore) {
    while (true) {
        List<SSTableReader> latestBucket = getNextBackgroundSSTables(gcBefore);
        if (latestBucket.isEmpty())
            return null;
        LifecycleTransaction modifier = cfs.getTracker().tryModify(latestBucket, OperationType.COMPACTION);
        if (modifier != null)
            return new CompactionTask(cfs, modifier, gcBefore);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 2 with LifecycleTransaction

use of org.apache.cassandra.db.lifecycle.LifecycleTransaction in project cassandra by apache.

the class TimeWindowCompactionStrategy method getMaximalTask.

@Override
// transaction is closed by AbstractCompactionTask::execute
@SuppressWarnings("resource")
public synchronized Collection<AbstractCompactionTask> getMaximalTask(int gcBefore, boolean splitOutput) {
    Iterable<SSTableReader> filteredSSTables = filterSuspectSSTables(sstables);
    if (Iterables.isEmpty(filteredSSTables))
        return null;
    LifecycleTransaction txn = cfs.getTracker().tryModify(filteredSSTables, OperationType.COMPACTION);
    if (txn == null)
        return null;
    return Collections.singleton(new CompactionTask(cfs, txn, gcBefore));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 3 with LifecycleTransaction

use of org.apache.cassandra.db.lifecycle.LifecycleTransaction in project cassandra by apache.

the class SizeTieredCompactionStrategy method getNextBackgroundTask.

@SuppressWarnings("resource")
public AbstractCompactionTask getNextBackgroundTask(int gcBefore) {
    while (true) {
        List<SSTableReader> hottestBucket = getNextBackgroundSSTables(gcBefore);
        if (hottestBucket.isEmpty())
            return null;
        LifecycleTransaction transaction = cfs.getTracker().tryModify(hottestBucket, OperationType.COMPACTION);
        if (transaction != null)
            return new CompactionTask(cfs, transaction, gcBefore);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 4 with LifecycleTransaction

use of org.apache.cassandra.db.lifecycle.LifecycleTransaction in project cassandra by apache.

the class DateTieredCompactionStrategy method getMaximalTask.

@Override
@SuppressWarnings("resource")
public synchronized Collection<AbstractCompactionTask> getMaximalTask(int gcBefore, boolean splitOutput) {
    Iterable<SSTableReader> filteredSSTables = filterSuspectSSTables(sstables);
    if (Iterables.isEmpty(filteredSSTables))
        return null;
    LifecycleTransaction txn = cfs.getTracker().tryModify(filteredSSTables, OperationType.COMPACTION);
    if (txn == null)
        return null;
    return Collections.<AbstractCompactionTask>singleton(new CompactionTask(cfs, txn, gcBefore));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 5 with LifecycleTransaction

use of org.apache.cassandra.db.lifecycle.LifecycleTransaction in project cassandra by apache.

the class LeveledCompactionStrategy method getNextBackgroundTask.

/**
     * the only difference between background and maximal in LCS is that maximal is still allowed
     * (by explicit user request) even when compaction is disabled.
     */
// transaction is closed by AbstractCompactionTask::execute
@SuppressWarnings("resource")
public AbstractCompactionTask getNextBackgroundTask(int gcBefore) {
    while (true) {
        OperationType op;
        LeveledManifest.CompactionCandidate candidate = manifest.getCompactionCandidates();
        if (candidate == null) {
            // if there is no sstable to compact in standard way, try compacting based on droppable tombstone ratio
            SSTableReader sstable = findDroppableSSTable(gcBefore);
            if (sstable == null) {
                logger.trace("No compaction necessary for {}", this);
                return null;
            }
            candidate = new LeveledManifest.CompactionCandidate(Collections.singleton(sstable), sstable.getSSTableLevel(), getMaxSSTableBytes());
            op = OperationType.TOMBSTONE_COMPACTION;
        } else {
            op = OperationType.COMPACTION;
        }
        LifecycleTransaction txn = cfs.getTracker().tryModify(candidate.sstables, OperationType.COMPACTION);
        if (txn != null) {
            LeveledCompactionTask newTask = new LeveledCompactionTask(cfs, txn, candidate.level, gcBefore, candidate.maxSSTableBytes, false);
            newTask.setCompactionType(op);
            return newTask;
        }
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Aggregations

LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)60 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)53 Test (org.junit.Test)28 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)24 Keyspace (org.apache.cassandra.db.Keyspace)23 CompactionController (org.apache.cassandra.db.compaction.CompactionController)13 CompactionIterator (org.apache.cassandra.db.compaction.CompactionIterator)12 File (java.io.File)10 Range (org.apache.cassandra.dht.Range)7 UUID (java.util.UUID)5 BytesToken (org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken)5 Token (org.apache.cassandra.dht.Token)5 IOException (java.io.IOException)4 AbstractCompactionStrategy (org.apache.cassandra.db.compaction.AbstractCompactionStrategy)4 CompactionAwareWriter (org.apache.cassandra.db.compaction.writers.CompactionAwareWriter)4 SSTableWriter (org.apache.cassandra.io.sstable.format.SSTableWriter)4 RestorableMeter (org.apache.cassandra.metrics.RestorableMeter)4 ByteBuffer (java.nio.ByteBuffer)3 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)3 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)3