Apache Solr open-source search software
grab commit lock when getting current version: LUCENE-481
Yonik Seeley9a9da2f7703e
diff --git a/CHANGES.txt b/CHANGES.txtindex c22b53d48ec..1274a91a778 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -322,6 +322,10 @@ Bug fixes20. 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)+Optimizations1. Disk usage (peak requirements during indexing and optimization)diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.javaindex 4742320f375..9240b47bd30 100644--- a/src/java/org/apache/lucene/index/IndexReader.java+++ b/src/java/org/apache/lucene/index/IndexReader.java@@ -228,7 +228,21 @@ public abstract class IndexReader {* @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 @@ public abstract class IndexReader {* @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;}/**