use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.
the class IndexFetcher method hasUnusedFiles.
private boolean hasUnusedFiles(Directory indexDir, IndexCommit commit) throws IOException {
String segmentsFileName = commit.getSegmentsFileName();
SegmentInfos infos = SegmentInfos.readCommit(indexDir, segmentsFileName);
Set<String> currentFiles = new HashSet<>(infos.files(true));
String[] allFiles = indexDir.listAll();
for (String file : allFiles) {
if (!file.equals(segmentsFileName) && !currentFiles.contains(file) && !file.endsWith(".lock")) {
LOG.info("Found unused file: " + file);
return true;
}
}
return false;
}
use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.
the class TestPerfTasksLogic method testForceMerge.
/**
* Test that we can call forceMerge(maxNumSegments).
*/
public void testForceMerge() throws Exception {
// 1. alg definition (required in every "logic" test)
String[] algLines = { "# ----- properties ", "content.source=org.apache.lucene.benchmark.byTask.feeds.LineDocSource", "docs.file=" + getReuters20LinesFile(), "content.source.log.step=3", "ram.flush.mb=-1", "max.buffered=3", "doc.term.vector=false", "content.source.forever=false", "directory=RAMDirectory", "merge.policy=org.apache.lucene.index.LogDocMergePolicy", "doc.stored=false", "doc.tokenized=false", "debug.level=1", "# ----- alg ", "{ \"Rounds\"", " ResetSystemErase", " CreateIndex", " { \"AddDocs\" AddDoc > : * ", " ForceMerge(3)", " CloseIndex()", "} : 2" };
// 2. execute the algorithm (required in every "logic" test)
Benchmark benchmark = execBenchmark(algLines);
// 3. test number of docs in the index
IndexReader ir = DirectoryReader.open(benchmark.getRunData().getDirectory());
// first 20 reuters docs.
int ndocsExpected = 20;
assertEquals("wrong number of docs in the index!", ndocsExpected, ir.numDocs());
ir.close();
// Make sure we have 3 segments:
SegmentInfos infos = SegmentInfos.readLatestCommit(benchmark.getRunData().getDirectory());
assertEquals(3, infos.size());
}
use of org.apache.lucene.index.SegmentInfos in project lucene-solr by apache.
the class CommitIndexTaskTest method testCommitData.
public void testCommitData() throws Exception {
PerfRunData runData = createPerfRunData();
new CreateIndexTask(runData).doLogic();
CommitIndexTask task = new CommitIndexTask(runData);
task.setParams("params");
task.doLogic();
SegmentInfos infos = SegmentInfos.readLatestCommit(runData.getDirectory());
assertEquals("params", infos.getUserData().get(OpenReaderTask.USER_DATA));
new CloseIndexTask(runData).doLogic();
}
Aggregations