Skip to content

[ISSUE #2424]Bump rand from 0.8.5 to 0.9.0 #2425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 98 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ serde_json = "1.0"
serde_json_any_key = "2.0.0"
anyhow = "1.0.95"
bytes = "1.9.0"
rand = "0.8"
rand = "0.9.0"
lazy_static = "1.5.0"
num_cpus = "1.16"

Expand Down
2 changes: 1 addition & 1 deletion rocketmq-broker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bytes = { workspace = true }
parking_lot.workspace = true

clap = { version = "4.5.27", features = ["derive"] }
rand = "0.8.5"
rand = { workspace = true }

#tools
dirs.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions rocketmq-broker/src/processor/pop_message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use bytes::Bytes;
use bytes::BytesMut;
use cheetah_string::CheetahString;
use rand::thread_rng;
use rand::Rng;
use rocketmq_common::common::config::TopicConfig;
use rocketmq_common::common::constant::consume_init_mode::ConsumeInitMode;
Expand Down Expand Up @@ -489,7 +488,7 @@
(subscription_data, None)
};

let randomq = thread_rng().gen_range(0..100);
let randomq = rand::rng().random_range(0..100);

Check warning on line 491 in rocketmq-broker/src/processor/pop_message_processor.rs

View check run for this annotation

Codecov / codecov/patch

rocketmq-broker/src/processor/pop_message_processor.rs#L491

Added line #L491 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect rand API usage

The new API call rng().random_range(0..100) is incorrect. The rand 0.9.0 crate uses gen_range method, not random_range.

Apply this diff to fix the API usage:

-let randomq = rand::rng().random_range(0..100);
+let randomq = rand::thread_rng().gen_range(0..100);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let randomq = rand::rng().random_range(0..100);
let randomq = rand::thread_rng().gen_range(0..100);

let revive_qid = if request_header.order.unwrap_or(false) {
POP_ORDER_REVIVE_QUEUE
} else {
Expand Down
Loading
Loading