use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class UnfilteredPartitionIterators method mergeLazily.
public static UnfilteredPartitionIterator mergeLazily(final List<? extends UnfilteredPartitionIterator> iterators, final int nowInSec) {
assert !iterators.isEmpty();
if (iterators.size() == 1)
return iterators.get(0);
final TableMetadata metadata = iterators.get(0).metadata();
final MergeIterator<UnfilteredRowIterator, UnfilteredRowIterator> merged = MergeIterator.get(iterators, partitionComparator, new MergeIterator.Reducer<UnfilteredRowIterator, UnfilteredRowIterator>() {
private final List<UnfilteredRowIterator> toMerge = new ArrayList<>(iterators.size());
public void reduce(int idx, UnfilteredRowIterator current) {
toMerge.add(current);
}
protected UnfilteredRowIterator getReduced() {
return new LazilyInitializedUnfilteredRowIterator(toMerge.get(0).partitionKey()) {
protected UnfilteredRowIterator initializeIterator() {
return UnfilteredRowIterators.merge(toMerge, nowInSec);
}
};
}
protected void onKeyChange() {
toMerge.clear();
}
});
return new AbstractUnfilteredPartitionIterator() {
public TableMetadata metadata() {
return metadata;
}
public boolean hasNext() {
return merged.hasNext();
}
public UnfilteredRowIterator next() {
return merged.next();
}
@Override
public void close() {
merged.close();
}
};
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class RowIterators method loggingIterator.
/**
* Wraps the provided iterator so it logs the returned rows for debugging purposes.
* <p>
* Note that this is only meant for debugging as this can log a very large amount of
* logging at INFO.
*/
public static RowIterator loggingIterator(RowIterator iterator, final String id) {
TableMetadata metadata = iterator.metadata();
logger.info("[{}] Logging iterator on {}.{}, partition key={}, reversed={}", id, metadata.keyspace, metadata.name, metadata.partitionKeyType.getString(iterator.partitionKey().getKey()), iterator.isReverseOrder());
class Log extends Transformation {
@Override
public Row applyToStatic(Row row) {
if (!row.isEmpty())
logger.info("[{}] {}", id, row.toString(metadata));
return row;
}
@Override
public Row applyToRow(Row row) {
logger.info("[{}] {}", id, row.toString(metadata));
return row;
}
}
return Transformation.apply(iterator, new Log());
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class UnfilteredRowIterators method loggingIterator.
/**
* Wraps the provided iterator so it logs the returned atoms for debugging purposes.
* <p>
* Note that this is only meant for debugging as this can log a very large amount of
* logging at INFO.
*/
public static UnfilteredRowIterator loggingIterator(UnfilteredRowIterator iterator, final String id, final boolean fullDetails) {
TableMetadata metadata = iterator.metadata();
logger.info("[{}] Logging iterator on {}.{}, partition key={}, reversed={}, deletion={}", id, metadata.keyspace, metadata.name, metadata.partitionKeyType.getString(iterator.partitionKey().getKey()), iterator.isReverseOrder(), iterator.partitionLevelDeletion().markedForDeleteAt());
class Logger extends Transformation {
@Override
public Row applyToStatic(Row row) {
if (!row.isEmpty())
logger.info("[{}] {}", id, row.toString(metadata, fullDetails));
return row;
}
@Override
public Row applyToRow(Row row) {
logger.info("[{}] {}", id, row.toString(metadata, fullDetails));
return row;
}
@Override
public RangeTombstoneMarker applyToMarker(RangeTombstoneMarker marker) {
logger.info("[{}] {}", id, marker.toString(metadata));
return marker;
}
}
return Transformation.apply(iterator, new Logger());
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class OrderPreservingPartitioner method describeOwnership.
public Map<Token, Float> describeOwnership(List<Token> sortedTokens) {
// allTokens will contain the count and be returned, sorted_ranges is shorthand for token<->token math.
Map<Token, Float> allTokens = new HashMap<Token, Float>();
List<Range<Token>> sortedRanges = new ArrayList<Range<Token>>(sortedTokens.size());
// this initializes the counts to 0 and calcs the ranges in order.
Token lastToken = sortedTokens.get(sortedTokens.size() - 1);
for (Token node : sortedTokens) {
allTokens.put(node, new Float(0.0));
sortedRanges.add(new Range<Token>(lastToken, node));
lastToken = node;
}
for (String ks : Schema.instance.getKeyspaces()) {
for (TableMetadata cfmd : Schema.instance.getTablesAndViews(ks)) {
for (Range<Token> r : sortedRanges) {
// Looping over every KS:CF:Range, get the splits size and add it to the count
allTokens.put(r.right, allTokens.get(r.right) + StorageService.instance.getSplits(ks, cfmd.name, r, cfmd.params.minIndexInterval).size());
}
}
}
// Sum every count up and divide count/total for the fractional ownership.
Float total = new Float(0.0);
for (Float f : allTokens.values()) total += f;
for (Map.Entry<Token, Float> row : allTokens.entrySet()) allTokens.put(row.getKey(), row.getValue() / total);
return allTokens;
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class SASIIndex method searcherFor.
public Searcher searcherFor(ReadCommand command) throws InvalidRequestException {
TableMetadata config = command.metadata();
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(config.id);
return controller -> new QueryPlan(cfs, command, DatabaseDescriptor.getRangeRpcTimeout()).execute(controller);
}
Aggregations