maedhroz commented on code in PR #3194:
URL: https://github.com/apache/cassandra/pull/3194#discussion_r1542043293
##########
src/java/org/apache/cassandra/index/sai/iterators/KeyRangeConcatIterator.java:
##########
@@ -18,84 +18,78 @@
package org.apache.cassandra.index.sai.iterators;
import java.util.ArrayList;
-import java.util.Comparator;
+import java.util.Iterator;
import java.util.List;
-import java.util.PriorityQueue;
import com.google.common.annotations.VisibleForTesting;
import org.apache.cassandra.index.sai.utils.PrimaryKey;
import org.apache.cassandra.io.util.FileUtils;
/**
- * {@link KeyRangeConcatIterator} takes a list of sorted range iterator and
concatenates them, leaving duplicates in
+ * {@link KeyRangeConcatIterator} takes a list of sorted range iterators and
concatenates them, leaving duplicates in
* place, to produce a new stably sorted iterator. Duplicates are eliminated
later in
* {@link org.apache.cassandra.index.sai.plan.StorageAttachedIndexSearcher}
* as results from multiple SSTable indexes and their respective segments are
consumed.
- *
+ * <p>
* ex. (1, 2, 3) + (3, 3, 4, 5) -> (1, 2, 3, 3, 3, 4, 5)
* ex. (1, 2, 2, 3) + (3, 4, 4, 6, 6, 7) -> (1, 2, 2, 3, 3, 4, 4, 6, 6, 7)
- *
- * TODO Investigate removing the use of PriorityQueue from this class <a
href="https://issues.apache.org/jira/browse/CASSANDRA-18165">CASSANDRA-18165</a>
*/
public class KeyRangeConcatIterator extends KeyRangeIterator
{
public static final String MUST_BE_SORTED_ERROR = "RangeIterator must be
sorted, previous max: %s, next min: %s";
- private final PriorityQueue<KeyRangeIterator> ranges;
+ private final Iterator<KeyRangeIterator> ranges;
+ private KeyRangeIterator currentRange;
private final List<KeyRangeIterator> toRelease;
- protected KeyRangeConcatIterator(KeyRangeIterator.Builder.Statistics
statistics, PriorityQueue<KeyRangeIterator> ranges)
+ protected KeyRangeConcatIterator(KeyRangeIterator.Builder.Statistics
statistics, List<KeyRangeIterator> ranges)
{
super(statistics);
- this.ranges = ranges;
+ if (ranges.isEmpty())
+ throw new IllegalArgumentException("Cannot concatenate empty list
of ranges");
+
+ this.ranges = ranges.iterator();
+ this.currentRange = this.ranges.next();
this.toRelease = new ArrayList<>(ranges);
Review Comment:
After looking at this, I think it might be worth trying to use the original
approach I proposed in
[CASSANDRA-18165](https://issues.apache.org/jira/browse/CASSANDRA-18165). We
should be able to avoid creating a new iterator, and while we're here, I'm not
really sure why we defensive copy `ranges` for `toRelease` when we've already
created a new list in the builder. (If we used my implementation, we could
rename `toRelease` to just `ranges` I guess?)
I know `getCurrent()` is gone, so it can't be a direct port, but I think we
can still do this without all the extra object creation...
--
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]