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());
}
}
}
}
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();
}
}
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();
}
}
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();
}
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;
}
Aggregations