-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-9701 (fix): Only check protocol name when generation is valid #8324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ | |
| import org.apache.kafka.common.utils.MockTime; | ||
| import org.apache.kafka.common.utils.Time; | ||
| import org.apache.kafka.common.utils.Timer; | ||
| import org.apache.kafka.test.TestCondition; | ||
| import org.apache.kafka.test.TestUtils; | ||
| import org.junit.Test; | ||
|
|
||
|
|
@@ -365,8 +364,8 @@ public void testJoinGroupRequestWithFencedInstanceIdException() { | |
|
|
||
| @Test | ||
| public void testJoinGroupProtocolTypeAndName() { | ||
| String wrongProtocolType = "wrong-type"; | ||
| String wrongProtocolName = "wrong-name"; | ||
| final String wrongProtocolType = "wrong-type"; | ||
| final String wrongProtocolName = "wrong-name"; | ||
|
|
||
| // No Protocol Type in both JoinGroup and SyncGroup responses | ||
| assertTrue(joinGroupWithProtocolTypeAndName(null, null, null)); | ||
|
|
@@ -391,6 +390,39 @@ public void testJoinGroupProtocolTypeAndName() { | |
| () -> joinGroupWithProtocolTypeAndName(PROTOCOL_TYPE, PROTOCOL_TYPE, wrongProtocolName)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNoGenerationWillNotTriggerProtocolNameCheck() { | ||
| final String wrongProtocolName = "wrong-name"; | ||
|
|
||
| setupCoordinator(); | ||
| mockClient.reset(); | ||
| mockClient.prepareResponse(groupCoordinatorResponse(node, Errors.NONE)); | ||
| coordinator.ensureCoordinatorReady(mockTime.timer(0)); | ||
|
|
||
| mockClient.prepareResponse(body -> { | ||
| if (!(body instanceof JoinGroupRequest)) { | ||
| return false; | ||
| } | ||
| JoinGroupRequest joinGroupRequest = (JoinGroupRequest) body; | ||
| return joinGroupRequest.data().protocolType().equals(PROTOCOL_TYPE); | ||
| }, joinGroupFollowerResponse(defaultGeneration, memberId, | ||
| "memberid", Errors.NONE, PROTOCOL_TYPE)); | ||
|
|
||
| mockClient.prepareResponse(body -> { | ||
| if (!(body instanceof SyncGroupRequest)) { | ||
| return false; | ||
| } | ||
| coordinator.resetGenerationOnLeaveGroup(); | ||
|
|
||
| SyncGroupRequest syncGroupRequest = (SyncGroupRequest) body; | ||
| return syncGroupRequest.data.protocolType().equals(PROTOCOL_TYPE) | ||
| && syncGroupRequest.data.protocolName().equals(PROTOCOL_NAME); | ||
| }, syncGroupResponse(Errors.NONE, PROTOCOL_TYPE, wrongProtocolName)); | ||
|
|
||
| // No exception shall be thrown as the generation is reset. | ||
| coordinator.joinGroupIfNeeded(mockTime.timer(100L)); | ||
| } | ||
|
|
||
| private boolean joinGroupWithProtocolTypeAndName(String joinGroupResponseProtocolType, | ||
| String syncGroupResponseProtocolType, | ||
| String syncGroupResponseProtocolName) { | ||
|
|
@@ -665,7 +697,7 @@ public boolean matches(AbstractRequest body) { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
|
Author
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. Just side cleanups starting L700 |
||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -703,7 +735,7 @@ public boolean matches(AbstractRequest body) { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -738,7 +770,7 @@ public void testWakeupAfterJoinGroupReceived() throws Exception { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -811,7 +843,7 @@ public boolean matches(AbstractRequest body) { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -884,7 +916,7 @@ public void testWakeupAfterSyncGroupReceived() throws Exception { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -945,7 +977,7 @@ public void testWakeupInOnJoinComplete() throws Exception { | |
| try { | ||
| coordinator.ensureActiveGroup(); | ||
| fail("Should have woken up from ensureActiveGroup()"); | ||
| } catch (WakeupException e) { | ||
| } catch (WakeupException ignored) { | ||
| } | ||
|
|
||
| assertEquals(1, coordinator.onJoinPrepareInvokes); | ||
|
|
@@ -990,12 +1022,8 @@ private AtomicBoolean prepareFirstHeartbeat() { | |
|
|
||
| private void awaitFirstHeartbeat(final AtomicBoolean heartbeatReceived) throws Exception { | ||
| mockTime.sleep(HEARTBEAT_INTERVAL_MS); | ||
| TestUtils.waitForCondition(new TestCondition() { | ||
| @Override | ||
| public boolean conditionMet() { | ||
| return heartbeatReceived.get(); | ||
| } | ||
| }, 3000, "Should have received a heartbeat request after joining the group"); | ||
| TestUtils.waitForCondition(heartbeatReceived::get, | ||
| 3000, "Should have received a heartbeat request after joining the group"); | ||
| } | ||
|
|
||
| private FindCoordinatorResponse groupCoordinatorResponse(Node node, Errors error) { | ||
|
|
@@ -1063,10 +1091,10 @@ public static class DummyCoordinator extends AbstractCoordinator { | |
| private int onJoinCompleteInvokes = 0; | ||
| private boolean wakeupOnJoinComplete = false; | ||
|
|
||
| public DummyCoordinator(GroupRebalanceConfig rebalanceConfig, | ||
| ConsumerNetworkClient client, | ||
| Metrics metrics, | ||
| Time time) { | ||
| DummyCoordinator(GroupRebalanceConfig rebalanceConfig, | ||
| ConsumerNetworkClient client, | ||
| Metrics metrics, | ||
| Time time) { | ||
| super(rebalanceConfig, new LogContext(), client, metrics, METRIC_GROUP_PREFIX, time); | ||
| } | ||
|
|
||
|
|
||
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.
@guozhangwang @abbccdda Shouldn't we synchronise this or use a local reference of the generation to be 100% safe?