LCOV - code coverage report
Current view: top level - safekeeper/src - lib.rs (source / functions) Coverage Total Hit
Test: 49aa928ec5b4b510172d8b5c6d154da28e70a46c.info Lines: 0.0 % 67 0
Test Date: 2024-11-13 18:23:39 Functions: 0.0 % 6 0

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

Generated by: LCOV version 2.1-beta