-
Notifications
You must be signed in to change notification settings - Fork 14.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
KAFKA-18561: Remove withKip853Rpc and replace it with withRaftProtocol #18600
base: trunk
Are you sure you want to change the base?
Conversation
Hi @ahuang98 |
2d4e93d
to
aaaab78
Compare
c36f9bc
to
312c113
Compare
@jsancio You're ok with this? |
312c113
to
d943da8
Compare
A label of 'needs-attention' was automatically added to this PR in order to raise the |
b93875b
to
fabd9f6
Compare
A label of 'needs-attention' was automatically added to this PR in order to raise the |
4e56589
to
543467d
Compare
A label of 'needs-attention' was automatically added to this PR in order to raise the |
e135aed
to
826ba56
Compare
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.
With this change it's more obvious that KafkaRaftClientTest only covers KIP_853_PROTOCOL
and lower, I wonder if it would be worth doing one of the following
- have KafkaRaftClientTest test the whole range of RaftProtocols
- replace
KIP_853_PROTOCOL
withlatestProtocol()
which will pick the last enum constant in RaftProtocol, and KafkaRaftClientTest will always test the newest protocol - java doc / rename for KafkaRaftClientTest to indicate this only covers a subset of the raft protocols
@@ -2265,4 +2267,17 @@ public ByteBuffer buffer() { | |||
return data; | |||
} | |||
} | |||
|
|||
private boolean isSupport853(RaftProtocol raftProtocol) { |
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.
you can use RaftClientTestContext.isReconfigSupported()
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.
Thanks.
I don't notice that we have such a helper method.
private static final String KIP_595_PROTOCOL = "KIP_595_PROTOCOL"; | ||
private static final String KIP_853_PROTOCOL = "KIP_853_PROTOCOL"; |
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.
my slight pref would be to remove these and just use the strings directly in the EnumSource annotations
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.
suggestion should also be applied to KafkaRaftClientTest if you agree
@CsvSource({ "false,false", "false,true", "true,false", "true,true" }) | ||
public void testLeaderListenerNotified(boolean entireLog, boolean withKip853Rpc) throws Exception { | ||
@MethodSource("generateKip853TestMatrix") | ||
public void testLeaderListenerNotified(boolean entireLog, RaftProtocol raftProtocol) throws Exception { |
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.
I guess another option would be just renaming the second parameter to boolean isReconfigSupported
, potentially easier for readers to know at a glance that we're not testing the entire set of raftProtocols (rather than navigating to the method source definition)
(then we would do .withRaftProtocol(isReconfigSupported ? KIP_853_PROTOCOL : KIP_595_PROTOCOL)
which I understand is a bit bulkier)
ReplicaKey voter1 = replicaKey(localId + 1, withKip853Rpc); | ||
ReplicaKey voter2 = replicaKey(localId + 2, withKip853Rpc); | ||
ReplicaKey observer3 = replicaKey(localId + 3, withKip853Rpc); | ||
boolean support853 = isSupport853(raftProtocol); |
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.
nit: support853
-> reconfigSupported
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.
was this change applied everywhere? we should remove isSupport853() since it's a dupe of reconfigSupported()
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.
Hi @ahuang98
Sorry for inconvience. Previously, I had a finger issue when rebasing.
Now all comments should be applied. PTAL
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.
there was no inconvenience 😅 sorry to hear about your finger! I missed your update today and will review tomorrow morning
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.
Thank you 😆
cb577db
to
5237314
Compare
d990b08
to
8a91dd6
Compare
I don't disagree it would be easy/fine to test all protocols in KafkaRaftClientTest - just to motivate why it may be excessive though - as you said we're basically testing w/o reconfig and w/ reconfig. Since each protocol is cumulative (e.g. |
Perhaps we can leave my suggestions in #18600 (review) as out of scope - I'll give another review today and see if @jsancio has time to approve |
f4e13da
to
aa09cd8
Compare
JIRA: KAFKA-18561 Remove withKip853Rpc and replace with withRaftProtocol and adjust corresponding test.
aa09cd8
to
d101ea5
Compare
@frankvicky let me know when you need another review, I spot checked some of the comments I left earlier that you thumbs up-ed and it seems they haven't all been addressed yet |
return Stream.of( | ||
Arguments.of(KIP_853_PROTOCOL, true), | ||
Arguments.of(KIP_853_PROTOCOL, false), | ||
Arguments.of(KIP_853_PROTOCOL, true), |
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.
this should be KIP_595
ReplicaKey follower2 = ReplicaKey.of(followerId2, followerDirectoryId2); | ||
|
||
RaftClientTestContext.Builder builder = new RaftClientTestContext.Builder(localId, localDirectoryId) | ||
.withKip853Rpc(withKip853Rpc); | ||
Builder builder = new Builder(localId, localDirectoryId) |
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.
Just to reduce verbosity? My preference is fully qualifying the Builder class given that it's an inner class with a pretty generic name but I'm honestly not sure which is better coding practice
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.
It's ok for me.
Full qualification is indeed more readable.
@@ -276,16 +281,16 @@ public void testListenerRenotified(boolean withKip853Rpc) throws Exception { | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { false, true }) | |||
public void testLeaderImmediatelySendsSnapshotId(boolean withKip853Rpc) throws Exception { | |||
@EnumSource(value = RaftProtocol.class) |
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.
we should have probably picked the same strategy for KafkaRaftClientSnapshotTest and KafkaRaftClientTest (either test all protocols for both tests or directly translate to matrix of KIP_595 and KIP_853)
I'm not sure if it's a big enough deal to ask you to standardize though - @jsancio thoughts?
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.
I agree that we should try to be consistent. I prefer if we inject the RaftProtocol
directly to the test as it is the most flexible abstraction. And to not inject a boolean that then gets converted to a RaftProtocol
.
I am okay testing all possible values of RaftProtocol
as long as it is not too much work to support and the tests don't take a lot longer.
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.
Thanks a bunch @frankvicky, I've tagged @jsancio to help review
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.
Thanks for this improvement @frankvicky . Looks good to me in general. Here are some suggestions to consider.
@@ -276,16 +281,16 @@ public void testListenerRenotified(boolean withKip853Rpc) throws Exception { | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { false, true }) | |||
public void testLeaderImmediatelySendsSnapshotId(boolean withKip853Rpc) throws Exception { | |||
@EnumSource(value = RaftProtocol.class) |
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.
I agree that we should try to be consistent. I prefer if we inject the RaftProtocol
directly to the test as it is the most flexible abstraction. And to not inject a boolean that then gets converted to a RaftProtocol
.
I am okay testing all possible values of RaftProtocol
as long as it is not too much work to support and the tests don't take a lot longer.
import static org.apache.kafka.raft.RaftClientTestContext.Builder; | ||
import static org.apache.kafka.raft.RaftClientTestContext.MockListener; | ||
import static org.apache.kafka.raft.RaftClientTestContext.RaftProtocol; |
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.
Let's revert this change. It cause a lot of unnecessary line changes to this file.
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.
Ok.
Just for memo: RaftProtocol
will be extracted as a single file. I will revert Builder
and MockListener
@@ -92,25 +97,25 @@ public void testNodeDirectoryId() { | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { true, false }) | |||
public void testInitializeSingleMemberQuorum(boolean withKip853Rpc) throws IOException { | |||
@EnumSource(value = RaftProtocol.class, names = {"KIP_595_PROTOCOL", "KIP_853_PROTOCOL"}) |
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.
As @ahuang98 mentioned. Let's try to be consistent between KafkaRaftClientTest
and KafkaRaftClientSnapshotTest
. Ideally we would test all RaftProtocol
but I understand if you want to consider that outside the scope of this PR if it is too difficult to change and make all of these tests pass.
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.
I think it could be done in a follow-up PR.
If you agree, I will open a ticket to trace it.
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.
Please ignore the above comment.
I tried to enable all raft protocols for KafkaRaftClientTest
, and all tests passed.
I will include this change in the next commit.
@@ -516,15 +521,15 @@ public void testEndQuorumEpochRetriesWhileResigned(boolean withKip853Rpc) throws | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { true, false }) | |||
public void testResignWillCompleteFetchPurgatory(boolean withKip853Rpc) throws Exception { | |||
@EnumSource(value = RaftClientTestContext.RaftProtocol.class, names = {"KIP_595_PROTOCOL", "KIP_853_PROTOCOL"}) |
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.
You imported RaftProtocol (import static ....RaftClientTestContext.RaftProtocol
) so you should be able to reference RaftProtocol
directly like you do in the method parameter. E.g. RaftProtocol raftProtocol
.
I am also okay if you want to pull RaftProtocol
into its own file. E.g. raft/src/test/java/org/apache/kafka/raft/RaftProtocol.java
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.
IMHO, I would prefer RaftProtocol
as a single file.
I will extract it in the next commit.
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.
@@ -516,15 +521,15 @@ public void testEndQuorumEpochRetriesWhileResigned(boolean withKip853Rpc) throws | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { true, false }) | |||
public void testResignWillCompleteFetchPurgatory(boolean withKip853Rpc) throws Exception { | |||
@EnumSource(value = RaftClientTestContext.RaftProtocol.class, names = {"KIP_595_PROTOCOL", "KIP_853_PROTOCOL"}) |
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.
IMHO, I would prefer RaftProtocol
as a single file.
I will extract it in the next commit.
import static org.apache.kafka.raft.RaftClientTestContext.Builder; | ||
import static org.apache.kafka.raft.RaftClientTestContext.MockListener; | ||
import static org.apache.kafka.raft.RaftClientTestContext.RaftProtocol; |
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.
Ok.
Just for memo: RaftProtocol
will be extracted as a single file. I will revert Builder
and MockListener
@@ -92,25 +97,25 @@ public void testNodeDirectoryId() { | |||
} | |||
|
|||
@ParameterizedTest | |||
@ValueSource(booleans = { true, false }) | |||
public void testInitializeSingleMemberQuorum(boolean withKip853Rpc) throws IOException { | |||
@EnumSource(value = RaftProtocol.class, names = {"KIP_595_PROTOCOL", "KIP_853_PROTOCOL"}) |
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.
I think it could be done in a follow-up PR.
If you agree, I will open a ticket to trace it.
JIRA: KAFKA-18561
Remove
withKip853Rpc
and replace it withwithRaftProtocol
and adjust the corresponding test.Committer Checklist (excluded from commit message)