Title: Calling Commit on an index that is currently been merged in Lucene
Tags: lucene
Question: 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&gt; metaData = new Dictionary<string,string&gt;();
metaData.Add("FileName", /*full path to the serialized file*/);
writer.Commit(metaData);
(Searcher process code)
IndexReader r2 = //IndexRead.Open...
Dictionary<string,string&gt; 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?
Comment: What version of Lucene are you using?


Here is another answer: 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..
Comment for this answer: thanks for the reply. You are right, I wasnt clear enough with in question. I updated my post with my goal, hopes it a bit clearer.
Comment for this answer: generating field cache is time consuming - around 12 seconds for index containing 5M documents.
Comment for this answer: I don't understand why you don't use the field cache directly
Comment for this answer: Have you tried to consume the field cache per segment? Looks like what you really need is DocValues (available in Lucene Java 4.0), don't know what the status is for Lucene.NET.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:10/28/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<lucene>', 'Title': 'Calling Commit on an index that is currently been merged in Lucene', 'ViewCount': 487, 'id': 13110780, 'user_AboutMe': None, 'user_AccountId': 1211910.0, 'user_DisplayName': 'Pini Salim', 'user_Reputation': 151.0, 'user_Views': 15.0, 'user_id': 1180298.0}}