25

We are using solr4.3 with master/slave setup, today I got the following error and solr stopped responding. What could be causing this,

 Caused by: org.apache.solr.common.SolrException: Index locked for write for core XXX
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:821)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:618)
    at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:949)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:984)
    at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:597)
    at org.apache.solr.core.CoreContainer$2.call(CoreContainer.java:592)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    ... 1 more
Caused by: org.apache.lucene.store.LockObtainFailedException: Index locked for write for core XX        at org.apache.solr.core.SolrCore.initIndex(SolrCore.java:484)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:745)
    ... 13 more
Cool Techie
  • 756
  • 2
  • 18
  • 39

8 Answers8

25

Delete file write.lock in folder /data/index/ for your core then restart tomcat. It will work.

Hieu Le
  • 2,106
  • 1
  • 23
  • 23
19

It seems the index has been locked during indexing.
Usually there would be a write.lock file within the index which needs to be removed to get it back.
The conditions can occur if the indexing breaks in between or other issues which may cause to lock file to be still in the index.

Check Forum

The write lock is due to the fact that an IndexWriter is always open in Solr even on the slaves.

Check for the Index Lock options which can handle the condition within configuration.

[An archived copy of the original link: https://web.archive.org/web/http://docs.lucidworks.com/display/solr/IndexConfig+in+SolrConfig ]

peak
  • 105,803
  • 17
  • 152
  • 177
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • What I am unable to understand is this happened on the slave, I can understand the lock happening on the master. Why would a slave lock? – Cool Techie Jul 03 '13 at 09:56
  • Thanks Jayandra, I did read up the lockType and also the fact this might happen in an OOM situation. What lockType would you suggest for a slave which is being used by multipl webapps? – Cool Techie Jul 03 '13 at 10:47
  • you can check for unlockOnStartup which would remove the lock fine and prevent these issues. – Jayendra Jul 03 '13 at 10:57
  • Just to add to this, I was using kill -9 after issuing a ./shutdown.sh on tomcat, since tomcat was taking very long to shutdown. Still haven't found why tomcat is taking this long, but this seems to be adding to the behavior. – Cool Techie Jul 06 '13 at 12:17
1

If you are using Rails,

just add into solr.xml this line

<lockType>simple</lockType>

its works for me)

Evseev Vadim
  • 314
  • 6
  • 6
  • 2
    What does it do? Please provide some documentation about this configuration value. Does it have any side effects Techie should know about? What does it have to do with rails? – Alexander Jul 05 '17 at 18:52
  • documentation is here https://cwiki.apache.org/confluence/display/solr/IndexConfig+in+SolrConfig see "lockType" there – Evseev Vadim Jul 06 '17 at 06:52
  • I've added it to the post, but I still don't get what it has to do with rails. Solr is solr - Rails is a programming language. – Alexander Jul 06 '17 at 10:19
  • its works for me I think that I have some bug in my Solr config or installation – Evseev Vadim Jul 06 '17 at 12:04
  • Not using rails, but worked for me. Restarted solr and problem solved! – Tomas Gonzalez Jun 05 '19 at 16:21
1

In some times this occurs because current user dont have permission in directory. Try using root and using -force for start solr.

  • 2
    oh no! looks like you posted the answer before finishing your sentence! Not to worry, you can always edit it to finish it. If you already have, ignore this comment. Edits don't show up right away, they have to be reviewed first, even on your own posts, which is a little silly, so I and the OP can't see your edit yet if it exists. – MMAdams Dec 19 '17 at 18:00
1

In my case this error occured when i try to create a new core in the path containing the index of an existing core e.g

/data/index/

This happened because i had changed the solrconfig.xml index data directory to move the default path to another location i called:

<dataDir>/data/index/</dataDir>

So reusing the solrconfig.xml to create a new core causes the error. Changing this to:

<dataDir>${solr.data.dir}/${solr.core.name}</dataDir>

Causes the index of a new core to be created in a path related to its core name and so write.lock permission issues with the index of an exisitng core are not encountered during the creation of the new core

0

Try to use : container.shutdown() after the indexing, it works if you want to update/search again without removing the file "write.lock".

Moujabr
  • 527
  • 1
  • 5
  • 12
0

check if the permissions are for root and change the permissions of the core files

0

Most likely this is due to files having the wrong ownership. Check permissions and ownerships.

If you still encounter error having done the above tasks, you may want to see the below;

Delete file write.lock in folder /data/index/ for your core then restart Tomcat Server.

Restart Tomcat Server in Linux:

<Tomcat Root>/bin>./catalina.sh stop

<Tomcat Root>/bin>./catalina.sh start
Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51