-
Notifications
You must be signed in to change notification settings - Fork 1.3k
LUCENE-15108 commit writer before opening DirectoryReader to fix test #15233
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
base: main
Are you sure you want to change the base?
LUCENE-15108 commit writer before opening DirectoryReader to fix test #15233
Conversation
@jainankitk @jpountz @rmuir - If you can take a look, thanks! |
Generally speaking it's not a problem to open a Reader on an index that has a writer open with pending changes. It's hard to understand what went wrong in the test from the description here so we can check whether this is an appropriate fix. |
Hi @msokolov , You are correct. Due to the lack of an index, the test fails. I tried testing the scenario you mentioned, added I believe this condition: |
Thanks for fixing this test, @VivekKumarNeu !
That seems to be the case. For the specific seed which fails, the test never does a commit so the index doesn't exist. It's interesting, the odds of this happening should be very low (~0.01%). After indexing every doc, there's a 1/31 probability that we commit. And we index over 256 docs! Anyway, I think your fix of doing one final commit before we read this index makes sense. Your actual fix is just a one line change, but this PR shows a lot of diffs from main. Can you fix that before we approve and merge? |
I think Mike's suggestion was to add a
So, that would fix it. It essentially replaces the "no commit written" case with "empty commit written". |
Yes, @msfroh, exactly -- I was concerned that the commit logic below was actually part of the test (maybe?) and was thinking to perturb it as little as possible. The test as it was would also test the case where there are some uncommitted updates that would be flushed when the reader is opened (I think), but if we add the explicit commit after indexing all the docs then this case will no longer be tested. |
In this case, the reader isn't being opened from the writer, but rather gets opened against the directory. So, the pending changes wouldn't get flushed AFAIK. (So the deletes don't get applied until the It's worth noting that @VivekKumarNeu -- can you please confirm that replacing the |
Ah right, that makes sense! |
a03edba
to
189b90b
Compare
Thanks so much for your input @msokolov ! It totally makes sense to keep the original test intent and avoid adding that writer.commit(). @msfroh , I updated the test to use writer.getReader() instead of DirectoryReader.open(dir), which makes it match the structure of our other tests. The test is happy now! Thanks for looking into it. Updated the PR. |
@vigyasharma Could you please review/merge the PR when you have time? Thank you! |
Description
The test failed because DirectoryReader.open() tried to read the index while there were still uncommitted changes in the writer.
The fix is to call writer.commit() after we have made all the changes and before opening the reader. That makes sure the reader can actually see a proper index.
PS: This is my first commit. Please comment if I need to make any changes, and I will update the PR accordingly. Thank you.