Skip to content
Merged
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
89 changes: 12 additions & 77 deletions rocketmq-common/src/common/stats/stats_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use std::time::SystemTime;

use crate::TimeUtils::current_millis;
Comment on lines 19 to +21
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 | 🟡 Minor

Remove unused SystemTime import.

The std::time::SystemTime import on line 19 is no longer used after refactoring to current_millis(). This dead import should be removed.

🧹 Proposed fix
 use std::fmt;
 use std::sync::atomic::AtomicU64;
 use std::sync::atomic::Ordering;
-use std::time::SystemTime;

 use crate::TimeUtils::current_millis;
📝 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
use std::time::SystemTime;
use crate::TimeUtils::current_millis;
use std::fmt;
use std::sync::atomic::AtomicU64;
use std::sync::atomic::Ordering;
use crate::TimeUtils::current_millis;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rocketmq-common/src/common/stats/stats_item.rs` around lines 19 - 21, Remove
the now-unused import "use std::time::SystemTime;" from the top of stats_item.rs
(the code now uses current_millis via use crate::TimeUtils::current_millis;),
search for any remaining references to SystemTime in the same file and delete
them if none exist, then run cargo check/cargo build to ensure no other usages
remain.

use parking_lot::Mutex;
use tracing::info;

Expand All @@ -37,17 +38,13 @@ pub struct StatsItem {

impl StatsItem {
pub fn new(stats_name: &str, stats_key: &str) -> Self {
let now_ms = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64;
StatsItem {
value: AtomicU64::new(0),
times: AtomicU64::new(0),
cs_list_minute: Mutex::new(LinkedList::new()),
cs_list_hour: Mutex::new(LinkedList::new()),
cs_list_day: Mutex::new(LinkedList::new()),
last_update_timestamp: AtomicU64::new(now_ms),
last_update_timestamp: AtomicU64::new(current_millis()),
stats_name: stats_name.to_string(),
stats_key: stats_key.to_string(),
}
Expand All @@ -67,13 +64,7 @@ impl StatsItem {
pub fn add(&self, value_delta: u64, times_delta: u64) {
self.value.fetch_add(value_delta, Ordering::Relaxed);
self.times.fetch_add(times_delta, Ordering::Relaxed);
self.last_update_timestamp.store(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_millis() as u64,
Ordering::Relaxed,
);
self.last_update_timestamp.store(current_millis(), Ordering::Relaxed);
}

/// Returns the current accumulated value.
Expand Down Expand Up @@ -163,24 +154,9 @@ impl StatsItem {
) {
let mut cs_list = cs_list.lock();
if cs_list.is_empty() {
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64
- 10 * 1000,
0,
0,
));
cs_list.push_back(CallSnapshot::new(current_millis() - 10 * 1000, 0, 0));
}
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64,
current_times,
current_value,
));
cs_list.push_back(CallSnapshot::new(current_millis(), current_times, current_value));
if cs_list.len() > 7 {
cs_list.pop_front();
}
Expand All @@ -189,24 +165,9 @@ impl StatsItem {
pub fn sampling_in_minutes(cs_list: &Mutex<LinkedList<CallSnapshot>>, current_value: u64, current_times: u64) {
let mut cs_list = cs_list.lock();
if cs_list.is_empty() {
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64
- 10 * 60 * 1000,
0,
0,
));
cs_list.push_back(CallSnapshot::new(current_millis() - 10 * 60 * 1000, 0, 0));
}
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64,
current_times,
current_value,
));
cs_list.push_back(CallSnapshot::new(current_millis(), current_times, current_value));
if cs_list.len() > 7 {
cs_list.pop_front();
}
Expand All @@ -215,24 +176,9 @@ impl StatsItem {
pub fn sampling_in_hour(cs_list: &Mutex<LinkedList<CallSnapshot>>, current_value: u64, current_times: u64) {
let mut cs_list = cs_list.lock();
if cs_list.is_empty() {
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64
- 60 * 60 * 1000,
0,
0,
));
cs_list.push_back(CallSnapshot::new(current_millis() - 60 * 60 * 1000, 0, 0));
}
cs_list.push_back(CallSnapshot::new(
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64,
current_times,
current_value,
));
cs_list.push_back(CallSnapshot::new(current_millis(), current_times, current_value));
if cs_list.len() > 25 {
cs_list.pop_front();
}
Expand Down Expand Up @@ -278,26 +224,15 @@ impl StatsItem {
}

pub fn compute_next_minutes_time_millis() -> u64 {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
(now / 60000 + 1) * 60000
(current_millis() / 60000 + 1) * 60000
}

pub fn compute_next_hour_time_millis() -> u64 {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
(now / 3600000 + 1) * 3600000
(current_millis() / 3600000 + 1) * 3600000
}

pub fn compute_next_morning_time_millis() -> u64 {
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
let now = current_millis();
let current_day = now / (24 * 3600000);
(current_day + 1) * 24 * 3600000
}
Expand Down
Loading