LCOV - code coverage report
Current view: top level - pageserver/src - l0_flush.rs (source / functions) Coverage Total Hit
Test: f5f94ec0366b63fd2cbbe02edc2087dbd893d04d.info Lines: 70.8 % 24 17
Test Date: 2024-11-20 05:34:23 Functions: 75.0 % 4 3

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

Generated by: LCOV version 2.1-beta