Skip to content
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

Fix resultcache multiple postaggregation restore #15402

Merged

Conversation

kgyrtkirk
Copy link
Member

See #15393 for more details

Comment on lines 653 to 655
for (int postPos = 0; postPos < query.getPostAggregatorSpecs().size(); postPos++) {
resultRow.set(postAggregatorStart + postPos, results.next());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this can happen but to be on the safe side?

Suggested change
for (int postPos = 0; postPos < query.getPostAggregatorSpecs().size(); postPos++) {
resultRow.set(postAggregatorStart + postPos, results.next());
}
for (int postPos = 0; postPos < query.getPostAggregatorSpecs().size(); postPos++) {
if (results.hasNext()) resultRow.set(postAggregatorStart + postPos, results.next());
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the contract around here should be to restore the same row that it have saved into the cache - if its not able to do so; I think it should fail with an exception - if it doesn't do that wouldn't that cause incorrect results - or not?

Copy link
Contributor

@LakshSingla LakshSingla Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also going through this area for a different purpose, and indeed there's a check below this code that checks if both the iterators have been exhausted completely, so even with the above check, the code would fail below. However, the error message would be more descriptive, so I think we should add the check back, otherwise it would fail with a generic NoSuchElementException exception

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the case you were thinking - but I'm afraid that check might not be that usefull for these cases; consider the following:

  • lets have
    • a results with {1 dim}+{1 aggs}+{1 postagg} = 3
    • a resultRow with {1 dim}+{1 aggs}+{2 postagg} = 4 (for whatever reason ?)
    • since in these cases the system is already facing a serious error - I'm not sure what value a nicer error message will give - as such error could not be fixed easily for sure
  • I think a more reasonable check would be to ensure that results.size() == resultRow.size() - so that we can remove the checking of all these iterators - as they are trying to do the same in a more complicated way

I've added an if to throw an exception in case there are no next when there should be one; but all these conditionals are kinda redundant as the iterator was created for a list

Copy link
Contributor

@LakshSingla LakshSingla Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/query/groupby/GroupByQueryQueryToolChest.java#L660
I was referring to this check. It should also handle the case that you mentioned above right? Perhaps adding the size check that you mentioned earlier is more legible. I am okay with the code either way.

while (postItr.hasNext() && results.hasNext()) {
for (int postPos = 0; postPos < query.getPostAggregatorSpecs().size(); postPos++) {
if (!results.hasNext()) {
throw new ISE("Ran out of objects while reading postaggs from cache!");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use DruidException.defensive instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to DruidException - I was just following the error handling which was already in this method; there is another ISE a few lines below and fetchAggregatorsFromCache also throws an ISE

@abhishekagarwal87 abhishekagarwal87 merged commit dff5bcb into apache:master Nov 21, 2023
83 checks passed
kgyrtkirk added a commit to kgyrtkirk/druid that referenced this pull request Nov 21, 2023
@kgyrtkirk
Copy link
Member Author

Thank you @LakshSingla and @abhishekagarwal87 for reviewing and merging the changes!

LakshSingla pushed a commit that referenced this pull request Nov 22, 2023
yashdeep97 pushed a commit to yashdeep97/druid that referenced this pull request Dec 1, 2023
@LakshSingla LakshSingla added this to the 28.0.1 milestone Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Druid 28.0.0 breaks the whole-query cache for groupBy queries with multiple post-aggregate metrics.
4 participants