Search in sources :

Example 1 with AlwaysPresentFilter

use of org.apache.cassandra.utils.AlwaysPresentFilter in project cassandra by apache.

the class CompactionController method getPurgeEvaluator.

/**
     * @param key
     * @return a predicate for whether tombstones marked for deletion at the given time for the given partition are
     * purgeable; we calculate this by checking whether the deletion time is less than the min timestamp of all SSTables
     * containing his partition and not participating in the compaction. This means there isn't any data in those
     * sstables that might still need to be suppressed by a tombstone at this timestamp.
     */
public Predicate<Long> getPurgeEvaluator(DecoratedKey key) {
    if (NEVER_PURGE_TOMBSTONES || !compactingRepaired())
        return time -> false;
    overlapIterator.update(key);
    Set<SSTableReader> filteredSSTables = overlapIterator.overlaps();
    Iterable<Memtable> memtables = cfs.getTracker().getView().getAllMemtables();
    long minTimestampSeen = Long.MAX_VALUE;
    boolean hasTimestamp = false;
    for (SSTableReader sstable : filteredSSTables) {
        // we check index file instead.
        if (sstable.getBloomFilter() instanceof AlwaysPresentFilter && sstable.getPosition(key, SSTableReader.Operator.EQ, false) != null || sstable.getBloomFilter().isPresent(key)) {
            minTimestampSeen = Math.min(minTimestampSeen, sstable.getMinTimestamp());
            hasTimestamp = true;
        }
    }
    for (Memtable memtable : memtables) {
        Partition partition = memtable.getPartition(key);
        if (partition != null) {
            minTimestampSeen = Math.min(minTimestampSeen, partition.stats().minTimestamp);
            hasTimestamp = true;
        }
    }
    if (!hasTimestamp)
        return time -> true;
    else {
        final long finalTimestamp = minTimestampSeen;
        return time -> time < finalTimestamp;
    }
}
Also used : java.util(java.util) Iterables(com.google.common.collect.Iterables) Logger(org.slf4j.Logger) OverlapIterator(org.apache.cassandra.utils.OverlapIterator) Predicate(java.util.function.Predicate) TombstoneOption(org.apache.cassandra.schema.CompactionParams.TombstoneOption) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) RateLimiter(com.google.common.util.concurrent.RateLimiter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Partition(org.apache.cassandra.db.partitions.Partition) FileDataInput(org.apache.cassandra.io.util.FileDataInput) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) FileUtils(org.apache.cassandra.io.util.FileUtils) SSTableIntervalTree.buildIntervals(org.apache.cassandra.db.lifecycle.SSTableIntervalTree.buildIntervals) Memtable(org.apache.cassandra.db.Memtable) Predicates(com.google.common.base.Predicates) Refs(org.apache.cassandra.utils.concurrent.Refs) AlwaysPresentFilter(org.apache.cassandra.utils.AlwaysPresentFilter) Partition(org.apache.cassandra.db.partitions.Partition) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) AlwaysPresentFilter(org.apache.cassandra.utils.AlwaysPresentFilter) Memtable(org.apache.cassandra.db.Memtable)

Example 2 with AlwaysPresentFilter

use of org.apache.cassandra.utils.AlwaysPresentFilter in project cassandra by apache.

the class LogTransactionTest method sstable.

private static SSTableReader sstable(File dataFolder, ColumnFamilyStore cfs, int generation, int size) throws IOException {
    Descriptor descriptor = new Descriptor(dataFolder, cfs.keyspace.getName(), cfs.getTableName(), generation, SSTableFormat.Type.BIG);
    Set<Component> components = ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.TOC);
    for (Component component : components) {
        File file = new File(descriptor.filenameFor(component));
        if (!file.exists())
            assertTrue(file.createNewFile());
        try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
            raf.setLength(size);
        }
    }
    FileHandle dFile = new FileHandle.Builder(descriptor.filenameFor(Component.DATA)).complete();
    FileHandle iFile = new FileHandle.Builder(descriptor.filenameFor(Component.PRIMARY_INDEX)).complete();
    SerializationHeader header = SerializationHeader.make(cfs.metadata(), Collections.emptyList());
    StatsMetadata metadata = (StatsMetadata) new MetadataCollector(cfs.metadata().comparator).finalizeMetadata(cfs.metadata().partitioner.getClass().getCanonicalName(), 0.01f, -1, null, header).get(MetadataType.STATS);
    SSTableReader reader = SSTableReader.internalOpen(descriptor, components, cfs.metadata, dFile, iFile, MockSchema.indexSummary.sharedCopy(), new AlwaysPresentFilter(), 1L, metadata, SSTableReader.OpenReason.NORMAL, header);
    reader.first = reader.last = MockSchema.readerBounds(generation);
    return reader;
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) AlwaysPresentFilter(org.apache.cassandra.utils.AlwaysPresentFilter) RandomAccessFile(java.io.RandomAccessFile) SerializationHeader(org.apache.cassandra.db.SerializationHeader) FileHandle(org.apache.cassandra.io.util.FileHandle) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 3 with AlwaysPresentFilter

use of org.apache.cassandra.utils.AlwaysPresentFilter in project cassandra by apache.

the class MockSchema method sstable.

public static SSTableReader sstable(int generation, int size, boolean keepRef, ColumnFamilyStore cfs) {
    Descriptor descriptor = new Descriptor(cfs.getDirectories().getDirectoryForNewSSTables(), cfs.keyspace.getName(), cfs.getTableName(), generation, SSTableFormat.Type.BIG);
    Set<Component> components = ImmutableSet.of(Component.DATA, Component.PRIMARY_INDEX, Component.FILTER, Component.TOC);
    for (Component component : components) {
        File file = new File(descriptor.filenameFor(component));
        try {
            file.createNewFile();
        } catch (IOException e) {
        }
    }
    if (size > 0) {
        try {
            File file = new File(descriptor.filenameFor(Component.DATA));
            try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
                raf.setLength(size);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    SerializationHeader header = SerializationHeader.make(cfs.metadata(), Collections.emptyList());
    StatsMetadata metadata = (StatsMetadata) new MetadataCollector(cfs.metadata().comparator).finalizeMetadata(cfs.metadata().partitioner.getClass().getCanonicalName(), 0.01f, -1, null, header).get(MetadataType.STATS);
    SSTableReader reader = SSTableReader.internalOpen(descriptor, components, cfs.metadata, RANDOM_ACCESS_READER_FACTORY.sharedCopy(), RANDOM_ACCESS_READER_FACTORY.sharedCopy(), indexSummary.sharedCopy(), new AlwaysPresentFilter(), 1L, metadata, SSTableReader.OpenReason.NORMAL, header);
    reader.first = reader.last = readerBounds(generation);
    if (!keepRef)
        reader.selfRef().release();
    return reader;
}
Also used : StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) AlwaysPresentFilter(org.apache.cassandra.utils.AlwaysPresentFilter) RandomAccessFile(java.io.RandomAccessFile) Descriptor(org.apache.cassandra.io.sstable.Descriptor) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) IOException(java.io.IOException) Component(org.apache.cassandra.io.sstable.Component) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 AlwaysPresentFilter (org.apache.cassandra.utils.AlwaysPresentFilter)3 File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 MetadataCollector (org.apache.cassandra.io.sstable.metadata.MetadataCollector)2 StatsMetadata (org.apache.cassandra.io.sstable.metadata.StatsMetadata)2 Predicates (com.google.common.base.Predicates)1 Iterables (com.google.common.collect.Iterables)1 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 IOException (java.io.IOException)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 org.apache.cassandra.db (org.apache.cassandra.db)1 Memtable (org.apache.cassandra.db.Memtable)1 SerializationHeader (org.apache.cassandra.db.SerializationHeader)1 SSTableIntervalTree.buildIntervals (org.apache.cassandra.db.lifecycle.SSTableIntervalTree.buildIntervals)1 Partition (org.apache.cassandra.db.partitions.Partition)1 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)1 Component (org.apache.cassandra.io.sstable.Component)1