Repository: tikv/tikv
File: components/raftstore/src/store/fsm/peer.rs (Rust)

Code before:
            }
            SignificantMsg::UnsafeRecoveryWaitApply(syncer) => {
                self.on_unsafe_recovery_wait_apply(syncer)
            }
            SignificantMsg::UnsafeRecoveryFillOutReport(syncer) => {
                self.on_unsafe_recovery_fill_out_report(syncer)
            }
            // for snapshot recovery (safe recovery)
            SignificantMsg::SnapshotBrWaitApply(syncer) => self.on_snapshot_br_wait_apply(syncer),
            SignificantMsg::CheckPendingAdmin(ch) => self.on_check_pending_admin(ch),
            SignificantMsg::ReadyToDestroyPeer {
                merged_by_target,
                clear_stat,
            } => {
                assert!(self.fsm.peer.pending_remove);
                self.on_ready_destroy_peer(merged_by_target, clear_stat);
            }
        }
    }

    fn on_enter_pre_force_leader(
        &mut self,
        syncer: UnsafeRecoveryForceLeaderSyncer,
        failed_stores: HashSet<u64>,
    ) {
        match self.fsm.peer.force_leader {
            Some(ForceLeaderState::PreForceLeader { .. }) => {
                self.on_force_leader_fail();
            }
            Some(ForceLeaderState::ForceLeader { .. }) => {
                // already is a force leader, do nothing
                return;
            }
            Some(ForceLeaderState::WaitTicks { .. }) => {
                self.fsm.peer.force_leader = None;
            }
            Some(ForceLeaderState::WaitForceCompact { .. }) => {
                self.fsm.peer.force_leader = None;
            }
            None => {}
        }

        if !self.fsm.peer.is_initialized() {
            warn!(
                "Unsafe recovery, cannot force leader since this peer is not initialized";
                "region_id" => self.fsm.region_id(),
                "peer_id" => self.fsm.peer_id(),
            );
            return;
        }


Review comment (suggestion):
```suggestion
                    info!("ignore delayed destroy peer message";
```

Code after:
            } => self.on_unsafe_recovery_pre_demote_failed_voters(syncer, failed_voters),
            SignificantMsg::UnsafeRecoveryDestroy(syncer) => {
                self.on_unsafe_recovery_destroy(syncer)
            }
            SignificantMsg::UnsafeRecoveryWaitApply(syncer) => {
                self.on_unsafe_recovery_wait_apply(syncer)
            }
            SignificantMsg::UnsafeRecoveryFillOutReport(syncer) => {
                self.on_unsafe_recovery_fill_out_report(syncer)
            }
            // for snapshot recovery (safe recovery)
            SignificantMsg::SnapshotBrWaitApply(syncer) => self.on_snapshot_br_wait_apply(syncer),
            SignificantMsg::CheckPendingAdmin(ch) => self.on_check_pending_admin(ch),
            SignificantMsg::ReadyToDestroyPeer {
                to_peer_id,
                merged_by_target,
                clear_stat,
            } => {
                if to_peer_id != self.fsm.peer_id() {
                    // Ignore redundant or stale messages from an outdated peer for the same region.
                    // This handles the corner case where a stale peer is being removed
                    // asynchronously while a new peer for the region is added.
                    // If the async cleanup thread returns a delayed message
                    // aimed to the removed peer, skip it to avoid acting on stale state.
                    // This is a corner case after introducing `async destroy peer` by PR#18805.
                    info!("delayed destroy peer message";
                        "old_peer_id" => to_peer_id,
                        "peer_id" => self.fsm.peer_id());
                    return;
                }
                self.on_ready_destroy_peer(merged_by_target, clear_stat);
            }
        }
    }

    fn on_enter_pre_force_leader(
        &mut self,
        syncer: UnsafeRecoveryForceLeaderSyncer,
        failed_stores: HashSet<u64>,
    ) {
        match self.fsm.peer.force_leader {
            Some(ForceLeaderState::PreForceLeader { .. }) => {
                self.on_force_leader_fail();
            }
            Some(ForceLeaderState::ForceLeader { .. }) => {
                // already is a force leader, do nothing
                return;
            }
            Some(ForceLeaderState::WaitTicks { .. }) => {
                self.fsm.peer.force_leader = None;
            }