[
https://issues.apache.org/jira/browse/LUCENENET-135?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620982#action_12620982
]
Digy commented on LUCENENET-135:
--------------------------------
Hi,
1) SupportClass.patch fixes
"Index/TestIndexWriter/TestDocumentsWriterExceptionThreads"
2) In fact , There is no race condition in DocumentsWriter(at least for now).
It all started when I saw two threads entering the "GetThreadState" at the same
time which is a synchronized method. So, I falsely determined that it was a
race condition. And finally, It turned out to be a bug in ThreadClass.
ThreadClass'es static "Current" method always returns a new instance of
ThreadClass,
and because it is used as a key to HashTable
"threadBindings"(DocumentsWriter.GetThreadState),
{code}
ThreadState state = (ThreadState)
threadBindings[SupportClass.ThreadClass.Current()];
if (state == null)
{
...
threadBindings[SupportClass.ThreadClass.Current()] = state;
}
{code}
"State==null" never gets false and ,everytime, initializations of the
first-time call are made.
I think the patch is correct. But after applying that patch the following
simple test case fails with an exception "Index was outside the bounds of the
array".
{code}
[Test]
public void TestIndexWriter1()
{
RAMDirectory dir = new RAMDirectory();
IndexWriter wr = new IndexWriter(dir,new WhitespaceAnalyzer(),
true);
wr.SetRAMBufferSizeMB(0.1);
Document doc = new Document();
Field f1 = new Field("field1", "", Field.Store.YES,
Field.Index.TOKENIZED);
doc.Add(f1);
for (int i = 0; i < 200000; i++)
{
f1.SetValue("some text, some more text,some text, some more
text,some text, some more text,");
try
{
wr.AddDocument(doc);
//if (i % 100 == 0) wr.Flush(); //Make that pass
}
catch (Exception ex)
{
Console.WriteLine("loop:" + i + "\n" + ex.Message + "\n" +
ex.StackTrace);
throw ex;
}
}
wr.Close();
}
{code}
*Any Idea?*
PS1:*Uncommenting Flush statement in the code makes that test pass*
PS2: If you decide to close this issue, please take a look at the
DocumentsWriter.patch(which has nothing to do with any test case but applied to
Lucene.java after the release of 2.3.1)
DIGY
> Race condition in DocumentsWriter.UpdateDocument
> ------------------------------------------------
>
> Key: LUCENENET-135
> URL: https://issues.apache.org/jira/browse/LUCENENET-135
> Project: Lucene.Net
> Issue Type: Bug
> Environment: 2.3.1
> Reporter: Digy
> Attachments: DocumentsWriter+SupportClass.rar,
> DocumentsWriter-Temp.patch, DocumentsWriter.patch, DocumentsWriter.patch,
> SupportClass.patch, SupportClass.patch
>
>
> There is a race condition in DocumentsWriter.UpdateDocument. Locking the
> whole method solves the problem but this is not what is intended in java
> version
> (testcase: Index/TestIndexWriter/TestDocumentsWriterExceptionThreads)
> I am working on it.
> DIGY
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.