2.8 KiB
2.8 KiB
id, name, status, depends_on, scope, risk, impact, level
| id | name | status | depends_on | scope | risk | impact | level | |
|---|---|---|---|---|---|---|---|---|
| config/dynamic-config | Implement DynamicConfig with ArcSwap hot-reload and ConfigReloadHandle | completed |
|
moderate | medium | component | implementation |
Description
Implement the dynamic configuration that can be hot-reloaded at runtime without restarting the process. This is the core of the config reload mechanism.
DynamicConfig
Hot-reloadable at runtime via ArcSwap. Changes take effect for new connections immediately.
sites: Vec<SiteConfig>— hostname → upstream mapping (collected from all listeners)rate_limit: RateLimitConfig—requests_per_second: u32,burst: u32body_limit_bytes: u64— max request body size
RateLimitConfig:
requests_per_second: u32— required, > 0burst: u32— required, > 0
ArcSwap Pattern
Arc<ArcSwap<DynamicConfig>>provides lock-free reads on the request hot pathConfigReloadHandlewithreload(new_config)method atomically swaps the entire config- No partial updates — the entire DynamicConfig is swapped at once
- All request handlers read current config via
Arcdereference (no lock contention)
Reload Flow
- Read the TOML config file from disk
- Deserialize into full config (both static and dynamic portions)
- Validate the full config (catches static misconfigurations early)
- If valid, swap DynamicConfig via ArcSwap; log warnings for any static changes
- If invalid, reject the reload and keep the old DynamicConfig
Reload Serialization
Use tokio::sync::Mutex on the reload code path. If a reload is in progress and a second is requested, the second waits, re-reads the config file (getting the latest), then proceeds.
Acceptance Criteria
DynamicConfigstruct defined withsites,rate_limit, andbody_limit_bytesfieldsRateLimitConfigstruct defined withrequests_per_secondandburstArc<ArcSwap<DynamicConfig>>used for lock-free reads in handlersConfigReloadHandlestruct withreload(DynamicConfig)method- Reload serialization via
tokio::sync::Mutexprevents concurrent reload race conditions - Static config change detection: if static fields differ from current, log warning listing changed fields
- Unit tests for ArcSwap swap (verify new config visible after reload)
- Unit tests for reload rejection on invalid config
- Unit tests for concurrent reload serialization
References
- docs/architecture/config.md — DynamicConfig, ArcSwap pattern, reload flow
- docs/architecture/decisions/008-static-dynamic-config-split.md — ArcSwap rationale
Notes
The sites vector is collected from all listeners into a single global routing table. Hostname uniqueness validation happens in the validation step, not in DynamicConfig itself.
Summary
To be filled on completion