chore: upgrade some dependencies (#5777)

* chore: upgrade some dependencies

* chore: upgrade some dependencies

* fix: cr

* fix: ci

* fix: test

* fix: cargo fmt
This commit is contained in:
fys
2025-03-27 10:48:44 +08:00
committed by GitHub
parent e107bd5529
commit 2b2ea5bf72
55 changed files with 665 additions and 555 deletions

View File

@@ -36,7 +36,7 @@ pub enum Error {
#[snafu(implicit)]
location: Location,
#[snafu(source)]
error: rand::distributions::WeightedError,
error: rand::distr::weighted::Error,
},
#[snafu(display("Exceeded deadline, operation: {}", operation))]

View File

@@ -543,11 +543,11 @@ pub(crate) mod tests {
assert!(rx.await.unwrap().is_empty());
fn generate_heartbeats(datanode_id: u64, region_ids: Vec<u32>) -> Vec<DatanodeHeartbeat> {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let start = current_time_millis();
(0..2000)
.map(|i| DatanodeHeartbeat {
timestamp: start + i * 1000 + rng.gen_range(0..100),
timestamp: start + i * 1000 + rng.random_range(0..100),
datanode_id,
regions: region_ids
.iter()

View File

@@ -61,7 +61,7 @@ impl Selector for RandomNodeSelector {
type Output = Vec<Peer>;
async fn select(&self, _ctx: &Self::Context, _opts: SelectorOptions) -> Result<Self::Output> {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mut nodes = self.nodes.clone();
nodes.shuffle(&mut rng);
Ok(nodes)

View File

@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use rand::seq::SliceRandom;
use rand::thread_rng;
use rand::rng;
use rand::seq::IndexedRandom;
use snafu::ResultExt;
use crate::error;
@@ -26,7 +26,10 @@ pub trait WeightedChoose<Item>: Send + Sync {
/// The method will choose multiple items.
///
/// Returns less than `amount` items if the weight_array is not enough.
/// ## Note
///
/// - Returns less than `amount` items if the weight_array is not enough.
/// - The returned items cannot be duplicated.
fn choose_multiple(&mut self, amount: usize) -> Result<Vec<Item>>;
/// Returns the length of the weight_array.
@@ -84,7 +87,7 @@ where
// unwrap safety: whether weighted_index is none has been checked before.
let item = self
.items
.choose_weighted(&mut thread_rng(), |item| item.weight as f64)
.choose_weighted(&mut rng(), |item| item.weight as f64)
.context(error::ChooseItemsSnafu)?
.item
.clone();
@@ -92,9 +95,11 @@ where
}
fn choose_multiple(&mut self, amount: usize) -> Result<Vec<Item>> {
let amount = amount.min(self.items.iter().filter(|item| item.weight > 0).count());
Ok(self
.items
.choose_multiple_weighted(&mut thread_rng(), amount, |item| item.weight as f64)
.choose_multiple_weighted(&mut rng(), amount, |item| item.weight as f64)
.context(error::ChooseItemsSnafu)?
.cloned()
.map(|item| item.item)
@@ -127,7 +132,7 @@ mod tests {
for _ in 0..100 {
let ret = choose.choose_multiple(3).unwrap();
assert_eq!(vec![1, 2], ret);
assert_eq!(vec![1], ret);
}
}
}