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