Solr索引文件被锁 java.nio.channels.OverlappingFileLockException

xiaoxiao2021-02-28  23

昨天把博客上线,今天早上起来发现昨天晚上Solr服务器出错了,到今天下午才有时间来解决,一个Tomcat放博客项目,另一个Tomcat放Solr服务器,配置了多个Solr Core,第一次重启Solr服务器所在的Tomcat,报错信息如下。

2018-05-18 14:06:01.173 ERROR (coreContainerWorkExecutor-2-thread-1) [ ] o.a.s.c.CoreContainer Error waiting for SolrCore to be created java.util.concurrent.ExecutionException: org.apache.solr.common.SolrException: Unable to create core [resource_core] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.solr.core.CoreContainer.lambda$load$14(CoreContainer.java:671) at com.codahale.metrics.InstrumentedExecutorService$InstrumentedRunnable.run(InstrumentedExecutorService.java:176) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor.lambda$execute$0(ExecutorUtil.java:188) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.solr.common.SolrException: Unable to create core [resource_core] at org.apache.solr.core.CoreContainer.createFromDescriptor(CoreContainer.java:1053) at org.apache.solr.core.CoreContainer.lambda$load$13(CoreContainer.java:642) at com.codahale.metrics.InstrumentedExecutorService$InstrumentedCallable.call(InstrumentedExecutorService.java:197) ... 5 more Caused by: org.apache.solr.common.SolrException at org.apache.solr.core.SolrCore.<init>(SolrCore.java:1008) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:863) at org.apache.solr.core.CoreContainer.createFromDescriptor(CoreContainer.java:1037) ... 7 more 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.NativeFSLockFactory.obtainFSLock(NativeFSLockFactory.java:126) at org.apache.lucene.store.FSLockFactory.obtainLock(FSLockFactory.java:41) at org.apache.lucene.store.BaseDirectory.obtainLock(BaseDirectory.java:45) at org.apache.lucene.store.FilterDirectory.obtainLock(FilterDirectory.java:104) at org.apache.solr.core.SolrCore.isWriterLocked(SolrCore.java:720) at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:742) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:954) ... 9 more

看到了一个OverlappingFileLockException,于是在网上找各种Lunece锁机制,Solr锁什么的,然后就是在core中修改solrconfig.xml文件,网上有看到在solrconfig.xml中<lockType>前面配置 <unlockOnStartup>true</unlockOnStartup>,配置了但是没用,于是我把<lockType>${solr.lock.type:native}</lockType>修改成<lockType>${solr.lock.type:simple}</lockType>,报错的信息不一样了。

2018-05-18 15:08:31.112 ERROR (coreContainerWorkExecutor-2-thread-1) [ ] o.a.s.c.CoreContainer Error waiting for SolrCore to be created java.util.concurrent.ExecutionException: org.apache.solr.common.SolrException: Unable to create core [resource_core] at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at org.apache.solr.core.CoreContainer.lambda$load$14(CoreContainer.java:671) at com.codahale.metrics.InstrumentedExecutorService$InstrumentedRunnable.run(InstrumentedExecutorService.java:176) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor.lambda$execute$0(ExecutorUtil.java:188) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: org.apache.solr.common.SolrException: Unable to create core [resource_core] at org.apache.solr.core.CoreContainer.createFromDescriptor(CoreContainer.java:1053) at org.apache.solr.core.CoreContainer.lambda$load$13(CoreContainer.java:642) at com.codahale.metrics.InstrumentedExecutorService$InstrumentedCallable.call(InstrumentedExecutorService.java:197) ... 5 more Caused by: org.apache.solr.common.SolrException: Index dir '/opt/solr-home/resource_core/data/index/' of core 'resource_core' is already locked. The most likely cause is another Solr server (or another solr core in this server) also configured to use this directory; other possible causes may be specific to lockType: simple at org.apache.solr.core.SolrCore.<init>(SolrCore.java:1008) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:863) at org.apache.solr.core.CoreContainer.createFromDescriptor(CoreContainer.java:1037) ... 7 more Caused by: org.apache.lucene.store.LockObtainFailedException: Index dir '/opt/solr-home/resource_core/data/index/' of core 'resource_core' is already locked. The most likely cause is another Solr server (or another solr core in this server) also configured to use this directory; other possible causes may be specific to lockType: simple at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:745) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:954) ... 9 more

我看到索引文件目录被锁了,提示是可能另一个Solr服务器也在使用这个目录,但是我的项目只有一个Solr服务器啊,于是重启Tomcat,看日志,结果发现Tomcat把Solr启动了两次,索引文件被锁的原因出来了,但是为什么Tomcat会将Solr启动两次呢,结果就是我配置了Tomcat的虚拟路径。

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="blog-solr" debug="0" reloadable="true" /> </Host>

参考https://blog.csdn.net/u011081244/article/details/62422013才知道原因为什么会启动两次。

参考https://jingyan.baidu.com/article/48206aeaf9422e216ad6b39b.html将项目放在webapps目录之外,然后再配置server.xml,重启Tomcat之后就正常了。

<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> <Context path="" docBase="/usr/tomcat/tomcat-solr/test-solr/blog-solr" debug="0" reloadable="true" /> </Host>

 

转载请注明原文地址: https://www.6miu.com/read-2650117.html

最新回复(0)