@@ -101,46 +101,32 @@ var TargetBytesPerLockConflictError = settings.RegisterIntSetting(
101101 settings .WithName ("storage.mvcc.target_bytes_per_lock_conflict_error" ),
102102)
103103
104- // getMaxConcurrentCompactions wraps the maxConcurrentCompactions env var in a
105- // func that may be installed on Options.MaxConcurrentCompactions. It also
106- // imposes a floor on the max, so that an engine is always created with at least
107- // 1 slot for a compactions.
108- //
109- // NB: This function inspects the environment every time it's called. This is
110- // okay, because Engine construction in NewPebble will invoke it and store the
111- // value on the Engine itself.
112- func getMaxConcurrentCompactions () int {
113- n := envutil .EnvOrDefaultInt (
114- "COCKROACH_CONCURRENT_COMPACTIONS" , func () int {
115- // The old COCKROACH_ROCKSDB_CONCURRENCY environment variable was never
116- // documented, but customers were told about it and use today in
117- // production. We don't want to break them, so if the new env var
118- // is unset but COCKROACH_ROCKSDB_CONCURRENCY is set, use the old env
119- // var's value. This old env var has a wart in that it's expressed as a
120- // number of concurrency slots to make available to both flushes and
121- // compactions (a vestige of the corresponding RocksDB option's
122- // mechanics). We need to adjust it to be in terms of just compaction
123- // concurrency by subtracting the flushing routine's dedicated slot.
124- //
125- // TODO(jackson): Should envutil expose its `getEnv` internal func for
126- // cases like this where we actually want to know whether it's present
127- // or not; not just fallback to a default?
128- if oldV := envutil .EnvOrDefaultInt ("COCKROACH_ROCKSDB_CONCURRENCY" , 0 ); oldV > 0 {
129- return oldV - 1
130- }
131-
132- // By default use up to min(numCPU-1, 3) threads for background
133- // compactions per store (reserving the final process for flushes).
134- const max = 3
135- if n := runtime .GOMAXPROCS (0 ); n - 1 < max {
136- return n - 1
137- }
138- return max
139- }())
140- if n < 1 {
141- return 1
142- }
143- return n
104+ var defaultMaxConcurrentCompactions = getDefaultMaxConcurrentCompactions ()
105+
106+ func getDefaultMaxConcurrentCompactions () int {
107+ if v := envutil .EnvOrDefaultInt ("COCKROACH_CONCURRENT_COMPACTIONS" , 0 ); v > 0 {
108+ return v
109+ }
110+ // The old COCKROACH_ROCKSDB_CONCURRENCY environment variable was never
111+ // documented, but customers were told about it and use today in
112+ // production. We don't want to break them, so if the new env var
113+ // is unset but COCKROACH_ROCKSDB_CONCURRENCY is set, use the old env
114+ // var's value. This old env var has a wart in that it's expressed as a
115+ // number of concurrency slots to make available to both flushes and
116+ // compactions (a vestige of the corresponding RocksDB option's
117+ // mechanics). We need to adjust it to be in terms of just compaction
118+ // concurrency by subtracting the flushing routine's dedicated slot.
119+ if oldV := envutil .EnvOrDefaultInt ("COCKROACH_ROCKSDB_CONCURRENCY" , 0 ); oldV > 0 {
120+ return max (oldV - 1 , 1 )
121+ }
122+
123+ // By default use up to min(GOMAXPROCS-1, 3) threads for background
124+ // compactions per store (reserving the final process for flushes).
125+ const upperLimit = 3
126+ if n := runtime .GOMAXPROCS (0 ); n - 1 < upperLimit {
127+ return max (n - 1 , 1 )
128+ }
129+ return upperLimit
144130}
145131
146132// l0SubLevelCompactionConcurrency is the sub-level threshold at which to
0 commit comments