jasonstack commented on code in PR #3649:
URL: https://github.com/apache/cassandra/pull/3649#discussion_r1833637087
##########
src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java:
##########
@@ -164,33 +183,75 @@ public UnfilteredRowIterator computeNext()
// saying this iterator must not return the same partition twice.
skipToNextPartition();
- UnfilteredRowIterator iterator =
nextRowIterator(this::nextSelectedKeyInRange);
- return iterator != null
- ? iteratePartition(iterator)
- : endOfData();
+ UnfilteredRowIterator iterator =
nextRowIterator(this::nextSelectedKeysInRange);
+ return iterator != null ? iteratePartition(iterator) : endOfData();
}
/**
- * Tries to obtain a row iterator for one of the supplied keys by
repeatedly calling
+ * Tries to obtain a row iterator for the supplied keys by repeatedly
calling
* {@link ResultRetriever#queryStorageAndFilter} until it gives a
non-null result.
- * The keySupplier should return the next key with every call to get()
and
- * null when there are no more keys to try.
+ * The keysSupplier should return the next batch of keys with every
call to get()
+ * and null when there are no more keys to try.
*
* @return an iterator or null if all keys were tried with no success
*/
- private @Nullable UnfilteredRowIterator nextRowIterator(@Nonnull
Supplier<PrimaryKey> keySupplier)
+ private @Nullable UnfilteredRowIterator nextRowIterator(@Nonnull
Supplier<List<PrimaryKey>> keysSupplier)
{
UnfilteredRowIterator iterator = null;
while (iterator == null)
{
- PrimaryKey key = keySupplier.get();
- if (key == null)
+ List<PrimaryKey> keys = keysSupplier.get();
+ if (keys.isEmpty())
return null;
- iterator = queryStorageAndFilter(key);
+ iterator = queryStorageAndFilter(keys);
}
return iterator;
}
+ /**
+ * Retrieves the next batch of primary keys (i.e. up to {@link
#partitionRowBatchSize} of them) that are
+ * contained by one of the query key ranges and selected by the {@link
QueryController}. If the next key falls
+ * out of the current key range, it skips to the next key range, and
so on. If no more keys accepted by
+ * the controller are available, and empty list is returned.
+ *
+ * @return a list of up to {@link #partitionRowBatchSize} primary keys
+ */
+ private List<PrimaryKey> nextSelectedKeysInRange()
+ {
+ List<PrimaryKey> threadLocalNextKeys = nextKeys.get();
+ threadLocalNextKeys.clear();
+ PrimaryKey firstKey;
+
+ do
+ {
+ firstKey = nextKeyInRange();
+
+ if (firstKey == null)
+ return Collections.emptyList();
+ }
+ while (queryController.doesNotSelect(firstKey) ||
firstKey.equals(lastKey));
+
+ lastKey = firstKey;
+ threadLocalNextKeys.add(firstKey);
+ fillNextSelectedKeysInPartition(firstKey.partitionKey(),
threadLocalNextKeys);
Review Comment:
nice!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]