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

Code before:

    fn delete_snapshot(&self, key: &SnapKey, snap: &Snapshot, check_entry: bool) -> bool {
        self.snap_mgr.delete_snapshot(key, snap, check_entry)
    }
}

impl<EK, ER> Runnable for Runner<EK, ER>
where
    EK: KvEngine,
    ER: RaftEngine,
{
    type Task = Task;

    fn run(&mut self, task: Task) {
        match task {
            Task::GcSnapshot => {
                if let Err(e) = self.handle_snap_mgr_gc() {
                    error!(?e;
                        "handle gc snap failed";
                        "store_id" => self.store_id,
                    );
                }

                let msg = StoreMsg::GcSnapshotFinish;
                if let Err(e) = StoreRouter::send(&self.router, msg) {
                    warn!(
                        "send StoreMsg::GcSnapshotFinish failed";
                        "err" => ?e,
                    );
                }
            }
            Task::DeleteSnapshotFiles {
                key,
                mut snapshot,
                check_entry,
            } => {
                let snapshot = snapshot.as_mut();
                if let Err(e) = snapshot.load_snapshot_meta_if_necessary() {
                    warn!(
                        "failed to load existent snapshot meta when try to build snapshot";
                        "snapshot" => %snapshot.path(),
                        "err" => ?e,
                    );
                }
                let ok = self.delete_snapshot(&key, snapshot, check_entry);
                if !ok {
                    error!("failed to delete snapshot for key {}", key);
                }
            }
        }
    }

Review comment (bug):
Let's keep it as an error, because `StoreTick::SnapGc` no longer ticks if it fails to send `StoreMsg::GcSnapshotFinish`. 

Code after:

    fn delete_snapshot(&self, key: &SnapKey, snap: &Snapshot, check_entry: bool) -> bool {
        self.snap_mgr.delete_snapshot(key, snap, check_entry)
    }
}

impl<EK, ER> Runnable for Runner<EK, ER>
where
    EK: KvEngine,
    ER: RaftEngine,
{
    type Task = Task;

    fn run(&mut self, task: Task) {
        match task {
            Task::GcSnapshot => {
                if let Err(e) = self.handle_snap_mgr_gc() {
                    error!(?e;
                        "handle gc snap failed";
                        "store_id" => self.store_id,
                    );
                }

                let msg = StoreMsg::GcSnapshotFinish;
                if let Err(e) = StoreRouter::send(&self.router, msg) {
                    warn!(
                        "send StoreMsg::GcSnapshotFinish failed, are we shutting down?";
                        "err" => ?e,
                    );
                }
            }
            Task::DeleteSnapshotFiles {
                key,
                mut snapshot,
                check_entry,
            } => {
                let snapshot = snapshot.as_mut();
                if let Err(e) = snapshot.load_snapshot_meta_if_necessary() {
                    warn!(
                        "failed to load existent snapshot meta when try to build snapshot";
                        "snapshot" => %snapshot.path(),
                        "err" => ?e,
                    );
                }
                let ok = self.delete_snapshot(&key, snapshot, check_entry);
                if !ok {
                    error!("failed to delete snapshot for key {}", key);
                }
            }
        }
    }