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