lucene更新在hibernate 5中停止工作

5lhxktic  于 2023-10-18  发布在  Lucene
关注(0)|答案(1)|浏览(202)

在服务器启动期间,索引工作正常(创建索引,搜索工作正常)。但是当我们试图更新一些索引时,我们得到了锁异常,索引不工作,搜索不给给予正确的结果。
下面是错误日志。同样的事情也发生在Linux服务器上。

2023-09-07T11:39:50,437 [ERROR] [Hibernate Search sync consumer thread for index com.demoBO] [org.hibernate.search.exception.impl.LogErrorHandler] - HSEARCH000058: Exception occurred org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: D:\test\com.demoBO\write.lock
Primary Failure:
    Entity com.demoBO  Id 532  Work Type  org.hibernate.search.backend.UpdateLuceneWork

org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: D:\test\com.demoBO\write.lock
    at org.apache.lucene.store.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:127) ~[lucene-core-5.5.5.jar:5.5.5 b3441673c21c83762035dc21d3827ad16aa17b68 - sarowe - 2017-10-20 08:57:09]
    at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) ~[lucene-core-5.5.5.jar:5.5.5 b3441673c21c83762035dc21d3827ad16aa17b68 - sarowe - 2017-10-20 08:57:09]
    at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) ~[lucene-core-5.5.5.jar:5.5.5 b3441673c21c83762035dc21d3827ad16aa17b68 - sarowe - 2017-10-20 08:57:09]
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:776) ~[lucene-core-5.5.5.jar:5.5.5 b3441673c21c83762035dc21d3827ad16aa17b68 - sarowe - 2017-10-20 08:57:09]
    at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.createNewIndexWriter(IndexWriterHolder.java:127) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.getIndexWriter(IndexWriterHolder.java:93) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.AbstractWorkspaceImpl.getIndexWriter(AbstractWorkspaceImpl.java:118) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.AbstractWorkspaceImpl.getIndexWriterDelegate(AbstractWorkspaceImpl.java:204) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.applyUpdates(LuceneBackendQueueTask.java:82) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.run(LuceneBackendQueueTask.java:47) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.applyChangesets(SyncWorkProcessor.java:167) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.run(SyncWorkProcessor.java:153) [hibernate-search-engine-5.11.6.Final.jar:5.11.6.Final]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_302]
2023-09-07T11:39:50,453 [ERROR] [Hibernate Search sync consumer thread for index com.demoBO] [org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask] - HSEARCH000072: Couldn't open the IndexWriter because of previous error: operation skipped, index ouf of sync!

我的demoBO看起来像:-

@Entity
@Indexed
@Table(name = "DEMO_TB")
public class demoBO extends AbstractBO implements Serializable,
        Comparable<demoBO> {

    @Column(name = "active")
    @Field(analyze=Analyze.NO, store = Store.YES)
    private Boolean status;
    
    @Column(name = "deletion")
    @Field(analyze=Analyze.NO, store = Store.YES)
    private Boolean deletion;

    @Column(name = "keyValue", length = 256)
    @Field(analyze=Analyze.YES, store = Store.YES)
    private String keyValue;

    @Transient
    private int status = 0;

在服务器启动期间,代码用于创建索引(在此之后生成一个write.lock文件):-

entityManager = (EntityManager) applicationContext.getBean(entityManager);
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    try {
        fullTextEntityManager.createIndexer(DemoBO.class).startAndWait();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
cgvd09ve

cgvd09ve1#

这个错误意味着两个独立的Lucene / Hibernate Search示例试图同时打开同一个索引,这是不可能的。
您很可能同时为同一个模型启动多个AlternityManagerFactory。你不应该。

相关问题