如何修复LockObtainFailedException:Lock获取超时?

时间:2014-09-03 16:52:23

标签: exception solr spring-data-solr

当我从Gradle任务运行它时,我的集成测试失败了。

org.springframework.data.solr.UncategorizedSolrException: **SolrCore 'collection1' is not available due to init failure: Error opening new searcher; nested exception is org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Error opening new searcher**
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:122)
at org.springframework.data.solr.core.SolrTemplate.saveDocuments(SolrTemplate.java:206)
at org.springframework.data.solr.core.SolrTemplate.saveDocuments(SolrTemplate.java:201)

org.apache.lucene.store.LockObtainFailedException:Lock获取超时:NativeFSLock@/opt/solr/example/solr/collection1/data/index/write.lock

当我在Intellij中直接运行集成测试时,测试成功运行。这是我对嵌入式服务器的bean定义。我添加了destroyMethod,它没有任何效果。

 @Bean(destroyMethod = "shutdown")
public SolrServer solrServer(org.apache.commons.configuration.Configuration configuration)  {

    EmbeddedSolrServerFactory factory;
    try {
        factory = new EmbeddedSolrServerFactory(configuration.getString("solr.home"));
    } catch (ParserConfigurationException | IOException | SAXException e) {
        String errorMsg = "Encountered an exception while initializing the SolrServer bean.";
        log.error(errorMsg, e);
        throw new OrdersClientRuntimeException(errorMsg, e);
    }
    return factory.getSolrServer();
}

以下是日志。一切似乎都在正常关闭。

2014-09-02 17:32:15.757 thread="Thread-6" level="DEBUG" logger="o.s.b.f.s.DisposableBeanAdapter" - **Invoking destroy method 'shutdown' on bean with name 'solrServer'**
2014-09-02 17:32:15.759 thread="Thread-8" level="DEBUG" logger="o.s.b.f.s.DefaultListableBeanFactory" - Retrieved dependent beans for bean 'solrDocumentRepository': [net.nike.orders.client.search.repository.DocumentRepositorySpec]
2014-09-02 17:32:15.759 thread="Thread-6" level="INFO " logger="org.apache.solr.core.CoreContainer" - **Shutting down CoreContainer instance=179265569**
2014-09-02 17:32:15.760 thread="Thread-8" level="DEBUG" logger="o.s.b.f.s.DisposableBeanAdapter" - **Invoking destroy method 'shutdown' on bean with name 'solrServer'**
2014-09-02 17:32:15.760 thread="Thread-8" level="INFO " logger="org.apache.solr.core.CoreContainer" - **Shutting down CoreContainer instance=1604485329**
2014-09-02 17:32:15.762 thread="Thread-6" level="INFO " logger="org.apache.solr.core.SolrCore" - [collection1]  **CLOSING SolrCore** org.apache.solr.core.SolrCore@28da98e2
2014-09-02 17:32:15.769 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - **Connection manager is shutting down**
2014-09-02 17:32:15.769 thread="Thread-6" level="INFO " logger="**org.apache.solr.update.UpdateHandler" - closing** DirectUpdateHandler2{commits=23,autocommit maxTime=15000ms,autocommits=0,soft autocommits=2,optimizes=0,rollbacks=0,expungeDeletes=0,docsPending=0,adds=0,deletesById=0,deletesByQuery=0,errors=0,cumulative_adds=33,cumulative_deletesById=32,cumulative_deletesByQuery=0,cumulative_errors=0,transaction_logs_total_size=5302,transaction_logs_total_number=10}
2014-09-02 17:32:15.771 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager shut down
2014-09-02 17:32:15.773 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager is shutting down
2014-09-02 17:32:15.774 thread="Thread-8" level="DEBUG" logger="o.a.h.i.c.PoolingClientConnectionManager" - Connection manager shut down

这是我的环境信息:

  • Linux Mint 17
  • Solr 4.9.0
  • Solr Test Framework 4.9.0
  • Oracle Java 1.7
  • Spring Data Solr 1.2.2.RELEASE
  • IntelliJ 13.1.4
  • Gradle 1.12
  • 测试是在Spock中开发的。

非常感谢任何帮助。谢谢!

3 个答案:

答案 0 :(得分:2)

我的测试遇到了同样的问题但是unlockOnStartup标志对我没用。我最终改变了锁定类型(并将unlockOnStartup注释掉了):

<lockType>${solr.lock.type:single}</lockType>
<!--<unlockOnStartup>true</unlockOnStartup>-->

关于默认锁定类型(本机)的说明让我觉得我不会在测试运行之间关闭服务器,但我还没有找到它:(

         native = NativeFSLockFactory - uses OS native file locking.
                  Do not use when multiple solr webapps in the same
                  JVM are attempting to share a single index.

答案 1 :(得分:0)

刚刚遇到类似问题并修复了它。

我在单元测试中使用EmbeddedSolrServer并在运行时动态创建新内核。

创建CoreContainer时,请务必在测试后调用shutdown()。

还要确保在测试后关闭所有SolrCore个实例。

调用coreContainer.create(CoreDescriptor, name, ...)会打开一个必须手动关闭的SolrCore。

通过传递coreName创建EmbeddedSolrServer时,SolrCore未打开!每个请求/操作都由EmbeddedSolrServer处理打开和关闭。

答案 2 :(得分:-1)

好的,我可以通过更改

解决问题
<unlockOnStartup>true</unlockOnStartup>

在solrconfig.xml文件中。