Remove even more boolean success flags#15134
Conversation
| } else { | ||
| IOUtils.deleteFilesIgnoringExceptions(tempDir, sortedFile); | ||
| } | ||
| tempDir.deleteFile(sortedFile); |
There was a problem hiding this comment.
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.
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.
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.
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