Skip to content

Commit 2c44fe4

Browse files
authored
Merge pull request #9187 from Xuanwo/unwind-safe-operator
refactor: Simplify the global data registry logic
2 parents 2254e89 + 1792a48 commit 2c44fe4

File tree

33 files changed

+353
-1120
lines changed

33 files changed

+353
-1120
lines changed

Cargo.lock

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

src/binaries/query/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ async fn main_entrypoint() -> Result<()> {
180180

181181
// Cluster register.
182182
{
183-
let cluster_discovery = ClusterDiscovery::instance();
184-
let register_to_metastore = cluster_discovery.register_to_metastore(&conf);
185-
register_to_metastore.await?;
183+
ClusterDiscovery::instance()
184+
.register_to_metastore(&conf)
185+
.await?;
186186
info!(
187187
"Databend query has been registered:{:?} to metasrv:{:?}.",
188188
conf.query.cluster_id, conf.meta.endpoints

src/common/base/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ futures = "0.3.24"
3434
libc = "0.2.133"
3535
num_cpus = "1.13.1"
3636
once_cell = "1.15.0"
37+
parking_lot = "0.12"
3738
pin-project-lite = "0.2.9"
3839
pprof = { version = "0.10.1", features = [
3940
"flamegraph",
@@ -42,6 +43,7 @@ pprof = { version = "0.10.1", features = [
4243
] }
4344
semver = "1.0.10"
4445
serde = { workspace = true }
46+
state = "0.5"
4547
tikv-jemalloc-ctl = { version = "0.5.0", optional = true }
4648
tikv-jemalloc-sys = "0.5.2"
4749
tokio = { version = "1.21.1", features = ["full"] }

src/common/base/src/base/global_runtime.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,25 @@
1515
use std::sync::Arc;
1616

1717
use common_exception::Result;
18-
use once_cell::sync::OnceCell;
1918

20-
use crate::base::singleton_instance::Singleton;
19+
use super::GlobalInstance;
2120
use crate::base::Runtime;
2221

2322
pub struct GlobalIORuntime;
2423

25-
static GLOBAL_RUNTIME: OnceCell<Singleton<Arc<Runtime>>> = OnceCell::new();
26-
2724
impl GlobalIORuntime {
28-
pub fn init(num_cpus: usize, v: Singleton<Arc<Runtime>>) -> Result<()> {
25+
pub fn init(num_cpus: usize) -> Result<()> {
2926
let thread_num = std::cmp::max(num_cpus, num_cpus::get() / 2);
3027
let thread_num = std::cmp::max(2, thread_num);
3128

32-
v.init(Arc::new(Runtime::with_worker_threads(
29+
GlobalInstance::set(Arc::new(Runtime::with_worker_threads(
3330
thread_num,
3431
Some("IO-worker".to_owned()),
35-
)?))?;
36-
37-
GLOBAL_RUNTIME.set(v.clone()).ok();
32+
)?));
3833
Ok(())
3934
}
4035

4136
pub fn instance() -> Arc<Runtime> {
42-
match GLOBAL_RUNTIME.get() {
43-
None => panic!("GlobalRuntime is not init"),
44-
Some(global_runtime) => global_runtime.get(),
45-
}
37+
GlobalInstance::get()
4638
}
4739
}

src/common/base/src/base/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ pub use shutdown_signal::signal_stream;
4949
pub use shutdown_signal::DummySignalStream;
5050
pub use shutdown_signal::SignalStream;
5151
pub use shutdown_signal::SignalType;
52-
pub use singleton_instance::Singleton;
53-
pub use singleton_instance::SingletonImpl;
52+
pub use singleton_instance::GlobalInstance;
5453
pub use stop_handle::StopHandle;
5554
pub use stoppable::Stoppable;
5655
pub use string_func::escape_for_key;

0 commit comments

Comments
 (0)