Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 关于 TiKV proposal apply 的一点疑问

At the end of the article TiKV Source Code Reading Series (18) Raft Propose Commit and Apply Scenario Analysis, there is the following description:
There is a special case here, which is the so-called “empty log”. In the implementation of raft-rs, when a new Leader is elected, the new Leader will broadcast an “empty log” to commit the logs from the previous term (for details, please refer to the Raft paper). At this time, there may still be some proposals proposed in the previous term that are still in the pending stage, and because a new Leader has been generated, these proposals can never be confirmed, so we need to clean them up to avoid the associated
callback
not being called, which would lead to some resources not being released. The cleanup logic refers to theApplyFsm::handle_entries_normal
function.
It mentions — “there may still be some proposals proposed in the previous term that are still in the pending stage, and because a new Leader has been generated, these proposals can never be confirmed.” My question is, shouldn’t these proposals be cleaned up and directly return a StaleCommand error when this leader last lost leadership, rather than waiting until it is re-elected as leader to clean them up?