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