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);
}
use of org.apache.cassandra.schema.TableMetadata in project cassandra by apache.
the class SSTableExpiredBlockers method main.
public static void main(String[] args) {
PrintStream out = System.out;
if (args.length < 2) {
out.println("Usage: sstableexpiredblockers <keyspace> <table>");
System.exit(1);
}
Util.initDatabaseDescriptor();
String keyspace = args[args.length - 2];
String columnfamily = args[args.length - 1];
Schema.instance.loadFromDisk(false);
TableMetadata metadata = Schema.instance.validateTable(keyspace, columnfamily);
Keyspace ks = Keyspace.openWithoutSSTables(keyspace);
ColumnFamilyStore cfs = ks.getColumnFamilyStore(columnfamily);
Directories.SSTableLister lister = cfs.getDirectories().sstableLister(Directories.OnTxnErr.THROW).skipTemporary(true);
Set<SSTableReader> sstables = new HashSet<>();
for (Map.Entry<Descriptor, Set<Component>> sstable : lister.list().entrySet()) {
if (sstable.getKey() != null) {
try {
SSTableReader reader = SSTableReader.open(sstable.getKey());
sstables.add(reader);
} catch (Throwable t) {
out.println("Couldn't open sstable: " + sstable.getKey().filenameFor(Component.DATA) + " (" + t.getMessage() + ")");
}
}
}
if (sstables.isEmpty()) {
out.println("No sstables for " + keyspace + "." + columnfamily);
System.exit(1);
}
int gcBefore = (int) (System.currentTimeMillis() / 1000) - metadata.params.gcGraceSeconds;
Multimap<SSTableReader, SSTableReader> blockers = checkForExpiredSSTableBlockers(sstables, gcBefore);
for (SSTableReader blocker : blockers.keySet()) {
out.println(String.format("%s blocks %d expired sstables from getting dropped: %s%n", formatForExpiryTracing(Collections.singleton(blocker)), blockers.get(blocker).size(), formatForExpiryTracing(blockers.get(blocker))));
}
System.exit(0);
}
Aggregations