1use foyer::{
16 Compression, LfuConfig, LruConfig, RecoverMode, RuntimeOptions, S3FifoConfig, Throttle,
17};
18
19use super::*;
20
21#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
23pub struct StorageConfig {
24 #[serde(default = "default::storage::share_buffers_sync_parallelism")]
26 pub share_buffers_sync_parallelism: u32,
27
28 #[serde(default = "default::storage::share_buffer_compaction_worker_threads_number")]
31 pub share_buffer_compaction_worker_threads_number: u32,
32
33 #[serde(default)]
38 pub shared_buffer_capacity_mb: Option<usize>,
39
40 #[serde(default = "default::storage::shared_buffer_flush_ratio")]
43 pub shared_buffer_flush_ratio: f32,
44
45 #[serde(default = "default::storage::shared_buffer_min_batch_flush_size_mb")]
48 pub shared_buffer_min_batch_flush_size_mb: usize,
49
50 #[serde(default = "default::storage::imm_merge_threshold")]
52 #[deprecated]
53 pub imm_merge_threshold: usize,
54
55 #[serde(default = "default::storage::write_conflict_detection_enabled")]
57 pub write_conflict_detection_enabled: bool,
58
59 #[serde(default)]
60 #[config_doc(nested)]
61 pub cache: CacheConfig,
62
63 #[serde(default)]
65 pub block_cache_capacity_mb: Option<usize>,
66
67 #[serde(default)]
69 pub meta_cache_capacity_mb: Option<usize>,
70
71 #[serde(default)]
73 pub high_priority_ratio_in_percent: Option<usize>,
74
75 #[serde(default)]
77 pub prefetch_buffer_capacity_mb: Option<usize>,
78
79 #[serde(default = "default::storage::max_cached_recent_versions_number")]
80 pub max_cached_recent_versions_number: usize,
81
82 #[serde(default = "default::storage::max_prefetch_block_number")]
84 pub max_prefetch_block_number: usize,
85
86 #[serde(default = "default::storage::disable_remote_compactor")]
87 pub disable_remote_compactor: bool,
88
89 #[serde(default = "default::storage::share_buffer_upload_concurrency")]
91 pub share_buffer_upload_concurrency: usize,
92
93 #[serde(default)]
94 pub compactor_memory_limit_mb: Option<usize>,
95
96 #[serde(default = "default::storage::compactor_max_task_multiplier")]
100 pub compactor_max_task_multiplier: f32,
101
102 #[serde(default = "default::storage::compactor_memory_available_proportion")]
105 pub compactor_memory_available_proportion: f64,
106
107 #[serde(default = "default::storage::sstable_id_remote_fetch_number")]
109 pub sstable_id_remote_fetch_number: u32,
110
111 #[serde(default = "default::storage::min_sstable_size_mb")]
112 pub min_sstable_size_mb: u32,
113
114 #[serde(default)]
115 #[config_doc(nested)]
116 pub data_file_cache: FileCacheConfig,
117
118 #[serde(default)]
119 #[config_doc(nested)]
120 pub meta_file_cache: FileCacheConfig,
121
122 #[serde(default)]
123 #[config_doc(nested)]
124 pub cache_refill: CacheRefillConfig,
125
126 #[serde(default = "default::storage::min_sst_size_for_streaming_upload")]
128 pub min_sst_size_for_streaming_upload: u64,
129
130 #[serde(default = "default::storage::max_concurrent_compaction_task_number")]
131 pub max_concurrent_compaction_task_number: u64,
132
133 #[serde(default = "default::storage::max_preload_wait_time_mill")]
134 pub max_preload_wait_time_mill: u64,
135
136 #[serde(default = "default::storage::max_version_pinning_duration_sec")]
137 pub max_version_pinning_duration_sec: u64,
138
139 #[serde(default = "default::storage::compactor_max_sst_key_count")]
140 pub compactor_max_sst_key_count: u64,
141 #[serde(default = "default::storage::compact_iter_recreate_timeout_ms")]
143 pub compact_iter_recreate_timeout_ms: u64,
144 #[serde(default = "default::storage::compactor_max_sst_size")]
145 pub compactor_max_sst_size: u64,
146 #[serde(default = "default::storage::enable_fast_compaction")]
147 pub enable_fast_compaction: bool,
148 #[serde(default = "default::storage::check_compaction_result")]
149 pub check_compaction_result: bool,
150 #[serde(default = "default::storage::max_preload_io_retry_times")]
151 pub max_preload_io_retry_times: usize,
152 #[serde(default = "default::storage::compactor_fast_max_compact_delete_ratio")]
153 pub compactor_fast_max_compact_delete_ratio: u32,
154 #[serde(default = "default::storage::compactor_fast_max_compact_task_size")]
155 pub compactor_fast_max_compact_task_size: u64,
156 #[serde(default = "default::storage::compactor_iter_max_io_retry_times")]
157 pub compactor_iter_max_io_retry_times: usize,
158
159 #[serde(default = "default::storage::table_info_statistic_history_times")]
161 #[deprecated]
162 pub table_info_statistic_history_times: usize,
163
164 #[serde(default, flatten)]
165 #[config_doc(omitted)]
166 pub unrecognized: Unrecognized<Self>,
167
168 #[serde(default = "default::storage::mem_table_spill_threshold")]
170 pub mem_table_spill_threshold: usize,
171
172 #[serde(default = "default::storage::compactor_concurrent_uploading_sst_count")]
174 pub compactor_concurrent_uploading_sst_count: Option<usize>,
175
176 #[serde(default = "default::storage::compactor_max_overlap_sst_count")]
177 pub compactor_max_overlap_sst_count: usize,
178
179 #[serde(default = "default::storage::compactor_max_preload_meta_file_count")]
183 pub compactor_max_preload_meta_file_count: usize,
184
185 #[serde(default = "default::storage::vector_file_block_size_kb")]
186 pub vector_file_block_size_kb: usize,
187
188 #[serde(default)]
193 pub object_store: ObjectStoreConfig,
194
195 #[serde(default = "default::storage::time_travel_version_cache_capacity")]
196 pub time_travel_version_cache_capacity: u64,
197
198 #[serde(default = "default::storage::iceberg_compaction_target_file_size_mb")]
200 pub iceberg_compaction_target_file_size_mb: u32,
201 #[serde(default = "default::storage::iceberg_compaction_enable_validate")]
202 pub iceberg_compaction_enable_validate: bool,
203 #[serde(default = "default::storage::iceberg_compaction_max_record_batch_rows")]
204 pub iceberg_compaction_max_record_batch_rows: usize,
205 #[serde(default = "default::storage::iceberg_compaction_min_size_per_partition_mb")]
206 pub iceberg_compaction_min_size_per_partition_mb: u32,
207 #[serde(default = "default::storage::iceberg_compaction_max_file_count_per_partition")]
208 pub iceberg_compaction_max_file_count_per_partition: u32,
209 #[serde(default = "default::storage::iceberg_compaction_write_parquet_max_row_group_rows")]
210 pub iceberg_compaction_write_parquet_max_row_group_rows: usize,
211
212 #[serde(default = "default::storage::iceberg_compaction_task_parallelism_ratio")]
214 pub iceberg_compaction_task_parallelism_ratio: f32,
215 #[serde(default = "default::storage::iceberg_compaction_enable_heuristic_output_parallelism")]
217 pub iceberg_compaction_enable_heuristic_output_parallelism: bool,
218 #[serde(default = "default::storage::iceberg_compaction_max_concurrent_closes")]
220 pub iceberg_compaction_max_concurrent_closes: usize,
221 #[serde(default = "default::storage::iceberg_compaction_enable_dynamic_size_estimation")]
223 pub iceberg_compaction_enable_dynamic_size_estimation: bool,
224 #[serde(default = "default::storage::iceberg_compaction_size_estimation_smoothing_factor")]
226 pub iceberg_compaction_size_estimation_smoothing_factor: f64,
227 #[serde(default = "default::storage::iceberg_compaction_small_file_threshold_mb")]
230 pub iceberg_compaction_small_file_threshold_mb: u32,
231 #[serde(default = "default::storage::iceberg_compaction_max_task_total_size_mb")]
233 pub iceberg_compaction_max_task_total_size_mb: u32,
234 #[serde(
238 default = "default::storage::iceberg_compaction_pending_parallelism_budget_multiplier"
239 )]
240 pub iceberg_compaction_pending_parallelism_budget_multiplier: f32,
241}
242
243#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
245pub struct CacheConfig {
246 #[serde(default)]
251 pub block_cache_capacity_mb: Option<usize>,
252
253 #[serde(default)]
256 pub block_cache_shard_num: Option<usize>,
257
258 #[serde(default)]
259 #[config_doc(omitted)]
260 pub block_cache_eviction: CacheEvictionConfig,
261
262 #[serde(default)]
267 pub meta_cache_capacity_mb: Option<usize>,
268
269 #[serde(default)]
272 pub meta_cache_shard_num: Option<usize>,
273
274 #[serde(default)]
275 #[config_doc(omitted)]
276 pub meta_cache_eviction: CacheEvictionConfig,
277
278 #[serde(default = "default::storage::vector_block_cache_capacity_mb")]
279 pub vector_block_cache_capacity_mb: usize,
280 #[serde(default = "default::storage::vector_block_cache_shard_num")]
281 pub vector_block_cache_shard_num: usize,
282 #[serde(default)]
283 #[config_doc(omitted)]
284 pub vector_block_cache_eviction_config: CacheEvictionConfig,
285 #[serde(default = "default::storage::vector_meta_cache_capacity_mb")]
286 pub vector_meta_cache_capacity_mb: usize,
287 #[serde(default = "default::storage::vector_meta_cache_shard_num")]
288 pub vector_meta_cache_shard_num: usize,
289 #[serde(default)]
290 #[config_doc(omitted)]
291 pub vector_meta_cache_eviction_config: CacheEvictionConfig,
292}
293
294#[derive(Clone, Debug, Serialize, Deserialize)]
296#[serde(tag = "algorithm")]
297pub enum CacheEvictionConfig {
298 Lru {
299 high_priority_ratio_in_percent: Option<usize>,
300 },
301 Lfu {
302 window_capacity_ratio_in_percent: Option<usize>,
303 protected_capacity_ratio_in_percent: Option<usize>,
304 cmsketch_eps: Option<f64>,
305 cmsketch_confidence: Option<f64>,
306 },
307 S3Fifo {
308 small_queue_capacity_ratio_in_percent: Option<usize>,
309 ghost_queue_capacity_ratio_in_percent: Option<usize>,
310 small_to_main_freq_threshold: Option<u8>,
311 },
312}
313
314impl Default for CacheEvictionConfig {
315 fn default() -> Self {
316 Self::Lru {
317 high_priority_ratio_in_percent: None,
318 }
319 }
320}
321
322#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
323pub struct CacheRefillConfig {
324 #[serde(default = "default::cache_refill::data_refill_levels")]
326 pub data_refill_levels: Vec<u32>,
327
328 #[serde(default = "default::cache_refill::timeout_ms")]
330 pub timeout_ms: u64,
331
332 #[serde(default = "default::cache_refill::concurrency")]
334 pub concurrency: usize,
335
336 #[serde(default = "default::cache_refill::unit")]
338 pub unit: usize,
339
340 #[serde(default = "default::cache_refill::threshold")]
344 pub threshold: f64,
345
346 #[serde(default = "default::cache_refill::recent_filter_shards")]
348 pub recent_filter_shards: usize,
349
350 #[serde(default = "default::cache_refill::recent_filter_layers")]
352 pub recent_filter_layers: usize,
353
354 #[serde(default = "default::cache_refill::recent_filter_rotate_interval_ms")]
356 pub recent_filter_rotate_interval_ms: usize,
357
358 #[serde(default = "default::cache_refill::skip_recent_filter")]
362 pub skip_recent_filter: bool,
363
364 #[serde(default, flatten)]
365 #[config_doc(omitted)]
366 pub unrecognized: Unrecognized<Self>,
367}
368
369#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
373pub struct FileCacheConfig {
374 #[serde(default = "default::file_cache::dir")]
375 pub dir: String,
376
377 #[serde(default = "default::file_cache::capacity_mb")]
378 pub capacity_mb: usize,
379
380 #[serde(default = "default::file_cache::file_capacity_mb")]
381 pub file_capacity_mb: usize,
382
383 #[serde(default = "default::file_cache::flushers")]
384 pub flushers: usize,
385
386 #[serde(default = "default::file_cache::reclaimers")]
387 pub reclaimers: usize,
388
389 #[serde(default = "default::file_cache::recover_concurrency")]
390 pub recover_concurrency: usize,
391
392 #[serde(default = "default::file_cache::insert_rate_limit_mb")]
394 pub insert_rate_limit_mb: usize,
395
396 #[serde(default = "default::file_cache::indexer_shards")]
397 pub indexer_shards: usize,
398
399 #[serde(default = "default::file_cache::compression")]
400 pub compression: Compression,
401
402 #[serde(default = "default::file_cache::flush_buffer_threshold_mb")]
403 pub flush_buffer_threshold_mb: Option<usize>,
404
405 #[serde(default = "default::file_cache::throttle")]
406 pub throttle: Throttle,
407
408 #[serde(default = "default::file_cache::fifo_probation_ratio")]
409 pub fifo_probation_ratio: f64,
410
411 #[serde(default = "default::file_cache::blob_index_size_kb")]
423 pub blob_index_size_kb: usize,
424
425 #[serde(default = "default::file_cache::recover_mode")]
435 pub recover_mode: RecoverMode,
436
437 #[serde(default = "default::file_cache::runtime_config")]
438 pub runtime_config: RuntimeOptions,
439
440 #[serde(default, flatten)]
441 #[config_doc(omitted)]
442 pub unrecognized: Unrecognized<Self>,
443}
444
445#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
447pub struct ObjectStoreConfig {
448 #[serde(
450 default = "default::object_store_config::set_atomic_write_dir",
451 alias = "object_store_set_atomic_write_dir"
452 )]
453 pub set_atomic_write_dir: bool,
454
455 #[serde(default)]
459 pub retry: ObjectStoreRetryConfig,
460
461 #[serde(default)]
463 pub s3: S3ObjectStoreConfig,
464
465 #[serde(default = "default::object_store_config::opendal_upload_concurrency")]
467 pub opendal_upload_concurrency: usize,
468
469 #[serde(default)]
471 pub opendal_writer_abort_on_err: bool,
472
473 #[serde(default = "default::object_store_config::upload_part_size")]
474 pub upload_part_size: usize,
475}
476
477impl ObjectStoreConfig {
478 pub fn set_atomic_write_dir(&mut self) {
479 self.set_atomic_write_dir = true;
480 }
481}
482
483#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
485pub struct S3ObjectStoreConfig {
486 #[serde(
488 default = "default::object_store_config::s3::keepalive_ms",
489 alias = "object_store_keepalive_ms"
490 )]
491 pub keepalive_ms: Option<u64>,
492 #[serde(
493 default = "default::object_store_config::s3::recv_buffer_size",
494 alias = "object_store_recv_buffer_size"
495 )]
496 pub recv_buffer_size: Option<usize>,
497 #[serde(
498 default = "default::object_store_config::s3::send_buffer_size",
499 alias = "object_store_send_buffer_size"
500 )]
501 pub send_buffer_size: Option<usize>,
502 #[serde(
503 default = "default::object_store_config::s3::nodelay",
504 alias = "object_store_nodelay"
505 )]
506 pub nodelay: Option<bool>,
507 #[serde(default = "default::object_store_config::s3::developer::retry_unknown_service_error")]
509 pub retry_unknown_service_error: bool,
510 #[serde(default = "default::object_store_config::s3::identity_resolution_timeout_s")]
511 pub identity_resolution_timeout_s: u64,
512 #[serde(default)]
513 pub developer: S3ObjectStoreDeveloperConfig,
514}
515
516#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
518pub struct S3ObjectStoreDeveloperConfig {
519 #[serde(
521 default = "default::object_store_config::s3::developer::retry_unknown_service_error",
522 alias = "object_store_retry_unknown_service_error"
523 )]
524 pub retry_unknown_service_error: bool,
525 #[serde(
528 default = "default::object_store_config::s3::developer::retryable_service_error_codes",
529 alias = "object_store_retryable_service_error_codes"
530 )]
531 pub retryable_service_error_codes: Vec<String>,
532
533 #[serde(default = "default::object_store_config::s3::developer::use_opendal")]
535 pub use_opendal: bool,
536}
537
538#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
539pub struct ObjectStoreRetryConfig {
540 #[serde(default = "default::object_store_config::object_store_req_backoff_interval_ms")]
544 pub req_backoff_interval_ms: u64,
545
546 #[serde(default = "default::object_store_config::object_store_req_backoff_max_delay_ms")]
548 pub req_backoff_max_delay_ms: u64,
549
550 #[serde(default = "default::object_store_config::object_store_req_backoff_factor")]
552 pub req_backoff_factor: u64,
553
554 #[serde(default = "default::object_store_config::object_store_upload_attempt_timeout_ms")]
556 pub upload_attempt_timeout_ms: u64,
557
558 #[serde(default = "default::object_store_config::object_store_upload_retry_attempts")]
560 pub upload_retry_attempts: usize,
561
562 #[serde(
564 default = "default::object_store_config::object_store_streaming_upload_attempt_timeout_ms"
565 )]
566 pub streaming_upload_attempt_timeout_ms: u64,
567
568 #[serde(
570 default = "default::object_store_config::object_store_streaming_upload_retry_attempts"
571 )]
572 pub streaming_upload_retry_attempts: usize,
573
574 #[serde(default = "default::object_store_config::object_store_read_attempt_timeout_ms")]
576 pub read_attempt_timeout_ms: u64,
577
578 #[serde(default = "default::object_store_config::object_store_read_retry_attempts")]
580 pub read_retry_attempts: usize,
581
582 #[serde(
584 default = "default::object_store_config::object_store_streaming_read_attempt_timeout_ms"
585 )]
586 pub streaming_read_attempt_timeout_ms: u64,
587
588 #[serde(default = "default::object_store_config::object_store_streaming_read_retry_attempts")]
590 pub streaming_read_retry_attempts: usize,
591
592 #[serde(default = "default::object_store_config::object_store_metadata_attempt_timeout_ms")]
594 pub metadata_attempt_timeout_ms: u64,
595
596 #[serde(default = "default::object_store_config::object_store_metadata_retry_attempts")]
598 pub metadata_retry_attempts: usize,
599
600 #[serde(default = "default::object_store_config::object_store_delete_attempt_timeout_ms")]
602 pub delete_attempt_timeout_ms: u64,
603
604 #[serde(default = "default::object_store_config::object_store_delete_retry_attempts")]
606 pub delete_retry_attempts: usize,
607
608 #[serde(
610 default = "default::object_store_config::object_store_delete_objects_attempt_timeout_ms"
611 )]
612 pub delete_objects_attempt_timeout_ms: u64,
613
614 #[serde(default = "default::object_store_config::object_store_delete_objects_retry_attempts")]
616 pub delete_objects_retry_attempts: usize,
617
618 #[serde(default = "default::object_store_config::object_store_list_attempt_timeout_ms")]
620 pub list_attempt_timeout_ms: u64,
621
622 #[serde(default = "default::object_store_config::object_store_list_retry_attempts")]
624 pub list_retry_attempts: usize,
625}
626
627#[derive(Debug, Clone)]
628pub enum EvictionConfig {
629 Lru(LruConfig),
630 Lfu(LfuConfig),
631 S3Fifo(S3FifoConfig),
632}
633
634impl EvictionConfig {
635 pub fn for_test() -> Self {
636 Self::Lru(LruConfig {
637 high_priority_pool_ratio: 0.0,
638 })
639 }
640}
641
642impl From<EvictionConfig> for foyer::EvictionConfig {
643 fn from(value: EvictionConfig) -> Self {
644 match value {
645 EvictionConfig::Lru(lru) => foyer::EvictionConfig::Lru(lru),
646 EvictionConfig::Lfu(lfu) => foyer::EvictionConfig::Lfu(lfu),
647 EvictionConfig::S3Fifo(s3fifo) => foyer::EvictionConfig::S3Fifo(s3fifo),
648 }
649 }
650}
651
652pub struct StorageMemoryConfig {
653 pub block_cache_capacity_mb: usize,
654 pub block_cache_shard_num: usize,
655 pub meta_cache_capacity_mb: usize,
656 pub meta_cache_shard_num: usize,
657 pub vector_block_cache_capacity_mb: usize,
658 pub vector_block_cache_shard_num: usize,
659 pub vector_meta_cache_capacity_mb: usize,
660 pub vector_meta_cache_shard_num: usize,
661 pub shared_buffer_capacity_mb: usize,
662 pub compactor_memory_limit_mb: usize,
663 pub prefetch_buffer_capacity_mb: usize,
664 pub block_cache_eviction_config: EvictionConfig,
665 pub meta_cache_eviction_config: EvictionConfig,
666 pub vector_block_cache_eviction_config: EvictionConfig,
667 pub vector_meta_cache_eviction_config: EvictionConfig,
668 pub block_file_cache_flush_buffer_threshold_mb: usize,
669 pub meta_file_cache_flush_buffer_threshold_mb: usize,
670}
671
672pub fn extract_storage_memory_config(s: &RwConfig) -> StorageMemoryConfig {
673 let block_cache_capacity_mb = s.storage.cache.block_cache_capacity_mb.unwrap_or(
674 s.storage
676 .block_cache_capacity_mb
677 .unwrap_or(default::storage::block_cache_capacity_mb()),
678 );
679 let meta_cache_capacity_mb = s.storage.cache.meta_cache_capacity_mb.unwrap_or(
680 s.storage
682 .block_cache_capacity_mb
683 .unwrap_or(default::storage::meta_cache_capacity_mb()),
684 );
685 let shared_buffer_capacity_mb = s
686 .storage
687 .shared_buffer_capacity_mb
688 .unwrap_or(default::storage::shared_buffer_capacity_mb());
689 let meta_cache_shard_num = s.storage.cache.meta_cache_shard_num.unwrap_or_else(|| {
690 let mut shard_bits = MAX_META_CACHE_SHARD_BITS;
691 while (meta_cache_capacity_mb >> shard_bits) < MIN_BUFFER_SIZE_PER_SHARD && shard_bits > 0 {
692 shard_bits -= 1;
693 }
694 shard_bits
695 });
696 let block_cache_shard_num = s.storage.cache.block_cache_shard_num.unwrap_or_else(|| {
697 let mut shard_bits = MAX_BLOCK_CACHE_SHARD_BITS;
698 while (block_cache_capacity_mb >> shard_bits) < MIN_BUFFER_SIZE_PER_SHARD && shard_bits > 0
699 {
700 shard_bits -= 1;
701 }
702 shard_bits
703 });
704 let compactor_memory_limit_mb = s
705 .storage
706 .compactor_memory_limit_mb
707 .unwrap_or(default::storage::compactor_memory_limit_mb());
708
709 let get_eviction_config = |c: &CacheEvictionConfig| {
710 match c {
711 CacheEvictionConfig::Lru {
712 high_priority_ratio_in_percent,
713 } => EvictionConfig::Lru(LruConfig {
714 high_priority_pool_ratio: high_priority_ratio_in_percent.unwrap_or(
715 s.storage
717 .high_priority_ratio_in_percent
718 .unwrap_or(default::storage::high_priority_ratio_in_percent()),
719 ) as f64
720 / 100.0,
721 }),
722 CacheEvictionConfig::Lfu {
723 window_capacity_ratio_in_percent,
724 protected_capacity_ratio_in_percent,
725 cmsketch_eps,
726 cmsketch_confidence,
727 } => EvictionConfig::Lfu(LfuConfig {
728 window_capacity_ratio: window_capacity_ratio_in_percent
729 .unwrap_or(default::storage::window_capacity_ratio_in_percent())
730 as f64
731 / 100.0,
732 protected_capacity_ratio: protected_capacity_ratio_in_percent
733 .unwrap_or(default::storage::protected_capacity_ratio_in_percent())
734 as f64
735 / 100.0,
736 cmsketch_eps: cmsketch_eps.unwrap_or(default::storage::cmsketch_eps()),
737 cmsketch_confidence: cmsketch_confidence
738 .unwrap_or(default::storage::cmsketch_confidence()),
739 }),
740 CacheEvictionConfig::S3Fifo {
741 small_queue_capacity_ratio_in_percent,
742 ghost_queue_capacity_ratio_in_percent,
743 small_to_main_freq_threshold,
744 } => EvictionConfig::S3Fifo(S3FifoConfig {
745 small_queue_capacity_ratio: small_queue_capacity_ratio_in_percent
746 .unwrap_or(default::storage::small_queue_capacity_ratio_in_percent())
747 as f64
748 / 100.0,
749 ghost_queue_capacity_ratio: ghost_queue_capacity_ratio_in_percent
750 .unwrap_or(default::storage::ghost_queue_capacity_ratio_in_percent())
751 as f64
752 / 100.0,
753 small_to_main_freq_threshold: small_to_main_freq_threshold
754 .unwrap_or(default::storage::small_to_main_freq_threshold()),
755 }),
756 }
757 };
758
759 let block_cache_eviction_config = get_eviction_config(&s.storage.cache.block_cache_eviction);
760 let meta_cache_eviction_config = get_eviction_config(&s.storage.cache.meta_cache_eviction);
761 let vector_block_cache_eviction_config =
762 get_eviction_config(&s.storage.cache.vector_block_cache_eviction_config);
763 let vector_meta_cache_eviction_config =
764 get_eviction_config(&s.storage.cache.vector_meta_cache_eviction_config);
765
766 let prefetch_buffer_capacity_mb =
767 s.storage
768 .shared_buffer_capacity_mb
769 .unwrap_or(match &block_cache_eviction_config {
770 EvictionConfig::Lru(lru) => {
771 ((1.0 - lru.high_priority_pool_ratio) * block_cache_capacity_mb as f64) as usize
772 }
773 EvictionConfig::Lfu(lfu) => {
774 ((1.0 - lfu.protected_capacity_ratio) * block_cache_capacity_mb as f64) as usize
775 }
776 EvictionConfig::S3Fifo(s3fifo) => {
777 (s3fifo.small_queue_capacity_ratio * block_cache_capacity_mb as f64) as usize
778 }
779 });
780
781 let block_file_cache_flush_buffer_threshold_mb = s
782 .storage
783 .data_file_cache
784 .flush_buffer_threshold_mb
785 .unwrap_or(default::storage::block_file_cache_flush_buffer_threshold_mb());
786 let meta_file_cache_flush_buffer_threshold_mb = s
787 .storage
788 .meta_file_cache
789 .flush_buffer_threshold_mb
790 .unwrap_or(default::storage::block_file_cache_flush_buffer_threshold_mb());
791
792 StorageMemoryConfig {
793 block_cache_capacity_mb,
794 block_cache_shard_num,
795 meta_cache_capacity_mb,
796 meta_cache_shard_num,
797 vector_block_cache_capacity_mb: s.storage.cache.vector_block_cache_capacity_mb,
798 vector_block_cache_shard_num: s.storage.cache.vector_block_cache_shard_num,
799 vector_meta_cache_capacity_mb: s.storage.cache.vector_meta_cache_capacity_mb,
800 vector_meta_cache_shard_num: s.storage.cache.vector_meta_cache_shard_num,
801 shared_buffer_capacity_mb,
802 compactor_memory_limit_mb,
803 prefetch_buffer_capacity_mb,
804 block_cache_eviction_config,
805 meta_cache_eviction_config,
806 vector_block_cache_eviction_config,
807 vector_meta_cache_eviction_config,
808 block_file_cache_flush_buffer_threshold_mb,
809 meta_file_cache_flush_buffer_threshold_mb,
810 }
811}
812
813pub mod default {
814
815 pub mod storage {
816 pub fn share_buffers_sync_parallelism() -> u32 {
817 1
818 }
819
820 pub fn share_buffer_compaction_worker_threads_number() -> u32 {
821 4
822 }
823
824 pub fn shared_buffer_capacity_mb() -> usize {
825 1024
826 }
827
828 pub fn shared_buffer_flush_ratio() -> f32 {
829 0.8
830 }
831
832 pub fn shared_buffer_min_batch_flush_size_mb() -> usize {
833 800
834 }
835
836 pub fn imm_merge_threshold() -> usize {
837 0 }
839
840 pub fn write_conflict_detection_enabled() -> bool {
841 cfg!(debug_assertions)
842 }
843
844 pub fn max_cached_recent_versions_number() -> usize {
845 60
846 }
847
848 pub fn block_cache_capacity_mb() -> usize {
849 512
850 }
851
852 pub fn high_priority_ratio_in_percent() -> usize {
853 70
854 }
855
856 pub fn window_capacity_ratio_in_percent() -> usize {
857 10
858 }
859
860 pub fn protected_capacity_ratio_in_percent() -> usize {
861 80
862 }
863
864 pub fn cmsketch_eps() -> f64 {
865 0.002
866 }
867
868 pub fn cmsketch_confidence() -> f64 {
869 0.95
870 }
871
872 pub fn small_queue_capacity_ratio_in_percent() -> usize {
873 10
874 }
875
876 pub fn ghost_queue_capacity_ratio_in_percent() -> usize {
877 1000
878 }
879
880 pub fn small_to_main_freq_threshold() -> u8 {
881 1
882 }
883
884 pub fn meta_cache_capacity_mb() -> usize {
885 128
886 }
887
888 pub fn disable_remote_compactor() -> bool {
889 false
890 }
891
892 pub fn share_buffer_upload_concurrency() -> usize {
893 8
894 }
895
896 pub fn compactor_memory_limit_mb() -> usize {
897 512
898 }
899
900 pub fn compactor_max_task_multiplier() -> f32 {
901 match std::env::var("RW_COMPACTOR_MODE")
902 .unwrap_or_default()
903 .as_str()
904 {
905 mode if mode.contains("iceberg") => 12.0000,
906 _ => 3.0000,
907 }
908 }
909
910 pub fn compactor_memory_available_proportion() -> f64 {
911 0.8
912 }
913
914 pub fn sstable_id_remote_fetch_number() -> u32 {
915 10
916 }
917
918 pub fn min_sstable_size_mb() -> u32 {
919 32
920 }
921
922 pub fn min_sst_size_for_streaming_upload() -> u64 {
923 32 * 1024 * 1024
925 }
926
927 pub fn max_concurrent_compaction_task_number() -> u64 {
928 16
929 }
930
931 pub fn max_preload_wait_time_mill() -> u64 {
932 0
933 }
934
935 pub fn max_version_pinning_duration_sec() -> u64 {
936 3 * 3600
937 }
938
939 pub fn compactor_max_sst_key_count() -> u64 {
940 2 * 1024 * 1024 }
942
943 pub fn compact_iter_recreate_timeout_ms() -> u64 {
944 10 * 60 * 1000
945 }
946
947 pub fn compactor_iter_max_io_retry_times() -> usize {
948 8
949 }
950
951 pub fn compactor_max_sst_size() -> u64 {
952 512 * 1024 * 1024 }
954
955 pub fn enable_fast_compaction() -> bool {
956 true
957 }
958
959 pub fn check_compaction_result() -> bool {
960 false
961 }
962
963 pub fn max_preload_io_retry_times() -> usize {
964 3
965 }
966
967 pub fn mem_table_spill_threshold() -> usize {
968 4 << 20
969 }
970
971 pub fn compactor_fast_max_compact_delete_ratio() -> u32 {
972 40
973 }
974
975 pub fn compactor_fast_max_compact_task_size() -> u64 {
976 2 * 1024 * 1024 * 1024 }
978
979 pub fn max_prefetch_block_number() -> usize {
980 16
981 }
982
983 pub fn compactor_concurrent_uploading_sst_count() -> Option<usize> {
984 None
985 }
986
987 pub fn compactor_max_overlap_sst_count() -> usize {
988 64
989 }
990
991 pub fn compactor_max_preload_meta_file_count() -> usize {
992 32
993 }
994
995 pub fn vector_file_block_size_kb() -> usize {
996 1024
997 }
998
999 pub fn vector_block_cache_capacity_mb() -> usize {
1000 16
1001 }
1002
1003 pub fn vector_block_cache_shard_num() -> usize {
1004 16
1005 }
1006
1007 pub fn vector_meta_cache_capacity_mb() -> usize {
1008 16
1009 }
1010
1011 pub fn vector_meta_cache_shard_num() -> usize {
1012 16
1013 }
1014
1015 pub fn table_info_statistic_history_times() -> usize {
1017 240
1018 }
1019
1020 pub fn block_file_cache_flush_buffer_threshold_mb() -> usize {
1021 256
1022 }
1023
1024 pub fn meta_file_cache_flush_buffer_threshold_mb() -> usize {
1025 64
1026 }
1027
1028 pub fn time_travel_version_cache_capacity() -> u64 {
1029 10
1030 }
1031
1032 pub fn iceberg_compaction_target_file_size_mb() -> u32 {
1033 1024
1034 }
1035
1036 pub fn iceberg_compaction_enable_validate() -> bool {
1037 false
1038 }
1039
1040 pub fn iceberg_compaction_max_record_batch_rows() -> usize {
1041 1024
1042 }
1043
1044 pub fn iceberg_compaction_write_parquet_max_row_group_rows() -> usize {
1045 1024 * 100 }
1047
1048 pub fn iceberg_compaction_min_size_per_partition_mb() -> u32 {
1049 1024
1050 }
1051
1052 pub fn iceberg_compaction_max_file_count_per_partition() -> u32 {
1053 32
1054 }
1055
1056 pub fn iceberg_compaction_task_parallelism_ratio() -> f32 {
1057 4.0
1058 }
1059
1060 pub fn iceberg_compaction_enable_heuristic_output_parallelism() -> bool {
1061 false
1062 }
1063
1064 pub fn iceberg_compaction_max_concurrent_closes() -> usize {
1065 8
1066 }
1067
1068 pub fn iceberg_compaction_enable_dynamic_size_estimation() -> bool {
1069 true
1070 }
1071
1072 pub fn iceberg_compaction_size_estimation_smoothing_factor() -> f64 {
1073 0.3
1074 }
1075
1076 pub fn iceberg_compaction_small_file_threshold_mb() -> u32 {
1077 32
1078 }
1079
1080 pub fn iceberg_compaction_max_task_total_size_mb() -> u32 {
1081 50 * 1024 }
1083
1084 pub fn iceberg_compaction_max_file_group_size_bytes() -> u64 {
1085 100 * 1024 * 1024 * 1024 }
1087
1088 pub fn iceberg_compaction_pending_parallelism_budget_multiplier() -> f32 {
1089 4.0
1090 }
1091 }
1092
1093 pub mod file_cache {
1094 use std::num::NonZeroUsize;
1095
1096 use foyer::{Compression, RecoverMode, RuntimeOptions, Throttle, TokioRuntimeOptions};
1097
1098 pub fn dir() -> String {
1099 "".to_owned()
1100 }
1101
1102 pub fn capacity_mb() -> usize {
1103 1024
1104 }
1105
1106 pub fn file_capacity_mb() -> usize {
1107 64
1108 }
1109
1110 pub fn flushers() -> usize {
1111 4
1112 }
1113
1114 pub fn reclaimers() -> usize {
1115 4
1116 }
1117
1118 pub fn recover_concurrency() -> usize {
1119 8
1120 }
1121
1122 pub fn insert_rate_limit_mb() -> usize {
1123 0
1124 }
1125
1126 pub fn indexer_shards() -> usize {
1127 64
1128 }
1129
1130 pub fn compression() -> Compression {
1131 Compression::None
1132 }
1133
1134 pub fn flush_buffer_threshold_mb() -> Option<usize> {
1135 None
1136 }
1137
1138 pub fn fifo_probation_ratio() -> f64 {
1139 0.1
1140 }
1141
1142 pub fn blob_index_size_kb() -> usize {
1143 16
1144 }
1145
1146 pub fn recover_mode() -> RecoverMode {
1147 RecoverMode::Quiet
1148 }
1149
1150 pub fn runtime_config() -> RuntimeOptions {
1151 RuntimeOptions::Unified(TokioRuntimeOptions::default())
1152 }
1153
1154 pub fn throttle() -> Throttle {
1155 Throttle::new()
1156 .with_iops_counter(foyer::IopsCounter::PerIoSize(
1157 NonZeroUsize::new(128 * 1024).unwrap(),
1158 ))
1159 .with_read_iops(100000)
1160 .with_write_iops(100000)
1161 .with_write_throughput(1024 * 1024 * 1024)
1162 .with_read_throughput(1024 * 1024 * 1024)
1163 }
1164 }
1165
1166 pub mod cache_refill {
1167 pub fn data_refill_levels() -> Vec<u32> {
1168 vec![]
1169 }
1170
1171 pub fn timeout_ms() -> u64 {
1172 6000
1173 }
1174
1175 pub fn concurrency() -> usize {
1176 10
1177 }
1178
1179 pub fn unit() -> usize {
1180 64
1181 }
1182
1183 pub fn threshold() -> f64 {
1184 0.5
1185 }
1186
1187 pub fn recent_filter_shards() -> usize {
1188 16
1189 }
1190
1191 pub fn recent_filter_layers() -> usize {
1192 6
1193 }
1194
1195 pub fn recent_filter_rotate_interval_ms() -> usize {
1196 10000
1197 }
1198
1199 pub fn skip_recent_filter() -> bool {
1200 false
1201 }
1202 }
1203
1204 pub mod object_store_config {
1205 const DEFAULT_REQ_BACKOFF_INTERVAL_MS: u64 = 1000; const DEFAULT_REQ_BACKOFF_MAX_DELAY_MS: u64 = 10 * 1000; const DEFAULT_REQ_MAX_RETRY_ATTEMPTS: usize = 3;
1208
1209 pub fn set_atomic_write_dir() -> bool {
1210 false
1211 }
1212
1213 pub fn object_store_req_backoff_interval_ms() -> u64 {
1214 DEFAULT_REQ_BACKOFF_INTERVAL_MS
1215 }
1216
1217 pub fn object_store_req_backoff_max_delay_ms() -> u64 {
1218 DEFAULT_REQ_BACKOFF_MAX_DELAY_MS }
1220
1221 pub fn object_store_req_backoff_factor() -> u64 {
1222 2
1223 }
1224
1225 pub fn object_store_upload_attempt_timeout_ms() -> u64 {
1226 8 * 1000 }
1228
1229 pub fn object_store_upload_retry_attempts() -> usize {
1230 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1231 }
1232
1233 pub fn object_store_streaming_upload_attempt_timeout_ms() -> u64 {
1235 5 * 1000 }
1237
1238 pub fn object_store_streaming_upload_retry_attempts() -> usize {
1239 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1240 }
1241
1242 pub fn object_store_read_attempt_timeout_ms() -> u64 {
1244 8 * 1000 }
1246
1247 pub fn object_store_read_retry_attempts() -> usize {
1248 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1249 }
1250
1251 pub fn object_store_streaming_read_attempt_timeout_ms() -> u64 {
1252 3 * 1000 }
1254
1255 pub fn object_store_streaming_read_retry_attempts() -> usize {
1256 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1257 }
1258
1259 pub fn object_store_metadata_attempt_timeout_ms() -> u64 {
1260 60 * 1000 }
1262
1263 pub fn object_store_metadata_retry_attempts() -> usize {
1264 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1265 }
1266
1267 pub fn object_store_delete_attempt_timeout_ms() -> u64 {
1268 5 * 1000
1269 }
1270
1271 pub fn object_store_delete_retry_attempts() -> usize {
1272 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1273 }
1274
1275 pub fn object_store_delete_objects_attempt_timeout_ms() -> u64 {
1277 5 * 1000
1278 }
1279
1280 pub fn object_store_delete_objects_retry_attempts() -> usize {
1281 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1282 }
1283
1284 pub fn object_store_list_attempt_timeout_ms() -> u64 {
1285 10 * 60 * 1000
1286 }
1287
1288 pub fn object_store_list_retry_attempts() -> usize {
1289 DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1290 }
1291
1292 pub fn opendal_upload_concurrency() -> usize {
1293 256
1294 }
1295
1296 pub fn upload_part_size() -> usize {
1297 16 * 1024 * 1024
1299 }
1300
1301 pub mod s3 {
1302 const DEFAULT_IDENTITY_RESOLUTION_TIMEOUT_S: u64 = 5;
1303
1304 const DEFAULT_KEEPALIVE_MS: u64 = 600 * 1000; pub fn keepalive_ms() -> Option<u64> {
1307 Some(DEFAULT_KEEPALIVE_MS) }
1309
1310 pub fn recv_buffer_size() -> Option<usize> {
1311 Some(1 << 21) }
1313
1314 pub fn send_buffer_size() -> Option<usize> {
1315 None
1316 }
1317
1318 pub fn nodelay() -> Option<bool> {
1319 Some(true)
1320 }
1321
1322 pub fn identity_resolution_timeout_s() -> u64 {
1323 DEFAULT_IDENTITY_RESOLUTION_TIMEOUT_S
1324 }
1325
1326 pub mod developer {
1327 pub fn retry_unknown_service_error() -> bool {
1328 false
1329 }
1330
1331 pub fn retryable_service_error_codes() -> Vec<String> {
1332 vec!["SlowDown".into(), "TooManyRequests".into()]
1333 }
1334
1335 pub fn use_opendal() -> bool {
1336 true
1337 }
1338 }
1339 }
1340 }
1341}