You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: observer.rs
    path of file: ./repos/tikv/components/resolved_ts/src
    
    the code of the file until where you have to start completion: // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.

use engine_traits::KvEngine;
use kvproto::metapb::Region;
use raft::StateRole;
use raftstore::coprocessor::*;
use tikv_util::worker::Scheduler;

use crate::{cmd::lock_only_filter, endpoint::Task,
    
    fn on_role_change(&self, ctx: &mut ObserverContext<'_>, role_change: &RoleChange) {
        // Stop to advance resolved ts after peer steps down to follower or candidate.
        // Do not need to check observe id because we expect all role change events are
        // scheduled in order.
        if role_change.state != StateRole::Leader {
            if let Err(e) = self.scheduler.schedule(Task::DeRegisterRegion {
                region_id: ctx.region().id,
            }) {
                info!("failed to schedule deregister region task"; "err" => ?e);
            }
        }
    }