LCOV - code coverage report
Current view: top level - pageserver/src - l0_flush.rs (source / functions) Coverage Total Hit
Test: 5fe7fa8d483b39476409aee736d6d5e32728bfac.info Lines: 70.8 % 24 17
Test Date: 2025-03-12 16:10:49 Functions: 75.0 % 4 3

            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          940 :     fn default() -> Self {
      11          940 :         Self::Direct {
      12          940 :             // TODO: using num_cpus results in different peak memory usage on different instance types.
      13          940 :             max_concurrency: NonZeroUsize::new(usize::max(1, num_cpus::get())).unwrap(),
      14          940 :         }
      15          940 :     }
      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          452 :     pub fn new(config: L0FlushConfig) -> Self {
      37          452 :         match config {
      38          452 :             L0FlushConfig::Direct { max_concurrency } => {
      39          452 :                 let semaphore = tokio::sync::Semaphore::new(max_concurrency.get());
      40          452 :                 Self(Arc::new(Inner::Direct { semaphore }))
      41          452 :             }
      42          452 :         }
      43          452 :     }
      44              : 
      45         1936 :     pub fn inner(&self) -> &Arc<Inner> {
      46         1936 :         &self.0
      47         1936 :     }
      48              : }
        

Generated by: LCOV version 2.1-beta