You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/11/03 13:37:25 UTC
[GitHub] [flink] dannycranmer opened a new pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
dannycranmer opened a new pull request #13886:
URL: https://github.com/apache/flink/pull/13886
## What is the purpose of the change
* The Flink Kinesis EFO consumer has a SubscribeToShard retry policy which will terminate the job after a given number of subsequent attempt failures. In high backpressure scenarios the Netty HTTP Client throws a ReadTimeoutException when the consumer takes longer than 30s to process a batch. If this happens (by default) 10 times in a row, the job will terminate. There is no need to terminate in this condition, and the restart results in the job falling further behind.
* There is a queue used to pass events between the network client and consumer application. When an error is thrown in the network thread, the queue is cleared to make space for the error event. This means that records will be thrown away to make space for errors (the records would be subsequently reloaded from the shard).
## Brief change log
* Excluded the ReadTimeoutException from the SubscribeToShard retry policy, such that that connector will gracefully reconnect once the consumer has processed the queued records.
* Added a new mechanism to pass exceptions between threads, meaning data does not need to be discarded. When an error is thrown, the error event will be processed by the consumer once all of the records have been processed.
## Verifying this change
* Existing unit tests continue to pass
* Added additional test coverage
* Deployed and tested on local Flink cluster
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): no
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
- The serializers: no
- The runtime per-record code paths (performance sensitive): yes
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: no
- The S3 file system connector: no
## Documentation
- Does this pull request introduce a new feature? no
- If yes, how is the feature documented? not applicable
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tzulitai closed pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
tzulitai closed pull request #13886:
URL: https://github.com/apache/flink/pull/13886
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dannycranmer commented on a change in pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
dannycranmer commented on a change in pull request #13886:
URL: https://github.com/apache/flink/pull/13886#discussion_r517186975
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -235,8 +243,13 @@ private boolean consumeAllRecordsFromKinesisShard(
String continuationSequenceNumber;
do {
- // Read timeout will occur after 30 seconds, add a sanity timeout here to prevent lockup
- FanOutSubscriptionEvent subscriptionEvent = queue.poll(DEQUEUE_WAIT_SECONDS, SECONDS);
+ FanOutSubscriptionEvent subscriptionEvent;
+ if (queue.isEmpty() && subscriptionErrorEvent.get() != null) {
Review comment:
Events are processed in chronological order, the consumer will process events in the order they arrive (since an error cancels the subscription, and no more records will be received on the same subscription). This approach is the same as using a queue with sufficient space, but avoids the scenario when the queue is full. For example, consider the following sequence:
1. batch A
2. batch B
3. batch C
4. error
The 4 events will be processed in that order. In the previous approach we would have to discard of a batch when the queue is at capacity.
If the errors were processed immediately, that would likely mean cancelling the EFO subscription and reacquiring, which would likely result in us discarding the queued record batches.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tzulitai commented on pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
tzulitai commented on pull request #13886:
URL: https://github.com/apache/flink/pull/13886#issuecomment-721653347
Thanks for the clarifications @dannycranmer! They are crystal clear :)
Merging this now to `master` ...
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #13886:
URL: https://github.com/apache/flink/pull/13886#issuecomment-720468092
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dannycranmer commented on pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
dannycranmer commented on pull request #13886:
URL: https://github.com/apache/flink/pull/13886#issuecomment-720466819
@tzulitai FYI
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dannycranmer commented on a change in pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
dannycranmer commented on a change in pull request #13886:
URL: https://github.com/apache/flink/pull/13886#discussion_r517193360
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -272,8 +289,6 @@ private boolean consumeAllRecordsFromKinesisShard(
private final CountDownLatch waitForSubscriptionLatch;
- private final Object lockObject = new Object();
Review comment:
Yes you are correct.
The order of processing that dictates we handle errors after the queue is fully consumed is similar to before. When an exception is thrown in the network thread, an error is always the last thing the consumer (record publisher) receives. Now we are not discarding batches to deliver that exception.
A better way to look at it is, what does handling the error actually mean? For this we would reacquire the EFO subscription to continue consuming data. We do not want to do this until we have processed all the records that have already arrived.
Let me know if this is still not clear.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tzulitai commented on a change in pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
tzulitai commented on a change in pull request #13886:
URL: https://github.com/apache/flink/pull/13886#discussion_r517120544
##########
File path: tools/maven/suppressions.xml
##########
@@ -43,7 +43,11 @@ under the License.
<suppress
files="FlinkKinesisProducer.java|FlinkKinesisProducerTest.java"
checks="IllegalImport"/>
- <!-- Classes copied from Hadoop -->
+ <!-- Kinesis EFO consumer required to handle Netty ReadTimeoutException -->
+ <suppress
+ files="FanOutRecordPublisherTest.java|FanOutShardSubscriber.java|FanOutShardSubscriberTest.java"
+ checks="IllegalImport"/>
Review comment:
Is this due to the fact that these classes are using non-shaded netty imports?
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -248,6 +261,10 @@ private boolean consumeAllRecordsFromKinesisShard(
eventConsumer.accept(event);
}
} else if (subscriptionEvent.isSubscriptionComplete()) {
+ if (subscriptionErrorEvent.get() != null) {
Review comment:
Question:
What exceptions is possible to appear here, in the case that a shard has been fully consumed / subscription expires?
To my understanding, under normal flow of a recoverable exception (e.g. netty read timeout), we should fall into the last branch of this `if-else` clause?
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -235,8 +243,13 @@ private boolean consumeAllRecordsFromKinesisShard(
String continuationSequenceNumber;
do {
- // Read timeout will occur after 30 seconds, add a sanity timeout here to prevent lockup
- FanOutSubscriptionEvent subscriptionEvent = queue.poll(DEQUEUE_WAIT_SECONDS, SECONDS);
+ FanOutSubscriptionEvent subscriptionEvent;
+ if (queue.isEmpty() && subscriptionErrorEvent.get() != null) {
Review comment:
Question:
Can you briefly explain why we would wait until the queue is fully consumed before handling exceptions?
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -272,8 +289,6 @@ private boolean consumeAllRecordsFromKinesisShard(
private final CountDownLatch waitForSubscriptionLatch;
- private final Object lockObject = new Object();
Review comment:
Making sure that I understand the new error throwing mechanism, from the looks of the code:
- Exceptions are now passed via an atomic reference, instead of being put into the queue
- Because of that, we no longer need to synchronize access to the queue (because it'll only ever be accessed serially in the `onNext` and `onComplete` methods). Therefore, this lock object is no longer needed.
- Also because of that, we can now simply block indefinitely when appending a subscription event to the queue, because we no longer need to let error events have a chance to take over.
What I am failing to understand is why we can now only handle errors _after_ the queue is fully consumed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot edited a comment on pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #13886:
URL: https://github.com/apache/flink/pull/13886#issuecomment-720495859
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dannycranmer commented on a change in pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
dannycranmer commented on a change in pull request #13886:
URL: https://github.com/apache/flink/pull/13886#discussion_r517210648
##########
File path: flink-connectors/flink-connector-kinesis/src/main/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriber.java
##########
@@ -248,6 +261,10 @@ private boolean consumeAllRecordsFromKinesisShard(
eventConsumer.accept(event);
}
} else if (subscriptionEvent.isSubscriptionComplete()) {
+ if (subscriptionErrorEvent.get() != null) {
Review comment:
Yes you are correct. I am not sure exactly what could appear here, I put the check in for sanity (any because some of the mocked behaviours hit this, they may not be realistic mocked behaviour). To you point, if an exception is received at this point, we could possibly ignore it, since we know the subscription is complete (shard will not be fully consumed, that is when the `continuationSequenceNumber` is `null` from a record batch).
The result of checking this is that the exception would be logged, we would backoff and count towards the retry policy (if retry-able exception). In both scenarios (subscription complete/error), the subscriber will return `INCOMPLETE` shard status and reacquire the subscription.
I am happy to remove this check if you prefer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] dannycranmer commented on a change in pull request #13886: [FLINK-19898][FLINK-19899][Kinesis][EFO] Optimise error handling and Retry Policy
Posted by GitBox <gi...@apache.org>.
dannycranmer commented on a change in pull request #13886:
URL: https://github.com/apache/flink/pull/13886#discussion_r517182787
##########
File path: tools/maven/suppressions.xml
##########
@@ -43,7 +43,11 @@ under the License.
<suppress
files="FlinkKinesisProducer.java|FlinkKinesisProducerTest.java"
checks="IllegalImport"/>
- <!-- Classes copied from Hadoop -->
+ <!-- Kinesis EFO consumer required to handle Netty ReadTimeoutException -->
+ <suppress
+ files="FanOutRecordPublisherTest.java|FanOutShardSubscriber.java|FanOutShardSubscriberTest.java"
+ checks="IllegalImport"/>
Review comment:
Yes non-shaded at check time. The Netty deps are shaded in the final build.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org