-
Notifications
You must be signed in to change notification settings - Fork 25.2k
The same search statement multiple times gets different total results #113256
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
Comments
Pinging @elastic/es-search (Team:Search) |
Thanks for the report; I've tagged this for the appropriate team who will likely know more, but I will note that we've released several bugfix releases in 7.17.x series that contain significant fixes and my first recommended step would be to attempt reproducing on the latest 7.17.x version. (I know that may be easier said than done, however.) |
I think there is one thing I may have forgotten to mention. That is, before raising this issue, I have spent a long time looking up a lot of information, including release notes, etc. https://www.elastic.co/guide/en/elasticsearch/reference/7.17/release-notes-7.17.1.html, and there is really no better and valuable information. The main reason is that I am not sure whether the _flush operation can solve this problem. As you said, it is difficult to upgrade the production environment in a short time or reproduce such a difficult problem in other environments. And I want to know more about why a segment in an index whose data does not change is not automatically committed for a long time. It is particularly important to find out the cause of this problem and what other means can be used to troubleshoot it, because it can avoid encountering this problem again in the future (if _flush can solve the current problem).Thanks~ One more thing to add, I can't reproduce this problem in an environment with relatively low server configuration but the same deployment architecture. The segments are automatically committed after a period of time. To be precise, I am still not sure whether the unstable search hits total is related to the uncommitted segments. Maybe you can help me with this conclusion. Thanks again. |
Oh, there is another new discovery. When I execute /index/_refresh, there will be a pending state without response for a long time. I can't restart the cluster at will in the production environment, but when I use _cluster/_settings put log configuration, it seems that only "logger._root": "debug" can take effect, and the rest of the parts cannot take effect.
I cannot get the expected response or see the corresponding log information after executing /_flush or /_refresh, but my cluster works very well from beginning to end and is always in the GREEN state. All shards are STARTED |
After more detailed investigation, it was found that there were too many tasks in the refresh thread pool queue of the problematic data node, and there was no downward trend. |
@gwbrown Hi friend, is the more professional team still following up on this issue?Do my new findings help me find the cause of this problem? |
Pinging @elastic/es-distributed (Team:Distributed) |
Searches search the refreshed data. So if refreshes do not go through for some reason, that's a reason you may be getting inconsistent results. Assuming you finally refresh the index (e.g., with a manual call to the refresh API), your search results should be stable (for the so-far ingested data). Feel free to paste the hot threads of the affected node to check where threads are and what they may be doing. This forum topic may also be relevant for you, which can be verified by the hot threads. |
@kingherc When the problem was first discovered, I used GET /_nodes/hot_threads to check the hot threads of the datanode, but I didn't find anything special. I used jstack to collect thread stack information of the node many times, and saw that the threads related to the refresh thread pool were waiting for the results of threads such as <0x0000fff767a424c0>, but I couldn't find the running information of the related threads in the dump file. They had disappeared, which means that these threads did not release the locks they obtained at the end. |
@killersteps the stack trace seems fairly similar to the forum topic's I mentioned.
We do a lot of async processing, so I am not sure we can definitely say they "lost" the lock and won't ultimately release it. I think it'd be better if you paste/attach here the whole output of hot threads, and maybe a couple of the jstack outputs, while the problem is occurring. |
@kingherc First of all, thank you for your reply and guidance. I carefully read the subject you mentioned and compared the stack information in the article. Unfortunately, I did not find the call to the DeleteFile0 method in the thread stack of the refresh thread pool in my jstack stack. So I judged that although the two problems have similar thread stack information, they are two different problems. In addition, my cluster is deployed on a Linux server instead of a Windows server. I collected some jstack information about the refresh thread of the datanode node to make some supplements. See if you can help me take a look? Because I am not very familiar with the source code of elasticsearch, thank you again! |
@kingherc When I looked at the stack trace, it seemed like it had something to do with replica synchronization. Oh, this is indeed a tricky problem. |
Indeed, the issue is that refreshes are somehow the bottleneck. However, there does not seem to be anything interesting from the above-mentioned hot threads. We still need to understand what they are waiting on, and without a full thread stack it may be hard to understand just from the screenshots. I'd suggest to try this to get all thread stacks, or using jstack again. |
@kingherc Since this problem has been delayed for a long time, we decided to restart the datanode07 node recently to solve the problem of the refresh thread pool being full, and manually perform _flush and _refresh operations. The following pictures are some hot thread information collected based on your suggestions. I am sorry that my ability is limited and I still cannot locate the root cause of the problem. I hope this can help your team and guide us to find the root cause. Finally, I would like to ask a question. If the data in an index will not change, should the committed and searchable values obtained through the _cat/segments/index?v API always be true? Because according to the basic situation we have located in this issue, the committed and searchable values of several segments in the shards allocated on the datanode07 node are false. |
Seeing this last stacktrace seems like it's stuck in the BitsetFilterCache while inside a refresh. I think this is more relevant for the Search team to answer (due to the BitsetFilterCache), so for the moment I'll remove the Distributed team from the ticket, to make it clear that Search team should comment on this.
Note that an index needs to be refreshed in order to get an up-to-date count of documents. And if the refreshes did not go through, that's potentially why you might have observed an unexpected number of documents. |
Pinging @elastic/es-search-foundations (Team:Search Foundations) |
@kingherc @benwtrent We restarted the datanode07 node to solve the problem. Currently, the query results are stable, and the refresh thread pool works normally, and no tasks are accumulated in the queue. -, - |
@kingherc @benwtrent @gwbrown @DaveCTurner Unfortunately, this problem reappeared in another elasticsearch cluster in our production environment. We checked the relevant thread dump information and obtained the following results: `"elasticsearch[node-2][refresh][T#2]" #86 daemon prio=5 os_prio=0 tid=0x0000fffc78007000 nid=0xb047e waiting on condition [0x0000fffc01c3d000] Locked ownable synchronizers: Locked ownable synchronizers: Our team compiled version 7.17.1 locally, added relevant logs, and found that all deadlocks occurred in the following method: org.elasticsearch.index.cache.bitset.BitsetFilterCache.BitSetProducerWarmer#warmReader. We suspect that the occurrence of this lock is related to the existence of a nested structure in the index mapping. This mechanism seems to be a warm-up function for this index when elasticsearch is searching. I'm not sure if the deadlock occurs because the CountDownLatch counter does not reach 0 or because of the internalReaderManager.maybeRefreshBlocking(); logic of org.elasticsearch.index.engine.InternalEngine.ExternalReaderManager#refreshIfNeeded (I prefer the latter because the comments of this method are very interesting and it looks easy to have problems, but it is lucene code) In short, when the problem occurs, there will be a lot of tasks in the refresh thread pool queue, and the search results will become unstable. I wonder if the expert team can give us some ideas for further troubleshooting and analysis? There are a few details that need to be explained here:
|
Please help @DaveCTurner to look at this very tricky problem, but I think it is just a phenomenon similar to the following discussion[https://discuss.elastic.co/t/massive-queue-in-refresh-thread-pool-on-a-single-node-causing-timeouts/280732/18]. The reason is not because of the [email protected]/sun.nio.fs.WindowsNativeDispatcher.DeleteFile0(Native Method) system call, but because of whether the warm-up of the nested query has a deadlock? Or is the org.elasticsearch.index.engine.InternalEngine.ExternalReaderManager#refreshIfNeeded method deadlocked at internalReaderManager.maybeRefreshBlocking();? |
Thanks very much for your interest in Elasticsearch. This appears to be a user question, and we'd like to direct these kinds of things to the Elasticsearch forum. If you can stop by there, we'd appreciate it. Specifically, you haven't provided a clear sequence of steps to reproduce the problem, nor have you shared the information requested above (complete There's an active community in the forum that should be able to help get an answer to your question. As such, I hope you don't mind that I close this. |
One sentence description
When I search using the following statement, the search gets different total hits multiple times.
For example:
"hits": {
"total": {
"value": 6000000(This value is unstable and may change occasionally, but in fact the data in this index will never change from a business perspective),
"relation": "eq"
},
...
}
Basic Information:
Elasticsearch version: 7.17.1
Cpu architecture: aarch64
Jdk version: 1.8
Cluster overview: 9 nodes, including 6 data nodes and 3 master nodes(Server resources and jvm resources are absolutely sufficient.)
Index(my_index) overview: 9 primary shards, 1 replica shard
Search statement
http://:9200/my_index/_search?request_cache=false&explain=true&track_total_hits=true&q=*
In the above search statement, I used three key parameters, corresponding to different purposes:
track_total_hits=true: to get an accurate hits total value
request_cache=false: disable query cache, eliminate the impact of cache
explain=true: explain the search, used to assist query
In actual applications, the query has some conditions. I am using q=* to check for unstable total doc counts. And again, the data in these problematic indexes will never change.
In addition, when checking some basic status through /_cluster/health and /_cat/shards, they are all GREEN and STARTED
It is worth mentioning that I have carefully analyzed this issue in combination with the sharing in this article: https://www.elastic.co/guide/en/elasticsearch/reference/7.17/consistent-scoring.html#_scores_are_not_reproducible
When I search using preference=_shards:0,1,2,3,4,5,6,7,8, the problem still recurs randomly
My current conclusion is that the committed status of some segments of the shards allocated on the datanode03 node of the cluster is false
When I use preference=_shards:0,1,2,3,4,5 to filter out the three shards 6,7,8 allocated on datanode03 (use /cat/shards/my_index to get this information), the hits total value becomes stable
But the most incomprehensible situation is that when observing all parameters such as os, jvm, mem, etc. through /nodes/datanode03/_stats, no possible abnormal information is found. They all look normal.
But the most incomprehensible situation is that I observed all the parameters such as os, jvm, mem, etc. through /nodes/datanode03/_stats, and no possible abnormal information was found. They all looked normal. I currently only have some segments that are not committed and the shards where these segments are located are coincidentally allocated on the datanode03 node. This is a valuable piece of information.
I want to get three help or discussion:
The text was updated successfully, but these errors were encountered: