Return-Path: Delivered-To: apmail-lucene-java-dev-archive@www.apache.org Received: (qmail 4339 invoked from network); 31 Oct 2007 01:47:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Oct 2007 01:47:18 -0000 Received: (qmail 8431 invoked by uid 500); 31 Oct 2007 01:46:59 -0000 Delivered-To: apmail-lucene-java-dev-archive@lucene.apache.org Received: (qmail 8388 invoked by uid 500); 31 Oct 2007 01:46:59 -0000 Mailing-List: contact java-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-dev@lucene.apache.org Delivered-To: mailing list java-dev@lucene.apache.org Received: (qmail 8377 invoked by uid 99); 31 Oct 2007 01:46:59 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 Oct 2007 18:46:59 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2007 01:47:11 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D6CB571422B for ; Tue, 30 Oct 2007 18:46:50 -0700 (PDT) Message-ID: <32397589.1193795210877.JavaMail.jira@brutus> Date: Tue, 30 Oct 2007 18:46:50 -0700 (PDT) From: "Yonik Seeley (JIRA)" To: java-dev@lucene.apache.org Subject: [jira] Commented: (LUCENE-1033) FieldsReader Thread Safety In-Reply-To: <17092702.1193348930772.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/LUCENE-1033?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12538973 ] Yonik Seeley commented on LUCENE-1033: -------------------------------------- Hi Michael, you are correct that FieldsReader is not thread-safe, but that's currently by design. The SegmentReader holding the FieldsReader synchronizes when using it to read fields (see document()). Do you see a path were the same FieldsReader is used without synchronization on the same object? > FieldsReader Thread Safety > -------------------------- > > Key: LUCENE-1033 > URL: https://issues.apache.org/jira/browse/LUCENE-1033 > Project: Lucene - Java > Issue Type: Bug > Components: Search > Affects Versions: 2.2 > Environment: Java SDK 1.5.X, Linux & FreeBSD > Reporter: Michael Klatt > Priority: Minor > > From what I've read, the IndexSearcher is supposed to be thread safe. However, I don't think that the FieldsReader class (used by the IndexReader, and in turn used by the IndexSearcher) is thread safe. I have one IndexSearcher that I use with all my threads, and what appears to happen in Lucene 2.2 is that the same FieldsReader object is shared by all threads. The private "fieldStream" and "indexStream" attributes both have file pointers which makes them not thread-safe. > For instance, in the "doc" method of FieldsReader: > fieldsStream.seek(position); > Document doc = new Document(); > int numFields = fieldsStream.readVInt(); > for (int i = 0; i < numFields; i++) { > int fieldNumber = fieldsStream.readVInt(); > FieldInfo fi = fieldInfos.fieldInfo(fieldNumber); > FieldSelectorResult acceptField = fieldSelector == null ? FieldSelectorResult.LOAD : fieldSelector.accept(fi.name); > Another thread can seek to another position, so the readVInt calls are reading the wrong location in the stream. This is a race condition and only shows up when a lot of document field data is being read. When I synchronized the doc method, the problem went away. Another solution would be to use separate IndexSearchers, or to clone the FIeldsReader for each thread (I have not investigated either solution). > I encountered this on Lucene 2.2, but I think the problem is still in the trunk. I was making a modification to the source code which caused the problem to be exaggerated, otherwise I probably wouldn't have discovered it. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org For additional commands, e-mail: java-dev-help@lucene.apache.org