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

Code before:
                .ctx
                .cleanup_scheduler
                .schedule(CleanupTask::Compact(task))
            {
                error!(
                    "schedule compact lock cf task failed";
                    "store_id" => self.fsm.store.id,
                    "err" => ?e,
                );
            }
        }

        self.register_compact_lock_cf_tick();
    }

    fn on_wake_up_regions(&self, abnormal_stores: Vec<u64>) {
        info!("try to wake up all hibernated regions in this store";
            "to_all" => abnormal_stores.is_empty());
        let store_id = self.ctx.store_id();
        let meta = self.ctx.store_meta.lock().unwrap();

        for (region_id, region) in &meta.regions {
            // Check whether the current region is not found on abnormal stores. If so,
            // this region is not the target to be awaken.
            if !region_on_stores(region, &abnormal_stores) {
                continue;
            }
            let peer = {
                match find_peer(region, store_id) {
                    None => continue,
                    Some(p) => p.clone(),
                }
            };
            {
                // Send MsgRegionWakeUp to Peer for awakening hibernated regions.
                let mut message = RaftMessage::default();
                message.set_region_id(*region_id);
                message.set_from_peer(peer.clone());
                message.set_to_peer(peer);
                message.set_region_epoch(region.get_region_epoch().clone());
                let mut msg = ExtraMessage::default();
                msg.set_type(ExtraMessageType::MsgRegionWakeUp);
                msg.forcely_awaken = true;
                message.set_extra_msg(msg);
                if let Err(e) = self.ctx.router.send_raft_message(message) {
                    error!(
                        "send awaken region message failed";
                        "region_id" => region_id,
                        "err" => ?e
                    );
                }

Review comment (suggestion):
I've realized that a panic may occur if a region is removed after the PD worker sends the region_ids.


Code after:
                bottommost_level_force: false,
            };
            if let Err(e) = self
                .ctx
                .cleanup_scheduler
                .schedule(CleanupTask::Compact(task))
            {
                error!(
                    "schedule compact lock cf task failed";
                    "store_id" => self.fsm.store.id,
                    "err" => ?e,
                );
            }
        }

        self.register_compact_lock_cf_tick();
    }

    fn on_wake_up_regions(&self, abnormal_stores: Vec<u64>, region_ids: Vec<u64>) {
        info!("try to wake up all hibernated regions in this store";
            "to_all" => abnormal_stores.is_empty());
        let store_id = self.ctx.store_id();
        let meta = self.ctx.store_meta.lock().unwrap();

        for region_id in region_ids {
            let region = &meta.regions[&region_id];
            // Check whether the current region is not found on abnormal stores. If so,
            // this region is not the target to be awaken.
            if !region_on_stores(region, &abnormal_stores) {
                continue;
            }
            let peer = {
                match find_peer(region, store_id) {
                    None => continue,
                    Some(p) => p.clone(),
                }
            };
            {
                // Send MsgRegionWakeUp to Peer for awakening hibernated regions.
                let mut message = RaftMessage::default();
                message.set_region_id(region_id);
                message.set_from_peer(peer.clone());
                message.set_to_peer(peer);
                message.set_region_epoch(region.get_region_epoch().clone());
                let mut msg = ExtraMessage::default();
                msg.set_type(ExtraMessageType::MsgRegionWakeUp);
                msg.forcely_awaken = true;
                message.set_extra_msg(msg);
                if let Err(e) = self.ctx.router.send_raft_message(message) {
                    error!(
                        "send awaken region message failed";