LCOV - code coverage report
Current view: top level - libs/pageserver_api/src - config.rs (source / functions) Coverage Total Hit
Test: 5fe7fa8d483b39476409aee736d6d5e32728bfac.info Lines: 89.2 % 176 157
Test Date: 2025-03-12 16:10:49 Functions: 3.4 % 203 7

            Line data    Source code
       1              : use camino::Utf8PathBuf;
       2              : 
       3              : #[cfg(test)]
       4              : mod tests;
       5              : 
       6              : use const_format::formatcp;
       7              : pub const DEFAULT_PG_LISTEN_PORT: u16 = 64000;
       8              : pub const DEFAULT_PG_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_PG_LISTEN_PORT}");
       9              : pub const DEFAULT_HTTP_LISTEN_PORT: u16 = 9898;
      10              : pub const DEFAULT_HTTP_LISTEN_ADDR: &str = formatcp!("127.0.0.1:{DEFAULT_HTTP_LISTEN_PORT}");
      11              : 
      12              : use std::collections::HashMap;
      13              : use std::num::{NonZeroU64, NonZeroUsize};
      14              : use std::str::FromStr;
      15              : use std::time::Duration;
      16              : 
      17              : use postgres_backend::AuthType;
      18              : use remote_storage::RemoteStorageConfig;
      19              : use serde_with::serde_as;
      20              : use utils::logging::LogFormat;
      21              : use utils::postgres_client::PostgresClientProtocol;
      22              : 
      23              : use crate::models::{ImageCompressionAlgorithm, LsnLease};
      24              : 
      25              : // Certain metadata (e.g. externally-addressable name, AZ) is delivered
      26              : // as a separate structure.  This information is not neeed by the pageserver
      27              : // itself, it is only used for registering the pageserver with the control
      28              : // plane and/or storage controller.
      29              : //
      30            9 : #[derive(PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
      31              : pub struct NodeMetadata {
      32              :     #[serde(rename = "host")]
      33              :     pub postgres_host: String,
      34              :     #[serde(rename = "port")]
      35              :     pub postgres_port: u16,
      36              :     pub http_host: String,
      37              :     pub http_port: u16,
      38              :     pub https_port: Option<u16>,
      39              : 
      40              :     // Deployment tools may write fields to the metadata file beyond what we
      41              :     // use in this type: this type intentionally only names fields that require.
      42              :     #[serde(flatten)]
      43              :     pub other: HashMap<String, serde_json::Value>,
      44              : }
      45              : 
      46              : /// `pageserver.toml`
      47              : ///
      48              : /// We use serde derive with `#[serde(default)]` to generate a deserializer
      49              : /// that fills in the default values for each config field.
      50              : ///
      51              : /// If there cannot be a static default value because we need to make runtime
      52              : /// checks to determine the default, make it an `Option` (which defaults to None).
      53              : /// The runtime check should be done in the consuming crate, i.e., `pageserver`.
      54              : #[serde_as]
      55           20 : #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
      56              : #[serde(default, deny_unknown_fields)]
      57              : pub struct ConfigToml {
      58              :     // types mapped 1:1 into the runtime PageServerConfig type
      59              :     pub listen_pg_addr: String,
      60              :     pub listen_http_addr: String,
      61              :     pub listen_https_addr: Option<String>,
      62              :     pub ssl_key_file: Utf8PathBuf,
      63              :     pub ssl_cert_file: Utf8PathBuf,
      64              :     pub availability_zone: Option<String>,
      65              :     #[serde(with = "humantime_serde")]
      66              :     pub wait_lsn_timeout: Duration,
      67              :     #[serde(with = "humantime_serde")]
      68              :     pub wal_redo_timeout: Duration,
      69              :     pub superuser: String,
      70              :     pub locale: String,
      71              :     pub page_cache_size: usize,
      72              :     pub max_file_descriptors: usize,
      73              :     pub pg_distrib_dir: Option<Utf8PathBuf>,
      74              :     #[serde_as(as = "serde_with::DisplayFromStr")]
      75              :     pub http_auth_type: AuthType,
      76              :     #[serde_as(as = "serde_with::DisplayFromStr")]
      77              :     pub pg_auth_type: AuthType,
      78              :     pub auth_validation_public_key_path: Option<Utf8PathBuf>,
      79              :     pub remote_storage: Option<RemoteStorageConfig>,
      80              :     pub tenant_config: TenantConfigToml,
      81              :     #[serde_as(as = "serde_with::DisplayFromStr")]
      82              :     pub broker_endpoint: storage_broker::Uri,
      83              :     #[serde(with = "humantime_serde")]
      84              :     pub broker_keepalive_interval: Duration,
      85              :     #[serde_as(as = "serde_with::DisplayFromStr")]
      86              :     pub log_format: LogFormat,
      87              :     pub concurrent_tenant_warmup: NonZeroUsize,
      88              :     pub concurrent_tenant_size_logical_size_queries: NonZeroUsize,
      89              :     #[serde(with = "humantime_serde")]
      90              :     pub metric_collection_interval: Duration,
      91              :     pub metric_collection_endpoint: Option<reqwest::Url>,
      92              :     pub metric_collection_bucket: Option<RemoteStorageConfig>,
      93              :     #[serde(with = "humantime_serde")]
      94              :     pub synthetic_size_calculation_interval: Duration,
      95              :     pub disk_usage_based_eviction: Option<DiskUsageEvictionTaskConfig>,
      96              :     pub test_remote_failures: u64,
      97              :     pub ondemand_download_behavior_treat_error_as_warn: bool,
      98              :     #[serde(with = "humantime_serde")]
      99              :     pub background_task_maximum_delay: Duration,
     100              :     pub control_plane_api: Option<reqwest::Url>,
     101              :     pub control_plane_api_token: Option<String>,
     102              :     pub control_plane_emergency_mode: bool,
     103              :     /// Unstable feature: subject to change or removal without notice.
     104              :     /// See <https://github.com/neondatabase/neon/pull/9218>.
     105              :     pub import_pgdata_upcall_api: Option<reqwest::Url>,
     106              :     /// Unstable feature: subject to change or removal without notice.
     107              :     /// See <https://github.com/neondatabase/neon/pull/9218>.
     108              :     pub import_pgdata_upcall_api_token: Option<String>,
     109              :     /// Unstable feature: subject to change or removal without notice.
     110              :     /// See <https://github.com/neondatabase/neon/pull/9218>.
     111              :     pub import_pgdata_aws_endpoint_url: Option<reqwest::Url>,
     112              :     pub heatmap_upload_concurrency: usize,
     113              :     pub secondary_download_concurrency: usize,
     114              :     pub virtual_file_io_engine: Option<crate::models::virtual_file::IoEngineKind>,
     115              :     pub ingest_batch_size: u64,
     116              :     pub max_vectored_read_bytes: MaxVectoredReadBytes,
     117              :     pub image_compression: ImageCompressionAlgorithm,
     118              :     pub timeline_offloading: bool,
     119              :     pub ephemeral_bytes_per_memory_kb: usize,
     120              :     pub l0_flush: Option<crate::models::L0FlushConfig>,
     121              :     pub virtual_file_io_mode: Option<crate::models::virtual_file::IoMode>,
     122              :     #[serde(skip_serializing_if = "Option::is_none")]
     123              :     pub no_sync: Option<bool>,
     124              :     pub wal_receiver_protocol: PostgresClientProtocol,
     125              :     pub page_service_pipelining: PageServicePipeliningConfig,
     126              :     pub get_vectored_concurrent_io: GetVectoredConcurrentIo,
     127              :     pub enable_read_path_debugging: Option<bool>,
     128              :     #[serde(skip_serializing_if = "Option::is_none")]
     129              :     pub validate_wal_contiguity: Option<bool>,
     130              :     #[serde(skip_serializing_if = "Option::is_none")]
     131              :     pub load_previous_heatmap: Option<bool>,
     132              :     #[serde(skip_serializing_if = "Option::is_none")]
     133              :     pub generate_unarchival_heatmap: Option<bool>,
     134              : }
     135              : 
     136            4 : #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     137              : #[serde(deny_unknown_fields)]
     138              : pub struct DiskUsageEvictionTaskConfig {
     139              :     pub max_usage_pct: utils::serde_percent::Percent,
     140              :     pub min_avail_bytes: u64,
     141              :     #[serde(with = "humantime_serde")]
     142              :     pub period: Duration,
     143              :     #[cfg(feature = "testing")]
     144              :     pub mock_statvfs: Option<statvfs::mock::Behavior>,
     145              :     /// Select sorting for evicted layers
     146              :     #[serde(default)]
     147              :     pub eviction_order: EvictionOrder,
     148              : }
     149              : 
     150            0 : #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     151              : #[serde(tag = "mode", rename_all = "kebab-case")]
     152              : #[serde(deny_unknown_fields)]
     153              : pub enum PageServicePipeliningConfig {
     154              :     Serial,
     155              :     Pipelined(PageServicePipeliningConfigPipelined),
     156              : }
     157            0 : #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     158              : #[serde(deny_unknown_fields)]
     159              : pub struct PageServicePipeliningConfigPipelined {
     160              :     /// Causes runtime errors if larger than max get_vectored batch size.
     161              :     pub max_batch_size: NonZeroUsize,
     162              :     pub execution: PageServiceProtocolPipelinedExecutionStrategy,
     163              : }
     164              : 
     165            0 : #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     166              : #[serde(rename_all = "kebab-case")]
     167              : pub enum PageServiceProtocolPipelinedExecutionStrategy {
     168              :     ConcurrentFutures,
     169              :     Tasks,
     170              : }
     171              : 
     172            0 : #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     173              : #[serde(tag = "mode", rename_all = "kebab-case")]
     174              : #[serde(deny_unknown_fields)]
     175              : pub enum GetVectoredConcurrentIo {
     176              :     /// The read path is fully sequential: layers are visited
     177              :     /// one after the other and IOs are issued and waited upon
     178              :     /// from the same task that traverses the layers.
     179              :     Sequential,
     180              :     /// The read path still traverses layers sequentially, and
     181              :     /// index blocks will be read into the PS PageCache from
     182              :     /// that task, with waiting.
     183              :     /// But data IOs are dispatched and waited upon from a sidecar
     184              :     /// task so that the traversing task can continue to traverse
     185              :     /// layers while the IOs are in flight.
     186              :     /// If the PS PageCache miss rate is low, this improves
     187              :     /// throughput dramatically.
     188              :     SidecarTask,
     189              : }
     190              : 
     191              : pub mod statvfs {
     192              :     pub mod mock {
     193            0 :         #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     194              :         #[serde(tag = "type")]
     195              :         pub enum Behavior {
     196              :             Success {
     197              :                 blocksize: u64,
     198              :                 total_blocks: u64,
     199              :                 name_filter: Option<utils::serde_regex::Regex>,
     200              :             },
     201              :             #[cfg(feature = "testing")]
     202              :             Failure { mocked_error: MockedError },
     203              :         }
     204              : 
     205              :         #[cfg(feature = "testing")]
     206            0 :         #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     207              :         #[allow(clippy::upper_case_acronyms)]
     208              :         pub enum MockedError {
     209              :             EIO,
     210              :         }
     211              : 
     212              :         #[cfg(feature = "testing")]
     213              :         impl From<MockedError> for nix::Error {
     214            0 :             fn from(e: MockedError) -> Self {
     215            0 :                 match e {
     216            0 :                     MockedError::EIO => nix::Error::EIO,
     217            0 :                 }
     218            0 :             }
     219              :         }
     220              :     }
     221              : }
     222              : 
     223            0 : #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     224              : #[serde(tag = "type", content = "args")]
     225              : pub enum EvictionOrder {
     226              :     RelativeAccessed {
     227              :         highest_layer_count_loses_first: bool,
     228              :     },
     229              : }
     230              : 
     231              : impl Default for EvictionOrder {
     232            4 :     fn default() -> Self {
     233            4 :         Self::RelativeAccessed {
     234            4 :             highest_layer_count_loses_first: true,
     235            4 :         }
     236            4 :     }
     237              : }
     238              : 
     239            0 : #[derive(Copy, Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     240              : #[serde(transparent)]
     241              : pub struct MaxVectoredReadBytes(pub NonZeroUsize);
     242              : 
     243              : /// A tenant's calcuated configuration, which is the result of merging a
     244              : /// tenant's TenantConfOpt with the global TenantConf from PageServerConf.
     245              : ///
     246              : /// For storing and transmitting individual tenant's configuration, see
     247              : /// TenantConfOpt.
     248            4 : #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
     249              : #[serde(deny_unknown_fields, default)]
     250              : pub struct TenantConfigToml {
     251              :     // Flush out an inmemory layer, if it's holding WAL older than this
     252              :     // This puts a backstop on how much WAL needs to be re-digested if the
     253              :     // page server crashes.
     254              :     // This parameter actually determines L0 layer file size.
     255              :     pub checkpoint_distance: u64,
     256              :     // Inmemory layer is also flushed at least once in checkpoint_timeout to
     257              :     // eventually upload WAL after activity is stopped.
     258              :     #[serde(with = "humantime_serde")]
     259              :     pub checkpoint_timeout: Duration,
     260              :     // Target file size, when creating image and delta layers.
     261              :     // This parameter determines L1 layer file size.
     262              :     pub compaction_target_size: u64,
     263              :     // How often to check if there's compaction work to be done.
     264              :     // Duration::ZERO means automatic compaction is disabled.
     265              :     #[serde(with = "humantime_serde")]
     266              :     pub compaction_period: Duration,
     267              :     /// Level0 delta layer threshold for compaction.
     268              :     pub compaction_threshold: usize,
     269              :     /// Controls the amount of L0 included in a single compaction iteration.
     270              :     /// The unit is `checkpoint_distance`, i.e., a size.
     271              :     /// We add L0s to the set of layers to compact until their cumulative
     272              :     /// size exceeds `compaction_upper_limit * checkpoint_distance`.
     273              :     pub compaction_upper_limit: usize,
     274              :     pub compaction_algorithm: crate::models::CompactionAlgorithmSettings,
     275              :     /// If true, compact down L0 across all tenant timelines before doing regular compaction.
     276              :     pub compaction_l0_first: bool,
     277              :     /// If true, use a separate semaphore (i.e. concurrency limit) for the L0 compaction pass. Only
     278              :     /// has an effect if `compaction_l0_first` is `true`.
     279              :     pub compaction_l0_semaphore: bool,
     280              :     /// Level0 delta layer threshold at which to delay layer flushes for compaction backpressure,
     281              :     /// such that they take 2x as long, and start waiting for layer flushes during ephemeral layer
     282              :     /// rolls. This helps compaction keep up with WAL ingestion, and avoids read amplification
     283              :     /// blowing up. Should be >compaction_threshold. 0 to disable. Disabled by default.
     284              :     pub l0_flush_delay_threshold: Option<usize>,
     285              :     /// Level0 delta layer threshold at which to stall layer flushes. Must be >compaction_threshold
     286              :     /// to avoid deadlock. 0 to disable. Disabled by default.
     287              :     pub l0_flush_stall_threshold: Option<usize>,
     288              :     /// If true, Level0 delta layer flushes will wait for S3 upload before flushing the next
     289              :     /// layer. This is a temporary backpressure mechanism which should be removed once
     290              :     /// l0_flush_{delay,stall}_threshold is fully enabled.
     291              :     pub l0_flush_wait_upload: bool,
     292              :     // Determines how much history is retained, to allow
     293              :     // branching and read replicas at an older point in time.
     294              :     // The unit is #of bytes of WAL.
     295              :     // Page versions older than this are garbage collected away.
     296              :     pub gc_horizon: u64,
     297              :     // Interval at which garbage collection is triggered.
     298              :     // Duration::ZERO means automatic GC is disabled
     299              :     #[serde(with = "humantime_serde")]
     300              :     pub gc_period: Duration,
     301              :     // Delta layer churn threshold to create L1 image layers.
     302              :     pub image_creation_threshold: usize,
     303              :     // Determines how much history is retained, to allow
     304              :     // branching and read replicas at an older point in time.
     305              :     // The unit is time.
     306              :     // Page versions older than this are garbage collected away.
     307              :     #[serde(with = "humantime_serde")]
     308              :     pub pitr_interval: Duration,
     309              :     /// Maximum amount of time to wait while opening a connection to receive wal, before erroring.
     310              :     #[serde(with = "humantime_serde")]
     311              :     pub walreceiver_connect_timeout: Duration,
     312              :     /// Considers safekeepers stalled after no WAL updates were received longer than this threshold.
     313              :     /// A stalled safekeeper will be changed to a newer one when it appears.
     314              :     #[serde(with = "humantime_serde")]
     315              :     pub lagging_wal_timeout: Duration,
     316              :     /// Considers safekeepers lagging when their WAL is behind another safekeeper for more than this threshold.
     317              :     /// A lagging safekeeper will be changed after `lagging_wal_timeout` time elapses since the last WAL update,
     318              :     /// to avoid eager reconnects.
     319              :     pub max_lsn_wal_lag: NonZeroU64,
     320              :     pub eviction_policy: crate::models::EvictionPolicy,
     321              :     pub min_resident_size_override: Option<u64>,
     322              :     // See the corresponding metric's help string.
     323              :     #[serde(with = "humantime_serde")]
     324              :     pub evictions_low_residence_duration_metric_threshold: Duration,
     325              : 
     326              :     /// If non-zero, the period between uploads of a heatmap from attached tenants.  This
     327              :     /// may be disabled if a Tenant will not have secondary locations: only secondary
     328              :     /// locations will use the heatmap uploaded by attached locations.
     329              :     #[serde(with = "humantime_serde")]
     330              :     pub heatmap_period: Duration,
     331              : 
     332              :     /// If true then SLRU segments are dowloaded on demand, if false SLRU segments are included in basebackup
     333              :     pub lazy_slru_download: bool,
     334              : 
     335              :     pub timeline_get_throttle: crate::models::ThrottleConfig,
     336              : 
     337              :     // How much WAL must be ingested before checking again whether a new image layer is required.
     338              :     // Expresed in multiples of checkpoint distance.
     339              :     pub image_layer_creation_check_threshold: u8,
     340              : 
     341              :     // How many multiples of L0 `compaction_threshold` will preempt image layer creation and do L0 compaction.
     342              :     // Set to 0 to disable preemption.
     343              :     pub image_creation_preempt_threshold: usize,
     344              : 
     345              :     /// The length for an explicit LSN lease request.
     346              :     /// Layers needed to reconstruct pages at LSN will not be GC-ed during this interval.
     347              :     #[serde(with = "humantime_serde")]
     348              :     pub lsn_lease_length: Duration,
     349              : 
     350              :     /// The length for an implicit LSN lease granted as part of `get_lsn_by_timestamp` request.
     351              :     /// Layers needed to reconstruct pages at LSN will not be GC-ed during this interval.
     352              :     #[serde(with = "humantime_serde")]
     353              :     pub lsn_lease_length_for_ts: Duration,
     354              : 
     355              :     /// Enable auto-offloading of timelines.
     356              :     /// (either this flag or the pageserver-global one need to be set)
     357              :     pub timeline_offloading: bool,
     358              : 
     359              :     pub wal_receiver_protocol_override: Option<PostgresClientProtocol>,
     360              : 
     361              :     /// Enable rel_size_v2 for this tenant. Once enabled, the tenant will persist this information into
     362              :     /// `index_part.json`, and it cannot be reversed.
     363              :     pub rel_size_v2_enabled: bool,
     364              : 
     365              :     // gc-compaction related configs
     366              :     /// Enable automatic gc-compaction trigger on this tenant.
     367              :     pub gc_compaction_enabled: bool,
     368              :     /// The initial threshold for gc-compaction in KB. Once the total size of layers below the gc-horizon is above this threshold,
     369              :     /// gc-compaction will be triggered.
     370              :     pub gc_compaction_initial_threshold_kb: u64,
     371              :     /// The ratio that triggers the auto gc-compaction. If (the total size of layers between L2 LSN and gc-horizon) / (size below the L2 LSN)
     372              :     /// is above this ratio, gc-compaction will be triggered.
     373              :     pub gc_compaction_ratio_percent: u64,
     374              : }
     375              : 
     376              : pub mod defaults {
     377              :     pub use storage_broker::DEFAULT_ENDPOINT as BROKER_DEFAULT_ENDPOINT;
     378              : 
     379              :     use crate::models::ImageCompressionAlgorithm;
     380              : 
     381              :     pub const DEFAULT_WAIT_LSN_TIMEOUT: &str = "300 s";
     382              :     pub const DEFAULT_WAL_REDO_TIMEOUT: &str = "60 s";
     383              : 
     384              :     pub const DEFAULT_SUPERUSER: &str = "cloud_admin";
     385              :     pub const DEFAULT_LOCALE: &str = if cfg!(target_os = "macos") {
     386              :         "C"
     387              :     } else {
     388              :         "C.UTF-8"
     389              :     };
     390              : 
     391              :     pub const DEFAULT_PAGE_CACHE_SIZE: usize = 8192;
     392              :     pub const DEFAULT_MAX_FILE_DESCRIPTORS: usize = 100;
     393              : 
     394              :     pub const DEFAULT_LOG_FORMAT: &str = "plain";
     395              : 
     396              :     pub const DEFAULT_CONCURRENT_TENANT_WARMUP: usize = 8;
     397              : 
     398              :     pub const DEFAULT_CONCURRENT_TENANT_SIZE_LOGICAL_SIZE_QUERIES: usize = 1;
     399              : 
     400              :     pub const DEFAULT_METRIC_COLLECTION_INTERVAL: &str = "10 min";
     401              :     pub const DEFAULT_METRIC_COLLECTION_ENDPOINT: Option<reqwest::Url> = None;
     402              :     pub const DEFAULT_SYNTHETIC_SIZE_CALCULATION_INTERVAL: &str = "10 min";
     403              :     pub const DEFAULT_BACKGROUND_TASK_MAXIMUM_DELAY: &str = "10s";
     404              : 
     405              :     pub const DEFAULT_HEATMAP_UPLOAD_CONCURRENCY: usize = 8;
     406              :     pub const DEFAULT_SECONDARY_DOWNLOAD_CONCURRENCY: usize = 1;
     407              : 
     408              :     pub const DEFAULT_INGEST_BATCH_SIZE: u64 = 100;
     409              : 
     410              :     /// Soft limit for the maximum size of a vectored read.
     411              :     ///
     412              :     /// This is determined by the largest NeonWalRecord that can exist (minus dbdir and reldir keys
     413              :     /// which are bounded by the blob io limits only). As of this writing, that is a `NeonWalRecord::ClogSetCommitted` record,
     414              :     /// with 32k xids. That's the max number of XIDS on a single CLOG page. The size of such a record
     415              :     /// is `sizeof(Transactionid) * 32768 + (some fixed overhead from 'timestamp`, the Vec length and whatever extra serde serialization adds)`.
     416              :     /// That is, slightly above 128 kB.
     417              :     pub const DEFAULT_MAX_VECTORED_READ_BYTES: usize = 130 * 1024; // 130 KiB
     418              : 
     419              :     pub const DEFAULT_IMAGE_COMPRESSION: ImageCompressionAlgorithm =
     420              :         ImageCompressionAlgorithm::Zstd { level: Some(1) };
     421              : 
     422              :     pub const DEFAULT_EPHEMERAL_BYTES_PER_MEMORY_KB: usize = 0;
     423              : 
     424              :     pub const DEFAULT_IO_BUFFER_ALIGNMENT: usize = 512;
     425              : 
     426              :     pub const DEFAULT_WAL_RECEIVER_PROTOCOL: utils::postgres_client::PostgresClientProtocol =
     427              :         utils::postgres_client::PostgresClientProtocol::Vanilla;
     428              : 
     429              :     pub const DEFAULT_SSL_KEY_FILE: &str = "server.key";
     430              :     pub const DEFAULT_SSL_CERT_FILE: &str = "server.crt";
     431              : }
     432              : 
     433              : impl Default for ConfigToml {
     434          488 :     fn default() -> Self {
     435              :         use defaults::*;
     436              : 
     437              :         Self {
     438          488 :             listen_pg_addr: (DEFAULT_PG_LISTEN_ADDR.to_string()),
     439          488 :             listen_http_addr: (DEFAULT_HTTP_LISTEN_ADDR.to_string()),
     440          488 :             listen_https_addr: (None),
     441          488 :             ssl_key_file: Utf8PathBuf::from(DEFAULT_SSL_KEY_FILE),
     442          488 :             ssl_cert_file: Utf8PathBuf::from(DEFAULT_SSL_CERT_FILE),
     443          488 :             availability_zone: (None),
     444          488 :             wait_lsn_timeout: (humantime::parse_duration(DEFAULT_WAIT_LSN_TIMEOUT)
     445          488 :                 .expect("cannot parse default wait lsn timeout")),
     446          488 :             wal_redo_timeout: (humantime::parse_duration(DEFAULT_WAL_REDO_TIMEOUT)
     447          488 :                 .expect("cannot parse default wal redo timeout")),
     448          488 :             superuser: (DEFAULT_SUPERUSER.to_string()),
     449          488 :             locale: DEFAULT_LOCALE.to_string(),
     450          488 :             page_cache_size: (DEFAULT_PAGE_CACHE_SIZE),
     451          488 :             max_file_descriptors: (DEFAULT_MAX_FILE_DESCRIPTORS),
     452          488 :             pg_distrib_dir: None, // Utf8PathBuf::from("./pg_install"), // TODO: formely, this was std::env::current_dir()
     453          488 :             http_auth_type: (AuthType::Trust),
     454          488 :             pg_auth_type: (AuthType::Trust),
     455          488 :             auth_validation_public_key_path: (None),
     456          488 :             remote_storage: None,
     457          488 :             broker_endpoint: (storage_broker::DEFAULT_ENDPOINT
     458          488 :                 .parse()
     459          488 :                 .expect("failed to parse default broker endpoint")),
     460          488 :             broker_keepalive_interval: (humantime::parse_duration(
     461          488 :                 storage_broker::DEFAULT_KEEPALIVE_INTERVAL,
     462          488 :             )
     463          488 :             .expect("cannot parse default keepalive interval")),
     464          488 :             log_format: (LogFormat::from_str(DEFAULT_LOG_FORMAT).unwrap()),
     465          488 : 
     466          488 :             concurrent_tenant_warmup: (NonZeroUsize::new(DEFAULT_CONCURRENT_TENANT_WARMUP)
     467          488 :                 .expect("Invalid default constant")),
     468          488 :             concurrent_tenant_size_logical_size_queries: NonZeroUsize::new(
     469          488 :                 DEFAULT_CONCURRENT_TENANT_SIZE_LOGICAL_SIZE_QUERIES,
     470          488 :             )
     471          488 :             .unwrap(),
     472          488 :             metric_collection_interval: (humantime::parse_duration(
     473          488 :                 DEFAULT_METRIC_COLLECTION_INTERVAL,
     474          488 :             )
     475          488 :             .expect("cannot parse default metric collection interval")),
     476          488 :             synthetic_size_calculation_interval: (humantime::parse_duration(
     477          488 :                 DEFAULT_SYNTHETIC_SIZE_CALCULATION_INTERVAL,
     478          488 :             )
     479          488 :             .expect("cannot parse default synthetic size calculation interval")),
     480          488 :             metric_collection_endpoint: (DEFAULT_METRIC_COLLECTION_ENDPOINT),
     481          488 : 
     482          488 :             metric_collection_bucket: (None),
     483          488 : 
     484          488 :             disk_usage_based_eviction: (None),
     485          488 : 
     486          488 :             test_remote_failures: (0),
     487          488 : 
     488          488 :             ondemand_download_behavior_treat_error_as_warn: (false),
     489          488 : 
     490          488 :             background_task_maximum_delay: (humantime::parse_duration(
     491          488 :                 DEFAULT_BACKGROUND_TASK_MAXIMUM_DELAY,
     492          488 :             )
     493          488 :             .unwrap()),
     494          488 : 
     495          488 :             control_plane_api: (None),
     496          488 :             control_plane_api_token: (None),
     497          488 :             control_plane_emergency_mode: (false),
     498          488 : 
     499          488 :             import_pgdata_upcall_api: (None),
     500          488 :             import_pgdata_upcall_api_token: (None),
     501          488 :             import_pgdata_aws_endpoint_url: (None),
     502          488 : 
     503          488 :             heatmap_upload_concurrency: (DEFAULT_HEATMAP_UPLOAD_CONCURRENCY),
     504          488 :             secondary_download_concurrency: (DEFAULT_SECONDARY_DOWNLOAD_CONCURRENCY),
     505          488 : 
     506          488 :             ingest_batch_size: (DEFAULT_INGEST_BATCH_SIZE),
     507          488 : 
     508          488 :             virtual_file_io_engine: None,
     509          488 : 
     510          488 :             max_vectored_read_bytes: (MaxVectoredReadBytes(
     511          488 :                 NonZeroUsize::new(DEFAULT_MAX_VECTORED_READ_BYTES).unwrap(),
     512          488 :             )),
     513          488 :             image_compression: (DEFAULT_IMAGE_COMPRESSION),
     514          488 :             timeline_offloading: true,
     515          488 :             ephemeral_bytes_per_memory_kb: (DEFAULT_EPHEMERAL_BYTES_PER_MEMORY_KB),
     516          488 :             l0_flush: None,
     517          488 :             virtual_file_io_mode: None,
     518          488 :             tenant_config: TenantConfigToml::default(),
     519          488 :             no_sync: None,
     520          488 :             wal_receiver_protocol: DEFAULT_WAL_RECEIVER_PROTOCOL,
     521          488 :             page_service_pipelining: if !cfg!(test) {
     522          488 :                 PageServicePipeliningConfig::Serial
     523              :             } else {
     524            0 :                 PageServicePipeliningConfig::Pipelined(PageServicePipeliningConfigPipelined {
     525            0 :                     max_batch_size: NonZeroUsize::new(32).unwrap(),
     526            0 :                     execution: PageServiceProtocolPipelinedExecutionStrategy::ConcurrentFutures,
     527            0 :                 })
     528              :             },
     529          488 :             get_vectored_concurrent_io: if !cfg!(test) {
     530          488 :                 GetVectoredConcurrentIo::Sequential
     531              :             } else {
     532            0 :                 GetVectoredConcurrentIo::SidecarTask
     533              :             },
     534          488 :             enable_read_path_debugging: if cfg!(test) || cfg!(feature = "testing") {
     535          488 :                 Some(true)
     536              :             } else {
     537            0 :                 None
     538              :             },
     539          488 :             validate_wal_contiguity: None,
     540          488 :             load_previous_heatmap: None,
     541          488 :             generate_unarchival_heatmap: None,
     542          488 :         }
     543          488 :     }
     544              : }
     545              : 
     546              : pub mod tenant_conf_defaults {
     547              : 
     548              :     // FIXME: This current value is very low. I would imagine something like 1 GB or 10 GB
     549              :     // would be more appropriate. But a low value forces the code to be exercised more,
     550              :     // which is good for now to trigger bugs.
     551              :     // This parameter actually determines L0 layer file size.
     552              :     pub const DEFAULT_CHECKPOINT_DISTANCE: u64 = 256 * 1024 * 1024;
     553              :     pub const DEFAULT_CHECKPOINT_TIMEOUT: &str = "10 m";
     554              : 
     555              :     // FIXME the below configs are only used by legacy algorithm. The new algorithm
     556              :     // has different parameters.
     557              : 
     558              :     // Target file size, when creating image and delta layers.
     559              :     // This parameter determines L1 layer file size.
     560              :     pub const DEFAULT_COMPACTION_TARGET_SIZE: u64 = 128 * 1024 * 1024;
     561              : 
     562              :     pub const DEFAULT_COMPACTION_PERIOD: &str = "20 s";
     563              :     pub const DEFAULT_COMPACTION_THRESHOLD: usize = 10;
     564              : 
     565              :     // This value needs to be tuned to avoid OOM. We have 3/4*CPUs threads for L0 compaction, that's
     566              :     // 3/4*16=9 on most of our pageservers. Compacting 20 layers requires about 1 GB memory (could
     567              :     // be reduced later by optimizing L0 hole calculation to avoid loading all keys into memory). So
     568              :     // with this config, we can get a maximum peak compaction usage of 9 GB.
     569              :     pub const DEFAULT_COMPACTION_UPPER_LIMIT: usize = 20;
     570              :     pub const DEFAULT_COMPACTION_L0_FIRST: bool = false;
     571              :     pub const DEFAULT_COMPACTION_L0_SEMAPHORE: bool = true;
     572              : 
     573              :     pub const DEFAULT_COMPACTION_ALGORITHM: crate::models::CompactionAlgorithm =
     574              :         crate::models::CompactionAlgorithm::Legacy;
     575              : 
     576              :     pub const DEFAULT_L0_FLUSH_WAIT_UPLOAD: bool = true;
     577              : 
     578              :     pub const DEFAULT_GC_HORIZON: u64 = 64 * 1024 * 1024;
     579              : 
     580              :     // Large DEFAULT_GC_PERIOD is fine as long as PITR_INTERVAL is larger.
     581              :     // If there's a need to decrease this value, first make sure that GC
     582              :     // doesn't hold a layer map write lock for non-trivial operations.
     583              :     // Relevant: https://github.com/neondatabase/neon/issues/3394
     584              :     pub const DEFAULT_GC_PERIOD: &str = "1 hr";
     585              :     pub const DEFAULT_IMAGE_CREATION_THRESHOLD: usize = 3;
     586              :     // If there are more than threshold * compaction_threshold (that is 3 * 10 in the default config) L0 layers, image
     587              :     // layer creation will end immediately. Set to 0 to disable. The target default will be 3 once we
     588              :     // want to enable this feature.
     589              :     pub const DEFAULT_IMAGE_CREATION_PREEMPT_THRESHOLD: usize = 0;
     590              :     pub const DEFAULT_PITR_INTERVAL: &str = "7 days";
     591              :     pub const DEFAULT_WALRECEIVER_CONNECT_TIMEOUT: &str = "10 seconds";
     592              :     pub const DEFAULT_WALRECEIVER_LAGGING_WAL_TIMEOUT: &str = "10 seconds";
     593              :     // The default limit on WAL lag should be set to avoid causing disconnects under high throughput
     594              :     // scenarios: since the broker stats are updated ~1/s, a value of 1GiB should be sufficient for
     595              :     // throughputs up to 1GiB/s per timeline.
     596              :     pub const DEFAULT_MAX_WALRECEIVER_LSN_WAL_LAG: u64 = 1024 * 1024 * 1024;
     597              :     pub const DEFAULT_EVICTIONS_LOW_RESIDENCE_DURATION_METRIC_THRESHOLD: &str = "24 hour";
     598              :     // By default ingest enough WAL for two new L0 layers before checking if new image
     599              :     // image layers should be created.
     600              :     pub const DEFAULT_IMAGE_LAYER_CREATION_CHECK_THRESHOLD: u8 = 2;
     601              :     pub const DEFAULT_GC_COMPACTION_ENABLED: bool = false;
     602              :     pub const DEFAULT_GC_COMPACTION_INITIAL_THRESHOLD_KB: u64 = 5 * 1024 * 1024; // 5GB
     603              :     pub const DEFAULT_GC_COMPACTION_RATIO_PERCENT: u64 = 100;
     604              : }
     605              : 
     606              : impl Default for TenantConfigToml {
     607          924 :     fn default() -> Self {
     608              :         use tenant_conf_defaults::*;
     609          924 :         Self {
     610          924 :             checkpoint_distance: DEFAULT_CHECKPOINT_DISTANCE,
     611          924 :             checkpoint_timeout: humantime::parse_duration(DEFAULT_CHECKPOINT_TIMEOUT)
     612          924 :                 .expect("cannot parse default checkpoint timeout"),
     613          924 :             compaction_target_size: DEFAULT_COMPACTION_TARGET_SIZE,
     614          924 :             compaction_period: humantime::parse_duration(DEFAULT_COMPACTION_PERIOD)
     615          924 :                 .expect("cannot parse default compaction period"),
     616          924 :             compaction_threshold: DEFAULT_COMPACTION_THRESHOLD,
     617          924 :             compaction_upper_limit: DEFAULT_COMPACTION_UPPER_LIMIT,
     618          924 :             compaction_algorithm: crate::models::CompactionAlgorithmSettings {
     619          924 :                 kind: DEFAULT_COMPACTION_ALGORITHM,
     620          924 :             },
     621          924 :             compaction_l0_first: DEFAULT_COMPACTION_L0_FIRST,
     622          924 :             compaction_l0_semaphore: DEFAULT_COMPACTION_L0_SEMAPHORE,
     623          924 :             l0_flush_delay_threshold: None,
     624          924 :             l0_flush_stall_threshold: None,
     625          924 :             l0_flush_wait_upload: DEFAULT_L0_FLUSH_WAIT_UPLOAD,
     626          924 :             gc_horizon: DEFAULT_GC_HORIZON,
     627          924 :             gc_period: humantime::parse_duration(DEFAULT_GC_PERIOD)
     628          924 :                 .expect("cannot parse default gc period"),
     629          924 :             image_creation_threshold: DEFAULT_IMAGE_CREATION_THRESHOLD,
     630          924 :             pitr_interval: humantime::parse_duration(DEFAULT_PITR_INTERVAL)
     631          924 :                 .expect("cannot parse default PITR interval"),
     632          924 :             walreceiver_connect_timeout: humantime::parse_duration(
     633          924 :                 DEFAULT_WALRECEIVER_CONNECT_TIMEOUT,
     634          924 :             )
     635          924 :             .expect("cannot parse default walreceiver connect timeout"),
     636          924 :             lagging_wal_timeout: humantime::parse_duration(DEFAULT_WALRECEIVER_LAGGING_WAL_TIMEOUT)
     637          924 :                 .expect("cannot parse default walreceiver lagging wal timeout"),
     638          924 :             max_lsn_wal_lag: NonZeroU64::new(DEFAULT_MAX_WALRECEIVER_LSN_WAL_LAG)
     639          924 :                 .expect("cannot parse default max walreceiver Lsn wal lag"),
     640          924 :             eviction_policy: crate::models::EvictionPolicy::NoEviction,
     641          924 :             min_resident_size_override: None,
     642          924 :             evictions_low_residence_duration_metric_threshold: humantime::parse_duration(
     643          924 :                 DEFAULT_EVICTIONS_LOW_RESIDENCE_DURATION_METRIC_THRESHOLD,
     644          924 :             )
     645          924 :             .expect("cannot parse default evictions_low_residence_duration_metric_threshold"),
     646          924 :             heatmap_period: Duration::ZERO,
     647          924 :             lazy_slru_download: false,
     648          924 :             timeline_get_throttle: crate::models::ThrottleConfig::disabled(),
     649          924 :             image_layer_creation_check_threshold: DEFAULT_IMAGE_LAYER_CREATION_CHECK_THRESHOLD,
     650          924 :             image_creation_preempt_threshold: DEFAULT_IMAGE_CREATION_PREEMPT_THRESHOLD,
     651          924 :             lsn_lease_length: LsnLease::DEFAULT_LENGTH,
     652          924 :             lsn_lease_length_for_ts: LsnLease::DEFAULT_LENGTH_FOR_TS,
     653          924 :             timeline_offloading: true,
     654          924 :             wal_receiver_protocol_override: None,
     655          924 :             rel_size_v2_enabled: false,
     656          924 :             gc_compaction_enabled: DEFAULT_GC_COMPACTION_ENABLED,
     657          924 :             gc_compaction_initial_threshold_kb: DEFAULT_GC_COMPACTION_INITIAL_THRESHOLD_KB,
     658          924 :             gc_compaction_ratio_percent: DEFAULT_GC_COMPACTION_RATIO_PERCENT,
     659          924 :         }
     660          924 :     }
     661              : }
        

Generated by: LCOV version 2.1-beta