Skip to content

Commit

Permalink
HSEARCH-2555 Make the SearchFactory release references to the LuceneW…
Browse files Browse the repository at this point in the history
…orkSerializer

... since it's the SearchFactory that requests them in the first place.
  • Loading branch information
yrodiere authored and Sanne committed Jan 20, 2017
1 parent 08b8f28 commit 2de44d8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
Expand Up @@ -19,7 +19,6 @@
import org.hibernate.search.backend.LuceneWork;
import org.hibernate.search.backend.spi.BackendQueueProcessor;
import org.hibernate.search.cfg.Environment;
import org.hibernate.search.indexes.serialization.spi.LuceneWorkSerializer;
import org.hibernate.search.indexes.spi.IndexManager;
import org.hibernate.search.spi.SearchIntegrator;
import org.hibernate.search.spi.WorkerBuildContext;
Expand Down Expand Up @@ -143,8 +142,6 @@ public boolean isTransactional() {

@Override
public void close() {
integrator.getServiceManager().releaseService( LuceneWorkSerializer.class );

try {
if ( connection != null ) {
connection.close();
Expand Down
Expand Up @@ -162,6 +162,7 @@ public ImmutableSearchFactory(SearchFactoryState state) {
this.isIdProvidedImplicit = state.isIdProvidedImplicit();
this.isMultitenancyEnabled = state.isMultitenancyEnabled();
this.indexManagerFactory = state.getIndexManagerFactory();
this.workSerializer = state.getWorkSerializerState();

this.enableDirtyChecks = ConfigurationParseHelper.getBooleanValue(
configurationProperties, Environment.ENABLE_DIRTY_CHECK, true
Expand Down Expand Up @@ -255,6 +256,10 @@ public void close() {
log.workerException( e );
}

if ( workSerializer != null ) {
serviceManager.releaseService( LuceneWorkSerializer.class );
}

this.allIndexesManager.stop();
this.timingSource.stop();

Expand Down Expand Up @@ -642,6 +647,11 @@ public LuceneWorkSerializer getWorkSerializer() {
return workSerializer;
}

@Override
public LuceneWorkSerializer getWorkSerializerState() {
return workSerializer;
}

@Override
public HSQuery createLuceneBasedHSQuery() {
return new LuceneHSQuery( this );
Expand Down
Expand Up @@ -376,6 +376,11 @@ public LuceneWorkSerializer getWorkSerializer() {
return delegate.getWorkSerializer();
}

@Override
public LuceneWorkSerializer getWorkSerializerState() {
return delegate.getWorkSerializerState();
}

@Override
public HSQuery createLuceneBasedHSQuery() {
return delegate.createLuceneBasedHSQuery();
Expand Down
Expand Up @@ -24,6 +24,7 @@
import org.hibernate.search.exception.ErrorHandler;
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.indexes.impl.IndexManagerHolder;
import org.hibernate.search.indexes.serialization.spi.LuceneWorkSerializer;
import org.hibernate.search.query.engine.spi.TimeoutExceptionFactory;
import org.hibernate.search.spi.IndexingMode;
import org.hibernate.search.spi.InstanceInitializer;
Expand Down Expand Up @@ -66,6 +67,7 @@ public class MutableSearchFactoryState implements SearchFactoryState {
private IndexManagerFactory indexManagerFactory;
private boolean enlistWorkerInTransaction;
private Statistics statistics;
private LuceneWorkSerializer workSerializer;

public void copyStateFromOldFactory(SearchFactoryState oldFactoryState) {
indexingMode = oldFactoryState.getIndexingMode();
Expand Down Expand Up @@ -93,6 +95,7 @@ public void copyStateFromOldFactory(SearchFactoryState oldFactoryState) {
indexManagerFactory = oldFactoryState.getIndexManagerFactory();
enlistWorkerInTransaction = oldFactoryState.enlistWorkerInTransaction();
statistics = oldFactoryState.getStatistics();
workSerializer = oldFactoryState.getWorkSerializerState();
}

@Override
Expand Down Expand Up @@ -335,4 +338,15 @@ public void setStatistics(Statistics statistics) {
this.statistics = statistics;
}

/**
* Immutable: what's important here is not to forget that a
* workSerializer has already been requested, so that
* the factory that copies this state will be able to know
* it should release this service.
*/
@Override
public LuceneWorkSerializer getWorkSerializerState() {
return workSerializer;
}

}
Expand Up @@ -22,6 +22,7 @@
import org.hibernate.search.exception.ErrorHandler;
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.indexes.impl.IndexManagerHolder;
import org.hibernate.search.indexes.serialization.spi.LuceneWorkSerializer;
import org.hibernate.search.query.engine.spi.TimeoutExceptionFactory;
import org.hibernate.search.spi.IndexingMode;
import org.hibernate.search.spi.InstanceInitializer;
Expand Down Expand Up @@ -82,4 +83,6 @@ public interface SearchFactoryState {
boolean enlistWorkerInTransaction();

Statistics getStatistics();

LuceneWorkSerializer getWorkSerializerState();
}

0 comments on commit 2de44d8

Please sign in to comment.