Search in sources :

Example 1 with BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy 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 BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy 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)

Example 3 with BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy in project flink by apache.

the class Elasticsearch6ApiCallBridge 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.common.unit.TimeValue)

Example 4 with BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy in project flink by apache.

the class Elasticsearch2ApiCallBridge 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.common.unit.TimeValue)

Example 5 with BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy in project flink by apache.

the class Elasticsearch5ApiCallBridge 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.common.unit.TimeValue)

Aggregations

BackoffPolicy (org.elasticsearch.action.bulk.BackoffPolicy)7 TimeValue (org.elasticsearch.common.unit.TimeValue)4 ActionListener (org.elasticsearch.action.ActionListener)2 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)2 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)2 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)2 TimeValue (org.elasticsearch.core.TimeValue)2 TimeValue (io.crate.common.unit.TimeValue)1 Test (org.junit.Test)1