Search in sources :

Example 11 with TableMetadata

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

Example 12 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 13 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 14 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 15 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)

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