public static DataRange forKeyRange(Range<Token> keyRange) { return new DataRange(keyRange.toRowBounds(), new IdentityQueryFilter()); }
/** * @param sstable SSTable to scan; must not be null * @param tokenRanges A set of token ranges to scan * @param limiter background i/o RateLimiter; may be null */ private SSTableScanner(SSTableReader sstable, Collection<Range<Token>> tokenRanges, RateLimiter limiter) { assert sstable != null; this.dfile = limiter == null ? sstable.openDataReader() : sstable.openDataReader(limiter); this.ifile = sstable.openIndexReader(); this.sstable = sstable; this.dataRange = null; List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(tokenRanges.size()); for (Range<Token> range : Range.normalize(tokenRanges)) addRange(range.toRowBounds(), boundsList); this.rangeIterator = boundsList.iterator(); }
private void recordSizeEstimates(ColumnFamilyStore table, Collection<Range<Token>> localRanges) { // for each local primary range, estimate (crudely) mean partition size and partitions count. Map<Range<Token>, Pair<Long, Long>> estimates = new HashMap<>(localRanges.size()); for (Range<Token> range : localRanges) { // filter sstables that have partitions in this range. Refs<SSTableReader> refs = null; while (refs == null) { ColumnFamilyStore.ViewFragment view = table.select(table.viewFilter(range.toRowBounds())); refs = Refs.tryRef(view.sstables); } long partitionsCount, meanPartitionSize; try { // calculate the estimates. partitionsCount = estimatePartitionsCount(refs, range); meanPartitionSize = estimateMeanPartitionSize(refs); } finally { refs.release(); } estimates.put(range, Pair.create(partitionsCount, meanPartitionSize)); } // atomically update the estimates. SystemKeyspace.updateSizeEstimates(table.metadata.ksName, table.metadata.cfName, estimates); }
final IPartitioner partitioner = cfStore.partitioner; for (Range<Token> range : ranges) rowBoundsList.add(range.toRowBounds()); refs.addAll(cfStore.selectAndReference(new Function<DataTracker.View, List<SSTableReader>>()
/** * Determine the minimal set of sections that can be extracted from this SSTable to cover the given ranges. * @return A sorted list of (offset,end) pairs that cover the given ranges in the datafile for this SSTable. */ public List<Pair<Long,Long>> getPositionsForRanges(Collection<Range<Token>> ranges) { // use the index to determine a minimal section for each range List<Pair<Long,Long>> positions = new ArrayList<>(); for (Range<Token> range : Range.normalize(ranges)) { assert !range.isWrapAround() || range.right.isMinimum(); // truncate the range so it at most covers the sstable AbstractBounds<RowPosition> bounds = range.toRowBounds(); RowPosition leftBound = bounds.left.compareTo(first) > 0 ? bounds.left : first.getToken().minKeyBound(); RowPosition rightBound = bounds.right.isMinimum() ? last.getToken().maxKeyBound() : bounds.right; if (leftBound.compareTo(last) > 0 || rightBound.compareTo(first) < 0) continue; long left = getPosition(leftBound, Operator.GT).position; long right = (rightBound.compareTo(last) > 0) ? uncompressedLength() : getPosition(rightBound, Operator.GT).position; if (left == right) // empty range continue; assert left < right : String.format("Range=%s openReason=%s first=%s last=%s left=%d right=%d", range, openReason, first, last, left, right); positions.add(Pair.create(left, right)); } return positions; }