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
16 changes: 6 additions & 10 deletions rust/cubestore/cubestore/src/util/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use crate::CubeError;
use std::net::ToSocketAddrs;
use std::net::UdpSocket;
use std::sync::Once;

#[derive(Debug, PartialEq, Eq)]
pub enum Compatibility {
Expand Down Expand Up @@ -189,8 +188,9 @@ impl Sink {

mod global_sink {
use super::*;
static mut GLOBAL_SINK: Option<Sink> = None;
static ONCE: Once = Once::new();
use std::sync::OnceLock;

static GLOBAL_SINK: OnceLock<Option<Sink>> = OnceLock::new();

pub fn init(
bind_addr: impl ToSocketAddrs,
Expand All @@ -201,11 +201,9 @@ mod global_sink {
let s = Sink::connect(bind_addr, server_addr, mode, constant_tags)?;

let mut called = false;
ONCE.call_once(|| {
unsafe {
GLOBAL_SINK = Some(s);
}
GLOBAL_SINK.get_or_init(|| {
called = true;
Some(s)
});
if !called {
panic!("Metrics initialized twice or used before initialization");
Expand All @@ -214,9 +212,7 @@ mod global_sink {
}

pub(super) fn sink() -> &'static Option<Sink> {
// Ensure we synchronize access to GLOBAL_SINK.
ONCE.call_once(|| {});
unsafe { &GLOBAL_SINK }
GLOBAL_SINK.get_or_init(|| None)
}
}

Expand Down
Loading