Search in sources :

Example 36 with LifecycleTransaction

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

the class LeveledCompactionStrategy method getMaximalTask.

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

Example 37 with LifecycleTransaction

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

the class CompactionManager method parallelAllSSTableOperation.

/**
     * Run an operation over all sstables using jobs threads
     *
     * @param cfs the column family store to run the operation on
     * @param operation the operation to run
     * @param jobs the number of threads to use - 0 means use all available. It never uses more than concurrent_compactors threads
     * @return status of the operation
     * @throws ExecutionException
     * @throws InterruptedException
     */
@SuppressWarnings("resource")
private AllSSTableOpStatus parallelAllSSTableOperation(final ColumnFamilyStore cfs, final OneSSTableOperation operation, int jobs, OperationType operationType) throws ExecutionException, InterruptedException {
    List<LifecycleTransaction> transactions = new ArrayList<>();
    try (LifecycleTransaction compacting = cfs.markAllCompacting(operationType)) {
        Iterable<SSTableReader> sstables = compacting != null ? Lists.newArrayList(operation.filterSSTables(compacting)) : Collections.<SSTableReader>emptyList();
        if (Iterables.isEmpty(sstables)) {
            logger.info("No sstables to {} for {}.{}", operationType.name(), cfs.keyspace.getName(), cfs.name);
            return AllSSTableOpStatus.SUCCESSFUL;
        }
        List<Future<?>> futures = new ArrayList<>();
        for (final SSTableReader sstable : sstables) {
            final LifecycleTransaction txn = compacting.split(singleton(sstable));
            transactions.add(txn);
            Callable<Object> callable = new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    operation.execute(txn);
                    return this;
                }
            };
            Future<?> fut = executor.submitIfRunning(callable, "paralell sstable operation");
            if (!fut.isCancelled())
                futures.add(fut);
            else
                return AllSSTableOpStatus.ABORTED;
            if (jobs > 0 && futures.size() == jobs) {
                FBUtilities.waitOnFutures(futures);
                futures.clear();
            }
        }
        FBUtilities.waitOnFutures(futures);
        assert compacting.originals().isEmpty();
        return AllSSTableOpStatus.SUCCESSFUL;
    } finally {
        Throwable fail = Throwables.close(null, transactions);
        if (fail != null)
            logger.error("Failed to cleanup lifecycle transactions {}", fail);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 38 with LifecycleTransaction

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

the class PendingRepairManager method getRepairFinishedCompactionTask.

@SuppressWarnings("resource")
private RepairFinishedCompactionTask getRepairFinishedCompactionTask(UUID sessionID) {
    Set<SSTableReader> sstables = get(sessionID).getSSTables();
    long repairedAt = ActiveRepairService.instance.consistent.local.getFinalSessionRepairedAt(sessionID);
    LifecycleTransaction txn = cfs.getTracker().tryModify(sstables, OperationType.COMPACTION);
    return txn == null ? null : new RepairFinishedCompactionTask(cfs, txn, sessionID, repairedAt);
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 39 with LifecycleTransaction

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

the class SizeTieredCompactionStrategy method getMaximalTask.

@SuppressWarnings("resource")
public Collection<AbstractCompactionTask> getMaximalTask(final 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;
    if (splitOutput)
        return Arrays.<AbstractCompactionTask>asList(new SplittingCompactionTask(cfs, txn, gcBefore));
    return Arrays.<AbstractCompactionTask>asList(new CompactionTask(cfs, txn, gcBefore));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 40 with LifecycleTransaction

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

the class SSTableTxnWriter method createRangeAware.

// log and writer closed during doPostCleanup
@SuppressWarnings("resource")
public static SSTableTxnWriter createRangeAware(TableMetadataRef metadata, long keyCount, long repairedAt, UUID pendingRepair, SSTableFormat.Type type, int sstableLevel, SerializationHeader header) {
    ColumnFamilyStore cfs = Keyspace.open(metadata.keyspace).getColumnFamilyStore(metadata.name);
    LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.WRITE);
    SSTableMultiWriter writer;
    try {
        writer = new RangeAwareSSTableWriter(cfs, keyCount, repairedAt, pendingRepair, type, sstableLevel, 0, txn, header);
    } catch (IOException e) {
        //as we send in 0
        throw new RuntimeException(e);
    }
    return new SSTableTxnWriter(txn, writer);
}
Also used : RangeAwareSSTableWriter(org.apache.cassandra.io.sstable.format.RangeAwareSSTableWriter) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) IOException(java.io.IOException)

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