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