use of org.apache.cassandra.db.lifecycle.SSTableIntervalTree in project cassandra by apache.
the class CompactionManager method sstablesInBounds.
private static Collection<SSTableReader> sstablesInBounds(ColumnFamilyStore cfs, Collection<Range<Token>> tokenRangeCollection) {
final Set<SSTableReader> sstables = new HashSet<>();
Iterable<SSTableReader> liveTables = cfs.getTracker().getView().select(SSTableSet.LIVE);
SSTableIntervalTree tree = SSTableIntervalTree.build(liveTables);
for (Range<Token> tokenRange : tokenRangeCollection) {
Iterable<SSTableReader> ssTableReaders = View.sstablesInBounds(tokenRange.left.minKeyBound(), tokenRange.right.maxKeyBound(), tree);
Iterables.addAll(sstables, ssTableReaders);
}
return sstables;
}
use of org.apache.cassandra.db.lifecycle.SSTableIntervalTree in project cassandra by apache.
the class StreamSession method getSSTableSectionsForRanges.
@VisibleForTesting
public static List<SSTableStreamingSections> getSSTableSectionsForRanges(Collection<Range<Token>> ranges, Collection<ColumnFamilyStore> stores, long overriddenRepairedAt, UUID pendingRepair) {
Refs<SSTableReader> refs = new Refs<>();
try {
for (ColumnFamilyStore cfStore : stores) {
final List<Range<PartitionPosition>> keyRanges = new ArrayList<>(ranges.size());
for (Range<Token> range : ranges) keyRanges.add(Range.makeRowRange(range));
refs.addAll(cfStore.selectAndReference(view -> {
Set<SSTableReader> sstables = Sets.newHashSet();
SSTableIntervalTree intervalTree = SSTableIntervalTree.build(view.select(SSTableSet.CANONICAL));
Predicate<SSTableReader> predicate;
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<SSTableStreamingSections> sections = new ArrayList<>(refs.size());
for (SSTableReader sstable : refs) {
long repairedAt = overriddenRepairedAt;
if (overriddenRepairedAt == ActiveRepairService.UNREPAIRED_SSTABLE)
repairedAt = sstable.getSSTableMetadata().repairedAt;
sections.add(new SSTableStreamingSections(refs.get(sstable), sstable.getPositionsForRanges(ranges), sstable.estimatedKeysForRanges(ranges), repairedAt));
}
return sections;
} catch (Throwable t) {
refs.release();
throw t;
}
}
use of org.apache.cassandra.db.lifecycle.SSTableIntervalTree in project cassandra by apache.
the class SizeEstimatesRecorder method recordSizeEstimates.
@SuppressWarnings("resource")
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> localRange : localRanges) {
for (Range<Token> unwrappedRange : localRange.unwrap()) {
// filter sstables that have partitions in this range.
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(unwrappedRange);
Iterable<SSTableReader> canonicalSSTables = View.sstablesInBounds(r.left, r.right, tree);
refs = Refs.tryRef(canonicalSSTables);
}
// calculate the estimates.
partitionsCount = estimatePartitionsCount(refs, unwrappedRange);
meanPartitionSize = estimateMeanPartitionSize(refs);
} finally {
if (refs != null)
refs.release();
}
estimates.put(unwrappedRange, Pair.create(partitionsCount, meanPartitionSize));
}
}
// atomically update the estimates.
SystemKeyspace.updateSizeEstimates(table.metadata.keyspace, table.metadata.name, estimates);
}
Aggregations