Don't load CompetionTerms if lookupFactory is null
Closes #4970 Closes #4788
This commit is contained in:
parent
90da268237
commit
3e3170278e
|
@ -205,13 +205,14 @@ public class Completion090PostingsFormat extends PostingsFormat {
|
||||||
|
|
||||||
private static class CompletionFieldsProducer extends FieldsProducer {
|
private static class CompletionFieldsProducer extends FieldsProducer {
|
||||||
|
|
||||||
private FieldsProducer delegateProducer;
|
private final FieldsProducer delegateProducer;
|
||||||
private LookupFactory lookupFactory;
|
private final LookupFactory lookupFactory;
|
||||||
|
|
||||||
public CompletionFieldsProducer(SegmentReadState state) throws IOException {
|
public CompletionFieldsProducer(SegmentReadState state) throws IOException {
|
||||||
String suggestFSTFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
|
String suggestFSTFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
|
||||||
IndexInput input = state.directory.openInput(suggestFSTFile, state.context);
|
IndexInput input = state.directory.openInput(suggestFSTFile, state.context);
|
||||||
CodecUtil.checkHeader(input, CODEC_NAME, SUGGEST_CODEC_VERSION, SUGGEST_CODEC_VERSION);
|
CodecUtil.checkHeader(input, CODEC_NAME, SUGGEST_CODEC_VERSION, SUGGEST_CODEC_VERSION);
|
||||||
|
FieldsProducer delegateProducer = null;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
PostingsFormat delegatePostingsFormat = PostingsFormat.forName(input.readString());
|
PostingsFormat delegatePostingsFormat = PostingsFormat.forName(input.readString());
|
||||||
|
@ -221,7 +222,7 @@ public class Completion090PostingsFormat extends PostingsFormat {
|
||||||
throw new ElasticsearchIllegalStateException("no provider with name [" + providerName + "] registered");
|
throw new ElasticsearchIllegalStateException("no provider with name [" + providerName + "] registered");
|
||||||
}
|
}
|
||||||
// TODO: we could clone the ReadState and make it always forward IOContext.MERGE to prevent unecessary heap usage?
|
// TODO: we could clone the ReadState and make it always forward IOContext.MERGE to prevent unecessary heap usage?
|
||||||
this.delegateProducer = delegatePostingsFormat.fieldsProducer(state);
|
delegateProducer = delegatePostingsFormat.fieldsProducer(state);
|
||||||
/*
|
/*
|
||||||
* If we are merging we don't load the FSTs at all such that we
|
* If we are merging we don't load the FSTs at all such that we
|
||||||
* don't consume so much memory during merge
|
* don't consume so much memory during merge
|
||||||
|
@ -231,7 +232,10 @@ public class Completion090PostingsFormat extends PostingsFormat {
|
||||||
// eventually we should have some kind of curciut breaker that prevents us from going OOM here
|
// eventually we should have some kind of curciut breaker that prevents us from going OOM here
|
||||||
// with some configuration
|
// with some configuration
|
||||||
this.lookupFactory = completionLookupProvider.load(input);
|
this.lookupFactory = completionLookupProvider.load(input);
|
||||||
|
} else {
|
||||||
|
this.lookupFactory = null;
|
||||||
}
|
}
|
||||||
|
this.delegateProducer = delegateProducer;
|
||||||
success = true;
|
success = true;
|
||||||
} finally {
|
} finally {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
|
@ -254,11 +258,11 @@ public class Completion090PostingsFormat extends PostingsFormat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Terms terms(String field) throws IOException {
|
public Terms terms(String field) throws IOException {
|
||||||
Terms terms = delegateProducer.terms(field);
|
final Terms terms = delegateProducer.terms(field);
|
||||||
if (terms == null) {
|
if (terms == null || lookupFactory == null) {
|
||||||
return terms;
|
return terms;
|
||||||
}
|
}
|
||||||
return new CompletionTerms(terms, this.lookupFactory);
|
return new CompletionTerms(terms, lookupFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue