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-15022: [8/N] more tests for HAAssignor #14164

Merged
merged 5 commits into from Aug 9, 2023

Conversation

lihaosky
Copy link
Collaborator

@lihaosky lihaosky commented Aug 7, 2023

Description

  1. More tests for HighAvailabilityTaskAssignor
  2. Remove null and optional check for RackAwareTaskAssignor
  3. Pass rack aware assignor configs to getMainConsumerConfigs so that they can be picked up in rebalance protocol
  4. Change STATELESS_NON_OVERLAP_COST to 0. It was a mistake to be 1. Stateless tasks should be moved without this cost.

Tests

Update of existing tests

@@ -300,7 +329,9 @@ private static Properties streamsProperties(final String appId,
// Increasing the number of threads to ensure that a rebalance happens each time a consumer sends a rejoin (KAFKA-10455)
mkEntry(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 40),
mkEntry(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.StringSerde.class.getName()),
mkEntry(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.StringSerde.class.getName())
mkEntry(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.StringSerde.class.getName()),
mkEntry(CommonClientConfigs.CLIENT_RACK_CONFIG, AssignmentTestUtils.RACK_0),
Copy link
Member

Choose a reason for hiding this comment

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

Why is this hard-coded? Should we use different racks for different KS instances?

@@ -91,6 +91,7 @@ private Properties effectiveConfigFrom(final Properties initialConfig) {
effectiveConfig.put(KafkaConfig.MessageMaxBytesProp(), 1000000);
effectiveConfig.put(KafkaConfig.ControlledShutdownEnableProp(), true);
effectiveConfig.put(KafkaConfig.ZkSessionTimeoutMsProp(), 10000);
effectiveConfig.put(KafkaConfig.RackProp(), "rack0");
Copy link
Member

Choose a reason for hiding this comment

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

why do we need this overwrite?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Might be some left over change. Let me delete it


if (topicPartitionInfo != null) {
lenient().when(mockInternalTopicManager.getTopicPartitionInfo(anySet())).thenAnswer(
i -> {
Copy link
Member

Choose a reason for hiding this comment

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

So i is the input parameter passed into getTopicPartitionInfo ? -- Can we find a better name?

return tp;
}
}
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Is null right here? Or should it be an empty Map ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can return empty Map.

configureDefault();

createDefaultMockTaskManager();
final List<Map<String, List<TopicPartitionInfo>>> changelogTopicPartitionInfo = getTopicPartitionInfo(3,
Copy link
Member

Choose a reason for hiding this comment

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

nit: move first parameter 3, into it's own line below (hard to read the code otherwise)

@@ -1213,12 +1376,18 @@ public void testAssignWithInternalTopics() {
final List<String> topics = asList("topic1", APPLICATION_ID + "-topicX");
final Set<TaskId> allTasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);

final MockInternalTopicManager internalTopicManager = configureDefault();
createDefaultMockTaskManager();
final List<Map<String, List<TopicPartitionInfo>>> changelogTopicPartitionInfo = getTopicPartitionInfo(4,
Copy link
Member

Choose a reason for hiding this comment

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

nit: move first parameter to next line

@@ -1241,12 +1410,18 @@ public void testAssignWithInternalTopicThatsSourceIsAnotherInternalTopic() {
final List<String> topics = asList("topic1", APPLICATION_ID + "-topicX", APPLICATION_ID + "-topicZ");
final Set<TaskId> allTasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);

final MockInternalTopicManager internalTopicManager = configureDefault();
createDefaultMockTaskManager();
final List<Map<String, List<TopicPartitionInfo>>> changelogTopicPartitionInfo = getTopicPartitionInfo(4,
Copy link
Member

Choose a reason for hiding this comment

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

as above

@@ -1768,16 +1993,22 @@ public void shouldReturnInterleavedAssignmentWithUnrevokedPartitionsRemovedWhenN
final Set<TaskId> allTasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);

subscriptions.put(CONSUMER_1,
Copy link
Member

@mjsax mjsax Aug 8, 2023

Choose a reason for hiding this comment

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

nit: move CONSUMER_1 to next line, too (same below)

KeyValue.pair(NODE_3, asList(REPLICA_3))
);

final List<Map<String, List<TopicPartitionInfo>>> ret = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

ret is not a good variable name

ret.add(new HashMap<>());
for (final String topic : topics) {
final List<TopicPartitionInfo> topicPartitionInfoList = new ArrayList<>();
ret.get(ret.size() - 1).put(topic, topicPartitionInfoList);
Copy link
Member

@mjsax mjsax Aug 8, 2023

Choose a reason for hiding this comment

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

Should we add a local variable instead of getting the map from the list? -- Similar to topicPartitionInfoList?

changelogPartitionsForTask.put(taskId, mkSet(new TopicPartition(changelogTopicName, i)));
tasksForTopicGroup.computeIfAbsent(new Subtopology(subtopology, null), k -> new HashSet<>()).add(taskId);

final Random random = new Random();
Copy link
Member

@mjsax mjsax Aug 8, 2023

Choose a reason for hiding this comment

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

We should init Random with a value that we log (to allow us to reproduce the same test)

final long seed = System.currentTimeMillis():
log.info(seed); // or just use println
final Random random = new Random(seed);

final UUID uuid = uuidForInt(i);
clientStates.put(uuid, emptyInstance(uuid, statefulTaskEndOffsetSums));
final Random random = new Random();
Copy link
Member

@mjsax mjsax Aug 8, 2023

Choose a reason for hiding this comment

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

as above: maybe setup Random inside @BeforeTest instead and share?

EMPTY_RACK_AWARE_ASSIGNMENT_TAGS);
EMPTY_RACK_AWARE_ASSIGNMENT_TAGS,
null,
null,
Copy link
Member

Choose a reason for hiding this comment

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

fix indention

EMPTY_RACK_AWARE_ASSIGNMENT_TAGS);
EMPTY_RACK_AWARE_ASSIGNMENT_TAGS,
null,
null,
Copy link
Member

Choose a reason for hiding this comment

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

fix indention

@mjsax mjsax merged commit 8730816 into apache:trunk Aug 9, 2023
1 check was pending
@lihaosky lihaosky deleted the rack-aware-more-tests branch August 10, 2023 04:12
jeqo pushed a commit to aiven/kafka that referenced this pull request Aug 15, 2023
Part of KIP-925.

- Add more tests for HighAvailabilityTaskAssignor
- Remove null and optional check for RackAwareTaskAssignor
- Pass rack aware assignor configs to getMainConsumerConfigs so that they can be picked up in rebalance protocol
- Change STATELESS_NON_OVERLAP_COST to 0. It was a mistake to be 1. Stateless tasks should be moved without this cost.
- Update of existing tests

Reviewers: Matthias J. Sax <matthias@confluent.io>
jeqo pushed a commit to jeqo/kafka that referenced this pull request Aug 15, 2023
Part of KIP-925.

- Add more tests for HighAvailabilityTaskAssignor
- Remove null and optional check for RackAwareTaskAssignor
- Pass rack aware assignor configs to getMainConsumerConfigs so that they can be picked up in rebalance protocol
- Change STATELESS_NON_OVERLAP_COST to 0. It was a mistake to be 1. Stateless tasks should be moved without this cost.
- Update of existing tests

Reviewers: Matthias J. Sax <matthias@confluent.io>
jeqo pushed a commit to jeqo/kafka that referenced this pull request Aug 15, 2023
Part of KIP-925.

- Add more tests for HighAvailabilityTaskAssignor
- Remove null and optional check for RackAwareTaskAssignor
- Pass rack aware assignor configs to getMainConsumerConfigs so that they can be picked up in rebalance protocol
- Change STATELESS_NON_OVERLAP_COST to 0. It was a mistake to be 1. Stateless tasks should be moved without this cost.
- Update of existing tests

Reviewers: Matthias J. Sax <matthias@confluent.io>
rreddy-22 pushed a commit to rreddy-22/kafka-rreddy that referenced this pull request Sep 20, 2023
Part of KIP-925.

- Add more tests for HighAvailabilityTaskAssignor
- Remove null and optional check for RackAwareTaskAssignor
- Pass rack aware assignor configs to getMainConsumerConfigs so that they can be picked up in rebalance protocol
- Change STATELESS_NON_OVERLAP_COST to 0. It was a mistake to be 1. Stateless tasks should be moved without this cost.
- Update of existing tests

Reviewers: Matthias J. Sax <matthias@confluent.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants