Principle:Apache Kafka Coordinator Partition Unloading
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Systems, Coordinator_Framework |
| Last Updated | 2026-02-09 12:00 GMT |
Overview
A graceful shutdown mechanism that cleans up coordinator resources when a broker loses leadership of a partition.
Description
Coordinator Partition Unloading is triggered when a broker is no longer the leader for a coordinator partition or when the topic is deleted. It transitions the coordinator to the CLOSED state, deregisters the partition writer listener, cancels all timers, fails any deferred events, calls the shard's onUnloaded callback, and removes the context from the runtime's map.
Usage
Use this principle to understand how coordinators handle leadership loss. Proper unloading prevents resource leaks and stale state.
Theoretical Basis
- Epoch Check: Only process unload if the request epoch is higher than the current epoch, or if the topic was deleted (empty epoch).
- State Transition: Transition to CLOSED state, triggering cleanup callbacks.
- Resource Cleanup: Deregister listeners, cancel timers, fail pending operations.
- Context Removal: Remove the coordinator context from the runtime's map to free memory.