失敗,我有碼頭9.2上運行的Java應用程序。兩者都使用相同版本的Jetty。索引器在部署後首次運行應用程序。我在Netbeans的Windows 10開發箱中沒有遇到任何問題。當我把它放在一臺linux機器上時,它不工作,我只有SSH訪問權和有限權限。的Lucene索引適用於Windows,Linux上的
Java代碼,類人首先運行,類組織運行第二。無論是在同一個Hibernate Session
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: [email protected]/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: [email protected]/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)。
[[email protected] 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
[[email protected] org.vtarc.CyberConnections.backend.entity.Person]$ cd ../org.vtarc.CyberConnections.backend.entity.Organization/
[[email protected] 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
還需要什麼嗎?
雖然我在兩個地方創建了一個Hibernate Session,第一個發生在servlet初始化並且在索引器完成後關閉。直到主UI稍後初始化,第二個會話纔開始。這一個留在範圍內。 – AFowler
它似乎是它的任一選項2號或一些競賽條件。我改變了日誌從信息調試和一切工作。所以,更多日誌會導致應用程序運行速度稍慢,這使得所有事情都能以成功的方式發生。等待另一項測試,看看這個理論是否正確。 – AFowler
@AFowler請注意,我說的是會話*工廠*不會話。並行使用多個會話應該可以正常工作,但使用相同索引的多個SessionFactory不會。我說:「*應*做工精細」,因爲我已經講過了,這是一個老版本的Hibernate Search的,並可能是馬車。 –