/// perform election when spu goes offline
perform election when spu goes offline
perform election when spu goes offline
fn force_election_spu_off(&self, offline_spu: SpuKV, actions: &mut PartitionActions) {
        debug!(
            "start election when spu went offline: {}",
            offline_spu.key()
        );
        let offline_leader_spu_id = offline_spu.spec.id;
        let spu_status = self.spu_store.online_status();
        let policy = SimplePolicy::new();
        // go thru each partitions whose leader matches offline spu.
        self.partition_store.visit_values(|partition_kv| {
            // find partition who's leader is same as offline spu
            if partition_kv.spec.leader == offline_leader_spu_id {
                // find suitable leader
                if let Some(candidate_leader) = partition_kv.status.candidate_leader(&spu_status, &policy)
                {
                    debug!(
                        "suitable leader has found: {} leader: {}",
                        partition_kv.key(),
                        candidate_leader
                    );
                    let mut part_kv_change = partition_kv.clone();
                    part_kv_change.spec.leader = candidate_leader;
                    actions
                        .partitions
                        .push(PartitionWSAction::UpdateSpec(part_kv_change));
                // change the
                } else {
                    warn!("no suitable leader has found: {}", partition_kv.key());
                    let mut part_kv_change = partition_kv.clone();
                    part_kv_change.status.resolution = PartitionResolution::LeaderOffline;
                    actions
                        .partitions
                        .push(PartitionWSAction::UpdateStatus(part_kv_change));
                }
            }
        });
    }
fn force_election_spu_off ( & self , offline_spu : SpuKV , actions : & mut PartitionActions ) { debug ! ( " " offline_spu key ( ) ) ; let offline_leader_spu_id = offline_spu . spec . id ; let spu_status = self . spu_store . online_status ( ) ; let policy = SimplePolicy :: new ( ) ; // go thru each partitions whose leader matches offline spu. self . partition_store . visit_values ( | partition_kv | { // find partition who's leader is same as offline spu if partition_kv . spec . leader == offline_leader_spu_id { // find suitable leader if let Some ( candidate_leader ) = partition_kv . status . candidate_leader ( & spu_status , & policy ) { debug ! ( " " partition_kv key ( ) candidate_leader ) ; let mut part_kv_change = partition_kv . clone ( ) ; part_kv_change . spec . leader = candidate_leader ; actions . partitions . push ( PartitionWSAction :: UpdateSpec ( part_kv_change ) ) ; // change the } else { warn ! ( " " partition_kv key ( ) ) ; let mut part_kv_change = partition_kv . clone ( ) ; part_kv_change . status . resolution = PartitionResolution :: LeaderOffline ; actions . partitions . push ( PartitionWSAction :: UpdateStatus ( part_kv_change ) ) ; } } } ) ; }
perform election when spu goes offline
perform election when spu goes offline
&self
offline_spu
SpuKV
actions
&mut PartitionActions