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