Lucene索引器适用于Windows,在Linux上运行失败

时间:2017-10-20 21:07:35

标签: linux windows lucene hibernate-search

我在Jetty 9.2上运行java应用程序。两者都使用相同版本的Jetty。索引器在部署后第一次启动应用程序时运行。我在Netbeans的Windows 10开发盒中没有任何问题。当我把它放在Linux机器上时,它不起作用,我只有SSH访问和有限的权限。

java代码,Class Person首先运行,类Organization运行第二。两者都在同一个休眠会话中

public static void reindexViaMassIndexer(Class<?> type, SessionFactory factory) {
    Session session = factory.getCurrentSession();
    FullTextSession fullTextSession = Search.getFullTextSession(session);
    MassIndexerProgressMonitor monitor = new SimpleIndexingProgressMonitor();

    try {
        fullTextSession
                .createIndexer(type)
                .typesToIndexInParallel(1)
                .batchSizeToLoadObjects(BATCH_SIZE)
                .cacheMode(CacheMode.NORMAL)
                .threadsToLoadObjects(10)
                .idFetchSize(BATCH_SIZE)
                .progressMonitor(monitor)
                .startAndWait();
    } catch (InterruptedException ex) {
        Logger.getLogger(HibernateLuceneIndexer.class.getName()).log(Level.SEVERE, null, ex);
    }

}

Pom文件

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search-orm</artifactId>
        <version>5.2.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>4.3.9.Final</version>
    </dependency>

错误输出

17:48:00,188 ERROR LogErrorHandler:67 - HSEARCH000058: Exception occurred org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/tmp/cyberdex_files/org.vtarc.CyberConnections.backend.entity.Organization/write.lock: java.nio.channels.OverlappingFileLockException
Primary Failure:
    Entity org.vtarc.CyberConnections.backend.entity.Organization  Id null  Work Type  org.hibernate.search.backend.PurgeAllLuceneWork

org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@/tmp/cyberdex_files/org.vtarc.CyberConnections.backend.entity.Organization/write.lock: java.nio.channels.OverlappingFileLockException
    at org.apache.lucene.store.Lock.obtain(Lock.java:89)
    at org.apache.lucene.index.IndexWriter.<init>(IndexWriter.java:755)
    at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.createNewIndexWriter(IndexWriterHolder.java:131)
    at org.hibernate.search.backend.impl.lucene.IndexWriterHolder.getIndexWriter(IndexWriterHolder.java:97)
    at org.hibernate.search.backend.impl.lucene.AbstractWorkspaceImpl.getIndexWriter(AbstractWorkspaceImpl.java:112)
    at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.applyUpdates(LuceneBackendQueueTask.java:81)
    at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.run(LuceneBackendQueueTask.java:47)
    at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.applyChangesets(SyncWorkProcessor.java:145)
    at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.run(SyncWorkProcessor.java:135)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.nio.channels.OverlappingFileLockException
    at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
    at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1108)
    at java.nio.channels.FileChannel.tryLock(FileChannel.java:1155)
    at org.apache.lucene.store.NativeFSLock.obtain(NativeFSLockFactory.java:169)
    at org.apache.lucene.store.Lock.obtain(Lock.java:96)
    ... 9 more

人员指数成功,组织失败。请注意,父目录也是jetty:jetty(user:group)。

[jetty@server org.vtarc.CyberConnections.backend.entity.Person]$ ls -l
-rw-r-----. 1 jetty jetty  1844 Oct 20 18:43 _9.fdt
-rw-r-----. 1 jetty jetty    67 Oct 20 18:43 _9.fdx
-rw-r-----. 1 jetty jetty  1310 Oct 20 18:43 _9.fnm
-rw-r-----. 1 jetty jetty  3687 Oct 20 18:43 _9_Lucene41_0.doc
-rw-r-----. 1 jetty jetty  4310 Oct 20 18:43 _9_Lucene41_0.pos
-rw-r-----. 1 jetty jetty 20500 Oct 20 18:43 _9_Lucene41_0.tim
-rw-r-----. 1 jetty jetty   576 Oct 20 18:43 _9_Lucene41_0.tip
-rw-r-----. 1 jetty jetty  1530 Oct 20 18:43 _9.nvd
-rw-r-----. 1 jetty jetty   171 Oct 20 18:43 _9.nvm
-rw-r-----. 1 jetty jetty   386 Oct 20 18:43 _9.si
-rw-r-----. 1 jetty jetty   102 Oct 20 18:43 segments_a
-rw-r-----. 1 jetty jetty    36 Oct 20 18:43 segments.gen
-rw-r-----. 1 jetty jetty     0 Oct 20 14:31 write.lock
[jetty@server org.vtarc.CyberConnections.backend.entity.Person]$ cd ../org.vtarc.CyberConnections.backend.entity.Organization/
[jetty@server org.vtarc.CyberConnections.backend.entity.Organization]$ ls -l
-rw-r-----. 1 jetty jetty 53 Oct 20 15:40 segments_5
-rw-r-----. 1 jetty jetty 36 Oct 20 15:40 segments.gen
-rw-r-----. 1 jetty jetty  0 Oct 20 14:31 write.lock

需要什么?

1 个答案:

答案 0 :(得分:1)

一种可能的解释是您正在为相同的配置创建多个SessionFactories / EntityManagerFactories,从而多次实例化Hibernate Search并在索引文件上创建锁冲突。如果是这样,那么,不要。另请参阅Hibernate search: persist causes sometimes OverlappingFileLockException

另一种可能的解释:这个版本的Hibernate Search真的很旧。您可能遇到了一个已经解决的错误。我知道有几个与已经解决的锁相关的错误,例如这个:https://stackoverflow.com/a/46284827/6692043