Apache Lucene open-source search software
LUCENE-5969: clear nocommit
Robert Muir98a52788273b
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundFormat.javaindex 1b9f2f40c6c..2c41d8cbe52 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundFormat.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/codecs/lucene40/Lucene40CompoundFormat.java@@ -51,6 +51,14 @@ public final class Lucene40CompoundFormat extends CompoundFormat {}}+ @Override+ public String[] files(SegmentInfo si) {+ return new String[] {+ IndexFileNames.segmentFileName(si.name, "", COMPOUND_FILE_EXTENSION),+ IndexFileNames.segmentFileName(si.name, "", COMPOUND_FILE_ENTRIES_EXTENSION)+ };+ }+/** Extension of compound file */static final String COMPOUND_FILE_EXTENSION = "cfs";/** Extension of compound file entries */diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.javaindex 6ac0a3b73af..e3943bacb28 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/CompoundFormat.java@@ -49,4 +49,8 @@ public abstract class CompoundFormat {*/// TODO: get checkAbort out of here, and everywhere, and have iw do it at a higher levelpublic abstract void write(Directory dir, SegmentInfo si, Collection<String> files, CheckAbort checkAbort, IOContext context) throws IOException;++ // TODO: get this out of here, and use trackingdirwrapper. but this is really scary in IW right now...+ // NOTE: generally si.useCompoundFile is not even yet 'set' when this is called.+ public abstract String[] files(SegmentInfo si);}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.javaindex 9576d51e9e8..d24623403f7 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50CompoundFormat.java@@ -103,7 +103,14 @@ public final class Lucene50CompoundFormat extends CompoundFormat {CodecUtil.writeFooter(entries);}}-++ @Override+ public String[] files(SegmentInfo si) {+ return new String[] {+ IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION),+ IndexFileNames.segmentFileName(si.name, "", ENTRIES_EXTENSION)+ };+ }/** Extension of compound file */static final String DATA_EXTENSION = "cfs";diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java b/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.javaindex 5692170740f..a0859d14eac 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexFileNames.java@@ -53,12 +53,6 @@ public final class IndexFileNames {/** Name of the generation reference file name */public static final String OLD_SEGMENTS_GEN = "segments.gen";- /** Extension of compound file */- public static final String COMPOUND_FILE_EXTENSION = "cfs";-- /** Extension of compound file entries */- public static final String COMPOUND_FILE_ENTRIES_EXTENSION = "cfe";-/*** Computes the full file name from base, extension and generation. If the* generation is -1, the file name is null. If it's 0, the file name isdiff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex bf42a534789..93df2aecfd5 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -3958,6 +3958,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {if (useCompoundFile) {success = false;+ String cfsFiles[] = merge.info.info.getCodec().compoundFormat().files(merge.info.info);Collection<String> filesToRemove = merge.info.files();try {@@ -3982,8 +3983,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {}synchronized(this) {- deleter.deleteFile(IndexFileNames.segmentFileName(mergedName, "", IndexFileNames.COMPOUND_FILE_EXTENSION));- deleter.deleteFile(IndexFileNames.segmentFileName(mergedName, "", IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION));+ for (String cfsFile : cfsFiles) {+ deleter.deleteFile(cfsFile);+ }deleter.deleteNewFiles(merge.info.files());}}@@ -4004,8 +4006,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {if (infoStream.isEnabled("IW")) {infoStream.message("IW", "abort merge after building CFS");}- deleter.deleteFile(IndexFileNames.segmentFileName(mergedName, "", IndexFileNames.COMPOUND_FILE_EXTENSION));- deleter.deleteFile(IndexFileNames.segmentFileName(mergedName, "", IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION));+ for (String cfsFile : cfsFiles) {+ deleter.deleteFile(cfsFile);+ }return 0;}}@@ -4452,10 +4455,9 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {static final Collection<String> createCompoundFile(InfoStream infoStream, Directory directory, CheckAbort checkAbort, final SegmentInfo info, IOContext context)throws IOException {- // nocommit: use trackingdirectorywrapper instead to know which files to delete when things fail:- String cfsFileName = IndexFileNames.segmentFileName(info.name, "", IndexFileNames.COMPOUND_FILE_EXTENSION);- String cfeFileName = IndexFileNames.segmentFileName(info.name, "", IndexFileNames.COMPOUND_FILE_ENTRIES_EXTENSION);-+ // TODO: use trackingdirectorywrapper instead of files() to know which files to delete when things fail:+ String cfsFiles[] = info.getCodec().compoundFormat().files(info);+if (infoStream.isEnabled("IW")) {infoStream.message("IW", "create compound file");}@@ -4468,14 +4470,15 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {success = true;} finally {if (!success) {- IOUtils.deleteFilesIgnoringExceptions(directory, cfsFileName, cfeFileName);+ IOUtils.deleteFilesIgnoringExceptions(directory, cfsFiles);}}// Replace all previous files with the CFS/CFE files:Set<String> siFiles = new HashSet<>();- siFiles.add(cfsFileName);- siFiles.add(cfeFileName);+ for (String cfsFile : cfsFiles) {+ siFiles.add(cfsFile);+ };info.setFiles(siFiles);return files;