【问题标题】:Hibernate Search indexing only part of my entitiesHibernate Search 仅索引我的部分实体
【发布时间】:2018-07-02 20:58:24
【问题描述】:

我在一个项目上使用休眠搜索,而 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

【问题讨论】:

    标签: java hibernate spring-boot hibernate-search


    【解决方案1】:

    您可能会在质量索引器仍在使用会话时以某种方式关闭会话。也许您正在使用一些奇特的设置或集成在单次事务后自动关闭会话?

    要确定是否是,请在调试模式下启动批量索引进程并在org.hibernate.internal.SessionImpl#close 中放置一个断点,或者将org.hibernate.internal.SessionImpl 的日志级别设置为TRACE。然后查看是否在批量索引停止之前关闭了会话:如果是,则您的代码中有问题,您应该延迟关闭,直到批量索引完成。

    【讨论】:

    • 调试应用程序,我已经能够确定质量索引器运行每个实体的第一批而不是终止会话。并且存储在数据库中的记录数与batchSizeToLoadObjectsthreadsToLoadObjects 属性成正比...例如:batch = 25 with 12 个线程导致只有 300 条记录被索引...我使用 Spring Boot它,hibernate的SessionImpl类是StatelessSessionImpl.class..它们之间有什么联系吗?
    • 这看起来很奇怪。您可能需要仔细检查您的事务配置。如果那里没有什么特别的,也许我们可以创建一个最小的复制器并在our JIRA instance 上创建一张票,这样我们可以看看?我们提供测试用例模板来帮助您做到这一点:github.com/hibernate/hibernate-test-case-templates/tree/master/…
    【解决方案2】:

    您的数据库连接在 Hibernate Search 完成之前被关闭。

    您是否正在运行连接池?确保它不会过早回收它认为已放弃的连接。

    以 c3p0 为例,通过设置进行测试 hibernate.c3p0.unreturnedConnectionTimeout 到配置文件中的 3600 之类的高值。

    如果它现在索引正确,你就有答案了。

    【讨论】:

      猜你喜欢
      • 2014-12-29
      • 2011-11-20
      • 1970-01-01
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多