Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to list the in-sync replicas (ISR) for a Kafka topic partition.
Kafka
isr = admin_client.describe_topics(['[1]'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'partition' or 'replica' instead of the topic name.
✗ Incorrect
The describe_topics method requires the topic name to fetch ISR info.
2fill in blank
mediumComplete the code to fetch the ISR list from the partition metadata.
Kafka
isr_list = partition_metadata.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replicas' which lists all replicas, not just in-sync ones.
✗ Incorrect
The isr attribute holds the list of in-sync replicas for the partition.
3fill in blank
hardFix the error in the code to correctly check if a replica is in the ISR set.
Kafka
if replica_id [1] partition_metadata.isr: print('Replica is in ISR')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which compares equality, not membership.
✗ Incorrect
Use in to check if replica_id is inside the ISR list.
4fill in blank
hardFill both blanks to create a dictionary of partitions with their ISR counts.
Kafka
isr_counts = {partition.partition: len(partition.[1]) for partition in topic_metadata.[2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replicas' instead of 'isr' for ISR count.
✗ Incorrect
Each partition's ISR list is accessed by isr, and partitions are listed in partitions.
5fill in blank
hardFill all three blanks to filter partitions with ISR count less than 3.
Kafka
low_isr_partitions = {p.partition: len(p.[1]) for p in topic_metadata.[2] if len(p.[3]) < 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'replicas' instead of 'isr' for ISR length.
✗ Incorrect
We use isr to get the ISR list length and partitions to iterate all partitions.