lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicholas Paldino <casper...@caspershouse.com>
Subject Re: File locking
Date Mon, 08 Apr 2013 10:20:45 GMT
Richard,

Lucene takes exclusive file locks on the index files when using the file directory, so having
multiple processes access the same files is a problem.

The recommended course of action is to create a service which uses Lucene and then can be
called from any number of processes.

- Nick

On Apr 5, 2013, at 6:20 AM, "Richard Wilde" <richard@wildesoft.net> wrote:

> I have deployed my application on Rackspace cloud (have 3-4 nodes running
> iis all sharing the same files) and am running into issues with:-
> 
> 
> 
> The process cannot access the file
> '\\fs1-n01\stor1wc1dfw1\381858\799525\somedomain.com\web\content\App_Data\Lu
> ceneIndex\write.lock' because it is being used by another process.
> 
> 
> 
> I am not sure why I am running into this issue, the code for this error is:-
> 
> 
> 
> public void Delete(long id, string type)
> 
> {
> 
>         directory = FSDirectory.Open(new
> DirectoryInfo(Settings.LuceneBaseDir));
> 
>         var writer = new IndexWriter(directory, analyzer, false,
> IndexWriter.MaxFieldLength.LIMITED);
> 
>         var queryParser = new QueryParser(Version.LUCENE_29, "Extract",
> analyzer);
> 
>         var special = string.Format("Id:{0} AND Type:{1}", id, type);
> 
>         writer.DeleteDocuments(queryParser.Parse(special));
> 
>         writer.Commit();
> 
>         writer.Close();
> 
>         directory.Close();
> 
> }
> 
> 
> 
> I have also code that indexes like:-
> 
> 
> 
>        public void Index(Document document)
> 
>        {
> 
>            directory = FSDirectory.Open(new
> DirectoryInfo(Settings.LuceneBaseDir));
> 
>            var writer = new IndexWriter(directory, analyzer, false,
> IndexWriter.MaxFieldLength.LIMITED);
> 
>            writer.AddDocument(document);
> 
>            writer.Close();
> 
>            directory.Close();
> 
>        }
> 
> 
> 
>      public void Index(Contact entity)
> 
>      {
> 
>         indexer.Index(GetDocument(entity));
> 
>      }
> 
> 
> 
> public Document GetDocument(Contact entity)
> 
> {
> 
>    var mytext = entity.ToStringExtension();
> 
>    var doc = new Document();
> 
>    doc.Add(new Field(IndexColumns.Extract.ToString(), mytext,
> Field.Store.YES, Field.Index.ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Type.ToString(), DocumentType,
> Field.Store.YES, Field.Index.ANALYZED_NO_NORMS));
> 
>    doc.Add(new Field(IndexColumns.ClientId.ToString(),
> entity.Client.Id.ToString(), Field.Store.YES,
> Field.Index.ANALYZED_NO_NORMS));
> 
>    doc.Add(new Field(IndexColumns.Title.ToString(), entity.Firstname + " "
> + entity.Lastname, Field.Store.YES, Field.Index.NOT_ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Content.ToString(), entity.Company,
> Field.Store.YES, Field.Index.NOT_ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Misc1.ToString(), entity.Phone,
> Field.Store.YES, Field.Index.NOT_ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Misc2.ToString(),
> entity.Email.ToString(CultureInfo.InvariantCulture), Field.Store.YES,
> Field.Index.NOT_ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Category.ToString(), entity.Category,
> Field.Store.YES, Field.Index.NOT_ANALYZED));
> 
>    doc.Add(new Field(IndexColumns.Id.ToString(),
> entity.Id.ToString(CultureInfo.InvariantCulture), Field.Store.YES,
> Field.Index.NOT_ANALYZED));
> 
>    return doc;
> 
> }
> 
> 
> 
> 
> 
> The error is intermittent but seems to happen when I delete/insert a
> document. I have a background service (web based) that may also be writing
> documents to the index every 30 seconds or so.. 
> 
> I am on version 2.9.4.2, should I upgrade to 3.0.3 bearing in mind I am
> running in Partial Trust and I recall reading an email regarding some
> problems with the release (I might be mistaken)
> 
> 
> 
> I suspect I am doing something stupid not sure how I can diagnose the
> problem?
> 
> 
> 
> Thanks
> 
> Rippo
> 
> 
> 
> 
> 

Mime
View raw message