Skip to content

Commit

Permalink
HSEARCH-3118 Ensure we properly close the directory when we close a L…
Browse files Browse the repository at this point in the history
…ucene index manager
  • Loading branch information
yrodiere committed May 22, 2019
1 parent 936fb0c commit e8ac812
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Expand Up @@ -133,7 +133,7 @@ public void close() {
try ( Closer<IOException> closer = new Closer<>() ) {
closer.push( LuceneWriteWorkOrchestratorImplementor::close, writeOrchestrator );
// Close the index writer after the orchestrators, when we're sure all works have been performed
closer.push( IndexWriterHolder::closeIndexWriter, indexWriterHolder );
closer.push( IndexWriterHolder::close, indexWriterHolder );
closer.push( LuceneIndexModel::close, model );
}
catch (IOException | RuntimeException e) {
Expand Down
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.search.backend.lucene.logging.impl.Log;
import org.hibernate.search.engine.common.spi.ErrorHandler;
import org.hibernate.search.engine.reporting.spi.EventContexts;
import org.hibernate.search.util.common.impl.Closer;
import org.hibernate.search.util.common.logging.impl.LoggerFactory;
import org.hibernate.search.util.common.reporting.EventContext;

Expand All @@ -28,7 +29,7 @@
/**
* @author Sanne Grinovero (C) 2011 Red Hat Inc.
*/
public class IndexWriterHolder {
public class IndexWriterHolder implements AutoCloseable {
private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );

private final String indexName;
Expand Down Expand Up @@ -67,6 +68,14 @@ public IndexWriterHolder(String indexName, Directory directory, Analyzer analyze
*/
}

@Override
public void close() throws IOException {
try ( Closer<IOException> closer = new Closer<>() ) {
closer.push( IndexWriterHolder::closeIndexWriter, this );
closer.push( Directory::close, directory );
}
}

/**
* Gets the IndexWriter, opening one if needed.
*
Expand Down

0 comments on commit e8ac812

Please sign in to comment.