Line data Source code
1 : //! Functions for handling page server configuration options
2 : //!
3 : //! Configuration options can be set in the pageserver.toml configuration
4 : //! file, or on the command line.
5 : //! See also `settings.md` for better description on every parameter.
6 :
7 : use anyhow::{bail, ensure, Context};
8 : use pageserver_api::models::ImageCompressionAlgorithm;
9 : use pageserver_api::{
10 : config::{DiskUsageEvictionTaskConfig, MaxVectoredReadBytes},
11 : shard::TenantShardId,
12 : };
13 : use remote_storage::{RemotePath, RemoteStorageConfig};
14 : use std::env;
15 : use storage_broker::Uri;
16 : use utils::logging::SecretString;
17 : use utils::postgres_client::PostgresClientProtocol;
18 :
19 : use once_cell::sync::OnceCell;
20 : use reqwest::Url;
21 : use std::num::NonZeroUsize;
22 : use std::sync::Arc;
23 : use std::time::Duration;
24 :
25 : use camino::{Utf8Path, Utf8PathBuf};
26 : use postgres_backend::AuthType;
27 : use utils::{
28 : id::{NodeId, TimelineId},
29 : logging::LogFormat,
30 : };
31 :
32 : use crate::tenant::storage_layer::inmemory_layer::IndexEntry;
33 : use crate::tenant::{TENANTS_SEGMENT_NAME, TIMELINES_SEGMENT_NAME};
34 : use crate::virtual_file;
35 : use crate::virtual_file::io_engine;
36 : use crate::{TENANT_HEATMAP_BASENAME, TENANT_LOCATION_CONFIG_NAME};
37 :
38 : /// Global state of pageserver.
39 : ///
40 : /// It's mostly immutable configuration, but some semaphores and the
41 : /// like crept in over time and the name stuck.
42 : ///
43 : /// Instantiated by deserializing `pageserver.toml` into [`pageserver_api::config::ConfigToml`]
44 : /// and passing that to [`PageServerConf::parse_and_validate`].
45 : ///
46 : /// # Adding a New Field
47 : ///
48 : /// 1. Add the field to `pageserver_api::config::ConfigToml`.
49 : /// 2. Fix compiler errors (exhaustive destructuring will guide you).
50 : ///
51 : /// For fields that require additional validation or filling in of defaults at runtime,
52 : /// check for examples in the [`PageServerConf::parse_and_validate`] method.
53 : #[derive(Debug, Clone, PartialEq, Eq)]
54 : pub struct PageServerConf {
55 : // Identifier of that particular pageserver so e g safekeepers
56 : // can safely distinguish different pageservers
57 : pub id: NodeId,
58 :
59 : /// Example (default): 127.0.0.1:64000
60 : pub listen_pg_addr: String,
61 : /// Example (default): 127.0.0.1:9898
62 : pub listen_http_addr: String,
63 :
64 : /// Current availability zone. Used for traffic metrics.
65 : pub availability_zone: Option<String>,
66 :
67 : // Timeout when waiting for WAL receiver to catch up to an LSN given in a GetPage@LSN call.
68 : pub wait_lsn_timeout: Duration,
69 : // How long to wait for WAL redo to complete.
70 : pub wal_redo_timeout: Duration,
71 :
72 : pub superuser: String,
73 : pub locale: String,
74 :
75 : pub page_cache_size: usize,
76 : pub max_file_descriptors: usize,
77 :
78 : // Repository directory, relative to current working directory.
79 : // Normally, the page server changes the current working directory
80 : // to the repository, and 'workdir' is always '.'. But we don't do
81 : // that during unit testing, because the current directory is global
82 : // to the process but different unit tests work on different
83 : // repositories.
84 : pub workdir: Utf8PathBuf,
85 :
86 : pub pg_distrib_dir: Utf8PathBuf,
87 :
88 : // Authentication
89 : /// authentication method for the HTTP mgmt API
90 : pub http_auth_type: AuthType,
91 : /// authentication method for libpq connections from compute
92 : pub pg_auth_type: AuthType,
93 : /// Path to a file or directory containing public key(s) for verifying JWT tokens.
94 : /// Used for both mgmt and compute auth, if enabled.
95 : pub auth_validation_public_key_path: Option<Utf8PathBuf>,
96 :
97 : pub remote_storage_config: Option<RemoteStorageConfig>,
98 :
99 : pub default_tenant_conf: crate::tenant::config::TenantConf,
100 :
101 : /// Storage broker endpoints to connect to.
102 : pub broker_endpoint: Uri,
103 : pub broker_keepalive_interval: Duration,
104 :
105 : pub log_format: LogFormat,
106 :
107 : /// Number of tenants which will be concurrently loaded from remote storage proactively on startup or attach.
108 : ///
109 : /// A lower value implicitly deprioritizes loading such tenants, vs. other work in the system.
110 : pub concurrent_tenant_warmup: ConfigurableSemaphore,
111 :
112 : /// Number of concurrent [`Tenant::gather_size_inputs`](crate::tenant::Tenant::gather_size_inputs) allowed.
113 : pub concurrent_tenant_size_logical_size_queries: ConfigurableSemaphore,
114 : /// Limit of concurrent [`Tenant::gather_size_inputs`] issued by module `eviction_task`.
115 : /// The number of permits is the same as `concurrent_tenant_size_logical_size_queries`.
116 : /// See the comment in `eviction_task` for details.
117 : ///
118 : /// [`Tenant::gather_size_inputs`]: crate::tenant::Tenant::gather_size_inputs
119 : pub eviction_task_immitated_concurrent_logical_size_queries: ConfigurableSemaphore,
120 :
121 : // How often to collect metrics and send them to the metrics endpoint.
122 : pub metric_collection_interval: Duration,
123 : // How often to send unchanged cached metrics to the metrics endpoint.
124 : pub metric_collection_endpoint: Option<Url>,
125 : pub metric_collection_bucket: Option<RemoteStorageConfig>,
126 : pub synthetic_size_calculation_interval: Duration,
127 :
128 : pub disk_usage_based_eviction: Option<DiskUsageEvictionTaskConfig>,
129 :
130 : pub test_remote_failures: u64,
131 :
132 : pub ondemand_download_behavior_treat_error_as_warn: bool,
133 :
134 : /// How long will background tasks be delayed at most after initial load of tenants.
135 : ///
136 : /// Our largest initialization completions are in the range of 100-200s, so perhaps 10s works
137 : /// as we now isolate initial loading, initial logical size calculation and background tasks.
138 : /// Smaller nodes will have background tasks "not running" for this long unless every timeline
139 : /// has it's initial logical size calculated. Not running background tasks for some seconds is
140 : /// not terrible.
141 : pub background_task_maximum_delay: Duration,
142 :
143 : pub control_plane_api: Option<Url>,
144 :
145 : /// JWT token for use with the control plane API.
146 : pub control_plane_api_token: Option<SecretString>,
147 :
148 : pub import_pgdata_upcall_api: Option<Url>,
149 : pub import_pgdata_upcall_api_token: Option<SecretString>,
150 : pub import_pgdata_aws_endpoint_url: Option<Url>,
151 :
152 : /// If true, pageserver will make best-effort to operate without a control plane: only
153 : /// for use in major incidents.
154 : pub control_plane_emergency_mode: bool,
155 :
156 : /// How many heatmap uploads may be done concurrency: lower values implicitly deprioritize
157 : /// heatmap uploads vs. other remote storage operations.
158 : pub heatmap_upload_concurrency: usize,
159 :
160 : /// How many remote storage downloads may be done for secondary tenants concurrently. Implicitly
161 : /// deprioritises secondary downloads vs. remote storage operations for attached tenants.
162 : pub secondary_download_concurrency: usize,
163 :
164 : /// Maximum number of WAL records to be ingested and committed at the same time
165 : pub ingest_batch_size: u64,
166 :
167 : pub virtual_file_io_engine: virtual_file::IoEngineKind,
168 :
169 : pub max_vectored_read_bytes: MaxVectoredReadBytes,
170 :
171 : pub image_compression: ImageCompressionAlgorithm,
172 :
173 : /// Whether to offload archived timelines automatically
174 : pub timeline_offloading: bool,
175 :
176 : /// How many bytes of ephemeral layer content will we allow per kilobyte of RAM. When this
177 : /// is exceeded, we start proactively closing ephemeral layers to limit the total amount
178 : /// of ephemeral data.
179 : ///
180 : /// Setting this to zero disables limits on total ephemeral layer size.
181 : pub ephemeral_bytes_per_memory_kb: usize,
182 :
183 : pub l0_flush: crate::l0_flush::L0FlushConfig,
184 :
185 : /// Direct IO settings
186 : pub virtual_file_io_mode: virtual_file::IoMode,
187 :
188 : /// Optionally disable disk syncs (unsafe!)
189 : pub no_sync: bool,
190 :
191 : pub wal_receiver_protocol: PostgresClientProtocol,
192 :
193 : pub page_service_pipelining: pageserver_api::config::PageServicePipeliningConfig,
194 :
195 : pub get_vectored_concurrent_io: pageserver_api::config::GetVectoredConcurrentIo,
196 : }
197 :
198 : /// Token for authentication to safekeepers
199 : ///
200 : /// We do not want to store this in a PageServerConf because the latter may be logged
201 : /// and/or serialized at a whim, while the token is secret. Currently this token is the
202 : /// same for accessing all tenants/timelines, but may become per-tenant/per-timeline in
203 : /// the future, more tokens and auth may arrive for storage broker, completely changing the logic.
204 : /// Hence, we resort to a global variable for now instead of passing the token from the
205 : /// startup code to the connection code through a dozen layers.
206 : pub static SAFEKEEPER_AUTH_TOKEN: OnceCell<Arc<String>> = OnceCell::new();
207 :
208 : impl PageServerConf {
209 : //
210 : // Repository paths, relative to workdir.
211 : //
212 :
213 14900 : pub fn tenants_path(&self) -> Utf8PathBuf {
214 14900 : self.workdir.join(TENANTS_SEGMENT_NAME)
215 14900 : }
216 :
217 144 : pub fn deletion_prefix(&self) -> Utf8PathBuf {
218 144 : self.workdir.join("deletion")
219 144 : }
220 :
221 0 : pub fn metadata_path(&self) -> Utf8PathBuf {
222 0 : self.workdir.join("metadata.json")
223 0 : }
224 :
225 56 : pub fn deletion_list_path(&self, sequence: u64) -> Utf8PathBuf {
226 : // Encode a version in the filename, so that if we ever switch away from JSON we can
227 : // increment this.
228 : const VERSION: u8 = 1;
229 :
230 56 : self.deletion_prefix()
231 56 : .join(format!("{sequence:016x}-{VERSION:02x}.list"))
232 56 : }
233 :
234 48 : pub fn deletion_header_path(&self) -> Utf8PathBuf {
235 : // Encode a version in the filename, so that if we ever switch away from JSON we can
236 : // increment this.
237 : const VERSION: u8 = 1;
238 :
239 48 : self.deletion_prefix().join(format!("header-{VERSION:02x}"))
240 48 : }
241 :
242 14796 : pub fn tenant_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
243 14796 : self.tenants_path().join(tenant_shard_id.to_string())
244 14796 : }
245 :
246 : /// Points to a place in pageserver's local directory,
247 : /// where certain tenant's LocationConf be stored.
248 0 : pub(crate) fn tenant_location_config_path(
249 0 : &self,
250 0 : tenant_shard_id: &TenantShardId,
251 0 : ) -> Utf8PathBuf {
252 0 : self.tenant_path(tenant_shard_id)
253 0 : .join(TENANT_LOCATION_CONFIG_NAME)
254 0 : }
255 :
256 0 : pub(crate) fn tenant_heatmap_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
257 0 : self.tenant_path(tenant_shard_id)
258 0 : .join(TENANT_HEATMAP_BASENAME)
259 0 : }
260 :
261 14348 : pub fn timelines_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
262 14348 : self.tenant_path(tenant_shard_id)
263 14348 : .join(TIMELINES_SEGMENT_NAME)
264 14348 : }
265 :
266 13456 : pub fn timeline_path(
267 13456 : &self,
268 13456 : tenant_shard_id: &TenantShardId,
269 13456 : timeline_id: &TimelineId,
270 13456 : ) -> Utf8PathBuf {
271 13456 : self.timelines_path(tenant_shard_id)
272 13456 : .join(timeline_id.to_string())
273 13456 : }
274 :
275 : /// Turns storage remote path of a file into its local path.
276 0 : pub fn local_path(&self, remote_path: &RemotePath) -> Utf8PathBuf {
277 0 : remote_path.with_base(&self.workdir)
278 0 : }
279 :
280 : //
281 : // Postgres distribution paths
282 : //
283 40 : pub fn pg_distrib_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
284 40 : let path = self.pg_distrib_dir.clone();
285 40 :
286 40 : #[allow(clippy::manual_range_patterns)]
287 40 : match pg_version {
288 40 : 14 | 15 | 16 | 17 => Ok(path.join(format!("v{pg_version}"))),
289 0 : _ => bail!("Unsupported postgres version: {}", pg_version),
290 : }
291 40 : }
292 :
293 20 : pub fn pg_bin_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
294 20 : Ok(self.pg_distrib_dir(pg_version)?.join("bin"))
295 20 : }
296 20 : pub fn pg_lib_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
297 20 : Ok(self.pg_distrib_dir(pg_version)?.join("lib"))
298 20 : }
299 :
300 : /// Parse a configuration file (pageserver.toml) into a PageServerConf struct,
301 : /// validating the input and failing on errors.
302 : ///
303 : /// This leaves any options not present in the file in the built-in defaults.
304 476 : pub fn parse_and_validate(
305 476 : id: NodeId,
306 476 : config_toml: pageserver_api::config::ConfigToml,
307 476 : workdir: &Utf8Path,
308 476 : ) -> anyhow::Result<Self> {
309 476 : let pageserver_api::config::ConfigToml {
310 476 : listen_pg_addr,
311 476 : listen_http_addr,
312 476 : availability_zone,
313 476 : wait_lsn_timeout,
314 476 : wal_redo_timeout,
315 476 : superuser,
316 476 : locale,
317 476 : page_cache_size,
318 476 : max_file_descriptors,
319 476 : pg_distrib_dir,
320 476 : http_auth_type,
321 476 : pg_auth_type,
322 476 : auth_validation_public_key_path,
323 476 : remote_storage,
324 476 : broker_endpoint,
325 476 : broker_keepalive_interval,
326 476 : log_format,
327 476 : metric_collection_interval,
328 476 : metric_collection_endpoint,
329 476 : metric_collection_bucket,
330 476 : synthetic_size_calculation_interval,
331 476 : disk_usage_based_eviction,
332 476 : test_remote_failures,
333 476 : ondemand_download_behavior_treat_error_as_warn,
334 476 : background_task_maximum_delay,
335 476 : control_plane_api,
336 476 : control_plane_api_token,
337 476 : control_plane_emergency_mode,
338 476 : import_pgdata_upcall_api,
339 476 : import_pgdata_upcall_api_token,
340 476 : import_pgdata_aws_endpoint_url,
341 476 : heatmap_upload_concurrency,
342 476 : secondary_download_concurrency,
343 476 : ingest_batch_size,
344 476 : max_vectored_read_bytes,
345 476 : image_compression,
346 476 : timeline_offloading,
347 476 : ephemeral_bytes_per_memory_kb,
348 476 : l0_flush,
349 476 : virtual_file_io_mode,
350 476 : concurrent_tenant_warmup,
351 476 : concurrent_tenant_size_logical_size_queries,
352 476 : virtual_file_io_engine,
353 476 : tenant_config,
354 476 : no_sync,
355 476 : wal_receiver_protocol,
356 476 : page_service_pipelining,
357 476 : get_vectored_concurrent_io,
358 476 : } = config_toml;
359 :
360 476 : let mut conf = PageServerConf {
361 : // ------------------------------------------------------------
362 : // fields that are already fully validated by the ConfigToml Deserialize impl
363 : // ------------------------------------------------------------
364 476 : listen_pg_addr,
365 476 : listen_http_addr,
366 476 : availability_zone,
367 476 : wait_lsn_timeout,
368 476 : wal_redo_timeout,
369 476 : superuser,
370 476 : locale,
371 476 : page_cache_size,
372 476 : max_file_descriptors,
373 476 : http_auth_type,
374 476 : pg_auth_type,
375 476 : auth_validation_public_key_path,
376 476 : remote_storage_config: remote_storage,
377 476 : broker_endpoint,
378 476 : broker_keepalive_interval,
379 476 : log_format,
380 476 : metric_collection_interval,
381 476 : metric_collection_endpoint,
382 476 : metric_collection_bucket,
383 476 : synthetic_size_calculation_interval,
384 476 : disk_usage_based_eviction,
385 476 : test_remote_failures,
386 476 : ondemand_download_behavior_treat_error_as_warn,
387 476 : background_task_maximum_delay,
388 476 : control_plane_api,
389 476 : control_plane_emergency_mode,
390 476 : heatmap_upload_concurrency,
391 476 : secondary_download_concurrency,
392 476 : ingest_batch_size,
393 476 : max_vectored_read_bytes,
394 476 : image_compression,
395 476 : timeline_offloading,
396 476 : ephemeral_bytes_per_memory_kb,
397 476 : import_pgdata_upcall_api,
398 476 : import_pgdata_upcall_api_token: import_pgdata_upcall_api_token.map(SecretString::from),
399 476 : import_pgdata_aws_endpoint_url,
400 476 : wal_receiver_protocol,
401 476 : page_service_pipelining,
402 476 : get_vectored_concurrent_io,
403 476 :
404 476 : // ------------------------------------------------------------
405 476 : // fields that require additional validation or custom handling
406 476 : // ------------------------------------------------------------
407 476 : workdir: workdir.to_owned(),
408 476 : pg_distrib_dir: pg_distrib_dir.unwrap_or_else(|| {
409 4 : std::env::current_dir()
410 4 : .expect("current_dir() failed")
411 4 : .try_into()
412 4 : .expect("current_dir() is not a valid Utf8Path")
413 476 : }),
414 476 : control_plane_api_token: control_plane_api_token.map(SecretString::from),
415 476 : id,
416 476 : default_tenant_conf: tenant_config,
417 476 : concurrent_tenant_warmup: ConfigurableSemaphore::new(concurrent_tenant_warmup),
418 476 : concurrent_tenant_size_logical_size_queries: ConfigurableSemaphore::new(
419 476 : concurrent_tenant_size_logical_size_queries,
420 476 : ),
421 476 : eviction_task_immitated_concurrent_logical_size_queries: ConfigurableSemaphore::new(
422 476 : // re-use `concurrent_tenant_size_logical_size_queries`
423 476 : concurrent_tenant_size_logical_size_queries,
424 476 : ),
425 476 : virtual_file_io_engine: match virtual_file_io_engine {
426 0 : Some(v) => v,
427 476 : None => match crate::virtual_file::io_engine_feature_test()
428 476 : .context("auto-detect virtual_file_io_engine")?
429 : {
430 476 : io_engine::FeatureTestResult::PlatformPreferred(v) => v, // make no noise
431 0 : io_engine::FeatureTestResult::Worse { engine, remark } => {
432 0 : // TODO: bubble this up to the caller so we can tracing::warn! it.
433 0 : eprintln!("auto-detected IO engine is not platform-preferred: engine={engine:?} remark={remark:?}");
434 0 : engine
435 : }
436 : },
437 : },
438 476 : l0_flush: l0_flush
439 476 : .map(crate::l0_flush::L0FlushConfig::from)
440 476 : .unwrap_or_default(),
441 476 : virtual_file_io_mode: virtual_file_io_mode.unwrap_or(virtual_file::IoMode::preferred()),
442 476 : no_sync: no_sync.unwrap_or(false),
443 476 : };
444 476 :
445 476 : // ------------------------------------------------------------
446 476 : // custom validation code that covers more than one field in isolation
447 476 : // ------------------------------------------------------------
448 476 :
449 476 : if conf.http_auth_type == AuthType::NeonJWT || conf.pg_auth_type == AuthType::NeonJWT {
450 0 : let auth_validation_public_key_path = conf
451 0 : .auth_validation_public_key_path
452 0 : .get_or_insert_with(|| workdir.join("auth_public_key.pem"));
453 0 : ensure!(
454 0 : auth_validation_public_key_path.exists(),
455 0 : format!(
456 0 : "Can't find auth_validation_public_key at '{auth_validation_public_key_path}'",
457 0 : )
458 : );
459 476 : }
460 :
461 476 : IndexEntry::validate_checkpoint_distance(conf.default_tenant_conf.checkpoint_distance)
462 476 : .map_err(anyhow::Error::msg)
463 476 : .with_context(|| {
464 0 : format!(
465 0 : "effective checkpoint distance is unsupported: {}",
466 0 : conf.default_tenant_conf.checkpoint_distance
467 0 : )
468 476 : })?;
469 :
470 476 : Ok(conf)
471 476 : }
472 :
473 : #[cfg(test)]
474 476 : pub fn test_repo_dir(test_name: &str) -> Utf8PathBuf {
475 476 : let test_output_dir = std::env::var("TEST_OUTPUT").unwrap_or("../tmp_check".into());
476 476 : Utf8PathBuf::from(format!("{test_output_dir}/test_{test_name}"))
477 476 : }
478 :
479 472 : pub fn dummy_conf(repo_dir: Utf8PathBuf) -> Self {
480 472 : let pg_distrib_dir = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../pg_install");
481 472 :
482 472 : let config_toml = pageserver_api::config::ConfigToml {
483 472 : wait_lsn_timeout: Duration::from_secs(60),
484 472 : wal_redo_timeout: Duration::from_secs(60),
485 472 : pg_distrib_dir: Some(pg_distrib_dir),
486 472 : metric_collection_interval: Duration::from_secs(60),
487 472 : synthetic_size_calculation_interval: Duration::from_secs(60),
488 472 : background_task_maximum_delay: Duration::ZERO,
489 472 : ..Default::default()
490 472 : };
491 472 : PageServerConf::parse_and_validate(NodeId(0), config_toml, &repo_dir).unwrap()
492 472 : }
493 : }
494 :
495 0 : #[derive(serde::Deserialize, serde::Serialize)]
496 : #[serde(deny_unknown_fields)]
497 : pub struct PageserverIdentity {
498 : pub id: NodeId,
499 : }
500 :
501 : /// Configurable semaphore permits setting.
502 : ///
503 : /// Does not allow semaphore permits to be zero, because at runtime initially zero permits and empty
504 : /// semaphore cannot be distinguished, leading any feature using these to await forever (or until
505 : /// new permits are added).
506 : #[derive(Debug, Clone)]
507 : pub struct ConfigurableSemaphore {
508 : initial_permits: NonZeroUsize,
509 : inner: std::sync::Arc<tokio::sync::Semaphore>,
510 : }
511 :
512 : impl ConfigurableSemaphore {
513 : /// Initializse using a non-zero amount of permits.
514 : ///
515 : /// Require a non-zero initial permits, because using permits == 0 is a crude way to disable a
516 : /// feature such as [`Tenant::gather_size_inputs`]. Otherwise any semaphore using future will
517 : /// behave like [`futures::future::pending`], just waiting until new permits are added.
518 : ///
519 : /// [`Tenant::gather_size_inputs`]: crate::tenant::Tenant::gather_size_inputs
520 1428 : pub fn new(initial_permits: NonZeroUsize) -> Self {
521 1428 : ConfigurableSemaphore {
522 1428 : initial_permits,
523 1428 : inner: std::sync::Arc::new(tokio::sync::Semaphore::new(initial_permits.get())),
524 1428 : }
525 1428 : }
526 :
527 : /// Returns the configured amount of permits.
528 0 : pub fn initial_permits(&self) -> NonZeroUsize {
529 0 : self.initial_permits
530 0 : }
531 : }
532 :
533 : impl PartialEq for ConfigurableSemaphore {
534 0 : fn eq(&self, other: &Self) -> bool {
535 0 : // the number of permits can be increased at runtime, so we cannot really fulfill the
536 0 : // PartialEq value equality otherwise
537 0 : self.initial_permits == other.initial_permits
538 0 : }
539 : }
540 :
541 : impl Eq for ConfigurableSemaphore {}
542 :
543 : impl ConfigurableSemaphore {
544 0 : pub fn inner(&self) -> &std::sync::Arc<tokio::sync::Semaphore> {
545 0 : &self.inner
546 0 : }
547 : }
548 :
549 : #[cfg(test)]
550 : mod tests {
551 :
552 : use camino::Utf8PathBuf;
553 : use utils::id::NodeId;
554 :
555 : use super::PageServerConf;
556 :
557 : #[test]
558 4 : fn test_empty_config_toml_is_valid() {
559 4 : // we use Default impl of everything in this situation
560 4 : let input = r#"
561 4 : "#;
562 4 : let config_toml = toml_edit::de::from_str::<pageserver_api::config::ConfigToml>(input)
563 4 : .expect("empty config is valid");
564 4 : let workdir = Utf8PathBuf::from("/nonexistent");
565 4 : PageServerConf::parse_and_validate(NodeId(0), config_toml, &workdir)
566 4 : .expect("parse_and_validate");
567 4 : }
568 :
569 : /// If there's a typo in the pageserver config, we'd rather catch that typo
570 : /// and fail pageserver startup than silently ignoring the typo, leaving whoever
571 : /// made it in the believe that their config change is effective.
572 : ///
573 : /// The default in serde is to allow unknown fields, so, we rely
574 : /// on developer+review discipline to add `deny_unknown_fields` when adding
575 : /// new structs to the config, and these tests here as a regression test.
576 : ///
577 : /// The alternative to all of this would be to allow unknown fields in the config.
578 : /// To catch them, we could have a config check tool or mgmt API endpoint that
579 : /// compares the effective config with the TOML on disk and makes sure that
580 : /// the on-disk TOML is a strict subset of the effective config.
581 : mod unknown_fields_handling {
582 : macro_rules! test {
583 : ($short_name:ident, $input:expr) => {
584 : #[test]
585 20 : fn $short_name() {
586 20 : let input = $input;
587 20 : let err = toml_edit::de::from_str::<pageserver_api::config::ConfigToml>(&input)
588 20 : .expect_err("some_invalid_field is an invalid field");
589 20 : dbg!(&err);
590 20 : assert!(err.to_string().contains("some_invalid_field"));
591 20 : }
592 : };
593 : }
594 : use indoc::indoc;
595 :
596 : test!(
597 : toplevel,
598 : indoc! {r#"
599 : some_invalid_field = 23
600 : "#}
601 : );
602 :
603 : test!(
604 : toplevel_nested,
605 : indoc! {r#"
606 : [some_invalid_field]
607 : foo = 23
608 : "#}
609 : );
610 :
611 : test!(
612 : disk_usage_based_eviction,
613 : indoc! {r#"
614 : [disk_usage_based_eviction]
615 : some_invalid_field = 23
616 : "#}
617 : );
618 :
619 : test!(
620 : tenant_config,
621 : indoc! {r#"
622 : [tenant_config]
623 : some_invalid_field = 23
624 : "#}
625 : );
626 :
627 : test!(
628 : l0_flush,
629 : indoc! {r#"
630 : [l0_flush]
631 : mode = "direct"
632 : some_invalid_field = 23
633 : "#}
634 : );
635 :
636 : // TODO: fix this => https://github.com/neondatabase/neon/issues/8915
637 : // test!(
638 : // remote_storage_config,
639 : // indoc! {r#"
640 : // [remote_storage_config]
641 : // local_path = "/nonexistent"
642 : // some_invalid_field = 23
643 : // "#}
644 : // );
645 : }
646 : }
|