@@ -114,6 +114,7 @@ impl DB {
114114 "sentinel 'F' present in {} — using steady-state L0 triggers" ,
115115 cf_name
116116 ) ;
117+ db. apply_steady_state_triggers ( ) ;
117118 }
118119 db
119120 }
@@ -159,29 +160,23 @@ impl DB {
159160 //
160161 // With bloom filters at 10 bits/key and a 128 MB write buffer, each L0
161162 // file has ~3.9 M keys, so its filter block is ~4.9 MB. At the slowdown
162- // threshold (96 files) that is ~470 MB of pinned filter blocks per CF,
163- // ~1.41 GB across 3 data CFs — within a 2 GB cache. At the stop threshold
164- // (128 files) it is ~628 MB per CF / ~1.88 GB total, still within bounds.
163+ // threshold (48 files) that is ~235 MB of pinned filter blocks per CF,
164+ // ~705 MB across 3 data CFs — within a 2 GB cache. At the stop threshold
165+ // (64 files) it is ~314 MB per CF / ~940 MB total, still within bounds.
165166 // Previously trigger=64 with 256 MB buffers caused pinned metadata to
166167 // overflow the 2 GB cache at L0=128 (~3.7 GB), spilling to uncontrolled
167- // heap and triggering OOM. Trigger=32 + slowdown=96 keeps the peak safe
168- // while allowing enough L0 accumulation for good bulk-load throughput.
168+ // heap and triggering OOM.
169169 //
170- // Set slowdown/stop triggers well above the compaction trigger so writes
171- // are never stalled while background compaction catches up.
172- // Disable the pending-compaction-bytes stall so the large backlog that
173- // builds up during the bulk load does not block writes.
174- const L0_BULK_TRIGGER : u32 = 32 ;
175- let trigger = L0_BULK_TRIGGER . to_string ( ) ;
176- let slowdown = ( L0_BULK_TRIGGER * 3 ) . to_string ( ) ;
177- let stop = ( L0_BULK_TRIGGER * 4 ) . to_string ( ) ;
170+ // Set slowdown/stop triggers above the compaction trigger so RocksDB
171+ // throttles writes while background compaction catches up.
172+ const L0_BULK_TRIGGER : & str = "32" ;
173+ const L0_BULK_SLOWDOWN : & str = "48" ;
174+ const L0_BULK_STOP : & str = "64" ;
178175
179176 let opts = [
180- ( "level0_file_num_compaction_trigger" , trigger. as_str ( ) ) ,
181- ( "level0_slowdown_writes_trigger" , slowdown. as_str ( ) ) ,
182- ( "level0_stop_writes_trigger" , stop. as_str ( ) ) ,
183- ( "soft_pending_compaction_bytes_limit" , "0" ) ,
184- ( "hard_pending_compaction_bytes_limit" , "0" ) ,
177+ ( "level0_file_num_compaction_trigger" , L0_BULK_TRIGGER ) ,
178+ ( "level0_slowdown_writes_trigger" , L0_BULK_SLOWDOWN ) ,
179+ ( "level0_stop_writes_trigger" , L0_BULK_STOP ) ,
185180 ] ;
186181 self . db . set_options_cf ( self . cf ( ) , & opts) . unwrap ( ) ;
187182 }
@@ -497,9 +492,10 @@ pub fn open_rocksdb(path: &Path, config: &Config) -> rocksdb::DB {
497492
498493 // Parallelize sub-ranges within a single compaction job (including the one-time
499494 // full_compaction at the end of initial sync). Without this, compact_range() is
500- // single-threaded regardless of increase_parallelism(). Setting it equal to the
501- // parallelism level keeps all background threads busy during the final compaction.
502- db_opts. set_max_subcompactions ( parallelism as u32 ) ;
495+ // single-threaded regardless of increase_parallelism(). Cap it at four because
496+ // subcompactions can multiply the configured background-job concurrency:
497+ // https://github.com/facebook/rocksdb/wiki/Subcompaction#options
498+ db_opts. set_max_subcompactions ( parallelism. min ( 4 ) as u32 ) ;
503499
504500 // Create a single shared LRU cache for all CFs. The total size is
505501 // --db-block-cache-mb (not multiplied by 3). RocksDB's LRU cache is
@@ -563,7 +559,17 @@ fn data_cf_options(config: &Config, shared_cache: &rocksdb::Cache) -> rocksdb::O
563559 cf_opts. set_compaction_style ( rocksdb:: DBCompactionStyle :: Level ) ;
564560 cf_opts. set_compression_type ( rocksdb:: DBCompressionType :: Lz4 ) ;
565561 cf_opts. set_bottommost_compression_type ( rocksdb:: DBCompressionType :: Zstd ) ;
566- cf_opts. set_target_file_size_base ( 1_073_741_824 ) ;
562+ cf_opts. set_target_file_size_base ( ( config. db_target_file_size_mb as u64 ) * 1024 * 1024 ) ;
563+ // 0 disables the limit. Set finite values via
564+ // --db-{soft,hard}-pending-compaction-gb to engage RocksDB's automatic write
565+ // throttling when the compaction backlog grows past the threshold. Steady-state
566+ // defaults are restored after full compaction.
567+ cf_opts. set_soft_pending_compaction_bytes_limit (
568+ ( config. db_soft_pending_compaction_gb as usize ) << 30 ,
569+ ) ;
570+ cf_opts. set_hard_pending_compaction_bytes_limit (
571+ ( config. db_hard_pending_compaction_gb as usize ) << 30 ,
572+ ) ;
567573 // L0 compaction triggers are left at RocksDB defaults (4/20/36) here.
568574 // After open, apply_bulk_load_triggers() widens them for initial sync
569575 // when the full-compaction sentinel 'F' is absent.
0 commit comments