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

Code before:
                // it needs to response GcPeerResponse.
                if self.ctx.cfg.enable_v2_compatible_learner {
                    self.on_gc_peer_request(msg);
                }
            }
            // It's v2 only message and ignore does no harm.
            ExtraMessageType::MsgGcPeerResponse | ExtraMessageType::MsgFlushMemtable => (),
            ExtraMessageType::MsgRefreshBuckets => self.on_msg_refresh_buckets(msg),
        }
    }

    fn reset_raft_tick(&mut self, state: GroupState) {
        debug!(
            "reset raft tick to {:?}", state;
            "region_id"=> self.fsm.region_id(),
            "peer_id" => self.fsm.peer_id(),
        );
        self.fsm.reset_hibernate_state(state);
        self.fsm.missing_ticks = 0;
        self.fsm.peer.should_wake_up = false;
        self.register_raft_base_tick();
        if self.fsm.peer.is_leader() {
            self.register_check_leader_lease_tick();
            self.register_report_region_buckets_tick();
            self.register_check_long_uncommitted_tick();
        }
    }

    // return false means the message is invalid, and can be ignored.
    fn validate_raft_msg(&mut self, msg: &RaftMessage) -> bool {
        let region_id = msg.get_region_id();
        let to = msg.get_to_peer();

        if to.get_store_id() != self.store_id() {
            warn!(
                "store not match, ignore it";
                "region_id" => region_id,
                "to_store_id" => to.get_store_id(),
                "my_store_id" => self.store_id(),
            );
            self.ctx
                .raft_metrics
                .message_dropped
                .mismatch_store_id
                .inc();
            return false;
        }

        if !msg.has_region_epoch() {
            error!(
                "missing epoch in raft message, ignore it";

Review comment (suggestion):
```suggestion
                    "receiver_store_id" => msg.get_from_peer().get_store_id(),
                    "ignored" => !self.fsm.peer.get_store().has_gen_snap_task(),
```

Code after:
                // it needs to response GcPeerResponse.
                if self.ctx.cfg.enable_v2_compatible_learner {
                    self.on_gc_peer_request(msg);
                }
            }
            // It's v2 only message and ignore does no harm.
            ExtraMessageType::MsgGcPeerResponse | ExtraMessageType::MsgFlushMemtable => (),
            ExtraMessageType::MsgRefreshBuckets => self.on_msg_refresh_buckets(msg),
            ExtraMessageType::MsgSnapGenPrecheckRequest => {
                let passed = self.ctx.snap_mgr.recv_snap_precheck(msg.region_id);
                self.fsm.peer.send_snap_gen_precheck_response(
                    self.ctx,
                    &msg.from_peer.unwrap(),
                    passed,
                )
            }
            ExtraMessageType::MsgSnapGenPrecheckResponse => {
                let passed = msg.get_extra_msg().get_snap_gen_precheck_passed();
                fail_point!("snap_gen_precheck_failed", !passed, |_| {});
                info!(
                    "snap gen precheck response: {}", passed;
                    "region_id" => self.region_id(),
                    "peer_id" => self.peer().id,
                    "store_id" => self.store_id(),
                    "receiver_peer_id" => msg.get_from_peer().get_id(),
                    "receiver_store_id" => msg.get_from_peer().get_store_id(),
                    "ignored" => !self.fsm.peer.get_store().has_gen_snap_task(),
                );
                if passed {
                    if let Some(gen_task) = self.fsm.peer.mut_store().take_gen_snap_task() {
                        self.fsm
                            .peer
                            .pending_request_snapshot_count
                            .fetch_add(1, Ordering::SeqCst);
                        self.ctx
                            .apply_router
                            .schedule_task(self.region_id(), ApplyTask::Snapshot(gen_task));
                    }
                }
            }
        }
    }

    fn reset_raft_tick(&mut self, state: GroupState) {
        debug!(
            "reset raft tick to {:?}", state;
            "region_id"=> self.fsm.region_id(),
            "peer_id" => self.fsm.peer_id(),
        );
        self.fsm.reset_hibernate_state(state);
        self.fsm.missing_ticks = 0;