feldera_types/config/dev_tweaks.rs
1use std::collections::BTreeMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use utoipa::ToSchema;
6
7/// The largest value either merge threshold accepts.
8///
9/// A spine blocks its producer at 128 loose batches, and a level below its
10/// threshold never merges. With threshold `n`, `14 + 7 * (n - 1)` batches
11/// can wait with no merge due, which reaches 128 at `n = 18`. 15 is a
12/// conservative choice; `merge_threshold_test` pins it.
13pub const MAX_MERGE_THRESHOLD_BATCHES: u16 = 15;
14
15/// Optional settings for tweaking Feldera internals.
16///
17/// These settings reflect experiments that may come and go and change from
18/// version to version. Users should not consider them to be stable.
19#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, ToSchema)]
20#[serde(default)]
21pub struct DevTweaks {
22 /// Buffer-cache implementation to use for storage reads.
23 ///
24 /// The default is `s3_fifo`.
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub buffer_cache_strategy: Option<BufferCacheStrategy>,
27
28 /// Override the number of buckets/shards used by sharded buffer caches.
29 ///
30 /// This only applies when `buffer_cache_strategy = "s3_fifo"`. Values are
31 /// rounded up to the next power of two because the current implementation
32 /// shards by `hash(key) & (n - 1)`.
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub buffer_max_buckets: Option<usize>,
35
36 /// How S3-FIFO caches are assigned to foreground/background workers.
37 ///
38 /// This only applies when `buffer_cache_strategy = "s3_fifo"`. The
39 /// default is `shared_per_worker_pair`; LRU always uses `per_thread`.
40 #[serde(skip_serializing_if = "Option::is_none")]
41 pub buffer_cache_allocation_strategy: Option<BufferCacheAllocationStrategy>,
42
43 /// Target number of cached bytes retained in each `FBuf` slab size class.
44 ///
45 /// The default is 16 MiB.
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub fbuf_slab_bytes_per_class: Option<usize>,
48
49 /// Whether to asynchronously fetch keys needed for the join operator from
50 /// storage. Asynchronous fetching should be faster for high-latency
51 /// storage, such as object storage, but it could use excessive amounts of
52 /// memory if the number of keys fetched is very large.
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub fetch_join: Option<bool>,
55
56 /// Whether to asynchronously fetch keys needed for the distinct operator
57 /// from storage. Asynchronous fetching should be faster for high-latency
58 /// storage, such as object storage, but it could use excessive amounts of
59 /// memory if the number of keys fetched is very large.
60 #[serde(skip_serializing_if = "Option::is_none")]
61 pub fetch_distinct: Option<bool>,
62
63 /// Which merger to use.
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub merger: Option<MergerType>,
66
67 /// If set, the maximum amount of storage, in MiB, for the POSIX backend to
68 /// allow to be in use before failing all writes with `StorageFull`. This
69 /// is useful for testing on top of storage that does not implement its own
70 /// quota mechanism.
71 #[serde(skip_serializing_if = "Option::is_none")]
72 pub storage_mb_max: Option<u64>,
73
74 /// Attempt to print a stack trace on stack overflow.
75 ///
76 /// To be used for debugging only; do not enable in production.
77 // NOTE: this flag is handled manually in `adapters/src/server.rs` before
78 // parsing DevTweaks. If the name or type of this field changes, make sure to
79 // adjust `server.rs` accordingly.
80 #[serde(skip_serializing_if = "Option::is_none")]
81 pub stack_overflow_backtrace: Option<bool>,
82
83 /// Controls the maximal number of records output by splitter operators
84 /// (joins, distinct, aggregation, rolling window and group operators) at
85 /// each step.
86 ///
87 /// The default value is 10,000 records.
88 // TODO: It would be better if the value were denominated in bytes rather
89 // than records, and if it were configurable per-operator.
90 #[serde(skip_serializing_if = "Option::is_none")]
91 pub splitter_chunk_size_records: Option<u64>,
92
93 /// Enable adaptive joins.
94 ///
95 /// Adaptive joins dynamically change their partitioning policy to avoid skew.
96 ///
97 /// Adaptive joins are disabled by default.
98 #[serde(skip_serializing_if = "Option::is_none")]
99 pub adaptive_joins: Option<bool>,
100
101 /// Evict eagerly from buffer caches as files get deleted.
102 ///
103 /// This is an optimization that drops files from
104 /// the cache as soon as they are deleted.
105 ///
106 /// It has unknown (no?) performance benefits from what I can tell.
107 ///
108 /// Historically it made sense to do this for two reasons:
109 /// a) we know with 100% guarantee that the file won't ever be
110 /// read again.
111 /// b) we could do this in O(logn) time with the LRU cache.
112 /// This is no longer true for s3-fifo where it is O(n).
113 ///
114 /// If the eviction is expensive, (many small objects in the cache)
115 /// this can cause a regression.
116 ///
117 /// New default disables this behavior by making it false.
118 ///
119 /// If this doesn't cause regression we will remove this option
120 /// in the future.
121 #[serde(skip_serializing_if = "Option::is_none")]
122 pub eager_evict: Option<bool>,
123
124 /// The minimum relative improvement threshold for the join balancer.
125 ///
126 /// The join balancer is a component that dynamically chooses an optimal
127 /// partitioning policy for adaptive join operators. This parameter
128 /// prevents the join balancer from making changes to the partitioning
129 /// policy if the improvement is not significant, since the overhead of such
130 /// rebalancing, especially when performed frequently, can exceed the
131 /// benefits.
132 ///
133 /// A rebalancing is considered significant if the relative estimated
134 /// improvement across the collections whose partitioning policy the
135 /// rebalancing changes is at least this threshold. Collections that keep
136 /// their policy are excluded, since they cost the same either way.
137 ///
138 /// A rebalancing is applied if both this threshold and
139 /// `balancer_min_absolute_improvement_threshold` are met.
140 ///
141 /// The default value is 1.2.
142 #[serde(skip_serializing_if = "Option::is_none")]
143 #[serde(default, deserialize_with = "crate::serde_via_value::deserialize")]
144 pub balancer_min_relative_improvement_threshold: Option<f64>,
145
146 /// The minimum absolute improvement threshold for the balancer.
147 ///
148 /// The join balancer is a component that dynamically chooses an optimal
149 /// partitioning policy for adaptive join operators. This parameter
150 /// prevents the join balancer from making changes to the partitioning
151 /// policy if the improvement is not significant, since the overhead of such
152 /// rebalancing, especially when performed frequently, can exceed the
153 /// benefits.
154 ///
155 /// A rebalancing is considered significant if the absolute estimated
156 /// improvement across the collections whose partitioning policy the
157 /// rebalancing changes is at least this threshold. The cost model used by the
158 /// balancer is based on the number of records in the largest partition of a
159 /// collection.
160 ///
161 /// A rebalancing is applied if both this threshold and
162 /// `balancer_min_relative_improvement_threshold` are met.
163 ///
164 /// The default value is 10,000.
165 #[serde(skip_serializing_if = "Option::is_none")]
166 pub balancer_min_absolute_improvement_threshold: Option<u64>,
167
168 /// Factor that discourages the use of the Balance policy in a perfectly balanced collection.
169 ///
170 /// Assuming a perfectly balanced key distribution, the Balance policy is slightly less efficient than Shard,
171 /// since it requires computing the hash of the entire key/value pair. This factor discourages the use of this policy
172 /// if the skew is `<balancer_balance_tax`.
173 ///
174 /// The default value is 1.1.
175 #[serde(skip_serializing_if = "Option::is_none")]
176 #[serde(default, deserialize_with = "crate::serde_via_value::deserialize")]
177 pub balancer_balance_tax: Option<f64>,
178
179 /// The balancer threshold for checking for an improved partitioning policy for a stream.
180 ///
181 /// Finding a good partitioning policy for a circuit involves solving an optimization problem,
182 /// which can be relatively expensive. Instead of doing this on every step, the balancer only
183 /// checks for an improved partitioning policy if the key distribution of a stream has changed
184 /// significantly since the current solution was computed. Specifically, it only kicks in when
185 /// the size of at least one shard of at least one stream in the cluster has changed by more than
186 /// this threshold.
187 ///
188 /// The default value is 0.1.
189 #[serde(skip_serializing_if = "Option::is_none")]
190 #[serde(default, deserialize_with = "crate::serde_via_value::deserialize")]
191 pub balancer_key_distribution_refresh_threshold: Option<f64>,
192
193 /// False-positive rate for Bloom filters on batches on storage.
194 ///
195 /// Deprecated: use `storage.bloom_false_positive_rate` instead.
196 #[serde(skip_serializing_if = "Option::is_none")]
197 #[serde(default, deserialize_with = "crate::serde_via_value::deserialize")]
198 pub bloom_false_positive_rate: Option<f64>,
199
200 /// Whether file-backed batches may use roaring membership filters when the
201 /// key type supports them.
202 #[serde(skip_serializing_if = "Option::is_none")]
203 pub enable_roaring: Option<bool>,
204
205 /// Maximum batch size in records for level 0 merges.
206 #[serde(skip_serializing_if = "Option::is_none")]
207 pub max_level0_batch_size_records: Option<u16>,
208
209 /// Merge threshold of an accumulator's spine: how many batches each
210 /// level above level 1 waits for before it merges them.
211 ///
212 /// Zero restores the built-in minimum. A spine that garbage-collects old
213 /// records always uses the built-in minimum.
214 #[serde(skip_serializing_if = "Option::is_none")]
215 pub accumulator_merge_threshold_batches: Option<u16>,
216
217 /// Merge threshold of an integral's spine: how many batches each level
218 /// above level 1 waits for before it merges them.
219 ///
220 /// The default is ten. Zero restores the built-in minimum. A spine
221 /// that garbage-collects old records always uses the built-in minimum.
222 #[serde(skip_serializing_if = "Option::is_none")]
223 pub integral_merge_threshold_batches: Option<u16>,
224
225 /// The number of merger threads.
226 ///
227 /// The default value is equal to the number of worker threads.
228 #[serde(skip_serializing_if = "Option::is_none")]
229 pub merger_threads: Option<u16>,
230
231 /// Additional bias the merger assigns to records with negative weights
232 /// (retractions) to promote them to higher levels of the LSM tree sooner.
233 ///
234 /// Reasonable values for this parameter are in the range [0, 10].
235 ///
236 /// The default value is 0, which means that retractions are not given
237 /// any additional bias.
238 #[serde(skip_serializing_if = "Option::is_none")]
239 pub negative_weight_multiplier: Option<u16>,
240
241 /// The share of the records at a spine's highest level with negative
242 /// weights above which the level merges its batches.
243 ///
244 /// A spine keeps most of its records at its highest level. When many of
245 /// them are retractions, merging the level's batches cancels them against
246 /// the records they retract, which shrinks the spine's storage.
247 ///
248 /// A fraction from 0 through 1; the default is 0.2. At 1 the level never
249 /// merges for this reason.
250 #[serde(skip_serializing_if = "Option::is_none")]
251 #[serde(default, deserialize_with = "crate::serde_via_value::deserialize")]
252 pub top_level_negative_weight_fraction: Option<f64>,
253
254 /// Don't automatically start a transaction for every step.
255 #[serde(skip_serializing_if = "Option::is_none")]
256 pub disable_auto_transaction: Option<bool>,
257
258 /// Override the timestamp returned by SQL `NOW()` at pipeline start.
259 ///
260 /// When set, the clock connector anchors `NOW()` to this RFC 3339
261 /// timestamp the first time the pipeline starts and advances at
262 /// wall-clock cadence from there:
263 /// `NOW() = now_offset + (wall_clock - wall_clock_at_start)`.
264 ///
265 /// Any RFC 3339 timestamp parseable by `chrono::DateTime<Utc>` is
266 /// accepted (years `0001` through `9999`), in the past or future
267 /// relative to wall clock.
268 ///
269 /// This is a testing knob for queries that depend on `NOW()`.
270 ///
271 /// On resume the clock continues from the last journaled `NOW()`;
272 /// `now_offset`'s value is honored only on a fresh start:
273 ///
274 /// | Initial run | Resume from checkpoint | Post-replay `NOW()` |
275 /// |---|---|---|
276 /// | no offset | no offset | wall clock (unchanged) |
277 /// | offset | offset | wall-clock pace from the last journaled value; the new offset value is ignored |
278 /// | offset | no offset | jumps to wall clock (explicit opt-out of the anchor) |
279 /// | no offset | offset | wall-clock pace from the last journaled value; the new offset value is ignored |
280 #[serde(skip_serializing_if = "Option::is_none")]
281 pub now_offset: Option<DateTime<Utc>>,
282
283 /// Drive `NOW()` from an external HTTP endpoint instead of wall clock.
284 ///
285 /// When `true`, the clock connector emits one initial tick (using
286 /// `now_offset` if set, otherwise wall clock) and then holds that
287 /// value. Subsequent calls to `POST /clock/advance` move `NOW()`
288 /// forward by the requested delta. Negative deltas are rejected;
289 /// the clock is forward-only.
290 #[serde(skip_serializing_if = "Option::is_none")]
291 pub now_http_driven: Option<bool>,
292
293 /// Enable streaming exchange.
294 #[serde(skip_serializing_if = "Option::is_none")]
295 pub streaming_exchange: Option<bool>,
296
297 /// Maximum number of bytes of queued but unacknowledged exchange messages
298 /// per pair of remote host and message type.
299 ///
300 /// A sender that pushes past this budget waits for the receiver to
301 /// acknowledge earlier messages before it queues more. There are three
302 /// message types, so a host buffers up to three times this many bytes for
303 /// each of the other hosts, plus any single message that exceeds the
304 /// budget on its own.
305 ///
306 /// The default is 10,000,000 bytes.
307 #[serde(skip_serializing_if = "Option::is_none")]
308 pub exchange_channel_capacity_bytes: Option<usize>,
309
310 /// Optimize input operators during transaction commit.
311 #[serde(skip_serializing_if = "Option::is_none")]
312 pub optimize_input_during_commit: Option<bool>,
313
314 /// Options not understood by this particular version.
315 ///
316 /// This allows the pipeline manager to take options that a custom or old
317 /// runtime version accepts.
318 #[serde(flatten)]
319 pub other_options: BTreeMap<String, serde_json::Value>,
320}
321
322impl DevTweaks {
323 pub fn buffer_cache_strategy(&self) -> BufferCacheStrategy {
324 self.buffer_cache_strategy.unwrap_or_default()
325 }
326 pub fn buffer_cache_allocation_strategy(&self) -> BufferCacheAllocationStrategy {
327 self.buffer_cache_allocation_strategy.unwrap_or_default()
328 }
329 pub fn effective_buffer_cache_allocation_strategy(&self) -> BufferCacheAllocationStrategy {
330 match self.buffer_cache_strategy() {
331 BufferCacheStrategy::S3Fifo => self.buffer_cache_allocation_strategy(),
332 BufferCacheStrategy::Lru => BufferCacheAllocationStrategy::PerThread,
333 }
334 }
335 pub fn fetch_join(&self) -> bool {
336 self.fetch_join.unwrap_or(false)
337 }
338 pub fn fetch_distinct(&self) -> bool {
339 self.fetch_distinct.unwrap_or(false)
340 }
341 pub fn merger(&self) -> MergerType {
342 self.merger.unwrap_or_default()
343 }
344 pub fn stack_overflow_backtrace(&self) -> bool {
345 self.stack_overflow_backtrace.unwrap_or(false)
346 }
347 pub fn splitter_chunk_size_records(&self) -> u64 {
348 self.splitter_chunk_size_records.unwrap_or(10_000)
349 }
350 pub fn adaptive_joins(&self) -> bool {
351 self.adaptive_joins.unwrap_or(false)
352 }
353 pub fn balancer_min_relative_improvement_threshold(&self) -> f64 {
354 self.balancer_min_relative_improvement_threshold
355 .unwrap_or(1.2)
356 }
357 pub fn balancer_min_absolute_improvement_threshold(&self) -> u64 {
358 self.balancer_min_absolute_improvement_threshold
359 .unwrap_or(10_000)
360 }
361 pub fn balancer_balance_tax(&self) -> f64 {
362 self.balancer_balance_tax.unwrap_or(1.1)
363 }
364 pub fn balancer_key_distribution_refresh_threshold(&self) -> f64 {
365 self.balancer_key_distribution_refresh_threshold
366 .unwrap_or(0.1)
367 }
368 pub fn bloom_false_positive_rate(&self) -> f64 {
369 self.bloom_false_positive_rate.unwrap_or(0.0001)
370 }
371 pub fn enable_roaring(&self) -> bool {
372 // Roaring is enabled by default, but `enable_roaring = false` remains
373 // available as a kill switch while the feature is still being tuned.
374 self.enable_roaring.unwrap_or(true)
375 }
376
377 /// Rejects settings outside their valid range, naming the field, the
378 /// value and the range.
379 pub fn validate(&self) -> Result<(), String> {
380 for (name, value) in [
381 (
382 "accumulator_merge_threshold_batches",
383 self.accumulator_merge_threshold_batches,
384 ),
385 (
386 "integral_merge_threshold_batches",
387 self.integral_merge_threshold_batches,
388 ),
389 ] {
390 if let Some(value) = value
391 && value > MAX_MERGE_THRESHOLD_BATCHES
392 {
393 return Err(format!(
394 "dev_tweaks.{name} is {value}, but the valid range is 0 through \
395 {MAX_MERGE_THRESHOLD_BATCHES}; 0 keeps the built-in minimum"
396 ));
397 }
398 }
399 if let Some(fraction) = self.top_level_negative_weight_fraction
400 && !(0.0..=1.0).contains(&fraction)
401 {
402 return Err(format!(
403 "dev_tweaks.top_level_negative_weight_fraction is {fraction}, but the valid \
404 range is 0 through 1"
405 ));
406 }
407 Ok(())
408 }
409
410 /// Batches an accumulator's spine waits for above level 1; zero means the
411 /// built-in minimum.
412 pub fn accumulator_merge_threshold_batches(&self) -> u16 {
413 self.accumulator_merge_threshold_batches.unwrap_or(10)
414 }
415
416 /// Batches an integral's spine waits for above level 1; zero means the
417 /// built-in minimum.
418 pub fn integral_merge_threshold_batches(&self) -> u16 {
419 self.integral_merge_threshold_batches.unwrap_or(10)
420 }
421
422 pub fn negative_weight_multiplier(&self) -> u16 {
423 self.negative_weight_multiplier.unwrap_or(0)
424 }
425
426 /// The share of the records at a spine's highest level with negative
427 /// weights above which the level merges its batches.
428 pub fn top_level_negative_weight_fraction(&self) -> f64 {
429 self.top_level_negative_weight_fraction.unwrap_or(0.2)
430 }
431
432 pub fn disable_auto_transaction(&self) -> bool {
433 self.disable_auto_transaction.unwrap_or(false)
434 }
435
436 /// Configured `now_offset` as milliseconds since the Unix epoch,
437 /// or `None` if no override is set.
438 pub fn now_offset_ms(&self) -> Option<i64> {
439 self.now_offset.map(|target| target.timestamp_millis())
440 }
441
442 pub fn now_http_driven(&self) -> bool {
443 self.now_http_driven.unwrap_or(false)
444 }
445
446 pub fn streaming_exchange(&self) -> bool {
447 self.streaming_exchange.unwrap_or(true)
448 }
449
450 pub fn exchange_channel_capacity_bytes(&self) -> usize {
451 self.exchange_channel_capacity_bytes.unwrap_or(10_000_000)
452 }
453
454 pub fn optimize_input_during_commit(&self) -> bool {
455 self.optimize_input_during_commit.unwrap_or(true)
456 }
457}
458
459/// Selects which eviction strategy backs a cache instance.
460#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
461#[serde(rename_all = "snake_case")]
462pub enum BufferCacheStrategy {
463 /// Use the sharded S3-FIFO cache backed by `quick_cache`.
464 #[default]
465 S3Fifo,
466
467 /// Use the mutex-protected weighted LRU cache.
468 Lru,
469}
470
471/// Controls how caches are shared across a foreground/background worker pair.
472#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
473#[serde(rename_all = "snake_case")]
474pub enum BufferCacheAllocationStrategy {
475 /// Share one cache across a foreground/background worker pair.
476 #[default]
477 SharedPerWorkerPair,
478
479 /// Create a separate cache for each foreground/background thread.
480 PerThread,
481
482 /// Share one cache across all foreground/background threads.
483 Global,
484}
485
486/// Which merger to use.
487#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
488#[serde(rename_all = "snake_case")]
489pub enum MergerType {
490 /// Newer merger, which should be faster for high-latency storage, such as
491 /// object storage, but it likely needs tuning.
492 PushMerger,
493
494 /// The old standby, with known performance.
495 #[default]
496 ListMerger,
497}
498
499#[cfg(test)]
500mod tests {
501 use serde_json::json;
502
503 use crate::config::{PipelineConfig, RuntimeConfig};
504
505 use super::*;
506
507 /// Either merge threshold is accepted up to the bound and rejected past
508 /// it, by name, with the value and the range in the message.
509 #[test]
510 fn merge_thresholds_are_bounded() {
511 assert_eq!(DevTweaks::default().validate(), Ok(()));
512 for field in [
513 "accumulator_merge_threshold_batches",
514 "integral_merge_threshold_batches",
515 ] {
516 let with = |value: u16| {
517 let mut tweaks = DevTweaks::default();
518 if field == "accumulator_merge_threshold_batches" {
519 tweaks.accumulator_merge_threshold_batches = Some(value);
520 } else {
521 tweaks.integral_merge_threshold_batches = Some(value);
522 }
523 tweaks
524 };
525 assert_eq!(with(0).validate(), Ok(()), "{field} = 0");
526 assert_eq!(
527 with(MAX_MERGE_THRESHOLD_BATCHES).validate(),
528 Ok(()),
529 "{field} at the bound"
530 );
531 let error = with(MAX_MERGE_THRESHOLD_BATCHES + 1)
532 .validate()
533 .expect_err("a value past the bound must be rejected");
534 assert!(error.contains(field), "{error}");
535 assert!(error.contains("16"), "{error}");
536 assert!(error.contains("0 through 15"), "{error}");
537 }
538 }
539
540 /// The share of negative weights that merges a spine's highest level
541 /// defaults to a fifth, and is accepted from 0 through 1 and rejected
542 /// outside that range or when it is not a number at all.
543 #[test]
544 fn top_level_negative_weight_fraction_is_a_share() {
545 assert_eq!(
546 DevTweaks::default().top_level_negative_weight_fraction(),
547 0.2
548 );
549 let with = |fraction| DevTweaks {
550 top_level_negative_weight_fraction: Some(fraction),
551 ..DevTweaks::default()
552 };
553 for fraction in [0.0, 0.2, 1.0] {
554 assert_eq!(with(fraction).validate(), Ok(()), "{fraction}");
555 }
556 for fraction in [-0.1, 1.5, f64::INFINITY, f64::NAN] {
557 let error = with(fraction)
558 .validate()
559 .expect_err("a share outside 0 through 1 must be rejected");
560 assert!(
561 error.contains("top_level_negative_weight_fraction"),
562 "{error}"
563 );
564 assert!(error.contains("0 through 1"), "{error}");
565 }
566 }
567
568 /// Regression test: `Option<f64>` fields inside `DevTweaks` must
569 /// survive a JSON-string round-trip through `PipelineConfig`, which
570 /// uses `#[serde(flatten)]` on `RuntimeConfig`. With `serde_json`'s
571 /// `arbitrary_precision` feature enabled, the serde `Content` buffer
572 /// represents numbers as maps, which breaks plain `f64`
573 /// deserialization (serde-rs/json#1157). The `serde_via_value`
574 /// workaround on each `Option<f64>` field fixes this.
575 #[test]
576 fn dev_tweaks_f64_roundtrip_through_pipeline_config() {
577 let rc = RuntimeConfig {
578 dev_tweaks: DevTweaks {
579 bloom_false_positive_rate: Some(0.0),
580 balancer_balance_tax: Some(1.1),
581 balancer_min_relative_improvement_threshold: Some(1.2),
582 balancer_key_distribution_refresh_threshold: Some(0.1),
583 top_level_negative_weight_fraction: Some(0.25),
584 ..Default::default()
585 },
586 ..Default::default()
587 };
588 let pc = PipelineConfig {
589 global: rc,
590 multihost: None,
591 name: Some("test-pipeline".into()),
592 given_name: None,
593 storage_config: None,
594 secrets_dir: None,
595 inputs: Default::default(),
596 outputs: Default::default(),
597 program_ir: None,
598 };
599
600 // JSON string round-trip (the path the pipeline process takes).
601 let json = serde_json::to_string_pretty(&pc).unwrap();
602 let pc2: PipelineConfig = serde_json::from_str(&json)
603 .expect("JSON string round-trip of PipelineConfig with f64 dev_tweaks must succeed");
604 assert_eq!(pc2.global.dev_tweaks.bloom_false_positive_rate, Some(0.0));
605 assert_eq!(pc2.global.dev_tweaks.balancer_balance_tax, Some(1.1));
606 assert_eq!(
607 pc2.global
608 .dev_tweaks
609 .balancer_min_relative_improvement_threshold,
610 Some(1.2)
611 );
612 assert_eq!(
613 pc2.global
614 .dev_tweaks
615 .balancer_key_distribution_refresh_threshold,
616 Some(0.1)
617 );
618 assert_eq!(
619 pc2.global.dev_tweaks.top_level_negative_weight_fraction,
620 Some(0.25)
621 );
622
623 // serde_json::Value round-trip (the path the pipeline manager takes).
624 let value = serde_json::to_value(&pc).unwrap();
625 let pc3: PipelineConfig = serde_json::from_value(value)
626 .expect("Value round-trip of PipelineConfig with f64 dev_tweaks must succeed");
627 assert_eq!(pc3.global.dev_tweaks.bloom_false_positive_rate, Some(0.0));
628 }
629
630 #[test]
631 fn other_options() {
632 let dt =
633 serde_json::from_value::<DevTweaks>(json!({"xyzzy": 1.0, "foobar": {"key": "value"}}))
634 .unwrap();
635 assert_eq!(
636 &dt.other_options,
637 &BTreeMap::from_iter([
638 (String::from("xyzzy"), json!(1.0)),
639 (String::from("foobar"), json!({"key": "value"}))
640 ]),
641 );
642 }
643}