-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Async search reads aggregation results on many threads. It's quite possible for it to concurrently serialize an aggregation and render it's xcontent. But the cardinality agg's results were not thread safe! They reuse non-thread safe shard constructs used to collect the agg. It's fine for the collection side not to be thread safe. But not results. Anyway! This would sometimes cause the async search index to contain invalid results which would fail to deserialize. This seems to happen frequently enough to some folks that it makes cardinality totally unusable with async search. So far as I can tell you have to create a race on the iterator to make that happen. This is enough: ``` curl -XDELETE -uelastic:password localhost:9200/test echo for i in {1..100}; do rm -f /tmp/bulk printf "%03d: " $i for j in {1..10000}; do echo '{"index": {}}' >> /tmp/bulk echo '{"i": '$i', "j": '$j'}' >> /tmp/bulk done curl -s -XPOST -HContent-Type:application/json -uelastic:password localhost:9200/test/_bulk?pretty --data-binary @/tmp/bulk | grep error done while true; do id=$(curl -s -XPOST -HContent-Type:application/json -uelastic:password 'localhost:9200/test/_async_search?pretty&request_cache=false&wait_for_completion_timeout=10ms' -d'{ "size": 0, "aggs": { "i": { "terms": { "field": "i" }, "aggs": { "j": { "cardinality": { "field": "j" } } } } } }' | jq -r .id) while curl -s -HContent-Type:application/json -uelastic:password localhost:9200/_async_search/$id?pretty | tee out | grep '"is_running" : true'; do cat out done cat out sleep 1 curl --fail-with-body -s -HContent-Type:application/json -uelastic:password localhost:9200/_async_search/$id?pretty || break done ``` Run that without this PR and it'll break with a message about being unable to deserialize stuff from the index. It'll give a 400 error too which is totally bogus. On my laptop it takes less than ten iterations of the loop. So this PR fixes it! It removes the non-thread safe stuff from the cardinality results. It also adds a half dozen extra unit tests that'll be run for hundreds of objects which should catch similar sorts of possible errors.
- Loading branch information
Showing
7 changed files
with
232 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.