我的简单代码是
我在java WebServlet中运行此代码
solrDir = config.getServletContext().getRealPath("/lotiya");
container = new CoreContainer(solrDir);
container.load();
server = new EmbeddedSolrServer(container, "collection1");
solrParams = new ModifiableSolrParams();
solrParams = new ModifiableSolrParams();
solrParams.add(CommonParams.Q, "*:*");
//solrParams.set("qt", "/dataimport");
//solrParams.set("command", "full-import");
//solrParams.set("command", "reload-config");
solrParams.set("wt", "json");
QueryResponse queryResponse = server.query(solrParams);
for (SolrDocument document : queryResponse.getResults()) {
System.out.println(document);
}
第一次,当dataimport运行良好时。 由于" write.lock"第二次运行时出现异常。在我知道的索引中 一个解决方案是重启服务器并检查,但每次这种技术都不可能。那么,有没有任何方法可以重新索引。
像...一样的例外代码。
org.apache.solr.common.SolrException: SolrCore 'collection1' is not available due to init failure: Index locked for write for core collection1
at org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:827)
at org.apache.solr.client.solrj.embedded.EmbeddedSolrServer.request(EmbeddedSolrServer.java:110)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at solrjj.TestSolr.doGet(TestSolr.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.solr.common.SolrException: Index locked for write for core collection1
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:844)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:630)
at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:562)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:597)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:258)
at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:250)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
... 3 more
Caused by: org.apache.lucene.store.LockObtainFailedException: Index locked for write for core collection1
at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:496)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:761)
... 11 more
答案 0 :(得分:1)
我认为您正在使用Servlet。使用servlet的init()方法尝试以下代码。
container = new CoreContainer(solrDir);
container.load();
server = new EmbeddedSolrServer(container, "collection1");
solrParams = new ModifiableSolrParams();
原因:当servlet加载初始化时,每次创建容器对象和已经使用collection1的服务器对象时,为什么会引发write.lock的错误