Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Kafka controller broker ID.
Kafka
controller_id = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 as the initial controller ID
Using None instead of an integer
Using broker_id directly without election
✗ Incorrect
The controller broker ID is set to -1 initially before election.
2fill in blank
mediumComplete the code to check if the current broker is the controller.
Kafka
is_controller = (broker_id [1] controller_id) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==
Using < or > which are not correct for equality check
✗ Incorrect
We check if the broker ID equals the controller ID to confirm controller status.
3fill in blank
hardFix the error in the code to elect a new controller broker.
Kafka
new_controller = min([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using controller_id which is a single value
Using broker_id which is a single ID
Using brokers which may be a dict or object, not a list
✗ Incorrect
The election picks the broker with the smallest ID from the list of broker IDs.
4fill in blank
hardFill both blanks to create a dictionary of brokers with their controller status.
Kafka
controller_status = {broker: (broker [1] controller_id) for broker in [2] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of ==
Iterating over brokers object instead of broker_ids list
✗ Incorrect
The dictionary comprehension maps each broker ID to True if it is the controller, else False.
5fill in blank
hardFill all three blanks to update the controller broker and notify all brokers.
Kafka
controller_id = [1] for broker in [2]: notify(broker, [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using controller_id instead of new_controller for assignment
Iterating over wrong variable instead of broker_ids
Sending wrong notification message
✗ Incorrect
We assign the new controller ID, then notify all brokers with a 'controller_changed' message.