Search in sources :

Example 6 with LifecycleTransaction

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

the class LeveledCompactionStrategy method getUserDefinedTask.

@Override
// transaction is closed by AbstractCompactionTask::execute
@SuppressWarnings("resource")
public AbstractCompactionTask getUserDefinedTask(Collection<SSTableReader> sstables, int gcBefore) {
    if (sstables.isEmpty())
        return null;
    LifecycleTransaction transaction = cfs.getTracker().tryModify(sstables, OperationType.COMPACTION);
    if (transaction == null) {
        logger.trace("Unable to mark {} for compaction; probably a background compaction got to it first.  You can disable background compactions temporarily if this is a problem", sstables);
        return null;
    }
    int level = sstables.size() > 1 ? 0 : sstables.iterator().next().getSSTableLevel();
    return new LeveledCompactionTask(cfs, transaction, level, gcBefore, level == 0 ? Long.MAX_VALUE : getMaxSSTableBytes(), false);
}
Also used : LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 7 with LifecycleTransaction

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

the class IndexSummaryManager method getCompactingAndNonCompactingSSTables.

/**
     * Returns a Pair of all compacting and non-compacting sstables.  Non-compacting sstables will be marked as
     * compacting.
     */
@SuppressWarnings("resource")
private Pair<List<SSTableReader>, Map<TableId, LifecycleTransaction>> getCompactingAndNonCompactingSSTables() {
    List<SSTableReader> allCompacting = new ArrayList<>();
    Map<TableId, LifecycleTransaction> allNonCompacting = new HashMap<>();
    for (Keyspace ks : Keyspace.all()) {
        for (ColumnFamilyStore cfStore : ks.getColumnFamilyStores()) {
            Set<SSTableReader> nonCompacting, allSSTables;
            LifecycleTransaction txn = null;
            do {
                View view = cfStore.getTracker().getView();
                allSSTables = ImmutableSet.copyOf(view.select(SSTableSet.CANONICAL));
                nonCompacting = ImmutableSet.copyOf(view.getUncompacting(allSSTables));
            } while (null == (txn = cfStore.getTracker().tryModify(nonCompacting, OperationType.UNKNOWN)));
            allNonCompacting.put(cfStore.metadata.id, txn);
            allCompacting.addAll(Sets.difference(allSSTables, nonCompacting));
        }
    }
    return Pair.create(allCompacting, allNonCompacting);
}
Also used : TableId(org.apache.cassandra.schema.TableId) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) View(org.apache.cassandra.db.lifecycle.View)

Example 8 with LifecycleTransaction

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

the class IndexSummaryRedistribution method redistributeSummaries.

public List<SSTableReader> redistributeSummaries() throws IOException {
    logger.info("Redistributing index summaries");
    List<SSTableReader> redistribute = new ArrayList<>();
    for (LifecycleTransaction txn : transactions.values()) {
        redistribute.addAll(txn.originals());
    }
    long total = 0;
    for (SSTableReader sstable : Iterables.concat(compacting, redistribute)) total += sstable.getIndexSummaryOffHeapSize();
    logger.trace("Beginning redistribution of index summaries for {} sstables with memory pool size {} MB; current spaced used is {} MB", redistribute.size(), memoryPoolBytes / 1024L / 1024L, total / 1024.0 / 1024.0);
    final Map<SSTableReader, Double> readRates = new HashMap<>(redistribute.size());
    double totalReadsPerSec = 0.0;
    for (SSTableReader sstable : redistribute) {
        if (isStopRequested())
            throw new CompactionInterruptedException(getCompactionInfo());
        if (sstable.getReadMeter() != null) {
            Double readRate = sstable.getReadMeter().fifteenMinuteRate();
            totalReadsPerSec += readRate;
            readRates.put(sstable, readRate);
        }
    }
    logger.trace("Total reads/sec across all sstables in index summary resize process: {}", totalReadsPerSec);
    // copy and sort by read rates (ascending)
    List<SSTableReader> sstablesByHotness = new ArrayList<>(redistribute);
    Collections.sort(sstablesByHotness, new ReadRateComparator(readRates));
    long remainingBytes = memoryPoolBytes;
    for (SSTableReader sstable : compacting) remainingBytes -= sstable.getIndexSummaryOffHeapSize();
    logger.trace("Index summaries for compacting SSTables are using {} MB of space", (memoryPoolBytes - remainingBytes) / 1024.0 / 1024.0);
    List<SSTableReader> newSSTables = adjustSamplingLevels(sstablesByHotness, transactions, totalReadsPerSec, remainingBytes);
    for (LifecycleTransaction txn : transactions.values()) txn.finish();
    total = 0;
    for (SSTableReader sstable : Iterables.concat(compacting, newSSTables)) total += sstable.getIndexSummaryOffHeapSize();
    logger.trace("Completed resizing of index summaries; current approximate memory used: {}", FBUtilities.prettyPrintMemory(total));
    return newSSTables;
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) HashMap(java.util.HashMap) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) ArrayList(java.util.ArrayList) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction)

Example 9 with LifecycleTransaction

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

the class SSTableTxnWriter method create.

// log and writer closed during doPostCleanup
@SuppressWarnings("resource")
public static SSTableTxnWriter create(TableMetadataRef metadata, Descriptor descriptor, long keyCount, long repairedAt, UUID pendingRepair, int sstableLevel, SerializationHeader header, Collection<Index> indexes) {
    // if the column family store does not exist, we create a new default SSTableMultiWriter to use:
    LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.WRITE);
    MetadataCollector collector = new MetadataCollector(metadata.get().comparator).sstableLevel(sstableLevel);
    SSTableMultiWriter writer = SimpleSSTableMultiWriter.create(descriptor, keyCount, repairedAt, pendingRepair, metadata, collector, header, indexes, txn);
    return new SSTableTxnWriter(txn, writer);
}
Also used : LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector)

Example 10 with LifecycleTransaction

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

the class SSTableTxnWriter method create.

// log and writer closed during doPostCleanup
@SuppressWarnings("resource")
public static SSTableTxnWriter create(ColumnFamilyStore cfs, Descriptor descriptor, long keyCount, long repairedAt, UUID pendingRepair, int sstableLevel, SerializationHeader header) {
    LifecycleTransaction txn = LifecycleTransaction.offline(OperationType.WRITE);
    SSTableMultiWriter writer = cfs.createSSTableMultiWriter(descriptor, keyCount, repairedAt, pendingRepair, sstableLevel, header, txn);
    return new SSTableTxnWriter(txn, writer);
}
Also used : 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