create compound file in merge after all merged segments

have been deleted in order to safe disk space.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150408 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Christoph Goller 2004-08-08 13:05:33 +00:00
parent f24f300492
commit dc74bab798
5 changed files with 15 additions and 14 deletions

View File

@ -400,7 +400,7 @@ public class IndexWriter {
optimize(); // start with zero or 1 seg
String mergedName = newSegmentName();
SegmentMerger merger = new SegmentMerger(directory, mergedName, useCompoundFile);
final SegmentMerger merger = new SegmentMerger(directory, mergedName);
final Vector segmentsToDelete = new Vector();
IndexReader sReader = null;
@ -426,6 +426,8 @@ public class IndexWriter {
public Object doBody() throws IOException {
segmentInfos.write(directory); // commit changes
deleteSegments(segmentsToDelete); // delete now-unused segments
if(useCompoundFile)
merger.createCompoundFile();
return null;
}
}.run();
@ -479,8 +481,8 @@ public class IndexWriter {
throws IOException {
String mergedName = newSegmentName();
if (infoStream != null) infoStream.print("merging segments");
SegmentMerger merger =
new SegmentMerger(directory, mergedName, useCompoundFile);
final SegmentMerger merger =
new SegmentMerger(directory, mergedName);
final Vector segmentsToDelete = new Vector();
for (int i = minSegment; i < segmentInfos.size(); i++) {
@ -512,6 +514,8 @@ public class IndexWriter {
public Object doBody() throws IOException {
segmentInfos.write(directory); // commit before deleting
deleteSegments(segmentsToDelete); // delete now-unused segments
if(useCompoundFile)
merger.createCompoundFile();
return null;
}
}.run();

View File

@ -37,7 +37,6 @@ import org.apache.lucene.store.RAMOutputStream;
* @see #add
*/
final class SegmentMerger {
private boolean useCompoundFile;
private Directory directory;
private String segment;
@ -56,12 +55,10 @@ final class SegmentMerger {
*
* @param dir The Directory to merge the other segments into
* @param name The name of the new segment
* @param compoundFile true if the new segment should use a compoundFile
*/
SegmentMerger(Directory dir, String name, boolean compoundFile) {
SegmentMerger(Directory dir, String name) {
directory = dir;
segment = name;
useCompoundFile = compoundFile;
}
/**
@ -96,9 +93,6 @@ final class SegmentMerger {
if (fieldInfos.hasVectors())
mergeVectors();
if (useCompoundFile)
createCompoundFile();
return value;
}
@ -114,7 +108,7 @@ final class SegmentMerger {
}
}
private final void createCompoundFile()
final void createCompoundFile()
throws IOException {
CompoundFileWriter cfsWriter =
new CompoundFileWriter(directory, segment + ".cfs");

View File

@ -76,7 +76,7 @@ class DocTest {
SegmentReader r1 = new SegmentReader(new SegmentInfo(seg1, 1, directory));
SegmentReader r2 = new SegmentReader(new SegmentInfo(seg2, 1, directory));
SegmentMerger merger = new SegmentMerger(directory, merged, false);
SegmentMerger merger = new SegmentMerger(directory, merged);
merger.add(r1);
merger.add(r2);
merger.merge();

View File

@ -181,12 +181,15 @@ public class TestDoc extends TestCase {
SegmentReader r2 = new SegmentReader(new SegmentInfo(seg2, 1, directory));
SegmentMerger merger =
new SegmentMerger(directory, merged, useCompoundFile);
new SegmentMerger(directory, merged);
merger.add(r1);
merger.add(r2);
merger.merge();
merger.closeReaders();
if(useCompoundFile)
merger.createCompoundFile();
directory.close();
}

View File

@ -72,7 +72,7 @@ public class TestSegmentMerger extends TestCase {
public void testMerge() {
//System.out.println("----------------TestMerge------------------");
SegmentMerger merger = new SegmentMerger(mergedDir, mergedSegment, false);
SegmentMerger merger = new SegmentMerger(mergedDir, mergedSegment);
merger.add(reader1);
merger.add(reader2);
try {