Line data Source code
1 : use std::num::NonZeroUsize;
2 : use std::sync::Arc;
3 :
4 : #[derive(Debug, PartialEq, Eq, Clone)]
5 : pub enum L0FlushConfig {
6 : Direct { max_concurrency: NonZeroUsize },
7 : }
8 :
9 : impl Default for L0FlushConfig {
10 944 : fn default() -> Self {
11 944 : Self::Direct {
12 944 : // TODO: using num_cpus results in different peak memory usage on different instance types.
13 944 : max_concurrency: NonZeroUsize::new(usize::max(1, num_cpus::get())).unwrap(),
14 944 : }
15 944 : }
16 : }
17 :
18 : impl From<pageserver_api::models::L0FlushConfig> for L0FlushConfig {
19 0 : fn from(config: pageserver_api::models::L0FlushConfig) -> Self {
20 0 : match config {
21 0 : pageserver_api::models::L0FlushConfig::Direct { max_concurrency } => {
22 0 : Self::Direct { max_concurrency }
23 0 : }
24 0 : }
25 0 : }
26 : }
27 :
28 : #[derive(Clone)]
29 : pub struct L0FlushGlobalState(Arc<Inner>);
30 :
31 : pub enum Inner {
32 : Direct { semaphore: tokio::sync::Semaphore },
33 : }
34 :
35 : impl L0FlushGlobalState {
36 454 : pub fn new(config: L0FlushConfig) -> Self {
37 454 : match config {
38 454 : L0FlushConfig::Direct { max_concurrency } => {
39 454 : let semaphore = tokio::sync::Semaphore::new(max_concurrency.get());
40 454 : Self(Arc::new(Inner::Direct { semaphore }))
41 454 : }
42 454 : }
43 454 : }
44 :
45 1966 : pub fn inner(&self) -> &Arc<Inner> {
46 1966 : &self.0
47 1966 : }
48 : }
|