-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix loop of OffsetForLeaderEpoch requests on quick leader changes #4433
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
668b5d9
Fix loop of OffsetForLeaderEpoch requests on quick leader changes
milindl b40e9c3
Address review comments
milindl c39f7c2
Merge branch 'master' into dev_bug_offsetforleaderepoch
milindl 23bab94
Add CHANGELOG.md entry
milindl 62c8d19
Merge branch 'master' into dev_bug_offsetforleaderepoch
milindl b12a8a7
Merge branch 'master' into dev_bug_offsetforleaderepoch
milindl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -212,6 +212,95 @@ static void do_test_ssl_error_retried(void) { | |
} | ||
|
||
|
||
/** | ||
* @brief If there's an OffsetForLeaderEpoch request which fails, and the leader | ||
* changes meanwhile, we end up in an infinite loop of OffsetForLeaderEpoch | ||
* requests. | ||
* Specifically: | ||
* a. Leader Change - causes OffsetForLeaderEpoch | ||
* request 'A'. | ||
* b. Request 'A' fails with a retriable error, and we retry it. | ||
* c. While waiting for Request 'A', the leader changes again, and we send a | ||
* Request 'B', but the leader epoch is not updated correctly in this | ||
* request, causing a loop. | ||
* | ||
* See #4425. | ||
*/ | ||
static void do_test_two_leader_changes(void) { | ||
const char *topic = test_mk_topic_name(__FUNCTION__, 1); | ||
const char *c1_groupid = topic; | ||
rd_kafka_t *c1; | ||
const char *bootstraps; | ||
rd_kafka_mock_cluster_t *mcluster; | ||
int msg_cnt = 5; | ||
uint64_t testid = test_id_generate(); | ||
rd_kafka_conf_t *conf; | ||
|
||
SUB_TEST_QUICK(); | ||
|
||
mcluster = test_mock_cluster_new(2, &bootstraps); | ||
rd_kafka_mock_topic_create(mcluster, topic, 1, 2); | ||
rd_kafka_mock_partition_set_leader(mcluster, topic, 0, 1); | ||
|
||
/* Seed the topic with messages */ | ||
test_produce_msgs_easy_v(topic, testid, 0, 0, msg_cnt, 10, | ||
"bootstrap.servers", bootstraps, | ||
"batch.num.messages", "1", NULL); | ||
|
||
test_conf_init(&conf, NULL, 60); | ||
|
||
test_conf_set(conf, "bootstrap.servers", bootstraps); | ||
test_conf_set(conf, "auto.offset.reset", "earliest"); | ||
test_conf_set(conf, "debug", "protocol"); | ||
|
||
c1 = test_create_consumer(c1_groupid, NULL, conf, NULL); | ||
test_consumer_subscribe(c1, topic); | ||
|
||
/* Consume initial messages and join the group, etc. */ | ||
test_consumer_poll("MSG_INIT", c1, testid, 0, 0, msg_cnt, NULL); | ||
|
||
/* The leader will change from 1->2, and the OffsetForLeaderEpoch will | ||
* be sent to broker 2. We need to first fail it with | ||
* an error, and then give enough time to change the leader before | ||
* returning a success. */ | ||
rd_kafka_mock_broker_push_request_error_rtts( | ||
mcluster, 2, RD_KAFKAP_OffsetForLeaderEpoch, 1, | ||
RD_KAFKA_RESP_ERR_KAFKA_STORAGE_ERROR, 900); | ||
|
||
rd_kafka_mock_broker_push_request_error_rtts( | ||
mcluster, 2, RD_KAFKAP_OffsetForLeaderEpoch, 1, | ||
RD_KAFKA_RESP_ERR_NO_ERROR, 1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can merge these two. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
rd_kafka_mock_partition_set_leader(mcluster, topic, 0, 2); | ||
rd_kafka_poll(c1, 1000); | ||
/* Enough time to make a request, fail with a retriable error, and | ||
* retry. */ | ||
rd_sleep(1); | ||
|
||
/* Reset leader. */ | ||
rd_kafka_mock_partition_set_leader(mcluster, topic, 0, 1); | ||
rd_kafka_poll(c1, 1000); | ||
rd_sleep(1); | ||
|
||
/* There should be no infinite loop of OffsetForLeaderEpoch, and | ||
* consequently, we should be able to consume these messages as a sign | ||
* of success. */ | ||
test_produce_msgs_easy_v(topic, testid, 0, 0, msg_cnt, 10, | ||
"bootstrap.servers", bootstraps, | ||
"batch.num.messages", "1", NULL); | ||
|
||
test_consumer_poll("MSG_INIT", c1, testid, 0, 0, msg_cnt, NULL); | ||
|
||
|
||
rd_kafka_destroy(c1); | ||
|
||
test_mock_cluster_destroy(mcluster); | ||
|
||
TEST_LATER_CHECK(); | ||
SUB_TEST_PASS(); | ||
} | ||
|
||
|
||
int main_0139_offset_validation_mock(int argc, char **argv) { | ||
|
||
if (test_needs_auth()) { | ||
|
@@ -223,5 +312,7 @@ int main_0139_offset_validation_mock(int argc, char **argv) { | |
|
||
do_test_ssl_error_retried(); | ||
|
||
do_test_two_leader_changes(); | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm that this test fails with the old code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it fails with a timeout after we enter the infinite loop