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

Following code examples demonstrate how to use org.apache.cassandra.db.lifecycle.View from 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.View and various code implementation of this class.
Example 1
Project : cassandra Source File : SizeEstimatesRecorder.java View Source Code on GitHub

    @SuppressWarnings("resource")
    private void recordSizeEstimates(ColumnFamilyStore table, Collection<Range<Token>> localRanges)
    {
        List<Range<Token>> unwrappedRanges = Range.normalize(localRanges);
        Map<Range<Token>, Pair<Long, Long>> estimates = new HashMap<>(localRanges.size());
        for (Range<Token> range : unwrappedRanges)
        {
            Refs<SSTableReader> refs = null;
            long partitionsCount, meanPartitionSize;

            try
            {
                while (refs == null)
                {
                    Iterable<SSTableReader> sstables = table.getTracker().getView().select(SSTableSet.CANONICAL);
                    SSTableIntervalTree tree = SSTableIntervalTree.build(sstables);
                    Range<PartitionPosition> r = Range.makeRowRange(range);
                    Iterable<SSTableReader> canonicalSSTables = View.sstablesInBounds(r.left, r.right, tree);
                    refs = Refs.tryRef(canonicalSSTables);
                }

                partitionsCount = estimatePartitionsCount(refs, range);
                meanPartitionSize = estimateMeanPartitionSize(refs);
            }
            finally
            {
                if (refs != null)
                    refs.release();
            }

            estimates.put(range, Pair.create(partitionsCount, meanPartitionSize));
        }

        SystemKeyspace.updateSizeEstimates(table.metadata.ksName, table.metadata.cfName, estimates);
    }
			
Example 2
Project : cassandra Source File : CassandraStreamManager.java View Source Code on GitHub

    @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;
        }
    }