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 1230 : fn default() -> Self {
12 1230 : Self::Direct {
13 1230 : // TODO: using num_cpus results in different peak memory usage on different instance types.
14 1230 : max_concurrency: NonZeroUsize::new(usize::max(1, num_cpus::get())).unwrap(),
15 1230 : }
16 1230 : }
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 564 : pub fn new(config: L0FlushConfig) -> Self {
28 564 : match config {
29 564 : L0FlushConfig::Direct { max_concurrency } => {
30 564 : let semaphore = tokio::sync::Semaphore::new(max_concurrency.get());
31 564 : Self(Arc::new(Inner::Direct { semaphore }))
32 564 : }
33 564 : }
34 564 : }
35 :
36 2904 : pub fn inner(&self) -> &Arc<Inner> {
37 2904 : &self.0
38 2904 : }
39 : }
|