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;
}
};
}
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();
}
Aggregations