LCOV - code coverage report
Current view: top level - pageserver/src - l0_flush.rs (source / functions) Coverage Total Hit
Test: 49aa928ec5b4b510172d8b5c6d154da28e70a46c.info Lines: 70.8 % 24 17
Test Date: 2024-11-13 18:23:39 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          398 :     fn default() -> Self {
      10          398 :         Self::Direct {
      11          398 :             // TODO: using num_cpus results in different peak memory usage on different instance types.
      12          398 :             max_concurrency: NonZeroUsize::new(usize::max(1, num_cpus::get())).unwrap(),
      13          398 :         }
      14          398 :     }
      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          190 :     pub fn new(config: L0FlushConfig) -> Self {
      36          190 :         match config {
      37          190 :             L0FlushConfig::Direct { max_concurrency } => {
      38          190 :                 let semaphore = tokio::sync::Semaphore::new(max_concurrency.get());
      39          190 :                 Self(Arc::new(Inner::Direct { semaphore }))
      40          190 :             }
      41          190 :         }
      42          190 :     }
      43              : 
      44          968 :     pub fn inner(&self) -> &Arc<Inner> {
      45          968 :         &self.0
      46          968 :     }
      47              : }
        

Generated by: LCOV version 2.1-beta