Index: CHANGES.txt =================================================================== --- CHANGES.txt (revision 1028944) +++ CHANGES.txt (working copy) @@ -61,6 +61,9 @@ * LUCENE-2235: Implement missing PerFieldAnalyzerWrapper.getOffsetGap(). (Javier Godoy via Uwe Schindler) +* LUCENE-2328: Fixed memory leak in how IndexWriter/Reader tracked + already sync'd files. (Earwin Burrfoot via Mike McCandless) + * LUCENE-2549: Fix TimeLimitingCollector#TimeExceededException to record the absolute docid. (Uwe Schindler) Index: src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexReader.java (revision 1028944) +++ src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -989,7 +989,7 @@ String[] startFiles = dir.listAll(); SegmentInfos infos = new SegmentInfos(); infos.read(dir); - new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null); + new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null, null); String[] endFiles = dir.listAll(); Arrays.sort(startFiles); Index: src/test/org/apache/lucene/index/TestIndexWriter.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexWriter.java (revision 1028944) +++ src/test/org/apache/lucene/index/TestIndexWriter.java (working copy) @@ -524,7 +524,7 @@ String[] startFiles = dir.listAll(); SegmentInfos infos = new SegmentInfos(); infos.read(dir); - new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null); + new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null, null); String[] endFiles = dir.listAll(); Arrays.sort(startFiles); Index: src/test/org/apache/lucene/index/TestIndexWriterDelete.java =================================================================== --- src/test/org/apache/lucene/index/TestIndexWriterDelete.java (revision 1028944) +++ src/test/org/apache/lucene/index/TestIndexWriterDelete.java (working copy) @@ -790,7 +790,7 @@ String[] startFiles = dir.listAll(); SegmentInfos infos = new SegmentInfos(); infos.read(dir); - new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null); + new IndexFileDeleter(dir, new KeepOnlyLastCommitDeletionPolicy(), infos, null, null, null); String[] endFiles = dir.listAll(); if (!Arrays.equals(startFiles, endFiles)) { Index: src/java/org/apache/lucene/index/DirectoryReader.java =================================================================== --- src/java/org/apache/lucene/index/DirectoryReader.java (revision 1028944) +++ src/java/org/apache/lucene/index/DirectoryReader.java (working copy) @@ -733,7 +733,7 @@ // KeepOnlyLastCommitDeleter: IndexFileDeleter deleter = new IndexFileDeleter(directory, deletionPolicy == null ? new KeepOnlyLastCommitDeletionPolicy() : deletionPolicy, - segmentInfos, null, null); + segmentInfos, null, null, synced); segmentInfos.updateGeneration(deleter.getLastSegmentInfos()); // Checkpoint the state we are about to change, in Index: src/java/org/apache/lucene/index/IndexWriter.java =================================================================== --- src/java/org/apache/lucene/index/IndexWriter.java (revision 1028944) +++ src/java/org/apache/lucene/index/IndexWriter.java (working copy) @@ -1126,7 +1126,7 @@ // KeepOnlyLastCommitDeleter: deleter = new IndexFileDeleter(directory, deletionPolicy == null ? new KeepOnlyLastCommitDeletionPolicy() : deletionPolicy, - segmentInfos, infoStream, docWriter); + segmentInfos, infoStream, docWriter, synced); if (deleter.startingCommitDeleted) // Deletion policy deleted the "head" commit point. @@ -4567,7 +4567,7 @@ } // Files that have been sync'd already - private HashSet synced = new HashSet(); + private final HashSet synced = new HashSet(); // Files that are now being sync'd private HashSet syncing = new HashSet(); Index: src/java/org/apache/lucene/index/IndexFileDeleter.java =================================================================== --- src/java/org/apache/lucene/index/IndexFileDeleter.java (revision 1028944) +++ src/java/org/apache/lucene/index/IndexFileDeleter.java (working copy) @@ -24,6 +24,7 @@ import java.io.PrintStream; import java.util.Map; import java.util.HashMap; +import java.util.Set; import java.util.List; import java.util.ArrayList; @@ -101,6 +102,8 @@ final boolean startingCommitDeleted; private SegmentInfos lastSegmentInfos; + private final Set synced; + /** Change to true to see details of reference counts when * infoStream != null */ public static boolean VERBOSE_REF_COUNTS = false; @@ -123,11 +126,12 @@ * @throws CorruptIndexException if the index is corrupt * @throws IOException if there is a low-level IO error */ - public IndexFileDeleter(Directory directory, IndexDeletionPolicy policy, SegmentInfos segmentInfos, PrintStream infoStream, DocumentsWriter docWriter) + public IndexFileDeleter(Directory directory, IndexDeletionPolicy policy, SegmentInfos segmentInfos, PrintStream infoStream, DocumentsWriter docWriter, Set synced) throws CorruptIndexException, IOException { this.docWriter = docWriter; this.infoStream = infoStream; + this.synced = synced; if (infoStream != null) message("init: current segments file is \"" + segmentInfos.getCurrentSegmentFileName() + "\"; deletionPolicy=" + policy); @@ -476,6 +480,12 @@ // commit points nor by the in-memory SegmentInfos: deleteFile(fileName); refCounts.remove(fileName); + + if (synced != null) { + synchronized(synced) { + synced.remove(fileName); + } + } } }