mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-09-02 17:15:43 +00:00
refactor(stats): rename UnsafeCounter to Counter
The counter is now a plain atomic (no longer UnsafeCell, no longer sharded), so the "Unsafe" prefix is a misleading leftover. Rename to Counter. Also fix a stale bench comment that claimed the ShardedAtomic variant mirrors production.
This commit is contained in:
@@ -94,7 +94,9 @@ impl Counter for CasSaturating {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// 3. ShardedAtomic: 16 cache-aligned shards + per-thread shard index.
|
// 3. ShardedAtomic: 16 cache-aligned shards + per-thread shard index.
|
||||||
// Mirrors production `stats_manager::UnsafeCounter`.
|
// Comparison-only variant (production `stats_manager::Counter` is
|
||||||
|
// single-atomic; sharding was evaluated and dropped as no benefit for the
|
||||||
|
// default 1-16 worker deployments).
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|||||||
@@ -375,19 +375,19 @@ impl Default for LabelSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// UnsafeCounter provides a high-performance atomic counter
|
/// Counter provides a high-performance atomic counter
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UnsafeCounter {
|
pub struct Counter {
|
||||||
value: AtomicU64,
|
value: AtomicU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UnsafeCounter {
|
impl Default for Counter {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnsafeCounter {
|
impl Counter {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
value: AtomicU64::new(0),
|
value: AtomicU64::new(0),
|
||||||
@@ -445,21 +445,21 @@ fn now_millis() -> u64 {
|
|||||||
/// MetricData contains both the counter and last update timestamp
|
/// MetricData contains both the counter and last update timestamp
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct MetricData {
|
struct MetricData {
|
||||||
counter: UnsafeCounter,
|
counter: Counter,
|
||||||
last_updated: AtomicU64,
|
last_updated: AtomicU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetricData {
|
impl MetricData {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter: UnsafeCounter::new(),
|
counter: Counter::new(),
|
||||||
last_updated: AtomicU64::new(now_millis()),
|
last_updated: AtomicU64::new(now_millis()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_with_value(initial: u64) -> Self {
|
fn new_with_value(initial: u64) -> Self {
|
||||||
Self {
|
Self {
|
||||||
counter: UnsafeCounter::new_with_value(initial),
|
counter: Counter::new_with_value(initial),
|
||||||
last_updated: AtomicU64::new(now_millis()),
|
last_updated: AtomicU64::new(now_millis()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -757,7 +757,7 @@ mod tests {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_unsafe_counter() {
|
async fn test_unsafe_counter() {
|
||||||
let counter = UnsafeCounter::new();
|
let counter = Counter::new();
|
||||||
|
|
||||||
assert_eq!(counter.get(), 0);
|
assert_eq!(counter.get(), 0);
|
||||||
counter.inc();
|
counter.inc();
|
||||||
|
|||||||
Reference in New Issue
Block a user