Hibernate Search + Spring + JPA + 2 webapps - correct configuration

天涯浪子 提交于 2019-12-13 20:16:02

问题


I have search long and hard, and cannot find a definitive answer.

I have 2 webapps running on a single instance of tomcat: /server and /ROOT

I have configured Hibernate Search configured for one of my entities, ie Products.

These entities are edited/added on /server and searched for by front end users on the website /ROOT

during normal operations, everything works as it should, editing entities on the server will result in those changes reflecting when doing a search on the front end.

however, after an undetermined time, or sequence of events, the index no longer gets updated.

here is the configuration for /server

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="jpaDataSource" />
    <property name="packagesToScan" value="com.foo" />
    <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="generateDdl" value="true" />
                    <property name="showSql" value="true" />
            </bean>
    </property>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}" />
</util:map>

and here is the config for /ROOT

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="com.foo" />
    <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                    <property name="generateDdl" value="true" />
                    <property name="showSql" value="true" />
            </bean>
    </property>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}" />
</util:map>

Essentially identical.

and here is how my Entity is configured, via an AspectJ ITD

privileged aspect Product_Search {

declare @type: Product: @Indexed;

declare @method :public Long Product.getId() : @DocumentId;
declare @method :public String Product.getTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSubTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getAlternativeTitle() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getIdentifier() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getPrimaryCreators() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSecondaryCreators() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getSubjectArea() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);
declare @method :public String Product.getPublisher() : @Field(index=Index.YES, analyze=Analyze.NO, store=Store.NO);
declare @method :public String Product.getTags() : @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO);

Upon further searching, I discovered the master/slave DirectoryProvider

/server

    <util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem-master" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}/primary" />
    <entry key="hibernate.search.default.sourceBase" value="${lucene.index.folder}/master" />
    <entry key="hibernate.search.default.refresh" value="120" />
</util:map>

/ROOT

    <util:map id="jpaPropertyMap">
    <entry key="hibernate.search.default.directory_provider" value="filesystem-slave" />
    <entry key="hibernate.search.default.sourceBase" value="${lucene.index.folder}/master" />
    <entry key="hibernate.search.default.indexBase" value="${lucene.index.folder}/slave" />
    <entry key="hibernate.search.default.refresh" value="300" />
</util:map>

This seemed to work, until earlier to day, when for some reason, my index "reset" itself, and only contained the items that were part of the last product import. What I mean is, that my DB has 10000 items, but if I did a query = new MatchAllDocsQuery();, I only got 15 (the size of the last import)

This is really driving me crazy.

At the moment, I am having to bring down the websites, delete the index, start the server, reindex using FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager()); fullTextEntityManager.createIndexer().startAndWait();

Let me know if you need any more info

Thanks


回答1:


If changes are only coming in via the server app and you always want to run server and ROOT on the same machine, there is no need for a master/slave setup. A simple filesystem setup should do, however, you want to make sure that on the ROOT app _hibernate.search.indexing_strategy = manual_ is specified. This way index updates would only occur when the explicit indexing API is used on the ROOT app.

have you turned on logging? Is there anything in the logs. I think the first step is trying to reproduce the problem in a reliable way. If you just say it works initially, but then suddenly it starts failing, it makes it hard to find the cause. Have you tried with some automated load tests?




回答2:


One idea - maybe you should switch to non-exclusive mode (see for exclusive_index_use)



来源:https://stackoverflow.com/questions/15479622/hibernate-search-spring-jpa-2-webapps-correct-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!