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