我在一个项目上使用休眠搜索,而MassIndexer仅索引我的部分记录。例如,在一个表中,我有601条记录,但是根据我的当前设置,它仅索引300个文档。
我当前的设置是:
txtEm.createIndexer( )
.batchSizeToLoadObjects( 25 )
.threadsToLoadObjects( 12 )
.cacheMode( CacheMode.NORMAL )
.idFetchSize( 150 )
.transactionTimeout( 1800 )
.startAndWait();
我已经用batchSizeToLoadObjects(1000)
进行了测试,它似乎索引了我的所有记录。但是我正在从事的这个项目是新的,并且数据库每个表只有几条记录。我担心当表增长时,实体将无法正确索引。
有人可以帮忙吗?我已经搜索了一些答案和配置最佳实践,但是找不到解决方案。
索引表时生成的日志可能会有所帮助。见下文:
2018-07-02 17:45:52.794 INFO 648 --- [ntifierloader-1] o.h.s.b.i.SimpleIndexingProgressMonitor : HSEARCH000027: Going to reindex 601 entities
2018-07-02 17:45:52.812 ERROR 648 --- [ntifierloader-1] o.h.s.exception.impl.LogErrorHandler : HSEARCH000058: HSEARCH000211: An exception occurred while the MassIndexer was fetching the primary identifiers list
org.hibernate.SessionException: Session was already closed!
at org.hibernate.internal.StatelessSessionImpl.managedClose(StatelessSessionImpl.java:378) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.StatelessSessionImpl.close(StatelessSessionImpl.java:358) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.search.batchindexing.impl.IdentifierProducer.inTransactionWrapper(IdentifierProducer.java:118) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.IdentifierProducer.run(IdentifierProducer.java:85) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.runWithErrorHandler(OptionallyWrapInJTATransaction.java:69) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.ErrorHandledRunnable.run(ErrorHandledRunnable.java:32) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_172]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_172]
at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_172]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_172]
2018-07-02 17:45:52.883 INFO 648 --- [entityloader-10] o.h.s.b.i.SimpleIndexingProgressMonitor : HSEARCH000030: 200 documents indexed in 902 ms
2018-07-02 17:45:52.883 INFO 648 --- [entityloader-10] o.h.s.b.i.SimpleIndexingProgressMonitor : HSEARCH000031: Indexing speed: 221,729492 documents/second; progress: 25,54%
2018-07-02 17:45:52.886 ERROR 648 --- [entityloader-10] s.b.i.IdentifierConsumerDocumentProducer : HSEARCH000065: Error while rolling back transaction after Session is closed!
org.hibernate.SessionException: Session is closed!
at org.hibernate.internal.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:132) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:311) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.rollbackTransaction(IdentifierConsumerDocumentProducer.java:205) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.loadList(IdentifierConsumerDocumentProducer.java:182) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.loadAllFromQueue(IdentifierConsumerDocumentProducer.java:140) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at org.hibernate.search.batchindexing.impl.IdentifierConsumerDocumentProducer.run(IdentifierConsumerDocumentProducer.java:117) ~[hibernate-search-orm-5.6.4.Final.jar:5.6.4.Final]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_172]
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) [na:1.8.0_172]
at java.util.concurrent.FutureTask.run(FutureTask.java) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_172]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_172]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_172]
这种SessionException
也会发生,我找不到解决方案。
创建索引的方法用@Transacional
注释。
我正在使用Spring Boot 1.5.6和Hibernate Search 5.6.4
答案 0 :(得分:0)
您可能以某种方式在质量索引器仍在使用它们时关闭会话。也许您正在使用某些特殊设置或集成功能,这些设置或集成功能在单笔交易后会自动关闭会话?
要确定是否存在,请以调试模式启动批量索引编制过程,并将断点置于org.hibernate.internal.SessionImpl#close
中,或将org.hibernate.internal.SessionImpl
的日志级别设置为TRACE。然后查看是否在批量索引停止之前关闭了会话:如果是,则代码中有问题,您应该延迟关闭直到批量索引完成。
答案 1 :(得分:0)
在完成Hibernate Search之前,您的数据库连接已关闭。
您正在运行连接池吗?确保它没有过早收回它认为被放弃的连接。
以c3p0为例,通过设置
hibernate.c3p0.unreturnedConnectionTimeout
到配置文件中的3600左右。
如果现在可以正确编制索引,则您有答案。