Calling Commit on an index that is currently been

2019-09-10 19:27发布

问题:

My question is regarded to Lucene .NET 2.9.2

Say I updated an index using IndexWriter, and that caused the scheduler to start merging segments in the backround. What will happen if i'll call Commit before the merge was completed? will the thread that called Commit will be blocked and wait for merge to finish, or the two threads are independent?

The answer is very important to my search implementation, since I rely on the FieldCache for performance issues, and if Commit wont wait for the merge to finish, I might get wrong DocIds...

Update:

What I am trying to do is a mapping between DocId to Appliciation Id - so I will not need to fetch stored value of my application Id when using IndexSearcher Search method. So I am trying to build the mapping during indexing, save that mapping to a binary file - and in my search - load that file into an array (in-memory...). So the file version must consist with the IndexReader (hope it was clear...)

For example: (Index process code)

IndexWriter writer = //initialize writer

//modify index using the writer add\delete\update doc methods...

//get updated reader to the index
IndexReader r1= wrtier.GetReader();

//read all values for all documents for specific field name.

long[] ids = FieldCache_Fields.DEFAULT.GetLongs(r1, "ID");

//serialize the array to a file (code not provided)

Dictionary<string,string> metaData = new Dictionary<string,string>();
metaData.Add("FileName", /*full path to the serialized file*/);
writer.Commit(metaData);

(Searcher process code)

IndexReader r2 = //IndexRead.Open...
Dictionary<string,string> metaData = r2.GetCommitUserData()

string fullPathToFile = metaData["FileName"];  //get the file name that was serialized

//load the array from the file (=deserialize file)
long[] ids = //load from file

//now I can convert internal DocId to my Application Id, and save time instead of fetching data from the stored field (which takes more time...)

Basically my question is that: Is there any chance that the DocIds of the two readers r1 and r2 wont fit, under the assumption that there were no other modifications to the index?

回答1:

Background merging won't block your commits.

But I don't understand your FieldCache issue : IndexReaders being immutable, a fieldcache instance can never become invalid..



标签: lucene