Class IndexingPressureAwareContentAggregator
- All Implemented Interfaces:
Closeable,AutoCloseable,CheckedConsumer<RestChannel,,Exception> Releasable,BaseRestHandler.RequestBodyChunkConsumer,BaseRestHandler.RestChannelConsumer
IndexingPressure.
This is intended for indexing-related REST endpoints that receive opaque request bodies (e.g. protobuf) which must be fully accumulated before processing. It provides backpressure by reserving memory up front and rejecting oversized requests with a 413 status.
When accept(RestChannel) is called, the aggregator reserves memory via
IndexingPressure.markCoordinatingOperationStarted(int, long, boolean). If the reservation fails
(e.g. EsRejectedExecutionException under heavy load), the IndexingPressureAwareContentAggregator.CompletionHandler.onFailure(org.elasticsearch.rest.RestChannel, java.lang.Exception)
callback is invoked so the caller can produce a format-appropriate error response (e.g. protobuf).
Once all chunks are accumulated, the reservation is lowered to the actual size and the
IndexingPressureAwareContentAggregator.CompletionHandler is invoked with the aggregated content and the pressure reservation
(as a Releasable) for the caller to release when appropriate.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTransforms the accumulated request body before it is handed to theIndexingPressureAwareContentAggregator.CompletionHandler.static interfaceCallback for request body accumulation lifecycle events. -
Constructor Summary
ConstructorsConstructorDescriptionIndexingPressureAwareContentAggregator(RestRequest request, IndexingPressure indexingPressure, long maxRequestSize, IndexingPressureAwareContentAggregator.CompletionHandler completionHandler, IndexingPressureAwareContentAggregator.BodyPostProcessor bodyPostProcessor) -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(RestChannel channel) voidhandleChunk(RestChannel channel, ReleasableBytesReference chunk, boolean isLast) Handle one chunk of the request body.voidCalled when the stream closes.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.rest.BaseRestHandler.RestChannelConsumer
closeMethods inherited from interface org.elasticsearch.core.CheckedConsumer
andThen
-
Constructor Details
-
IndexingPressureAwareContentAggregator
public IndexingPressureAwareContentAggregator(RestRequest request, IndexingPressure indexingPressure, long maxRequestSize, IndexingPressureAwareContentAggregator.CompletionHandler completionHandler, IndexingPressureAwareContentAggregator.BodyPostProcessor bodyPostProcessor)
-
-
Method Details
-
accept
- Specified by:
acceptin interfaceCheckedConsumer<RestChannel,Exception>
-
handleChunk
Description copied from interface:BaseRestHandler.RequestBodyChunkConsumerHandle one chunk of the request body. The handler must close the chunk once it is no longer needed to avoid leaking.- Specified by:
handleChunkin interfaceBaseRestHandler.RequestBodyChunkConsumer- Parameters:
channel- The rest channel associated to the requestchunk- The chunk of request body that is ready for processingisLast- Whether the chunk is the last one of the request
-
streamClose
public void streamClose()Description copied from interface:BaseRestHandler.RequestBodyChunkConsumerCalled when the stream closes. This could happen prior to the completion of the request if the underlying channel was closed. Implementors should do their best to clean up resources and early terminate request processing if it is triggered before a response is generated.- Specified by:
streamClosein interfaceBaseRestHandler.RequestBodyChunkConsumer
-