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