pub fn destroy<T, C>(
        &mut self,
        ctx: &PollContext<EK, ER, T, C>,
        keep_data: bool,
    ) -> Result<()> {
        fail_point!("raft_store_skip_destroy_peer", |_| Ok(()));
        let t = Instant::now();

        let region = self.region().clone();
        info!(
            "begin to destroy";
            "region_id" => self.region_id,
            "peer_id" => self.peer.get_id(),
        );

        // Set Tombstone state explicitly
        let mut kv_wb = ctx.engines.kv.write_batch();
        let mut raft_wb = ctx.engines.raft.log_batch(1024);
        self.mut_store().clear_meta(&mut kv_wb, &mut raft_wb)?;
        write_peer_state(
            &mut kv_wb,
            &region,
            PeerState::Tombstone,
            self.pending_merge_state.clone(),
        )?;
        // write kv rocksdb first in case of restart happen between two write
        let mut write_opts = WriteOptions::new();
        write_opts.set_sync(ctx.cfg.sync_log);
        ctx.engines.kv.write_opt(&kv_wb, &write_opts)?;
        ctx.engines.raft.consume(&mut raft_wb, ctx.cfg.sync_log)?;

        if self.get_store().is_initialized() && !keep_data {
            // If we meet panic when deleting data and raft log, the dirty data
            // will be cleared by a newer snapshot applying or restart.
            if let Err(e) = self.get_store().clear_data() {
                error!(
                    "failed to schedule clear data task";
                    "region_id" => self.region_id,
                    "peer_id" => self.peer.get_id(),
                    "err" => ?e,
                    "error_code" => %e.error_code(),
                );
            }
        }

        self.pending_reads.clear_all(Some(region.get_id()));

        for Proposal { cb, .. } in self.proposals.queue.drain(..) {
            apply::notify_req_region_removed(region.get_id(), cb);
        }

        info!(
            "peer destroy itself";
            "region_id" => self.region_id,
            "peer_id" => self.peer.get_id(),
            "takes" => ?t.elapsed(),
        );

        Ok(())
    }
/// Does the real destroy task which includes:
/// 1. Set the region to tombstone;
/// 2. Clear data;
/// 3. Notify all pending requests.
Does the real destroy task which includes:
1. Set the region to tombstone;
2. Clear data;
3. Notify all pending requests.
Does the real destroy task which includes : 1 . Set the region to tombstone ; 2 . Clear data ; 3 . Notify all pending requests .
pub fn destroy<T, C>(
        &mut self,
        ctx: &PollContext<EK, ER, T, C>,
        keep_data: bool,
    ) -> Result<()> {
        fail_point!("raft_store_skip_destroy_peer", |_| Ok(()));
        let t = Instant::now();
        let region = self.region().clone();
        info!(
            "begin to destroy";
            "region_id" => self.region_id,
            "peer_id" => self.peer.get_id(),
        );
        // Set Tombstone state explicitly
        let mut kv_wb = ctx.engines.kv.write_batch();
        let mut raft_wb = ctx.engines.raft.log_batch(1024);
        self.mut_store().clear_meta(&mut kv_wb, &mut raft_wb)?;
        write_peer_state(
            &mut kv_wb,
            &region,
            PeerState::Tombstone,
            self.pending_merge_state.clone(),
        )?;
        // write kv rocksdb first in case of restart happen between two write
        let mut write_opts = WriteOptions::new();
        write_opts.set_sync(ctx.cfg.sync_log);
        ctx.engines.kv.write_opt(&kv_wb, &write_opts)?;
        ctx.engines.raft.consume(&mut raft_wb, ctx.cfg.sync_log)?;
        if self.get_store().is_initialized() && !keep_data {
            // If we meet panic when deleting data and raft log, the dirty data
            // will be cleared by a newer snapshot applying or restart.
            if let Err(e) = self.get_store().clear_data() {
                error!(
                    "failed to schedule clear data task";
                    "region_id" => self.region_id,
                    "peer_id" => self.peer.get_id(),
                    "err" => ?e,
                    "error_code" => %e.error_code(),
                );
            }
        }
        self.pending_reads.clear_all(Some(region.get_id()));
        for Proposal { cb, .. } in self.proposals.queue.drain(..) {
            apply::notify_req_region_removed(region.get_id(), cb);
        }
        info!(
            "peer destroy itself";
            "region_id" => self.region_id,
            "peer_id" => self.peer.get_id(),
            "takes" => ?t.elapsed(),
        );
        Ok(())
    }
pub fn destroy < T , C > ( & mut self , ctx : & PollContext < EK , ER , T , C > , keep_data : bool , ) -> Result < ( ) > { fail_point ! ( " " Ok ( ( ) ) ) ; let t = Instant :: now ( ) ; let region = self . region ( ) . clone ( ) ; info ! ( " " " " self region_id " " self peer get_id ( ) ) ; // Set Tombstone state explicitly let mut kv_wb = ctx . engines . kv . write_batch ( ) ; let mut raft_wb = ctx . engines . raft . log_batch ( 1024 ) ; self . mut_store ( ) . clear_meta ( & mut kv_wb , & mut raft_wb ) ? ; write_peer_state ( & mut kv_wb , & region , PeerState :: Tombstone , self . pending_merge_state . clone ( ) , ) ? ; // write kv rocksdb first in case of restart happen between two write let mut write_opts = WriteOptions :: new ( ) ; write_opts . set_sync ( ctx . cfg . sync_log ) ; ctx . engines . kv . write_opt ( & kv_wb , & write_opts ) ? ; ctx . engines . raft . consume ( & mut raft_wb , ctx . cfg . sync_log ) ? ; if self . get_store ( ) . is_initialized ( ) && ! keep_data { // If we meet panic when deleting data and raft log, the dirty data // will be cleared by a newer snapshot applying or restart. if let Err ( e ) = self . get_store ( ) . clear_data ( ) { error ! ( " " " " self region_id " " self peer get_id ( ) " " e " " e error_code ( ) ) ; } } self . pending_reads . clear_all ( Some ( region . get_id ( ) ) ) ; for Proposal { cb , .. } in self . proposals . queue . drain ( .. ) { apply :: notify_req_region_removed ( region . get_id ( ) , cb ) ; } info ! ( " " " " self region_id " " self peer get_id ( ) " " t elapsed ( ) ) ; Ok ( ( ) ) }
Does the real destroy task which includes:
1.
Does the real destroy task which includes : 1 .
&mut self
ctx
&PollContext<EK, ER, T, C>
keep_data
bool