Github user rmetzger commented on a diff in the pull request:
https://github.com/apache/flink/pull/2861#discussion_r90917049
--- Diff:
flink-streaming-connectors/flink-connector-elasticsearch2/src/main/java/org/apache/flink/streaming/connectors/elasticsearch2/ElasticsearchSink.java
---
@@ -186,22 +191,44 @@ public void beforeBulk(long executionId, BulkRequest
request) {
@Override
public void afterBulk(long executionId, BulkRequest
request, BulkResponse response) {
+ boolean allRequestsRepeatable = true;
if (response.hasFailures()) {
for (BulkItemResponse itemResp :
response.getItems()) {
if (itemResp.isFailed()) {
- LOG.error("Failed to
index document in Elasticsearch: " + itemResp.getFailureMessage());
-
failureThrowable.compareAndSet(null, new
RuntimeException(itemResp.getFailureMessage()));
+ // Check if index
request can be retried
+ String
failureMessageLowercase = itemResp.getFailureMessage().toLowerCase();
+ if
(failureMessageLowercase.contains("timeout") ||
failureMessageLowercase.contains("timed out") // Generic timeout errors
+ ||
failureMessageLowercase.contains("UnavailableShardsException".toLowerCase()) //
Shard not available due to rebalancing or node down
+ ||
(failureMessageLowercase.contains("data/write/bulk") &&
failureMessageLowercase.contains("bulk")) // Bulk index queue on node full
+ ) {
+
LOG.debug("Retry batch: " + itemResp.getFailureMessage());
+
reAddBulkRequest(request);
+ } else { // Cannot
retry action
+
allRequestsRepeatable = false;
+
LOG.error("Failed to index document in Elasticsearch: " +
itemResp.getFailureMessage());
+
failureThrowable.compareAndSet(null, new
RuntimeException(itemResp.getFailureMessage()));
+ }
}
}
- hasFailure.set(true);
+ if (!allRequestsRepeatable) {
+ hasFailure.set(true);
+ }
}
}
@Override
public void afterBulk(long executionId, BulkRequest
request, Throwable failure) {
- LOG.error(failure.getMessage());
- failureThrowable.compareAndSet(null, failure);
- hasFailure.set(true);
+ if (failure instanceof ClusterBlockException //
Examples: "no master"
+ || failure instanceof
ElasticsearchTimeoutException // ElasticsearchTimeoutException sounded good,
not seen in stress tests yet
+ )
+ {
+ LOG.debug("Retry batch on throwable: "
+ failure.getMessage());
+ reAddBulkRequest(request);
+ } else {
+ LOG.error("Failed to index bulk in
Elasticsearch. " + failure.getMessage());
--- End diff --
String concat
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---