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 : /// Whether to offload archived timelines automatically
168 : pub timeline_offloading: bool,
169 :
170 : /// How many bytes of ephemeral layer content will we allow per kilobyte of RAM. When this
171 : /// is exceeded, we start proactively closing ephemeral layers to limit the total amount
172 : /// of ephemeral data.
173 : ///
174 : /// Setting this to zero disables limits on total ephemeral layer size.
175 : pub ephemeral_bytes_per_memory_kb: usize,
176 :
177 : pub l0_flush: crate::l0_flush::L0FlushConfig,
178 :
179 : /// Direct IO settings
180 : pub virtual_file_io_mode: virtual_file::IoMode,
181 : }
182 :
183 : /// Token for authentication to safekeepers
184 : ///
185 : /// We do not want to store this in a PageServerConf because the latter may be logged
186 : /// and/or serialized at a whim, while the token is secret. Currently this token is the
187 : /// same for accessing all tenants/timelines, but may become per-tenant/per-timeline in
188 : /// the future, more tokens and auth may arrive for storage broker, completely changing the logic.
189 : /// Hence, we resort to a global variable for now instead of passing the token from the
190 : /// startup code to the connection code through a dozen layers.
191 : pub static SAFEKEEPER_AUTH_TOKEN: OnceCell<Arc<String>> = OnceCell::new();
192 :
193 : impl PageServerConf {
194 : //
195 : // Repository paths, relative to workdir.
196 : //
197 :
198 6902 : pub fn tenants_path(&self) -> Utf8PathBuf {
199 6902 : self.workdir.join(TENANTS_SEGMENT_NAME)
200 6902 : }
201 :
202 72 : pub fn deletion_prefix(&self) -> Utf8PathBuf {
203 72 : self.workdir.join("deletion")
204 72 : }
205 :
206 0 : pub fn metadata_path(&self) -> Utf8PathBuf {
207 0 : self.workdir.join("metadata.json")
208 0 : }
209 :
210 28 : pub fn deletion_list_path(&self, sequence: u64) -> Utf8PathBuf {
211 : // Encode a version in the filename, so that if we ever switch away from JSON we can
212 : // increment this.
213 : const VERSION: u8 = 1;
214 :
215 28 : self.deletion_prefix()
216 28 : .join(format!("{sequence:016x}-{VERSION:02x}.list"))
217 28 : }
218 :
219 24 : pub fn deletion_header_path(&self) -> Utf8PathBuf {
220 : // Encode a version in the filename, so that if we ever switch away from JSON we can
221 : // increment this.
222 : const VERSION: u8 = 1;
223 :
224 24 : self.deletion_prefix().join(format!("header-{VERSION:02x}"))
225 24 : }
226 :
227 6876 : pub fn tenant_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
228 6876 : self.tenants_path().join(tenant_shard_id.to_string())
229 6876 : }
230 :
231 : /// Points to a place in pageserver's local directory,
232 : /// where certain tenant's LocationConf be stored.
233 0 : pub(crate) fn tenant_location_config_path(
234 0 : &self,
235 0 : tenant_shard_id: &TenantShardId,
236 0 : ) -> Utf8PathBuf {
237 0 : self.tenant_path(tenant_shard_id)
238 0 : .join(TENANT_LOCATION_CONFIG_NAME)
239 0 : }
240 :
241 0 : pub(crate) fn tenant_heatmap_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
242 0 : self.tenant_path(tenant_shard_id)
243 0 : .join(TENANT_HEATMAP_BASENAME)
244 0 : }
245 :
246 6686 : pub fn timelines_path(&self, tenant_shard_id: &TenantShardId) -> Utf8PathBuf {
247 6686 : self.tenant_path(tenant_shard_id)
248 6686 : .join(TIMELINES_SEGMENT_NAME)
249 6686 : }
250 :
251 6310 : pub fn timeline_path(
252 6310 : &self,
253 6310 : tenant_shard_id: &TenantShardId,
254 6310 : timeline_id: &TimelineId,
255 6310 : ) -> Utf8PathBuf {
256 6310 : self.timelines_path(tenant_shard_id)
257 6310 : .join(timeline_id.to_string())
258 6310 : }
259 :
260 : /// Turns storage remote path of a file into its local path.
261 0 : pub fn local_path(&self, remote_path: &RemotePath) -> Utf8PathBuf {
262 0 : remote_path.with_base(&self.workdir)
263 0 : }
264 :
265 : //
266 : // Postgres distribution paths
267 : //
268 20 : pub fn pg_distrib_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
269 20 : let path = self.pg_distrib_dir.clone();
270 20 :
271 20 : #[allow(clippy::manual_range_patterns)]
272 20 : match pg_version {
273 20 : 14 | 15 | 16 | 17 => Ok(path.join(format!("v{pg_version}"))),
274 0 : _ => bail!("Unsupported postgres version: {}", pg_version),
275 : }
276 20 : }
277 :
278 10 : pub fn pg_bin_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
279 10 : Ok(self.pg_distrib_dir(pg_version)?.join("bin"))
280 10 : }
281 10 : pub fn pg_lib_dir(&self, pg_version: u32) -> anyhow::Result<Utf8PathBuf> {
282 10 : Ok(self.pg_distrib_dir(pg_version)?.join("lib"))
283 10 : }
284 :
285 : /// Parse a configuration file (pageserver.toml) into a PageServerConf struct,
286 : /// validating the input and failing on errors.
287 : ///
288 : /// This leaves any options not present in the file in the built-in defaults.
289 204 : pub fn parse_and_validate(
290 204 : id: NodeId,
291 204 : config_toml: pageserver_api::config::ConfigToml,
292 204 : workdir: &Utf8Path,
293 204 : ) -> anyhow::Result<Self> {
294 204 : let pageserver_api::config::ConfigToml {
295 204 : listen_pg_addr,
296 204 : listen_http_addr,
297 204 : availability_zone,
298 204 : wait_lsn_timeout,
299 204 : wal_redo_timeout,
300 204 : superuser,
301 204 : page_cache_size,
302 204 : max_file_descriptors,
303 204 : pg_distrib_dir,
304 204 : http_auth_type,
305 204 : pg_auth_type,
306 204 : auth_validation_public_key_path,
307 204 : remote_storage,
308 204 : broker_endpoint,
309 204 : broker_keepalive_interval,
310 204 : log_format,
311 204 : metric_collection_interval,
312 204 : metric_collection_endpoint,
313 204 : metric_collection_bucket,
314 204 : synthetic_size_calculation_interval,
315 204 : disk_usage_based_eviction,
316 204 : test_remote_failures,
317 204 : ondemand_download_behavior_treat_error_as_warn,
318 204 : background_task_maximum_delay,
319 204 : control_plane_api,
320 204 : control_plane_api_token,
321 204 : control_plane_emergency_mode,
322 204 : heatmap_upload_concurrency,
323 204 : secondary_download_concurrency,
324 204 : ingest_batch_size,
325 204 : max_vectored_read_bytes,
326 204 : image_compression,
327 204 : timeline_offloading,
328 204 : ephemeral_bytes_per_memory_kb,
329 204 : l0_flush,
330 204 : virtual_file_io_mode,
331 204 : concurrent_tenant_warmup,
332 204 : concurrent_tenant_size_logical_size_queries,
333 204 : virtual_file_io_engine,
334 204 : tenant_config,
335 204 : } = config_toml;
336 :
337 204 : let mut conf = PageServerConf {
338 : // ------------------------------------------------------------
339 : // fields that are already fully validated by the ConfigToml Deserialize impl
340 : // ------------------------------------------------------------
341 204 : listen_pg_addr,
342 204 : listen_http_addr,
343 204 : availability_zone,
344 204 : wait_lsn_timeout,
345 204 : wal_redo_timeout,
346 204 : superuser,
347 204 : page_cache_size,
348 204 : max_file_descriptors,
349 204 : http_auth_type,
350 204 : pg_auth_type,
351 204 : auth_validation_public_key_path,
352 204 : remote_storage_config: remote_storage,
353 204 : broker_endpoint,
354 204 : broker_keepalive_interval,
355 204 : log_format,
356 204 : metric_collection_interval,
357 204 : metric_collection_endpoint,
358 204 : metric_collection_bucket,
359 204 : synthetic_size_calculation_interval,
360 204 : disk_usage_based_eviction,
361 204 : test_remote_failures,
362 204 : ondemand_download_behavior_treat_error_as_warn,
363 204 : background_task_maximum_delay,
364 204 : control_plane_api,
365 204 : control_plane_emergency_mode,
366 204 : heatmap_upload_concurrency,
367 204 : secondary_download_concurrency,
368 204 : ingest_batch_size,
369 204 : max_vectored_read_bytes,
370 204 : image_compression,
371 204 : timeline_offloading,
372 204 : ephemeral_bytes_per_memory_kb,
373 204 :
374 204 : // ------------------------------------------------------------
375 204 : // fields that require additional validation or custom handling
376 204 : // ------------------------------------------------------------
377 204 : workdir: workdir.to_owned(),
378 204 : pg_distrib_dir: pg_distrib_dir.unwrap_or_else(|| {
379 2 : std::env::current_dir()
380 2 : .expect("current_dir() failed")
381 2 : .try_into()
382 2 : .expect("current_dir() is not a valid Utf8Path")
383 204 : }),
384 204 : control_plane_api_token: control_plane_api_token.map(SecretString::from),
385 204 : id,
386 204 : default_tenant_conf: tenant_config,
387 204 : concurrent_tenant_warmup: ConfigurableSemaphore::new(concurrent_tenant_warmup),
388 204 : concurrent_tenant_size_logical_size_queries: ConfigurableSemaphore::new(
389 204 : concurrent_tenant_size_logical_size_queries,
390 204 : ),
391 204 : eviction_task_immitated_concurrent_logical_size_queries: ConfigurableSemaphore::new(
392 204 : // re-use `concurrent_tenant_size_logical_size_queries`
393 204 : concurrent_tenant_size_logical_size_queries,
394 204 : ),
395 204 : virtual_file_io_engine: match virtual_file_io_engine {
396 0 : Some(v) => v,
397 204 : None => match crate::virtual_file::io_engine_feature_test()
398 204 : .context("auto-detect virtual_file_io_engine")?
399 : {
400 204 : 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 204 : l0_flush: l0_flush
409 204 : .map(crate::l0_flush::L0FlushConfig::from)
410 204 : .unwrap_or_default(),
411 204 : virtual_file_io_mode: virtual_file_io_mode.unwrap_or(virtual_file::IoMode::preferred()),
412 204 : };
413 204 :
414 204 : // ------------------------------------------------------------
415 204 : // custom validation code that covers more than one field in isolation
416 204 : // ------------------------------------------------------------
417 204 :
418 204 : if conf.http_auth_type == AuthType::NeonJWT || conf.pg_auth_type == AuthType::NeonJWT {
419 0 : let auth_validation_public_key_path = conf
420 0 : .auth_validation_public_key_path
421 0 : .get_or_insert_with(|| workdir.join("auth_public_key.pem"));
422 0 : ensure!(
423 0 : auth_validation_public_key_path.exists(),
424 0 : format!(
425 0 : "Can't find auth_validation_public_key at '{auth_validation_public_key_path}'",
426 0 : )
427 : );
428 204 : }
429 :
430 204 : IndexEntry::validate_checkpoint_distance(conf.default_tenant_conf.checkpoint_distance)
431 204 : .map_err(anyhow::Error::msg)
432 204 : .with_context(|| {
433 0 : format!(
434 0 : "effective checkpoint distance is unsupported: {}",
435 0 : conf.default_tenant_conf.checkpoint_distance
436 0 : )
437 204 : })?;
438 :
439 204 : Ok(conf)
440 204 : }
441 :
442 : #[cfg(test)]
443 204 : pub fn test_repo_dir(test_name: &str) -> Utf8PathBuf {
444 204 : let test_output_dir = std::env::var("TEST_OUTPUT").unwrap_or("../tmp_check".into());
445 204 : Utf8PathBuf::from(format!("{test_output_dir}/test_{test_name}"))
446 204 : }
447 :
448 202 : pub fn dummy_conf(repo_dir: Utf8PathBuf) -> Self {
449 202 : let pg_distrib_dir = Utf8PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../pg_install");
450 202 :
451 202 : let config_toml = pageserver_api::config::ConfigToml {
452 202 : wait_lsn_timeout: Duration::from_secs(60),
453 202 : wal_redo_timeout: Duration::from_secs(60),
454 202 : pg_distrib_dir: Some(pg_distrib_dir),
455 202 : metric_collection_interval: Duration::from_secs(60),
456 202 : synthetic_size_calculation_interval: Duration::from_secs(60),
457 202 : background_task_maximum_delay: Duration::ZERO,
458 202 : ..Default::default()
459 202 : };
460 202 : PageServerConf::parse_and_validate(NodeId(0), config_toml, &repo_dir).unwrap()
461 202 : }
462 : }
463 :
464 0 : #[derive(serde::Deserialize, serde::Serialize)]
465 : #[serde(deny_unknown_fields)]
466 : pub struct PageserverIdentity {
467 : pub id: NodeId,
468 : }
469 :
470 : /// Configurable semaphore permits setting.
471 : ///
472 : /// Does not allow semaphore permits to be zero, because at runtime initially zero permits and empty
473 : /// semaphore cannot be distinguished, leading any feature using these to await forever (or until
474 : /// new permits are added).
475 : #[derive(Debug, Clone)]
476 : pub struct ConfigurableSemaphore {
477 : initial_permits: NonZeroUsize,
478 : inner: std::sync::Arc<tokio::sync::Semaphore>,
479 : }
480 :
481 : impl ConfigurableSemaphore {
482 : /// Initializse using a non-zero amount of permits.
483 : ///
484 : /// Require a non-zero initial permits, because using permits == 0 is a crude way to disable a
485 : /// feature such as [`Tenant::gather_size_inputs`]. Otherwise any semaphore using future will
486 : /// behave like [`futures::future::pending`], just waiting until new permits are added.
487 : ///
488 : /// [`Tenant::gather_size_inputs`]: crate::tenant::Tenant::gather_size_inputs
489 612 : pub fn new(initial_permits: NonZeroUsize) -> Self {
490 612 : ConfigurableSemaphore {
491 612 : initial_permits,
492 612 : inner: std::sync::Arc::new(tokio::sync::Semaphore::new(initial_permits.get())),
493 612 : }
494 612 : }
495 :
496 : /// Returns the configured amount of permits.
497 0 : pub fn initial_permits(&self) -> NonZeroUsize {
498 0 : self.initial_permits
499 0 : }
500 : }
501 :
502 : impl PartialEq for ConfigurableSemaphore {
503 0 : fn eq(&self, other: &Self) -> bool {
504 0 : // the number of permits can be increased at runtime, so we cannot really fulfill the
505 0 : // PartialEq value equality otherwise
506 0 : self.initial_permits == other.initial_permits
507 0 : }
508 : }
509 :
510 : impl Eq for ConfigurableSemaphore {}
511 :
512 : impl ConfigurableSemaphore {
513 0 : pub fn inner(&self) -> &std::sync::Arc<tokio::sync::Semaphore> {
514 0 : &self.inner
515 0 : }
516 : }
517 :
518 : #[cfg(test)]
519 : mod tests {
520 :
521 : use camino::Utf8PathBuf;
522 : use utils::id::NodeId;
523 :
524 : use super::PageServerConf;
525 :
526 : #[test]
527 2 : fn test_empty_config_toml_is_valid() {
528 2 : // we use Default impl of everything in this situation
529 2 : let input = r#"
530 2 : "#;
531 2 : let config_toml = toml_edit::de::from_str::<pageserver_api::config::ConfigToml>(input)
532 2 : .expect("empty config is valid");
533 2 : let workdir = Utf8PathBuf::from("/nonexistent");
534 2 : PageServerConf::parse_and_validate(NodeId(0), config_toml, &workdir)
535 2 : .expect("parse_and_validate");
536 2 : }
537 :
538 : /// If there's a typo in the pageserver config, we'd rather catch that typo
539 : /// and fail pageserver startup than silently ignoring the typo, leaving whoever
540 : /// made it in the believe that their config change is effective.
541 : ///
542 : /// The default in serde is to allow unknown fields, so, we rely
543 : /// on developer+review discipline to add `deny_unknown_fields` when adding
544 : /// new structs to the config, and these tests here as a regression test.
545 : ///
546 : /// The alternative to all of this would be to allow unknown fields in the config.
547 : /// To catch them, we could have a config check tool or mgmt API endpoint that
548 : /// compares the effective config with the TOML on disk and makes sure that
549 : /// the on-disk TOML is a strict subset of the effective config.
550 : mod unknown_fields_handling {
551 : macro_rules! test {
552 : ($short_name:ident, $input:expr) => {
553 : #[test]
554 10 : fn $short_name() {
555 10 : let input = $input;
556 10 : let err = toml_edit::de::from_str::<pageserver_api::config::ConfigToml>(&input)
557 10 : .expect_err("some_invalid_field is an invalid field");
558 10 : dbg!(&err);
559 10 : assert!(err.to_string().contains("some_invalid_field"));
560 10 : }
561 : };
562 : }
563 : use indoc::indoc;
564 :
565 : test!(
566 : toplevel,
567 : indoc! {r#"
568 : some_invalid_field = 23
569 : "#}
570 : );
571 :
572 : test!(
573 : toplevel_nested,
574 : indoc! {r#"
575 : [some_invalid_field]
576 : foo = 23
577 : "#}
578 : );
579 :
580 : test!(
581 : disk_usage_based_eviction,
582 : indoc! {r#"
583 : [disk_usage_based_eviction]
584 : some_invalid_field = 23
585 : "#}
586 : );
587 :
588 : test!(
589 : tenant_config,
590 : indoc! {r#"
591 : [tenant_config]
592 : some_invalid_field = 23
593 : "#}
594 : );
595 :
596 : test!(
597 : l0_flush,
598 : indoc! {r#"
599 : [l0_flush]
600 : mode = "direct"
601 : some_invalid_field = 23
602 : "#}
603 : );
604 :
605 : // TODO: fix this => https://github.com/neondatabase/neon/issues/8915
606 : // test!(
607 : // remote_storage_config,
608 : // indoc! {r#"
609 : // [remote_storage_config]
610 : // local_path = "/nonexistent"
611 : // some_invalid_field = 23
612 : // "#}
613 : // );
614 : }
615 : }
|