0
0
Kafkadevops~10 mins

Leader election in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the leader election strategy in Kafka configuration.

Kafka
props.put("leader.election.strategy", "[1]");
Drag options to blanks, or click blank then click option'
Aorg.apache.kafka.controller.KafkaLeaderElectionStrategy
Borg.apache.kafka.controller.LeaderElectionStrategy
Corg.apache.kafka.controller.ZkLeaderElectionStrategy
Dorg.apache.kafka.controller.DefaultLeaderElectionStrategy
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a generic or non-existent class name.
Confusing Zookeeper based strategy with Kafka's internal strategy.
2fill in blank
medium

Complete the code to configure the leader election timeout in milliseconds.

Kafka
props.put("leader.election.timeout.ms", "[1]");
Drag options to blanks, or click blank then click option'
A1000
B60000
C5000
D30000
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the timeout too low causing frequent leader elections.
Using values that are too high causing slow failover.
3fill in blank
hard

Fix the error in the code to correctly start leader election on the controller.

Kafka
controller.[1]LeaderElection();
Drag options to blanks, or click blank then click option'
Astart
Brun
Cbegin
Dinitiate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initiate' or 'begin' which are not valid method names.
Using 'run' which is unrelated here.
4fill in blank
hard

Fill both blanks to create a map of partition to leader with condition on leader id.

Kafka
Map<Integer, String> leaderMap = partitions.stream()
  .filter(p -> p.leader().id() [1] 0)
  .collect(Collectors.toMap(p -> p.partition(), p -> p.[2]()));
Drag options to blanks, or click blank then click option'
A>
BgetLeader
Cleader
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter condition.
Using 'getLeader' which is not a method on partition.
5fill in blank
hard

Fill all three blanks to create a map of topic to leader id for partitions with leader id greater than 0.

Kafka
Map<String, Integer> topicLeaderMap = partitions.stream()
  .filter(p -> p.[1]().id() [2] 0)
  .collect(Collectors.toMap(p -> p.[3](), p -> p.leader().id()));
Drag options to blanks, or click blank then click option'
Aleader
B==
Ctopic
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' in the filter.
Using 'partition()' instead of 'topic()' for the map key.