Skip to content

Commit 173751e

Browse files
committed
Document magic numbers and unsafe env var usage in tests
1 parent ac76b13 commit 173751e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/buffered_write_layer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use tokio::task::JoinHandle;
1010
use tokio_util::sync::CancellationToken;
1111
use tracing::{debug, error, info, instrument, warn};
1212

13-
const MEMORY_OVERHEAD_MULTIPLIER: f64 = 1.2; // 20% overhead for DashMap, RwLock, schema refs
13+
// 20% overhead accounts for DashMap internal structures, RwLock wrappers,
14+
// Arc<Schema> refs, and Arrow buffer alignment padding
15+
const MEMORY_OVERHEAD_MULTIPLIER: f64 = 1.2;
1416

1517
#[derive(Debug, Default)]
1618
pub struct RecoveryStats {
@@ -95,6 +97,7 @@ impl BufferedWriteLayer {
9597
let estimated_size = (batch_size as f64 * MEMORY_OVERHEAD_MULTIPLIER) as usize;
9698

9799
let max_bytes = self.max_memory_bytes();
100+
// Hard limit at 120% provides headroom for in-flight writes while preventing OOM
98101
let hard_limit = max_bytes.saturating_add(max_bytes / 5);
99102

100103
for _ in 0..100 {

src/mem_buffer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use std::sync::RwLock;
1111
use std::sync::atomic::{AtomicI64, AtomicUsize, Ordering};
1212
use tracing::{debug, info, instrument, warn};
1313

14-
const BUCKET_DURATION_MICROS: i64 = 10 * 60 * 1_000_000; // 10 minutes in microseconds
14+
// 10-minute buckets balance flush granularity vs overhead. Shorter = more flushes,
15+
// longer = larger Delta files. Matches default flush interval for aligned boundaries.
16+
const BUCKET_DURATION_MICROS: i64 = 10 * 60 * 1_000_000;
1517

1618
/// Check if two schemas are compatible for merge.
1719
/// Compatible means: all existing fields must be present in incoming schema with same type,

tests/test_dml_operations.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ mod test_dml_operations {
1717
keys: Vec<(String, Option<String>)>,
1818
}
1919

20+
// SAFETY: All tests using EnvGuard are marked #[serial], ensuring single-threaded
21+
// execution. No other threads read env vars during test execution.
2022
impl EnvGuard {
2123
fn set(key: &str, value: &str) -> Self {
2224
let old = std::env::var(key).ok();
23-
// SAFETY: Tests run serially via #[serial] attribute
2425
unsafe { std::env::set_var(key, value) };
25-
Self {
26-
keys: vec![(key.to_string(), old)],
27-
}
26+
Self { keys: vec![(key.to_string(), old)] }
2827
}
2928

3029
fn add(&mut self, key: &str, value: &str) {

0 commit comments

Comments
 (0)