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-17986: Fix ConsumerRebootstrapTest and ProducerRebootstrapTest #18175

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

Conversation

peterxcli
Copy link
Contributor

@peterxcli peterxcli commented Dec 13, 2024

ProducerRebootstrapTest has many issues in using kraft.

  1. it passes unclean.leader.election.enable as server config but it is not configured on controller node. We should append the config to topic in creating topic.

  2. it assumes topic is distributed on [0, 1]. If the order is not correct, the test can't pass. We should create the topic manually to ensure the distribution.

  3. in kraft mode, the time to trigger unclean election is 5 mins. it is too long to wait. We should configure controller to reduce the number.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

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

- Add unclean.leader.election.enable=true to topic configuration when creating
  test topic to ensure controller node has the correct setting
- Set unclean.leader.election.interval.ms to 1ms (down from default 5 minutes)
  to speed up test execution in KRaft mode
@github-actions github-actions bot added triage PRs from the community core Kafka Broker tests Test fixes (including flaky tests) small Small PRs labels Dec 13, 2024
@chia7712 chia7712 changed the title KAFKA-17986: Fix ConsumerRebootstrapTest and ProducerRebootstrapTest KAFKA-17986: Fix ProducerRebootstrapTest Dec 14, 2024
@chia7712
Copy link
Contributor

@peterxcli I update the topic to match the changes. it is ok to file two PRs :)

@github-actions github-actions bot removed the small Small PRs label Dec 15, 2024
Properties topicProps = new Properties();
topicProps.put(TopicConfig.UNCLEAN_LEADER_ELECTION_ENABLE_CONFIG, "true");

admin.createTopics(List.of(new NewTopic(topicName, 2, (short) 2).configs(Utils.propsToStringMap(topicProps)))).all().get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we need cluster.waitForTopic(topicName, 2); here?

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 that's only necessary when the topic metadata has changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but create topic will change metadata, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh thanks, you're right.
But seems the old test infra doesn't wait for the metadata propagation explicitly.
So I think it's ok the skip that.

def createTopicWithAdminRaw[B <: KafkaBroker](
admin: Admin,
topic: String,
numPartitions: Int = 1,
replicationFactor: Int = 1,
replicaAssignment: collection.Map[Int, Seq[Int]] = Map.empty,
topicConfig: Properties = new Properties,
): Uuid = {
val configsMap = new util.HashMap[String, String]()
topicConfig.forEach((k, v) => configsMap.put(k.toString, v.toString))
val result = if (replicaAssignment.isEmpty) {
admin.createTopics(Collections.singletonList(new NewTopic(
topic, numPartitions, replicationFactor.toShort).configs(configsMap)))
} else {
val assignment = new util.HashMap[Integer, util.List[Integer]]()
replicaAssignment.foreachEntry { case (k, v) =>
val replicas = new util.ArrayList[Integer]
v.foreach(r => replicas.add(r.asInstanceOf[Integer]))
assignment.put(k.asInstanceOf[Integer], replicas)
}
admin.createTopics(Collections.singletonList(new NewTopic(
topic, assignment).configs(configsMap)))
}
result.topicId(topic).get()
}

Add ability to configure fixed broker ports in test framework instead of using ephemeral ports. This helps with:

- Debugging by making broker ports predictable and consistent
- Avoiding port conflicts in certain test scenarios
- Better control over broker port assignment

Changes include:
- Add fixedBrokerPorts flag to TestKitNodes and ClusterConfig
- Add port selection logic in KafkaClusterTestKit
- Add choosePort() utility method to TestUtils
- Update ClusterTest annotation to support fixed ports configuration

The change is backward compatible as fixedBrokerPorts defaults to false, maintaining existing behavior.
This reverts commit 5580f3e.
@github-actions github-actions bot added the small Small PRs label Dec 17, 2024
- Remove @disabled annotation from ConsumerRebootstrapTest
- Add clarifying comment about leader shutdown in ProducerRebootstrapTest
- Improve documentation in RebootstrapTest regarding unclean leader election
- Clean up comment formatting
@peterxcli peterxcli marked this pull request as ready for review December 17, 2024 11:43
@peterxcli
Copy link
Contributor Author

This PR only fix these two tests, will migrate them to ClusteTest after I add the ability to use fixed broker port with it.

@peterxcli
Copy link
Contributor Author

Hi @chia7712, this PR is ready for review, PTAL. Thanks!

@peterxcli peterxcli changed the title KAFKA-17986: Fix ProducerRebootstrapTest KAFKA-17986: Fix ConsumerRebootstrapTest and ProducerRebootstrapTest Dec 17, 2024
@peterxcli
Copy link
Contributor Author

@peterxcli I update the topic to match the changes. it is ok to file two PRs :)

As we discussed #18175 (comment), change this PR title back to "Fix ConsumerRebootstrapTest and ProducerRebootstrapTest".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Kafka Broker small Small PRs tests Test fixes (including flaky tests) triage PRs from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants