fn connection_for_shard(
        shard: u16,
        nr_shards: ShardCount,
        shard_conns: &[Vec<Arc<Connection>>],
    ) -> Arc<Connection> {
        // Try getting the desired connection
        if let Some(conn) = Self::choose_random_connection_from_slice(&shard_conns[shard as usize])
        {
            return conn;
        }

        // If this fails try getting any other in random order
        let mut shards_to_try: Vec<u16> = (0..shard).chain(shard + 1..nr_shards.get()).collect();

        while !shards_to_try.is_empty() {
            let idx = rand::thread_rng().gen_range(0..shards_to_try.len());
            let shard = shards_to_try.swap_remove(idx);

            if let Some(conn) =
                Self::choose_random_connection_from_slice(&shard_conns[shard as usize])
            {
                return conn;
            }
        }

        unreachable!("could not find any connection in supposedly non-empty pool")
    }
// Tries to get a connection to given shard, if it's broken returns any working connection
Tries to get a connection to given shard, if it's broken returns any working connection
Tries to get a connection to given shard if it ' s broken returns any working connection
fn connection_for_shard(
        shard: u16,
        nr_shards: ShardCount,
        shard_conns: &[Vec<Arc<Connection>>],
    ) -> Arc<Connection> {
        // Try getting the desired connection
        if let Some(conn) = Self::choose_random_connection_from_slice(&shard_conns[shard as usize])
        {
            return conn;
        }
        // If this fails try getting any other in random order
        let mut shards_to_try: Vec<u16> = (0..shard).chain(shard + 1..nr_shards.get()).collect();
        while !shards_to_try.is_empty() {
            let idx = rand::thread_rng().gen_range(0..shards_to_try.len());
            let shard = shards_to_try.swap_remove(idx);
            if let Some(conn) =
                Self::choose_random_connection_from_slice(&shard_conns[shard as usize])
            {
                return conn;
            }
        }
        unreachable!("could not find any connection in supposedly non-empty pool")
    }
fn connection_for_shard ( shard : u16 , nr_shards : ShardCount , shard_conns : & [ Vec < Arc < Connection > > ] , ) -> Arc < Connection > { // Try getting the desired connection if let Some ( conn ) = Self :: choose_random_connection_from_slice ( & shard_conns [ shard as usize ] ) { return conn ; } // If this fails try getting any other in random order let mut shards_to_try : Vec < u16 > = ( 0 .. shard ) . chain ( shard + 1 .. nr_shards . get ( ) ) . collect ( ) ; while ! shards_to_try . is_empty ( ) { let idx = rand :: thread_rng ( ) . gen_range ( 0 .. shards_to_try . len ( ) ) ; let shard = shards_to_try . swap_remove ( idx ) ; if let Some ( conn ) = Self :: choose_random_connection_from_slice ( & shard_conns [ shard as usize ] ) { return conn ; } } unreachable ! ( " " ) }
Tries to get a connection to given shard, if it's broken returns any working connection
Tries to get a connection to given shard if it ' s broken returns any working connection
shard
u16
nr_shards
ShardCount
shard_conns
&[Vec<Arc<Connection>>]
shard
u16
nr_shards
ShardCount
shard_conns
&[Vec<Arc<Connection>>]