Skip to content
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

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

frankvicky
Copy link
Contributor

JIRA: KAFKA-18561
Remove withKip853Rpc and replace it with withRaftProtocol and adjust the corresponding test.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added triage PRs from the community tests Test fixes (including flaky tests) kraft labels Jan 17, 2025
@frankvicky
Copy link
Contributor Author

Hi @ahuang98
Please take a look when you have a free cycle.
Many thanks 🙇🏼

@ijuma ijuma requested a review from jsancio January 18, 2025 13:39
@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from c36f9bc to 312c113 Compare January 21, 2025 02:29
@ijuma
Copy link
Member

ijuma commented Jan 22, 2025

@jsancio You're ok with this?

Copy link

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from b93875b to fabd9f6 Compare January 26, 2025 02:04
Copy link

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from 4e56589 to 543467d Compare January 29, 2025 02:55
Copy link

A label of 'needs-attention' was automatically added to this PR in order to raise the
attention of the committers. Once this issue has been triaged, the triage label
should be removed to prevent this automation from happening again.

@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from e135aed to 826ba56 Compare January 31, 2025 07:42
@ahuang98
Copy link
Contributor

ahuang98 commented Jan 31, 2025

@ijuma I introduced withRaftProtocol and believe @jsancio is okay with this change. I'll review first

Copy link
Contributor

@ahuang98 ahuang98 left a 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 with latestProtocol() 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) {
Copy link
Contributor

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()

Copy link
Contributor Author

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.

Comment on lines 67 to 68
private static final String KIP_595_PROTOCOL = "KIP_595_PROTOCOL";
private static final String KIP_853_PROTOCOL = "KIP_853_PROTOCOL";
Copy link
Contributor

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

Copy link
Contributor

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 {
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: support853 -> reconfigSupported

Copy link
Contributor

@ahuang98 ahuang98 Mar 5, 2025

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()

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 😆

@github-actions github-actions bot removed needs-attention triage PRs from the community labels Feb 1, 2025
@frankvicky frankvicky force-pushed the KAFKA-18561 branch 4 times, most recently from cb577db to 5237314 Compare February 12, 2025 04:46
@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from d990b08 to 8a91dd6 Compare February 17, 2025 09:08
@ahuang98
Copy link
Contributor

the easiest way is to test all protocols since the key difference between these protocols is support re-config or not.
WDYT?

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. KIP_853_PROTOCOL necessarily includes KIP_595_PROTOCOL, KIP_996_PROTOCOL includes KIP_853_PROTOCOL and KIP_595_PROTOCOL), testing a version before KIP_853 and any one version after KIP_853 should be sufficient.

@ahuang98
Copy link
Contributor

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

@frankvicky frankvicky force-pushed the KAFKA-18561 branch 2 times, most recently from f4e13da to aa09cd8 Compare February 23, 2025 14:34
JIRA: KAFKA-18561
Remove withKip853Rpc and replace with withRaftProtocol and adjust
corresponding test.
@ahuang98
Copy link
Contributor

ahuang98 commented Mar 5, 2025

@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),
Copy link
Contributor

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)
Copy link
Contributor

@ahuang98 ahuang98 Mar 7, 2025

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

@ahuang98 ahuang98 left a 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

Copy link
Member

@jsancio jsancio left a 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)
Copy link
Member

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.

Comment on lines 56 to 58
import static org.apache.kafka.raft.RaftClientTestContext.Builder;
import static org.apache.kafka.raft.RaftClientTestContext.MockListener;
import static org.apache.kafka.raft.RaftClientTestContext.RaftProtocol;
Copy link
Member

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.

Copy link
Contributor Author

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"})
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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"})
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

@frankvicky frankvicky left a 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"})
Copy link
Contributor Author

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.

Comment on lines 56 to 58
import static org.apache.kafka.raft.RaftClientTestContext.Builder;
import static org.apache.kafka.raft.RaftClientTestContext.MockListener;
import static org.apache.kafka.raft.RaftClientTestContext.RaftProtocol;
Copy link
Contributor Author

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"})
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved kraft tests Test fixes (including flaky tests)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants