Skip to content

Commit

Permalink
Prevent usage of object based RamUsageEstimator in Completion090Posti…
Browse files Browse the repository at this point in the history
…ngsFormat
  • Loading branch information
s1monw committed Jan 31, 2014
1 parent 3e31702 commit 6e18a89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Expand Up @@ -204,6 +204,7 @@ public int getMaxAnalyzedPathsForOneInput() {

@Override
public LookupFactory load(IndexInput input) throws IOException {
long sizeInBytes = 0;
int version = CodecUtil.checkHeader(input, CODEC_NAME, CODEC_VERSION_START, CODEC_VERSION_LATEST);
final Map<String, AnalyzingSuggestHolder> lookupMap = new HashMap<String, AnalyzingSuggestHolder>();
input.seek(input.length() - 8);
Expand Down Expand Up @@ -249,8 +250,10 @@ public LookupFactory load(IndexInput input) throws IOException {

AnalyzingSuggestHolder holder = new AnalyzingSuggestHolder(preserveSep, preservePositionIncrements, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions,
hasPayloads, maxAnalyzedPathsForOneInput, fst, sepLabel, payloadSep, endByte, holeCharacter);
sizeInBytes += fst.sizeInBytes();
lookupMap.put(entry.getValue(), holder);
}
final long ramBytesUsed = sizeInBytes;
return new LookupFactory() {
@Override
public Lookup getLookup(FieldMapper<?> mapper, CompletionSuggestionContext suggestionContext) {
Expand Down Expand Up @@ -309,6 +312,11 @@ public CompletionStats stats(String... fields) {
AnalyzingSuggestHolder getAnalyzingSuggestHolder(FieldMapper<?> mapper) {
return lookupMap.get(mapper.names().indexName());
}

@Override
public long ramBytesUsed() {
return ramBytesUsed;
}
};
}

Expand Down
Expand Up @@ -272,7 +272,7 @@ public int size() {

@Override
public long ramBytesUsed() {
return RamUsageEstimator.sizeOf(lookupFactory) + delegateProducer.ramBytesUsed();
return (lookupFactory == null ? 0 : lookupFactory.ramBytesUsed()) + delegateProducer.ramBytesUsed();
}
}

Expand Down Expand Up @@ -367,5 +367,6 @@ public static abstract class LookupFactory {
public abstract Lookup getLookup(FieldMapper<?> mapper, CompletionSuggestionContext suggestionContext);
public abstract CompletionStats stats(String ... fields);
abstract AnalyzingCompletionLookupProvider.AnalyzingSuggestHolder getAnalyzingSuggestHolder(FieldMapper<?> mapper);
public abstract long ramBytesUsed();
}
}
Expand Up @@ -224,7 +224,7 @@ public LookupFactory load(IndexInput input) throws IOException {
long offset = input.readVLong();
meta.put(offset, name);
}

long sizeInBytes = 0;
for (Map.Entry<Long, String> entry : meta.entrySet()) {
input.seek(entry.getKey());
FST<Pair<Long, BytesRef>> fst = new FST<Pair<Long, BytesRef>>(input, new PairOutputs<Long, BytesRef>(
Expand All @@ -236,9 +236,11 @@ public LookupFactory load(IndexInput input) throws IOException {
boolean preserveSep = (options & SERIALIZE_PRESERVE_SEPERATORS) != 0;
boolean hasPayloads = (options & SERIALIZE_HAS_PAYLOADS) != 0;
boolean preservePositionIncrements = (options & SERIALIZE_PRESERVE_POSITION_INCREMENTS) != 0;
sizeInBytes += fst.sizeInBytes();
lookupMap.put(entry.getValue(), new AnalyzingSuggestHolder(preserveSep, preservePositionIncrements, maxSurfaceFormsPerAnalyzedForm, maxGraphExpansions,
hasPayloads, maxAnalyzedPathsForOneInput, fst));
}
final long ramBytesUsed = sizeInBytes;
return new LookupFactory() {
@Override
public Lookup getLookup(FieldMapper<?> mapper, CompletionSuggestionContext suggestionContext) {
Expand Down Expand Up @@ -295,6 +297,11 @@ public CompletionStats stats(String... fields) {
AnalyzingSuggestHolder getAnalyzingSuggestHolder(FieldMapper<?> mapper) {
return lookupMap.get(mapper.names().indexName());
}

@Override
public long ramBytesUsed() {
return ramBytesUsed;
}
};
}

Expand Down

0 comments on commit 6e18a89

Please sign in to comment.