Skip to content

Commit 9e41382

Browse files
committed
refactor(config): decompose ServerConfig into focused single-concern files
ServerConfig and its supporting types (LogFormat, PortsConfig, path helpers, and the new ServerSection wrapper) were all defined inline in mod.rs, which had grown past 400 lines of mixed concerns. Each type now lives in its own file: config.rs, log_format.rs, paths.rs, ports.rs, and section.rs. mod.rs is reduced to pub-mod declarations and re-exports. All call sites that accessed flat config fields (config.host, config.data_dir, config.ports.*, etc.) are updated to the new config.server.* path introduced by ServerSection. Bootstrap modules, main.rs, env.rs, and auth security tests all updated accordingly.
1 parent 8507f48 commit 9e41382

15 files changed

Lines changed: 722 additions & 462 deletions

nodedb/src/bootstrap/background_loops.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ pub struct EventPlaneComponents {
2727
/// Includes: Event Plane consumers, event trigger processor, webhook manager wiring,
2828
/// collection GC, L2 cleanup, tenant rate/audit/memory timers, checkpoint manager,
2929
/// usage metering flush, and cold tier task.
30+
///
31+
/// Returns the [`EventPlane`] handle. The caller MUST hold this for the
32+
/// server's lifetime — dropping it aborts every consumer task and turns
33+
/// the per-core event ring buffers into one-way drains, which silently
34+
/// loses every WriteEvent emitted by the Data Plane until process exit.
35+
#[must_use = "EventPlane must be held for the server's lifetime; dropping it stops all event consumers"]
3036
pub fn spawn_background_loops(
3137
shared: &Arc<SharedState>,
3238
components: EventPlaneComponents,
3339
config: &ServerConfig,
3440
num_cores: usize,
3541
shutdown_rx: tokio::sync::watch::Receiver<bool>,
36-
) {
42+
) -> crate::event::EventPlane {
3743
let EventPlaneComponents {
3844
wal,
3945
event_consumers,
@@ -47,7 +53,10 @@ pub fn spawn_background_loops(
4753
shared.webhook_manager.set_state(Arc::clone(shared));
4854

4955
// Event Plane: one consumer Tokio task per Data Plane core.
50-
let _event_plane = crate::event::EventPlane::spawn(
56+
// Returned to the caller — must outlive the server, otherwise its
57+
// Drop impl aborts every consumer and the Data Plane producers
58+
// start dropping every WriteEvent they emit.
59+
let event_plane = crate::event::EventPlane::spawn(
5160
event_consumers,
5261
Arc::clone(&wal),
5362
watermark_store,
@@ -144,7 +153,7 @@ pub fn spawn_background_loops(
144153
if let Some(ref cold_settings) = config.cold_storage {
145154
let shared_cold = Arc::clone(shared);
146155
let cold_settings_clone = cold_settings.clone();
147-
let data_dir_clone = config.data_dir.clone();
156+
let data_dir_clone = config.server.data_dir.clone();
148157
let shutdown_rx_cold = shutdown_rx.clone();
149158
crate::control::cold_tier::spawn_cold_tier_task(
150159
shared_cold,
@@ -154,6 +163,8 @@ pub fn spawn_background_loops(
154163
);
155164
info!("cold tier task spawned");
156165
}
166+
167+
event_plane
157168
}
158169

159170
/// Spawn the response poller loop (routes Data Plane responses to waiting sessions).

nodedb/src/bootstrap/credentials.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ pub fn replay_surrogate_wal(shared: &Arc<SharedState>, wal_records: &Arc<[WalRec
4545
/// Bootstrap the superuser credential from config / data dir, or warn about trust mode.
4646
pub fn bootstrap_superuser(shared: &Arc<SharedState>, config: &ServerConfig) -> anyhow::Result<()> {
4747
let auth_mode = config.auth.mode.clone();
48-
match config.auth.resolve_superuser_password(&config.data_dir) {
48+
match config
49+
.auth
50+
.resolve_superuser_password(&config.server.data_dir)
51+
{
4952
Ok(Some(password)) => {
5053
shared
5154
.credentials
@@ -79,11 +82,11 @@ pub fn print_startup_banner(config: &ServerConfig, cluster_mode_str: &str) {
7982
eprintln!(
8083
"{}",
8184
crate::version::format_banner(
82-
config.ports.pgwire,
83-
config.ports.http,
84-
config.ports.native,
85+
config.server.ports.pgwire,
86+
config.server.ports.http,
87+
config.server.ports.native,
8588
cluster_mode_str,
86-
&config.data_dir.display().to_string(),
89+
&config.server.data_dir.display().to_string(),
8790
&format!("{:?}", config.auth.mode),
8891
)
8992
);

nodedb/src/bootstrap/data_plane.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn spawn_data_plane_cores(
7575
quarantine_registry,
7676
system_metrics,
7777
} = resources;
78-
let num_cores = config.data_plane_cores;
78+
let num_cores = config.server.data_plane_cores;
7979
let compaction_cfg = CoreCompactionConfig {
8080
interval: config.checkpoint.compaction_interval(),
8181
tombstone_threshold: config.checkpoint.compaction_tombstone_threshold,
@@ -92,7 +92,7 @@ pub fn spawn_data_plane_cores(
9292
core_id,
9393
data_side.request_rx,
9494
data_side.response_tx,
95-
&config.data_dir,
95+
&config.server.data_dir,
9696
Arc::clone(&wal_records),
9797
replay_tombstones.clone(),
9898
num_cores,

nodedb/src/bootstrap/listeners.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub async fn spawn_protocol_listeners(
5555
let tls_for = |enabled: bool| -> Option<tokio_rustls::TlsAcceptor> {
5656
if enabled { base_acceptor.clone() } else { None }
5757
};
58-
let tls_flags = config.tls.as_ref();
58+
let tls_flags = config.server.tls.as_ref();
5959
let pgwire_tls_enabled = tls_flags.is_some_and(|t| t.pgwire);
6060
let http_tls_enabled = tls_flags.is_some_and(|t| t.http);
6161
let resp_tls_enabled = tls_flags.is_some_and(|t| t.resp);
@@ -89,7 +89,7 @@ pub async fn spawn_protocol_listeners(
8989
let http_auth_mode = config.auth.mode.clone();
9090
let http_listen = config.http_addr();
9191
let http_tls = if http_tls_enabled {
92-
config.tls.clone()
92+
config.server.tls.clone()
9393
} else {
9494
None
9595
};

nodedb/src/bootstrap/state_wiring.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ pub fn wire_state(
109109
.as_ref()
110110
.map(|s| s.to_snapshot_storage_config())
111111
.unwrap_or_else(crate::config::server::SnapshotStorageSettings::default_storage_config);
112-
match crate::storage::snapshot_writer::build_snapshot_store(&snap_cfg, &config.data_dir) {
112+
match crate::storage::snapshot_writer::build_snapshot_store(
113+
&snap_cfg,
114+
&config.server.data_dir,
115+
) {
113116
Ok(store) => {
114117
if let Some(state) = Arc::get_mut(shared) {
115118
state.snapshot_storage = store;
@@ -132,8 +135,10 @@ pub fn wire_state(
132135
.unwrap_or_else(
133136
crate::config::server::QuarantineStorageSettings::default_storage_config,
134137
);
135-
match crate::storage::quarantine::registry::build_quarantine_store(&q_cfg, &config.data_dir)
136-
{
138+
match crate::storage::quarantine::registry::build_quarantine_store(
139+
&q_cfg,
140+
&config.server.data_dir,
141+
) {
137142
Ok(store) => {
138143
if let Some(state) = Arc::get_mut(shared) {
139144
state.quarantine_storage = store;
@@ -209,7 +214,7 @@ pub fn wire_state(
209214
crate::control::trace_export::TraceExporter::disabled()
210215
};
211216
state.debug_endpoints_enabled = config.observability.debug_endpoints_enabled;
212-
state.data_dir = config.data_dir.clone();
217+
state.data_dir = config.server.data_dir.clone();
213218
state.scheduler_config = config.scheduler.clone();
214219
}
215220

nodedb/src/bootstrap/tracing_init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::ServerConfig;
1414
/// `tracing::info!` / `tracing::warn!` calls are expected to emit.
1515
pub fn init_tracing(config: &ServerConfig) {
1616
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("warn"));
17-
if config.log_format == crate::config::LogFormat::Json {
17+
if config.server.log_format == crate::config::LogFormat::Json {
1818
tracing_subscriber::registry()
1919
.with(
2020
tracing_subscriber::fmt::layer()

0 commit comments

Comments
 (0)