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

Generated by: LCOV version 2.1-beta