Getting Index locked for write: CMS.Search.Lucene3.SearchLock exception in event log

balinder singh asked on February 14, 2020 19:20

I created a scheduled task which sync few fields on all the contacts in the system with external system. I have search index on contacts. During scheduled task run, I get following exception in my event log. See below. Search index gets rebuild seems fine though. I am guessing this has to do with my code calling Contact updates individually.

My questions are: * why I am seeing this ? * Does it have to do anything with my code calling Contact update individually using Kentico API? if so is there a way to bulk update Contacts using Kentico API. I guess I can directly update using SQL but I would prefer Kentico API way.

    var contactList = ContactInfoProvider.GetContacts().Columns(listOfColumnsToBeRetrived).WhereNotEmpty(whereNotEmptyColumnName);
foreach (ContactInfo contact in contactList)
            contact.SetValue("CustomField", "newvalue");
            // Saves the updated contact to the database
            // Ideally it should be a bulk update but not sure if it does this individually

Error detail in event log

Description:Message: Index locked for write: CMS.Search.Lucene3.SearchLock

Exception type: Lucene.Net.Store.LockObtainFailedException Stack trace: at Lucene.Net.Index.DirectoryReader.AcquireWriteLock() at Lucene.Net.Index.IndexReader.DeleteDocument(Int32 docNum) at Lucene.Net.Index.IndexReader.DeleteDocuments(Term term) at CMS.Search.Lucene3.LuceneIndexSearcher.Delete(String name, String value) at CMS.Search.SearchHelper.Delete(String fieldName, String value, SearchIndexInfo indexInfo) at CMS.Search.SearchHelper.Update(ILuceneSearchDocument iDoc, SearchIndexInfo indexInfo) at CMS.Search.SearchIndexer.ExecuteProcessTask(SearchTaskInfo sti) at CMS.Search.SearchIndexer.ExecuteTask(SearchTaskInfo sti) at CMS.Search.SearchTaskInfoProvider.ProcessSearchTasks() at CMS.Search.SearchTaskInfoProvider.RunInternal()

Correct Answer

Roman Hutnyk answered on February 15, 2020 15:18

I guess it could happen because each contact update triggers search index update. Anytime system attempts to update index for next contact update (in terms of index) of previous contact may not be completed yet, so index remains locked.

According to documentation you might want to disable automatic index update, but using scheduled task. You'll need to add following setting to web.config file

<add key="CMSProcessSearchTasksByScheduler" value="true" />

1 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.