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