Raise error in #scroll_batches when search backend returns a failure#916
Conversation
konalegi
left a comment
There was a problem hiding this comment.
Looks good to me, small changes are required to format of the error
lib/chewy/search/scrolling.rb
Outdated
|
|
||
| loop do | ||
| failures = result.dig('_shards', 'failures') | ||
| raise Chewy::Error, failures if failures.present? |
There was a problem hiding this comment.
I think Chewy::Error is not the best thing here, from your example, failures is a hash, and Chewy::Error is simply a StandardError with a string argument. Please make a specific error message and convert failure into a meaningful string? For instance
Lines 20 to 32 in 10ff43b
README.md
Outdated
| ## Running specs | ||
|
|
||
| Make sure you're running a local Elasticsearch instance. | ||
|
|
||
| ``` | ||
| ES_PORT=9200 bundle exec rspec | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Btw, could we remove this? I planning to backport docker-compose setup with ES, so it runs on proper port https://github.com/toptal/chewy/pull/917/files#diff-e45e45baeda1c1e73482975a664062aa56f20c03dd9d64a827aba57775bed0d3R1-R16
| let(:countries) { Array.new(3) { |i| Country.create!(rating: i + 2, name: "country #{i}") } } | ||
|
|
||
| describe '#scroll_batches' do | ||
| describe 'with search backend returning failures' do |
There was a problem hiding this comment.
btw, do you think it will be possible to provide integration spec? Where you really call ES and get real answer?
There was a problem hiding this comment.
Do you have a suggestion how I can set up an integration spec that returns this error state? Elasticsearch should return a total count higher than zero but then return zero hits in order to hit this code path.
|
Hey @tomdev Could you please share your chewy version, elasticsearch server version and elasticsearch gem version, that could be helpful? The issue could be also solved if you could set the scroll pointer expiration (which defaults to 1 minute) for |
|
Hey Barthez, thanks for reproducing the issue. Interesting to see the response is actually a We're unable to continue using Elasticsearch as we're using the AWS OpenSearch service. We're running:
We haven't identified any other issues (thus far) using chewy against OpenSearch. An attempt to increase the scroll pointer expiration did not succeed; we've set it to Do you think OpenSearch returning a |
|
Thanks @tomdev Chewy does not aim to support OpenSearch. This sounds like an altered behavior of OpenSearch vs Elasticsearch. I would suggest adding a custom exception, something like |
|
I implemented the This is slightly altering the behaviour of how this data is retrieved and even though the test suite succeeds I wanted to double check if anyone knows why the previous approach was chosen (loop until fetched >= total hits). Could I be missing an edge case here that was covered by the previous implementation? The specs don't indicate that. |
|
We've been running this PR in production for ~2 weeks and have seen the failure (where we'd previously got stuck in an infinite loop) now successfully raising the |
|
Thank you @tomdev. Sorry, I lost track of this PR. Cold you please rebase and fix the conflict? I will try to merge & release it as soon as possible. |
|
@tomdev is this PR still relevant? Sorry for the delay, I've been extremely busy. |
No worries, same here! Yes; this is still relevant to us, and we've been running from this PR in production for months. It's working well for us. I think this PR needs some rebasing and fixing conflicts, I can take a look at that. |
|
@tomdev Sure thank you! Keep in mind, we have moved to ES 8.x, so some extra adjustments might be needed. |
|
Master has been updated with CI fixes and compatibility changes (#998) — we now target Ruby 3.2+ and Rails 7.2+. Could you rebase this PR on top of master so CI can run properly? Thanks! |
|
This fixes a real production issue — shard failures during scroll causing infinite loops. The approach looks sound. Could you:
Happy to merge once that's done. |
AlfonsoUceda
left a comment
There was a problem hiding this comment.
Will take care of rubocop offenses and changelog entry
We are running into a bug in production when performing
chewy:sync.Our search backend is intermittently returning a
200response without hits and containing a backend failure, see example response:scroll_batches currently is not taking these failures into account. Because there are no hits returned, the logic of
fetched >= totalwill never be reached, causing the loop to never break.Because of this we've experienced
chewy:syncrunning for days instead of an hour. (Yes, we now have proper monitoring in place...)This PR will raise a
Chewy::Errorwhen the search backend is returning failures.Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).