-
Notifications
You must be signed in to change notification settings - Fork 24.7k
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 search shards count method when targeting concrete and aliased indices #3268
Conversation
Thanks for pointing this out! Let me just check if I got it right. The searchShards method has been fixed (I see that #2682 is closed and the related #2683 has been merged) but the same change has not been applied to the searchShardsCount method, right? And that would lead to erroneously forcing query_and_fetch if the searchShardsCount returns 1? I guess it would be nice to share the same code between the two methods then and maybe write a test that reproduces the bug that we are trying to address. What do you think? |
@javanna yeah you got it perfectly right! Yeah I agree I can work on it and update my pull request hopefully before the end of the week if you want. If you want it done before it is ok if you prefer to implement it yourself |
No rush, you can go ahead and update your pull request when you have time. |
@javanna great thanks I will |
hey, I suggest we pull this fix first, just so we have a fix in master and 0.90, and think about optimization / refactoring in a separate issue? One note regarding potentially sharing code, its important that we don't cause the round robin iterators be invoked when calling searchShardsCount, cause if they will, it will mean that with the common case, of 1 replica, the same copy of the data will be hit each time (a single search request will increment the round robin index by 1 for the count, and then the next one will increment it again for the search). |
@kimchy sure we can push this fix and work on the refactoring in a separate issue. I was about to update the pull request with the refactoring tomorrow (I am still missing the unit tests for it). Basically what I have done is create a new private method Set computeTargetedShards(ClusterState clusterState, String[] indices, String[] concreteIndices, @nullable Map<String, Set> routing) with the shared logic in it. It is called by searchShardsCount and searchShards. |
@kimchy sorry a part is missing there the computeTargetedShards would return a set of IndexShardRoutingTable |
@kimchy ok I am going to open another issue with my proposed pull request tomorrow and we will be able to discuss more there about the suggested refactoring and maybe ways to optimize / improve it |
* es/6.x: (106 commits) Revert "Fix elasticsearch-cli dependency" Fix elasticsearch-cli dependency [Watcher] Use index.auto_expand_replicas: 0-1 (#3284) [DOCS] Reformatted machine learning overview (#3346) [DOCS] Added monitoring PRs to 6.1 release notes (#3297) [DOCS] Added xpack.ml.node_concurrent_job_allocations setting (#3327) [DOCS] Fixed troubleshooting titles Watcher: Set index and type dynamically in index action (#3264) Tests: Ensure that watcher is started in HipchatServiceTests Fix test due to BytesSizeValue negative value deprecation [DOCS] Explain ML datafeed run-as integration/limitations (#3311) Monitoring: Ensure all monitoring watches filter by timestamp (#3238) Fix license messaging for Logstash functionality (#3268) [DOCS] Updated titles of ML APIs Fixes test to support BytesSizeValue changes (#3321) Revert "Fixes test to support BytesSizeValue changes (#3321)" Fixes test to support BytesSizeValue changes (#3321) Add missing import Check for existing x-pack directory when running the `users` CLI tool (#3271) [DOCS] Fixed title in 6.1.0 release notes ...
This is related to the same example as issue #2682.
This bug can lead to a forced query_and_fetch search type which might not be the expected behavior.
I propose to fix it this way because it is a quick 2 lines patch. But maybe we should refactor a bit and add a shared method for searchShards and searchShardsCount to avoid divergent behavior in the future.
Reading the code it seems like searchShardsCount is mainly implemented to test if we are hitting 1 shard or more than 1 shards so maybe it could be renamed and optimized for that specific use case.
Feel free to fix the problem otherwise or to tell me what do you prefer and I will be happy to change this pull request.