Disable RAM usage estimation on Lucene 3.x segments.

Close #5201
This commit is contained in:
Adrien Grand 2014-02-20 19:01:53 +01:00
parent 428080b49a
commit 96d028e721
2 changed files with 28 additions and 5 deletions

View File

@ -19,9 +19,11 @@
package org.elasticsearch.index.engine;
import org.apache.lucene.util.Version;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -41,17 +43,27 @@ public class SegmentsStats implements Streamable, ToXContent {
}
static {
assert Version.LUCENE_46.onOrAfter(Lucene.VERSION); // remove special -1 handling below
}
public void add(long count, long memoryInBytes) {
this.count += count;
this.memoryInBytes += memoryInBytes;
// replace me with
// "this.memoryInBytes += memoryInBytes;"
// upon upgrade to Lucene 4.7
if (memoryInBytes == -1) {
this.memoryInBytes = -1;
} else if (this.memoryInBytes != -1) {
this.memoryInBytes += memoryInBytes;
}
}
public void add(SegmentsStats mergeStats) {
if (mergeStats == null) {
return;
}
this.count += mergeStats.count;
this.memoryInBytes += mergeStats.memoryInBytes;
add(mergeStats.count, mergeStats.memoryInBytes);
}
/**

View File

@ -20,6 +20,7 @@
package org.elasticsearch.index.engine.internal;
import com.google.common.collect.Lists;
import org.apache.lucene.codecs.lucene3x.Lucene3xCodec;
import org.apache.lucene.index.*;
import org.apache.lucene.index.IndexWriter.IndexReaderWarmer;
import org.apache.lucene.search.IndexSearcher;
@ -30,6 +31,7 @@ import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.Version;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.cluster.routing.operation.hash.djb.DjbHashFunction;
@ -1118,9 +1120,18 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin
}
}
static {
assert Version.LUCENE_46.onOrAfter(Lucene.VERSION); // Lucene 4.7 fixed Lucene 3.X RAM usage estimations, see LUCENE-5462
}
private long getReaderRamBytesUsed(AtomicReaderContext reader) {
return SegmentReaderUtils.segmentReader(reader.reader()).ramBytesUsed();
final SegmentReader segmentReader = SegmentReaderUtils.segmentReader(reader.reader());
if (segmentReader.getSegmentInfo().info.getCodec() instanceof Lucene3xCodec) {
// https://issues.apache.org/jira/browse/LUCENE-5462
// RAM usage estimation is very costly on Lucene 3.x segments
return -1;
}
return segmentReader.ramBytesUsed();
}
@Override
@ -1357,7 +1368,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin
config.setMaxThreadStates(indexConcurrency);
config.setCodec(codecService.codec(codecName));
/* We set this timeout to a highish value to work around
* the default poll interval in the Lucene lock that is
* the default poll interval in the Lucene lock that is
* 1000ms by default. We might need to poll multiple times
* here but with 1s poll this is only executed twice at most
* in combination with the default writelock timeout*/