lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r1060398 - in /lucene/java/branches/lucene_2_9: CHANGES.txt src/java/org/apache/lucene/index/SegmentInfo.java
Date Tue, 18 Jan 2011 14:45:03 GMT
Author: shaie
Date: Tue Jan 18 14:45:03 2011
New Revision: 1060398

URL: http://svn.apache.org/viewvc?rev=1060398&view=rev
Log:
LUCENE-2584: port fix to 2.9

Modified:
    lucene/java/branches/lucene_2_9/CHANGES.txt
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentInfo.java

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=1060398&r1=1060397&r2=1060398&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Tue Jan 18 14:45:03 2011
@@ -3,7 +3,10 @@ $Id$
 
 ======================= 2.9 branch (not yet released) ==================
 
-No changes.
+Bug fixes
+
+* LUCENE-2584: SegmentInfo.files() could hit ConcurrentModificationException if
+  called by multiple threads. (Alexander Kanarsky via Shai Erera)
 
 ======================= Release 2.9.4 2010-12-03 =======================
 

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentInfo.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentInfo.java?rev=1060398&r1=1060397&r2=1060398&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentInfo.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentInfo.java Tue
Jan 18 14:45:03 2011
@@ -22,11 +22,13 @@ import org.apache.lucene.store.IndexOutp
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.util.BitVector;
 import java.io.IOException;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Set;
 
 /**
  * Information about a segment such as it's name, directory, and files related
@@ -570,7 +572,7 @@ public final class SegmentInfo {
     return hasProx;
   }
 
-  private void addIfExists(List files, String fileName) throws IOException {
+  private void addIfExists(Set files, String fileName) throws IOException {
     if (dir.fileExists(fileName))
       files.add(fileName);
   }
@@ -588,16 +590,16 @@ public final class SegmentInfo {
       return files;
     }
     
-    files = new ArrayList();
+    Set filesSet = new HashSet();
     
     boolean useCompoundFile = getUseCompoundFile();
 
     if (useCompoundFile) {
-      files.add(name + "." + IndexFileNames.COMPOUND_FILE_EXTENSION);
+      filesSet.add(name + "." + IndexFileNames.COMPOUND_FILE_EXTENSION);
     } else {
       final String[] exts = IndexFileNames.NON_STORE_INDEX_EXTENSIONS;
       for(int i=0;i<exts.length;i++)
-        addIfExists(files, name + "." + exts[i]);
+        addIfExists(filesSet, name + "." + exts[i]);
     }
 
     if (docStoreOffset != -1) {
@@ -605,23 +607,23 @@ public final class SegmentInfo {
       // vectors) with other segments
       assert docStoreSegment != null;
       if (docStoreIsCompoundFile) {
-        files.add(docStoreSegment + "." + IndexFileNames.COMPOUND_FILE_STORE_EXTENSION);
+        filesSet.add(docStoreSegment + "." + IndexFileNames.COMPOUND_FILE_STORE_EXTENSION);
       } else {
         final String[] exts = IndexFileNames.STORE_INDEX_EXTENSIONS;
         for(int i=0;i<exts.length;i++)
-          addIfExists(files, docStoreSegment + "." + exts[i]);
+          addIfExists(filesSet, docStoreSegment + "." + exts[i]);
       }
     } else if (!useCompoundFile) {
       // We are not sharing, and, these files were not
       // included in the compound file
       final String[] exts = IndexFileNames.STORE_INDEX_EXTENSIONS;
       for(int i=0;i<exts.length;i++)
-        addIfExists(files, name + "." + exts[i]);
+        addIfExists(filesSet, name + "." + exts[i]);
     }
 
     String delFileName = IndexFileNames.fileNameFromGeneration(name, "." + IndexFileNames.DELETES_EXTENSION,
delGen);
     if (delFileName != null && (delGen >= YES || dir.fileExists(delFileName)))
{
-      files.add(delFileName);
+      filesSet.add(delFileName);
     }
 
     // Careful logic for norms files    
@@ -630,14 +632,14 @@ public final class SegmentInfo {
         long gen = normGen[i];
         if (gen >= YES) {
           // Definitely a separate norm file, with generation:
-          files.add(IndexFileNames.fileNameFromGeneration(name, "." + IndexFileNames.SEPARATE_NORMS_EXTENSION
+ i, gen));
+          filesSet.add(IndexFileNames.fileNameFromGeneration(name, "." + IndexFileNames.SEPARATE_NORMS_EXTENSION
+ i, gen));
         } else if (NO == gen) {
           // No separate norms but maybe plain norms
           // in the non compound file case:
           if (!hasSingleNormFile && !useCompoundFile) {
             String fileName = name + "." + IndexFileNames.PLAIN_NORMS_EXTENSION + i;
             if (dir.fileExists(fileName)) {
-              files.add(fileName);
+              filesSet.add(fileName);
             }
           }
         } else if (CHECK_DIR == gen) {
@@ -649,7 +651,7 @@ public final class SegmentInfo {
             fileName = name + "." + IndexFileNames.PLAIN_NORMS_EXTENSION + i;
           }
           if (fileName != null && dir.fileExists(fileName)) {
-            files.add(fileName);
+            filesSet.add(fileName);
           }
         }
       }
@@ -667,11 +669,11 @@ public final class SegmentInfo {
       for(int i=0;i<allFiles.length;i++) {
         String fileName = allFiles[i];
         if (filter.accept(null, fileName) && fileName.length() > prefixLength
&& Character.isDigit(fileName.charAt(prefixLength)) && fileName.startsWith(prefix))
{
-          files.add(fileName);
+          filesSet.add(fileName);
         }
       }
     }
-    return files;
+    return files = new ArrayList(filesSet);
   }
 
   /* Called whenever any change is made that affects which



Mime
View raw message