-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fixing SortField comparison to use equals instead of reference equality #6901
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"search across indices with mixed long and double numeric types": | ||
- skip: | ||
version: " - 2.6.99" | ||
reason: relies on numeric sort optimization that landed in 2.7.0 only | ||
|
||
- do: | ||
indices.create: | ||
index: test_1 | ||
body: | ||
settings: | ||
number_of_shards: "1" | ||
number_of_replicas: "0" | ||
mappings: | ||
properties: | ||
counter: | ||
type: long | ||
|
||
- do: | ||
indices.create: | ||
index: test_2 | ||
body: | ||
settings: | ||
number_of_shards: "1" | ||
number_of_replicas: "0" | ||
mappings: | ||
properties: | ||
counter: | ||
type: double | ||
- do: | ||
bulk: | ||
refresh: true | ||
body: | ||
- index: | ||
_index: test_1 | ||
- counter: 223372036854775800 | ||
- index: | ||
_index: test_2 | ||
- counter: 1223372036854775800.23 | ||
- index: | ||
_index: test_2 | ||
- counter: 184.4 | ||
|
||
- do: | ||
search: | ||
index: test_* | ||
rest_total_hits_as_int: true | ||
body: | ||
sort: [{ counter: desc }] | ||
- match: { hits.total: 3 } | ||
- length: { hits.hits: 3 } | ||
- match: { hits.hits.0._index: test_2 } | ||
- match: { hits.hits.0._source.counter: 1223372036854775800.23 } | ||
- match: { hits.hits.0.sort: [1223372036854775800.23] } | ||
- match: { hits.hits.1._index: test_1 } | ||
- match: { hits.hits.1._source.counter: 223372036854775800 } | ||
- match: { hits.hits.1.sort: [223372036854775800] } | ||
|
||
- do: | ||
search: | ||
index: test_* | ||
rest_total_hits_as_int: true | ||
body: | ||
sort: [{ counter: asc }] | ||
- match: { hits.total: 3 } | ||
- length: { hits.hits: 3 } | ||
- match: { hits.hits.0._index: test_2 } | ||
- match: { hits.hits.0._source.counter: 184.4 } | ||
- match: { hits.hits.0.sort: [184.4] } | ||
- match: { hits.hits.1._index: test_1 } | ||
- match: { hits.hits.1._source.counter: 223372036854775800 } | ||
- match: { hits.hits.1.sort: [223372036854775800] } |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -635,7 +635,7 @@ private static Sort createSort(TopFieldDocs[] topFieldDocs) { | |
*/ | ||
private static boolean isSortWideningRequired(TopFieldDocs[] topFieldDocs, int sortFieldindex) { | ||
for (int i = 0; i < topFieldDocs.length - 1; i++) { | ||
if (topFieldDocs[i].fields[sortFieldindex] != topFieldDocs[i + 1].fields[sortFieldindex]) { | ||
if (!topFieldDocs[i].fields[sortFieldindex].equals(topFieldDocs[i + 1].fields[sortFieldindex])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gashutos mind taking a look? I found this one out while adding tests for multi index search queries There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I remember I did test this with int & long and it worked fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not exactly this one, but assume that index1 and index2 have same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh got it, so correctness wise it was still giving right results ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, no visible effect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, that I got. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh got it, you mean we don't need this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, its good to have. I was just curious why it is failing :)
No no, we need it, thank you for adding it... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reta I think this is mixed cluster scenario which is failing in The new changes we did as part of widening sort type handles it correctly but that will be in only latest version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Correct, so I was adding the version check here:
So the test should be skipped for anything below 2.7.0 (we backported this change to 2.x so it should work for 3.0.0 and 2.7.0) but for some reasons, the test is run on versions it is not supposed to ... I am curious to find out why .... Running the test on 2.x branch manually passed for me, looking into it ... |
||
return true; | ||
} | ||
} | ||
|
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.
@gashutos so I found out why test is flipping, this is very interesting.
The test only works on single node clusters (or, to generalize it, when search results come from single node without serialization being involved). The reason for that is that
SortedNumericSortField
s are deserialized by Apache Lucene asSortField
s and that is how they come toSearchPhaseController
. As you may guessed already, the sort optimization does not trigger anymore becauseinstanceof SortedNumericSortField
is not met (those are justSortField
instances).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.
This is concerning @reta , The optimization will still get applied but while merging results, if it has different SortFiled.Type (INT & LONG from two different shards), it will fail the request -
Let me see what could be done here....
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.
Yes, it will fail the request, which is essentially the "expected" behavior as per current implementation. So basically without the optimization - the test always fails, with optimization - passed on single node clusters.
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.
But current implementation works for Int & Long indices. Since we used to widen sortType to Long for Int field too during shard level sort. That will break with this, I wasnt knowing serilization will trigger issue here hence didnt test on multinode scenario....
tagging @nknize 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.
No, it does not (Lucene is typecasting), here is the prove:
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.
@gashutos just to may be clarify, this is not the regression caused by optimization changes, it existed before and still exist in Elasticsearch 7.x release line.
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.
@reta I verified that this is regression. To reproduce this, do below steps.
size
field aslong
fromint
I raised a PR to fix this behaviour, #6926 lets get that in before this PR.
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.
👍 test case have been updated