|
19 | 19 | import org.elasticsearch.core.Releasable; |
20 | 20 | import org.elasticsearch.index.stats.IndexingPressureStats; |
21 | 21 |
|
| 22 | +import java.util.List; |
22 | 23 | import java.util.Optional; |
| 24 | +import java.util.concurrent.CopyOnWriteArrayList; |
23 | 25 | import java.util.concurrent.atomic.AtomicBoolean; |
24 | 26 | import java.util.concurrent.atomic.AtomicLong; |
25 | 27 |
|
26 | | -public class IndexingPressure { |
| 28 | +public class IndexingPressure implements IndexingPressureMonitor { |
27 | 29 |
|
28 | 30 | public static final Setting<ByteSizeValue> MAX_INDEXING_BYTES = Setting.memorySizeSetting( |
29 | 31 | "indexing_pressure.memory.limit", |
@@ -127,6 +129,8 @@ public class IndexingPressure { |
127 | 129 | private final long replicaLimit; |
128 | 130 | private final long operationLimit; |
129 | 131 |
|
| 132 | + private final List<IndexingPressureListener> listeners = new CopyOnWriteArrayList<>(); |
| 133 | + |
130 | 134 | public IndexingPressure(Settings settings) { |
131 | 135 | this.lowWatermark = SPLIT_BULK_LOW_WATERMARK.get(settings).getBytes(); |
132 | 136 | this.lowWatermarkSize = SPLIT_BULK_LOW_WATERMARK_SIZE.get(settings).getBytes(); |
@@ -339,12 +343,14 @@ void checkLargestPrimaryOperationIsWithinLimits( |
339 | 343 | long largestOperationSizeInBytes, |
340 | 344 | boolean allowsOperationsBeyondSizeLimit |
341 | 345 | ) { |
| 346 | + listeners.forEach(l -> l.onPrimaryOperationTracked(largestOperationSizeInBytes)); |
342 | 347 | if (largestOperationSizeInBytes > operationLimit) { |
343 | 348 | this.largeOpsRejections.getAndIncrement(); |
344 | 349 | this.totalRejectedLargeOpsBytes.addAndGet(largestOperationSizeInBytes); |
345 | 350 | if (allowsOperationsBeyondSizeLimit == false) { |
346 | 351 | this.primaryRejections.getAndIncrement(); |
347 | 352 | this.primaryDocumentRejections.addAndGet(operations); |
| 353 | + listeners.forEach(l -> l.onLargeIndexingOperationRejection(largestOperationSizeInBytes)); |
348 | 354 | throw new EsRejectedExecutionException( |
349 | 355 | "Request contains an operation of size [" |
350 | 356 | + largestOperationSizeInBytes |
@@ -489,4 +495,14 @@ public IndexingPressureStats stats() { |
489 | 495 | totalRejectedLargeOpsBytes.get() |
490 | 496 | ); |
491 | 497 | } |
| 498 | + |
| 499 | + @Override |
| 500 | + public long getMaxAllowedOperationSizeInBytes() { |
| 501 | + return operationLimit; |
| 502 | + } |
| 503 | + |
| 504 | + @Override |
| 505 | + public void addListener(IndexingPressureListener listener) { |
| 506 | + listeners.add(listener); |
| 507 | + } |
492 | 508 | } |
0 commit comments