Search in sources :

Example 11 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class SASIIndexBuilder method build.

public void build() {
    AbstractType<?> keyValidator = cfs.metadata().partitionKeyType;
    for (Map.Entry<SSTableReader, Map<ColumnMetadata, ColumnIndex>> e : sstables.entrySet()) {
        SSTableReader sstable = e.getKey();
        Map<ColumnMetadata, ColumnIndex> indexes = e.getValue();
        try (RandomAccessReader dataFile = sstable.openDataReader()) {
            PerSSTableIndexWriter indexWriter = SASIIndex.newWriter(keyValidator, sstable.descriptor, indexes, OperationType.COMPACTION);
            long previousKeyPosition = 0;
            try (KeyIterator keys = new KeyIterator(sstable.descriptor, cfs.metadata())) {
                while (keys.hasNext()) {
                    if (isStopRequested())
                        throw new CompactionInterruptedException(getCompactionInfo());
                    final DecoratedKey key = keys.next();
                    final long keyPosition = keys.getKeyPosition();
                    indexWriter.startPartition(key, keyPosition);
                    try {
                        RowIndexEntry indexEntry = sstable.getPosition(key, SSTableReader.Operator.EQ);
                        dataFile.seek(indexEntry.position);
                        // key
                        ByteBufferUtil.readWithShortLength(dataFile);
                        try (SSTableIdentityIterator partition = SSTableIdentityIterator.create(sstable, dataFile, key)) {
                            // if the row has statics attached, it has to be indexed separately
                            if (cfs.metadata().hasStaticColumns())
                                indexWriter.nextUnfilteredCluster(partition.staticRow());
                            while (partition.hasNext()) indexWriter.nextUnfilteredCluster(partition.next());
                        }
                    } catch (IOException ex) {
                        throw new FSReadError(ex, sstable.getFilename());
                    }
                    bytesProcessed += keyPosition - previousKeyPosition;
                    previousKeyPosition = keyPosition;
                }
                completeSSTable(indexWriter, sstable, indexes.values());
            }
        }
    }
}
Also used : ColumnMetadata(org.apache.cassandra.schema.ColumnMetadata) SSTableIdentityIterator(org.apache.cassandra.io.sstable.SSTableIdentityIterator) KeyIterator(org.apache.cassandra.io.sstable.KeyIterator) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) DecoratedKey(org.apache.cassandra.db.DecoratedKey) IOException(java.io.IOException) RowIndexEntry(org.apache.cassandra.db.RowIndexEntry) PerSSTableIndexWriter(org.apache.cassandra.index.sasi.disk.PerSSTableIndexWriter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnIndex(org.apache.cassandra.index.sasi.conf.ColumnIndex) RandomAccessReader(org.apache.cassandra.io.util.RandomAccessReader) FSReadError(org.apache.cassandra.io.FSReadError)

Example 12 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class CollatedViewIndexBuilder method build.

public void build() {
    try {
        int pageSize = cfs.indexManager.calculateIndexingPageSize();
        RegularAndStaticColumns targetPartitionColumns = extractIndexedColumns();
        while (iter.hasNext()) {
            if (isStopRequested())
                throw new CompactionInterruptedException(getCompactionInfo());
            DecoratedKey key = iter.next();
            cfs.indexManager.indexPartition(key, indexers, pageSize, targetPartitionColumns);
        }
    } finally {
        iter.close();
    }
}
Also used : CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) DecoratedKey(org.apache.cassandra.db.DecoratedKey) RegularAndStaticColumns(org.apache.cassandra.db.RegularAndStaticColumns)

Example 13 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class KeyRangeIterator method performSkipTo.

protected void performSkipTo(Long nextToken) {
    while (iterator.hasNext()) {
        DecoratedKey key = iterator.peek();
        if (Long.compare((long) key.getToken().getTokenValue(), nextToken) >= 0)
            break;
        // consume smaller key
        iterator.next();
    }
}
Also used : DecoratedKey(org.apache.cassandra.db.DecoratedKey)

Example 14 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class SkipListMemIndex method search.

@SuppressWarnings("resource")
public RangeIterator<Long, Token> search(Expression expression) {
    ByteBuffer min = expression.lower == null ? null : expression.lower.value;
    ByteBuffer max = expression.upper == null ? null : expression.upper.value;
    SortedMap<ByteBuffer, ConcurrentSkipListSet<DecoratedKey>> search;
    if (min == null && max == null) {
        throw new IllegalArgumentException();
    }
    if (min != null && max != null) {
        search = index.subMap(min, expression.lower.inclusive, max, expression.upper.inclusive);
    } else if (min == null) {
        search = index.headMap(max, expression.upper.inclusive);
    } else {
        search = index.tailMap(min, expression.lower.inclusive);
    }
    RangeUnionIterator.Builder<Long, Token> builder = RangeUnionIterator.builder();
    for (ConcurrentSkipListSet<DecoratedKey> keys : search.values()) {
        int size;
        if ((size = keys.size()) > 0)
            builder.add(new KeyRangeIterator(keys, size));
    }
    return builder.build();
}
Also used : ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) RangeUnionIterator(org.apache.cassandra.index.sasi.utils.RangeUnionIterator) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Token(org.apache.cassandra.index.sasi.disk.Token) ByteBuffer(java.nio.ByteBuffer)

Example 15 with DecoratedKey

use of org.apache.cassandra.db.DecoratedKey in project cassandra by apache.

the class ViewBuilderTask method call.

public Long call() {
    String ksName = baseCfs.metadata.keyspace;
    if (prevToken == null)
        logger.debug("Starting new view build for range {}", range);
    else
        logger.debug("Resuming view build for range {} from token {} with {} covered keys", range, prevToken, keysBuilt);
    /*
         * It's possible for view building to start before MV creation got propagated to other nodes. For this reason
         * we should wait for schema to converge before attempting to send any view mutations to other nodes, or else
         * face UnknownTableException upon Mutation deserialization on the nodes that haven't processed the schema change.
         */
    boolean schemaConverged = Gossiper.instance.waitForSchemaAgreement(10, TimeUnit.SECONDS, () -> this.isStopped);
    if (!schemaConverged)
        logger.warn("Failed to get schema to converge before building view {}.{}", baseCfs.keyspace.getName(), view.name);
    Function<org.apache.cassandra.db.lifecycle.View, Iterable<SSTableReader>> function;
    function = org.apache.cassandra.db.lifecycle.View.select(SSTableSet.CANONICAL, s -> range.intersects(s.getBounds()));
    try (ColumnFamilyStore.RefViewFragment viewFragment = baseCfs.selectAndReference(function);
        Refs<SSTableReader> sstables = viewFragment.refs;
        ReducingKeyIterator keyIter = new ReducingKeyIterator(sstables)) {
        PeekingIterator<DecoratedKey> iter = Iterators.peekingIterator(keyIter);
        while (!isStopped && iter.hasNext()) {
            DecoratedKey key = iter.next();
            Token token = key.getToken();
            // skip tokens already built or not present in range
            if (range.contains(token) && (prevToken == null || token.compareTo(prevToken) > 0)) {
                buildKey(key);
                ++keysBuilt;
                // build other keys sharing the same token
                while (iter.hasNext() && iter.peek().getToken().equals(token)) {
                    key = iter.next();
                    buildKey(key);
                    ++keysBuilt;
                }
                if (keysBuilt % ROWS_BETWEEN_CHECKPOINTS == 1)
                    SystemKeyspace.updateViewBuildStatus(ksName, view.name, range, token, keysBuilt);
                prevToken = token;
            }
        }
    }
    finish();
    return keysBuilt;
}
Also used : ReadExecutionController(org.apache.cassandra.db.ReadExecutionController) Rows(org.apache.cassandra.db.rows.Rows) ReadQuery(org.apache.cassandra.db.ReadQuery) SSTableSet(org.apache.cassandra.db.lifecycle.SSTableSet) LoggerFactory(org.slf4j.LoggerFactory) Range(org.apache.cassandra.dht.Range) Callable(java.util.concurrent.Callable) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) Global.nanoTime(org.apache.cassandra.utils.Clock.Global.nanoTime) PeekingIterator(com.google.common.collect.PeekingIterator) Iterators(com.google.common.collect.Iterators) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) Gossiper(org.apache.cassandra.gms.Gossiper) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Token(org.apache.cassandra.dht.Token) Mutation(org.apache.cassandra.db.Mutation) OperationType(org.apache.cassandra.db.compaction.OperationType) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) Objects(com.google.common.base.Objects) ReducingKeyIterator(org.apache.cassandra.io.sstable.ReducingKeyIterator) Refs(org.apache.cassandra.utils.concurrent.Refs) Unit(org.apache.cassandra.db.compaction.CompactionInfo.Unit) Function(com.google.common.base.Function) Logger(org.slf4j.Logger) FBUtilities(org.apache.cassandra.utils.FBUtilities) Iterator(java.util.Iterator) Collection(java.util.Collection) UnfilteredRowIterators(org.apache.cassandra.db.rows.UnfilteredRowIterators) UUID(java.util.UUID) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) UUIDGen(org.apache.cassandra.utils.UUIDGen) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DeletionTime(org.apache.cassandra.db.DeletionTime) StorageProxy(org.apache.cassandra.service.StorageProxy) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UnfilteredPartitionIterators(org.apache.cassandra.db.partitions.UnfilteredPartitionIterators) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) DecoratedKey(org.apache.cassandra.db.DecoratedKey) Token(org.apache.cassandra.dht.Token) ReducingKeyIterator(org.apache.cassandra.io.sstable.ReducingKeyIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Aggregations

DecoratedKey (org.apache.cassandra.db.DecoratedKey)80 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)31 Test (org.junit.Test)28 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)22 ByteBuffer (java.nio.ByteBuffer)21 TableMetadata (org.apache.cassandra.schema.TableMetadata)20 Keyspace (org.apache.cassandra.db.Keyspace)18 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)16 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)8 File (org.apache.cassandra.io.util.File)8 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 RowMutation (org.apache.cassandra.db.RowMutation)7 Table (org.apache.cassandra.db.Table)7 Row (org.apache.cassandra.db.rows.Row)7 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)7 Token (org.apache.cassandra.dht.Token)7 BufferDecoratedKey (org.apache.cassandra.db.BufferDecoratedKey)6 RowIndexEntry (org.apache.cassandra.db.RowIndexEntry)5