You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/06/11 11:45:04 UTC
svn commit: r953628 - in /lucene/dev/trunk/lucene: CHANGES.txt
src/java/org/apache/lucene/index/IndexFileDeleter.java
src/test/org/apache/lucene/index/TestIndexWriter.java
Author: mikemccand
Date: Fri Jun 11 09:45:04 2010
New Revision: 953628
URL: http://svn.apache.org/viewvc?rev=953628&view=rev
Log:
LUCENE-2496: don't throw NPE on trying to CREATE over a corrupt index
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=953628&r1=953627&r2=953628&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Jun 11 09:45:04 2010
@@ -481,6 +481,10 @@ Bug fixes
files when a mergedSegmentWarmer is set on IndexWriter. (Mike
McCandless)
+* LUCENE-2496: Don't throw NPE if IndexWriter is opened with CREATE on
+ a prior (corrupt) index missing its segments_N file. (Mike
+ McCandless)
+
New features
* LUCENE-2128: Parallelized fetching document frequencies during weight
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java?rev=953628&r1=953627&r2=953628&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/index/IndexFileDeleter.java Fri Jun 11 09:45:04 2010
@@ -134,8 +134,10 @@ final class IndexFileDeleter {
this.docWriter = docWriter;
this.infoStream = infoStream;
+ final String currentSegmentsFile = segmentInfos.getCurrentSegmentFileName();
+
if (infoStream != null)
- message("init: current segments file is \"" + segmentInfos.getCurrentSegmentFileName() + "\"; deletionPolicy=" + policy);
+ message("init: current segments file is \"" + currentSegmentsFile + "\"; deletionPolicy=" + policy);
this.policy = policy;
this.directory = directory;
@@ -146,7 +148,6 @@ final class IndexFileDeleter {
indexFilenameFilter = new IndexFileNameFilter(codecs);
CommitPoint currentCommitPoint = null;
- boolean seenIndexFiles = false;
String[] files = null;
try {
files = directory.listAll();
@@ -158,7 +159,6 @@ final class IndexFileDeleter {
for (String fileName : files) {
if ((indexFilenameFilter.accept(null, fileName)) && !fileName.endsWith("write.lock") && !fileName.equals(IndexFileNames.SEGMENTS_GEN)) {
- seenIndexFiles = true;
// Add this file to refCounts with initial count 0:
getRefCount(fileName);
@@ -201,10 +201,7 @@ final class IndexFileDeleter {
}
}
- // If we haven't seen any Lucene files, then currentCommitPoint is expected
- // to be null, because it means it's a fresh Directory. Therefore it cannot
- // be any NFS cache issues - so just ignore.
- if (currentCommitPoint == null && seenIndexFiles) {
+ if (currentCommitPoint == null && currentSegmentsFile != null) {
// We did not in fact see the segments_N file
// corresponding to the segmentInfos that was passed
// in. Yet, it must exist, because our caller holds
@@ -214,7 +211,7 @@ final class IndexFileDeleter {
// try now to explicitly open this commit point:
SegmentInfos sis = new SegmentInfos();
try {
- sis.read(directory, segmentInfos.getCurrentSegmentFileName(), codecs);
+ sis.read(directory, currentSegmentsFile, codecs);
} catch (IOException e) {
throw new CorruptIndexException("failed to locate current segments_N file");
}
@@ -244,7 +241,7 @@ final class IndexFileDeleter {
// Finally, give policy a chance to remove things on
// startup:
- if (seenIndexFiles) {
+ if (currentSegmentsFile != null) {
policy.onInit(commits);
}
Modified: lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java?rev=953628&r1=953627&r2=953628&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestIndexWriter.java Fri Jun 11 09:45:04 2010
@@ -4954,5 +4954,32 @@ public class TestIndexWriter extends Luc
writer.close();
assertEquals("expected a no-op close after IW.rollback()", 0, dir.listAll().length);
}
-
+
+ public void testNoSegmentFile() throws IOException {
+ File tempDir = _TestUtil.getTempDir("noSegmentFile");
+ try {
+ Directory dir = FSDirectory.open(tempDir);
+ dir.setLockFactory(new NoLockFactory());
+ IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new MockAnalyzer())
+ .setMaxBufferedDocs(2));
+
+ Document doc = new Document();
+ doc.add(new Field("c", "val", Store.YES, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS));
+ w.addDocument(doc);
+ w.addDocument(doc);
+ String[] files = dir.listAll();
+ for(String file : files) {
+ System.out.println("file=" + file);
+ }
+ IndexWriter w2 = new IndexWriter(dir, new IndexWriterConfig(
+ TEST_VERSION_CURRENT, new MockAnalyzer())
+ .setMaxBufferedDocs(2).setOpenMode(OpenMode.CREATE));
+
+ w2.close();
+ dir.close();
+ } finally {
+ _TestUtil.rmDir(tempDir);
+ }
+ }
}