lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bernhard Messer <Bernhard.Mes...@intrafind.de>
Subject Re: optimize TermVectorsReader, remove synchronization from code
Date Wed, 18 Aug 2004 09:14:41 GMT
Otis,

i will check everything tonight and add a new patch to Bugzilla.

regards
Bernhard

Otis Gospodnetic wrote:

>I was going to consider applying this, but the included diff has
>wrapped lines.  Is there a Bugzilla entry with this code attached?
>
>Also, is there only SegmentReader.java diff here, or am I missing a
>piece of diff?  I don't see any synchronized methods/blocks removed
>from the code, so I'm confused about this optimization.
>
>Otis
>
>--- Bernhard Messer <Bernhard.Messer@intrafind.de> wrote:
>
>  
>
>>Sorry, but there was a bug in the patch i provided several minutes
>>ago. 
>>A NullpointerException can occur in SegmentReader doClose method. The
>>
>>change in the new diff file checks if the ThreadLocal object was
>>created 
>>and is not null before trying to get the TermVectorReader from it.
>>
>>best regards
>>Bernhard
>>
>>    
>>
>>>Index: SegmentReader.java
>>>      
>>>
>>===================================================================
>>RCS file:
>>
>>    
>>
>/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/SegmentReader.java,v
>  
>
>>retrieving revision 1.25
>>diff -u -r1.25 SegmentReader.java
>>--- SegmentReader.java	11 Aug 2004 17:37:52 -0000	1.25
>>+++ SegmentReader.java	15 Aug 2004 15:07:47 -0000
>>@@ -42,8 +42,7 @@
>>   private FieldsReader fieldsReader;
>> 
>>   TermInfosReader tis;
>>-  TermVectorsReader termVectorsReader;
>>-
>>+  
>>   BitVector deletedDocs = null;
>>   private boolean deletedDocsDirty = false;
>>   private boolean normsDirty = false;
>>@@ -51,6 +50,8 @@
>> 
>>   InputStream freqStream;
>>   InputStream proxStream;
>>+  
>>+  private ThreadLocal termVectorsLocal = null;
>> 
>>   // Compound File Reader when based on a compound file segment
>>   CompoundFileReader cfsReader = null;
>>@@ -128,7 +129,17 @@
>>     openNorms(cfsDir);
>> 
>>     if (fieldInfos.hasVectors()) { // open term vector files only as
>>needed
>>-      termVectorsReader = new TermVectorsReader(cfsDir, segment,
>>fieldInfos);
>>+    	final Directory dir = cfsDir;
>>+    	termVectorsLocal = new ThreadLocal() {
>>+    		protected synchronized Object initialValue() {
>>+    			try {
>>+    				return new TermVectorsReader(dir, segment, fieldInfos);
>>+    			} catch (IOException ioe) {
>>+    				ioe.printStackTrace();
>>+    				return null;
>>+    			}
>>+    		}
>>+    	};
>>     }
>>   }
>> 
>>@@ -164,8 +175,13 @@
>>       proxStream.close();
>> 
>>     closeNorms();
>>-    if (termVectorsReader != null) termVectorsReader.close();
>>-
>>+    if (termVectorsLocal != null) {
>>+    	TermVectorsReader termVectorsReader =
>>(TermVectorsReader)termVectorsLocal.get();
>>+    	if (termVectorsReader != null) {
>>+    		termVectorsReader.close();
>>+    	}
>>+    }
>>+    
>>     if (cfsReader != null)
>>       cfsReader.close();
>>   }
>>@@ -408,6 +424,15 @@
>>     FieldInfo fi = fieldInfos.fieldInfo(field);
>>     if (fi == null || !fi.storeTermVector) return null;
>> 
>>+    if (termVectorsLocal == null) {
>>+    	return null;
>>+    }
>>+    
>>+    TermVectorsReader termVectorsReader =
>>(TermVectorsReader)termVectorsLocal.get();
>>+  	if (termVectorsReader == null) {
>>+  		return null;
>>+  	}
>>+
>>     return termVectorsReader.get(docNumber, field);
>>   }
>> 
>>@@ -419,9 +444,14 @@
>>    *  If no such fields existed, the method returns null.
>>    */
>>   public TermFreqVector[] getTermFreqVectors(int docNumber) {
>>-    if (termVectorsReader == null)
>>-      return null;
>>-
>>+  	if (termVectorsLocal == null) {
>>+    	return null;
>>+    }
>>+  	
>>+  	TermVectorsReader termVectorsReader =
>>(TermVectorsReader)termVectorsLocal.get();
>>+  	if (termVectorsReader == null) {
>>+  		return null;
>>+  	}
>>     return termVectorsReader.get(docNumber);
>>   }
>> }
>>
>>    
>>
>---------------------------------------------------------------------
>  
>
>>To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: lucene-dev-help@jakarta.apache.org
>
>  
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message