Skip to content

Commit

Permalink
Don't load CompetionTerms if lookupFactory is null
Browse files Browse the repository at this point in the history
Closes #4970
Closes #4788
  • Loading branch information
s1monw committed Jan 31, 2014
1 parent fc75f42 commit 1c5a077
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -205,13 +205,14 @@ public void startTerm(BytesRef text) throws IOException {

private static class CompletionFieldsProducer extends FieldsProducer {

private FieldsProducer delegateProducer;
private LookupFactory lookupFactory;
private final FieldsProducer delegateProducer;
private final LookupFactory lookupFactory;

public CompletionFieldsProducer(SegmentReadState state) throws IOException {
String suggestFSTFile = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
IndexInput input = state.directory.openInput(suggestFSTFile, state.context);
CodecUtil.checkHeader(input, CODEC_NAME, SUGGEST_CODEC_VERSION, SUGGEST_CODEC_VERSION);
FieldsProducer delegateProducer = null;
boolean success = false;
try {
PostingsFormat delegatePostingsFormat = PostingsFormat.forName(input.readString());
Expand All @@ -221,7 +222,7 @@ public CompletionFieldsProducer(SegmentReadState state) throws IOException {
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?
this.delegateProducer = delegatePostingsFormat.fieldsProducer(state);
delegateProducer = delegatePostingsFormat.fieldsProducer(state);
/*
* If we are merging we don't load the FSTs at all such that we
* don't consume so much memory during merge
Expand All @@ -231,7 +232,10 @@ public CompletionFieldsProducer(SegmentReadState state) throws IOException {
// eventually we should have some kind of curciut breaker that prevents us from going OOM here
// with some configuration
this.lookupFactory = completionLookupProvider.load(input);
} else {
this.lookupFactory = null;
}
this.delegateProducer = delegateProducer;
success = true;
} finally {
if (!success) {
Expand All @@ -254,11 +258,11 @@ public Iterator<String> iterator() {

@Override
public Terms terms(String field) throws IOException {
Terms terms = delegateProducer.terms(field);
if (terms == null) {
final Terms terms = delegateProducer.terms(field);
if (terms == null || lookupFactory == null) {
return terms;
}
return new CompletionTerms(terms, this.lookupFactory);
return new CompletionTerms(terms, lookupFactory);
}

@Override
Expand Down

0 comments on commit 1c5a077

Please sign in to comment.