Java Code Examples for org.apache.cassandra.db.lifecycle.View

Following code examples demonstrate how to use org.apache.cassandra.db.lifecycle.Viewfrom cassandra. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.cassandra.db.lifecycle.Viewand various code implementation of this class.

    @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 = getPreviewPredicate(previewKind);
                }
                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)
                {
                    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());
            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;
        }
    } 


Advertisement
Javadoc
An immutable structure holding the current memtable, the memtables pending flush, the sstables for a

column family, and the sstables that are active in compaction (a subset of the sstables). Modifications to instances are all performed via a Function produced by the static methods in this class. These are composed as necessary and provided to the Tracker.apply() methods, which atomically reject or accept and apply the changes to the View.

Read More
Advertisement