LCOV - code coverage report
Current view: top level - safekeeper/src - lib.rs (source / functions) Coverage Total Hit
Test: e402c46de0a007db6b48dddbde450ddbb92e6ceb.info Lines: 39.2 % 79 31
Test Date: 2024-06-25 10:31:23 Functions: 12.5 % 8 1

            Line data    Source code
       1              : #![deny(clippy::undocumented_unsafe_blocks)]
       2              : use camino::Utf8PathBuf;
       3              : use once_cell::sync::Lazy;
       4              : use remote_storage::RemoteStorageConfig;
       5              : use tokio::runtime::Runtime;
       6              : 
       7              : use std::time::Duration;
       8              : use storage_broker::Uri;
       9              : 
      10              : use utils::{auth::SwappableJwtAuth, id::NodeId, logging::SecretString};
      11              : 
      12              : mod auth;
      13              : pub mod broker;
      14              : pub mod control_file;
      15              : pub mod control_file_upgrade;
      16              : pub mod copy_timeline;
      17              : pub mod debug_dump;
      18              : pub mod handler;
      19              : pub mod http;
      20              : pub mod json_ctrl;
      21              : pub mod metrics;
      22              : pub mod patch_control_file;
      23              : pub mod pull_timeline;
      24              : pub mod receive_wal;
      25              : pub mod recovery;
      26              : pub mod remove_wal;
      27              : pub mod safekeeper;
      28              : pub mod send_wal;
      29              : pub mod state;
      30              : pub mod timeline;
      31              : pub mod timeline_manager;
      32              : pub mod timelines_set;
      33              : pub mod wal_backup;
      34              : pub mod wal_backup_partial;
      35              : pub mod wal_service;
      36              : pub mod wal_storage;
      37              : 
      38              : mod timelines_global_map;
      39              : use std::sync::Arc;
      40              : pub use timelines_global_map::GlobalTimelines;
      41              : use utils::auth::JwtAuth;
      42              : 
      43              : pub mod defaults {
      44              :     pub use safekeeper_api::{
      45              :         DEFAULT_HTTP_LISTEN_ADDR, DEFAULT_HTTP_LISTEN_PORT, DEFAULT_PG_LISTEN_ADDR,
      46              :         DEFAULT_PG_LISTEN_PORT,
      47              :     };
      48              : 
      49              :     pub const DEFAULT_HEARTBEAT_TIMEOUT: &str = "5000ms";
      50              :     pub const DEFAULT_MAX_OFFLOADER_LAG_BYTES: u64 = 128 * (1 << 20);
      51              :     pub const DEFAULT_PARTIAL_BACKUP_TIMEOUT: &str = "15m";
      52              : }
      53              : 
      54              : #[derive(Debug, Clone)]
      55              : pub struct SafeKeeperConf {
      56              :     // Repository directory, relative to current working directory.
      57              :     // Normally, the safekeeper changes the current working directory
      58              :     // to the repository, and 'workdir' is always '.'. But we don't do
      59              :     // that during unit testing, because the current directory is global
      60              :     // to the process but different unit tests work on different
      61              :     // data directories to avoid clashing with each other.
      62              :     pub workdir: Utf8PathBuf,
      63              :     pub my_id: NodeId,
      64              :     pub listen_pg_addr: String,
      65              :     pub listen_pg_addr_tenant_only: Option<String>,
      66              :     pub listen_http_addr: String,
      67              :     pub advertise_pg_addr: Option<String>,
      68              :     pub availability_zone: Option<String>,
      69              :     pub no_sync: bool,
      70              :     pub broker_endpoint: Uri,
      71              :     pub broker_keepalive_interval: Duration,
      72              :     pub heartbeat_timeout: Duration,
      73              :     pub peer_recovery_enabled: bool,
      74              :     pub remote_storage: Option<RemoteStorageConfig>,
      75              :     pub max_offloader_lag_bytes: u64,
      76              :     pub backup_parallel_jobs: usize,
      77              :     pub wal_backup_enabled: bool,
      78              :     pub pg_auth: Option<Arc<JwtAuth>>,
      79              :     pub pg_tenant_only_auth: Option<Arc<JwtAuth>>,
      80              :     pub http_auth: Option<Arc<SwappableJwtAuth>>,
      81              :     /// JWT token to connect to other safekeepers with.
      82              :     pub sk_auth_token: Option<SecretString>,
      83              :     pub current_thread_runtime: bool,
      84              :     pub walsenders_keep_horizon: bool,
      85              :     pub partial_backup_enabled: bool,
      86              :     pub partial_backup_timeout: Duration,
      87              :     pub disable_periodic_broker_push: bool,
      88              : }
      89              : 
      90              : impl SafeKeeperConf {
      91            0 :     pub fn is_wal_backup_enabled(&self) -> bool {
      92            0 :         self.remote_storage.is_some() && self.wal_backup_enabled
      93            0 :     }
      94              : }
      95              : 
      96              : impl SafeKeeperConf {
      97              :     #[cfg(test)]
      98            4 :     fn dummy() -> Self {
      99            4 :         SafeKeeperConf {
     100            4 :             workdir: Utf8PathBuf::from("./"),
     101            4 :             no_sync: false,
     102            4 :             listen_pg_addr: defaults::DEFAULT_PG_LISTEN_ADDR.to_string(),
     103            4 :             listen_pg_addr_tenant_only: None,
     104            4 :             listen_http_addr: defaults::DEFAULT_HTTP_LISTEN_ADDR.to_string(),
     105            4 :             advertise_pg_addr: None,
     106            4 :             availability_zone: None,
     107            4 :             remote_storage: None,
     108            4 :             my_id: NodeId(0),
     109            4 :             broker_endpoint: storage_broker::DEFAULT_ENDPOINT
     110            4 :                 .parse()
     111            4 :                 .expect("failed to parse default broker endpoint"),
     112            4 :             broker_keepalive_interval: Duration::from_secs(5),
     113            4 :             peer_recovery_enabled: true,
     114            4 :             wal_backup_enabled: true,
     115            4 :             backup_parallel_jobs: 1,
     116            4 :             pg_auth: None,
     117            4 :             pg_tenant_only_auth: None,
     118            4 :             http_auth: None,
     119            4 :             sk_auth_token: None,
     120            4 :             heartbeat_timeout: Duration::new(5, 0),
     121            4 :             max_offloader_lag_bytes: defaults::DEFAULT_MAX_OFFLOADER_LAG_BYTES,
     122            4 :             current_thread_runtime: false,
     123            4 :             walsenders_keep_horizon: false,
     124            4 :             partial_backup_enabled: false,
     125            4 :             partial_backup_timeout: Duration::from_secs(0),
     126            4 :             disable_periodic_broker_push: false,
     127            4 :         }
     128            4 :     }
     129              : }
     130              : 
     131              : // Tokio runtimes.
     132            0 : pub static WAL_SERVICE_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     133            0 :     tokio::runtime::Builder::new_multi_thread()
     134            0 :         .thread_name("WAL service worker")
     135            0 :         .enable_all()
     136            0 :         .build()
     137            0 :         .expect("Failed to create WAL service runtime")
     138            0 : });
     139              : 
     140            0 : pub static HTTP_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     141            0 :     tokio::runtime::Builder::new_multi_thread()
     142            0 :         .thread_name("HTTP worker")
     143            0 :         .enable_all()
     144            0 :         .build()
     145            0 :         .expect("Failed to create WAL service runtime")
     146            0 : });
     147              : 
     148            0 : pub static BROKER_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     149            0 :     tokio::runtime::Builder::new_multi_thread()
     150            0 :         .thread_name("broker worker")
     151            0 :         .worker_threads(2) // there are only 2 tasks, having more threads doesn't make sense
     152            0 :         .enable_all()
     153            0 :         .build()
     154            0 :         .expect("Failed to create broker runtime")
     155            0 : });
     156              : 
     157            0 : pub static WAL_REMOVER_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     158            0 :     tokio::runtime::Builder::new_multi_thread()
     159            0 :         .thread_name("WAL remover")
     160            0 :         .worker_threads(1)
     161            0 :         .enable_all()
     162            0 :         .build()
     163            0 :         .expect("Failed to create broker runtime")
     164            0 : });
     165              : 
     166            0 : pub static WAL_BACKUP_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     167            0 :     tokio::runtime::Builder::new_multi_thread()
     168            0 :         .thread_name("WAL backup worker")
     169            0 :         .enable_all()
     170            0 :         .build()
     171            0 :         .expect("Failed to create WAL backup runtime")
     172            0 : });
     173              : 
     174            0 : pub static METRICS_SHIFTER_RUNTIME: Lazy<Runtime> = Lazy::new(|| {
     175            0 :     tokio::runtime::Builder::new_multi_thread()
     176            0 :         .thread_name("metric shifter")
     177            0 :         .worker_threads(1)
     178            0 :         .enable_all()
     179            0 :         .build()
     180            0 :         .expect("Failed to create broker runtime")
     181            0 : });
        

Generated by: LCOV version 2.1-beta