internal bool UpdateDocument(Document doc, Analyzer analyzer, Term delTerm)
{
// This call is synchronized but fast
DocumentsWriterThreadState state = GetThreadState(doc, delTerm);
DocState docState = state.docState;
docState.doc = doc;
docState.analyzer = analyzer;
bool doReturnFalse = false; // {{Aroush-2.9}} to handle return from finally clause
bool success = false;
try
{
// This call is not synchronized and does all the
// work
DocWriter perDoc;
try
{
perDoc = state.consumer.ProcessDocument();
}
finally
{
docState.Clear();
}
// This call is synchronized but fast
FinishDocument(state, perDoc);
success = true;
}
finally
{
if (!success)
{
lock (this)
{
if (aborting)
{
state.isIdle = true;
System.Threading.Monitor.PulseAll(this);
Abort();
}
else
{
skipDocWriter.docID = docState.docID;
bool success2 = false;
try
{
waitQueue.Add(skipDocWriter);
success2 = true;
}
finally
{
if (!success2)
{
state.isIdle = true;
System.Threading.Monitor.PulseAll(this);
Abort();
// return false; // {{Aroush-2.9}} this 'return false' is move to outside finally
doReturnFalse = true;
}
}
if (!doReturnFalse) // {{Aroush-2.9}} added because of the above 'return false' removal
{
state.isIdle = true;
System.Threading.Monitor.PulseAll(this);
// If this thread state had decided to flush, we
// must clear it so another thread can flush
if (state.doFlushAfter)
{
state.doFlushAfter = false;
flushPending = false;
System.Threading.Monitor.PulseAll(this);
}
// Immediately mark this document as deleted
// since likely it was partially added. This
// keeps indexing as "all or none" (atomic) when
// adding a document:
AddDeleteDocID(state.docState.docID);
}
}
}
}
}
if (doReturnFalse) // {{Aroush-2.9}} see comment abouve
{
return false;
}
return state.doFlushAfter || TimeToFlushDeletes();
}