-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSANDRA-19428 #3194
CASSANDRA-19428 #3194
Conversation
* replace KeyRangeConcatIterator's PriorityQeueu with List * remove KeyRangeIterator.current and simplify * remove injected exception and tests - not relevant to the current implementation * expand randomized testing * inline getCurrent() -> peek(); rename getCount to getMaxKeys * redefine skipTo contract to not return a value (which saves unnecessary work when skipTo is called multiple times in a row) * calling hasNext in skipTo is a pessimization; if the iterator is in DONE state, then skipTo will see it and avoid further effort; if it is not, then we are computing a next value that we're just going to throw away * Fix a bug in QueryController#getIndexResults error handling
Suggestion to change SingleNodeQueryFailureTest (passes locally for me)
|
{ | ||
return getRandom().nextDouble(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at these three methods, it seems like nextDouble()
and randomDouble()
produce the same result, since 0 + (1 - 0) * getRandom().nextDouble()
== 1 * getRandom().nextDouble()
== getRandom().nextDouble()
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally! Let's leave nextDouble
in and remove randomDouble
?
// all sstable indexes in view have been referenced, need to clean up when exception is thrown | ||
builder.cleanup(); | ||
queryView.referencedIndexes.forEach(SSTableIndex::releaseQuietly); | ||
if (rangeCount == 0) | ||
queryView.referencedIndexes.forEach(SSTableIndex::releaseQuietly); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
throw new IllegalArgumentException("Cannot concatenate empty list of ranges"); | ||
|
||
this.ranges = ranges.iterator(); | ||
this.currentRange = this.ranges.next(); | ||
this.toRelease = new ArrayList<>(ranges); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at this, I think it might be worth trying to use the original approach I proposed in 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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
On |
@@ -129,6 +129,16 @@ public static int between(int min, int max) | |||
return getRandom().nextIntBetween(min, max - 1); | |||
} | |||
|
|||
public static double nextDouble() | |||
{ | |||
return randomDoubleBetween(0, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think this could also just be getRandom().nextDouble()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
randomDoubleBetween
calls getRandom().nextDouble()
under the hood. It seems more clear to me to use the randomDoubleBetween
with the max and min explicitly stated. Though, now as you mentioned, I noticed that nextBoolean
uses directly getRandom().nextBoolean()
. I don't have strong preference for one or the other. I can change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's equivalent...just seemed less complicated to go directly to getRandom().nextDouble()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
this.ranges = ranges; | ||
this.toRelease = new ArrayList<>(ranges); | ||
this.current = 0; | ||
this.ranges = new ArrayList<>(ranges); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Do we even need the defensive copy? ranges
is private and never accessible by users of the iterator, and there is already an ArrayList
created in the builder, which is also private, right? The only way I could imagine we get in trouble is if someone adds to the builds after calling buildIterator()
, but that's definitely incorrect usage/we should never do it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I did not understand correctly this comment:
If we used my implementation, we could rename toRelease to just ranges I guess?
So you suggest it to be this.ranges = ranges
? (I just checked that this is what we already do in other iterators too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you suggest it to be this.ranges = ranges?
Yeah, basically...the defensive copy just seems paranoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple tiny nits, but LGTM!
The final approved patch is: |
Thanks for sending a pull request! Here are some tips if you're new here:
Commit messages should follow the following format:
The Cassandra Jira