如何修复 LockObtainFailedException:锁定获取超时?
Posted
技术标签:
【中文标题】如何修复 LockObtainFailedException:锁定获取超时?【英文标题】:How to fix LockObtainFailedException: Lock obtain timed out? 【发布时间】:2014-09-03 16:52:23 【问题描述】:当我从 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:锁获取超时: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** DirectUpdateHandler2commits=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 测试框架 4.9.0 Oracle Java 1.7 Spring Data Solr 1.2.2.RELEASE IntelliJ 13.1.4 Gradle 1.12 在 Spock 中开发测试任何帮助将不胜感激。谢谢!
【问题讨论】:
【参考方案1】:我在测试中遇到了同样的问题,但 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.
【讨论】:
【参考方案2】:刚刚遇到类似的问题并已解决。
我在单元测试中使用EmbeddedSolrServer
,并在运行时动态创建新内核。
创建CoreContainer
时,请务必在测试后调用shutdown()。
还要确保所有SolrCore
实例在您的测试后都已关闭。
调用 coreContainer.create(CoreDescriptor, name, ...)
会打开一个 SolrCore,您必须手动关闭它。
通过传递 coreName 创建EmbeddedSolrServer
时,SolrCore 没有打开!每个请求/操作的打开和关闭由EmbeddedSolrServer
处理。
【讨论】:
【参考方案3】:好的,所以我可以通过更改来解决问题
<unlockOnStartup>true</unlockOnStartup>
在 solrconfig.xml 文件中。
【讨论】:
以上是关于如何修复 LockObtainFailedException:锁定获取超时?的主要内容,如果未能解决你的问题,请参考以下文章