Skip to main content

risingwave_storage/
opts.rs

1// Copyright 2023 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 risingwave_common::config::streaming::CacheRefillPolicy;
16use risingwave_common::config::{
17    EvictionConfig, ObjectStoreConfig, RwConfig, StorageMemoryConfig, extract_storage_memory_config,
18};
19use risingwave_common::system_param::reader::{SystemParamsRead, SystemParamsReader};
20use risingwave_common::system_param::system_params_for_test;
21
22#[derive(Clone, Debug)]
23pub struct StorageOpts {
24    /// The size of parallel task for one compact/flush job.
25    pub parallel_compact_size_mb: u32,
26    /// Target size of the Sstable.
27    pub sstable_size_mb: u32,
28    /// Minimal target size of the Sstable to store data of different state-table in independent files as soon as possible.
29    pub min_sstable_size_mb: u32,
30    /// Size of each block in bytes in SST.
31    pub block_size_kb: u32,
32    /// Deprecated and ignored by SST filter builders; kept for backward compatibility.
33    pub bloom_false_positive: f64,
34    /// parallelism while syncing share buffers into L0 SST. Should NOT be 0.
35    pub share_buffers_sync_parallelism: u32,
36    /// Worker threads number of dedicated tokio runtime for share buffer compaction. 0 means use
37    /// tokio's default value (number of CPU core).
38    pub share_buffer_compaction_worker_threads_number: u32,
39    /// Maximum shared buffer size, writes attempting to exceed the capacity will stall until there
40    /// is enough space.
41    pub shared_buffer_capacity_mb: usize,
42    /// The shared buffer will start flushing data to object when the ratio of memory usage to the
43    /// shared buffer capacity exceed such ratio.
44    pub shared_buffer_flush_ratio: f32,
45    /// The minimum total flush size of shared buffer spill. When a shared buffer spill is trigger,
46    /// the total flush size across multiple epochs should be at least higher than this size.
47    pub shared_buffer_min_batch_flush_size_mb: usize,
48    /// Remote directory for storing data and metadata objects.
49    pub data_directory: String,
50    /// Whether to enable write conflict detection
51    pub write_conflict_detection_enabled: bool,
52    /// Capacity of sstable block cache.
53    pub block_cache_capacity_mb: usize,
54    /// the number of block-cache shard. Less shard means that more concurrent-conflict.
55    pub block_cache_shard_num: usize,
56    /// Eviction config for block cache.
57    pub block_cache_eviction_config: EvictionConfig,
58    /// Capacity of sstable meta cache.
59    pub meta_cache_capacity_mb: usize,
60    /// the number of meta-cache shard. Less shard means that more concurrent-conflict.
61    pub meta_cache_shard_num: usize,
62    /// Eviction config for meta cache.
63    pub meta_cache_eviction_config: EvictionConfig,
64    /// max memory usage for large query.
65    pub prefetch_buffer_capacity_mb: usize,
66
67    pub max_cached_recent_versions_number: usize,
68
69    pub max_prefetch_block_number: usize,
70
71    pub disable_remote_compactor: bool,
72    /// Number of tasks shared buffer can upload in parallel.
73    pub share_buffer_upload_concurrency: usize,
74    /// Capacity of sstable meta cache.
75    pub compactor_memory_limit_mb: usize,
76    /// compactor streaming iterator recreate timeout.
77    /// deprecated
78    pub compact_iter_recreate_timeout_ms: u64,
79    /// Number of SST ids fetched from meta per RPC
80    pub sstable_id_remote_fetch_number: u32,
81    /// Whether to enable streaming upload for sstable.
82    pub min_sst_size_for_streaming_upload: u64,
83    pub max_concurrent_compaction_task_number: u64,
84    pub max_version_pinning_duration_sec: u64,
85    pub compactor_iter_max_io_retry_times: usize,
86
87    /// If set, block metadata keys will be shortened when their length exceeds this threshold.
88    pub shorten_block_meta_key_threshold: Option<usize>,
89
90    pub data_file_cache_dir: String,
91    pub data_file_cache_capacity_mb: usize,
92    pub data_file_cache_file_capacity_mb: usize,
93    pub data_file_cache_flushers: usize,
94    pub data_file_cache_reclaimers: usize,
95    pub data_file_cache_recover_mode: foyer::RecoverMode,
96    pub data_file_cache_recover_concurrency: usize,
97    pub data_file_cache_indexer_shards: usize,
98    pub data_file_cache_compression: foyer::Compression,
99    pub data_file_cache_flush_buffer_threshold_mb: usize,
100    pub data_file_cache_fifo_probation_ratio: f64,
101    pub data_file_cache_blob_index_size_kb: usize,
102    pub data_file_cache_runtime_config: foyer::RuntimeOptions,
103    pub data_file_cache_throttle: foyer::Throttle,
104
105    pub cache_refill_data_refill_levels: Vec<u32>,
106    pub cache_refill_timeout_ms: u64,
107    pub cache_refill_meta_refill_concurrency: usize,
108    pub cache_refill_concurrency: usize,
109    pub cache_refill_recent_filter_shards: usize,
110    pub cache_refill_recent_filter_layers: usize,
111    pub cache_refill_recent_filter_rotate_interval_ms: usize,
112    pub cache_refill_unit: usize,
113    pub cache_refill_threshold: f64,
114    pub cache_refill_skip_recent_filter: bool,
115    pub cache_refill_skip_inheritance_filter: bool,
116    pub cache_refill_table_cache_refill_default_policy: CacheRefillPolicy,
117
118    pub meta_file_cache_dir: String,
119    pub meta_file_cache_capacity_mb: usize,
120    pub meta_file_cache_file_capacity_mb: usize,
121    pub meta_file_cache_flushers: usize,
122    pub meta_file_cache_reclaimers: usize,
123    pub meta_file_cache_recover_mode: foyer::RecoverMode,
124    pub meta_file_cache_recover_concurrency: usize,
125    pub meta_file_cache_indexer_shards: usize,
126    pub meta_file_cache_compression: foyer::Compression,
127    pub meta_file_cache_flush_buffer_threshold_mb: usize,
128    pub meta_file_cache_fifo_probation_ratio: f64,
129    pub meta_file_cache_blob_index_size_kb: usize,
130    pub meta_file_cache_runtime_config: foyer::RuntimeOptions,
131    pub meta_file_cache_throttle: foyer::Throttle,
132    pub sst_skip_bloom_filter_in_serde: bool,
133
134    pub vector_file_block_size_kb: usize,
135    pub vector_block_cache_capacity_mb: usize,
136    pub vector_block_cache_shard_num: usize,
137    pub vector_block_cache_eviction_config: EvictionConfig,
138    pub vector_meta_cache_capacity_mb: usize,
139    pub vector_meta_cache_shard_num: usize,
140    pub vector_meta_cache_eviction_config: EvictionConfig,
141
142    /// The storage url for storing backups.
143    pub backup_storage_url: String,
144    /// The storage directory for storing backups.
145    pub backup_storage_directory: String,
146    /// max time which wait for preload. 0 represent do not do any preload.
147    pub max_preload_wait_time_mill: u64,
148
149    pub compactor_max_sst_key_count: u64,
150    pub compactor_max_task_multiplier: f32,
151    pub compactor_max_sst_size: u64,
152    /// enable `FastCompactorRunner`.
153    pub enable_fast_compaction: bool,
154    pub check_compaction_result: bool,
155    pub max_preload_io_retry_times: usize,
156    pub compactor_fast_max_compact_delete_ratio: u32,
157    pub compactor_fast_max_compact_task_size: u64,
158
159    pub mem_table_spill_threshold: usize,
160
161    pub compactor_concurrent_uploading_sst_count: Option<usize>,
162
163    pub compactor_max_overlap_sst_count: usize,
164
165    /// The maximum number of meta files that can be preloaded.
166    pub compactor_max_preload_meta_file_count: usize,
167
168    pub object_store_config: ObjectStoreConfig,
169    pub time_travel_version_cache_capacity: u64,
170    pub table_change_log_cache_capacity: u64,
171
172    pub iceberg_compaction_enable_validate: bool,
173    pub iceberg_compaction_max_record_batch_rows: usize,
174    pub iceberg_compaction_write_parquet_max_row_group_rows: usize,
175    pub iceberg_compaction_min_size_per_partition_mb: u32,
176    pub iceberg_compaction_max_file_count_per_partition: u32,
177    pub iceberg_compaction_target_binpack_group_size_mb: Option<u64>,
178    pub iceberg_compaction_min_group_size_mb: Option<u64>,
179    pub iceberg_compaction_min_group_file_count: Option<usize>,
180
181    /// The ratio of iceberg compaction max parallelism to the number of CPU cores
182    pub iceberg_compaction_task_parallelism_ratio: f32,
183    /// Whether to enable heuristic output parallelism in iceberg compaction.
184    pub iceberg_compaction_enable_heuristic_output_parallelism: bool,
185    /// Maximum number of concurrent file close operations
186    pub iceberg_compaction_max_concurrent_closes: usize,
187    /// Whether to enable dynamic size estimation for iceberg compaction.
188    pub iceberg_compaction_enable_dynamic_size_estimation: bool,
189    /// The smoothing factor for size estimation in iceberg compaction.(default: 0.3)
190    pub iceberg_compaction_size_estimation_smoothing_factor: f64,
191    /// Multiplier for pending waiting parallelism budget for iceberg compaction task queue.
192    pub iceberg_compaction_pending_parallelism_budget_multiplier: f32,
193    /// Pull interval for iceberg compaction task requests in milliseconds.
194    pub iceberg_compaction_pull_interval_ms: u64,
195    /// Whether to enable prefetch for iceberg compaction.
196    pub iceberg_compaction_enable_prefetch: bool,
197}
198
199impl Default for StorageOpts {
200    fn default() -> Self {
201        let c = RwConfig::default();
202        let p = system_params_for_test();
203        let s = extract_storage_memory_config(&c);
204        Self::from((&c, &p.into(), &s))
205    }
206}
207
208impl From<(&RwConfig, &SystemParamsReader, &StorageMemoryConfig)> for StorageOpts {
209    fn from((c, p, s): (&RwConfig, &SystemParamsReader, &StorageMemoryConfig)) -> Self {
210        let mut data_file_cache_throttle = c.storage.data_file_cache.throttle.clone();
211        if data_file_cache_throttle.write_throughput.is_none() {
212            data_file_cache_throttle = data_file_cache_throttle.with_write_throughput(
213                c.storage.data_file_cache.insert_rate_limit_mb * 1024 * 1024,
214            );
215        }
216        let mut meta_file_cache_throttle = c.storage.meta_file_cache.throttle.clone();
217        if meta_file_cache_throttle.write_throughput.is_none() {
218            meta_file_cache_throttle = meta_file_cache_throttle.with_write_throughput(
219                c.storage.meta_file_cache.insert_rate_limit_mb * 1024 * 1024,
220            );
221        }
222
223        Self {
224            parallel_compact_size_mb: p.parallel_compact_size_mb(),
225            sstable_size_mb: p.sstable_size_mb(),
226            min_sstable_size_mb: c.storage.min_sstable_size_mb,
227            block_size_kb: p.block_size_kb(),
228            bloom_false_positive: p.bloom_false_positive(),
229            share_buffers_sync_parallelism: c.storage.share_buffers_sync_parallelism,
230            share_buffer_compaction_worker_threads_number: c
231                .storage
232                .share_buffer_compaction_worker_threads_number,
233            shared_buffer_capacity_mb: s.shared_buffer_capacity_mb,
234            shared_buffer_flush_ratio: c.storage.shared_buffer_flush_ratio,
235            shared_buffer_min_batch_flush_size_mb: c.storage.shared_buffer_min_batch_flush_size_mb,
236            data_directory: p.data_directory().to_owned(),
237            write_conflict_detection_enabled: c.storage.write_conflict_detection_enabled,
238            block_cache_capacity_mb: s.block_cache_capacity_mb,
239            block_cache_shard_num: s.block_cache_shard_num,
240            block_cache_eviction_config: s.block_cache_eviction_config.clone(),
241            meta_cache_capacity_mb: s.meta_cache_capacity_mb,
242            meta_cache_shard_num: s.meta_cache_shard_num,
243            meta_cache_eviction_config: s.meta_cache_eviction_config.clone(),
244            prefetch_buffer_capacity_mb: s.prefetch_buffer_capacity_mb,
245            max_cached_recent_versions_number: c.storage.max_cached_recent_versions_number,
246            max_prefetch_block_number: c.storage.max_prefetch_block_number,
247            disable_remote_compactor: c.storage.disable_remote_compactor,
248            share_buffer_upload_concurrency: c.storage.share_buffer_upload_concurrency,
249            compactor_memory_limit_mb: s.compactor_memory_limit_mb,
250            sstable_id_remote_fetch_number: c.storage.sstable_id_remote_fetch_number,
251            min_sst_size_for_streaming_upload: c.storage.min_sst_size_for_streaming_upload,
252            max_concurrent_compaction_task_number: c.storage.max_concurrent_compaction_task_number,
253            max_version_pinning_duration_sec: c.storage.max_version_pinning_duration_sec,
254            data_file_cache_dir: c.storage.data_file_cache.dir.clone(),
255            data_file_cache_capacity_mb: c.storage.data_file_cache.capacity_mb,
256            data_file_cache_file_capacity_mb: c.storage.data_file_cache.file_capacity_mb,
257            data_file_cache_flushers: c.storage.data_file_cache.flushers,
258            data_file_cache_reclaimers: c.storage.data_file_cache.reclaimers,
259            data_file_cache_recover_mode: c.storage.data_file_cache.recover_mode,
260            data_file_cache_recover_concurrency: c.storage.data_file_cache.recover_concurrency,
261            data_file_cache_indexer_shards: c.storage.data_file_cache.indexer_shards,
262            data_file_cache_compression: c.storage.data_file_cache.compression,
263            data_file_cache_flush_buffer_threshold_mb: s.block_file_cache_flush_buffer_threshold_mb,
264            data_file_cache_fifo_probation_ratio: c.storage.data_file_cache.fifo_probation_ratio,
265            data_file_cache_blob_index_size_kb: c.storage.data_file_cache.blob_index_size_kb,
266            data_file_cache_runtime_config: c.storage.data_file_cache.runtime_config.clone(),
267            data_file_cache_throttle,
268            meta_file_cache_dir: c.storage.meta_file_cache.dir.clone(),
269            meta_file_cache_capacity_mb: c.storage.meta_file_cache.capacity_mb,
270            meta_file_cache_file_capacity_mb: c.storage.meta_file_cache.file_capacity_mb,
271            meta_file_cache_flushers: c.storage.meta_file_cache.flushers,
272            meta_file_cache_reclaimers: c.storage.meta_file_cache.reclaimers,
273            meta_file_cache_recover_mode: c.storage.meta_file_cache.recover_mode,
274            meta_file_cache_recover_concurrency: c.storage.meta_file_cache.recover_concurrency,
275            meta_file_cache_indexer_shards: c.storage.meta_file_cache.indexer_shards,
276            meta_file_cache_compression: c.storage.meta_file_cache.compression,
277            meta_file_cache_flush_buffer_threshold_mb: s.meta_file_cache_flush_buffer_threshold_mb,
278            meta_file_cache_fifo_probation_ratio: c.storage.meta_file_cache.fifo_probation_ratio,
279            meta_file_cache_blob_index_size_kb: c.storage.meta_file_cache.blob_index_size_kb,
280            meta_file_cache_runtime_config: c.storage.meta_file_cache.runtime_config.clone(),
281            meta_file_cache_throttle,
282            sst_skip_bloom_filter_in_serde: c.storage.sst_skip_bloom_filter_in_serde,
283            cache_refill_data_refill_levels: c.storage.cache_refill.data_refill_levels.clone(),
284            cache_refill_timeout_ms: c.storage.cache_refill.timeout_ms,
285            cache_refill_meta_refill_concurrency: c.storage.cache_refill.meta_refill_concurrency,
286            cache_refill_concurrency: c.storage.cache_refill.concurrency,
287            cache_refill_recent_filter_shards: c.storage.cache_refill.recent_filter_shards,
288            cache_refill_recent_filter_layers: c.storage.cache_refill.recent_filter_layers,
289            cache_refill_recent_filter_rotate_interval_ms: c
290                .storage
291                .cache_refill
292                .recent_filter_rotate_interval_ms,
293            cache_refill_unit: c.storage.cache_refill.unit,
294            cache_refill_threshold: c.storage.cache_refill.threshold,
295            cache_refill_skip_recent_filter: c.storage.cache_refill.skip_recent_filter,
296            cache_refill_skip_inheritance_filter: c.storage.cache_refill.skip_inheritance_filter,
297            cache_refill_table_cache_refill_default_policy: c
298                .streaming
299                .developer
300                .cache_refill_policy,
301            max_preload_wait_time_mill: c.storage.max_preload_wait_time_mill,
302            compact_iter_recreate_timeout_ms: c.storage.compact_iter_recreate_timeout_ms,
303
304            max_preload_io_retry_times: c.storage.max_preload_io_retry_times,
305            backup_storage_url: p.backup_storage_url().to_owned(),
306            backup_storage_directory: p.backup_storage_directory().to_owned(),
307            compactor_max_sst_key_count: c.storage.compactor_max_sst_key_count,
308            compactor_max_task_multiplier: c.storage.compactor_max_task_multiplier,
309            compactor_max_sst_size: c.storage.compactor_max_sst_size,
310            enable_fast_compaction: c.storage.enable_fast_compaction,
311            check_compaction_result: c.storage.check_compaction_result,
312            mem_table_spill_threshold: c.storage.mem_table_spill_threshold,
313            object_store_config: c.storage.object_store.clone(),
314            compactor_fast_max_compact_delete_ratio: c
315                .storage
316                .compactor_fast_max_compact_delete_ratio,
317            compactor_fast_max_compact_task_size: c.storage.compactor_fast_max_compact_task_size,
318            compactor_iter_max_io_retry_times: c.storage.compactor_iter_max_io_retry_times,
319            shorten_block_meta_key_threshold: c.storage.shorten_block_meta_key_threshold,
320            compactor_concurrent_uploading_sst_count: c
321                .storage
322                .compactor_concurrent_uploading_sst_count,
323            time_travel_version_cache_capacity: c.storage.time_travel_version_cache_capacity,
324            table_change_log_cache_capacity: c.storage.table_change_log_cache_capacity,
325            compactor_max_overlap_sst_count: c.storage.compactor_max_overlap_sst_count,
326            compactor_max_preload_meta_file_count: c.storage.compactor_max_preload_meta_file_count,
327
328            iceberg_compaction_enable_validate: c.storage.iceberg_compaction_enable_validate,
329            iceberg_compaction_max_record_batch_rows: c
330                .storage
331                .iceberg_compaction_max_record_batch_rows,
332            #[expect(deprecated)]
333            iceberg_compaction_write_parquet_max_row_group_rows: c
334                .storage
335                .iceberg_compaction_write_parquet_max_row_group_rows,
336            iceberg_compaction_min_size_per_partition_mb: c
337                .storage
338                .iceberg_compaction_min_size_per_partition_mb,
339            iceberg_compaction_max_file_count_per_partition: c
340                .storage
341                .iceberg_compaction_max_file_count_per_partition,
342            iceberg_compaction_task_parallelism_ratio: c
343                .storage
344                .iceberg_compaction_task_parallelism_ratio,
345            iceberg_compaction_enable_heuristic_output_parallelism: c
346                .storage
347                .iceberg_compaction_enable_heuristic_output_parallelism,
348            iceberg_compaction_max_concurrent_closes: c
349                .storage
350                .iceberg_compaction_max_concurrent_closes,
351            iceberg_compaction_enable_dynamic_size_estimation: c
352                .storage
353                .iceberg_compaction_enable_dynamic_size_estimation,
354            iceberg_compaction_size_estimation_smoothing_factor: c
355                .storage
356                .iceberg_compaction_size_estimation_smoothing_factor,
357            iceberg_compaction_pending_parallelism_budget_multiplier: c
358                .storage
359                .iceberg_compaction_pending_parallelism_budget_multiplier,
360            iceberg_compaction_pull_interval_ms: c.storage.iceberg_compaction_pull_interval_ms,
361            iceberg_compaction_enable_prefetch: c.storage.iceberg_compaction_enable_prefetch,
362            iceberg_compaction_target_binpack_group_size_mb: c
363                .storage
364                .iceberg_compaction_target_binpack_group_size_mb,
365            iceberg_compaction_min_group_size_mb: c.storage.iceberg_compaction_min_group_size_mb,
366            iceberg_compaction_min_group_file_count: c
367                .storage
368                .iceberg_compaction_min_group_file_count,
369            vector_file_block_size_kb: c.storage.vector_file_block_size_kb,
370            vector_block_cache_capacity_mb: s.vector_block_cache_capacity_mb,
371            vector_block_cache_shard_num: s.vector_block_cache_shard_num,
372            vector_block_cache_eviction_config: s.vector_block_cache_eviction_config.clone(),
373            vector_meta_cache_capacity_mb: s.vector_meta_cache_capacity_mb,
374            vector_meta_cache_shard_num: s.vector_meta_cache_shard_num,
375            vector_meta_cache_eviction_config: s.vector_meta_cache_eviction_config.clone(),
376        }
377    }
378}