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