1#![allow(missing_docs)]
11
12use std::sync::Arc;
22use std::sync::atomic::AtomicBool;
23use std::time::{Duration, SystemTime, UNIX_EPOCH};
24
25use mz_build_info::BuildInfo;
26use mz_dyncfg::{Config, ConfigDefault, ConfigSet, ConfigUpdates, ParameterScope};
27use mz_ore::instrument;
28use mz_ore::now::NowFn;
29use mz_persist::cfg::BlobKnobs;
30use mz_persist::retry::Retry;
31use mz_persist::s3::{BLOB_HTTP_POOL_MAX_IN_FLIGHT_PER_CLIENT, BlobHttpPool};
32use mz_postgres_client::PostgresClientKnobs;
33use proptest_derive::Arbitrary;
34use semver::Version;
35use serde::{Deserialize, Serialize};
36use tokio::sync::watch;
37
38use crate::async_runtime;
39use crate::internal::machine::{
40 NEXT_LISTEN_BATCH_RETRYER_CLAMP, NEXT_LISTEN_BATCH_RETRYER_INITIAL_BACKOFF,
41 NEXT_LISTEN_BATCH_RETRYER_MULTIPLIER,
42};
43use crate::internal::state::ROLLUP_THRESHOLD;
44use crate::operators::STORAGE_SOURCE_DECODE_FUEL;
45use crate::read::READER_LEASE_DURATION;
46
47const SELF_MANAGED_VERSIONS: &[Version; 2] = &[
49 Version::new(0, 130, 0),
51 Version::new(0, 147, 0),
53];
54
55#[derive(Debug, Clone)]
107pub struct PersistConfig {
108 pub build_version: Version,
110 pub hostname: String,
113 pub is_cc_active: bool,
115 pub announce_memory_limit: Option<usize>,
117 pub now: NowFn,
119 pub configs: Arc<ConfigSet>,
124 configs_synced_once: Arc<watch::Sender<bool>>,
127 pub compaction_enabled: bool,
129 pub compaction_process_requests: Arc<AtomicBool>,
131 pub compaction_concurrency_limit: usize,
134 pub compaction_queue_size: usize,
137 pub compaction_yield_after_n_updates: usize,
140 pub writer_lease_duration: Duration,
143 pub critical_downgrade_interval: Duration,
145 pub isolated_runtime_worker_threads: usize,
148}
149
150impl std::ops::Deref for PersistConfig {
152 type Target = ConfigSet;
153 fn deref(&self) -> &Self::Target {
154 &self.configs
155 }
156}
157
158impl PersistConfig {
159 pub fn new_default_configs(build_info: &BuildInfo, now: NowFn) -> Self {
162 Self::new(build_info, now, all_dyncfgs(ConfigSet::default()))
163 }
164
165 pub fn new(build_info: &BuildInfo, now: NowFn, configs: ConfigSet) -> Self {
168 let compaction_disabled = mz_ore::env::is_var_truthy("MZ_PERSIST_COMPACTION_DISABLED");
170
171 let (configs_synced_once, _) = watch::channel(false);
173
174 Self {
175 build_version: build_info.semver_version(),
176 is_cc_active: false,
177 announce_memory_limit: None,
178 now,
179 configs: Arc::new(configs),
180 configs_synced_once: Arc::new(configs_synced_once),
181 compaction_enabled: !compaction_disabled,
182 compaction_process_requests: Arc::new(AtomicBool::new(true)),
183 compaction_concurrency_limit: 5,
184 compaction_queue_size: 20,
185 compaction_yield_after_n_updates: 100_000,
186 writer_lease_duration: 60 * Duration::from_secs(60),
187 critical_downgrade_interval: Duration::from_secs(30),
188 isolated_runtime_worker_threads: num_cpus::get(),
189 hostname: {
194 use std::fmt::Write;
195 let mut name = std::env::var("HOSTNAME").unwrap_or_else(|_| "unknown".to_owned());
196 write!(&mut name, " {}", build_info.version)
197 .expect("writing to string should not fail");
198 name
199 },
200 }
201 }
202
203 pub(crate) fn set_config<T: ConfigDefault>(&self, cfg: &Config<T>, val: T) {
204 let mut updates = ConfigUpdates::default();
205 updates.add(cfg, val);
206 updates.apply(self)
207 }
208
209 pub fn apply_from(&self, updates: &ConfigUpdates) {
215 updates.apply(&self.configs);
216 self.configs_synced_once.send_replace(true);
217 }
218
219 #[instrument(level = "info")]
228 pub async fn configs_synced_once(&self) {
229 self.configs_synced_once
230 .subscribe()
231 .wait_for(|synced| *synced)
232 .await
233 .expect("we have a borrow on sender so it cannot drop");
234 }
235
236 pub fn storage_source_decode_fuel(&self) -> usize {
239 STORAGE_SOURCE_DECODE_FUEL.get(self)
240 }
241
242 pub fn set_reader_lease_duration(&self, val: Duration) {
244 self.set_config(&READER_LEASE_DURATION, val);
245 }
246
247 pub fn set_rollup_threshold(&self, val: usize) {
249 self.set_config(&ROLLUP_THRESHOLD, val);
250 }
251
252 pub fn set_next_listen_batch_retryer(&self, val: RetryParameters) {
255 self.set_config(
256 &NEXT_LISTEN_BATCH_RETRYER_INITIAL_BACKOFF,
257 val.initial_backoff,
258 );
259 self.set_config(&NEXT_LISTEN_BATCH_RETRYER_MULTIPLIER, val.multiplier);
260 self.set_config(&NEXT_LISTEN_BATCH_RETRYER_CLAMP, val.clamp);
261 }
262
263 pub fn disable_compaction(&self) {
264 tracing::info!("Disabling Persist Compaction");
265 self.compaction_process_requests
266 .store(false, std::sync::atomic::Ordering::Relaxed);
267 }
268
269 pub fn enable_compaction(&self) {
270 tracing::info!("Enabling Persist Compaction");
271 self.compaction_process_requests
272 .store(true, std::sync::atomic::Ordering::Relaxed);
273 }
274
275 pub fn new_for_tests() -> Self {
277 use mz_build_info::DUMMY_BUILD_INFO;
278 use mz_ore::now::SYSTEM_TIME;
279
280 let mut cfg = Self::new_default_configs(&DUMMY_BUILD_INFO, SYSTEM_TIME.clone());
281 cfg.hostname = "tests".into();
282 cfg.isolated_runtime_worker_threads = async_runtime::TEST_THREADS;
283 cfg
284 }
285}
286
287#[allow(non_upper_case_globals)]
288pub(crate) const MiB: usize = 1024 * 1024;
289
290pub fn all_dyncfgs(configs: ConfigSet) -> ConfigSet {
305 mz_persist::cfg::all_dyn_configs(configs)
306 .add(&crate::batch::BATCH_DELETE_ENABLED)
307 .add(&crate::batch::BLOB_TARGET_SIZE)
308 .add(&crate::batch::INLINE_WRITES_TOTAL_MAX_BYTES)
309 .add(&crate::batch::INLINE_WRITES_SINGLE_MAX_BYTES)
310 .add(&crate::batch::ENCODING_ENABLE_DICTIONARY)
311 .add(&crate::batch::ENCODING_COMPRESSION_FORMAT)
312 .add(&crate::batch::STRUCTURED_KEY_LOWER_LEN)
313 .add(&crate::batch::MAX_RUN_LEN)
314 .add(&crate::batch::MAX_RUNS)
315 .add(&BLOB_OPERATION_TIMEOUT)
316 .add(&BLOB_OPERATION_ATTEMPT_TIMEOUT)
317 .add(&BLOB_CONNECT_TIMEOUT)
318 .add(&BLOB_READ_TIMEOUT)
319 .add(&SHARD_METRICS)
320 .add(&PER_SHARD_METRICS_ENABLE_REGEX)
321 .add(&SHARD_INFO_METRIC)
322 .add(&crate::cfg::CONSENSUS_CONNECTION_POOL_MAX_SIZE)
323 .add(&crate::cfg::CONSENSUS_CONNECTION_POOL_MAX_WAIT)
324 .add(&crate::cfg::CONSENSUS_CONNECTION_POOL_TTL_STAGGER)
325 .add(&crate::cfg::CONSENSUS_CONNECTION_POOL_TTL)
326 .add(&crate::cfg::CRDB_CONNECT_TIMEOUT)
327 .add(&crate::cfg::CRDB_TCP_USER_TIMEOUT)
328 .add(&crate::cfg::CRDB_KEEPALIVES_IDLE)
329 .add(&crate::cfg::CRDB_KEEPALIVES_INTERVAL)
330 .add(&crate::cfg::CRDB_KEEPALIVES_RETRIES)
331 .add(&crate::cfg::USE_CRITICAL_SINCE_TXN)
332 .add(&crate::cfg::USE_CRITICAL_SINCE_CATALOG)
333 .add(&crate::cfg::USE_CRITICAL_SINCE_SOURCE)
334 .add(&crate::cfg::USE_CRITICAL_SINCE_SNAPSHOT)
335 .add(&crate::cfg::SOURCE_HYDRATION_FRONTIER_COALESCE_BYTES)
336 .add(&crate::cfg::SOURCE_FETCH_CONCURRENCY)
337 .add(&BATCH_BUILDER_MAX_OUTSTANDING_PARTS)
338 .add(&COMPACTION_HEURISTIC_MIN_INPUTS)
339 .add(&COMPACTION_HEURISTIC_MIN_PARTS)
340 .add(&COMPACTION_HEURISTIC_MIN_UPDATES)
341 .add(&COMPACTION_MEMORY_BOUND_BYTES)
342 .add(&GC_BLOB_DELETE_CONCURRENCY_LIMIT)
343 .add(&STATE_VERSIONS_RECENT_LIVE_DIFFS_LIMIT)
344 .add(&USAGE_STATE_FETCH_CONCURRENCY_LIMIT)
345 .add(&crate::cache::STATE_UPDATE_LEASE_TIMEOUT)
346 .add(&crate::cli::admin::CATALOG_FORCE_COMPACTION_FUEL)
347 .add(&crate::cli::admin::CATALOG_FORCE_COMPACTION_WAIT)
348 .add(&crate::cli::admin::EXPRESSION_CACHE_FORCE_COMPACTION_FUEL)
349 .add(&crate::cli::admin::EXPRESSION_CACHE_FORCE_COMPACTION_WAIT)
350 .add(&crate::fetch::FETCH_SEMAPHORE_COST_ADJUSTMENT)
351 .add(&crate::fetch::FETCH_SEMAPHORE_PERMIT_ADJUSTMENT)
352 .add(&crate::fetch::VALIDATE_PART_BOUNDS_ON_READ)
353 .add(&crate::fetch::OPTIMIZE_IGNORED_DATA_FETCH)
354 .add(&crate::internal::cache::BLOB_CACHE_MEM_LIMIT_BYTES)
355 .add(&crate::internal::cache::BLOB_CACHE_SCALE_WITH_THREADS)
356 .add(&crate::internal::cache::BLOB_CACHE_SCALE_FACTOR_BYTES)
357 .add(&crate::internal::compact::COMPACTION_MINIMUM_TIMEOUT)
358 .add(&crate::internal::compact::COMPACTION_CHECK_PROCESS_FLAG)
359 .add(&crate::internal::machine::CLAIM_UNCLAIMED_COMPACTIONS)
360 .add(&crate::internal::machine::CLAIM_COMPACTION_PERCENT)
361 .add(&crate::internal::machine::CLAIM_COMPACTION_MIN_VERSION)
362 .add(&crate::internal::machine::NEXT_LISTEN_BATCH_RETRYER_CLAMP)
363 .add(&crate::internal::machine::NEXT_LISTEN_BATCH_RETRYER_FIXED_SLEEP)
364 .add(&crate::internal::machine::NEXT_LISTEN_BATCH_RETRYER_INITIAL_BACKOFF)
365 .add(&crate::internal::machine::NEXT_LISTEN_BATCH_RETRYER_MULTIPLIER)
366 .add(&crate::internal::state::ROLLUP_THRESHOLD)
367 .add(&crate::internal::state::ROLLUP_USE_ACTIVE_ROLLUP)
368 .add(&crate::internal::state::GC_FALLBACK_THRESHOLD_MS)
369 .add(&crate::internal::state::GC_USE_ACTIVE_GC)
370 .add(&crate::internal::state::GC_MIN_VERSIONS)
371 .add(&crate::internal::state::GC_MAX_VERSIONS)
372 .add(&crate::internal::state::ROLLUP_FALLBACK_THRESHOLD_MS)
373 .add(&crate::internal::state::ENABLE_INCREMENTAL_COMPACTION)
374 .add(&crate::operators::STORAGE_SOURCE_DECODE_FUEL)
375 .add(&crate::read::READER_LEASE_DURATION)
376 .add(&crate::rpc::PUBSUB_CLIENT_ENABLED)
377 .add(&crate::rpc::PUBSUB_PUSH_DIFF_ENABLED)
378 .add(&crate::rpc::PUBSUB_SAME_PROCESS_DELEGATE_ENABLED)
379 .add(&crate::rpc::PUBSUB_CONNECT_ATTEMPT_TIMEOUT)
380 .add(&crate::rpc::PUBSUB_REQUEST_TIMEOUT)
381 .add(&crate::rpc::PUBSUB_CONNECT_MAX_BACKOFF)
382 .add(&crate::rpc::PUBSUB_CLIENT_SENDER_CHANNEL_SIZE)
383 .add(&crate::rpc::PUBSUB_CLIENT_RECEIVER_CHANNEL_SIZE)
384 .add(&crate::rpc::PUBSUB_SERVER_CONNECTION_CHANNEL_SIZE)
385 .add(&crate::rpc::PUBSUB_STATE_CACHE_SHARD_REF_CHANNEL_SIZE)
386 .add(&crate::rpc::PUBSUB_RECONNECT_BACKOFF)
387 .add(&crate::stats::STATS_AUDIT_PERCENT)
388 .add(&crate::stats::STATS_AUDIT_PANIC)
389 .add(&crate::stats::STATS_BUDGET_BYTES)
390 .add(&crate::stats::STATS_COLLECTION_ENABLED)
391 .add(&crate::stats::STATS_FILTER_ENABLED)
392 .add(&crate::stats::STATS_UNTRIMMABLE_COLUMNS_EQUALS)
393 .add(&crate::stats::STATS_UNTRIMMABLE_COLUMNS_PREFIX)
394 .add(&crate::stats::STATS_UNTRIMMABLE_COLUMNS_SUFFIX)
395 .add(&crate::fetch::PART_DECODE_FORMAT)
396 .add(&crate::fetch::PART_DECODE_BATCH_ROWS)
397 .add(&crate::write::COMBINE_INLINE_WRITES)
398 .add(&crate::write::VALIDATE_PART_BOUNDS_ON_WRITE)
399}
400
401impl PersistConfig {
402 pub(crate) const DEFAULT_FALLBACK_ROLLUP_THRESHOLD_MULTIPLIER: usize = 3;
403
404 pub fn set_state_versions_recent_live_diffs_limit(&self, val: usize) {
405 self.set_config(&STATE_VERSIONS_RECENT_LIVE_DIFFS_LIMIT, val);
406 }
407}
408
409pub const CONSENSUS_CONNECTION_POOL_MAX_SIZE: Config<usize> = Config::new(
413 "persist_consensus_connection_pool_max_size",
414 50,
415 "The maximum size the connection pool to Postgres/CRDB will grow to.",
416 ParameterScope::Environment,
417);
418
419const CONSENSUS_CONNECTION_POOL_MAX_WAIT: Config<Duration> = Config::new(
424 "persist_consensus_connection_pool_max_wait",
425 Duration::from_secs(60),
426 "The amount of time we'll wait for a connection to become available.",
427 ParameterScope::Environment,
428);
429
430const CONSENSUS_CONNECTION_POOL_TTL: Config<Duration> = Config::new(
434 "persist_consensus_connection_pool_ttl",
435 Duration::from_secs(300),
436 "\
437 The minimum TTL of a Consensus connection to Postgres/CRDB before it is \
438 proactively terminated",
439 ParameterScope::Environment,
440);
441
442const CONSENSUS_CONNECTION_POOL_TTL_STAGGER: Config<Duration> = Config::new(
450 "persist_consensus_connection_pool_ttl_stagger",
451 Duration::from_secs(6),
452 "The minimum time between TTLing Consensus connections to Postgres/CRDB.",
453 ParameterScope::Environment,
454);
455
456pub const CRDB_CONNECT_TIMEOUT: Config<Duration> = Config::new(
459 "crdb_connect_timeout",
460 Duration::from_secs(5),
461 "The time to connect to CockroachDB before timing out and retrying.",
462 ParameterScope::Environment,
463);
464
465pub const CRDB_TCP_USER_TIMEOUT: Config<Duration> = Config::new(
469 "crdb_tcp_user_timeout",
470 Duration::from_secs(30),
471 "\
472 The TCP timeout for connections to CockroachDB. Specifies the amount of \
473 time that transmitted data may remain unacknowledged before the TCP \
474 connection is forcibly closed.",
475 ParameterScope::Environment,
476);
477
478pub const CRDB_KEEPALIVES_IDLE: Config<Duration> = Config::new(
479 "crdb_keepalives_idle",
480 Duration::from_secs(10),
481 "\
482 The amount of idle time before a TCP keepalive packet is sent on CRDB \
483 connections.",
484 ParameterScope::Environment,
485);
486
487pub const CRDB_KEEPALIVES_INTERVAL: Config<Duration> = Config::new(
488 "crdb_keepalives_interval",
489 Duration::from_secs(5),
490 "The time interval between TCP keepalive probes on CRDB connections.",
491 ParameterScope::Environment,
492);
493
494pub const CRDB_KEEPALIVES_RETRIES: Config<u32> = Config::new(
495 "crdb_keepalives_retries",
496 5,
497 "\
498 The maximum number of TCP keepalive probes that will be sent before \
499 dropping a CRDB connection.",
500 ParameterScope::Environment,
501);
502
503pub const USE_CRITICAL_SINCE_TXN: Config<bool> = Config::new(
505 "persist_use_critical_since_txn",
506 true,
507 "Use the critical since (instead of the overall since) when initializing a subscribe.",
508 ParameterScope::Environment,
509);
510
511pub const USE_CRITICAL_SINCE_CATALOG: Config<bool> = Config::new(
513 "persist_use_critical_since_catalog",
514 false,
515 "Use the critical since (instead of the overall since) for the Persist-backed catalog.",
516 ParameterScope::Environment,
517);
518
519pub const USE_CRITICAL_SINCE_SOURCE: Config<bool> = Config::new(
521 "persist_use_critical_since_source",
522 false,
523 "Use the critical since (instead of the overall since) in the Persist source.",
524 ParameterScope::Environment,
525);
526
527pub const SOURCE_HYDRATION_FRONTIER_COALESCE_BYTES: Config<usize> = Config::new(
532 "persist_source_hydration_frontier_coalesce_bytes",
533 0,
534 "While catching up to the hydration-time upper, the persist source coalesces \
535 frontier downgrades until this many encoded bytes have been emitted (0 disables).",
536 ParameterScope::Environment,
537);
538
539pub const SOURCE_FETCH_CONCURRENCY: Config<usize> = Config::new(
544 "persist_source_fetch_concurrency",
545 1,
546 "Maximum number of part fetches the persist source issues concurrently per worker \
547 (1 = serial).",
548 ParameterScope::Environment,
549);
550
551pub const USE_CRITICAL_SINCE_SNAPSHOT: Config<bool> = Config::new(
553 "persist_use_critical_since_snapshot",
554 false,
555 "Use the critical since (instead of the overall since) when taking snapshots in the controller or in fast-path peeks.",
556 ParameterScope::Environment,
557);
558
559pub const BATCH_BUILDER_MAX_OUTSTANDING_PARTS: Config<usize> = Config::new(
563 "persist_batch_builder_max_outstanding_parts",
564 2,
565 "The number of writes a batch builder can have outstanding before we slow down the writer.",
566 ParameterScope::Environment,
567);
568
569pub const COMPACTION_HEURISTIC_MIN_INPUTS: Config<usize> = Config::new(
573 "persist_compaction_heuristic_min_inputs",
574 8,
575 "Don't skip compaction if we have more than this many hollow batches as input.",
576 ParameterScope::Environment,
577);
578
579pub const COMPACTION_HEURISTIC_MIN_PARTS: Config<usize> = Config::new(
583 "persist_compaction_heuristic_min_parts",
584 8,
585 "Don't skip compaction if we have more than this many parts as input.",
586 ParameterScope::Environment,
587);
588
589pub const COMPACTION_HEURISTIC_MIN_UPDATES: Config<usize> = Config::new(
593 "persist_compaction_heuristic_min_updates",
594 1024,
595 "Don't skip compaction if we have more than this many updates as input.",
596 ParameterScope::Environment,
597);
598
599pub const COMPACTION_MEMORY_BOUND_BYTES: Config<usize> = Config::new(
604 "persist_compaction_memory_bound_bytes",
605 1024 * MiB,
606 "Attempt to limit compaction to this amount of memory.",
607 ParameterScope::Environment,
608);
609
610pub const GC_BLOB_DELETE_CONCURRENCY_LIMIT: Config<usize> = Config::new(
612 "persist_gc_blob_delete_concurrency_limit",
613 32,
614 "Limit the number of concurrent deletes GC can perform to this threshold.",
615 ParameterScope::Environment,
616);
617
618pub const STATE_VERSIONS_RECENT_LIVE_DIFFS_LIMIT: Config<usize> = Config::new(
628 "persist_state_versions_recent_live_diffs_limit",
629 30 * 128,
630 "Fetch this many diffs when fetching recent diffs.",
631 ParameterScope::Environment,
632);
633
634pub const USAGE_STATE_FETCH_CONCURRENCY_LIMIT: Config<usize> = Config::new(
636 "persist_usage_state_fetch_concurrency_limit",
637 8,
638 "Limit the concurrency in of fetching in the perioding Persist-storage-usage calculation.",
639 ParameterScope::Environment,
640);
641
642impl PostgresClientKnobs for PersistConfig {
643 fn connection_pool_max_size(&self) -> usize {
644 CONSENSUS_CONNECTION_POOL_MAX_SIZE.get(self)
645 }
646
647 fn connection_pool_max_wait(&self) -> Option<Duration> {
648 Some(CONSENSUS_CONNECTION_POOL_MAX_WAIT.get(self))
649 }
650
651 fn connection_pool_ttl(&self) -> Duration {
652 CONSENSUS_CONNECTION_POOL_TTL.get(self)
653 }
654
655 fn connection_pool_ttl_stagger(&self) -> Duration {
656 CONSENSUS_CONNECTION_POOL_TTL_STAGGER.get(self)
657 }
658
659 fn connect_timeout(&self) -> Duration {
660 CRDB_CONNECT_TIMEOUT.get(self)
661 }
662
663 fn tcp_user_timeout(&self) -> Duration {
664 CRDB_TCP_USER_TIMEOUT.get(self)
665 }
666
667 fn keepalives_idle(&self) -> Duration {
668 CRDB_KEEPALIVES_IDLE.get(self)
669 }
670
671 fn keepalives_interval(&self) -> Duration {
672 CRDB_KEEPALIVES_INTERVAL.get(self)
673 }
674
675 fn keepalives_retries(&self) -> u32 {
676 CRDB_KEEPALIVES_RETRIES.get(self)
677 }
678
679 fn statement_timeout(&self) -> Duration {
680 Duration::ZERO
682 }
683}
684
685#[derive(Copy, Clone, Debug, Eq, PartialEq, Arbitrary, Serialize, Deserialize)]
686pub struct RetryParameters {
687 pub fixed_sleep: Duration,
688 pub initial_backoff: Duration,
689 pub multiplier: u32,
690 pub clamp: Duration,
691}
692
693impl RetryParameters {
694 pub fn persist_defaults() -> Self {
695 Self {
696 fixed_sleep: Duration::ZERO,
697 initial_backoff: Duration::from_millis(4),
700 multiplier: 2,
701 clamp: Duration::from_secs(16),
704 }
705 }
706
707 pub(crate) fn into_retry(self, now: SystemTime) -> Retry {
708 let seed = now
709 .duration_since(UNIX_EPOCH)
710 .map_or(0, |x| u64::from(x.subsec_nanos()));
711 Retry {
712 fixed_sleep: self.fixed_sleep,
713 initial_backoff: self.initial_backoff,
714 multiplier: self.multiplier,
715 clamp_backoff: self.clamp,
716 seed,
717 }
718 }
719}
720
721pub(crate) const BLOB_OPERATION_TIMEOUT: Config<Duration> = Config::new(
722 "persist_blob_operation_timeout",
723 Duration::from_secs(180),
724 "Maximum time allowed for a network call, including retry attempts.",
725 ParameterScope::Environment,
726);
727
728pub(crate) const BLOB_OPERATION_ATTEMPT_TIMEOUT: Config<Duration> = Config::new(
729 "persist_blob_operation_attempt_timeout",
730 Duration::from_secs(90),
731 "Maximum time allowed for a single network call.",
732 ParameterScope::Environment,
733);
734
735pub(crate) const BLOB_CONNECT_TIMEOUT: Config<Duration> = Config::new(
736 "persist_blob_connect_timeout",
737 Duration::from_secs(7),
738 "Maximum time to wait for a socket connection to be made.",
739 ParameterScope::Environment,
740);
741
742pub(crate) const BLOB_READ_TIMEOUT: Config<Duration> = Config::new(
743 "persist_blob_read_timeout",
744 Duration::from_secs(10),
745 "Maximum time to wait to read the first byte of a response, including connection time.",
746 ParameterScope::Environment,
747);
748
749pub const SHARD_METRICS: Config<&'static str> = Config::new(
756 "persist_shard_metrics",
757 ShardMetricsExport::default().as_str(),
758 "Which persist shard metrics to export: 'per_shard' (the `mz_persist_shard_*` families \
759 with one series per shard), 'summary' (their bounded `_percentile`, `_sum`, `_topk` and \
760 per-version aggregates), 'both', or 'none'. Shard counts and process-level counters are \
761 always exported.",
762 ParameterScope::Environment,
763);
764
765#[derive(Debug, Clone, Copy, PartialEq, Eq)]
767pub enum ShardMetricsExport {
768 None,
769 Summary,
770 PerShard,
771 Both,
772}
773
774impl ShardMetricsExport {
775 pub const ALL: [Self; 4] = [Self::None, Self::Summary, Self::PerShard, Self::Both];
776
777 pub const fn default() -> Self {
780 Self::Summary
781 }
782
783 pub const fn as_str(self) -> &'static str {
784 match self {
785 Self::None => "none",
786 Self::Summary => "summary",
787 Self::PerShard => "per_shard",
788 Self::Both => "both",
789 }
790 }
791
792 pub fn parse(s: &str) -> Option<Self> {
794 Self::ALL.into_iter().find(|v| v.as_str() == s)
795 }
796
797 pub fn from_str_lossy(s: &str) -> Self {
803 Self::parse(s).unwrap_or_else(Self::default)
804 }
805
806 pub fn get(configs: &ConfigSet) -> Self {
807 Self::from_str_lossy(&SHARD_METRICS.get(configs))
808 }
809
810 pub fn per_shard(self) -> bool {
812 matches!(self, Self::PerShard | Self::Both)
813 }
814
815 pub fn summary(self) -> bool {
817 matches!(self, Self::Summary | Self::Both)
818 }
819}
820
821pub const PER_SHARD_METRICS_ENABLE_REGEX: Config<&'static str> = Config::new(
828 "persist_per_shard_metrics_enable_regex",
829 "",
830 "While `persist_shard_metrics` is 'summary' or 'none', keep exporting the per-shard series \
831 whose `shard` or `name` label matches this regex (unanchored). Empty or invalid keeps \
832 none.",
833 ParameterScope::Environment,
834);
835
836pub const SHARD_INFO_METRIC: Config<bool> = Config::new(
840 "persist_shard_info_metric",
841 false,
842 "Whether to export `mz_persist_shard_info`, which lists this process's shards by `shard` \
843 and `name` with one series each.",
844 ParameterScope::Environment,
845);
846
847impl BlobKnobs for PersistConfig {
848 fn operation_timeout(&self) -> Duration {
849 BLOB_OPERATION_TIMEOUT.get(self)
850 }
851
852 fn operation_attempt_timeout(&self) -> Duration {
853 BLOB_OPERATION_ATTEMPT_TIMEOUT.get(self)
854 }
855
856 fn connect_timeout(&self) -> Duration {
857 BLOB_CONNECT_TIMEOUT.get(self)
858 }
859
860 fn read_timeout(&self) -> Duration {
861 BLOB_READ_TIMEOUT.get(self)
862 }
863
864 fn is_cc_active(&self) -> bool {
865 self.is_cc_active
866 }
867
868 fn http_pool(&self) -> BlobHttpPool {
869 BlobHttpPool::get(self)
870 }
871
872 fn http_pool_max_in_flight_per_client(&self) -> usize {
873 BLOB_HTTP_POOL_MAX_IN_FLIGHT_PER_CLIENT.get(self)
874 }
875}
876
877pub fn code_can_read_data(code_version: &Version, data_version: &Version) -> bool {
898 code_version.cmp_precedence(data_version).is_ge()
901}
902
903pub fn code_can_write_data(code_version: &Version, data_version: &Version) -> bool {
908 if !code_can_read_data(code_version, data_version) {
909 return false;
910 }
911
912 if code_version.major == 0 && code_version.minor <= SELF_MANAGED_VERSIONS[1].minor {
913 true
916 } else if code_version.major == 0 {
917 SELF_MANAGED_VERSIONS[0]
919 .cmp_precedence(data_version)
920 .is_le()
921 } else if code_version.major <= 26 {
922 SELF_MANAGED_VERSIONS[1]
924 .cmp_precedence(data_version)
925 .is_le()
926 } else {
927 code_version.major - 1 <= data_version.major
929 }
930}