Skip to content

Commit 307f0e9

Browse files
committed
[ISSUE #2424]Bump rand from 0.8.5 to 0.9.0
1 parent 840d3a6 commit 307f0e9

File tree

11 files changed

+114
-38
lines changed

11 files changed

+114
-38
lines changed

Cargo.lock

Lines changed: 99 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ serde_json = "1.0"
5656
serde_json_any_key = "2.0.0"
5757
anyhow = "1.0.95"
5858
bytes = "1.9.0"
59-
rand = "0.8"
59+
rand = "0.9.0"
6060
lazy_static = "1.5.0"
6161
num_cpus = "1.16"
6262

rocketmq-broker/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ bytes = { workspace = true }
4040
parking_lot.workspace = true
4141

4242
clap = { version = "4.5.27", features = ["derive"] }
43-
rand = "0.8.5"
43+
rand = { workspace = true }
4444

4545
#tools
4646
dirs.workspace = true

rocketmq-broker/src/processor/pop_message_processor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use std::sync::Arc;
2727
use bytes::Bytes;
2828
use bytes::BytesMut;
2929
use cheetah_string::CheetahString;
30-
use rand::thread_rng;
3130
use rand::Rng;
3231
use rocketmq_common::common::config::TopicConfig;
3332
use rocketmq_common::common::constant::consume_init_mode::ConsumeInitMode;
@@ -489,7 +488,7 @@ where
489488
(subscription_data, None)
490489
};
491490

492-
let randomq = thread_rng().gen_range(0..100);
491+
let randomq = rand::rng().random_range(0..100);
493492
let revive_qid = if request_header.order.unwrap_or(false) {
494493
POP_ORDER_REVIVE_QUEUE
495494
} else {

rocketmq-broker/src/processor/send_message_processor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ where
11931193
let mut new_topic =
11941194
CheetahString::from_string(mix_all::get_retry_topic(request_header.group.as_str()));
11951195
let mut queue_id_int =
1196-
rand::thread_rng().gen_range(0..subscription_group_config.retry_queue_nums());
1196+
rand::rng().random_range(0..subscription_group_config.retry_queue_nums());
11971197
let topic_sys_flag = if request_header.unit_mode {
11981198
TopicSysFlag::build_sys_flag(false, true)
11991199
} else {
@@ -1593,7 +1593,7 @@ where
15931593
}
15941594

15951595
pub(crate) fn random_queue_id(&self, write_queue_nums: u32) -> u32 {
1596-
rand::thread_rng().gen_range(0..=99999999) % write_queue_nums
1596+
rand::rng().random_range(0..=99999999) % write_queue_nums
15971597
}
15981598
}
15991599

rocketmq-client/src/common/thread_local_index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ impl ThreadLocalIndex {
3737
let mut index = index.borrow_mut();
3838
let new_value = match *index {
3939
Some(val) => val.wrapping_add(1) & POSITIVE_MASK,
40-
None => rand::thread_rng().gen_range(0..=MAX) & POSITIVE_MASK,
40+
None => rand::rng().random_range(0..=MAX) & POSITIVE_MASK,
4141
};
4242
*index = Some(new_value);
4343
new_value
4444
})
4545
}
4646

4747
pub fn reset(&self) {
48-
let new_value = rand::thread_rng().gen_range(0..=MAX).abs();
48+
let new_value = rand::rng().random_range(0..=MAX).abs();
4949
THREAD_LOCAL_INDEX.with(|index| {
5050
*index.borrow_mut() = Some(new_value);
5151
});

rocketmq-client/src/consumer/consumer_impl/pull_api_wrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ impl PullAPIWrapper {
456456
}
457457

458458
pub fn random_num() -> i32 {
459-
let mut rng = rand::thread_rng();
460-
let mut value = rng.gen::<i32>();
459+
let mut rng = rand::rng();
460+
let mut value = rng.random::<i32>();
461461
if value < 0 {
462462
value = value.abs();
463463
if value < 0 {

rocketmq-client/src/factory/mq_client_instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::thread;
2323
use std::time::Duration;
2424

2525
use cheetah_string::CheetahString;
26-
use rand::seq::SliceRandom;
26+
use rand::seq::IndexedRandom;
2727
use rocketmq_common::common::base::service_state::ServiceState;
2828
use rocketmq_common::common::constant::PermName;
2929
use rocketmq_common::common::filter::expression_type::ExpressionType;
@@ -508,7 +508,7 @@ impl MQClientInstance {
508508
if let Some(topic_route_data) = topic_route_table.get(topic) {
509509
let brokers = &topic_route_data.broker_datas;
510510
if !brokers.is_empty() {
511-
let bd = brokers.choose(&mut rand::thread_rng());
511+
let bd = brokers.choose(&mut rand::rng());
512512
if let Some(bd) = bd {
513513
return bd.select_broker_addr();
514514
}

rocketmq-client/src/latency/latency_fault_tolerance_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ where
101101

102102
if !tmp_list.is_empty() {
103103
use rand::seq::SliceRandom;
104-
let mut rng = rand::thread_rng();
104+
let mut rng = rand::rng();
105105
tmp_list.shuffle(&mut rng);
106106
for fault_item in tmp_list {
107107
if fault_item

rocketmq-remoting/src/clients/rocketmq_default_impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,6 @@ impl<PR: RequestProcessor + Sync + Clone + 'static> RemotingClient for RocketmqD
424424
}
425425

426426
fn init_value_index() -> i32 {
427-
let mut rng = rand::thread_rng();
428-
rng.gen_range(0..999)
427+
let mut rng = rand::rng();
428+
rng.random_range(0..999)
429429
}

rocketmq-remoting/src/protocol/route/route_data_view.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ impl BrokerData {
131131
pub fn select_broker_addr(&self) -> Option<CheetahString> {
132132
let master_address = self.broker_addrs.get(&(mix_all::MASTER_ID)).cloned();
133133
if master_address.is_none() {
134-
return self
135-
.broker_addrs
136-
.values()
137-
.choose(&mut rand::thread_rng())
138-
.cloned();
134+
return self.broker_addrs.values().choose(&mut rand::rng()).cloned();
139135
}
140136
master_address
141137
}

0 commit comments

Comments
 (0)