Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/108875.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 108875
summary: Break on `FieldData` when building global ordinals
area: Aggregations
type: bug
issues:
- 97075
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BytesRef next() throws IOException {
}
final OrdinalMap ordinalMap = OrdinalMap.build(null, termsEnums, weights, PackedInts.DEFAULT);
final long memorySizeInBytes = ordinalMap.ramBytesUsed();
breaker.addWithoutBreaking(memorySizeInBytes);
breaker.addEstimateBytesAndMaybeBreak(memorySizeInBytes, "Global Ordinals");

TimeValue took = new TimeValue(System.nanoTime() - startTimeNS, TimeUnit.NANOSECONDS);
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.elasticsearch.test.FieldMaskingReader;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;

public class FieldDataCacheTests extends ESTestCase {
private static final ToScriptFieldFactory<SortedSetDocValues> MOCK_TO_SCRIPT_FIELD = (dv, n) -> new DelegateDocValuesField(
Expand Down Expand Up @@ -100,7 +101,8 @@ public void testGlobalOrdinalsCircuitBreaker() throws Exception {
iw.close();
DirectoryReader ir = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(dir), new ShardId("_index", "_na_", 0));

int[] timesCalled = new int[1];
int[] timesCalledForParent = new int[1];
long[] timesCalledForFieldData = new long[1];
SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData = new SortedSetOrdinalsIndexFieldData(
new DummyAccountingFieldDataCache(),
"field1",
Expand All @@ -113,16 +115,22 @@ public CircuitBreaker getBreaker(String name) {
@Override
public void addEstimateBytesAndMaybeBreak(long bytes, String label) throws CircuitBreakingException {
assertThat(label, equalTo("Global Ordinals"));
assertThat(bytes, equalTo(0L));
timesCalled[0]++;
if (bytes == 0) {
timesCalledForParent[0]++;
} else {
assertThat(timesCalledForFieldData[0], equalTo(0L));
assertThat(bytes, greaterThan(0L));
timesCalledForFieldData[0] = bytes;
}
}
};
}
},
MOCK_TO_SCRIPT_FIELD
);
sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
assertThat(timesCalled[0], equalTo(2));
IndexOrdinalsFieldData globalOrdinals = sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
assertThat(timesCalledForParent[0], equalTo(2));
assertThat(timesCalledForFieldData[0], equalTo(globalOrdinals.getOrdinalMap().ramBytesUsed()));

ir.close();
dir.close();
Expand Down