Skip to content

Commit e0c52e5

Browse files
authored
Break on FieldData when building global ordinals (elastic#108875) (elastic#138470)
This commit adds the bytes and break if we get over the limit of the breaker when building global ordinals.
1 parent 92bccf5 commit e0c52e5

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

docs/changelog/108875.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 108875
2+
summary: Break on `FieldData` when building global ordinals
3+
area: Aggregations
4+
type: bug
5+
issues:
6+
- 97075

server/src/main/java/org/elasticsearch/index/fielddata/ordinals/GlobalOrdinalsBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public BytesRef next() throws IOException {
7272
}
7373
final OrdinalMap ordinalMap = OrdinalMap.build(null, termsEnums, weights, PackedInts.DEFAULT);
7474
final long memorySizeInBytes = ordinalMap.ramBytesUsed();
75-
breaker.addWithoutBreaking(memorySizeInBytes);
75+
breaker.addEstimateBytesAndMaybeBreak(memorySizeInBytes, "Global Ordinals");
7676

7777
TimeValue took = new TimeValue(System.nanoTime() - startTimeNS, TimeUnit.NANOSECONDS);
7878
if (logger.isDebugEnabled()) {

server/src/test/java/org/elasticsearch/index/fielddata/FieldDataCacheTests.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.elasticsearch.test.FieldMaskingReader;
3838

3939
import static org.hamcrest.Matchers.equalTo;
40+
import static org.hamcrest.Matchers.greaterThan;
4041

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

103-
int[] timesCalled = new int[1];
104+
int[] timesCalledForParent = new int[1];
105+
long[] timesCalledForFieldData = new long[1];
104106
SortedSetOrdinalsIndexFieldData sortedSetOrdinalsIndexFieldData = new SortedSetOrdinalsIndexFieldData(
105107
new DummyAccountingFieldDataCache(),
106108
"field1",
@@ -113,16 +115,22 @@ public CircuitBreaker getBreaker(String name) {
113115
@Override
114116
public void addEstimateBytesAndMaybeBreak(long bytes, String label) throws CircuitBreakingException {
115117
assertThat(label, equalTo("Global Ordinals"));
116-
assertThat(bytes, equalTo(0L));
117-
timesCalled[0]++;
118+
if (bytes == 0) {
119+
timesCalledForParent[0]++;
120+
} else {
121+
assertThat(timesCalledForFieldData[0], equalTo(0L));
122+
assertThat(bytes, greaterThan(0L));
123+
timesCalledForFieldData[0] = bytes;
124+
}
118125
}
119126
};
120127
}
121128
},
122129
MOCK_TO_SCRIPT_FIELD
123130
);
124-
sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
125-
assertThat(timesCalled[0], equalTo(2));
131+
IndexOrdinalsFieldData globalOrdinals = sortedSetOrdinalsIndexFieldData.loadGlobal(ir);
132+
assertThat(timesCalledForParent[0], equalTo(2));
133+
assertThat(timesCalledForFieldData[0], equalTo(globalOrdinals.getOrdinalMap().ramBytesUsed()));
126134

127135
ir.close();
128136
dir.close();

0 commit comments

Comments
 (0)