Skip to content

Commit 5b425d6

Browse files
committed
Replace hashmap by a counter in TrackingPostingsInMemoryBytesCodec
1 parent 64023d7 commit 5b425d6

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

server/src/main/java/org/elasticsearch/index/codec/TrackingPostingsInMemoryBytesCodec.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.apache.lucene.index.SegmentWriteState;
2323
import org.apache.lucene.index.Terms;
2424
import org.apache.lucene.index.TermsEnum;
25-
import org.apache.lucene.internal.hppc.IntIntHashMap;
2625
import org.apache.lucene.util.BytesRef;
2726
import org.elasticsearch.common.util.FeatureFlag;
2827

@@ -63,22 +62,18 @@ public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException
6362
static final class TrackingLengthFieldsConsumer extends FieldsConsumer {
6463
final SegmentWriteState state;
6564
final FieldsConsumer in;
66-
final IntIntHashMap termsBytesPerField;
65+
final long[] totalBytes;
6766

6867
TrackingLengthFieldsConsumer(SegmentWriteState state, FieldsConsumer in) {
6968
this.state = state;
7069
this.in = in;
71-
this.termsBytesPerField = new IntIntHashMap(state.fieldInfos.size());
70+
this.totalBytes = new long[1];
7271
}
7372

7473
@Override
7574
public void write(Fields fields, NormsProducer norms) throws IOException {
76-
in.write(new TrackingLengthFields(fields, termsBytesPerField, state.fieldInfos), norms);
77-
long totalBytes = 0;
78-
for (int bytes : termsBytesPerField.values) {
79-
totalBytes += bytes;
80-
}
81-
state.segmentInfo.putAttribute(IN_MEMORY_POSTINGS_BYTES_KEY, Long.toString(totalBytes));
75+
in.write(new TrackingLengthFields(fields, totalBytes, state.fieldInfos), norms);
76+
state.segmentInfo.putAttribute(IN_MEMORY_POSTINGS_BYTES_KEY, Long.toString(totalBytes[0]));
8277
}
8378

8479
@Override
@@ -88,12 +83,12 @@ public void close() throws IOException {
8883
}
8984

9085
static final class TrackingLengthFields extends FilterLeafReader.FilterFields {
91-
final IntIntHashMap termsBytesPerField;
86+
final long[] totalBytes;
9287
final FieldInfos fieldInfos;
9388

94-
TrackingLengthFields(Fields in, IntIntHashMap termsBytesPerField, FieldInfos fieldInfos) {
89+
TrackingLengthFields(Fields in, long[] totalBytes, FieldInfos fieldInfos) {
9590
super(in);
96-
this.termsBytesPerField = termsBytesPerField;
91+
this.totalBytes = totalBytes;
9792
this.fieldInfos = fieldInfos;
9893
}
9994

@@ -103,11 +98,7 @@ public Terms terms(String field) throws IOException {
10398
if (terms == null) {
10499
return null;
105100
}
106-
int fieldNum = fieldInfos.fieldInfo(field).number;
107-
return new TrackingLengthTerms(
108-
terms,
109-
bytes -> termsBytesPerField.put(fieldNum, Math.max(termsBytesPerField.getOrDefault(fieldNum, 0), bytes))
110-
);
101+
return new TrackingLengthTerms(terms, bytes -> totalBytes[0] += bytes);
111102
}
112103
}
113104

0 commit comments

Comments
 (0)