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

Code before:
        // snapshot is applied.
        meta.regions
            .insert(region_id, peer.get_peer().region().to_owned());
        meta.region_read_progress
            .insert(region_id, peer.peer.read_progress.clone());

        let mailbox = BasicMailbox::new(tx, peer, self.ctx.router.state_cnt().clone());
        self.ctx.router.register(region_id, mailbox);
        self.ctx
            .router
            .force_send(region_id, PeerMsg::Start)
            .unwrap();
        Ok(true)
    }

    fn on_compaction_finished(&mut self, event: EK::CompactedEvent) {
        if let Err(e) = self
            .ctx
            .split_check_scheduler
            .schedule(SplitCheckTask::CompactedEvent {
                event,
                region_split_check_diff: self.ctx.cfg.region_split_check_diff().0,
            })
        {
            error!(
                "failed to schedule split check for compaction finished event";
                "err" => %e,
            );
        }
    }

    fn register_load_metrics_window_tick(&self) {
        // For now, we will only gather these metrics is periodic full compaction is
        // enabled.
        if !self.ctx.cfg.periodic_full_compact_start_times.is_empty() {
            self.ctx
                .schedule_store_tick(StoreTick::LoadMetricsWindow, LOAD_STATS_WINDOW_DURATION)
        }
    }

    fn on_load_metrics_window_tick(&mut self) {
        self.register_load_metrics_window_tick();

        let proc_stat = self
            .ctx
            .process_stat
            .get_or_insert_with(|| ProcessStat::cur_proc_stat().unwrap());
        let cpu_usage: f64 = proc_stat.cpu_usage().unwrap();
        PROCESS_STAT_CPU_USAGE.set(cpu_usage);
    }


Review comment (suggestion):
How about removing `StoreMsg::CompactedEvent` and sending `SplitCheckTask::CompactedEvent`  directly at https://github.com/tikv/tikv/blob/a150e4569fda1c64763fda297f4e09775759de4a/components/engine_rocks/src/compact_listener.rs#L298

Code after:
        peer.peer.local_first_replicate = is_local_first;

        // Following snapshot may overlap, should insert into region_ranges after
        // snapshot is applied.
        meta.regions
            .insert(region_id, peer.get_peer().region().to_owned());
        meta.region_read_progress
            .insert(region_id, peer.peer.read_progress.clone());

        let mailbox = BasicMailbox::new(tx, peer, self.ctx.router.state_cnt().clone());
        self.ctx.router.register(region_id, mailbox);
        self.ctx
            .router
            .force_send(region_id, PeerMsg::Start)
            .unwrap();
        Ok(true)
    }

    fn on_compaction_finished(&mut self, event: EK::CompactedEvent) {
        if let Err(e) = self
            .ctx
            .split_check_scheduler
            .schedule(SplitCheckTask::CompactedEvent {
                event,
                region_split_check_diff: self.ctx.cfg.region_split_check_diff().0,
            })
        {
            error!(
                "failed to schedule split check for compaction finished event";
                "err" => %e,
            );
        }
    }

    fn register_load_metrics_window_tick(&self) {
        // For now, we will only gather these metrics is periodic full compaction is
        // enabled.
        if !self.ctx.cfg.periodic_full_compact_start_times.is_empty() {
            self.ctx
                .schedule_store_tick(StoreTick::LoadMetricsWindow, LOAD_STATS_WINDOW_DURATION)
        }
    }

    fn on_load_metrics_window_tick(&mut self) {
        self.register_load_metrics_window_tick();

        let proc_stat = self
            .ctx
            .process_stat
            .get_or_insert_with(|| ProcessStat::cur_proc_stat().unwrap());
        let cpu_usage: f64 = proc_stat.cpu_usage().unwrap();