Rahul sivasankaran
Rahul sivasankaran

Reputation: 1

Hibernate Search 6.x - How can I make the Lucene Index Directory to readonly

I have a requirement where the lucene indexes are generated during build time to serve the autocomplete APIs using hibernate search. The solution doesn't need dynamic index generation or updation. This only should serve the search query with the already generarted and copied indexes.

Hibernate search 6.x and Higher as per my knowledge doesn't have a configuration to make the lucene base index directory readonly. If any one know how to do it please provide me an insight.

I am using JPA and my persistence.xml configuration for hibernate search is below

  <property name="hibernate.search.backend.directory.type" value="local-filesystem"/>
  <property name="hibernate.search.backend.directory.root" value="${LUCENE_INDEX_DIR}"/>
  <property name="hibernate.search.mapping.build_missing_discovered_jandex_indexes" value="false"/>
  <property name="hibernate.search.backend.lucene_version" value="8.11.2"/>
  <property name="hibernate.search.schema_management.strategy" value="none"/>
  <property name="hibernate.search.backend.directory.locking.strategy" value="none"/>
  <property name="hibernate.search.backend.directory.locking.strategy" value="none"/>

I thought the last 2 configuration should make it work by providing the index directory read only access inside container. But it is not working

I have generated the indexes using mass indexing and published the whole index directory during the build pipeline to Maven.

SearchSession searchSession = Search.session(
        HibernateUtil.getEntityManagerFactory().createEntityManager());
    MassIndexer indexer = searchSession.massIndexer().purgeAllOnStart(true);

During the deployment, I am downloading the published indexes and make it as part of my docker image to copy it to a container file system location and I am making the location writable to work. This is working ok for me.

Now we are adopting quarkus and JIB for docker image creation, I need either of the following to make my solution works

  1. How to make the lucene backend work with read only index directory

  2. How can I set container folder permissions in JIB when creating a docker image.

Upvotes: 0

Views: 120

Answers (1)

yrodiere
yrodiere

Reputation: 9977

How to make the lucene backend work with read only index directory

There is no read-only mode in Hibernate Search -- yet.

The avoid Hibernate Search writing to the index, just don't trigger writes manually, and (if using the ORM integration) disable automatic triggers

hibernate.search.indexing.listeners.enabled = false

To have Hibernate Search start without attempting any write to the index directory for the purpose of locking, disable locking:

hibernate.search.backend.directory.locking.strategy = none

WARNING: This is obviously unsafe if your application does attempt to write to indexes.

In Quarkus, you would need to rely on unsupported properties -- feel free to open issues on GitHub to have these properties supported if you think they are useful:

quarkus.hibernate-orm.unsupported-properties."hibernate.search.indexing.listeners.enabled" = false
quarkus.hibernate-orm.unsupported-properties."hibernate.search.backend.directory.locking.strategy" = none

That being said, I'm intrigued that you are using the Lucene backend in a Quarkus application -- that's not supported yet. How are you doing that?

How can I set container folder permissions in JIB when creating a docker image.

No idea, sorry. I'm not sure that's possible, but would be happy to be proven wrong.

I'd suggest creating the image with JIB, then using an additional step in your build pipeline to launch the app using a Dockerfile? You'd take the JIB image, create the relevant directory, populate the indexes, and create a new image.

Or, just use Dockerfiles. That's possible as well with Quarkus, and it seems your use case might justify it.

Upvotes: 0

Related Questions