michaeljmarshall commented on code in PR #4353:
URL: https://github.com/apache/cassandra/pull/4353#discussion_r2683420733


##########
src/java/org/apache/cassandra/index/sai/plan/StorageAttachedIndexSearcher.java:
##########
@@ -120,24 +132,45 @@ public PartitionIterator 
filterReplicaFilteringProtection(PartitionIterator full
     public UnfilteredPartitionIterator search(ReadExecutionController 
executionController) throws RequestTimeoutException
     {
         if (!command.isTopK())
+        {
             return new ResultRetriever(executionController, false);
+        }
         else
         {
-            Supplier<ResultRetriever> resultSupplier = () -> new 
ResultRetriever(executionController, true);
-
-            // VSTODO performance: if there is shadowed primary keys, we have 
to at least query twice.
-            //  First time to find out there are shadow keys, second time to 
find out there are no more shadow keys.
-            while (true)
+            // Need a consistent view of the memtables/sstables and their 
associated index, so we get the view now
+            // and propagate it as needed.
+            QueryViewBuilder.QueryView queryView = buildAnnQueryView();
+            try
+            {
+                queryController.maybeTriggerGuardrails(queryView);
+                ScoreOrderedResultRetriever result = new 
ScoreOrderedResultRetriever(queryController, executionController, queryContext, 
queryView, command.limits().count());
+                return (UnfilteredPartitionIterator) new 
VectorTopKProcessor(command).takeTopKThenSortByPrimaryKey(result);
+            }
+            finally
             {
-                long lastShadowedKeysCount = 
queryContext.vectorContext().getShadowedPrimaryKeys().size();
-                ResultRetriever result = resultSupplier.get();
-                UnfilteredPartitionIterator topK = 
(UnfilteredPartitionIterator) new VectorTopKProcessor(command).filter(result);
+                
queryView.referencedIndexes.forEach(SSTableIndex::releaseQuietly);

Review Comment:
   I'll add a comment and make the `QueryView` implement `AutoCloseable` so we 
can just do try-with-resources here.



-- 
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]

Reply via email to