Search in sources :

Example 1 with Transformation

use of org.apache.cassandra.db.transform.Transformation 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 2 with Transformation

use of org.apache.cassandra.db.transform.Transformation 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 3 with Transformation

use of org.apache.cassandra.db.transform.Transformation in project cassandra by apache.

the class CompositesSearcher method filterStaleEntries.

// We assume all rows in dataIter belong to the same partition.
private UnfilteredRowIterator filterStaleEntries(UnfilteredRowIterator dataIter, final ByteBuffer indexValue, final List<IndexEntry> entries, final OpOrder.Group writeOp, final int nowInSec) {
    // collect stale index entries and delete them when we close this iterator
    final List<IndexEntry> staleEntries = new ArrayList<>();
    // any index entries which would be shadowed by it
    if (!dataIter.partitionLevelDeletion().isLive()) {
        DeletionTime deletion = dataIter.partitionLevelDeletion();
        entries.forEach(e -> {
            if (deletion.deletes(e.timestamp))
                staleEntries.add(e);
        });
    }
    UnfilteredRowIterator iteratorToReturn = null;
    if (isStaticColumn()) {
        if (entries.size() != 1)
            throw new AssertionError("A partition should have at most one index within a static column index");
        iteratorToReturn = dataIter;
        if (index.isStale(dataIter.staticRow(), indexValue, nowInSec)) {
            // The entry is staled, we return no rows in this partition.
            staleEntries.addAll(entries);
            iteratorToReturn = UnfilteredRowIterators.noRowsIterator(dataIter.metadata(), dataIter.partitionKey(), Rows.EMPTY_STATIC_ROW, dataIter.partitionLevelDeletion(), dataIter.isReverseOrder());
        }
        deleteAllEntries(staleEntries, writeOp, nowInSec);
    } else {
        ClusteringComparator comparator = dataIter.metadata().comparator;
        class Transform extends Transformation {

            private int entriesIdx;

            @Override
            public Row applyToRow(Row row) {
                IndexEntry entry = findEntry(row.clustering());
                if (!index.isStale(row, indexValue, nowInSec))
                    return row;
                staleEntries.add(entry);
                return null;
            }

            private IndexEntry findEntry(Clustering clustering) {
                assert entriesIdx < entries.size();
                while (entriesIdx < entries.size()) {
                    IndexEntry entry = entries.get(entriesIdx++);
                    // The entries are in clustering order. So that the requested entry should be the
                    // next entry, the one at 'entriesIdx'. However, we can have stale entries, entries
                    // that have no corresponding row in the base table typically because of a range
                    // tombstone or partition level deletion. Delete such stale entries.
                    // For static column, we only need to compare the partition key, otherwise we compare
                    // the whole clustering.
                    int cmp = comparator.compare(entry.indexedEntryClustering, clustering);
                    // this would means entries are not in clustering order, which shouldn't happen
                    assert cmp <= 0;
                    if (cmp == 0)
                        return entry;
                    else
                        staleEntries.add(entry);
                }
                // entries correspond to the rows we've queried, so we shouldn't have a row that has no corresponding entry.
                throw new AssertionError();
            }

            @Override
            public void onPartitionClose() {
                deleteAllEntries(staleEntries, writeOp, nowInSec);
            }
        }
        iteratorToReturn = Transformation.apply(dataIter, new Transform());
    }
    return iteratorToReturn;
}
Also used : Transformation(org.apache.cassandra.db.transform.Transformation) ArrayList(java.util.ArrayList) IndexEntry(org.apache.cassandra.index.internal.IndexEntry)

Aggregations

Transformation (org.apache.cassandra.db.transform.Transformation)3 TableMetadata (org.apache.cassandra.schema.TableMetadata)2 ArrayList (java.util.ArrayList)1 IndexEntry (org.apache.cassandra.index.internal.IndexEntry)1 Logger (org.slf4j.Logger)1