Search in sources :

Example 16 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class CompactionManager method validateSSTableBoundsForAnticompaction.

static void validateSSTableBoundsForAnticompaction(UUID sessionID, Collection<SSTableReader> sstables, RangesAtEndpoint ranges) {
    List<Range<Token>> normalizedRanges = Range.normalize(ranges.ranges());
    for (SSTableReader sstable : sstables) {
        Bounds<Token> bounds = new Bounds<>(sstable.first.getToken(), sstable.last.getToken());
        if (!Iterables.any(normalizedRanges, r -> (r.contains(bounds.left) && r.contains(bounds.right)) || r.intersects(bounds))) {
            // this should never happen - in PendingAntiCompaction#getSSTables we select all sstables that intersect the repaired ranges, that can't have changed here
            String message = String.format("%s SSTable %s (%s) does not intersect repaired ranges %s, this sstable should not have been included.", PreviewKind.NONE.logPrefix(sessionID), sstable, bounds, normalizedRanges);
            logger.error(message);
            throw new IllegalStateException(message);
        }
    }
}
Also used : NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) WrappedExecutorPlus(org.apache.cassandra.concurrent.WrappedExecutorPlus) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) File(org.apache.cassandra.io.util.File) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) CompactionExecutor.compactionThreadGroup(org.apache.cassandra.db.compaction.CompactionManager.CompactionExecutor.compactionThreadGroup) TabularData(javax.management.openmbean.TabularData) org.apache.cassandra.utils(org.apache.cassandra.utils) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) BooleanSupplier(java.util.function.BooleanSupplier) ExecutorFactory(org.apache.cassandra.concurrent.ExecutorFactory) Collections.singleton(java.util.Collections.singleton) NO_PENDING_REPAIR(org.apache.cassandra.service.ActiveRepairService.NO_PENDING_REPAIR) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ViewBuilderTask(org.apache.cassandra.db.view.ViewBuilderTask) com.google.common.collect(com.google.common.collect) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Predicate(java.util.function.Predicate) UNREPAIRED_SSTABLE(org.apache.cassandra.service.ActiveRepairService.UNREPAIRED_SSTABLE) TombstoneOption(org.apache.cassandra.schema.CompactionParams.TombstoneOption) Collectors(java.util.stream.Collectors) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) FileUtils(org.apache.cassandra.io.util.FileUtils) Future(org.apache.cassandra.utils.concurrent.Future) TableMetadata(org.apache.cassandra.schema.TableMetadata) StatsMetadata(org.apache.cassandra.io.sstable.metadata.StatsMetadata) ILifecycleTransaction(org.apache.cassandra.db.lifecycle.ILifecycleTransaction) FutureTask.callable(org.apache.cassandra.concurrent.FutureTask.callable) java.util(java.util) OpenDataException(javax.management.openmbean.OpenDataException) Range(org.apache.cassandra.dht.Range) Callable(java.util.concurrent.Callable) WrappedLifecycleTransaction(org.apache.cassandra.db.lifecycle.WrappedLifecycleTransaction) RateLimiter(com.google.common.util.concurrent.RateLimiter) Schema(org.apache.cassandra.schema.Schema) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) TableMetrics(org.apache.cassandra.metrics.TableMetrics) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) CompactionMetrics(org.apache.cassandra.metrics.CompactionMetrics) AbstractBounds(org.apache.cassandra.dht.AbstractBounds) Component(org.apache.cassandra.io.sstable.Component) Descriptor(org.apache.cassandra.io.sstable.Descriptor) MetadataCollector(org.apache.cassandra.io.sstable.metadata.MetadataCollector) Refs(org.apache.cassandra.utils.concurrent.Refs) ExecutorService(java.util.concurrent.ExecutorService) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) SSTableRewriter(org.apache.cassandra.io.sstable.SSTableRewriter) SecondaryIndexBuilder(org.apache.cassandra.index.SecondaryIndexBuilder) AutoSavingCache(org.apache.cassandra.cache.AutoSavingCache) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) Bounds(org.apache.cassandra.dht.Bounds) SSTableIntervalTree(org.apache.cassandra.db.lifecycle.SSTableIntervalTree) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PreviewKind(org.apache.cassandra.streaming.PreviewKind) Holder(org.apache.cassandra.db.compaction.CompactionInfo.Holder) ImmediateFuture(org.apache.cassandra.utils.concurrent.ImmediateFuture) Global.executorFactory(org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory) DatabaseDescriptor.getConcurrentCompactors(org.apache.cassandra.config.DatabaseDescriptor.getConcurrentCompactors) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IndexSummaryRedistribution(org.apache.cassandra.io.sstable.IndexSummaryRedistribution) SSTableWriter(org.apache.cassandra.io.sstable.format.SSTableWriter) View(org.apache.cassandra.db.lifecycle.View) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) AbstractBounds(org.apache.cassandra.dht.AbstractBounds) Bounds(org.apache.cassandra.dht.Bounds) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range)

Example 17 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class CompactionManager method forceUserDefinedCleanup.

public void forceUserDefinedCleanup(String dataFiles) {
    String[] filenames = dataFiles.split(",");
    HashMap<ColumnFamilyStore, Descriptor> descriptors = Maps.newHashMap();
    for (String filename : filenames) {
        // extract keyspace and columnfamily name from filename
        Descriptor desc = Descriptor.fromFilename(filename.trim());
        if (Schema.instance.getTableMetadataRef(desc) == null) {
            logger.warn("Schema does not exist for file {}. Skipping.", filename);
            continue;
        }
        // group by keyspace/columnfamily
        ColumnFamilyStore cfs = Keyspace.open(desc.ksname).getColumnFamilyStore(desc.cfname);
        desc = cfs.getDirectories().find(new File(filename.trim()).name());
        if (desc != null)
            descriptors.put(cfs, desc);
    }
    if (!StorageService.instance.isJoined()) {
        logger.error("Cleanup cannot run before a node has joined the ring");
        return;
    }
    for (Map.Entry<ColumnFamilyStore, Descriptor> entry : descriptors.entrySet()) {
        ColumnFamilyStore cfs = entry.getKey();
        Keyspace keyspace = cfs.keyspace;
        final RangesAtEndpoint replicas = StorageService.instance.getLocalReplicas(keyspace.getName());
        final Set<Range<Token>> allRanges = replicas.ranges();
        final Set<Range<Token>> transientRanges = replicas.onlyTransient().ranges();
        boolean hasIndexes = cfs.indexManager.hasIndexes();
        SSTableReader sstable = lookupSSTable(cfs, entry.getValue());
        if (sstable == null) {
            logger.warn("Will not clean {}, it is not an active sstable", entry.getValue());
        } else {
            CleanupStrategy cleanupStrategy = CleanupStrategy.get(cfs, allRanges, transientRanges, sstable.isRepaired(), FBUtilities.nowInSeconds());
            try (LifecycleTransaction txn = cfs.getTracker().tryModify(sstable, OperationType.CLEANUP)) {
                doCleanupOne(cfs, txn, cleanupStrategy, allRanges, hasIndexes);
            } catch (IOException e) {
                logger.error("forceUserDefinedCleanup failed: {}", e.getLocalizedMessage());
            }
        }
    }
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) ILifecycleTransaction(org.apache.cassandra.db.lifecycle.ILifecycleTransaction) WrappedLifecycleTransaction(org.apache.cassandra.db.lifecycle.WrappedLifecycleTransaction) IOException(java.io.IOException) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) Descriptor(org.apache.cassandra.io.sstable.Descriptor) File(org.apache.cassandra.io.util.File)

Example 18 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class LocalSessions method filterLocalRanges.

RangesAtEndpoint filterLocalRanges(String keyspace, Set<Range<Token>> ranges) {
    RangesAtEndpoint localRanges = StorageService.instance.getLocalReplicas(keyspace);
    RangesAtEndpoint.Builder builder = RangesAtEndpoint.builder(localRanges.endpoint());
    for (Range<Token> range : ranges) {
        for (Replica replica : localRanges) {
            if (replica.range().equals(range)) {
                builder.add(replica);
            } else if (replica.contains(range)) {
                builder.add(replica.decorateSubrange(range));
            }
        }
    }
    return builder.build();
}
Also used : RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Token(org.apache.cassandra.dht.Token) Replica(org.apache.cassandra.locator.Replica)

Example 19 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class CassandraStreamManager method createOutgoingStreams.

@Override
public Collection<OutgoingStream> createOutgoingStreams(StreamSession session, RangesAtEndpoint replicas, UUID pendingRepair, PreviewKind previewKind) {
    Refs<SSTableReader> refs = new Refs<>();
    try {
        final List<Range<PartitionPosition>> keyRanges = new ArrayList<>(replicas.size());
        for (Replica replica : replicas) keyRanges.add(Range.makeRowRange(replica.range()));
        refs.addAll(cfs.selectAndReference(view -> {
            Set<SSTableReader> sstables = Sets.newHashSet();
            SSTableIntervalTree intervalTree = SSTableIntervalTree.build(view.select(SSTableSet.CANONICAL));
            Predicate<SSTableReader> predicate;
            if (previewKind.isPreview()) {
                predicate = previewKind.predicate();
            } else if (pendingRepair == ActiveRepairService.NO_PENDING_REPAIR) {
                predicate = Predicates.alwaysTrue();
            } else {
                predicate = s -> s.isPendingRepair() && s.getSSTableMetadata().pendingRepair.equals(pendingRepair);
            }
            for (Range<PartitionPosition> keyRange : keyRanges) {
                // still actually selecting what we wanted.
                for (SSTableReader sstable : Iterables.filter(View.sstablesInBounds(keyRange.left, keyRange.right, intervalTree), predicate)) {
                    sstables.add(sstable);
                }
            }
            if (logger.isDebugEnabled())
                logger.debug("ViewFilter for {}/{} sstables", sstables.size(), Iterables.size(view.select(SSTableSet.CANONICAL)));
            return sstables;
        }).refs);
        List<Range<Token>> normalizedFullRanges = Range.normalize(replicas.onlyFull().ranges());
        List<Range<Token>> normalizedAllRanges = Range.normalize(replicas.ranges());
        // Create outgoing file streams for ranges possibly skipping repaired ranges in sstables
        List<OutgoingStream> streams = new ArrayList<>(refs.size());
        for (SSTableReader sstable : refs) {
            List<Range<Token>> ranges = sstable.isRepaired() ? normalizedFullRanges : normalizedAllRanges;
            List<SSTableReader.PartitionPositionBounds> sections = sstable.getPositionsForRanges(ranges);
            Ref<SSTableReader> ref = refs.get(sstable);
            if (sections.isEmpty()) {
                ref.release();
                continue;
            }
            streams.add(new CassandraOutgoingFile(session.getStreamOperation(), ref, sections, ranges, sstable.estimatedKeysForRanges(ranges)));
        }
        return streams;
    } catch (Throwable t) {
        refs.release();
        throw t;
    }
}
Also used : OutgoingStream(org.apache.cassandra.streaming.OutgoingStream) Iterables(com.google.common.collect.Iterables) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) LoggerFactory(org.slf4j.LoggerFactory) Range(org.apache.cassandra.dht.Range) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) StreamMessageHeader(org.apache.cassandra.streaming.messages.StreamMessageHeader) ArrayList(java.util.ArrayList) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) StreamSession(org.apache.cassandra.streaming.StreamSession) Predicates(com.google.common.base.Predicates) IncomingStream(org.apache.cassandra.streaming.IncomingStream) Refs(org.apache.cassandra.utils.concurrent.Refs) Ref(org.apache.cassandra.utils.concurrent.Ref) Logger(org.slf4j.Logger) StreamReceiver(org.apache.cassandra.streaming.StreamReceiver) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) SSTableIntervalTree(org.apache.cassandra.db.lifecycle.SSTableIntervalTree) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Replica(org.apache.cassandra.locator.Replica) TableStreamManager(org.apache.cassandra.streaming.TableStreamManager) PreviewKind(org.apache.cassandra.streaming.PreviewKind) List(java.util.List) PartitionPosition(org.apache.cassandra.db.PartitionPosition) Predicate(com.google.common.base.Predicate) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) View(org.apache.cassandra.db.lifecycle.View) Refs(org.apache.cassandra.utils.concurrent.Refs) ArrayList(java.util.ArrayList) Range(org.apache.cassandra.dht.Range) Replica(org.apache.cassandra.locator.Replica) OutgoingStream(org.apache.cassandra.streaming.OutgoingStream) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) PartitionPosition(org.apache.cassandra.db.PartitionPosition) SSTableIntervalTree(org.apache.cassandra.db.lifecycle.SSTableIntervalTree)

Example 20 with RangesAtEndpoint

use of org.apache.cassandra.locator.RangesAtEndpoint in project cassandra by apache.

the class RangeRelocator method calculateRangesToStreamWithEndpoints.

/**
 * calculating endpoints to stream current ranges to if needed
 * in some situations node will handle current ranges as part of the new ranges
 */
public static RangesByEndpoint calculateRangesToStreamWithEndpoints(RangesAtEndpoint streamRanges, AbstractReplicationStrategy strat, TokenMetadata tmdBefore, TokenMetadata tmdAfter) {
    RangesByEndpoint.Builder endpointRanges = new RangesByEndpoint.Builder();
    for (Replica toStream : streamRanges) {
        // If the range we are sending is full only send it to the new full replica
        // There will also be a new transient replica we need to send the data to, but not
        // the repaired data
        EndpointsForRange oldEndpoints = strat.calculateNaturalReplicas(toStream.range().right, tmdBefore);
        EndpointsForRange newEndpoints = strat.calculateNaturalReplicas(toStream.range().right, tmdAfter);
        logger.debug("Need to stream {}, current endpoints {}, new endpoints {}", toStream, oldEndpoints, newEndpoints);
        for (Replica newEndpoint : newEndpoints) {
            Replica oldEndpoint = oldEndpoints.byEndpoint().get(newEndpoint.endpoint());
            // Nothing to do
            if (newEndpoint.equals(oldEndpoint))
                continue;
            // Completely new range for this endpoint
            if (oldEndpoint == null) {
                if (toStream.isTransient() && newEndpoint.isFull())
                    throw new AssertionError(String.format("Need to stream %s, but only have %s which is transient and not full", newEndpoint, toStream));
                for (Range<Token> intersection : newEndpoint.range().intersectionWith(toStream.range())) {
                    endpointRanges.put(newEndpoint.endpoint(), newEndpoint.decorateSubrange(intersection));
                }
            } else {
                Set<Range<Token>> subsToStream = Collections.singleton(toStream.range());
                // First subtract what we already have
                if (oldEndpoint.isFull() == newEndpoint.isFull() || oldEndpoint.isFull())
                    subsToStream = toStream.range().subtract(oldEndpoint.range());
                // Now we only stream what is still replicated
                subsToStream.stream().flatMap(range -> range.intersectionWith(newEndpoint.range()).stream()).forEach(tokenRange -> endpointRanges.put(newEndpoint.endpoint(), newEndpoint.decorateSubrange(tokenRange)));
            }
        }
    }
    return endpointRanges.build();
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Range(org.apache.cassandra.dht.Range) Multimap(com.google.common.collect.Multimap) Future(java.util.concurrent.Future) Token(org.apache.cassandra.dht.Token) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Pair(org.apache.cassandra.utils.Pair) RangeStreamer(org.apache.cassandra.dht.RangeStreamer) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) StreamOperation(org.apache.cassandra.streaming.StreamOperation) Keyspace(org.apache.cassandra.db.Keyspace) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Logger(org.slf4j.Logger) FBUtilities(org.apache.cassandra.utils.FBUtilities) Collection(java.util.Collection) Set(java.util.Set) RangesByEndpoint(org.apache.cassandra.locator.RangesByEndpoint) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) Replica(org.apache.cassandra.locator.Replica) StreamState(org.apache.cassandra.streaming.StreamState) List(java.util.List) AbstractReplicationStrategy(org.apache.cassandra.locator.AbstractReplicationStrategy) StreamPlan(org.apache.cassandra.streaming.StreamPlan) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FailureDetector(org.apache.cassandra.gms.FailureDetector) Collections(java.util.Collections) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Token(org.apache.cassandra.dht.Token) Range(org.apache.cassandra.dht.Range) EndpointsForRange(org.apache.cassandra.locator.EndpointsForRange) Replica(org.apache.cassandra.locator.Replica) EndpointsByReplica(org.apache.cassandra.locator.EndpointsByReplica) RangesByEndpoint(org.apache.cassandra.locator.RangesByEndpoint)

Aggregations

RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)32 Token (org.apache.cassandra.dht.Token)22 Range (org.apache.cassandra.dht.Range)20 Replica (org.apache.cassandra.locator.Replica)17 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)10 EndpointsByReplica (org.apache.cassandra.locator.EndpointsByReplica)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Test (org.junit.Test)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 Collection (java.util.Collection)8 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)8 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Set (java.util.Set)7 UUID (java.util.UUID)7 Replica.fullReplica (org.apache.cassandra.locator.Replica.fullReplica)7 IOException (java.io.IOException)6 Replica.transientReplica (org.apache.cassandra.locator.Replica.transientReplica)6