addIndexes(IndexReader[]): Delete segment of non-empty

goal index an close its SegmentReader


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150394 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christoph Goller 2004-08-06 12:21:24 +00:00
parent 4b8434c0e8
commit fecb54ff64
1 changed files with 13 additions and 4 deletions

View File

@ -400,11 +400,16 @@ public class IndexWriter {
optimize(); // start with zero or 1 seg
String mergedName = newSegmentName();
SegmentMerger merger = new SegmentMerger(directory, mergedName, false);
if (segmentInfos.size() == 1) // add existing index, if any
merger.add(new SegmentReader(segmentInfos.info(0)));
SegmentMerger merger = new SegmentMerger(directory, mergedName, useCompoundFile);
final Vector segmentsToDelete = new Vector();
IndexReader sReader = null;
if (segmentInfos.size() == 1){ // add existing index, if any
sReader = new SegmentReader(segmentInfos.info(0));
merger.add(sReader);
segmentsToDelete.addElement(sReader); // queue segment for deletion
}
for (int i = 0; i < readers.length; i++) // add new indexes
merger.add(readers[i]);
@ -412,11 +417,15 @@ public class IndexWriter {
segmentInfos.setSize(0); // pop old infos & add new
segmentInfos.addElement(new SegmentInfo(mergedName, docCount, directory));
if(sReader != null)
sReader.close();
synchronized (directory) { // in- & inter-process sync
new Lock.With(directory.makeLock("commit.lock"), COMMIT_LOCK_TIMEOUT) {
public Object doBody() throws IOException {
segmentInfos.write(directory); // commit changes
deleteSegments(segmentsToDelete); // delete now-unused segments
return null;
}
}.run();