Search in sources :

Example 1 with TimeValue

use of org.elasticsearch.core.TimeValue in project flink by apache.

the class Elasticsearch7SinkBuilder method getBulkProcessorBuilderFactory.

@Override
protected BulkProcessorBuilderFactory getBulkProcessorBuilderFactory() {
    return new BulkProcessorBuilderFactory() {

        @Override
        public BulkProcessor.Builder apply(RestHighLevelClient client, BulkProcessorConfig bulkProcessorConfig, BulkProcessor.Listener listener) {
            BulkProcessor.Builder builder = BulkProcessor.builder(new // This cannot be inlined as a
            BulkRequestConsumerFactory() {

                // lambda because then
                // deserialization fails
                @Override
                public void accept(BulkRequest bulkRequest, ActionListener<BulkResponse> bulkResponseActionListener) {
                    client.bulkAsync(bulkRequest, RequestOptions.DEFAULT, bulkResponseActionListener);
                }
            }, listener);
            if (bulkProcessorConfig.getBulkFlushMaxActions() != -1) {
                builder.setBulkActions(bulkProcessorConfig.getBulkFlushMaxActions());
            }
            if (bulkProcessorConfig.getBulkFlushMaxMb() != -1) {
                builder.setBulkSize(new ByteSizeValue(bulkProcessorConfig.getBulkFlushMaxMb(), ByteSizeUnit.MB));
            }
            if (bulkProcessorConfig.getBulkFlushInterval() != -1) {
                builder.setFlushInterval(new TimeValue(bulkProcessorConfig.getBulkFlushInterval()));
            }
            BackoffPolicy backoffPolicy;
            final TimeValue backoffDelay = new TimeValue(bulkProcessorConfig.getBulkFlushBackOffDelay());
            final int maxRetryCount = bulkProcessorConfig.getBulkFlushBackoffRetries();
            switch(bulkProcessorConfig.getFlushBackoffType()) {
                case CONSTANT:
                    backoffPolicy = BackoffPolicy.constantBackoff(backoffDelay, maxRetryCount);
                    break;
                case EXPONENTIAL:
                    backoffPolicy = BackoffPolicy.exponentialBackoff(backoffDelay, maxRetryCount);
                    break;
                case NONE:
                    backoffPolicy = BackoffPolicy.noBackoff();
                    break;
                default:
                    throw new IllegalArgumentException("Received unknown backoff policy type " + bulkProcessorConfig.getFlushBackoffType());
            }
            builder.setBackoffPolicy(backoffPolicy);
            return builder;
        }
    };
}
Also used : ActionListener(org.elasticsearch.action.ActionListener) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) BulkProcessor(org.elasticsearch.action.bulk.BulkProcessor) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) TimeValue(org.elasticsearch.core.TimeValue)

Example 2 with TimeValue

use of org.elasticsearch.core.TimeValue in project flink by apache.

the class Elasticsearch7ApiCallBridge method configureBulkProcessorBackoff.

@Override
public void configureBulkProcessorBackoff(BulkProcessor.Builder builder, @Nullable ElasticsearchSinkBase.BulkFlushBackoffPolicy flushBackoffPolicy) {
    BackoffPolicy backoffPolicy;
    if (flushBackoffPolicy != null) {
        switch(flushBackoffPolicy.getBackoffType()) {
            case CONSTANT:
                backoffPolicy = BackoffPolicy.constantBackoff(new TimeValue(flushBackoffPolicy.getDelayMillis()), flushBackoffPolicy.getMaxRetryCount());
                break;
            case EXPONENTIAL:
            default:
                backoffPolicy = BackoffPolicy.exponentialBackoff(new TimeValue(flushBackoffPolicy.getDelayMillis()), flushBackoffPolicy.getMaxRetryCount());
        }
    } else {
        backoffPolicy = BackoffPolicy.noBackoff();
    }
    builder.setBackoffPolicy(backoffPolicy);
}
Also used : BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) TimeValue(org.elasticsearch.core.TimeValue)

Aggregations

BackoffPolicy (org.elasticsearch.action.bulk.BackoffPolicy)2 TimeValue (org.elasticsearch.core.TimeValue)2 ActionListener (org.elasticsearch.action.ActionListener)1 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)1 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)1 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)1