Search in sources :

Example 51 with TableMetadata

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Transformation(org.apache.cassandra.db.transform.Transformation)

Example 52 with TableMetadata

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());
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) Transformation(org.apache.cassandra.db.transform.Transformation) Logger(org.slf4j.Logger)

Example 53 with TableMetadata

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;
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata)

Example 54 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) org.apache.cassandra.config(org.apache.cassandra.config) java.util(java.util) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) BiFunction(java.util.function.BiFunction) org.apache.cassandra.db(org.apache.cassandra.db) PerSSTableIndexWriter(org.apache.cassandra.index.sasi.disk.PerSSTableIndexWriter) Callable(java.util.concurrent.Callable) AbstractType(org.apache.cassandra.db.marshal.AbstractType) QueryPlan(org.apache.cassandra.index.sasi.plan.QueryPlan) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Tracker(org.apache.cassandra.db.lifecycle.Tracker) Schema(org.apache.cassandra.schema.Schema) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) Row(org.apache.cassandra.db.rows.Row) Operator(org.apache.cassandra.cql3.Operator) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) OperationType(org.apache.cassandra.db.compaction.OperationType) Pair(org.apache.cassandra.utils.Pair) Murmur3Partitioner(org.apache.cassandra.dht.Murmur3Partitioner) Descriptor(org.apache.cassandra.io.sstable.Descriptor) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) IndexMode(org.apache.cassandra.index.sasi.conf.IndexMode) Index(org.apache.cassandra.index.Index) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) ColumnIndex(org.apache.cassandra.index.sasi.conf.ColumnIndex) TargetParser(org.apache.cassandra.index.TargetParser) RowFilter(org.apache.cassandra.db.filter.RowFilter) Mode(org.apache.cassandra.index.sasi.disk.OnDiskIndexBuilder.Mode) IndexTransaction(org.apache.cassandra.index.transactions.IndexTransaction) FBUtilities(org.apache.cassandra.utils.FBUtilities) org.apache.cassandra.notifications(org.apache.cassandra.notifications) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) IndexRegistry(org.apache.cassandra.index.IndexRegistry) Iterables(com.googlecode.concurrenttrees.common.Iterables) SecondaryIndexBuilder(org.apache.cassandra.index.SecondaryIndexBuilder) SSTableFlushObserver(org.apache.cassandra.io.sstable.format.SSTableFlushObserver) TableMetadata(org.apache.cassandra.schema.TableMetadata) PartitionIterator(org.apache.cassandra.db.partitions.PartitionIterator) QueryPlan(org.apache.cassandra.index.sasi.plan.QueryPlan)

Example 55 with TableMetadata

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) PrintStream(java.io.PrintStream) Set(java.util.Set) HashSet(java.util.HashSet) Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Keyspace(org.apache.cassandra.db.Keyspace) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Descriptor(org.apache.cassandra.io.sstable.Descriptor) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

TableMetadata (org.apache.cassandra.schema.TableMetadata)129 Test (org.junit.Test)63 ByteBuffer (java.nio.ByteBuffer)29 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)17 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)13 File (java.io.File)10 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)10 Mutation (org.apache.cassandra.db.Mutation)8 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)8 KeyspaceMetadata (org.apache.cassandra.schema.KeyspaceMetadata)8 Descriptor (org.apache.cassandra.io.sstable.Descriptor)7 IndexMetadata (org.apache.cassandra.schema.IndexMetadata)6 IOException (java.io.IOException)5 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)5 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)5 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)5 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)4 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)4 AbstractType (org.apache.cassandra.db.marshal.AbstractType)4 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)4