Skip to main content

risingwave_common/config/
storage.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use foyer::{
16    Compression, LfuConfig, LruConfig, RecoverMode, RuntimeOptions, S3FifoConfig, Throttle,
17};
18use serde::de::Error as _;
19
20use super::*;
21
22/// The section `[storage]` in `risingwave.toml`.
23#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
24#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
25pub struct StorageConfig {
26    /// parallelism while syncing share buffers into L0 SST. Should NOT be 0.
27    #[serde(default = "default::storage::share_buffers_sync_parallelism")]
28    pub share_buffers_sync_parallelism: u32,
29
30    /// Worker threads number of dedicated tokio runtime for share buffer compaction. 0 means use
31    /// tokio's default value (number of CPU core).
32    #[serde(default = "default::storage::share_buffer_compaction_worker_threads_number")]
33    pub share_buffer_compaction_worker_threads_number: u32,
34
35    /// Configure the maximum shared buffer size in MB explicitly. Writes attempting to exceed the capacity
36    /// will stall until there is enough space. The overridden value will only be effective if:
37    /// 1. `block_cache_capacity_mb` and `meta_cache_capacity_mb` are also configured explicitly.
38    /// 2. `block_cache_capacity_mb` + `meta_cache_capacity_mb` + `meta_cache_capacity_mb` doesn't exceed 0.3 * non-reserved memory.
39    #[serde(default)]
40    pub shared_buffer_capacity_mb: Option<usize>,
41
42    /// The shared buffer will start flushing data to object when the ratio of memory usage to the
43    /// shared buffer capacity exceed such ratio.
44    #[serde(default = "default::storage::shared_buffer_flush_ratio")]
45    pub shared_buffer_flush_ratio: f32,
46
47    /// The minimum total flush size of shared buffer spill. When a shared buffer spilled is trigger,
48    /// the total flush size across multiple epochs should be at least higher than this size.
49    #[serde(default = "default::storage::shared_buffer_min_batch_flush_size_mb")]
50    pub shared_buffer_min_batch_flush_size_mb: usize,
51
52    /// The threshold for the number of immutable memtables to merge to a new imm.
53    #[serde(default = "default::storage::imm_merge_threshold")]
54    #[deprecated]
55    pub imm_merge_threshold: usize,
56
57    /// Whether to enable write conflict detection
58    #[serde(default = "default::storage::write_conflict_detection_enabled")]
59    pub write_conflict_detection_enabled: bool,
60
61    #[serde(default)]
62    #[config_doc(nested)]
63    pub cache: CacheConfig,
64
65    /// DEPRECATED: This config will be deprecated in the future version, use `storage.cache.block_cache_capacity_mb` instead.
66    #[serde(default)]
67    pub block_cache_capacity_mb: Option<usize>,
68
69    /// DEPRECATED: This config will be deprecated in the future version, use `storage.cache.meta_cache_capacity_mb` instead.
70    #[serde(default)]
71    pub meta_cache_capacity_mb: Option<usize>,
72
73    /// DEPRECATED: This config will be deprecated in the future version, use `storage.cache.block_cache_eviction.high_priority_ratio_in_percent` with `storage.cache.block_cache_eviction.algorithm = "Lru"` instead.
74    #[serde(default)]
75    pub high_priority_ratio_in_percent: Option<usize>,
76
77    /// max memory usage for large query
78    #[serde(default)]
79    pub prefetch_buffer_capacity_mb: Option<usize>,
80
81    #[serde(default = "default::storage::max_cached_recent_versions_number")]
82    pub max_cached_recent_versions_number: usize,
83
84    /// max prefetch block number
85    #[serde(
86        default = "default::storage::max_prefetch_block_number",
87        deserialize_with = "deserialize_max_prefetch_block_number"
88    )]
89    pub max_prefetch_block_number: usize,
90
91    #[serde(default = "default::storage::disable_remote_compactor")]
92    pub disable_remote_compactor: bool,
93
94    /// Number of tasks shared buffer can upload in parallel.
95    #[serde(default = "default::storage::share_buffer_upload_concurrency")]
96    pub share_buffer_upload_concurrency: usize,
97
98    #[serde(default)]
99    pub compactor_memory_limit_mb: Option<usize>,
100
101    /// Compactor calculates the maximum number of tasks that can be executed on the node based on
102    /// `worker_num` and `compactor_max_task_multiplier`.
103    /// `max_pull_task_count` = `worker_num` * `compactor_max_task_multiplier`
104    #[serde(default = "default::storage::compactor_max_task_multiplier")]
105    pub compactor_max_task_multiplier: f32,
106
107    /// The percentage of memory available when compactor is deployed separately.
108    /// `non_reserved_memory_bytes` = `system_memory_available_bytes` * `compactor_memory_available_proportion`
109    #[serde(default = "default::storage::compactor_memory_available_proportion")]
110    pub compactor_memory_available_proportion: f64,
111
112    /// Number of SST ids fetched from meta per RPC
113    #[serde(default = "default::storage::sstable_id_remote_fetch_number")]
114    pub sstable_id_remote_fetch_number: u32,
115
116    #[serde(default = "default::storage::min_sstable_size_mb")]
117    pub min_sstable_size_mb: u32,
118
119    #[serde(default)]
120    #[config_doc(nested)]
121    pub data_file_cache: FileCacheConfig,
122
123    #[serde(default)]
124    #[config_doc(nested)]
125    pub meta_file_cache: FileCacheConfig,
126
127    /// sst serde happens when a sst meta is written to meta disk cache.
128    /// Excluding the SST filter from serde can reduce the meta disk cache entry size
129    /// and reduce disk IO throughput at the cost of making the SST filter useless.
130    #[serde(default = "default::storage::sst_skip_bloom_filter_in_serde")]
131    pub sst_skip_bloom_filter_in_serde: bool,
132
133    #[serde(default)]
134    #[config_doc(nested)]
135    pub cache_refill: CacheRefillConfig,
136
137    /// Whether to enable streaming upload for sstable.
138    #[serde(default = "default::storage::min_sst_size_for_streaming_upload")]
139    pub min_sst_size_for_streaming_upload: u64,
140
141    #[serde(default = "default::storage::max_concurrent_compaction_task_number")]
142    pub max_concurrent_compaction_task_number: u64,
143
144    #[serde(default = "default::storage::max_preload_wait_time_mill")]
145    pub max_preload_wait_time_mill: u64,
146
147    #[serde(default = "default::storage::max_version_pinning_duration_sec")]
148    pub max_version_pinning_duration_sec: u64,
149
150    #[serde(default = "default::storage::compactor_max_sst_key_count")]
151    pub compactor_max_sst_key_count: u64,
152    // DEPRECATED: This config will be deprecated in the future version, use `storage.compactor_iter_max_io_retry_times` instead.
153    #[serde(default = "default::storage::compact_iter_recreate_timeout_ms")]
154    pub compact_iter_recreate_timeout_ms: u64,
155    #[serde(default = "default::storage::compactor_max_sst_size")]
156    pub compactor_max_sst_size: u64,
157    #[serde(default = "default::storage::enable_fast_compaction")]
158    pub enable_fast_compaction: bool,
159    #[serde(default = "default::storage::check_compaction_result")]
160    pub check_compaction_result: bool,
161    #[serde(default = "default::storage::max_preload_io_retry_times")]
162    pub max_preload_io_retry_times: usize,
163    #[serde(default = "default::storage::compactor_fast_max_compact_delete_ratio")]
164    pub compactor_fast_max_compact_delete_ratio: u32,
165    #[serde(default = "default::storage::compactor_fast_max_compact_task_size")]
166    pub compactor_fast_max_compact_task_size: u64,
167    #[serde(default = "default::storage::compactor_iter_max_io_retry_times")]
168    pub compactor_iter_max_io_retry_times: usize,
169
170    /// If set, block metadata keys will be shortened when their length exceeds this threshold.
171    /// This reduces `SSTable` metadata size by storing only the minimal distinguishing prefix.
172    /// - `None`: Disabled (default)
173    /// - `Some(n)`: Only shorten keys with length >= n bytes
174    #[serde(default = "default::storage::shorten_block_meta_key_threshold")]
175    pub shorten_block_meta_key_threshold: Option<usize>,
176
177    /// Deprecated: The window size of table info statistic history.
178    #[serde(default = "default::storage::table_info_statistic_history_times")]
179    #[deprecated]
180    pub table_info_statistic_history_times: usize,
181
182    #[serde(default, flatten)]
183    #[config_doc(omitted)]
184    pub unrecognized: Unrecognized<Self>,
185
186    /// The spill threshold for mem table.
187    #[serde(default = "default::storage::mem_table_spill_threshold")]
188    pub mem_table_spill_threshold: usize,
189
190    /// The concurrent uploading number of `SSTables` of builder
191    #[serde(default = "default::storage::compactor_concurrent_uploading_sst_count")]
192    pub compactor_concurrent_uploading_sst_count: Option<usize>,
193
194    #[serde(default = "default::storage::compactor_max_overlap_sst_count")]
195    pub compactor_max_overlap_sst_count: usize,
196
197    /// The maximum number of meta files that can be preloaded.
198    /// If the number of meta files exceeds this value, the compactor will try to compute parallelism only through `SstableInfo`, no longer preloading `SstableMeta`.
199    /// This is to prevent the compactor from consuming too much memory, but it may cause the compactor to be less efficient.
200    #[serde(default = "default::storage::compactor_max_preload_meta_file_count")]
201    pub compactor_max_preload_meta_file_count: usize,
202
203    #[serde(default = "default::storage::vector_file_block_size_kb")]
204    pub vector_file_block_size_kb: usize,
205
206    /// Object storage configuration
207    /// 1. General configuration
208    /// 2. Some special configuration of Backend
209    /// 3. Retry and timeout configuration
210    #[serde(default)]
211    pub object_store: ObjectStoreConfig,
212
213    #[serde(default = "default::storage::time_travel_version_cache_capacity")]
214    pub time_travel_version_cache_capacity: u64,
215
216    #[serde(default = "default::storage::table_change_log_cache_capacity")]
217    pub table_change_log_cache_capacity: u64,
218
219    // iceberg compaction
220    #[serde(default = "default::storage::iceberg_compaction_enable_validate")]
221    pub iceberg_compaction_enable_validate: bool,
222    #[serde(default = "default::storage::iceberg_compaction_max_record_batch_rows")]
223    pub iceberg_compaction_max_record_batch_rows: usize,
224    #[serde(default = "default::storage::iceberg_compaction_min_size_per_partition_mb")]
225    pub iceberg_compaction_min_size_per_partition_mb: u32,
226    #[serde(default = "default::storage::iceberg_compaction_max_file_count_per_partition")]
227    pub iceberg_compaction_max_file_count_per_partition: u32,
228    /// DEPRECATED: This config will be deprecated in the future version.
229    /// Use sink config `compaction.write_parquet_max_row_group_rows` instead.
230    #[serde(default = "default::storage::iceberg_compaction_write_parquet_max_row_group_rows")]
231    #[deprecated(
232        note = "This config is deprecated. Use sink config `compaction.write_parquet_max_row_group_rows` instead."
233    )]
234    pub iceberg_compaction_write_parquet_max_row_group_rows: usize,
235
236    /// The ratio of iceberg compaction max parallelism to the number of CPU cores
237    #[serde(default = "default::storage::iceberg_compaction_task_parallelism_ratio")]
238    pub iceberg_compaction_task_parallelism_ratio: f32,
239    /// Whether to enable heuristic output parallelism in iceberg compaction.
240    #[serde(default = "default::storage::iceberg_compaction_enable_heuristic_output_parallelism")]
241    pub iceberg_compaction_enable_heuristic_output_parallelism: bool,
242    /// Maximum number of concurrent file close operations
243    #[serde(default = "default::storage::iceberg_compaction_max_concurrent_closes")]
244    pub iceberg_compaction_max_concurrent_closes: usize,
245    /// Whether to enable dynamic size estimation for iceberg compaction.
246    #[serde(default = "default::storage::iceberg_compaction_enable_dynamic_size_estimation")]
247    pub iceberg_compaction_enable_dynamic_size_estimation: bool,
248    /// The smoothing factor for size estimation in iceberg compaction.(default: 0.3)
249    #[serde(default = "default::storage::iceberg_compaction_size_estimation_smoothing_factor")]
250    pub iceberg_compaction_size_estimation_smoothing_factor: f64,
251    /// Multiplier for pending waiting parallelism budget for iceberg compaction task queue.
252    /// Effective pending budget = `ceil(max_task_parallelism * multiplier)`. Default 4.0.
253    /// Set < 1.0 to reduce buffering (may increase `PullTask` RPC frequency); set higher to batch more tasks.
254    #[serde(
255        default = "default::storage::iceberg_compaction_pending_parallelism_budget_multiplier"
256    )]
257    pub iceberg_compaction_pending_parallelism_budget_multiplier: f32,
258    /// Pull interval for iceberg compaction task requests in milliseconds.
259    #[serde(
260        default = "default::storage::iceberg_compaction_pull_interval_ms",
261        deserialize_with = "deserialize_iceberg_compaction_pull_interval_ms"
262    )]
263    pub iceberg_compaction_pull_interval_ms: u64,
264    /// Enable prefetching entire data files before compacting them.
265    ///
266    /// When enabled, each input file is downloaded with a single HTTP GET before compaction
267    /// begins, replacing the default pattern of N+1 range reads (1 footer + N column chunks)
268    /// with a single sequential read per file. This reduces object storage READ API calls
269    /// from D×(1+N) to D per compaction cycle.
270    ///
271    /// Trade-off: higher peak memory — one full file is held in memory per concurrent
272    /// compaction task. Enable only when object storage API cost is a priority and memory headroom is
273    /// sufficient. See also the memory-protection config knobs such as
274    /// `iceberg_compaction_task_parallelism_ratio`.
275    #[serde(default = "default::storage::iceberg_compaction_enable_prefetch")]
276    pub iceberg_compaction_enable_prefetch: bool,
277
278    #[serde(default = "default::storage::iceberg_compaction_target_binpack_group_size_mb")]
279    pub iceberg_compaction_target_binpack_group_size_mb: Option<u64>,
280    #[serde(default = "default::storage::iceberg_compaction_min_group_size_mb")]
281    pub iceberg_compaction_min_group_size_mb: Option<u64>,
282    #[serde(default = "default::storage::iceberg_compaction_min_group_file_count")]
283    pub iceberg_compaction_min_group_file_count: Option<usize>,
284}
285
286/// the section `[storage.cache]` in `risingwave.toml`.
287#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
288#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
289pub struct CacheConfig {
290    /// Configure the capacity of the block cache in MB explicitly.
291    /// The overridden value will only be effective if:
292    /// 1. `meta_cache_capacity_mb` and `shared_buffer_capacity_mb` are also configured explicitly.
293    /// 2. `block_cache_capacity_mb` + `meta_cache_capacity_mb` + `meta_cache_capacity_mb` doesn't exceed 0.3 * non-reserved memory.
294    #[serde(default)]
295    pub block_cache_capacity_mb: Option<usize>,
296
297    /// Configure the number of shards in the block cache explicitly.
298    /// If not set, the shard number will be determined automatically based on cache capacity.
299    #[serde(default)]
300    pub block_cache_shard_num: Option<usize>,
301
302    #[serde(default)]
303    #[config_doc(omitted)]
304    pub block_cache_eviction: CacheEvictionConfig,
305
306    /// Configure the capacity of the block cache in MB explicitly.
307    /// The overridden value will only be effective if:
308    /// 1. `block_cache_capacity_mb` and `shared_buffer_capacity_mb` are also configured explicitly.
309    /// 2. `block_cache_capacity_mb` + `meta_cache_capacity_mb` + `meta_cache_capacity_mb` doesn't exceed 0.3 * non-reserved memory.
310    #[serde(default)]
311    pub meta_cache_capacity_mb: Option<usize>,
312
313    /// Configure the number of shards in the meta cache explicitly.
314    /// If not set, the shard number will be determined automatically based on cache capacity.
315    #[serde(default)]
316    pub meta_cache_shard_num: Option<usize>,
317
318    #[serde(default)]
319    #[config_doc(omitted)]
320    pub meta_cache_eviction: CacheEvictionConfig,
321
322    #[serde(default = "default::storage::vector_block_cache_capacity_mb")]
323    pub vector_block_cache_capacity_mb: usize,
324    #[serde(default = "default::storage::vector_block_cache_shard_num")]
325    pub vector_block_cache_shard_num: usize,
326    #[serde(default)]
327    #[config_doc(omitted)]
328    pub vector_block_cache_eviction_config: CacheEvictionConfig,
329    #[serde(default = "default::storage::vector_meta_cache_capacity_mb")]
330    pub vector_meta_cache_capacity_mb: usize,
331    #[serde(default = "default::storage::vector_meta_cache_shard_num")]
332    pub vector_meta_cache_shard_num: usize,
333    #[serde(default)]
334    #[config_doc(omitted)]
335    pub vector_meta_cache_eviction_config: CacheEvictionConfig,
336}
337
338/// the section `[storage.cache.eviction]` in `risingwave.toml`.
339#[derive(Clone, Debug, Serialize, Deserialize)]
340#[serde(tag = "algorithm")]
341pub enum CacheEvictionConfig {
342    Lru {
343        high_priority_ratio_in_percent: Option<usize>,
344    },
345    Lfu {
346        window_capacity_ratio_in_percent: Option<usize>,
347        protected_capacity_ratio_in_percent: Option<usize>,
348        cmsketch_eps: Option<f64>,
349        cmsketch_confidence: Option<f64>,
350    },
351    S3Fifo {
352        small_queue_capacity_ratio_in_percent: Option<usize>,
353        ghost_queue_capacity_ratio_in_percent: Option<usize>,
354        small_to_main_freq_threshold: Option<u8>,
355    },
356}
357
358impl Default for CacheEvictionConfig {
359    fn default() -> Self {
360        Self::Lru {
361            high_priority_ratio_in_percent: None,
362        }
363    }
364}
365
366#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
367#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
368pub struct CacheRefillConfig {
369    /// Inflight meta cache refill tasks limit.
370    ///
371    /// 0 for unlimited.
372    #[serde(default = "default::cache_refill::meta_refill_concurrency")]
373    pub meta_refill_concurrency: usize,
374
375    /// `SSTable` levels to refill.
376    #[serde(default = "default::cache_refill::data_refill_levels")]
377    pub data_refill_levels: Vec<u32>,
378
379    /// Cache refill maximum timeout to apply version delta.
380    #[serde(default = "default::cache_refill::timeout_ms")]
381    pub timeout_ms: u64,
382
383    /// Inflight data cache refill tasks.
384    #[serde(default = "default::cache_refill::concurrency")]
385    pub concurrency: usize,
386
387    /// Block count that a data cache refill request fetches.
388    #[serde(default = "default::cache_refill::unit")]
389    pub unit: usize,
390
391    /// Data cache refill unit admission ratio.
392    ///
393    /// Only unit whose blocks are admitted above the ratio will be refilled.
394    #[serde(default = "default::cache_refill::threshold")]
395    pub threshold: f64,
396
397    /// Recent filter layer shards.
398    #[serde(default = "default::cache_refill::recent_filter_shards")]
399    pub recent_filter_shards: usize,
400
401    /// Recent filter layer count.
402    #[serde(default = "default::cache_refill::recent_filter_layers")]
403    pub recent_filter_layers: usize,
404
405    /// Recent filter layer rotate interval.
406    #[serde(default = "default::cache_refill::recent_filter_rotate_interval_ms")]
407    pub recent_filter_rotate_interval_ms: usize,
408
409    /// Skip check recent filter on data refill.
410    ///
411    /// This option is suitable for a single compute node or debugging.
412    #[serde(default = "default::cache_refill::skip_recent_filter")]
413    pub skip_recent_filter: bool,
414
415    #[serde(default, flatten)]
416    #[config_doc(omitted)]
417    pub unrecognized: Unrecognized<Self>,
418}
419
420/// The subsection `[storage.data_file_cache]` and `[storage.meta_file_cache]` in `risingwave.toml`.
421///
422/// It's put at [`StorageConfig::data_file_cache`] and  [`StorageConfig::meta_file_cache`].
423#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
424#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde, ConfigDoc)]
425pub struct FileCacheConfig {
426    #[serde(default = "default::file_cache::dir")]
427    pub dir: String,
428
429    #[serde(default = "default::file_cache::capacity_mb")]
430    pub capacity_mb: usize,
431
432    #[serde(default = "default::file_cache::file_capacity_mb")]
433    pub file_capacity_mb: usize,
434
435    #[serde(default = "default::file_cache::flushers")]
436    pub flushers: usize,
437
438    #[serde(default = "default::file_cache::reclaimers")]
439    pub reclaimers: usize,
440
441    #[serde(default = "default::file_cache::recover_concurrency")]
442    pub recover_concurrency: usize,
443
444    /// Deprecated soon. Please use `throttle` to do I/O throttling instead.
445    #[serde(default = "default::file_cache::insert_rate_limit_mb")]
446    pub insert_rate_limit_mb: usize,
447
448    #[serde(default = "default::file_cache::indexer_shards")]
449    pub indexer_shards: usize,
450
451    #[serde(default = "default::file_cache::compression")]
452    pub compression: Compression,
453
454    #[serde(default = "default::file_cache::flush_buffer_threshold_mb")]
455    pub flush_buffer_threshold_mb: Option<usize>,
456
457    #[serde(default = "default::file_cache::throttle")]
458    pub throttle: Throttle,
459
460    #[serde(default = "default::file_cache::fifo_probation_ratio")]
461    pub fifo_probation_ratio: f64,
462
463    /// Set the blob index size for each blob.
464    ///
465    /// A larger blob index size can hold more blob entries, but it will also increase the io size of each blob part
466    /// write.
467    ///
468    /// NOTE:
469    ///
470    /// - The size will be aligned up to a multiplier of 4K.
471    /// - Modifying this configuration will invalidate all existing file cache data.
472    ///
473    /// Default: 16 `KiB`
474    #[serde(default = "default::file_cache::blob_index_size_kb")]
475    pub blob_index_size_kb: usize,
476
477    /// Recover mode.
478    ///
479    /// Options:
480    ///
481    /// - "None": Do not recover disk cache.
482    /// - "Quiet": Recover disk cache and skip errors.
483    /// - "Strict": Recover disk cache and panic on errors.
484    ///
485    /// More details, see [`RecoverMode::None`], [`RecoverMode::Quiet`] and [`RecoverMode::Strict`],
486    #[serde(default = "default::file_cache::recover_mode")]
487    pub recover_mode: RecoverMode,
488
489    #[serde(default = "default::file_cache::runtime_config")]
490    pub runtime_config: RuntimeOptions,
491
492    #[serde(default, flatten)]
493    #[config_doc(omitted)]
494    pub unrecognized: Unrecognized<Self>,
495}
496
497/// The subsections `[storage.object_store]`.
498#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
499#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
500pub struct ObjectStoreConfig {
501    // alias is for backward compatibility
502    #[serde(
503        default = "default::object_store_config::set_atomic_write_dir",
504        alias = "object_store_set_atomic_write_dir"
505    )]
506    pub set_atomic_write_dir: bool,
507
508    /// Retry and timeout configuration
509    /// Description retry strategy driven by exponential back-off
510    /// Exposes the timeout and retries of each Object store interface. Therefore, the total timeout for each interface is determined based on the interface's timeout/retry configuration and the exponential back-off policy.
511    #[serde(default)]
512    pub retry: ObjectStoreRetryConfig,
513
514    /// Some special configuration of S3 Backend
515    #[serde(default)]
516    pub s3: S3ObjectStoreConfig,
517
518    /// Maximum number of concurrent object store requests (read, `streaming_read`, metadata, etc.).
519    /// 0 means unlimited. When set to a positive value, a semaphore will be used to limit
520    /// the number of in-flight requests to the object store, preventing HTTP connection pool
521    /// contention under high concurrency.
522    #[serde(default = "default::object_store_config::object_store_req_concurrency_limit")]
523    pub req_concurrency_limit: usize,
524
525    /// Maximum number of concurrent HTTP requests used by the `OpenDAL` GCS backend.
526    /// 0 means unlimited.
527    #[serde(default = "default::object_store_config::http_concurrent_limit")]
528    pub http_concurrent_limit: usize,
529
530    // TODO: the following field will be deprecated after opendal is stabilized
531    #[serde(default = "default::object_store_config::opendal_upload_concurrency")]
532    pub opendal_upload_concurrency: usize,
533
534    // TODO: the following field will be deprecated after opendal is stabilized
535    #[serde(default)]
536    pub opendal_writer_abort_on_err: bool,
537
538    #[serde(default = "default::object_store_config::upload_part_size")]
539    pub upload_part_size: usize,
540}
541
542fn deserialize_max_prefetch_block_number<'de, D>(deserializer: D) -> Result<usize, D::Error>
543where
544    D: serde::Deserializer<'de>,
545{
546    let value = usize::deserialize(deserializer)?;
547    if value == 0 {
548        return Err(D::Error::custom(
549            "storage.max_prefetch_block_number must be greater than 0",
550        ));
551    }
552    Ok(value)
553}
554
555fn deserialize_iceberg_compaction_pull_interval_ms<'de, D>(deserializer: D) -> Result<u64, D::Error>
556where
557    D: serde::Deserializer<'de>,
558{
559    let value = u64::deserialize(deserializer)?;
560    if value == 0 {
561        return Err(D::Error::custom(
562            "storage.iceberg_compaction_pull_interval_ms must be greater than 0",
563        ));
564    }
565    Ok(value)
566}
567
568impl ObjectStoreConfig {
569    pub fn set_atomic_write_dir(&mut self) {
570        self.set_atomic_write_dir = true;
571    }
572}
573
574/// The subsections `[storage.object_store.s3]`.
575#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
576#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
577pub struct S3ObjectStoreConfig {
578    // alias is for backward compatibility
579    #[serde(
580        default = "default::object_store_config::s3::keepalive_ms",
581        alias = "object_store_keepalive_ms"
582    )]
583    pub keepalive_ms: Option<u64>,
584    #[serde(
585        default = "default::object_store_config::s3::recv_buffer_size",
586        alias = "object_store_recv_buffer_size"
587    )]
588    pub recv_buffer_size: Option<usize>,
589    #[serde(
590        default = "default::object_store_config::s3::send_buffer_size",
591        alias = "object_store_send_buffer_size"
592    )]
593    pub send_buffer_size: Option<usize>,
594    #[serde(
595        default = "default::object_store_config::s3::nodelay",
596        alias = "object_store_nodelay"
597    )]
598    pub nodelay: Option<bool>,
599    /// For backwards compatibility, users should use `S3ObjectStoreDeveloperConfig` instead.
600    #[serde(default = "default::object_store_config::s3::developer::retry_unknown_service_error")]
601    pub retry_unknown_service_error: bool,
602    #[serde(default = "default::object_store_config::s3::identity_resolution_timeout_s")]
603    pub identity_resolution_timeout_s: u64,
604    #[serde(default)]
605    pub developer: S3ObjectStoreDeveloperConfig,
606}
607
608/// The subsections `[storage.object_store.s3.developer]`.
609#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
610#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
611pub struct S3ObjectStoreDeveloperConfig {
612    /// Whether to retry s3 sdk error from which no error metadata is provided.
613    #[serde(
614        default = "default::object_store_config::s3::developer::retry_unknown_service_error",
615        alias = "object_store_retry_unknown_service_error"
616    )]
617    pub retry_unknown_service_error: bool,
618    /// An array of error codes that should be retried.
619    /// e.g. `["SlowDown", "TooManyRequests"]`
620    #[serde(
621        default = "default::object_store_config::s3::developer::retryable_service_error_codes",
622        alias = "object_store_retryable_service_error_codes"
623    )]
624    pub retryable_service_error_codes: Vec<String>,
625
626    // TODO: deprecate this config when we are completely deprecate aws sdk.
627    #[serde(default = "default::object_store_config::s3::developer::use_opendal")]
628    pub use_opendal: bool,
629}
630
631#[serde_with::apply(Option => #[serde(with = "none_as_empty_string")])]
632#[derive(Clone, Debug, Serialize, Deserialize, DefaultFromSerde)]
633pub struct ObjectStoreRetryConfig {
634    // A retry strategy driven by exponential back-off.
635    // The retry strategy is used for all object store operations.
636    /// Given a base duration for retry strategy in milliseconds.
637    #[serde(default = "default::object_store_config::object_store_req_backoff_interval_ms")]
638    pub req_backoff_interval_ms: u64,
639
640    /// The max delay interval for the retry strategy. No retry delay will be longer than this `Duration`.
641    #[serde(default = "default::object_store_config::object_store_req_backoff_max_delay_ms")]
642    pub req_backoff_max_delay_ms: u64,
643
644    /// A multiplicative factor that will be applied to the exponential back-off retry delay.
645    #[serde(default = "default::object_store_config::object_store_req_backoff_factor")]
646    pub req_backoff_factor: u64,
647
648    /// Maximum timeout for `upload` operation
649    #[serde(default = "default::object_store_config::object_store_upload_attempt_timeout_ms")]
650    pub upload_attempt_timeout_ms: u64,
651
652    /// Total counts of `upload` operation retries
653    #[serde(default = "default::object_store_config::object_store_upload_retry_attempts")]
654    pub upload_retry_attempts: usize,
655
656    /// Maximum timeout for `streaming_upload_init` and `streaming_upload`
657    #[serde(
658        default = "default::object_store_config::object_store_streaming_upload_attempt_timeout_ms"
659    )]
660    pub streaming_upload_attempt_timeout_ms: u64,
661
662    /// Total counts of `streaming_upload` operation retries
663    #[serde(
664        default = "default::object_store_config::object_store_streaming_upload_retry_attempts"
665    )]
666    pub streaming_upload_retry_attempts: usize,
667
668    /// Maximum timeout for `read` operation
669    #[serde(default = "default::object_store_config::object_store_read_attempt_timeout_ms")]
670    pub read_attempt_timeout_ms: u64,
671
672    /// Total counts of `read` operation retries
673    #[serde(default = "default::object_store_config::object_store_read_retry_attempts")]
674    pub read_retry_attempts: usize,
675
676    /// Maximum timeout for `streaming_read_init` and `streaming_read` operation
677    #[serde(
678        default = "default::object_store_config::object_store_streaming_read_attempt_timeout_ms"
679    )]
680    pub streaming_read_attempt_timeout_ms: u64,
681
682    /// Total counts of `streaming_read operation` retries
683    #[serde(default = "default::object_store_config::object_store_streaming_read_retry_attempts")]
684    pub streaming_read_retry_attempts: usize,
685
686    /// Maximum timeout for `metadata` operation
687    #[serde(default = "default::object_store_config::object_store_metadata_attempt_timeout_ms")]
688    pub metadata_attempt_timeout_ms: u64,
689
690    /// Total counts of `metadata` operation retries
691    #[serde(default = "default::object_store_config::object_store_metadata_retry_attempts")]
692    pub metadata_retry_attempts: usize,
693
694    /// Maximum timeout for `delete` operation
695    #[serde(default = "default::object_store_config::object_store_delete_attempt_timeout_ms")]
696    pub delete_attempt_timeout_ms: u64,
697
698    /// Total counts of `delete` operation retries
699    #[serde(default = "default::object_store_config::object_store_delete_retry_attempts")]
700    pub delete_retry_attempts: usize,
701
702    /// Maximum timeout for `delete_object` operation
703    #[serde(
704        default = "default::object_store_config::object_store_delete_objects_attempt_timeout_ms"
705    )]
706    pub delete_objects_attempt_timeout_ms: u64,
707
708    /// Total counts of `delete_object` operation retries
709    #[serde(default = "default::object_store_config::object_store_delete_objects_retry_attempts")]
710    pub delete_objects_retry_attempts: usize,
711
712    /// Maximum timeout for `list` operation
713    #[serde(default = "default::object_store_config::object_store_list_attempt_timeout_ms")]
714    pub list_attempt_timeout_ms: u64,
715
716    /// Total counts of `list` operation retries
717    #[serde(default = "default::object_store_config::object_store_list_retry_attempts")]
718    pub list_retry_attempts: usize,
719}
720
721#[derive(Debug, Clone)]
722pub enum EvictionConfig {
723    Lru(LruConfig),
724    Lfu(LfuConfig),
725    S3Fifo(S3FifoConfig),
726}
727
728impl EvictionConfig {
729    pub fn for_test() -> Self {
730        Self::Lru(LruConfig {
731            high_priority_pool_ratio: 0.0,
732        })
733    }
734}
735
736impl From<EvictionConfig> for foyer::EvictionConfig {
737    fn from(value: EvictionConfig) -> Self {
738        match value {
739            EvictionConfig::Lru(lru) => foyer::EvictionConfig::Lru(lru),
740            EvictionConfig::Lfu(lfu) => foyer::EvictionConfig::Lfu(lfu),
741            EvictionConfig::S3Fifo(s3fifo) => foyer::EvictionConfig::S3Fifo(s3fifo),
742        }
743    }
744}
745
746pub struct StorageMemoryConfig {
747    pub block_cache_capacity_mb: usize,
748    pub block_cache_shard_num: usize,
749    pub meta_cache_capacity_mb: usize,
750    pub meta_cache_shard_num: usize,
751    pub vector_block_cache_capacity_mb: usize,
752    pub vector_block_cache_shard_num: usize,
753    pub vector_meta_cache_capacity_mb: usize,
754    pub vector_meta_cache_shard_num: usize,
755    pub shared_buffer_capacity_mb: usize,
756    pub compactor_memory_limit_mb: usize,
757    pub prefetch_buffer_capacity_mb: usize,
758    pub block_cache_eviction_config: EvictionConfig,
759    pub meta_cache_eviction_config: EvictionConfig,
760    pub vector_block_cache_eviction_config: EvictionConfig,
761    pub vector_meta_cache_eviction_config: EvictionConfig,
762    pub block_file_cache_flush_buffer_threshold_mb: usize,
763    pub meta_file_cache_flush_buffer_threshold_mb: usize,
764}
765
766pub fn extract_storage_memory_config(s: &RwConfig) -> StorageMemoryConfig {
767    let block_cache_capacity_mb = s.storage.cache.block_cache_capacity_mb.unwrap_or(
768        // adapt to old version
769        s.storage
770            .block_cache_capacity_mb
771            .unwrap_or(default::storage::block_cache_capacity_mb()),
772    );
773    let meta_cache_capacity_mb = s.storage.cache.meta_cache_capacity_mb.unwrap_or(
774        // adapt to old version
775        s.storage
776            .block_cache_capacity_mb
777            .unwrap_or(default::storage::meta_cache_capacity_mb()),
778    );
779    let shared_buffer_capacity_mb = s
780        .storage
781        .shared_buffer_capacity_mb
782        .unwrap_or(default::storage::shared_buffer_capacity_mb());
783    let meta_cache_shard_num = s.storage.cache.meta_cache_shard_num.unwrap_or_else(|| {
784        let mut shard_bits = MAX_META_CACHE_SHARD_BITS;
785        while (meta_cache_capacity_mb >> shard_bits) < MIN_BUFFER_SIZE_PER_SHARD && shard_bits > 0 {
786            shard_bits -= 1;
787        }
788        shard_bits
789    });
790    let block_cache_shard_num = s.storage.cache.block_cache_shard_num.unwrap_or_else(|| {
791        let mut shard_bits = MAX_BLOCK_CACHE_SHARD_BITS;
792        while (block_cache_capacity_mb >> shard_bits) < MIN_BUFFER_SIZE_PER_SHARD && shard_bits > 0
793        {
794            shard_bits -= 1;
795        }
796        shard_bits
797    });
798    let compactor_memory_limit_mb = s
799        .storage
800        .compactor_memory_limit_mb
801        .unwrap_or(default::storage::compactor_memory_limit_mb());
802
803    let get_eviction_config = |c: &CacheEvictionConfig| {
804        match c {
805            CacheEvictionConfig::Lru {
806                high_priority_ratio_in_percent,
807            } => EvictionConfig::Lru(LruConfig {
808                high_priority_pool_ratio: high_priority_ratio_in_percent.unwrap_or(
809                    // adapt to old version
810                    s.storage
811                        .high_priority_ratio_in_percent
812                        .unwrap_or(default::storage::high_priority_ratio_in_percent()),
813                ) as f64
814                    / 100.0,
815            }),
816            CacheEvictionConfig::Lfu {
817                window_capacity_ratio_in_percent,
818                protected_capacity_ratio_in_percent,
819                cmsketch_eps,
820                cmsketch_confidence,
821            } => EvictionConfig::Lfu(LfuConfig {
822                window_capacity_ratio: window_capacity_ratio_in_percent
823                    .unwrap_or(default::storage::window_capacity_ratio_in_percent())
824                    as f64
825                    / 100.0,
826                protected_capacity_ratio: protected_capacity_ratio_in_percent
827                    .unwrap_or(default::storage::protected_capacity_ratio_in_percent())
828                    as f64
829                    / 100.0,
830                cmsketch_eps: cmsketch_eps.unwrap_or(default::storage::cmsketch_eps()),
831                cmsketch_confidence: cmsketch_confidence
832                    .unwrap_or(default::storage::cmsketch_confidence()),
833            }),
834            CacheEvictionConfig::S3Fifo {
835                small_queue_capacity_ratio_in_percent,
836                ghost_queue_capacity_ratio_in_percent,
837                small_to_main_freq_threshold,
838            } => EvictionConfig::S3Fifo(S3FifoConfig {
839                small_queue_capacity_ratio: small_queue_capacity_ratio_in_percent
840                    .unwrap_or(default::storage::small_queue_capacity_ratio_in_percent())
841                    as f64
842                    / 100.0,
843                ghost_queue_capacity_ratio: ghost_queue_capacity_ratio_in_percent
844                    .unwrap_or(default::storage::ghost_queue_capacity_ratio_in_percent())
845                    as f64
846                    / 100.0,
847                small_to_main_freq_threshold: small_to_main_freq_threshold
848                    .unwrap_or(default::storage::small_to_main_freq_threshold()),
849            }),
850        }
851    };
852
853    let block_cache_eviction_config = get_eviction_config(&s.storage.cache.block_cache_eviction);
854    let meta_cache_eviction_config = get_eviction_config(&s.storage.cache.meta_cache_eviction);
855    let vector_block_cache_eviction_config =
856        get_eviction_config(&s.storage.cache.vector_block_cache_eviction_config);
857    let vector_meta_cache_eviction_config =
858        get_eviction_config(&s.storage.cache.vector_meta_cache_eviction_config);
859
860    let prefetch_buffer_capacity_mb =
861        s.storage
862            .shared_buffer_capacity_mb
863            .unwrap_or(match &block_cache_eviction_config {
864                EvictionConfig::Lru(lru) => {
865                    ((1.0 - lru.high_priority_pool_ratio) * block_cache_capacity_mb as f64) as usize
866                }
867                EvictionConfig::Lfu(lfu) => {
868                    ((1.0 - lfu.protected_capacity_ratio) * block_cache_capacity_mb as f64) as usize
869                }
870                EvictionConfig::S3Fifo(s3fifo) => {
871                    (s3fifo.small_queue_capacity_ratio * block_cache_capacity_mb as f64) as usize
872                }
873            });
874
875    let block_file_cache_flush_buffer_threshold_mb = s
876        .storage
877        .data_file_cache
878        .flush_buffer_threshold_mb
879        .unwrap_or(default::storage::block_file_cache_flush_buffer_threshold_mb());
880    let meta_file_cache_flush_buffer_threshold_mb = s
881        .storage
882        .meta_file_cache
883        .flush_buffer_threshold_mb
884        .unwrap_or(default::storage::block_file_cache_flush_buffer_threshold_mb());
885
886    StorageMemoryConfig {
887        block_cache_capacity_mb,
888        block_cache_shard_num,
889        meta_cache_capacity_mb,
890        meta_cache_shard_num,
891        vector_block_cache_capacity_mb: s.storage.cache.vector_block_cache_capacity_mb,
892        vector_block_cache_shard_num: s.storage.cache.vector_block_cache_shard_num,
893        vector_meta_cache_capacity_mb: s.storage.cache.vector_meta_cache_capacity_mb,
894        vector_meta_cache_shard_num: s.storage.cache.vector_meta_cache_shard_num,
895        shared_buffer_capacity_mb,
896        compactor_memory_limit_mb,
897        prefetch_buffer_capacity_mb,
898        block_cache_eviction_config,
899        meta_cache_eviction_config,
900        vector_block_cache_eviction_config,
901        vector_meta_cache_eviction_config,
902        block_file_cache_flush_buffer_threshold_mb,
903        meta_file_cache_flush_buffer_threshold_mb,
904    }
905}
906
907pub mod default {
908
909    pub mod storage {
910        pub fn share_buffers_sync_parallelism() -> u32 {
911            1
912        }
913
914        pub fn share_buffer_compaction_worker_threads_number() -> u32 {
915            4
916        }
917
918        pub fn shared_buffer_capacity_mb() -> usize {
919            1024
920        }
921
922        pub fn shared_buffer_flush_ratio() -> f32 {
923            0.8
924        }
925
926        pub fn shared_buffer_min_batch_flush_size_mb() -> usize {
927            800
928        }
929
930        pub fn imm_merge_threshold() -> usize {
931            0 // disable
932        }
933
934        pub fn write_conflict_detection_enabled() -> bool {
935            cfg!(debug_assertions)
936        }
937
938        pub fn max_cached_recent_versions_number() -> usize {
939            60
940        }
941
942        pub fn block_cache_capacity_mb() -> usize {
943            512
944        }
945
946        pub fn high_priority_ratio_in_percent() -> usize {
947            70
948        }
949
950        pub fn window_capacity_ratio_in_percent() -> usize {
951            10
952        }
953
954        pub fn protected_capacity_ratio_in_percent() -> usize {
955            80
956        }
957
958        pub fn cmsketch_eps() -> f64 {
959            0.002
960        }
961
962        pub fn cmsketch_confidence() -> f64 {
963            0.95
964        }
965
966        pub fn small_queue_capacity_ratio_in_percent() -> usize {
967            10
968        }
969
970        pub fn ghost_queue_capacity_ratio_in_percent() -> usize {
971            1000
972        }
973
974        pub fn small_to_main_freq_threshold() -> u8 {
975            1
976        }
977
978        pub fn meta_cache_capacity_mb() -> usize {
979            128
980        }
981
982        pub fn disable_remote_compactor() -> bool {
983            false
984        }
985
986        pub fn share_buffer_upload_concurrency() -> usize {
987            8
988        }
989
990        pub fn compactor_memory_limit_mb() -> usize {
991            512
992        }
993
994        pub fn compactor_max_task_multiplier() -> f32 {
995            match std::env::var("RW_COMPACTOR_MODE")
996                .unwrap_or_default()
997                .as_str()
998            {
999                mode if mode.contains("iceberg") => 12.0000,
1000                _ => 3.0000,
1001            }
1002        }
1003
1004        pub fn compactor_memory_available_proportion() -> f64 {
1005            0.8
1006        }
1007
1008        pub fn sstable_id_remote_fetch_number() -> u32 {
1009            10
1010        }
1011
1012        pub fn min_sstable_size_mb() -> u32 {
1013            32
1014        }
1015
1016        pub fn min_sst_size_for_streaming_upload() -> u64 {
1017            // 32MB
1018            32 * 1024 * 1024
1019        }
1020
1021        pub fn max_concurrent_compaction_task_number() -> u64 {
1022            16
1023        }
1024
1025        pub fn max_preload_wait_time_mill() -> u64 {
1026            0
1027        }
1028
1029        pub fn max_version_pinning_duration_sec() -> u64 {
1030            3 * 3600
1031        }
1032
1033        pub fn compactor_max_sst_key_count() -> u64 {
1034            2 * 1024 * 1024 // 200w
1035        }
1036
1037        pub fn compact_iter_recreate_timeout_ms() -> u64 {
1038            10 * 60 * 1000
1039        }
1040
1041        pub fn compactor_iter_max_io_retry_times() -> usize {
1042            8
1043        }
1044
1045        pub fn shorten_block_meta_key_threshold() -> Option<usize> {
1046            None
1047        }
1048
1049        pub fn compactor_max_sst_size() -> u64 {
1050            512 * 1024 * 1024 // 512m
1051        }
1052
1053        pub fn enable_fast_compaction() -> bool {
1054            true
1055        }
1056
1057        pub fn check_compaction_result() -> bool {
1058            false
1059        }
1060
1061        pub fn max_preload_io_retry_times() -> usize {
1062            3
1063        }
1064
1065        pub fn mem_table_spill_threshold() -> usize {
1066            4 << 20
1067        }
1068
1069        pub fn compactor_fast_max_compact_delete_ratio() -> u32 {
1070            40
1071        }
1072
1073        pub fn compactor_fast_max_compact_task_size() -> u64 {
1074            2 * 1024 * 1024 * 1024 // 2g
1075        }
1076
1077        pub fn max_prefetch_block_number() -> usize {
1078            16
1079        }
1080
1081        pub fn compactor_concurrent_uploading_sst_count() -> Option<usize> {
1082            None
1083        }
1084
1085        pub fn compactor_max_overlap_sst_count() -> usize {
1086            64
1087        }
1088
1089        pub fn compactor_max_preload_meta_file_count() -> usize {
1090            32
1091        }
1092
1093        pub fn vector_file_block_size_kb() -> usize {
1094            1024
1095        }
1096
1097        pub fn vector_block_cache_capacity_mb() -> usize {
1098            16
1099        }
1100
1101        pub fn vector_block_cache_shard_num() -> usize {
1102            16
1103        }
1104
1105        pub fn vector_meta_cache_capacity_mb() -> usize {
1106            16
1107        }
1108
1109        pub fn vector_meta_cache_shard_num() -> usize {
1110            16
1111        }
1112
1113        // deprecated
1114        pub fn table_info_statistic_history_times() -> usize {
1115            240
1116        }
1117
1118        pub fn block_file_cache_flush_buffer_threshold_mb() -> usize {
1119            256
1120        }
1121
1122        pub fn meta_file_cache_flush_buffer_threshold_mb() -> usize {
1123            64
1124        }
1125
1126        pub fn time_travel_version_cache_capacity() -> u64 {
1127            10
1128        }
1129
1130        pub fn table_change_log_cache_capacity() -> u64 {
1131            60
1132        }
1133
1134        pub fn sst_skip_bloom_filter_in_serde() -> bool {
1135            false
1136        }
1137
1138        pub fn iceberg_compaction_enable_validate() -> bool {
1139            false
1140        }
1141
1142        pub fn iceberg_compaction_max_record_batch_rows() -> usize {
1143            1024
1144        }
1145
1146        pub fn iceberg_compaction_write_parquet_max_row_group_rows() -> usize {
1147            1024 * 100 // 100k
1148        }
1149
1150        pub fn iceberg_compaction_min_size_per_partition_mb() -> u32 {
1151            1024
1152        }
1153
1154        pub fn iceberg_compaction_max_file_count_per_partition() -> u32 {
1155            32
1156        }
1157
1158        pub fn iceberg_compaction_task_parallelism_ratio() -> f32 {
1159            4.0
1160        }
1161
1162        pub fn iceberg_compaction_enable_heuristic_output_parallelism() -> bool {
1163            false
1164        }
1165
1166        pub fn iceberg_compaction_max_concurrent_closes() -> usize {
1167            8
1168        }
1169
1170        pub fn iceberg_compaction_enable_dynamic_size_estimation() -> bool {
1171            true
1172        }
1173
1174        pub fn iceberg_compaction_size_estimation_smoothing_factor() -> f64 {
1175            0.3
1176        }
1177
1178        pub fn iceberg_compaction_pending_parallelism_budget_multiplier() -> f32 {
1179            4.0
1180        }
1181
1182        pub fn iceberg_compaction_pull_interval_ms() -> u64 {
1183            5000
1184        }
1185
1186        pub fn iceberg_compaction_enable_prefetch() -> bool {
1187            false
1188        }
1189
1190        pub fn iceberg_compaction_target_binpack_group_size_mb() -> Option<u64> {
1191            Some(100 * 1024) // 100GB
1192        }
1193
1194        pub fn iceberg_compaction_min_group_size_mb() -> Option<u64> {
1195            None
1196        }
1197
1198        pub fn iceberg_compaction_min_group_file_count() -> Option<usize> {
1199            None
1200        }
1201    }
1202
1203    pub mod file_cache {
1204        use std::num::NonZeroUsize;
1205
1206        use foyer::{Compression, RecoverMode, RuntimeOptions, Throttle, TokioRuntimeOptions};
1207
1208        pub fn dir() -> String {
1209            "".to_owned()
1210        }
1211
1212        pub fn capacity_mb() -> usize {
1213            1024
1214        }
1215
1216        pub fn file_capacity_mb() -> usize {
1217            64
1218        }
1219
1220        pub fn flushers() -> usize {
1221            4
1222        }
1223
1224        pub fn reclaimers() -> usize {
1225            4
1226        }
1227
1228        pub fn recover_concurrency() -> usize {
1229            8
1230        }
1231
1232        pub fn insert_rate_limit_mb() -> usize {
1233            0
1234        }
1235
1236        pub fn indexer_shards() -> usize {
1237            64
1238        }
1239
1240        pub fn compression() -> Compression {
1241            Compression::None
1242        }
1243
1244        pub fn flush_buffer_threshold_mb() -> Option<usize> {
1245            None
1246        }
1247
1248        pub fn fifo_probation_ratio() -> f64 {
1249            0.1
1250        }
1251
1252        pub fn blob_index_size_kb() -> usize {
1253            16
1254        }
1255
1256        pub fn recover_mode() -> RecoverMode {
1257            RecoverMode::Quiet
1258        }
1259
1260        pub fn runtime_config() -> RuntimeOptions {
1261            RuntimeOptions::Unified(TokioRuntimeOptions::default())
1262        }
1263
1264        pub fn throttle() -> Throttle {
1265            Throttle::new()
1266                .with_iops_counter(foyer::IopsCounter::PerIoSize(
1267                    NonZeroUsize::new(128 * 1024).unwrap(),
1268                ))
1269                .with_read_iops(100000)
1270                .with_write_iops(100000)
1271                .with_write_throughput(1024 * 1024 * 1024)
1272                .with_read_throughput(1024 * 1024 * 1024)
1273        }
1274    }
1275
1276    pub mod cache_refill {
1277        pub fn meta_refill_concurrency() -> usize {
1278            0
1279        }
1280
1281        pub fn data_refill_levels() -> Vec<u32> {
1282            vec![]
1283        }
1284
1285        pub fn timeout_ms() -> u64 {
1286            6000
1287        }
1288
1289        pub fn concurrency() -> usize {
1290            10
1291        }
1292
1293        pub fn unit() -> usize {
1294            64
1295        }
1296
1297        pub fn threshold() -> f64 {
1298            0.5
1299        }
1300
1301        pub fn recent_filter_shards() -> usize {
1302            16
1303        }
1304
1305        pub fn recent_filter_layers() -> usize {
1306            6
1307        }
1308
1309        pub fn recent_filter_rotate_interval_ms() -> usize {
1310            10000
1311        }
1312
1313        pub fn skip_recent_filter() -> bool {
1314            false
1315        }
1316    }
1317
1318    pub mod object_store_config {
1319        const DEFAULT_REQ_BACKOFF_INTERVAL_MS: u64 = 1000; // 1s
1320        const DEFAULT_REQ_BACKOFF_MAX_DELAY_MS: u64 = 10 * 1000; // 10s
1321        const DEFAULT_REQ_MAX_RETRY_ATTEMPTS: usize = 3;
1322
1323        pub fn set_atomic_write_dir() -> bool {
1324            false
1325        }
1326
1327        pub fn object_store_req_concurrency_limit() -> usize {
1328            0
1329        }
1330
1331        pub fn http_concurrent_limit() -> usize {
1332            0
1333        }
1334
1335        pub fn object_store_req_backoff_interval_ms() -> u64 {
1336            DEFAULT_REQ_BACKOFF_INTERVAL_MS
1337        }
1338
1339        pub fn object_store_req_backoff_max_delay_ms() -> u64 {
1340            DEFAULT_REQ_BACKOFF_MAX_DELAY_MS // 10s
1341        }
1342
1343        pub fn object_store_req_backoff_factor() -> u64 {
1344            2
1345        }
1346
1347        pub fn object_store_upload_attempt_timeout_ms() -> u64 {
1348            8 * 1000 // 8s
1349        }
1350
1351        pub fn object_store_upload_retry_attempts() -> usize {
1352            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1353        }
1354
1355        // init + upload_part + finish
1356        pub fn object_store_streaming_upload_attempt_timeout_ms() -> u64 {
1357            5 * 1000 // 5s
1358        }
1359
1360        pub fn object_store_streaming_upload_retry_attempts() -> usize {
1361            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1362        }
1363
1364        // tips: depend on block_size
1365        pub fn object_store_read_attempt_timeout_ms() -> u64 {
1366            8 * 1000 // 8s
1367        }
1368
1369        pub fn object_store_read_retry_attempts() -> usize {
1370            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1371        }
1372
1373        pub fn object_store_streaming_read_attempt_timeout_ms() -> u64 {
1374            3 * 1000 // 3s
1375        }
1376
1377        pub fn object_store_streaming_read_retry_attempts() -> usize {
1378            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1379        }
1380
1381        pub fn object_store_metadata_attempt_timeout_ms() -> u64 {
1382            60 * 1000 // 1min
1383        }
1384
1385        pub fn object_store_metadata_retry_attempts() -> usize {
1386            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1387        }
1388
1389        pub fn object_store_delete_attempt_timeout_ms() -> u64 {
1390            5 * 1000
1391        }
1392
1393        pub fn object_store_delete_retry_attempts() -> usize {
1394            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1395        }
1396
1397        // tips: depend on batch size
1398        pub fn object_store_delete_objects_attempt_timeout_ms() -> u64 {
1399            5 * 1000
1400        }
1401
1402        pub fn object_store_delete_objects_retry_attempts() -> usize {
1403            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1404        }
1405
1406        pub fn object_store_list_attempt_timeout_ms() -> u64 {
1407            10 * 60 * 1000
1408        }
1409
1410        pub fn object_store_list_retry_attempts() -> usize {
1411            DEFAULT_REQ_MAX_RETRY_ATTEMPTS
1412        }
1413
1414        pub fn opendal_upload_concurrency() -> usize {
1415            256
1416        }
1417
1418        pub fn upload_part_size() -> usize {
1419            // 16m
1420            16 * 1024 * 1024
1421        }
1422
1423        pub mod s3 {
1424            const DEFAULT_IDENTITY_RESOLUTION_TIMEOUT_S: u64 = 5;
1425
1426            const DEFAULT_KEEPALIVE_MS: u64 = 600 * 1000; // 10min
1427
1428            pub fn keepalive_ms() -> Option<u64> {
1429                Some(DEFAULT_KEEPALIVE_MS) // 10min
1430            }
1431
1432            pub fn recv_buffer_size() -> Option<usize> {
1433                Some(1 << 21) // 2m
1434            }
1435
1436            pub fn send_buffer_size() -> Option<usize> {
1437                None
1438            }
1439
1440            pub fn nodelay() -> Option<bool> {
1441                Some(true)
1442            }
1443
1444            pub fn identity_resolution_timeout_s() -> u64 {
1445                DEFAULT_IDENTITY_RESOLUTION_TIMEOUT_S
1446            }
1447
1448            pub mod developer {
1449                pub fn retry_unknown_service_error() -> bool {
1450                    false
1451                }
1452
1453                pub fn retryable_service_error_codes() -> Vec<String> {
1454                    vec!["SlowDown".into(), "TooManyRequests".into()]
1455                }
1456
1457                pub fn use_opendal() -> bool {
1458                    true
1459                }
1460            }
1461        }
1462    }
1463}