Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only iterate the files that we recovered from the commit #9761

Merged
merged 1 commit into from Feb 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/main/java/org/elasticsearch/common/lucene/Lucene.java
Expand Up @@ -19,19 +19,13 @@

package org.elasticsearch.common.lucene;

import com.google.common.collect.Iterables;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexFormatTooNewException;
import org.apache.lucene.index.IndexFormatTooOldException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.index.*;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.ComplexExplanation;
import org.apache.lucene.search.ConstantScoreQuery;
Expand Down Expand Up @@ -70,6 +64,10 @@

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import static org.elasticsearch.common.lucene.search.NoopCollector.NOOP_COLLECTOR;

Expand Down Expand Up @@ -120,6 +118,17 @@ public static SegmentInfos readSegmentInfos(Directory directory) throws IOExcept
return SegmentInfos.readLatestCommit(directory);
}

/**
* Returns an iterable that allows to iterate over all files in this segments info
*/
public static Iterable<String> files(SegmentInfos infos) throws IOException {
final List<Collection<String>> list = new ArrayList<>();
for (SegmentCommitInfo info : infos) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this include the segments file? (e.g. call infos.files() instead) The old listAll() would have included it too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a fix for this here e8f276b

list.add(info.files());
}
return Iterables.concat(list.toArray(new Collection[0]));
}

/**
* Reads the segments infos from the given commit, failing if it fails to load
*/
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.SegmentInfos;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ExceptionsHelper;
Expand Down Expand Up @@ -106,11 +107,11 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
long version = -1;
long translogId = -1;
final Set<String> typesToUpdate = Sets.newHashSet();
SegmentInfos si = null;
indexShard.store().incRef();
try {
try {
indexShard.store().failIfCorrupted();
SegmentInfos si = null;
try {
si = Lucene.readSegmentInfos(indexShard.store().directory());
} catch (Throwable e) {
Expand Down Expand Up @@ -156,11 +157,14 @@ public void recover(boolean indexShouldExists, RecoveryState recoveryState) thro
try {
int numberOfFiles = 0;
long totalSizeInBytes = 0;
for (String name : indexShard.store().directory().listAll()) {
numberOfFiles++;
long length = indexShard.store().directory().fileLength(name);
totalSizeInBytes += length;
recoveryState.getIndex().addFileDetail(name, length, length);
if (si != null) {
final Directory directory = indexShard.store().directory();
for (String name : Lucene.files(si)) {
numberOfFiles++;
long length = directory.fileLength(name);
totalSizeInBytes += length;
recoveryState.getIndex().addFileDetail(name, length, length);
}
}
RecoveryState.Index index = recoveryState.getIndex();
index.totalFileCount(numberOfFiles);
Expand Down