-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Remove even more boolean success flags #15134
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?
Conversation
} else { | ||
IOUtils.deleteFilesIgnoringExceptions(tempDir, sortedFile); | ||
} | ||
tempDir.deleteFile(sortedFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exceptions thrown by this should be handled by the method calling this close()
method
if (success) { | ||
IOUtils.close(reader, dir); | ||
} else { | ||
IOUtils.closeWhileHandlingException(reader, writer, dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code implicitly calls close()
on writer
after rollback()
has been called, but IndexWriter
can handle that
This one is more complicated than the others. Especially the first file is hard. Why was it possible to remove success without any other code change? |
You mean That loop only exits normally once it gets to the end (returns |
This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really a hard one. The easy ones are perfectly fine, the other ones are partly hard to read, biut with github side-by-side view its manageable:
- Simple ones are fine
- SegmentCoreReaders is more complex than before (nested try blocks). Maybe revert that one and keep the old success pattern here?
- FreeTextSuggester is not understandable by me :-(
- TestSimpleServer is fine, but you need to notice the
try (socket)
on top!
} finally { | ||
try { | ||
if (success) { | ||
IOUtils.close(reader, dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It helps to note here that reader
and dir
are closed whatever the outcome. This means that both those can be moved to try-with-resources when they are created, so they are always closed.
Previously, writer
was only closed explicitly if an exception was thrown. If it completed normally, only rollback()
was called. But IndexWriter
checks for close
being called after rollback
, and makes sure that it is only closed once. So this means that writer
can also be in a try-with-resources when it is created, as the extra implicit close
at the end of the outer try is a no-op if rollback
is called, and closes it if an exception is thrown (which is what the previous code also did).
In terms of live-ness, the try for the finally block the IOUtils.rm
runs in has increased in scope to include creating the Document
, FieldType
, and IndexWriter
at the start. Previously, if IndexWriter
threw an exception, the directory wouldn't be cleaned up. This is now the case, so it won't leak tempIndexPath
if IndexWriter
throws an exception
Most of the remaining ones are in backwards-compatible codecs and the test framework