NIFI-3152: Ensure that we always close the IndexWriter when appropriate in SimpleIndexManager, even if an IOException is thrown when trying to commit the IndexWriter

This closes #1300.

Signed-off-by: Bryan Bende <bbende@apache.org>
This commit is contained in:
Mark Payne 2016-12-05 14:30:57 -05:00 committed by Bryan Bende
parent 7633fe35c1
commit fc0d336f36
No known key found for this signature in database
GPG Key ID: A0DDA9ED50711C39
1 changed files with 5 additions and 2 deletions

View File

@ -158,8 +158,11 @@ public class SimpleIndexManager implements IndexManager {
} else if (count.getCount() <= 1) { } else if (count.getCount() <= 1) {
// we are finished with this writer. // we are finished with this writer.
logger.debug("Decrementing count for Index Writer for {} to {}; Closing writer", indexingDirectory, count.getCount() - 1); logger.debug("Decrementing count for Index Writer for {} to {}; Closing writer", indexingDirectory, count.getCount() - 1);
try {
writer.commit(); writer.commit();
} finally {
count.close(); count.close();
}
} else { } else {
// decrement the count. // decrement the count.
logger.debug("Decrementing count for Index Writer for {} to {}", indexingDirectory, count.getCount() - 1); logger.debug("Decrementing count for Index Writer for {} to {}", indexingDirectory, count.getCount() - 1);