Skip to content

HSEARCH-5388 Warn users if their Lucene caching policy is ineffective #4638

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public interface LuceneLog
* here to the next value.
*/
@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 195, value = "")
@Message(id = ID_OFFSET + 196, value = "")
void nextLoggerIdForConvenience();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET;
import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET_LEGACY_ENGINE;
import static org.jboss.logging.Logger.Level.TRACE;
import static org.jboss.logging.Logger.Level.WARN;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -328,4 +329,9 @@ SearchException vectorKnnMatchVectorTypeDiffersFromField(String absoluteFieldPat
@Message(id = ID_OFFSET + 194, value = "Current factory cannot be resocped to '%1$s' as it is scoped to '%2$s'.")
SearchException incompatibleScopeRootType(@FormatWith(ClassFormatter.class) Class<?> requested,
@FormatWith(ClassFormatter.class) Class<?> actual);

@LogMessage(level = WARN)
@Message(id = ID_OFFSET + 195, value = "Configured query cache policy is ineffective as query cache is not enabled. "
+ "Set the cache explicitly through the QueryCachingConfigurer.")
void ineffectiveQueryCachingPolicy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.hibernate.search.backend.lucene.cache.impl.LuceneQueryCachingContext;
import org.hibernate.search.backend.lucene.logging.impl.LuceneMiscLog;
import org.hibernate.search.backend.lucene.logging.impl.QueryLog;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.HibernateSearchMultiReader;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.IndexReaderMetadataResolver;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.ReadIndexManagerContext;
Expand Down Expand Up @@ -131,7 +132,13 @@ public IndexSearcher createSearcher() {
searcher.setSimilarity( similarity );

cachingContext.queryCache().ifPresent( searcher::setQueryCache );
cachingContext.queryCachingPolicy().ifPresent( searcher::setQueryCachingPolicy );
if ( cachingContext.queryCachingPolicy().isPresent() ) {
searcher.setQueryCachingPolicy( cachingContext.queryCachingPolicy().get() );
// Note: Lucene 11 will not enable cache by default so policy won't get applied, let's warn users if this happens:
if ( searcher.getQueryCache() == null ) {
QueryLog.INSTANCE.ineffectiveQueryCachingPolicy();
}
}

return searcher;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public interface LuceneLog
* here to the next value.
*/
@LogMessage(level = TRACE)
@Message(id = ID_OFFSET + 195, value = "")
@Message(id = ID_OFFSET + 196, value = "")
void nextLoggerIdForConvenience();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET;
import static org.hibernate.search.backend.lucene.logging.impl.LuceneLog.ID_OFFSET_LEGACY_ENGINE;
import static org.jboss.logging.Logger.Level.TRACE;
import static org.jboss.logging.Logger.Level.WARN;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -328,4 +329,9 @@ SearchException vectorKnnMatchVectorTypeDiffersFromField(String absoluteFieldPat
@Message(id = ID_OFFSET + 194, value = "Current factory cannot be resocped to '%1$s' as it is scoped to '%2$s'.")
SearchException incompatibleScopeRootType(@FormatWith(ClassFormatter.class) Class<?> requested,
@FormatWith(ClassFormatter.class) Class<?> actual);

@LogMessage(level = WARN)
@Message(id = ID_OFFSET + 195, value = "Configured query cache policy is ineffective as query cache is not enabled. "
+ "Set the cache explicitly through the QueryCachingConfigurer.")
void ineffectiveQueryCachingPolicy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.hibernate.search.backend.lucene.cache.impl.LuceneQueryCachingContext;
import org.hibernate.search.backend.lucene.logging.impl.LuceneMiscLog;
import org.hibernate.search.backend.lucene.logging.impl.QueryLog;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.HibernateSearchMultiReader;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.IndexReaderMetadataResolver;
import org.hibernate.search.backend.lucene.lowlevel.reader.impl.ReadIndexManagerContext;
Expand Down Expand Up @@ -131,7 +132,13 @@ public IndexSearcher createSearcher() {
searcher.setSimilarity( similarity );

cachingContext.queryCache().ifPresent( searcher::setQueryCache );
cachingContext.queryCachingPolicy().ifPresent( searcher::setQueryCachingPolicy );
if ( cachingContext.queryCachingPolicy().isPresent() ) {
searcher.setQueryCachingPolicy( cachingContext.queryCachingPolicy().get() );
// Note: Lucene 11 will not enable cache by default so policy won't get applied, let's warn users if this happens:
if ( searcher.getQueryCache() == null ) {
QueryLog.INSTANCE.ineffectiveQueryCachingPolicy();
}
}

return searcher;
}
Expand Down