Search in sources :

Example 6 with BackoffPolicy

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

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

Example 7 with BackoffPolicy

use of org.elasticsearch.action.bulk.BackoffPolicy in project crate by crate.

the class LimitedBackoffPolicyTest method testNoNext.

@Test
public void testNoNext() throws Exception {
    BackoffPolicy policy = new LimitedExponentialBackoff(0, 1, Integer.MAX_VALUE);
    Iterator<TimeValue> it = policy.iterator();
    it.next();
    expectedException.expect(NoSuchElementException.class);
    expectedException.expectMessage("Reached maximum amount of backoff iterations. Only 1 iterations allowed.");
    it.next();
}
Also used : BackoffPolicy(org.elasticsearch.action.bulk.BackoffPolicy) TimeValue(io.crate.common.unit.TimeValue) Test(org.junit.Test)

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