Line data Source code
1 : use std::{num::NonZeroUsize, sync::Arc};
2 :
3 0 : #[derive(Debug, PartialEq, Eq, Clone, serde::Deserialize)]
4 : #[serde(tag = "mode", rename_all = "kebab-case", deny_unknown_fields)]
5 : pub enum L0FlushConfig {
6 : #[serde(rename_all = "snake_case")]
7 : Direct { max_concurrency: NonZeroUsize },
8 : }
9 :
10 : impl Default for L0FlushConfig {
11 394 : fn default() -> Self {
12 394 : Self::Direct {
13 394 : // TODO: using num_cpus results in different peak memory usage on different instance types.
14 394 : max_concurrency: NonZeroUsize::new(usize::max(1, num_cpus::get())).unwrap(),
15 394 : }
16 394 : }
17 : }
18 :
19 : #[derive(Clone)]
20 : pub struct L0FlushGlobalState(Arc<Inner>);
21 :
22 : pub enum Inner {
23 : Direct { semaphore: tokio::sync::Semaphore },
24 : }
25 :
26 : impl L0FlushGlobalState {
27 182 : pub fn new(config: L0FlushConfig) -> Self {
28 182 : match config {
29 182 : L0FlushConfig::Direct { max_concurrency } => {
30 182 : let semaphore = tokio::sync::Semaphore::new(max_concurrency.get());
31 182 : Self(Arc::new(Inner::Direct { semaphore }))
32 182 : }
33 182 : }
34 182 : }
35 :
36 1134 : pub fn inner(&self) -> &Arc<Inner> {
37 1134 : &self.0
38 1134 : }
39 : }
|