lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r358685 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/index/IndexReader.java
Date Fri, 23 Dec 2005 02:38:28 GMT
Author: yonik
Date: Thu Dec 22 18:38:23 2005
New Revision: 358685

URL: http://svn.apache.org/viewcvs?rev=358685&view=rev
Log:
grab commit lock when getting current version: LUCENE-481

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=358685&r1=358684&r2=358685&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Dec 22 18:38:23 2005
@@ -322,6 +322,10 @@
 20. Fixed MultiReader.undeleteAll() to correctly update numDocs.
     (Robert Kirchgessner via Doug Cutting, LUCENE-479)
 
+21. Race condition in IndexReader.getCurrentVersion() and isCurrent()
+    fixed by aquiring the commit lock.
+    (Luc Vanlerberghe via Yonik Seeley, LUCENE-481)
+
 Optimizations
      
  1. Disk usage (peak requirements during indexing and optimization)

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=358685&r1=358684&r2=358685&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Thu Dec 22 18:38:23
2005
@@ -228,7 +228,21 @@
    * @throws IOException if segments file cannot be read.
    */
   public static long getCurrentVersion(Directory directory) throws IOException {
-    return SegmentInfos.readCurrentVersion(directory);
+    synchronized (directory) {                 // in- & inter-process sync
+      Lock commitLock=directory.makeLock(IndexWriter.COMMIT_LOCK_NAME);
+      
+      boolean locked=false;
+      
+      try {
+         locked=commitLock.obtain(IndexWriter.COMMIT_LOCK_TIMEOUT);
+         
+         return SegmentInfos.readCurrentVersion(directory);
+      } finally {
+        if (locked) {
+          commitLock.release();
+        }
+      }
+    }
   }
   
   /**
@@ -246,10 +260,21 @@
    * @throws IOException
    */
   public boolean isCurrent() throws IOException {
-    if (SegmentInfos.readCurrentVersion(directory) != segmentInfos.getVersion()) {
-      return false;
+    synchronized (directory) {                 // in- & inter-process sync
+      Lock commitLock=directory.makeLock(IndexWriter.COMMIT_LOCK_NAME);
+      
+      boolean locked=false;
+      
+      try {
+         locked=commitLock.obtain(IndexWriter.COMMIT_LOCK_TIMEOUT);
+         
+         return SegmentInfos.readCurrentVersion(directory) == segmentInfos.getVersion();
+      } finally {
+        if (locked) {
+          commitLock.release();
+        }
+      }
     }
-    return true;
   }
 
   /**



Mime
View raw message