Search in sources :

Example 1 with SinglePartitionPager

use of org.apache.cassandra.service.pager.SinglePartitionPager in project cassandra by apache.

the class SecondaryIndexManager method indexPartition.

/**
     * When building an index against existing data in sstables, add the given partition to the index
     */
public void indexPartition(DecoratedKey key, Set<Index> indexes, int pageSize) {
    if (logger.isTraceEnabled())
        logger.trace("Indexing partition {}", baseCfs.metadata().partitionKeyType.getString(key.getKey()));
    if (!indexes.isEmpty()) {
        SinglePartitionReadCommand cmd = SinglePartitionReadCommand.fullPartitionRead(baseCfs.metadata(), FBUtilities.nowInSeconds(), key);
        int nowInSec = cmd.nowInSec();
        boolean readStatic = false;
        SinglePartitionPager pager = new SinglePartitionPager(cmd, null, ProtocolVersion.CURRENT);
        while (!pager.isExhausted()) {
            try (ReadExecutionController controller = cmd.executionController();
                OpOrder.Group writeGroup = Keyspace.writeOrder.start();
                UnfilteredPartitionIterator page = pager.fetchPageUnfiltered(baseCfs.metadata(), pageSize, controller)) {
                if (!page.hasNext())
                    break;
                try (UnfilteredRowIterator partition = page.next()) {
                    Set<Index.Indexer> indexers = indexes.stream().map(index -> index.indexerFor(key, partition.columns(), nowInSec, writeGroup, IndexTransaction.Type.UPDATE)).filter(Objects::nonNull).collect(Collectors.toSet());
                    // Short-circuit empty partitions if static row is processed or isn't read
                    if (!readStatic && partition.isEmpty() && partition.staticRow().isEmpty())
                        break;
                    indexers.forEach(Index.Indexer::begin);
                    if (!readStatic) {
                        if (!partition.staticRow().isEmpty())
                            indexers.forEach(indexer -> indexer.insertRow(partition.staticRow()));
                        indexers.forEach((Index.Indexer i) -> i.partitionDelete(partition.partitionLevelDeletion()));
                        readStatic = true;
                    }
                    MutableDeletionInfo.Builder deletionBuilder = MutableDeletionInfo.builder(partition.partitionLevelDeletion(), baseCfs.getComparator(), false);
                    while (partition.hasNext()) {
                        Unfiltered unfilteredRow = partition.next();
                        if (unfilteredRow.isRow()) {
                            Row row = (Row) unfilteredRow;
                            indexers.forEach(indexer -> indexer.insertRow(row));
                        } else {
                            assert unfilteredRow.isRangeTombstoneMarker();
                            RangeTombstoneMarker marker = (RangeTombstoneMarker) unfilteredRow;
                            deletionBuilder.add(marker);
                        }
                    }
                    MutableDeletionInfo deletionInfo = deletionBuilder.build();
                    if (deletionInfo.hasRanges()) {
                        Iterator<RangeTombstone> iter = deletionInfo.rangeIterator(false);
                        while (iter.hasNext()) indexers.forEach(indexer -> indexer.rangeTombstone(iter.next()));
                    }
                    indexers.forEach(Index.Indexer::finish);
                }
            }
        }
    }
}
Also used : java.util(java.util) Iterables(com.google.common.collect.Iterables) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) JMXEnabledThreadPoolExecutor(org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) LoggerFactory(org.slf4j.LoggerFactory) org.apache.cassandra.db(org.apache.cassandra.db) Constructor(java.lang.reflect.Constructor) Function(java.util.function.Function) StringUtils(org.apache.commons.lang3.StringUtils) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Indexes(org.apache.cassandra.schema.Indexes) org.apache.cassandra.db.rows(org.apache.cassandra.db.rows) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder) Strings(com.google.common.base.Strings) org.apache.cassandra.index.transactions(org.apache.cassandra.index.transactions) IndexTarget(org.apache.cassandra.cql3.statements.IndexTarget) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Refs(org.apache.cassandra.utils.concurrent.Refs) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) org.apache.cassandra.db.partitions(org.apache.cassandra.db.partitions) Longs(com.google.common.primitives.Longs) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) RowFilter(org.apache.cassandra.db.filter.RowFilter) FBUtilities(org.apache.cassandra.utils.FBUtilities) IndexMetadata(org.apache.cassandra.schema.IndexMetadata) java.util.concurrent(java.util.concurrent) Tracing(org.apache.cassandra.tracing.Tracing) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) Futures(com.google.common.util.concurrent.Futures) NamedThreadFactory(org.apache.cassandra.concurrent.NamedThreadFactory) CassandraIndex(org.apache.cassandra.index.internal.CassandraIndex) Stream(java.util.stream.Stream) SinglePartitionPager(org.apache.cassandra.service.pager.SinglePartitionPager) StageManager(org.apache.cassandra.concurrent.StageManager) Joiner(com.google.common.base.Joiner) View(org.apache.cassandra.db.lifecycle.View) SinglePartitionPager(org.apache.cassandra.service.pager.SinglePartitionPager) OpOrder(org.apache.cassandra.utils.concurrent.OpOrder)

Aggregations

Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Longs (com.google.common.primitives.Longs)1 Futures (com.google.common.util.concurrent.Futures)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 Constructor (java.lang.reflect.Constructor)1 java.util (java.util)1 java.util.concurrent (java.util.concurrent)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 JMXEnabledThreadPoolExecutor (org.apache.cassandra.concurrent.JMXEnabledThreadPoolExecutor)1 NamedThreadFactory (org.apache.cassandra.concurrent.NamedThreadFactory)1 StageManager (org.apache.cassandra.concurrent.StageManager)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 IndexTarget (org.apache.cassandra.cql3.statements.IndexTarget)1